akhauriyash/Code-Regression huggingface dataset:
/**
 * @file main.cpp
 * @author Kentaro Sugimoto (tarotene@gmail.com)
 * @brief Output the cost (to stdout) for an unordered set with its size (from stdin) according to "silly sort".
 * For more detail, please refer https://www.ipsj.or.jp/07editj/promenade/4506.pdf (Japanese only).
 * @version 0.1
 * @date 2019-03-21
 * 
 * @copyright Copyright (c) 2019
 * 
 */

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

int main(int argc, char const *argv[])
{
    // input elements from stdin
    int n = 0;
    cin >> n;
    vector<int> elements(n, 0);
    for (int i = 0; i < n; ++i)
    {
        cin >> elements[i];
    }

    // pre-sort
    auto elements_sorted = elements;
    sort(elements_sorted.begin(), elements_sorted.end());

    // construct loop
    map<int, int> loop;
    for (int i = 0; i < n; ++i)
    {
        loop[elements_sorted[i]] = elements[i];
    }

    // construct subloops and their inverses
    vector<map<int, int>> subloop(n), subloop_inv(n);

    map<int, bool> checked;
    for (int i = 0; i < n; ++i)
    {
        checked[elements[i]] = false;
    }

    for (int i = 0; i < n; ++i)
    {
        int k = elements[i];
        while (checked[k] == false)
        {
            checked[k] = true;
            subloop[i][k] = loop[k];
            subloop_inv[i][loop[k]] = k;
            k = loop[k];
        }
    }

    // find the minimum for each subloop
    vector<int> submin(n, 0);
    for (int i = 0; i < n; ++i)
    {
        auto itr = subloop[i].begin();
        submin[i] = itr->first;
    }

    // derive the sum of elements for each subloop
    vector<int> subsum(n, 0);
    for (int i = 0; i < n; ++i) {
        for (auto itr = subloop[i].begin(); itr != subloop[i].end(); ++itr)
        {
            subsum[i] += itr->first;
        }
    }

    // calculate the cost for whole loops
    int cost = 0;
    for (int i = 0; i < n; ++i)
    {
        if (subloop[i].size() <= 1)
        {
            continue;
        }
        else
        {
            cost += min(subsum[i] + (subloop[i].size() - 2) * submin[i], subsum[i] + submin[i] + (subloop[i].size() + 1) * elements_sorted[0]);
        }
    }

    cout << cost << endl;

    return 0;
}



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


int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a,b) + min(c,d) << endl;
    
}


Measured memory_bytes: 256
<?php
  list($a) = explode(" ", trim(fgets(STDIN)));
  list($b) = explode(" ", trim(fgets(STDIN)));
  list($c) = explode(" ", trim(fgets(STDIN)));

  $ai = $bi = $ci = 0;

  $t = 'a';

  while(1){
    if($t == 'a') {
      if(strlen($a) == $ai){
        echo 'A';
        exit;
      }
      $t = $a[$ai];
      $ai++;
    }
    if($t == 'b') {
      if(strlen($b) == $bi){
        echo 'B';
        exit;
      }
      $t = $b[$bi];
      $bi++;
    }
    if($t == 'c') {
      if(strlen($c) == $ci){
        echo 'C';
        exit;
      }
      $t = $c[$ci];
      $ci++;
    }
  }

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

int main() {
  int n;
  cin >> n;
  std::vector<int> d(n);
  rep(i,n) cin >> d.at(i);

  int total = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      total += d.at(i) * d.at(j);
    }
  }
  cout << total << endl;
}


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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};


void solve(long long N, long long M, long long K, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C, std::vector<long long> D){
    UnionFind uf(N);
    vector<i64> ans(N, -1);
    rep(i, M){
        --A[i];
        --B[i];
        uf.unite(A[i], B[i]);
        ans[A[i]]--;
        ans[B[i]]--;
    }
    rep(i, N){
        ans[i] += uf.size(i);
    }
    rep(i, K){
        --C[i];
        --D[i];
        if(uf.find(C[i]) == uf.find(D[i])){
            ans[C[i]]--;
            ans[D[i]]--;
        }
    }
    rep(i, N - 1) cout << ans[i] << " ";
    cout << ans[N - 1] << endl;
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    std::vector<long long> C(K);
    std::vector<long long> D(K);
    for(int i = 0 ; i < K ; i++){
        scanf("%lld",&C[i]);
        scanf("%lld",&D[i]);
    }
    solve(N, M, K, std::move(A), std::move(B), std::move(C), std::move(D));
    return 0;
}


Measured memory_bytes: 5120
#include <cstdio>
#include <cmath>

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

typedef long long   signed int LL;
typedef long long unsigned int LU;

