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

template <typename D, typename T = D>
class Tree
{
public:
	Tree( long long int size = 0, D InitialValueArg = D() ) {
		long long int n = 1LL;
		CalcTree.emplace_back( vector<T>( n ) );
		while( n <= size ) {
			n <<= 1LL;
			addOneLine( n );
		}
		InitialValue = InitialValueArg;
		Data.resize( n, InitialValue );
		for( size_t i = 0; i < Data.size(); i++ ) {
			update( i, Data[i] );
		}
		MaxSize = n;
		NowIndex = 0LL;
	}

	virtual T preprocessing( D a ) {
		return T( a );
	}

	virtual T treeupdate( T a, T b ) {
		return a;
	}

	void update( long long int idx, D data ) {
		Data[idx] = data;
		(*(CalcTree.rbegin()))[idx] = preprocessing( data );
		for( auto ite = CalcTree.rbegin(); ite + 1 < CalcTree.rend(); ) {
			idx >>= 1LL;
			T updatedata = treeupdate( (*ite)[idx * 2], (*ite)[idx * 2 + 1] );
			ite++;
			if( (*ite)[idx] != updatedata ) {
				(*ite)[idx] = updatedata;
			} else {
				break;
			}
		}
	}

	void show() {
		for( auto x : CalcTree ) {
			for( auto y : x ) {
				cout << y << " ";
			}
			cout << endl;
		}
	}

	void push( D data ) {
		if( NowIndex == MaxSize ) {
			MaxSize <<= 1LL;
			addOneLine( MaxSize );
			vector<D>Datamemo( MaxSize, InitialValue );
			copy( Data.begin(), Data.end(), Datamemo.begin() );
			for( long long int i = 0; i < Datamemo.size(); i++ ) {
				update( i, Datamemo[i] );
			}
		}
		Data[NowIndex] = data;
		update( NowIndex, data );
		NowIndex++;
	}

	T range( long long int l, long long int r ) {
		return rangeProcessing( 0, l, r, 0, 0, MaxSize );
	}

	long long int t() {
		return 10;
	}

private:
	vector<vector<T>> CalcTree;
	vector<D> Data;
	long long int MaxSize;
	long long int NowIndex;
	D InitialValue;

	void addOneLine( long long int n ) {
		CalcTree.emplace_back( vector<T>( n ) );
	}

	T rangeProcessing( long long int d, long long int a, long long int b, long long int k, long long int l, long long int r ) {
		if( !(r <= a || b <= l) && d < CalcTree.size() ) {
			if( a <= l&&r <= b ) {
				return CalcTree[d][k];
			} else {
				return treeupdate( rangeProcessing( d + 1, a, b, k * 2, l, (l + r) / 2 ), rangeProcessing( d + 1, a, b, k * 2 + 1, (l + r) / 2, r ) );
			}
		}
		return InitialValue;
	}
};

class RMQ : public Tree<long long int>
{
public:
	RMQ( long long int a, long long int b ) :Tree( a, b ) {

	}
	long long int treeupdate( long long int a, long long int b ) {
		return max( a, b );
	}
};

int main() {
	long long int N;
	cin >> N;
	vector<long long int >data( N );
	RMQ rmq( N + 1, LLONG_MIN );
	long long int sum = 0;
	for( size_t i = 0; i < N; i++ ) {
		cin >> data[i];
		sum += data[i];
	}
	vector<long long int>dp( N + 1, LLONG_MIN );
	dp[0] = 0;
	rmq.update( 0, 0 );
	long long int maxnum = 0;
	for( size_t i = 0; i < N; i++ ) {
		dp[data[i]] = rmq.range( 0, data[i] ) + data[i];
		rmq.update( data[i], dp[data[i]] );
	}
	for( size_t i = 0; i < N + 1; i++ ) {
		maxnum = max( maxnum, dp[i] );
	}
	cout << sum - maxnum << endl;
}

Measured memory_bytes: 7600
#include <bits/stdc++.h>
#define FOR(i, n) for(ll i = 0; i < n; i++)
#define FORR(i, n) for(ll i = n; i >= 0; i--)
#define FORS(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) accumulate(v.begin(),v.end(),0)
#define SORT(v) sort(v.begin(),v.end())
#define OUT(n) (cout << n << endl)
#define IN1(a) (cin >> a)
#define IN2(a,b) (cin >> a >> b)
#define IN3(a,b,c) (cin >> a >> b >> c)
#define IN4(a,b,c,d) (cin >> a >> b >> c >> d)
using namespace std;
typedef long long ll;

int main(){
  ll n;
  string one,two;
  IN1(n);
  vector<string>a_array(n);
  FOR(i,n){
    cin >> one;
    sort(one.begin(),one.end());
    a_array[i] = one;
  }
  ll ans = 0;
  map<string,int>count;
  FOR(i,n){
    ans += count[a_array[i]]++;
  }
  OUT(ans);
}

Measured memory_bytes: 12032
/*suri_kumkaran*/

#include <bits/stdc++.h>

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long

typedef long long int64;
typedef vector<int> VI64;
typedef vector<pair<int,int>> VII64;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;


int64 ME(int64 a,int64 b,int64 m)
{
    int64 mul=a,ans=1;
    while(b)
    {
      if(b&1)
      {
        ans*=mul;
        ans%=m;
      }
      mul*=mul;
      mul%=m;
      b/=2;
    }
    return ans%m;
}


