akhauriyash/Code-Regression huggingface dataset:
/********************************************************
  **░██████╗██╗░░░░░░█████╗░██╗░░░██╗██╗░█████╗░░██████╗░**
  **██╔════╝██║░░░░░██╔══██╗██║░░░██║██║██╔══██╗██╔════╝░**
  **╚█████╗░██║░░░░░███████║╚██╗░██╔╝██║██║░░╚═╝██║░░██╗░**
  **░╚═══██╗██║░░░░░██╔══██║░╚████╔╝░██║██║░░██╗██║░░╚██╗**
  **██████╔╝███████╗██║░░██║░░╚██╔╝░░██║╚█████╔╝╚██████╔╝**
  **╚═════╝░╚══════╝╚═╝░░╚═╝░░░╚═╝░░░╚═╝░╚════╝░░╚═════╝░**
  *********************************************************/
 
#include <bits/stdc++.h>
using namespace std;
 
 
#define ll                          long long
#define ld                          long double
 
#define forn(i,n)                   for(int i=0;i<n;++i)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
#define isSubstring(s1,s2)          s1.find(s2) != std::string::npos
	
#define pb                          push_back
#define pf                          push_front
//#define mp                          make_pair
#define fr                          first
#define sc                          second
 
#define vpi                         vector<pair<int,int>>
#define vi                          vector<int>
#define sz(a)                       (int)a.size()
 
#define   endl                       "\n"
#define     nl                       cout<<"\n";
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
#define  MN                           INT_MIN
#define  MX                           INT_MAX
#define int long long
bool isPrime(ll n){if(n<2)return false;for(ll x = 2;x*x <=n;x++){if(n%x == 0)return false;}return true;}
bool isPerfectSquare(long double x){long double sr=sqrt(x);return((sr-floor(sr))==0);}
int gcd(int a, int b){if(a==0)return b;if(b==0) return a;if(a==b)return a;if(a>b)return gcd(a-b,b);return gcd(a,b-a);}
 
int32_t main()
{
	fastio;
	int n,m;
	cin >> n >> m;
	priority_queue<int> q;
	int a[n];
	for(int i = 0;i<n;i++)
	{
		cin >> a[i];
	}
	unordered_map<int,int> mp;
	for(int i = 0;i<m;i++)
	{
		int b,c;
		cin >> b >> c;
		mp[c] += b;
		if(mp[c] == b)
		{
			q.push(c);
		}
	}
	sort(a,a+n);
	int s = 0;
	for(int i = 0;i<n;i++)
	{
		//cout << q.top() << endl;
		if(a[i] >= q.top() || q.empty())
		{
			s+= a[i];
		}else
		{
			s += q.top();
			mp[q.top()]--;
			if(mp[q.top()] <= 0){
				q.pop();
			}
		}
		//cout << q.top() << " " << mp[q.top()] << endl;
	}
	cout << s << endl;
}

Measured memory_bytes: 9044
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using Vi = vector<int>;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n;
    cin>>n;
    if(n%2==1){
        cout<<0<<endl;
    }
    else{
        ll ans=0;
        ll memo=10;
        rep(i,40){
            ans+=n/memo;
            memo*=5;
        }
        cout<<ans<<endl;
    }
    
}