template<typename T> void swap(T &x, T &y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T &a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T &a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

char s[100001];

int main() {
	scanf("%s", s);
	
	int i = 0, c = 0;
	char p = s[0];
	while(s[i] != '\0') {
		if(s[i] != p) { p = s[i]; c++; }
		i++;
	}
	
	printf("%d\n", c);
	
	return 0;
}


Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int hi = 0;
		ArrayList<Integer> xlist = new ArrayList<Integer>();
		ArrayList<Integer> ylist = new ArrayList<Integer>();
		ArrayList<Integer> hlist = new ArrayList<Integer>();
		for ( int i = 0; i < n; i++ ) {
			xlist.add(in.nextInt());
			ylist.add(in.nextInt());
			hlist.add(in.nextInt());

			if ( hlist.get(i) != 0 ) hi = i;
		}
		in.close();

		for ( int cy = 0; cy <= 100; cy++ ) {
			for ( int cx = 0; cx <= 100; cx++ ) {
				boolean match = true;
				int Height = hlist.get(hi) + Math.abs(xlist.get(hi) - cx) + Math.abs(ylist.get(hi) - cy);
				
				for ( int i = 0; i < hlist.size(); i++ ) {					
					if(hlist.get(i) != 0) {
						int tempH = hlist.get(i) + Math.abs(xlist.get(i) - cx) + Math.abs(ylist.get(i) - cy);
						if ( Height != tempH ) {
							match = false;
							break;
						} else {
							Height = tempH;							
						}						
					}
					
					if(hlist.get(i) == 0 && Height > Math.abs(xlist.get(i) - cx) + Math.abs(ylist.get(i) - cy)) {
						match = false;
						break;
					}
				}
				if ( match ) {
					System.out.println(cx + " " + cy + " " + Height);
					return;
				}
			}
		}
	}
}


Measured memory_bytes: 21972
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

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