int32_t main()
{
	IOS;
	int T=1;
	//cin>>T;
	while(T--)
	{
		int n,k,i,j;
		cin>>n>>k;
		int ans[k]={0};
		int pr=0;
		for(i=k;i>=1;i--)
		{
			int div=k/i;
			ans[i]=ME(div,n,MOD);
			for(j=2*i;j<=k;j+=i)
			{
				ans[i]-=ans[j];
				ans[i]+=MOD;
				ans[i]%=MOD;
			}
			pr+=(ans[i]*i)%MOD;
			pr%=MOD;
		}
		cout<<pr<<endl;
	}

	return 0;
}

Measured memory_bytes: 4364
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

int f(int m, int d) {
	int d1 = d / 10;
	int d2 = d % 10;

	if (d1 >= 2 and d2 >= 2 and d1*d2 == m) {
		return 1;
	}
	else return 0;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int m, d;
	cin >> m >> d;

	int ans = 0;
	rep(i, 1, m + 1) {
		rep(j, 1, d + 1) {
			ans += f(i, j);
		}
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#define M 100000
#define MAX 1000000001
#define MIN -100000000
#define mod 998244353 
#define ss second
#define ff first
#define ll long long int
#define pb push_back
#define ld double
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

int main(){
	fast;
	int h,w,k;
	cin>>h>>w>>k;
	int x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	string s[h+1];
	for(int i=1;i<=h;i++)
		cin>>s[i];
	int dp[h+1][w+1];
	memset(dp,-1,sizeof(dp));
	queue<pair<int,int>>q;
	q.push({x1,y1});
	dp[x1][y1] = 0;
	while(q.empty() == false){
		pair<int,int>current = q.front();
		// cout<<current.ff<<" sddj "<<current.ss<<endl;
		for(int i=1;i<=k;i++){
			if(current.ff + i<=h && dp[current.ff+i][current.ss] == -1){
				if(s[current.ff+i][current.ss-1] == '.'){
					q.push({current.ff+i,current.ss});
					dp[current.ff+i][current.ss] = dp[current.ff][current.ss]+1;
				}
				else{
					break;
				}
			}
			else if(current.ff + i<=h && dp[current.ff+i][current.ss] <= dp[current.ff][current.ss])
				break;
		}
		for(int i=1;i<=k;i++){
			if(current.ff -i>0 && dp[current.ff-i][current.ss] == -1){
				if(s[current.ff-i][current.ss-1] == '.'){
					q.push({current.ff-i,current.ss});
					dp[current.ff-i][current.ss] = dp[current.ff][current.ss]+1;
				}
				else{
					break;
				}
			}
			else if(current.ff -i>0 && dp[current.ff-i][current.ss] <= dp[current.ff][current.ss])
				break;
		}

		for(int i=1;i<=k;i++){
			if(current.ss + i<=w && dp[current.ff][current.ss+i] == -1){
				if(s[current.ff][current.ss+i-1] == '.'){
					q.push({current.ff,current.ss+i});
					// cout<<current.ff<<" "<<(current.ss+i)<<"\n";
					dp[current.ff][current.ss+i] = dp[current.ff][current.ss]+1;
				}
				else{
					break;
				}
			}
			else if(current.ss + i<=w && dp[current.ff][current.ss+i] <= dp[current.ff][current.ss])
				break;
		}
		for(int i=1;i<=k;i++){
			if(current.ss -i>0 && dp[current.ff][current.ss-i] == -1){
				if(s[current.ff][current.ss-i-1] == '.'){
					q.push({current.ff,current.ss-i});
					dp[current.ff][current.ss-i] = dp[current.ff][current.ss]+1;
				}
				else{
					break;
				}
			}
			else if(current.ss -i>0 && dp[current.ff][current.ss-i] <= dp[current.ff][current.ss])
				break;
		}
		q.pop();
	}
	// for(int i=1;i<=h;i++){
	// 	for(int j=1;j<=w;j++)
	// 		cout<<dp[i][j]<<" ";
	// 	cout<<endl;
	// }
	cout<<dp[x2][y2]<<"\n";

	return 0;
}

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

int mygcd(int a, int b){
    if(a < b){
        int t = a; a = b; b = t;
    }
    while(b != 0){
        int r = a%b;
        a = b;
        b = r;
    }
    return a;
}

int main(){
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s;
    cin >> t;

    long long int ans = mygcd(n, m);
    ans *= n/mygcd(n, m);
    ans *= m/mygcd(n, m);

    long long int n1 = ans/n, m1 = ans/m;
    for(long long int i = 0; i*n1 < ans; i++){
        if(n1*i % m1 != 0) continue;
        long long int ind = (n1*i)/m1;
        if(s[i] != t[ind]) ans = -1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3764
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int a[SIZE];
int main(){
    int N; R(N);
    REP(i,N){
        R(a[i]);
    }
    sort(a,a+N);
    int an=0;
    REPP(i,1,N){
        int it=0;
        REPP(j,i+1,N){
            while(it<i&&a[it]+a[i]<=a[j])it++;
            an+=i-it;
        }
    }
    W(an);
    return 0;
}


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

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

int main(){
    string s,t;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            t+=s[i];
        }
    }
    cout<<t<<endl;
    return 0;
}

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


int main(){
   int n; cin>>n;
   map<string,int> mp;
   rep(i,n){
      string s;
      cin>>s;
      mp[s]++;
   }
   int mx=0;
   //辞書順になっているので数が大きいものから出力する
   for(auto p:mp) mx=max(mx,p.second);
   for(auto p:mp){
      if(p.second!=mx) continue;
      cout<<p.first<<endl;
   }
   return 0;
}

   


Measured memory_bytes: 25216
//https://atcoder.jp/contests/abc070/tasks/abc070_d
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

template< typename T >
struct edge {
	int src, to;
	T cost;
	edge(int _to, T _cost) : src(-1), to(_to), cost(_cost) {}
	edge(int _src, int _to, T _cost) : src(_src), to(_to), cost(_cost) {}
	edge &operator=(const int &x) {
		to = x;
		return *this;
	}
	operator int() const { return to; }
};

template< typename T>
struct node {
	vector<edge<T>> edges;
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< node< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(const WeightedGraph< T > &g, int s, vector<int>& prev) {
	const auto INF = numeric_limits<T>::max();
	vector<T> dist(g.size(), INF);
	prev.assign(g.size(),-1);

	using Pi = pair<T, int>; //dist,node id
	priority_queue<Pi, vector<Pi>, greater<Pi>> que;
	dist[s] = 0;
	que.emplace(dist[s], s);
	while(!que.empty()) {
		T cost;
		int idx; //node id
		tie(cost, idx) = que.top();
		que.pop();
		if(dist[idx] < cost)
			continue;
		for(auto &e : g[idx].edges) {
			auto next_cost = cost + e.cost;
			if(dist[e.to] <= next_cost)
				continue;
			dist[e.to] = next_cost;
			prev[e.to] = idx;
			que.emplace(dist[e.to], e.to);
		}
	}
	return dist;
}

int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N; cin>>N;
    WeightedGraph<ll> graph(N+1);
     REP(i,N-1){
        int a,b; ll c; cin>>a>>b>>c;
        graph.at(a).edges.emplace_back(a,b,c);
        graph.at(b).edges.emplace_back(b,a,c);
    }    
    ll Q,K; cin>>Q>>K;
    vector<pair<int,int>> xyq(Q);
    for(auto&& xy:xyq){
        cin>>xy.first>>xy.second;
    }

    vector<int> prev;
    auto result = dijkstra(graph, K, prev);
    for(const auto& xy:xyq){
        ll ans = result.at(xy.first) + result.at(xy.second);
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 12272
// AOJ 0120: Patisserie
// 2017.8.21 bal4u@uu
// 2017.11.20

#include <stdio.h>
#include <string.h>
#include <math.h>

#define INF 1000
int r[13], n, lim;
double d[13][13];					// ???????????±???????????????????°´????????¢
double dp[4100][13];
char buf[50], *p;

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

double rec(int b, int k)
{
	int i, ii;
	double ans, x;

	if (dp[b][k] >= 0) return dp[b][k];
	if (b == lim) ans = r[k];
	else {
		ans = INF;
		for (ii = 1, i = 0; i < n; i++, ii<<=1) {
			if (b & ii) continue;
			x = rec(b | ii, i) + d[r[k]][r[i]];
			if (x < ans) ans = x;
		}
	}
	return dp[b][k] = ans;
}

int main()
{
	int w, i, j;
	double ans, x;

	for (i = 3; i <= 10; i++) {
		int jj;
		for (jj = i*i, j = i; j <= 10; j++, jj+= i)
		d[i][j] = d[j][i] = 2 * sqrt(jj);
	}

	while (fgets(p=buf, 50, stdin) != NULL) {
		w = getint(); p++;
		n = 0, j = 0;
		while (*p >= ' ') {	i = getint(), p++, r[n++] = i, j += i; }
		if (2 * j <= w) { puts("OK"); continue; }
		lim = (1 << n) - 1;
		ans = INF;
		for (i = 0; i < n; i++) {
			memset(dp, -0x33, sizeof(dp));
			x = rec(1<<i, i) + r[i];
			if (x < ans) ans = x;
		}
		puts(ans <= w ? "OK" : "NA");
	}
	return 0;
}

Measured memory_bytes: 1980
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  ll m = 1;
  map<string, ll> mp;
  rep(i, n) {
    string x;
    cin >> x;
    if (mp.find(x) != mp.end()) {
      mp[x]++;
      m = max(m, mp[x]);
    } else {
      mp[x] = 1;
    }
  }
  for(auto it = mp.begin(); it != mp.end(); it++) {
    if (it->second == m) {
      cout << it->first << endl;
    }
    
  }

  return 0;
}

Measured memory_bytes: 19232
int main(){
  int a,b,c=0;
  scanf("%d%d",&a,&b);
  if(a==1&&b==1)c=400000;
  if(a==1)c+=300000;
  if(a==2)c+=200000;
  if(a==3)c+=100000;
  if(b==1)c+=300000;
  if(b==2)c+=200000;
  if(b==3)c+=100000;
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 128
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

X=gets.to_i
dp=array(X+1,false)
dp[0]=true
products=[100,101,102,103,104,105]
(X-100+1).times do|i|
    products.each do|p|
        break if i+p>X
        dp[i+p]=true if dp[i]
    end
end
puts yn_judge(dp[X],1,0)

Measured memory_bytes: 2556
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 

/*ここから*/
int V;//頂点の個数
vector<int> e[200010];//iから出る辺
int t[200010];//親情報の記録媒体

//すでにある辺と頂点の情報から木の作成
void Tree(int s){//sは一番根元
    for(int i=1;i<=V;i++){
        t[i]=i;//初期情報
    }
    queue <int> q;
    q.push(s);
    while(!q.empty()){
        int from;
        from=q.front();
        q.pop();
        while(!e[from].empty()){
            int to;
            to=e[from].back();
            e[from].pop_back();
            if(to!=t[from]){
                t[to]=from;
                q.push(to);
            }
        }
    }
}

vector <int> s[100010];//下向き移動用
int des[100010];
bool des_f[100010];
void Des(int i){//最下層計算
    if(!des_f[i]){
        if(s[i].empty()){des[i]=0;des_f[i]=true;}
        else{
            vector<int> v=s[i];
            int max=0;
            while(!v.empty()){
                int k=v.back();
                v.pop_back();
                if(!des_f[k]){Des(k);}
                if(max<des[k]){max=des[k];}
            }
            des[i]=max+1;
            des_f[i]=true;
        }
    }
}


int main()
{ 
    int n;
    cin>>n;
    int u,v;
    cin>>u>>v;
    //木の作成
    V=n;
    for(int i=0;i<V-1;i++){
        int a,b;
        cin>>a>>b;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    Tree(v);
    //for(int i=1;i<=V;i++){cout<<i<<t[i]<<endl;}
    //下向きの木構造
    for(int i=1;i<=n;i++){
        if(t[i]!=i){
            s[t[i]].push_back(i);
        }
    }

    //各点から最下層までの距離
    for(int i=0;i<=n;i++){//初期化
        des[i]=0;
        des_f[i]=false;
    }
    for(int i=1;i<=n;i++){
        Des(i);
    }
    /*for(int i=1;i<=n;i++){
        cout<<i<<' '<<t[i]<<' '<<des[i]<<endl;
    }*/


    //uとvの距離の計算
    int l=0;//距離
    int w=u;
    while(w!=v){
        w=t[w];
        l++;
    }
    int ans=0;
    if(l%2==1){
        ans=l/2;
        for(int i=0;i<ans;i++){
            u=t[u];
        }
        cout<<ans+des[u]<<endl;
        return 0;
    }
    else{
        ans=(l-1)/2;
        for(int i=0;i<ans;i++){
            u=t[u];
        }
        cout<<ans+des[u]+1<<endl;
        return 0;
    }



    return 0;
}

Measured memory_bytes: 18688
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		String n = scan.nextLine();
		String[] list = n.split("");
		String answer = "No";
		if(list[0].equals(list[1]) && list[0].equals(list[2])) {
				answer = "Yes";
		}else if(list[1].equals(list[2]) && list[1].equals(list[3])){
				answer = "Yes";
		}

		System.out.println(answer);
	}
}


Measured memory_bytes: 21844
n = int(input())
ba = [0] * 20000
tempSum = 0
minCount = 100000
c = 0
while 9 * c <= n:

    cSum = 0
    temp = 9 * c
    while temp > 0:
        cSum += temp % 9
        temp = temp // 9

    b = (n - 9 * c) // 6
    temp = 6 * b
    bSum = 0
    while temp > 0:
        bSum += temp % 6
        temp = temp // 6
    a = n - 9 * c - 6 * b
        
    minCount = min(minCount, a + bSum + cSum)
    
    c += 1

print(minCount)

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

main () {
  int n;
  scanf("%d", &n);

  vector<int> d(n);
  rep(i,n) {
    scanf("%d", &d[i]);
  }

  sort(d.begin(), d.end());

  printf("%d\n", d[n/2] - d[n/2-1]);

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define N 2000
using namespace std;

bool solve (int n, int m, int A[], int max) {
  if (m < 0 || n > max) return false;
  else if (m == 0) return true;
  else return solve(n+1, m-A[n], A, max) || solve(n+1, m, A, max);
}

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

  int n, q, i, m;
  int A[N];

  // input
  cin >> n;
  rep(i,n) cin >> A[i];

  cin >> q;
  rep(i,q) {
    cin >> m;
    (solve(0,m,A,n))? cout << "yes" : cout << "no";
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
     
using namespace std;
#define ll long long 
#define ld long double

int main()
{   int n;
    int k;
    cin>>n>>k;
    ll arr[n];
    for (int i=0;i<n;i++){
        cin>>arr[i];
    }
    ll brr[n]={};
    brr[0]=0;
    if (k>=n){
        k=n;
    }
    for (int i=1;i<=k;i++){
        brr[i]=brr[i-1]+abs(arr[i]-arr[i-1]);
        for (int j=i-2;j>=0;j--){
            brr[i]=min(brr[i],brr[j]+abs(arr[i]-arr[j]));
        }
    }
    for (int i=k+1;i<n;i++){
        brr[i]=brr[i-1]+abs(arr[i]-arr[i-1]);
        for (int j=i-2;j>=i-k;j--){
            brr[i]=min(brr[i],brr[j]+abs(arr[i]-arr[j]));
        }
    }
    cout<<brr[n-1]<<endl;
    
    return 0;
}


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

#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define eb emplace_back
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using Vi = vector<int>;

void run() {
	string a, b, temp;
	cin >> a >> b;
	int no_a, no_b;
	cin >> no_a >> no_b;
	while(cin >> temp) {
		if(temp == a) no_a--;
		if(temp == b) no_b--;
	} 
	cout << no_a << " " << no_b << endl;
}

int main() 
{
    IO;
    double st = clock();
    run();
    cerr << "\n" << "time = " << (clock() - st) / CLOCKS_PER_SEC << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int a,b,c;
  	cin>>a>>b>>c;
  	int occa = 0 , occb = 0;
  	if(a == 5)
      occa++;
  	if(b == 5)
      occa++;
  	if(c == 5)
      occa++;
  	if(a == 7)
      occb++;
  	if(b == 7)
      occb++;
  	if(c == 7)
      occb++;
  
  	if(occa == 2 && occb == 1)
      cout<<"YES";
  	else
      cout<<"NO";
  
}

Measured memory_bytes: 256
import sys
from collections import Counter

sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))

c = Counter(a)
c2 = [i[1] for i in c.items() if i[1] >= 2]
sum = 0
for i in c2:
    sum += i * (i - 1) // 2

for i in a:
    if c[i] - 1 >= 2:
        tmp = sum - c[i] * (c[i] - 1) // 2
        tmp += (c[i] - 1) * (c[i] - 2) // 2
        print(tmp)
    else:
        tmp = sum - c[i] * (c[i] - 1) // 2
        print(tmp)


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

int main()
{
  int N, M; cin >> N >> M;
  int size = (1 << N);
  const int INF = 1e9 + 10;
  vector<int> dp(size, INF);
  dp[0] = 0;
  rep(i, M) {
    int a, b; cin >> a >> b;
    int key = 0;
    rep(j, b) {
      int c; cin >> c;
      key += (1 << (c - 1));
    }
    rep(k, size) {
      if (dp[k] != -1) {
        dp[(k | key)] = min(dp[(k | key)], dp[k] + a);
      }
    }
  }

  if (dp[size - 1] == INF) cout << -1 << endl;
  else cout << dp[size - 1] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int n,i,b,c,d,e,f;
    b=100;
    d=100000;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        c=b*1.05;
        e=d*1.05;
        if(c*1000!=e){
            c=c+1;
        }
        b=c;
        d=c*1000;

    }
    printf("%d\n",c*1000);
    return 0;
}

Measured memory_bytes: 588
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  int H, W;
  cin >> H >> W;
  char S[52][52];
  rep(j, W + 2) { S[0][j] = '.'; }
  rep(i, H) {
    S[i + 1][0] = '.';
    rep(j, W) { cin >> S[i + 1][j + 1]; }
    S[i + 1][51] = '.';
  }
  rep(j, W + 2) { S[51][j] = '.'; }

  bool flag = true;
  rep(i, H) {
    rep(j, W) {
      if (S[i][j] == '#') {
        if (S[i - 1][j] == '.' && S[i + 1][j] == '.' && S[i][j - 1] == '.' &&
            S[i][j + 1] == '.') {
          flag = false;
        }
      }
    }
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
n, y = map(int, input().split())

for a in range(n+1):
    for b in range(n+1-a):
        c = n-a-b
        total = 10000*a + 5000*b + 1000*c
        if total==y:
            print("{0} {1} {2}".format(a,b,c))
            exit()

print("-1 -1 -1")

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

int main()
{
    int d;
    cin >> d;
    vector<int> c(26);
    vector<vector<int>> s(d,vector<int>(26));

    for (int i = 0; i < 26; i++)
    {
        cin >> c[i];
    }
    for (int i = 0; i < d; i++)
    {
        for (int j = 0; j < 26; j++)
        {
            cin >> s[i][j];
        }
    }
    vector<int> t(d);
    for (int i = 0; i < d; i++)
    {
        t[i] = i % 26 + 1;
    }
    
    int m = 150000;
    long long ans = 0;
    while(m--){
        vector<int> tt(d);
        for (int i = 0; i < d; i++)
        {
            tt[i] = t[i];
        }
        int dd = m % d,p = (m % 26 + 13) % 26 + 1;
        t[dd] = p;

        long long buf = 0;
        vector<int> last(26,0);
        for (int i = 0; i < d; i++)
        {
            buf += s[i][t[i] - 1];
            last[t[i] - 1] = i + 1;
            for (int j = 0; j < 26; j++)
            {
                buf -= c[j] * (i + 1 - last[j]);
            }
        }

        if(ans < buf)ans = buf;
        else
        {
            for (int i = 0; i < d; i++)
            {
                t[i] = tt[i];
            }
        }
    }
    //cout << ans << endl;
    for (int i = 0; i < d; i++)
    {
        cout << t[i] << endl;
    }
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<pair<ll,ll>> seg;
int main()
{
	ll N;
	cin>>N;
	for(ll i=0;i<N;i++)
	{
		ll x,l;
		cin>>x>>l;
		seg.push_back({x-l,x+l});
	}
	sort(seg.begin(),seg.end());
	ll rmax=seg[0].second;
	ll ans=0;
	for(ll i=1;i<N;i++)
	{
		if(seg[i].first<rmax)
		{
			rmax=min(rmax,seg[i].second);
			ans++;
		}
		else
		{
			rmax=seg[i].second;
		}
	}
	cout<<N-ans<<"\n";
	return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
#define re(i,n) for(int i=0;i<n;++i)
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define red(i,r,l) for(int i=r;i>=l;i--)
#define db(x) cout<<#x<<"="<<(x)<<" "
#define el cout<<endl
using namespace std;
const int MXN = 510, MXM = 200010, mol = 1e9 + 7;

int N, Q, M;
int f[MXN][MXN];
int main() {
	scanf("%d %d %d", &N, &M, &Q);
    for (int i = 0; i < M; ++i)
    {
        int x, y;
        scanf("%d %d", &x, &y);
        f[x][y]++;
    }

    for (int j = 1; j <= N; ++j) {
        for (int i = j - 1; i >= 1; --i) {
            f[i][j] = f[i][j] + f[i + 1][j] + f[i][j - 1] - f[i + 1][j - 1];
        }
    }
	for (int i = 1; i <= Q; ++i) {
		int x, y;
		scanf("%d %d", &x, &y);
        printf("%d\n", f[x][y]);
	}
	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
using namespace std;
int main (){
/*-------------custom------------------*/
int h,w,ans[101][101]={0},checker=-2,b=0,checkerH[101][101]={0};
char dr[101][101];
/*-------------------------------------*/
/*-------------imput-------------------*/
cin>>h>>w;
for (int s=0;s<h;s++){
        for (int s_=0;s_<w;s_++){
                cin>>dr[s][s_];
                if (dr[s][s_]=='c'){
                        checkerH[s][s_]=-1;
                }
        }
}
/*------------------------------------*/
/*-----------calcuration--------------*/
for (int s=0;s<h;s++){
        for (int s_=0;s_<w;s_++){
                        if (dr[s][s_]=='.'){
                        for (int s__=s_;s__>=0;s__--){
                                if (dr[s][s__]=='.'&&checker!=-1){
                                        checker=0;
                                }
                                else if (dr[s][s__]=='c'){
                                        ans[s][s_]=b;
                                        checker=-1;
                                        b=0;
                                        break;
                                }
                                b++;
                        }
                if (checker==0){ans[s][s_]=-1;}
                         checker=-2;  b=0; 
                }
        } 
}        
for (int s=0;s<h;s++){
        for (int s_=0;s_<w;s_++){
                if (checkerH[s][s_]==-1)ans[s][s_]=0;
        }
}
/*-------------------------------------*/
/*---------------output----------------*/
for (int s=0;s<h;s++){
        for (int s_=0;s_<w;s_++){
                if (s_==w-1){
                        cout<<ans[s][s_];
                }
                else {
                        cout<<ans[s][s_]<<" ";
                } 
        } cout<<endl;
/*------------------------------------*/
}
return 0;
}

Measured memory_bytes: 3192
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	@scala.annotation.tailrec
	def loop(start: Int, end: Int)(f: Int => Unit): Unit =
		if (start <= end) {
			f(start)
			loop(start + 1, end)(f)
		}

	val n, m = Scanner.nextInt
	
	pw.println((n * (n-1) + m * (m-1)) / 2)
	pw.flush()
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 27220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    ll N,a;
    ll Asum=0;
    vector<ll> A;
    cin >> N;
    REP(i,N){
        cin >> a;
        Asum+=a;
        A.push_back(a);
    }
    Asum%=MOD;
    ll Ans = (Asum*Asum)%MOD;
    
    REP(i,N){
        Ans = (Ans+MOD-((A[i]*A[i])%MOD))%MOD;
    }
    
    Ans = (Ans*500000004)%MOD;
    cout << Ans << endl;
    
    return 0;
}



Measured memory_bytes: 5308
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  long long a,b,x;
  C3(a,b,x);
  int c = 0;
  if(a % x == 0)
    c=1;
  cout << (b/x) - (a/x) + c<< endl;
  ret 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String data = sc.nextLine();
        
        int n = Integer.parseInt(data);
        Set<String> linkedHashSet = new LinkedHashSet<String>();
        
        for(int i = 0; i < n; i++)
        {
            String buf = sc.nextLine();
            linkedHashSet.add(buf);
        }
        
        Object[] after = linkedHashSet.toArray();
        
        
        System.out.println(after.length);
    }
}


Measured memory_bytes: 82024
import sys

stdin = sys.stdin

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

n, k = na()
h = na()
dp = [0] * (n + 1)
for i in range(1, n):
    dp[i] = 10 ** 9
    for j in range(1, k + 1):
        if i - j < 0:
            break
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print(dp[n-1])



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

public class Main {
	public static void main(String[] args) {
		FastScanner br = new FastScanner();
		ArrayList<Integer> caca = new ArrayList<Integer>();
		for(int i = br.ni();i>0;i--) {
			caca.add(br.ni());
		}
		int cont = 0;
		for(int i = caca.size()-1;i>=0;i--) {
			boolean fl = false;
			for(int i2 = i-1;i2>=0;i2--) {
				if(caca.get(i2)>caca.get(i))fl=true;
			}
			if(!fl) cont++;
		}
		System.out.println(cont);
	}
}

class FastScanner {
	BufferedReader br;
	StringTokenizer st;

	public FastScanner(String s) {
		try {
			br = new BufferedReader(new FileReader(s));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	public FastScanner() {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	ArrayList<Integer>[] ng(int n, int e) {
		ArrayList<Integer>[] adj = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			adj[i] = new ArrayList<Integer>();
		}
		for (int i = 0; i < e; i++) {
			int a = ni() - 1;
			int b = ni() - 1;
			adj[a].add(b);
			adj[b].add(a);
		}
		return adj;
	}

	Integer[] nIa(int n) {
		Integer[] arr = new Integer[n];
		for (int i = 0; i < n; i++) {
			arr[i] = ni();
		}
		return arr;
	}

	int[] nia(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = ni();
		}
		return arr;
	}

	Long[] nLa(int n) {
		Long[] arr = new Long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nl();
		}
		return arr;
	}

	long[] nla(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nl();
		}
		return arr;
	}

	String[] nsa(int n) {
		String[] arr = new String[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nt();
		}
		return arr;
	}

	String nt() {
		while (st == null || !st.hasMoreElements()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

	int ni() {
		return Integer.parseInt(nt());
	}

	long nl() {
		return Long.parseLong(nt());
	}

	double nd() {
		return Double.parseDouble(nt());
	}

}

Measured memory_bytes: 20948
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long 

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

// combination(n,r)
int combination(int n, int r){
	if(r == 0 || r == n)	return 1;
	else if(r == 1)	return n;
	return (combination(n - 1, r - 1) + combination(n - 1, r));
}

// gcd(a,b)
int gcd(int a,int b){
	return (b == 0) ? a : gcd(b, a % b);
}

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

// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
	return (*a - *b);
}

// append(array,*size,addNum)
void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
	int temp = array[(*size - 1)];
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
	return temp;
}

void nongetpop(int *array,int *size){
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
}

int main(int argc, char const *argv[])
{
	char c_str[] = "CODEFESTIVAL2016" ;
	char input[17];
	int cnt = 0;

	scanf("%s",input);
	for (int i = 0; i < 17; i++){
		if (c_str[i] != input[i])	++cnt;
	}
	printf("%d\n", cnt);
	return 0;
}


Measured memory_bytes: 128
n = $stdin.gets.to_i

data = Array.new
n.times do
  data << $stdin.gets.chomp.split(" ").map(&:to_i)
end

top = data.sort!{|a1, a2| a2[1] <=> a1[1]}.select{|d| d[1] == data[0][1]}
top.sort!
printf "%d %d\n", top[0][0], top[0][1]

Measured memory_bytes: 6108
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		List<Integer> values = new ArrayList<>();
		for (String token : tokens) {
			values.add(Integer.parseInt(token));
		}
		Collections.sort(values);
		int result = 0;
		while (true) {
			int r = operation(values);
			if (r == 0) {
				break;
			}
			result += r;
			Collections.sort(values);
		}
		System.out.println(result);
		in.close();
	}

	public static int operation(List<Integer> values) {
		if (values.get(0) == values.get(2)) {
			return 0;
		}
		if (values.get(0) == values.get(1)) {
			int result = values.get(2)-values.get(1);
			values.set(0, values.get(2));
			values.set(1, values.get(2));
			return result;
		}
		if ((values.get(1) - values.get(0)) % 2 == 0) {
			int result = (values.get(1) - values.get(0)) / 2;
			values.set(0, values.get(1));
			return result;
		} else {
			int result = (values.get(1) + 1 - values.get(0)) / 2;
			values.set(0, values.get(1));
			values.set(1, values.get(1) + 1);
			return result;
		}
	}
}