Measured memory_bytes: 384
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_f(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_f2(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    uint64_t A, B, C, D;

    scanf("%"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, &A, &B, &C, &D);

    uint64_t count = 0;

    count += B / C - (A - 1) / C;
    count += B / D - (A - 1) / D;
    count -= B / (C * D / gcdU64(C, D)) - (A - 1) / (C * D / gcdU64(C, D));

    printf("%"PRIu64, B - A + 1 - count);

    return 0;
}


Measured memory_bytes: 128
#include "stdio.h"

int main(void){
  int x,y,z,i,j,k;
  scanf("%ld %ld %ld", &x, &y, &z);
  long a[x][y];
  long b[y][z];
  long c[x][z];
  for(i = 0; i < x; i++){
    for(j = 0; j < y; j++){
      a[i][j] = 0;
    }
  }

  for(i = 0; i < y; i++){
    for(j = 0; j < z; j++){
      b[i][j] = 0;
    }
  }

  for(i = 0; i < x; i++){
    for(j = 0; j < z; j++){
      c[i][j] = 0;
    }
  }
  for(i = 0; i < x; i++){
    for(j = 0; j <y; j++){
      scanf("%ld \n", &a[i][j]);
    }
  }
  for(i = 0; i < y; i++){
    for(j = 0; j < z; j++){
      scanf("%ld \n", &b[i][j]);
    }
  }
  for(i = 0; i < x; i++){
    for(j = 0; j < z; j++){
      int sum = 0;
      for(k = 0; k < y; k++){
        sum = a[i][k] * b[k][j];
        c[i][j] += sum;
      }
    }
  }
  for(i = 0; i < x; i++){
    for(j = 0; j < z; j++){
      if(j != z-1){
        printf("%ld ", c[i][j]);
      }else{
        printf("%ld", c[i][j]);
      }
    }
    printf("\n");
  }
}



Measured memory_bytes: 2100
"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let N = cin.getInt();
    let A = new Array(N + 2);
    for (let n = 1; n <= N; n++) A[n] = cin.getInt();
    A[0] = 0, A[N + 1] = 0;
    let D = 0;
    for (let n = 0; n <= N; n++) D += Math.abs(A[n] - A[n + 1]);
    for (let n = 1; n <= N; n++) {
        let ans = D - Math.abs(A[n - 1] - A[n]) - Math.abs(A[n] - A[n + 1]) + Math.abs(A[n - 1] - A[n + 1]);
        console.log(ans);
    }
}
class Inputer{constructor(t){if(typeof t=='undefined')throw new Error('引数（stdin）を省略できません！');this.cnt=0,this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    LL a,b,k,mn;
    cin >> a >> b >> k;
    mn=min(a,k);
    a-=mn,k-=mn;
    b-=min(b,k);
    cout << a << ' ' << b;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define sl(i,m) for(auto i=m.begin();i!=m.end();++i)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<int,int>
#define vl vector<long long>
#define se set <long long int>
#define pii pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define tc int t;i(t);while(t--)
#define all(v) v.begin(), v.end()
#define i(x) cin>>x
#define o(x) cout<<x
#define nl o("\n");
#define pi 3.14159265359
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    SYNC 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    lli n,max=0,sum=0;
    i(n);
    lli ar[n];
    l(i,0,n)
    {
        i(ar[i]);
        if(ar[i]>max)
        max=ar[i];
        sum+=(max-ar[i]);
    }
    o(sum);
}

Measured memory_bytes: 5144
n = int(input())
As = list(map(int, input().split()))

# four = sum([1 for a in As if a%4 == 0])
# odd = sum([1 for a in As if a%2 == 1])
# two = sum([1 for a in As if a%2 == 0 and a%4 != 0])
four = 0
odd = 0
two = 0
for a in As:
    if a % 2 == 1:
        odd += 1
    elif a % 4 == 0:
        four += 1
    else:
        two += 1


if four < two%2 + odd - 1:
    print("No")
else:
    print("Yes")



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

const int INF = 1000000000;

typedef long long ll;

int num[105];

struct edge {
    int to, cap, rev;
};

vector<edge> G[105];
bool used[105];

void add_edge(int from, int to, int cap) {
    G[from].push_back((edge) {
        to, cap, G[to].size()
    });
    G[to].push_back((edge) {
        from, 0, G[from].size()-1
    });
}

int dfs(int v, int t, int f) {
    if(v == t) return f;
    used[v] = true;

    for(int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0) {
            int d = dfs(e.to,t,min(e.cap,f));
            if(d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

ll max_flow(int s, int t) {
    ll f = 0;
    for(;;) {
        fill(used, used + 105, false);
        int d = dfs(s,t,INF);
        if(d == 0) return f;
        f += d;
    }
    return f;
}

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &num[i]);
    }
    ll ideal = 0;
    int s = 0;
    int t = n + 1;
    for(int i = 1; i <= n; i++) {
        if(num[i] <= 0) add_edge(s, i, -num[i]);
        else {
            ideal += num[i];
            add_edge(i, t, num[i]);
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 2 * i; j <= n; j += i) {
            add_edge(i,j, INF);
        }
    }
    ll ans = ideal - max_flow(s, t);
    
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())

def Y(num):
 cnt = 0
 for i in range(1,int(num**0.5+1)):
  if num % i == 0:
   cnt += 1
   if i != num**0.5:
    cnt += 1
 return cnt
            
res = 0
for i in range(n+1):
 if i%2 == 0:
  continue
 if Y(i) == 8:
  res += 1

print(res)

Measured memory_bytes: 3188
#include<iostream>
#include<string>

using namespace std;

int main() {
  string str;
  string pat;

  cin >> str >> pat;

  int ans = 0;
  for(int i = 0; i < str.size(); i++) {
    int s = i;
    int p;
    for(p = 0; p < pat.size(); p++) {
      if(str[i+p] != pat[p]) {
        break;
      }
    }

    if(p == pat.size()) {
      cout << i << endl;
    }
  }

  return 0;
}

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

int main(){
  int a,b;
  int d,r;
  double x,y;
  double f;

  cin >> a >> b;
  x = static_cast<double>(a);
  y = static_cast<double>(b);

  d = a/b;
  r = a%b;
  f = x/y;

  cout << d << " " << r << " " << fixed << setprecision(7) << f << endl;

  return 0;
}



Measured memory_bytes: 3284
#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct node{
	int l,r;
}a[100500];
bool cmp(node p,node q)
{
	return p.r<q.r;
}

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int i;
	for (i=1;i<=m;i++)
	    scanf("%d%d",&a[i].l,&a[i].r);
	sort(a+1,a+1+m,cmp);
	int ans=1,nowr=a[1].r;
	for (i=2;i<=m;i++)
	    if (a[i].l>=nowr)
		    {nowr=a[i].r;ans++;}
	printf("%d",ans);
	return 0; 
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

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

	int m;
	cin >> m;
	vector<int> b( m );
	for( int i = 0; i < m; ++i ) { cin >> b[i]; }

	cout << (a < b) << endl;

	return 0;
}



Measured memory_bytes: 3176
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>

using namespace std;