void run(void){
  int n;
  scanf("%d",&n);
  char *s=(char *)calloc(n+1,sizeof(char));
  scanf("%s",s);
  int cntE=0;
  int i;
  for(i=0;i<n;i++){
    if(s[i]=='E') cntE++;
  }
  int min=n;
  int cntW=0;
  for(i=0;i<n;i++){
    if(s[i]=='E') cntE--;
    min=MIN(min,cntE+cntW);
    if(s[i]=='W') cntW++;
  }
  printf("%d\n",min);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int D;
vector<int> c(26); 
vector<vector<int>> s(365, vector<int>(26));

vector<int> cal_score(vector<int> t){
    vector<int> res(D);
    int satis = 0;
    vector<int> last(26, 0);
    rep(d, D){
        satis += s[d][t[d] - 1];
        last[t[d] - 1] = d + 1;
        rep(i, 26){
            satis -= c[i] * (d - last[i] + 1);
        }
        res[d] = satis;
    }
    return res;
}


int main(){
    // input 
    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D){
        rep(j, 26){
            cin >> s[i][j];
        }
    }
    vector<int> t(D);
    rep(i, D) cin >> t[i];
    vector<int> res = cal_score(t);
    rep(i, D) cout << res[i] << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <vector>
#include <cstdint>

struct Guy {
  int B;
  intmax_t L;
  Guy(int B, intmax_t L): B(B), L(L) {}
};

int testcase_ends() {
  int N;
  scanf("%d", &N);

  if (N == 0)
    return 1;

  std::vector<Guy> guys   ;
  for (int i=0; i<N; ++i) {
    int M;
    intmax_t L;
    scanf("%d %jd", &M, &L);

    int B=0;
    for (int j=0; j<M; ++j) {
      int S, E;
      scanf("%d %d", &S, &E);
      S -= 6;
      E -= 6;
      B |= ((1<<E)-1) ^ ((1<<S)-1);
    }
    guys.emplace_back(B, L);
  }

  // tsurai
  std::vector<intmax_t> dp(1<<16);
  intmax_t res=0;
  for (size_t j=0; j<guys.size(); ++j) {
    for (size_t i=dp.size(); i--;) {
      int next=guys[j].B;
      if (i & next) continue;

      dp[i|next] = std::max(dp[i|next], dp[i]+guys[j].L);
      res = std::max(res, dp[i|next]);
    }
  }

  printf("%jd\n", res);
  return 0;
}

int main() {
  while (true)
    if (testcase_ends())
      return 0;
}

Measured memory_bytes: 3080
#ABC157C　4/16
def main():
    import sys
    N, M = map(int, sys.stdin.readline().split())
    T = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
    #print(T)
    flag = True
    ans = [-1 for _ in range(N)]
    for i in range(M):
        idx = T[i][0]-1
        v = T[i][1]
        if ans[idx] ==-1 or ans[idx] ==v:
            ans[idx] = v
        else:
            flag = False
            break
    #print(ans)
    if len(ans)>=2 and ans[0]==0:
        flag = False
        
    if len(ans)>=2 and ans[0]==-1:
        ans[0]=1
        
    for i in range(N):
        if ans[i] ==-1:
            ans[i] =0
    ans = list(map(str, ans))
    ans = ''.join(ans)
    
    if flag == False:
        print(-1)
    else:
        print(ans)
    
        
if __name__=='__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,W,v[100],w[100];
  cin>>N>>W;
  for(int i=0;i<N;i++)cin>>v[i]>>w[i];
  int dp[101][10001]={};
  for(int i=0;i<N;i++){
    for(int j=0;j<=W;j++){
      dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
      if(j+w[i]<=W)
	dp[i+1][j+w[i]]=max(dp[i][j]+v[i],dp[i+1][j+w[i]]);
    }
  }
  int ans=0;
  for(int i=0;i<=W;i++)ans=max(ans,dp[N][i]);
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 7052
n = int(input())
names = []
for i in range(n):
  names.append(input())
names = [i[0] for i in names]
nm = ["M","A","R","C","H"]
ks = [names.count(nm[i]) for i in range(5)]
ans = 0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans += ks[i] * ks[j] * ks[k]
print(ans)

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> answer;
    for (int i = 1; i <= 7; ++i) {
        for (int j = 1; j <= 8 - i; ++j) {
            for (int k = 1; k <= 9 - j - i; ++k) {
                vector<int> temp;
                for (int l = 0; l < i; ++l) {
                    temp.push_back(3);
                }
                for (int l = 0; l < j; ++l) {
                    temp.push_back(5);
                }
                for (int l = 0; l < k; ++l) {
                    temp.push_back(7);
                }
                int input = 0;
                for (int l = 0; l < temp.size(); ++l) {
                    input += temp[l] * (int)pow(10, temp.size() - l - 1);
                }
                answer.push_back(input);
                while (next_permutation(temp.begin(), temp.end())) {
                    input = 0;
                    for (int l = 0; l < temp.size(); ++l) {
                        input += temp[l] * (int)pow(10, temp.size() - l - 1);
                    }
                    answer.push_back(input);
                }
            }
        }
    }
    sort(answer.begin(), answer.end());
    int N;
    cin >> N;
    for (int i = 0; i < answer.size(); ++i) {
        if (N < answer[i]) {
            cout << i << endl;
            return 0;
        }
    }
    cout << answer.size() << endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>	
#include <cmath>
#include <string>
#include<math.h>
#include<sstream>//���炵���̂Œ���
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;


int main()
{
	cin >> n;
	vector<pair<pair<string, int>, int>> rs(n);
	rep(i, n) {
		cin >> rs[i].first.first >> rs[i].first.second;
		rs[i].first.second *= -1;
		rs[i].second = i+1;
	}
	sort(all(rs));
	rep(i, n)cout << rs[i].second << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
	
int main(){
	IOS
	int a;
	cin >> a;
	int b, c;
	b=pow(a, 2);
	c=pow(a, 3);
	cout << a + b +c << '\n';
}


Measured memory_bytes: 4112
#include<bits/stdc++.h>
using namespace std;
int n,m;

const int N = 10010, M = 100010;
typedef long long ll;
const ll INF = 1e18;
typedef pair<ll,ll> pll;
vector<pll> P;
int all=2,src=1,t=2;
namespace graph{
	int S,T,cnt=1,hed[N],to[M],nxt[M];
	ll cap[M],cost[M];
	inline void adde(int u,int v,ll _fl,ll _c){
		++cnt;to[cnt]=v,nxt[cnt]=hed[u],cap[cnt]=_fl,cost[cnt]=_c;hed[u]=cnt;
		++cnt;to[cnt]=u,nxt[cnt]=hed[v],cap[cnt]=0,cost[cnt]=-_c;hed[v]=cnt;
	}

	queue<int>Q;
	ll d[N];bool vis[N];ll incf[N];
	int pre[N];
	bool spfa(){
		for(int i=min(1,S);i<=max(all,T);i++)d[i]=INF;
		memset(vis,0,sizeof(vis));
		Q.push(S);d[S]=0;vis[S]=1;
		incf[S]=INF;
		while(!Q.empty()){
			// cout << Q.front() << "?" << endl;
			int u=Q.front();vis[u]=false;Q.pop();
			// cout << u << " " << endl;
			for(int i=hed[u];i;i=nxt[i]){
				int v=to[i];
				if(!cap[i])continue;
				if(d[v]>d[u]+cost[i]){
					d[v]=d[u]+cost[i];
					incf[v]=min(incf[u],cap[i]);
					pre[v]=i;
					if(!vis[v])vis[v]=true,Q.push(v);
				}
			}
		}
		if(d[T]==INF)return false;
		return true;
	}
	ll mincost,maxflow;
	void update(){
		int x=T;
		while(x!=S){
			int i=pre[x];
			cap[i]-=incf[T];
			cap[i^1]+=incf[T];
			x=to[i^1];
		}
		maxflow+=incf[T];
		mincost+=d[T]*incf[T];
		P.push_back(pll(d[T],incf[T]));
	}

	void mincost_maxflow(){
		while(spfa()){
			// cout << ":" << endl;
			update();
			// cout << "!" << endl;
			if(P.back().second>(1ll<<50))break;
		}
	}
}

const int NN = 110;
int id[NN][NN], cnt[NN];
int s[NN][NN], p[NN][NN];
ll c[NN][NN];

int main()
{
	cin >> n;
	for(int i=1;i<=n;i++){
		scanf("%d",&cnt[i]);
		for(int j=1;j<=cnt[i];j++){
			scanf("%d%d%lld",&s[i][j],&p[i][j],&c[i][j]);
		}
		for(int j=1;j<=cnt[i];j++)for(int k=j+1;k<=cnt[i];k++){
			if(s[i][j]>s[i][k]){
				swap(s[i][j],s[i][k]),swap(p[i][j],p[i][k]),swap(c[i][j],c[i][k]);
			}
		}
	}
	graph::S=src,graph::T=t;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=cnt[i]-1;j++){
			id[i][j]=++all;
		}
		id[i][0]=src, id[i][cnt[i]]=t;
		for(int j=1;j<=cnt[i];j++){
			graph::adde(id[i][j-1],id[i][j],p[i][j],0);
			graph::adde(id[i][j-1],id[i][j],INF,c[i][j]);
		}
	}cin >> m;
	while(m--){
		int u,v,w;scanf("%d%d%d",&u,&v,&w);
		for(int j=1,k=1;j<=cnt[v];j++){
			for(;k<=cnt[u]&&s[u][k]+w<s[v][j];++k);
			graph::adde(id[v][j-1],id[u][k-1],INF,0);
		}
	}
	// cout << " --- " << endl;
	graph::mincost_maxflow();
	vector<pll> q;
	ll x=0,y=0;
	for(size_t i=0;i<P.size();i++){
		// cout << P[i].first << " " << P[i].second << endl;
		q.push_back(pll(x,y));
		x+=P[i].second,y+=P[i].first*P[i].second;
	}
	cin >> m;
	while(m--){
		ll A;scanf("%lld",&A);
		size_t i=lower_bound(P.begin(),P.end(),pll(A,-INF))-P.begin();
		if(i==P.size())printf("-1\n");
		else printf("%lld\n",q[i].first*A-q[i].second);
	}
}