Measured memory_bytes: 23764
import java.awt.Point;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	
	public static class Segment{
		int length, color;

		public Segment(int length, int color) {
			super();
			this.length = length;
			this.color = color;
		}

		@Override
		public String toString() {
			return "Segment [length=" + length + ", color=" + color + "]";
		}
	}
	
	public static int remove(ArrayList<Segment> seg_list, int left, int right){
		int reduce = 0;
		
		while(left >= 0 && right < seg_list.size()){
			if(seg_list.get(left).color != seg_list.get(right).color){
				break;
			}
			
			final int len = seg_list.get(left).length + seg_list.get(right).length;
			if(len < 4){
				break;
			}
			
			left--;
			right++;
			reduce += len;
		}
		
		return reduce;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			ArrayList<Segment> seg_list = new ArrayList<Main.Segment>();
			for(int i = 0; i < n; i++){
				final int color = sc.nextInt();
				
				if(seg_list.isEmpty()){
					seg_list.add(new Segment(1, color));
				}else if(seg_list.get(seg_list.size() - 1).color == color){
					seg_list.get(seg_list.size() - 1).length++;
				}else{
					seg_list.add(new Segment(1, color));
				}
			}
			
			int min = n;
			
			for(int divide = 0; divide < seg_list.size(); divide++){
				if(seg_list.get(divide).length == 1){
					//
					//--xxxo---
					if(divide != 0 && seg_list.get(divide - 1).length >= 3){
						final int len = 1 + seg_list.get(divide - 1).length;
						min = Math.min(min, n - len - remove(seg_list, divide - 2, divide + 1));
					}
					
					//oxxx
					if(divide != seg_list.size() - 1 && seg_list.get(divide + 1).length >= 3){
						final int len = 1 + seg_list.get(divide + 1).length;
						min = Math.min(min, n - len - remove(seg_list, divide - 1, divide + 2));
					}
					
					//xxoxx
					if(divide != 0 && divide != seg_list.size() - 1 &&
							seg_list.get(divide - 1).color == seg_list.get(divide + 1).color){
						final int len = seg_list.get(divide - 1).length + seg_list.get(divide + 1).length + 1;
						
						if(len >= 4){
							min = Math.min(min, n - len - remove(seg_list, divide - 2, divide + 2));
						}
					}
				}else{
					//--xxxo---
					if(divide != 0 && seg_list.get(divide - 1).length >= 3){
						final int len = seg_list.get(divide - 1).length + 1;
						seg_list.get(divide).length--;
						min = Math.min(min, n - len - remove(seg_list, divide - 2, divide));
						seg_list.get(divide).length++;
					}
					
					//oxxx
					if(divide != seg_list.size() - 1 && seg_list.get(divide + 1).length >= 3){
						final int len = 1 + seg_list.get(divide + 1).length;
						seg_list.get(divide).length--;
						min = Math.min(min, n - len - remove(seg_list, divide, divide + 2));
						seg_list.get(divide).length++;
					}
				}
			}
			
			System.out.println(min);
		}
		
	}
}