int main(){
	string s;
	while(cin>>s){
		string out;
		for (int i = 0; i < (int)s.size(); i++){
			if(s[i] != '@'){ out.push_back(s[i]); continue;}
			for (int j = 0; j < s[i+1] - '0'; j++){
				out.push_back(s[i+2]);
			}
			i+=2;
		}
		cout << out << endl;
	}
    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void) {
  int i, j, k, ans = 1, n, now = 0, be, a, dis = 0;
  scanf("%d", &n);
  scanf("%d", &be);
  for(i = 1; i < n; ++i) {
    scanf("%d", &a);
    if(dis) {
      if((now && be > a) || (!now && be < a)) ++ans, dis = 0;
    } else {
      if(be < a) now = 1, dis = 1;
      if(be > a) now = 0, dis = 1;
    }
    be = a;
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d;
    cin>>a>>b>>c;
    if(a>=b&&a>=c)d=a*10+b+c;
    else{
    if(b>=a&&b>=c)d=b*10+a+c;
    else{
    if(c>=a&&c>=b)d=c*10+a+b;
    }
    }
    cout<<d<<endl;
    return 0;
}


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

int main(){
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	a=max(40,a);
	b=max(40,b);
	c=max(40,c);
	d=max(40,d);
	e=max(40,e);
	cout << (a+b+c+d+e)/5<<endl;
	return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#include <functional>
#include <iomanip>
#define rep(i,N) for(ll i=0;i<N;i++)
#define disp(a) cout << a << endl;
#define PI 3.1415926535897932384626433
//cout << fixed << setprecision(20) << ** << endl;
typedef long long ll;
using namespace std;
double deg2rad(double degree)
{
    return degree * PI / 180.0000000000;
}
int main()
{
	ll A,V,B,W,T;
	cin>>A>>V>>B>>W>>T;

	if(V<=W){
		cout<<"NO"<<endl;
	}
	else if(abs(W*T-V*T)>=abs(A-B)){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 3132
#include<iostream>
#include<cstdio>
using namespace std;
const int MAX = 101;

char a[MAX][MAX];
int mt[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
int n, m, sum=0;

void dfs(int x, int y, const char ch){
	if (x < 0 || x >= n || y < 0 || y >= m || a[x][y] != ch || a[x][y] == '0'){
		return ;
	}
	a[x][y] = '0';
	for (int i = 0; i < 4; i++){
		int nx = x + mt[i][0];
		int ny = y + mt[i][1];
		dfs(nx, ny, ch);
	}
}
	
void solve(){
	for (int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if (a[i][j] != '0'){
				dfs(i, j, a[i][j]);
				sum++;
			}
		}
	}
}

int main(){
	
	while(scanf("%d %d", &n, &m) == 2 && n){
	sum = 0;	
	
	for (int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin >> a[i][j];
		}
	}
	
	solve();
	cout << sum << endl;
	}
	return 0;
}





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

using namespace std;

int main()
{
    vector<int> a(3);
    for (int i = 0; i < 3; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    cout << a[0] + a[1];
    return 0;
}


Measured memory_bytes: 256
n=int(input())
ans=0
while n>0:
  l=len(str(n))
  if l%2==0:
    n=10**(l-1)-1
  l=len(str(n))
  if l==1:
    ans+=n
  else:
    chk=int(str(n)[0])
    ans+=n-(10**(l-1)-1)
  if l>0:
    n=10**(l-2)-1
print(ans)

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

int x[105];

int main()
{
	long long ans=0,maxn=9999999999;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&x[i]);
	for(int i=1;i<=100;i++)
	{
		ans=0;
		for(int j=1;j<=n;j++)
			ans+=(i-x[j])*(i-x[j]);
		maxn=min(ans,maxn);
	}
	cout<<maxn<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
	
	for(;;){
		char ban[3][3];
		char result = 'N';
		
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 3; j++){
				cin >> ban[i][j];
				if(ban[i][j] == '0'){
					goto FIN;
				}
			}
		}
		
		for(int i = 0; i < 3; i++){
			if(ban[i][0] == ban[i][1] && ban[i][1] == ban[i][2]){	//ツ可。ツ板サツ津ィ
				if(ban[i][0] == 'b'){
					result = 'b';
				}
				else if(ban[i][0] == 'w'){
					result = 'w';
				}
			}
		}
		for(int i = 0; i < 3; i++){
			if(ban[0][i] == ban[1][i] && ban[1][i] == ban[2][i]){	//ツ可。ツ板サツ津ィ
				if(ban[0][i] == 'b'){
					result = 'b';
				}
				else if(ban[0][i] == 'w'){
					result = 'w';
				}
			}
		}
		
		if(ban[0][0] == ban[1][1] && ban[1][1] == ban[2][2]){	//ツづ按づ按づ淞板サツ津ィ
			if(ban[0][0] == 'b'){
				result = 'b';
			}
			else if(ban[0][0] == 'w'){
				result = 'w';
			}
		}
		if(ban[0][2] == ban[1][1] && ban[1][1] == ban[2][0]){	//ツづ按づ按づ淞板サツ津ィ
			if(ban[0][2] == 'b'){
				result = 'b';
			}
			else if(ban[0][2] == 'w'){
				result = 'w';
			}
		}
		
		if(result == 'N'){
			cout << "NA" << endl;
		}
		else{
			cout << result << endl;
		}
	}
	FIN:;
	getchar();
		getchar();
			getchar();
				getchar();
					getchar();
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <vector>
#include <map>

const int MN = 100005;

int N, A[MN], B[MN], X, cnt, M, Ans;
std::map<int, int> mp;

int vis[MN];
std::vector<int> G[MN];
void DFS(int u) {
	vis[u] = 1;
	for (int v : G[u]) if (!vis[v]) DFS(v);
}

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) scanf("%d", &A[i]), ++mp[A[i]], X ^= A[i];
	for (int i = 1; i <= N; ++i) scanf("%d", &B[i]), --mp[B[i]];
	++mp[X];
	for (auto p : mp) if (p.second < 0) return puts("-1"), 0;
	for (auto &p : mp) p.second = ++cnt;
	for (int i = 1; i <= N; ++i) if (A[i] != B[i]) {
		int u = mp[B[i]], v = mp[A[i]];
		G[u].push_back(v);
		G[v].push_back(u);
		++M;
	}
	for (int i = 1; i <= cnt; ++i) if (!G[i].empty())
		if (!vis[i]) ++Ans, DFS(i);
	if (!G[mp[X]].empty()) --Ans;
	printf("%d\n", M + Ans);
	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long K = sc.nextLong();
		int[] a = new int[N];
		int[] b = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		qsort(a, b, 0, N - 1);
		long cnt = 0;
		int idx = 0;
		while (cnt < K) {
			cnt += b[idx];
			idx++;
		}
		System.out.println(String.valueOf(a[idx - 1]));
	}

	static void qsort(int[] a, int[] b, int left, int right) {
		if (left >= right) {
			return;
		}
		int p = a[(left + right) / 2];
		int l = left;
		int r = right;
		int tmp;
		while(l <= r) {
		while(a[l] < p) { l++; }
		while(a[r] > p) { r--; }
			if (l <= r) {
				tmp = a[l];
				a[l] = a[r];
				a[r] = tmp;
				tmp = b[l];
				b[l] = b[r];
				b[r] = tmp;
				l++;
				r--;
			}
		}
		qsort(a, b, left, r);
		qsort(a, b, l, right);
	}

	static class Scanner {
		private InputStream in;
		private final byte[] buf = new byte[1024];
		private int cur = 0;
		private int len = 0;

		Scanner (InputStream in) {
			this.in = in;
		}

		private int read() {
			if (cur >= len) {
				cur = 0;
				try {
					len = in.read(buf);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (len < 0) {
					return -1;
				}
			}
			return (int)buf[cur++];
		}

		public String next() {
			int c = read();
			if (c == -1) {
				throw new NoSuchElementException();
			}
			while (c < 33 || 126 < c) {
				c = read();
			}
			StringBuilder sb = new StringBuilder();
			while (33 <= c && c <= 126) {
				sb.appendCodePoint(c);
				c = read();
			}
			return sb.toString();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 42832
import sys

s=list(input())

def f(p,i,F):
  if i == 4 and p == 7:
    print(F+"=7")
    sys.exit()
  elif i==4:
    return ""
  else:
    f(p+int(s[i]),i+1,F+"+"+s[i])
    f(p-int(s[i]),i+1,F+"-"+s[i])
    
f(int(s[0]),1,s[0])

Measured memory_bytes: 3064
//Rochy'.'
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define fl(i,a,b) for(int i=a;i<b;++i)
#define fa(i,a) for(auto i:a)
#define ii pair <int,int>
#define vi vector <int>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
using namespace std;
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));
if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar()))x=x*10+c-48;if(nega)x=-x;}
template <typename T> inline void writep(T x){if(x>9)writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
template <typename R, typename D> inline void Min(R &a, D b){if(a>b) a=b;}
template <typename D, typename R> inline void Max(D &a, R b){if(a<b) a=b;}
const int N = 200005;
string t,s;
int k,cnt,cnt2;
int main(){
    ios_base::sync_with_stdio(NULL);
    cin. tie(NULL); cout. tie(NULL);
//    freopen(".inp" , "r", stdin);
//    freopen(".out", "w", stdout);
	cin>>t;s=t;cin>>k;
	fl(i,1,s.size()){
		if(s[i]==s[i-1]){
			++cnt;
			s[i]='?';
		}
	}
	if(k==1)return!(cout<<cnt);
	if(s.back()=='?'||s.back()!=s[0])return!(cout<<1ll*cnt*k);
	cnt2=1;t[0]='?';
	fl(i,1,t.size()){
		if(t[i]==t[i-1]){
			++cnt2;
			t[i]='?';
		}
	}
	if(t.back()=='?')return!(cout<<1ll*(cnt+cnt2)*(k/2)+cnt*(k&1));
	cout<<1ll*cnt+1ll*cnt2*(k-1);
    return 0;
}

Measured memory_bytes: 256
/*  ***  In The Name of God ... ***  */ 
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int N = 1e5 + 10 ;

string s ;

int n , ar [ N ] , pre [ N ] , par [ N ] ; 

pair < int , int > solve ( char c ) {
	for ( int i = 0 ; i < n ; ++ i ) {
		ar [ i + 1 ] = ( s [ i ] == c ? 1 : -1 ) ;
	}
	for ( int i = 1 ; i <= n ; ++ i )
		ar [ i ] += ar [ i - 1 ] ;
	for ( int i = 1 ; i <= n ; ++ i ) {
		pre [ i ] = pre [ i - 1 ] ;
		par [ i ] = par [ i - 1 ] ; 
		if ( ar [ i ] < pre [ i ] )
			pre [ i ] = ar [ i ] , par [ i ] = i ;
		if ( i > 1 && ar [ i ] - pre [ i - 2 ] > 0 ) {
			return { par [ i - 2 ] + 1 , i } ; 
		}
	}
	return { -1 , -1 } ; 
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> s ;
	n = ( int ) s . size ( );
	for ( char want = 'a' ; want <= 'z' ; ++ want ) {
		pair < int , int > res = solve ( want ) ;
		if ( res . first != -1 ) {
			
			cout << res . first << ' ' << res . second << '\n' ;
			return 0 ; 
		}
	}
	cout << -1 << ' ' << -1 << '\n' ; 
}


Measured memory_bytes: 2768
#include<iostream>
#include<algorithm>
using namespace std;
int a[111],b[111],n,m,x,y,z;
main()
{
	for(cin>>n>>m>>x>>y;z<n;cin>>a[z++]);
	for(z=0;z<m;cin>>b[z++]);
	sort(a,a+n),sort(b,b+m);
	for(z=x+1;z<=y;z++)
	{
		if(a[n-1]<z&&z<=b[0])
		{
			cout<<"No ";
			break;
		}
	}
	cout<<"War"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
template<typename key> using ordered_set = tree <key, null_type, less<key>, rb_tree_tag, tree_order_statistics_node_update>; 
 
ll n, w;
ll weight[101], price[101];
ll dp[101][100003];

ll solve(int ind, ll remW) {
   if(remW < 0) 
      return INT64_MIN;
   if(ind == n) {
      if(remW < 0)
         return INT64_MIN;
      return 0;
   }
   ll &rt = dp[ind][remW];
   if(rt != -1)
      return rt;
   rt = max(0ll, solve(ind + 1, remW));
   rt = max(rt, price[ind] + solve(ind + 1, remW - weight[ind]));
   return rt;
}

int main () {
   IO;
   cin >> n >> w;
   for(int i = 0; i < n; i++) 
      cin >> weight[i] >> price[i];
   memset(dp, -1, sizeof dp);
   cout << solve(0, w);
   return 0;
}

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

#define ABS(n) (n<0?-(n):(n))

#define INF (1<<20)
int field[128][128];

int dist(int x1, int y1, int x2, int y2)
{
	x1-=(y1-1)/2;
	x2-=(y2-1)/2;

	return (ABS(x1-x2)+ABS(y1-y2)+ABS((x1+y1)-(x2+y2)))/2;
}

int main()
{
	int w,h,n,x0,y0,cnt,ans;
	while(cin >> w, w)
	{
		cin >> h;
		for(int y=1; y<=h; y++)
		for(int x=1; x<=w; x++)
		{
			field[y][x] = INF;
		}
		
		cin >> n;
		while(n--)
		{
			cin >> x0 >> y0;
			for(int y=1; y<=h; y++)
			for(int x=1; x<=w; x++)
			{
				field[y][x] = min(field[y][x],dist(x0,y0,x,y));
			}
		}

		ans = 0;
		cin >> n;
		while(n--)
		{
			cnt = 0;
			cin >> x0 >> y0;
			for(int y=1; y<=h; y++)
			for(int x=1; x<=w; x++)
			{
				if(field[y][x]>dist(x0,y0,x,y)) cnt++;
			}
			ans = max(ans,cnt);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld; //
typedef double db; //
typedef string str; //
//
typedef pair<int, int> pi;
typedef pair<ll,ll> pl; //
typedef pair<ld,ld> pd; //
#define mp make_pair
#define f first
#define s second

typedef vector<int> vi; 
typedef vector<ll> vl; //
typedef vector<ld> vd; //
typedef vector<str> vs; //
typedef vector<pi> vpi; //
typedef vector<pl> vpl; //
typedef vector<pd> vpd; //
//
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() //
#define rsz resize
#define ins insert //
#define ft front() //
#define bk back() //
#define pf push_front //
#define pb push_back
#define eb emplace_back //
#define lb lower_bound //
#define ub upper_bound //

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5; //
const ll INF = 1e18; //
const ld PI = 4*atan((ld)1); 
const int xd[4] = {0,1,0,-1}, yd[4] = {1,0,-1,0}; //

template<class T> bool ckmin(T& a, const T& b) { 
	return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { 
	return a < b ? a = b, 1 : 0; }
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

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

    ll K, A, B;
    cin >> K >> A >> B;
    if (K+1 < A) {
        cout << K+1 << endl;
        return 0;
    }

    ll poss = K+1;
    ll cur = A;
    if ((A+K+1)%2 == 1){ 
        cur++;
    } 
    cur += ((K-(A-1))/2) * (B-A);
    poss = max(poss, cur);

    cout << poss << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
using namespace std;
 
int n,m,r;
const int INF=1e7;
int d[2][200][200];
typedef pair<int,int> P;
 
int main(){
 
 
    while(scanf("%d %d",&n,&m),n){
	    
	   for(int i=0;i<n;i++){
		  for(int j=0;j<n;j++) d[0][i][j]=d[1][i][j]=INF;
		  d[0][i][i]=d[1][i][i]=0;
	   }
	    
	   for(int i=0;i<m;i++){
		  int x,y,t;
		  char c;
		  scanf("%d %d %d %c",&x,&y,&t,&c);
		  x--; y--;
		  
		  d[c=='L'][x][y]=min(d[c=='L'][x][y],t);
		  d[c=='L'][y][x]=min(d[c=='L'][y][x],t);
	   }
	    
	   for(int k=0;k<n;k++){
		  for(int i=0;i<n;i++){
			 for(int j=0;j<n;j++){
				d[0][i][j]=min(d[0][i][j],d[0][i][k]+d[0][k][j]);
				d[1][i][j]=min(d[1][i][j],d[1][i][k]+d[1][k][j]);
			 }
		  }
	   }
	   
	   int now,z;
	   scanf("%d",&r);
	   scanf("%d",&now); now--;
	   vector<vector<int> > dp(1000,vector<int>(200,INF));
	   dp[0][now]=0;
	    
	   for(int i=0;i<r-1;i++){
		   scanf("%d",&z); z--;
		   
		   for(int j=0;j<n;j++){
			   for(int k=0;k<n;k++){
				   // 
				   dp[i+1][k]=min(dp[i+1][k],dp[i][j]+d[1][now][j]+d[0][j][k]+d[1][k][z]);
			   }
			   
			   dp[i+1][j]=min(dp[i+1][j],dp[i][j]+d[1][now][z]);
		   }
		   now=z;
	   }


/*
	   //int res=INF;
	   for(int i=1;i<r;i++){
		  for(int j=0;j<n;j++){
						    
			 for(int k=0;k<n;k++){
				dp[i][k]=min(dp[i][k],dp[i-1][j]+d[1][z[i-1]][j]+d[0][j][k]+d[1][k][z[i]]);
				//if(i==r-1 && res>dp[i][k]) res=dp[i][k];
			 }
			 dp[i][j]=min(dp[i][j],dp[i-1][j]+d[1][z[i-1]][z[i]]);
			 //if(i==r-1 && res>dp[i][j]) res=dp[i][j];
		  }
	   }
*/
	   printf("%d\n",*min_element(dp[r-1].begin(),dp[r-1].end()));
	    
    }
}

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

int main(){
    string S,T,U;
    cin >> S >> T;
    int A, B;
    cin >> A >> B;
    cin >> U;
    if(S == U){
        A--;
    }else{
        B--;
    }

    cout<< A << " "<< B <<endl;
}


Measured memory_bytes: 256
// IOI 2021
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
 
////////////////////////////////////////////////////////////////////
 
const int N = 3e3 + 5;

int DP[N][N][2];

void Add(int &x, int y) {
	x += y;
	if (x >= MOD) x -= MOD;
}

int main() {
 
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));

	int n, m; cin >> n >> m;
	for (int i = 0; i <= n; i++) DP[0][i][(i == 0)] = 1;
	for (int i = 0; i < m; i++) for (int j = 0; j <= n; j++) for (int k = 0; k < 2; k++) {
		Add(DP[i + 1][j - 1][k | (j == 1)], (0 < j) * DP[i][j][k]);
		Add(DP[i + 1][j][k | (j == 1)], (0 < j) * DP[i][j][k]);
		Add(DP[i + 1][j + 1][k], (j < n) * DP[i][j][k]);
		Add(DP[i + 1][j][k], (j < n) * DP[i][j][k]);
	}
	int ans = 0;
	for (int i = 0; i <= n; i++) Add(ans, DP[m][i][1]);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 73996
fun main(args: Array<String>) = p10()

fun p10() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toInt() }.toIntArray()
    readLine()
    val queries = readLine()!!.split(' ').map { it.toInt() }

    val sumSet = mutableSetOf<Int>()

    for (i in 0L until (1L shl n)) {
        sumSet.add(aList.filterIndexed { index, _ -> (i shr index) % 2 == 0L }.sum())
    }

    val answer = StringBuilder()
    
    for (query in queries) {
        answer.appendln(if (query in sumSet) "yes" else "no")
    }

    print(answer)
}



Measured memory_bytes: 70112
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,k;
int head[N],ver[N],nxt[N],tot;
int a[N];
int dep[N];
long long ans;
void add(int x,int y)
{
	ver[++tot]=y;
	nxt[tot]=head[x];
	head[x]=tot;
}
void dfs(int x,int fa)
{
	dep[x]=0;
	for(int i=head[x];i;i=nxt[i])
	{
		int y=ver[i];
		if(y!=fa)
		{
			dfs(y,x);
			dep[x]=max(dep[x],dep[y]+1);
		}
	}
	if(dep[x]==k-1&&fa!=1)
	{
		ans++;
		dep[x]=-1;
	}
}
int main()
{
	int n;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{		
		scanf("%d",&a[i]);
		if(i!=1)
		add(a[i],i);
	}
	if(k==1)
	{
		for(int i=1;i<=n;i++)
		if(a[i]!=1)
		{
			ans++;
		}
		printf("%lld",ans);
		return 0;
	}
	dfs(1,1);
	if(a[1]!=1)
	ans++;
	printf("%lld",ans);
	return 0;
}

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

class LessInt {
public:
    bool operator()(const pair<int,int>& riLeft, const pair<int,int>& riRight) const {
        return riLeft.first > riRight.first;
    }
};

void print_vector(std::vector<ll> v)
{
  std::vector<ll>::iterator itr;
  for(itr=v.begin(); itr!=v.end(); itr++)
  {
    cout << *itr << " ";
  }
  cout << endl;
}

std::vector<ll> make_D(std::vector<pair<int,int> > v, int n)
{
  std::vector<ll> D;
  int i=0;
  std::vector<pair<int,int> >::iterator itr;
  itr = v.begin();
  while(i<n&&itr!=v.end())
  {
    ll tmp=(*itr).first;
    for(int j=0; j<(*itr).second; j++)
    {
      D.push_back(tmp);
      i++;
      if(i==n)
      {
        return D;
      }
    }
    itr++;
  }
  return D;
}

int main()
{
  int n,m;
  cin >> n >> m;
  std::vector<ll> A,D;
  std::vector<pair<int,int> > CB;
  for(int i=0; i<n; i++)
  {
    int tmp;
    cin >> tmp;
    A.push_back(tmp);
  }
  sort(A.begin(),A.end());
  for(int i=0; i<m; i++)
  {
    int b,c;
    cin >> b >> c;
    CB.push_back(make_pair(c,b));
  }
  sort(CB.begin(),CB.end(),LessInt());
  D = make_D(CB,n);
  ll M = 0;
  ll tmp = 0;
  tmp =accumulate(A.begin(),A.end(),tmp);
  M = max(M,tmp);
  for(int x=0; x<(int)D.size(); x++)
  {
    tmp -= A.at(x);
    tmp += D.at(x);
    M = max(M,tmp);
  }
  cout << M << endl;
  return 0;
}


Measured memory_bytes: 4340
#include<stdio.h>
#define WHITE 0
#define BLACK 2
#define GLAY 1
#define N 102
int g[N][N],d[N],color[N],k[N],Q[N];
int time,n,head=0,tail=0;

void Enqueue(int Q[],int s){
  Q[tail]=s;
  tail++;
}
 
int Dequeue(int Q[]){
  head++;
  return Q[head-1];
}
 
 
void BFS(int s){
  int i,u;
  
  for(i = 1;i <=n; i++){
    color[i] = WHITE;
    d[i] = -1;
  }
   color[s]=GLAY;
  d[s]=0;
  Enqueue(Q,s);
   
  while(head!=tail){
    u=Dequeue(Q);
    for(i=1;i<=n;i++){
      if(g[u][i]==1){ 
    if(color[i]==WHITE){
      color[i]=GLAY;
      d[i]=d[u]+1;
      Enqueue(Q,i);
    }
      }
    }
    color[u]=BLACK;
  }
}
 
int main(){
  int i,j,l,u,v;
  scanf("%d",&n);
 
  for(i = 0;i < n; i++){
    scanf("%d",&u);
    scanf("%d",&l);
    for(j = 0;j < l;j++){
      scanf("%d",&v);
      g[u][v] = 1;
    }
  }
 
 
      BFS(1);
    for(i = 1; i <=n;i++){
      printf("%d %d\n", i,d[i]);
    }
    return 0;
  }

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

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

    // for prime mod
    constexpr mint inv() const {
        return pow(mod-2);
    }
    constexpr mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
};
ostream& operator<<(ostream& os, const mint& m){
    os << m.x;
    return os;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(All(a));
  if (n%2 == 0) {
    for (ll i = 0; i < n; i += 2) {
      if (a[i] != i+1 || a[i+1] != i+1) {
        cout << 0 << '\n';
        return 0;
      }
    }
  }
  if (n%2 == 1) {
    if (a[0] != 0) {
      cout << 0 << '\n';
      return 0;
    }
    for (ll i = 1; i < n; i += 2) {
      if (a[i] != i+1 || a[i+1] != i+1) {
        cout << 0 << '\n';
        return 0;
      }
    }
  }
  mint ans = 1;
  n /= 2;
  rep(i,n) {
    ans *= 2;
  }
  cout << ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 4028
s=input()
S=list(s)
count=1
a=[]
a.append(S[0])
S.remove(S[0])
x=''
for i in range(len(S)):
    x+=S[i]
    if a[len(a)-1]!=x:
        a.append(x)
        x=''
        count+=1
    else:
        continue
print(len(a))

Measured memory_bytes: 9832
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

const ll MOD = 1e9 + 7;


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

	map<ll, ll> m;
	for (int i = k; i >= 1; i--) {
		ll cnt = 1;
		int num = k / i;
		
		ll pi = num;


		ll tmp = n;
		for (int j = 0; j < 32; j++) {
			if (((n >> j)&1)==1) {
				
				cnt = (cnt * pi) % MOD;
			}
			pi = (pi * pi) % MOD;
		}
		
		
		

		for (int j = 2 * i; j <= k; j += i) {
			cnt =(cnt + MOD - m[j])%MOD;
		}

		m[i] = cnt;
	}


	ll sum = 0;
	for (auto it = m.begin(); it != m.end(); it++) {
		sum = (sum + (it->first * it->second) % MOD) % MOD;
	}

	cout << sum << endl;


}

Measured memory_bytes: 9788
N = int(input())
a = list(map(int,input().split()))

def solve(cand):
	global a
	res = 0
	for ai in a:
		if ai - 1 == cand or ai == cand or ai + 1 == cand:
			res += 1
	return res

cnt = {}
for ai in a:
	for i in range(-1,2):
		b = ai + i
		if b >= 0:
			if b not in cnt:
				cnt[b] = 1
			else:
				cnt[b] += 1

candX = max(cnt.items(), key=lambda x:x[1])[0]
res = solve(candX);

print(res)

Measured memory_bytes: 19684
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=1e5+5;
int n;

namespace utils{
	template <class T> inline void apn(T &x,const T y){x>y?x=y:0;}
	template <class T> inline void apx(T &x,const T y){x<y?x=y:0;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

namespace G{
	int cnt,fir[N],fa[N],sz[N],dep[N];
	struct edge{
		int to,nx;
	}eg[N<<1];

	inline void add(const int a,const int b){
		eg[++cnt]=(edge){b,fir[a]};
		fir[a]=cnt;
	}

	void dfs(const int x){
		sz[x]=1;
		for(int i=fir[x]; i; i=eg[i].nx){
			const int y=eg[i].to;
			if(sz[y]) continue;
			fa[y]=x;
			dep[y]=dep[x]+1;
			dfs(y);
			sz[x]+=sz[y];
		}
	}

	bool jdg(){
		int x=n,des_dep=(dep[n]>>1)+1;
		for(; dep[x]>des_dep; x=fa[x]);
		return n-sz[x]>sz[x];
	}
}

int main(){
	n=nxi();
	for(int i=1; i<n; ++i){
		const int a=nxi(),b=nxi();
		G::add(a,b);
		G::add(b,a);
	}
	G::dfs(1);
	puts(G::jdg()?"Fennec":"Snuke");
	return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  vector<ll> v;
  rep(i,n) v.pb(m+i);
  sort(all(v));
  ll sum=0;
  rep(i,n) sum+=v[i];
  ll ans=MAX,x;
  rep(i,n) {
    ll s=0;
    rep(j,n) {
      if(i==j) continue;
      s+=v[j];
    }
    if(ans>abs(sum-s)) {
      ans=abs(sum-s);
      x=s;
    }
  }
  pr(x);
}

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


Measured memory_bytes: 256
const Main = (input) => {
  const inputArr = input.split('\n')
  const num = inputArr[0]
  const scoredRestaurants = inputArr
    .filter((ele, i) => !!i)
    .map((row, i) => [i + 1].concat(row.split(' ')))

  const sorted = scoredRestaurants.sort(compare)
  sorted.forEach((ele, i) => {
    if (ele[1] !== '') console.log(ele[0])
  })
}

const compare = (a, b) => {
    const aName = a[1]
    const bName = b[1]

    return aName === bName ? scoreCompare(a, b)
    : aName < bName ? -1 : 1
}

const scoreCompare = (a, b) => {
    const aScore = parseInt(a[2], 10)
    const bScore = parseInt(b[2], 10)
    return aScore === bScore ? 0
    : aScore < bScore ? 1 : -1
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 7500
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int nans = n * (n-1) / 2;
    int mans = m * (m-1) / 2;
    int ans = nans + mans;
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
num = [0]*(10**5+1)
for i in a:
  num[i] += 1
sm = sum(a)
q = int(input())
for _ in range(q):
  x,y = map(int,input().split())
  nx = num[x]
  sm = sm+y*nx-x*nx
  print(sm)
  num[x] = 0
  num[y] += nx

Measured memory_bytes: 84104
/**
*   @Author : MeGaCrazy
*   @InitTime : Wed Jan 02 22:44:30 2019
*   @Idea :
*
*
*
*
*
*  Happy Solving :)
**/
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
   //freopen("in","r",stdin);
   //freopen("out","w",stdout);
#endif
    int n;
    cin>>n;
    vector<int>v;
    for(int i=0;i<n;i++){
       int a;
       cin>>a;
       v.push_back(a);
    }
    long long ans=0;

    long long a=v[0];
    long long sum=abs(a);

    if(a<0){
        ans+=abs(a)+1;
        sum=1;

    }
    if(v[0]==0){
       ans=1;
       sum=1;
    }
    for(int i=1;i<n;i++){
    	if(sum <0 && sum + v[i] >0 || sum >0 && sum + v[i] <0){
    	    sum+=v[i];
	    continue;
    	}
    	if(sum <0){
    	     ans+=abs(sum+v[i])+1;	
    	     sum=1;
    	}else if(sum >0){
    	    ans+=abs(sum+v[i])+1;
    	    sum=-1;
    	}
    }


    sum=abs(a)*-1;
    long long ans1=0;

    if(a>0){
        ans1+=abs(a)+1;
        sum=-1;
    }
    if(v[0]==0){
       ans1=1;
       sum=-1;
    }

    for(int i=1;i<n;i++){
    	if(sum <0 && sum + v[i] >0 || sum >0 && sum + v[i] <0){
    	    sum+=v[i];
	    continue;
    	}
    	if(sum <0){
    	     ans1+=abs(sum+v[i])+1;	
    	     sum=1;
    	}else if(sum >0){
    	    ans1+=abs(sum+v[i])+1;
    	    sum=-1;
    	}
    }
    cout<<min(ans1,ans)<<endl;





}

Measured memory_bytes: 892
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }
        int[] ans = new int[N];
        for (int i = 0; i < N; i++) {
            ans[A[i]-1] = i+1;
        }
        StringJoiner sj = new StringJoiner(" ");
        for(int x : ans) {
            sj.add(Integer.toString(x));
        }
        System.out.println(sj.toString());
    }
}


Measured memory_bytes: 58416
-- abs.hs --- ABS

-- author: Seong Yong-ju <sei40kr@gmail.com>

solve :: Int -> Int -> [Int] -> Int
solve z w [] = abs $ z - w
solve _ w [a] = abs $ a - w
solve _ w (a1:a2:_) = max (abs $ a1 - w) (abs $ a1 - a2)

main :: IO ()
main = do
  [n, z, w] <- map (read :: String -> Int) . words <$> getLine
  as <- map (read :: String -> Int) . take n . words <$> getLine
  print $ solve z w $ reverse as


Measured memory_bytes: 2300
from itertools import permutations
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
inf = 10 ** 10
n, m, r = map(int,input().split())
R = list(map(int,input().split()))

edge = [[inf] * n for i in range(n)]
for i in range(m):
    a, b, c = map(int,input().split())
    edge[a - 1][b - 1] = c

G = csgraph_from_dense(edge, null_value = inf)
d = floyd_warshall(G, False)

rec = inf
for i in permutations(R, r):
    temp = 0
    #print(i)
    for j in range(r):
        if j == r - 1:continue
        temp += d[i[j] - 1][i[j + 1] - 1]
    rec = min(rec, temp)

print(int(rec))

Measured memory_bytes: 19936