Measured memory_bytes: 2176
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
long long n,k;
int main()
{
	scanf("%lld%lld",&n,&k);
	if(k*2LL==n)
	{
		printf("%lld",3LL*k);
	}
	else
	{
		long long res=n,x,y;
		if(k<n-k)
		{
			x=k;
			y=n-k-k;
			res+=2*x;
			while(x!=0LL && y!=0LL)
			{
			//	res+=x;
				if(x<y)
				{
					res+=(y-1LL)/x*2LL*x;
					y%=x;
					res+=y*2LL;
					x-=y;
				}
				else
				{
					res+=(x-1LL)/y*2LL*y;
					x%=y;
					res+=x*2LL;
					y-=x;
				}
			}
			res+=x+y;
		}
		else
		{
			x=n-(n-k)-(n-k);
			y=n-k;
			res+=2*y;
			while(x!=0LL && y!=0LL)
			{
			//	res+=y;
				if(x<y)
				{
					res+=(y-1LL)/x*2LL*x;
					y%=x;
					res+=y*2LL;
					x-=y;
				}
				else
				{
					res+=(x-1LL)/y*2LL*y;
					x%=y;
					res+=x*2LL;
					y-=x;
				}
			}
			res+=x+y; 
		}
		printf("%lld",res);
	}
	return 0;
}

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

#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>

int f(int x) {
    int res = 0;
    while (x%2 == 0) {
        x/=2;
        res++;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    int n;
    cin >> n;
    int ans = 0;
    for (int i=1; i<=n; i++) {
        int cur;
        cin >> cur;
        ans += f(cur);
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  cin>>n;
  vin a(n);
  vin ans(n);
  rep(i,0,n) cin>>a[i];
  int c=0;
  rep(i,0,n){
    c=c^a[i];
  }
  //cout<<c<<endl;
 // int v=0;
  rep(i,0,n){
     ans[i]=c^a[i];
  }
 // cout<<v<<endl;
  rep(i,0,n) cout<<ans[i]<<endl;
}

Measured memory_bytes: 4824
package main

import (
        "bufio"
        "fmt"
        "os"
)

func solution(n, m int, t, p, x []int) []int {
        out := make([]int, m)
        for i := 0; i < m; i++ {
                for j, num := range t {
                        if p[i] == j+1 {
                                out[i] += x[i]
                        } else {
                                out[i] += num
                        }
                }
        }
        return out
}

func main() {
        r := bufio.NewReader(os.Stdin)
        var n, m int
        fmt.Fscan(r, &n)
        t := make([]int, n)
        for i := range t {
                fmt.Fscan(r, &t[i])
        }
        fmt.Fscan(r, &m)
        p := make([]int, m)
        x := make([]int, m)
        for i := 0; i < m; i++ {
                fmt.Fscan(r, &p[i], &x[i])
        }
        for _, num := range solution(n, m, t, p, x) {
                fmt.Println(num)
        }
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		char[] S = sc.next().toCharArray();
		char[] T = sc.next().toCharArray();
		int N = S.length;
		int M = T.length;
		int[][] dp = new int[N + 1][M + 1];
		for (int i = 0; i <= N; i++) {
			for (int j = 0; j <= M; j++) {
				if (i < N && j < M && S[i] == T[j]) {
					dp[i + 1][j + 1] = Math.max(dp[i + 1][j + 1], dp[i][j] + 1);
				}
				if (i < N) dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j]);
				if (j < M) dp[i][j + 1] = Math.max(dp[i][j + 1], dp[i][j]);
			}
		}
		StringBuilder sb = new StringBuilder();
		int i = N;
		int j = M;
		while (i > 0 && j > 0) {
			if (S[i - 1] == T[j - 1]) {
				sb.append(S[i - 1]);
				--i;
				--j;
				continue;
			}
			if (dp[i - 1][j] == dp[i][j]) {
				--i;
				continue;
			}
			if (dp[i][j - 1] == dp[i][j]) {
				--j;
				continue;
			}
		}
		System.out.println(sb.reverse());
	}

}