Measured memory_bytes: 41208
#include <iostream>
// A - ><

using namespace std;

int c[500005];

int main() {
    int i,lst,cnt;
    long long ans;
    string S;

    cin.sync_with_stdio(0);
    cin.tie(0);

    cin >> S;
    S = " " + S;

    cnt = 0;
    ans = 0;
    lst = 0;
    for (i = 1;i < S.size();i++) {
        if (S[i] == '<')
            cnt++;
        else if (cnt > 0)
            cnt = 0;
        else
            cnt--;

        ans += cnt;
        if (S[i] != S[i - 1])
            lst = i;
        if (cnt < 0) {
            if (i - lst + 1 > c[lst - 1])
                ans += (i - lst + 2);
            else
                ans += (i - lst + 1);
            cnt = 0;
        }
        c[i] = cnt;
    }

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

    return 0;
}

Measured memory_bytes: 2864
n,m=map(int,input().split())
switch=[]
for i in range(m):
    a=list(map(int,input().split()))
    switch.append(a[1:])
p=list(map(int,input().split()))
cur=0
s=[]
a=''
def generate(a,n):
    if len(a)==n:
        s.append(a)
    else:
        generate(a+'0',n)
        generate(a+'1',n)
generate(a,n)
result=0
for k in s:
    tmp=0
    for i in range(m):
        count=0
        for j in switch[i]:
            if k[j-1]=='1':
                count+=1
        if count%2==p[i]:
            pass
        else:
            break
        tmp+=1
    if tmp==m:
        result+=1