Measured memory_bytes: 83148
#include <iostream>
using namespace std;
int main(void){
    int k,s,x,y,z;
    int ans=0;
    cin >>k >>s;
    for(x=0;x<=k;x++){
        for(y=0;y<=k;y++){
            z=s-x-y;
            if(z>=0 && z<=k)
            ans++;
            
        }
    }
    cout <<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int H, W;
    cin >> H >> W;
    
    char a[H][W];
    bool yoko[H];
    bool tate[H];

    REP(i, H) {
        REP(j, W) {
            cin >> a[i][j];
        }
    }

    REP(i, H) {
        bool tmp = false;
        REP(j, W) {
            if (a[i][j] == '#') 
                tmp = true;
        }
        yoko[i] = tmp;
    }
    REP(i, W) {
        bool tmp = false;
        REP(j, H) {
            if (a[j][i] == '#') 
                tmp = true;
        }
        tate[i] = tmp;
    }
    
    REP(i, H) {
        REP(j, W) {
            if (yoko[i] && tate[j])
            cout << a[i][j];
        }
        cout << endl;
    }





    return 0;
}

Measured memory_bytes: 256
# N
# a1 b1 c1
# aN bN cN
# 連続してA,B,Cを行えない．
# max

N = gets.to_i
a, b, c = N.times.map{gets.split.map(&:to_i)}.transpose

dp_a = [0]
dp_b = [0]
dp_c = [0]

N.times do |i|
  dp_a[i + 1] = a[i] + [dp_b[i], dp_c[i]].max
  dp_b[i + 1] = b[i] + [dp_c[i], dp_a[i]].max
  dp_c[i + 1] = c[i] + [dp_a[i], dp_b[i]].max
end
puts [dp_a[N], dp_b[N], dp_c[N]].max

Measured memory_bytes: 14428
#include <cmath>
#include <cstdio>

#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
typedef long long int ll;