print(result)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
 
int main() {
  string input_sequence;
  cin >> input_sequence;
  int num_cells_placed = 0;
  for(int i = 0; i < (int)input_sequence.size(); ++i){
    if (input_sequence[i] == '1'){
      num_cells_placed++; 
    }
  }
  cout << num_cells_placed << endl;
  
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Aman
 */


#include<bits/stdc++.h>

using namespace std;

#include <iostream>

void __print(int x) { cout << x; }

void __print(long x) { cout << x; }

void __print(long long x) { cout << x; }

template<typename T, typename V>
void __print(const pair<T, V> &x) {
    cout << '{';
    __print(x.first);
    cout << ',';
    __print(x.second);
    cout << '}';
}

template<typename T>
void __print(const T &x) {
    int f = 0;
    cout << '{';
    for (auto &i: x) cout << (f++ ? "," : ""), __print(i);
    cout << "}";
}

void _print() { cout << "]\n"; }

template<typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cout << ", ";
    _print(v...);
}


#define ll   long long
#define F first
#define S second
#ifdef LOCAL
#else
#define dbg(x...)
#endif


class

EDistMax {
public:

    void solve2(std::istream &cin, std::ostream &cout) {
        ll n, mina = 1e16, maxa = -1e16;
        cin >> n;
        vector<pair<ll, ll>> v(n);
        for (auto &i:v) {
            cin >> i.F >> i.S;
            mina = min(mina, i.F + i.S);
            maxa = max(maxa, i.F + i.S);

        }
        ll ans = abs(maxa - mina);
        mina = 1e16, maxa = -1e16;
        for (auto &i:v) {
            mina = min(mina, i.F - i.S);
            maxa = max(maxa, i.F - i.S);
        }
        ans = max(ans, abs(maxa - mina));
        cout << ans;


    }

    void solve(std::istream &cin, std::ostream &cout) {
        ll t = 1;
//            cin >> t;
        while (t--) {
            solve2(cin, cout);
        }
    }

};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    EDistMax solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	ll n, m, v, p;
	cin >> n >> m >> v >> p;
	vector<ll> a(n);
	for (auto &i : a) cin >> i;
	sort(a.begin(), a.end());

	auto f = [&](int md)
	{
		ll x = a[md] + m;
		auto t = a;
		t.erase(t.begin() + md);
		ll z = 0;
		while (!t.empty() && t.back() > x) ++z, t.pop_back();
		if (z >= p) return false;
		z = p-1-z;
		while (!t.empty() && z--) t.pop_back();
		z = v - (n - t.size());
		if (z <= 0) return true;

		vector<ll> g;
		for (auto i : t)
			if (x-i > 0)
				g.push_back(x-i);
		reverse(g.begin(), g.end());
		while (!g.empty() && g.back() >= m) --z, g.pop_back();

		return accumulate(g.begin(), g.end(), 0LL) >= z * m;
	};

	int lo = 0, hi = n-1;
	while (lo < hi)
	{
		int md = (lo + hi) / 2;
		if (f(md))
			hi = md;
		else
			lo = md + 1;
	}

	cout << n - lo << "\n";

	return 0;
}


Measured memory_bytes: 3696