int main() {
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  ll ans;
  if(n-m/2>=0)
    ans = m/2;
  else
    ans = n + (m-2*n)/4;

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main()
{
    long N,i;
    scanf("%ld",&N);
    for(i=(long)sqrt(N);i>0;i--) if(N%i==0) break;
    printf("%d\n",(int)log10(N/i)+1);
    return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;
int a,b,c,d,e,k;
int main()
{
    cin>>a;
    cin>>b;
    cin>>c;
    cin>>d;
    cin>>e;
    cin>>k;
    if((b-a<=k)&&(c-a<=k)&&(d-a<=k)&&(e-a<=k)&&(c-b<=k)&&(d-b<=k)&&(e-b<=k)&&(d-c<=k)&&(e-c<=k)&&(e-d<=k))
        cout<<"Yay!";
    else
        cout<<":(";


    return 0;
}

Measured memory_bytes: 256
import collections
n = int(input())
l = list(int(x) for x in input().split())
el = []
ol = []
for i in range(n):
  if i % 2 == 0:
    el.append(l[i])
  else:
    ol.append(l[i])
if len(set(el + ol)) == 1:
  print(int(len(l)/2))
  exit()
e1 = collections.Counter(el).most_common()[0][0]
o1 = collections.Counter(ol).most_common()[0][0]
cnt1 = 0
cnt2 = 0
if e1 != o1:
  print(len(el) - collections.Counter(el).most_common()[0][1] + len(ol) - collections.Counter(ol).most_common()[0][1])
else:
  print(min(len(el)-collections.Counter(el).most_common()[0][1]+len(ol)-collections.Counter(ol).most_common()[1][1],len(el)-collections.Counter(el).most_common()[1][1]+len(ol)-collections.Counter(ol).most_common()[0][1]))


Measured memory_bytes: 17548
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
void checkpoint1()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif*/
}
int main()
{
	checkpoint1();
	ll n,k;
	cin>>n>>k;
	ll a[n];
	for(ll i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	ll ans=0;
	for(ll i=0;i<k;i++)
		ans+=a[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3648
S=input()
counter=0
if len(S)%2==0:
    for i in range(int(len(S)/2)):
        if S[i]!=S[-i-1]:
            counter+=1
else:
    for i in range(int((len(S)-1)/2)):
        if S[i]!=S[-i-1]:
            counter+=1
print(counter)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int maxN = 1e2+2;
const int maxV = 1e5+5;
const long long oo = 1e15;
typedef long long ll;
int N, W;
int v[maxN], w[maxN];
ll f[maxN][maxV];
int main() {
    cin >> N >> W;
    for(int i = 1; i <= N; ++i)
        cin >> w[i] >> v[i];
    ll ans = 0;
    for(int i = 0; i <= N; ++i)
        for(int j = 0; j < maxV; ++j) f[i][j] = oo;
    f[0][0] = 0;
    for(int i = 1; i <= N; ++i)
        for(int j = 0; j<maxV; ++j) {
            f[i][j] = f[i-1][j];
            if (j - v[i] >= 0 && f[i-1][j-v[i]] != oo) {
                //cout << i << " " << f[i][j] << endl;
                f[i][j] = min(f[i][j], f[i-1][j-v[i]]+w[i]);
            }
        }
    //cout << f[1][1] << endl;
    for(int i = maxV-1; i >= 0; --i)
    if (f[N][i] <= W) {
        ans = i;
        break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 79104
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define endl '\n'

const int max4 = 10004;
const int maxx = 100005;
const int max6 = 1000006;
const int lg5 = 17;

const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;

/***************/

int powmod (int a, int b, int mod) {
    int res = 1; a %= mod;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
    }
    return res;
}
#define ll long long
ll gcd (ll a, ll b) {
    while (b > 0) {
        ll t = a % b;
        a = b, b = t;
    }
    return a;
}

int lcm (int a, int b) {
    return (a / gcd (a, b)) * b;
}

int is_prime (int n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/******Don't forget to use long long when needed!!******/

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    string s;
    int x, y;
    cin >> x >> y;
    int res = INF;
    if (y >= x) {
        res = min(res, y - x);
    }
    if (y >= -x) {
        res = min(res, y - -x + 1);
    }
    if (-y >= x) {
        res = min(res, -y - x + 1);
    }
    if (-y >= -x) {
        res = min(res, -y - -x + 2);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
def nCr(n, r):
    import math
    # nCrのr>nは組み合わせが存在しないので0を返す
    # raiseすべきのこともあるかも
    if r > n:
        return 0
    return math.factorial(n) // ((math.factorial(n - r) * math.factorial(r)))

memo = [-1] * 300000
memo2 = [-1] * 300000
memo3 = [-1] * 300000

n = int(input())
dat = list(map(int, input().split()))
from collections import Counter
c = Counter(dat)
total = 0
#print(c)
for k in c:
    if c[k] > 1:
        memo[k] = nCr(c[k], 2)
        memo2[k] = nCr(c[k]-1, 2)
        memo3[k] = memo[k] - memo2[k]
        total += memo[k]
#print(memo[:10])
#print(memo2[:10])
#print(memo3[:10])
#print(total)
for i in range(n):
    if memo3[dat[i]] == -1:
        print(total)
    else:
        print(total - memo3[dat[i]])


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

using namespace std;
typedef long long ll;

int main () {
    int N; cin >> N;
    vector<double> x(N);
    vector<string> u(N);
    for (int i = 0; i < N; ++i) {
        cin >> x[i] >> u[i];
    }

    int sumJPY = 0;
    double sumBTC = 0;
    for (int i = 0; i < N; ++i) {
        if (u[i] == "JPY") sumJPY += x[i];
        else sumBTC += x[i];
    }

    cout << sumJPY + sumBTC * 380000 << endl;

}



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

int main() {
	int a, b, c, d, e;
	e = 0;
	cin >> a;
	b = a / 100;
	c = (a / 10) - (b * 10);
	d = a - (a / 10) * 10;
	if (b == 1) {
		e += 1;
	}
	if (c
		== 1) {
		e += 1;
	}
	if (d== 1) {
		e += 1;
	}
	cout << e << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    string s;
    cin >> s;
    REP(i,5){
        cout << s[i];
    }
    cout << " ";
    REP(i,7){
        cout << s[i + 6];
    }
    cout << " ";
    REP(i,5){
        cout << s[i + 14];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n, m; cin >> n >> m;
    map<int, int> mp;
    rep(i, m) {
        mp[i] = 0;
    }
    rep(i, n) {
        int k; cin >> k;
        rep(j, k) {
            int a; cin >> a;
            mp[a]++;
        }
    }
    int ans = 0;
    for (auto x : mp) {
        if (x.second == n) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

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

    int a[11000];

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

    if(ans>=0) cout << ans << endl;
    else cout << "-1" << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    ll n, m;
    cin >> n >> m;

    ll x[n], y[m];
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];

    ll sx = 0, sy = 0;
    repr(i, 1, n-1){
        sx += (ll) i * (n-i) * (x[i]-x[i-1]);
        sx %= MOD;
    }

    repr(i, 1, m-1){
        sy += (ll) i * (m-i) * (y[i]-y[i-1]);
        sy %= MOD;
    }

    cout << (sx * sy)%MOD << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 1792
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int N;
std::vector<vector<int> > G;
std::vector<int> parent;
std::vector<int> depth;
std::vector<int> type;

void dfs(int i, int d) {
    depth[i] = d;
    for (int j = 0; j < G[i].size(); j++) {
        parent[G[i][j]] = i;
        dfs(G[i][j], d + 1);
    }
    if (G[i].size() == 0) {
        type[i] = 0;
    } else {
        type[i] = 1;
    }
}

int main() {

    cin >> N;
    for (int i = 0; i < N; i++) {
        G.push_back(vector<int>());
        parent.push_back(-1);
        depth.push_back(0);
        type.push_back(0);
    }
    std::vector<int> notroot(N, 0);
    for (int i = 0; i < N; i++) {
        int id, k;
        cin >> id >> k;
        for (int j = 0; j < k; j++) {
            int child;
            cin >> child;
            notroot[child] = 1;
            G[id].push_back(child);
        }
    }
    
    int root;
    for (int i = 0; i < N; i++) {
        if (notroot[i] == 0) {
            root = i;
            break;
        }
    }
    dfs(root, 0);

    for (int i = 0; i < N; i++) {
        cout << "node " << i << ": ";
        cout << "parent = " << parent[i] << ", ";
        cout << "depth = " << depth[i] << ", ";
        
        if (depth[i] == 0) {
            cout << "root, ";
        } else {
            if (type[i] == 0) {
                cout << "leaf, ";
            } else {
                cout << "internal node, ";
            }
        }
        cout << "[";
        for (int j = 0; j < G[i].size(); j++) {
            cout << G[i][j];
            if (j != G[i].size() - 1) {
                cout << ", ";
            }
        }
        cout << "]" << endl;
    }

    return 0;
}

Measured memory_bytes: 6092
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>

using namespace std;
#define vsort(v) sort(v.begin(), v.end()); // 昇順
#define vsort_reverse(v) sort(v.begin(), v.end(), greater<int>()); // 降順
#define bsearch(v, n) binary_search(v.begin(), v.end(), n) 
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N, L;
	cin >> N >> L;
	vector<string> S;
	for(int i = 0; i < N; i++) {
		string buffer;
		cin >> buffer;
		S.push_back(buffer);
	}
	vsort(S);
	for(int i = 0; i < S.size(); i++) cout << S[i];
	cout << endl;
}


Measured memory_bytes: 256
N,M = readline.strip.split().map(&:to_i)
bridges = readlines.map(&:strip).map {|bridge| bridge.split.map(&:to_i) }
islands_with_bridge = bridges.flatten.uniq

result = 'IMPOSSIBLE'
counts = []
bridges.each do |bridge|
  index = 
    if bridge[0]==1
      bridge[1]
    elsif bridge[1]==N
      bridge[0]
    end
  next if index.nil?

  counts[index] ||= 0
  counts[index]+=1
  if counts[index]==2
    puts 'POSSIBLE'
    exit
  end
end

puts result

#p N
#p M
#p bridges


Measured memory_bytes: 64764
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int h[N];
typedef long long ll;

int main()
{
    ll n,k;
    cin>>n>>k;
    for(int i=0;i<n;++i)
        cin>>h[i];
    sort(h,h+n,greater<int>());
    ll ans=0;
    for(int i=k;i<n;++i)
        ans+=h[i];
    cout<<ans;
    return 0;
}
/*

*/

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){

	int k,n;
	cin>>k>>n;
	int a[n];
	int b=0;
	int ans=0;

	for(int i=0;i<n;i++){
	
		cin>>a[i];
	}
	for(int i=1;i<n;i++){
	
		ans+=a[i]-a[i-1];
		if(a[i]-a[i-1]>=b){
		
			b=a[i]-a[i-1];
		}
	}
	if(k-a[n-1]+a[0]>b){
	
		cout<<ans;
		return 0;
	}
	ans+=k-a[n-1]+a[0];
	ans-=b;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 4384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int X=(A+D-1)/D;
  int Y=(C+B-1)/B;
  if(X>=Y){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
   int N, a, b, c;
   cin >> N;
   a = N / 100;
   b = (N - 100 * a) /10;
   c = N - 100 * a - 10 * b;
   cout << a + b + c << endl;
}

Measured memory_bytes: 3620
/*
 * d.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int w, h, x, y, r;
  cin >> w >> h >> x >> y >> r;

  bool ok = (x - r >= 0 && x + r <= w && y - r >= 0 && y + r <= h);
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}

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

class Main {

	static int moves(int die, int limit)
	{
		int cnt = 0;
		if(die>=limit) return 0;
		
		while(die < limit)
		{
			cnt++;
			die = 2*die;
		}
		return cnt;
	}
	public static void main(String[] args) {
		
		FastScanner s = new FastScanner();
		int a = s.nextInt();
		int b = s.nextInt();
		int ans = 0;
		
		if(a>=13) ans = b;
		else if(a>=6&& a<=12) ans = b/2;
		else ans = 0;
		
		
		System.out.println(ans);
		
	}

static   class FastScanner {
		
	    private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner() {
			this(System.in);
		}

		public FastScanner(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		
		}	

	}

}


Measured memory_bytes: 20692
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 02:04:12 2020

@author: liang
"""
import math

N = int(input())
d = list()
for i in range(N):
    x, y = map(int,input().split())
    d.append((x,y))
#print(d)
lis = list(range(N))
num = list()
perm_list = list()

def make_perm():
    if len(num) == N:
        perm_list.append(num.copy())
    for n in lis:
        a = lis.pop(0)
        num.append(a)
        make_perm()
        num.pop()
        lis.append(a)
        
make_perm()
#print(len(perm_list))
res = 0
for nums in perm_list:
    tmp = 0
    for i in range(N-1):
        tmp += math.sqrt((d[nums[i]][0]-d[nums[i+1]][0])**2 + (d[nums[i]][1] - d[nums[i+1]][1])**2)
    res += tmp
print(res/len(perm_list))

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

typedef long long ll;
const int maxn = 200005, maxm = 200005;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

#define pb push_back

int n, m, d[maxn];

struct edge
{
	int to, next;
} e[maxm * 2];
int h[maxn], tot = 1;
int w[maxm], col[maxn], fa[maxn], fe[maxn];
vector<int> vec[maxn];

inline void add(int u, int v)
{
	e[++tot] = (edge) {v, h[u]}; h[u] = tot;
	e[++tot] = (edge) {u, h[v]}; h[v] = tot;
}

void dfs(int u)
{
	for (int v : vec[u]) {
		if (col[v] == -1) col[v] = col[u] ^ 1, dfs(v);
	}
}

int main()
{
	n = gi(); m = gi();
	for (int i = 1; i <= n; ++i) d[i] = gi();
	for (int i = 1; i <= m; ++i) add(gi(), gi());
	fill(w + 1, w + m + 1, 1e9);

	d[0] = 2e9;
	for (int u = 1; u <= n; ++u) {
		int p = h[u] >> 1, mn = e[h[u]].to;
		for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
			if (d[v] < d[mn] || (d[v] == d[mn] && v < mn)) mn = v, p = i >> 1;
		if (d[mn] > d[u]) return puts("-1"), 0;
		w[p]=d[u];fa[u] = mn; vec[mn].pb(u);
	}
	
	fill(col + 1, col + n + 1, -1);
	for (int i = 1; i <= n; ++i) if (fa[fa[i]] == i && col[i] == -1) col[i] = 0, dfs(i); 
	for (int i = 1; i <= n; ++i) putchar(col[i] == 0 ? 'B' : 'W');
	puts("");
	for (int i = 1; i <= m; ++i) printf("%d\n", w[i]);
	
	return 0;
}


Measured memory_bytes: 16896
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,k;
vi a;

int main(){
	cin>>n>>k;
	a=vi(n);
	int t=inf;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a.begin(),a.end());
	for(int i=0;i<n;i++) if(i+k-1<n) t=min(t,a[i+k-1]-a[i]);
	cout<<t<<endl;
}

Measured memory_bytes: 640
def dfs(s):
  res=0
  if s!="":
    if int(s)>n:
      return res
  if (s.count('7')>=1 and s.count('5')>=1 and s.count('3')>=1):res=1
  for c in "357":
    res+=dfs(s+c)
  return res

n=int(input())
print(dfs(''))

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

int sign(int x) {
	return (x > 0) - (x < 0);
}

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

	int n; std::cin >> n;
	int ans = 0, t = 0, last = -1;
	for (int i = 0; i < n; ++ i) {
		int x; std::cin >> x;
		if (!i || (sign(x - last) * t == -1)) {
			++ ans; t = 0;
		}
		else if (!t && sign(x - last)) {
			t = sign(x - last);
		}
		last = x;
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<array>
#include<functional>
#include<iomanip>
#include<ios>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)

typedef int value_type; /* ソートするキーの型 */

value_type med3(value_type x, value_type y, value_type z)
/* x, y, z の中間値を返す */
{
    if (x < y)
        if (y < z) return y; else if (z < x) return x; else return z; else
        if (z < y) return y; else if (x < z) return x; else return z;
}
int gcd(int a, int b) {
  if(a < b) return gcd(b, a);
  int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
void quicksort(value_type a[], int left, int right,value_type index[])
/* クイックソート
 * a     : ソートする配列 
 * left  : ソートするデータの開始位置
 * right : ソートするデータの終了位置
 * index: index配列
 */
{
    if (left < right) {
        int i = left, j = right;
        value_type tmp, pivot = med3(a[i], a[i + (j - i) / 2], a[j]); /* (i+j)/2ではオーバーフローしてしまう */
        while (1) { /* a[] を pivot 以上と以下の集まりに分割する */
            while (a[i] < pivot) i++; /* a[i] >= pivot となる位置を検索 */
            while (pivot < a[j]) j--; /* a[j] <= pivot となる位置を検索 */
            if (i >= j) break;
            tmp = a[i]; a[i] = a[j]; a[j] = tmp; /* a[i],a[j] を交換 */
            tmp = index[i]; index[i] = index[j]; index[j] = tmp;
            i++; j--;
        }
        quicksort(a, left, i - 1,index);  /* 分割した左を再帰的にソート */
        quicksort(a, j + 1, right,index); /* 分割した右を再帰的にソート */
    }
}


int dfs(int n,int N){
    if (n>N){
        return 0;
    }
    

    int ret;
    
    return ret;
}

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

    long long A[N];
    long long absA[N];
    int sumb=0;
    long long sum=0;
    long long min=pow(10,9);
    long long ans;
    FOR(i,N){
        cin>>A[i];
        absA[i]=abs(A[i]);
        if(A[i]<0){
            sumb++;
        }
        if(min>absA[i]){
            min=absA[i];
        }
        sum+=absA[i];

    }
    if(sumb%2==0){
        ans=sum;
    }else{
        ans=sum-2*min;
    }

    cout <<ans<<endl;

    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll a[100010];
ll b[100010];
int main(){
	ll n;
	scanf("%lld",&n);
	rep(i,0,n)scanf("%lld",a+i);
	rep(i,0,n)scanf("%lld",b+i);
	rep(i,0,n)a[i]-=b[i];
	sortup(a,n);
	ll s=0,ans=0;
	rep(i,0,n)if(a[i]<0)s+=a[i],ans++;
	for(int i=n-1;i>=0;i--)if(a[i]>0&&s<0)s+=a[i],ans++;
	printf("%lld\n",s>=0?ans:-1);
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i<N; i++) cin >> A.at(i);
  for (int i = 0; i<N; i++) {
    if (A.at(i)%2 == 0 && A.at(i)%3 != 0 && A.at(i)%5 != 0) {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
}

Measured memory_bytes: 256