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

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=a;i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(a>b)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class t> void mkuni(vc<t>&v){
	sort(all(v));
	v.erase(unique(all(v)),v.ed);
}

ll read(){ll i;cin>>i;return i;}

const int inf=LLONG_MAX/3;

bool inc(int a,int b,int c){
	return a<=b&&b<=c;
}

const int dyx[]={-1,0,1,0,-1};

void slv(int w,int h){
	vc<string> a(h);
	per(i,h)cin>>a[i];
	int m=0;
	vvc<int> idx(h,vi(w,-1));
	rep(i,h)rep(j,w)if(a[i][j]!='.'&&idx[i][j]==-1){
		int id=m++;
		queue<pi> q;
		idx[i][j]=id;
		q.push(pi(i,j));
		while(!q.empty()){
			int s,t;
			tie(s,t)=q.front();q.pop();
			rep(k,4){
				int u=s+dyx[k],v=t+dyx[k+1];
				if(inc(0,u,h-1)&&inc(0,v,w-1)&&a[u][v]==a[s][t]&&idx[u][v]==-1){
					idx[u][v]=id;
					q.push(pi(u,v));
				}
			}
		}
	}
	vi l(m,inf),r(m,-inf),x(m,0),par(m,-1);
	vvc<int> ch(m);
	rep(i,h)rep(j,w)if(idx[i][j]!=-1){
		x[idx[i][j]]+=j;
		if(i==0){
			chmin(l[idx[i][j]],j);
			chmax(r[idx[i][j]],j);
		}else{
			if(idx[i-1][j]!=-1&&idx[i][j]!=idx[i-1][j]){
				chmin(l[idx[i][j]],j);
				chmax(r[idx[i][j]],j);
				par[idx[i][j]]=idx[i-1][j];
			}
		}
	}
	rng(i,1,m)ch[par[i]].pb(i);
	bool ok=1;
	function<pi(int i)> rec=[&](int i){
		int b=x[i],c=4;
		for(auto to:ch[i]){
			pi d=rec(to);
			b+=d.a;
			c+=d.b;
		}
		if((2*l[i]-1)*c>=2*b)
			ok=0;
		if(2*b>=(2*r[i]+1)*c)
			ok=0;
		return pi(b,c);
	};
	rec(0);
	if(ok)
		cout<<"STABLE"<<endl;
	else
		cout<<"UNSTABLE"<<endl;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	
	while(1){
		int w=read(),h=read();
		if(w==0)break;
		slv(w,h);
	}
}



Measured memory_bytes: 3156
#include<stdio.h>
#include<math.h>

int main() {
	int i,n,Rt[200000],max,min;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &Rt[i]);
	}
	min= Rt[0];
	max = Rt[1]-Rt[0];
	for (i = 1; i < n; i++) {
		if (max < Rt[i] - min) {
			max = Rt[i] - min;
		}
		if (min > Rt[i]) {
			min = Rt[i];
		}
	}
	printf("%d\n", max);

}

Measured memory_bytes: 3480
import java.util.*;
class Main{
  static int[][][] dp;
  static int mod = (int)1e9+7;
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int m = scan.nextInt();
    dp = new int[2][n+1][2];
    dp[0][0][1]=1;
    for(int i=1;i<=n;++i)dp[0][i][0]=1;
    for(int i=0;i<m;++i){
      for(int j=0;j<=n;++j){
		for(int k=0;k<2;++k){
          if(j==0){
            if(k==0)dp[(i+1)%2][0][0]=0;
            else dp[(i+1)%2][0][1] = (dp[i%2][0][1] + (dp[i%2][1][0] + dp[i%2][1][1])%mod)%mod;
          }else if(j==1){
            if(k==0){
              if(n<2)dp[(i+1)%2][j][k]=0;
              else dp[(i+1)%2][1][0] = (dp[i%2][1][0]+dp[i%2][2][0])%mod;
            }else{
              if(n<2)dp[(i+1)%2][1][1] = (dp[i%2][1][0] + (dp[i%2][1][1]+dp[i%2][0][1])%mod)%mod;
              else dp[(i+1)%2][1][1] = (((dp[i%2][1][0]+dp[i%2][0][1])%mod + dp[i%2][1][1]*2%mod)%mod + dp[i%2][2][1])%mod;
            }
          }else{
            dp[(i+1)%2][j][k] = (dp[i%2][j][k]+dp[i%2][j-1][k])%mod;
            if(j+1<=n)dp[(i+1)%2][j][k] = (dp[(i+1)%2][j][k] + (dp[i%2][j][k]+dp[i%2][j+1][k])%mod)%mod;
          }
        }
      }
    }
    long ans = 0;
    for(int i=0;i<=n;++i)ans = (ans + dp[m%2][i][1])%mod;
    System.out.println(ans);
  }
}

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

int main(void)
{
  unsigned long long N, K;
  cin >> N >> K;
  unsigned long long ary[100000];
  for (unsigned long long i = 0; i < 100000; ++i) {
    ary[i] = 0;
  }
  for (unsigned long long i = 0; i < N; ++i) {
    unsigned long long a, b;
    cin >> a >> b;
    ary[a-1] += b;
  }
  unsigned long long k = 0;
  for (unsigned long long i = 0; i < 100000; ++i) {
    if (k + ary[i] >= K) {
      cout << i+1 << endl;
      break;
    }
    k += ary[i];
  }

  return 0;
}


Measured memory_bytes: 1024
#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[i];
    }
    int ans = 0;
    int cur = a[1], turn = 0;
    if(a[0] < a[1]) {
        turn = 1;
    }
    else if(a[0] > a[1]) {
        turn = -1;
    }
    for(int i = 2; i < n; i++) {
        int turn_;
        if(a[i] > cur) {
            turn_ = 1;
        }
        else if(a[i] == cur) {
            turn_ = 0;
        }
        else {
            turn_ = -1;
        }
        if(turn == 0) {
            turn = turn_;
            cur = a[i];
        }
        else if(turn_ == 0) {
            cur = a[i];
        }
        else if(turn == turn_) {
            cur = a[i];
        }
        else {
            ans++;
            cur = a[i];
            if(i != n-1) {
                if(a[i] < a[i+1]) {
                    turn = 1;
                }
                else if(a[i] == a[i+1]) {
                    turn = 0;
                }
                else {
                    turn = -1;
                }
            }
        }
    }
    cout << ans + 1 << "\n";
    return 0;
}

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

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

using namespace std;

#define F first
#define S second
#define pb push_back
#define m_t make_tuple
#define m_p make_pair
#define mp make_pair

typedef long long ll;
typedef long double ld;


#define FILE "teleports"
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);
#else
//  freopen(FILE".in", "r", stdin);
//  freopen(FILE".out", "w", stdout);
#endif // LOCAL
  int c[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c[i][j];
    }
  }
  int a[3];
  for (a[0] = 0; a[0] <= 100; a[0]++) {
    for (a[1] = 0; a[1] <= 100; a[1]++) {
      for (a[2] = 0; a[2] <= 100; a[2]++) {
        int b[3] = {c[0][0] - a[0], c[1][1] - a[1], c[2][2] - a[2]};
        bool f = true;
        for (int i = 0; i < 3; i++) {
          for (int j = 0; j < 3; j++) {
            if (a[i] + b[j] != c[i][j]) f = false;
          }
        }
        if (f) {
          cout << "Yes";
          return 0;
        }
      }
    }
  }
  cout << "No";
#ifdef LOCAL
  cerr << fixed << setprecision(10) << "TIME = " << 1.0 * clock() / CLOCKS_PER_SEC << '\n';
#endif // LOCAL
  return 0;
}


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

Measured memory_bytes: 2700
open System.IO
open System

let n = stdin.ReadLine() |> int
let a = [|0..n|] |> Array.map (fun x ->if x <> 0 then stdin.ReadLine()|> int else 0)

let maxI, maxA = a |> Array.mapi (fun i x -> i, x) |> Array.maxBy (fun (_ ,x) -> x )
let aRemoved = a |> Array.copy
aRemoved.[maxI]<-0
let nextI, nextA = aRemoved |> Array.mapi (fun i x -> i, x) |> Array.maxBy (fun (_ ,x) -> x )

let sw = new StreamWriter(Console.OpenStandardOutput())
sw.AutoFlush <- false
Console.SetOut(sw)

a.[1..] 
|> Array.map (fun x -> if x = maxA then nextA else maxA )
|> Array.iter stdout.WriteLine
stdout.Flush()


Measured memory_bytes: 38608
#include <iostream>

using namespace std;

int a, b, c;

void solve() {
	if (b - a == c - b) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
}

int main()
{
	// 入力
	cin >> a >> b >> c;
	solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define lll bignum
#define ls(x) ( x << 1 )
#define rs(x) ( x << 1 | 1 )
//#define mid ( ( l + r ) >> 1 )
#define lowbit(x) ( x & -x )
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define re register
#define For(i, j, k) for(re int i = (j); i <= (k); ++i)
#define foR(i, j, k) for(re int i = (j); i >= (k); --i)
#define Cross(i, j, k) for(re int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 100011;
const ll inf = 0x3f3f3f3f3f3f;

ll A, B;
double T;

namespace IO {

	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; bool f = 0; char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = (x << 3) + (x << 1) + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write( ll x ) {
		if ( x < 0 ) putchar ('-'), x = -x;
		if ( x > 9 ) write ( x / 10 ); putchar ( x % 10 | 48 );
	}

	inline void wrn ( ll x ) { write (x); putchar (' '); }

	inline void wln ( ll x ) { write (x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn (x), wln (y); }

}

using namespace IO;

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	ll Ans = 0;
	A = read(), B = read(), T = read() + 0.5;
	Ans += floor (T / A) * B; return wln (Ans), 0;
}

/*

*/



Measured memory_bytes: 256
from itertools import product as prd
n, m, q = map(int, input().split())
Jyoken = []

for i in range(q):
    a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    Jyoken.append([a, b, c, d])

patterns = [[i] for i in range(1, m + 1)]

for i in range(n - 1):
    temp = []
    for pattern in patterns:
        matsubi = pattern[-1]
        for num in range(matsubi, m + 1):
            temp.append(pattern + [num])
    patterns = temp

#print(patterns)

max_point = 0
for A in patterns:
    point = 0
    for rule in Jyoken:
        a, b, c, d = rule
        if A[b] - A[a] == c:
            point += d
    max_point = max(point, max_point)
print(max_point)

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cerr <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}


using namespace std;

int main() {
	make(n);
	makev(v, n);
	lint A = 2, B = 2;
	FORD(i,n-1,0) {
		int l = v[i];
		A = ((A + l-1)/l) * l;
		B = (B/l) * l;
		if (B < A) {
			printf("-1\n");
			return 0;
		}
		B += l-1;
	}
	printf("%lld %lld\n", A, B);
}


Measured memory_bytes: 892
#include<bits/stdc++.h> //何故か読み込んでくれないbits/stdc++ (GCC環境は作った気がするけども...)
using namespace std;

int main(){
	//square route
	//参考 : https://muttan1203.hatenablog.com/entry/AOJ_2015 (解説AC)
	
	int N,M;
	cin >> N >> M;
	while(N||M){
		int loop,loop2;
		map<int,int> H;
		map<int,int> W;
		vector<int> h(N);
		vector<int> w(M);
		for(loop=0;loop<N;loop++){
			cin >> h[loop];
		}
		for(loop=0;loop<M;loop++){
			cin >> w[loop];
		}
		int hin,win;
		int hmax=0,wmax=0;
		for(loop=0;loop<N;loop++){
			hin=0;
			for(loop2=loop;loop2<N;loop2++){
				hin+=h[loop2];
				if(H.count(hin)){
					H[hin]++;
				}else{
					H[hin] = 1;
					if(hmax<hin)
						hmax=hin;
				}
			}
		}
		for(loop=0;loop<M;loop++){
			win=0;
			for(loop2=loop;loop2<M;loop2++){
				win+=w[loop2];
				if(W.count(win)){
					W[win]++;
				}else{
					W[win] = 1;
					if(wmax<win){
						wmax=win;
					}
				}
			}
		}
		int maxi=max(hmax,wmax)+1;
		int ans=0;
		for(loop=1;loop<maxi;loop++){
			if(H.count(loop)&&W.count(loop)){
				ans+=H[loop]*W[loop];
			}
		}
		cout << ans << endl;
		cin >> N >> M;
	}
	return 0;
}


Measured memory_bytes: 29848
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define REP(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define INF 10000000
#define ll long long

using namespace std;

typedef pair<int, int> P;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int N;
char c[101];
set<char> a, b, res;
int m;

int main(){
    scanf("%d", &N);
    REP(i, N) scanf("%s", &c[i]);

    m = 0;

    for(int i=1;i<N;++i){
        for(int j=0;j<i;++j) a.insert(c[j]);

        for(int k=i;k<N;++k) b.insert(c[k]);

        set_intersection(a.begin(), a.end(), b.begin(), b.end(), inserter(res, res.end()));

        m = max(m, (int)res.size());

        a.clear();
        b.clear();
        res.clear();
    }

    printf("%d", m);

	return 0;
}

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

int main()
{
	int n; cin>>n ;
	int a[n+1];
	for(int i = 1 ; i<=n ; i++ ) cin>>a[i];
	long long int count = 0 , max = INT_MAX ;
	 
	for(int i = 1 ; i<=n ; i++){
		if( a[i] <= max ) {
			count++;
			//cout<<"i = "<<i;
			max = a[i] ;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

using namespace std;
typedef long long int64;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int64 a,b,k;
  cin>>a>>b>>k;

  if(a>=k){
    a-=k;
  }else if(a+b>=k){
    b-=k-a;
    a=0;
  }else{
    a=0;
    b=0;
  }

  cout<<a<<" "<<b<<endl;




  return 0;
}

Measured memory_bytes: 888
A,B = map(int,input().split())
count =0
for i in range(A,B+1):
    a1 = i - (i // 10) * 10
    a5 = i // 10000
    a2 = ((i - ((i // 100) * 100)) - a1) // 10
    a4 = i // 1000 - (i // 10000) * 10
    if a1 == a5 and a2 == a4:
        count += 1
print(count)

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

using namespace std;

int main(){
    int N,K,ans=0;
    cin >> N >> K;
    vector<int> A(N,0);
    ans = N;
    if(N<=K){
        cout << "0" << endl;
    }else{
        for(int i=0;i<N;i++){
            int a;
            cin >> a;
            a--;
            A[a]++;
        }

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

        for(int i=0;i<K;i++){
            ans -= A[N-1-i];
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 1024
#pragma GCC optimize (2)
#include<bits/stdc++.h>
using namespace std;
int main()
{
	
	long long a,b,c,d;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	long long e=max(a,b);
	long long f=min(a,b);
	long long g=max(c,d);
	long long h=min(c,d);
	if(e>=0&&g>=0&&f>=0&&h>=0)
	{
		long long aa=e*g;
		printf("%lld\n",aa);
	}
	else if(e>=0&&f<0&&g>=0&&h<0)
	{
		long long bb=e*g;
		long long cc=f*h;
		long long aa=max(bb,cc);
		printf("%lld\n",aa);
	}
	else if(e>=0&&f>=0&&g<0&&h<0)
	{
		long long aa=f*g;
		printf("%lld\n",aa);
	}
	else if(e<0&&f<0&&g>=0&&h>=0)
	{
		long long aa=e*h;
		printf("%lld\n",aa);
	}
	else if(e>=0&&f>=0&&g>=0&&h<0)
	{
		long long aa=e*g;
		printf("%lld\n",aa);
	}
	else if(e>=0&&f<0&&g>=0&&h>=0)
	{
		long long aa=e*g;
		printf("%lld\n",aa);
	}
	else if(e<0&&f<0&&g>=0&&h<0)
	{
		long long aa=f*h;
		printf("%lld\n",aa);
	}
	else if(e>=0&&f<0&&g<0&&h<0)
	{
		long long aa=f*h;
		printf("%lld\n",aa);
	}
	else 
	{
		long long aa=f*h;
		printf("%lld\n",aa);
	}
}

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

int main()
{
    int N;
    cin >> N;
    string S,T,R;
    cin >> S;
    cin >> T;
    for(int i=0;i<N;i++){
        R += S.at(i);
        R += T.at(i);
    }
    cout << R <<endl;
}

Measured memory_bytes: 256
def main12():
    num = int(input(""));
    point = [];
    flag = []
    for i in range(num):
        point.append(int(input("")));
        if (point[i] % 10) == 0:
            flag.append(False);
        else:
            flag.append(True);
    if sum(point) % 10 != 0:
        print(sum(point));
    else:
        if flag.count(True) == 0:
            print(0);
        else:
            minn = 1000;
            p = -1;
            for i in range(num):
                if flag[i]:
                    if minn > point[i]:
                        minn = point[i];
                        p = i;
            point[p] = 0;
            print(sum(point));


if __name__ == '__main__':
    main12()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char s[101][101];
	int a[101][101]={0};
	int i,n,j,m,sum,i1,j1;
	cin>>n>>m; 
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++)
		cin>>s[i][j];
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){	
			if(s[i][j]!='#'){
				sum=0;
				for(i1=1;i1<=n;i1++){
					for(j1=1;j1<=m;j1++){
						if((s[i1][j1]=='#')&&((i1>=i-1&&i1<=i+1)&&(j1>=j-1&&j1<=j+1)))
						sum++;				
					}
				}				
			}
			a[i][j]=sum;
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			if(s[i][j]=='#')
			cout<<"#";
			else cout<<a[i][j];
			if(j==m)
			cout<<endl;
		}
	}
	return 0;
}

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

int main(){
  int x, y, a, i;
  scanf("%d %d", &x, &y);
  if(!(x < 0 || y < 0 || x > 1000000000 || y > 1000000000)){
    while(x != 0 && y != 0){
      if(x > y) x = x % y;
      else y = y % x;
    }
    if(x == 0)
      printf("%d\n", y);
    else
      printf("%d\n", x);
  }
  return 0;
}



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

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

#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)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
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; }

// ---- ----

#define bit(b, i) (((b) >> (i)) & 1)

int n;
string s;
map<pair<string, string>, LL> mp;

int main() {
	cin >> n >> s;
	
	inc(b, 1 << n) {
		string t, u;
		inc(i, n) { (bit(b, i) ? t : u) += s[i]; }
		reverse(ALL(u));
		// cout << "post: " << t << ", " << u << endl;
		mp[MP(t, u)]++;
	}
	LL ans = 0;
	inc(b, 1 << n) {
		string t, u;
		inc(i, n) { (bit(b, i) ? t : u) += s[n + i]; }
		reverse(ALL(u));
		// cout << "get:  " << t << ", " << u << " = " << mp[MP(u, t)] << endl;
		ans += mp[MP(u, t)];
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 87680
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;

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

  int a = 0;
  for (int i = 0; i < m; i++) {
    int tmp;
    cin >> tmp;
    a += tmp;
  }

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

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

long long a, b, c, k;

int main() {
    //freopen("input.txt", "r", stdin);
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> a >> b >> c >> k;
    if (k % 2 == 0)
        cout << a - b;
    else
        cout << b - a;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		sc.close();
		String ans="";
		switch(n%10) {
		case 2:
		case 4:
		case 5:
		case 7:
		case 9:
			ans="hon";
			break;
		case 0:
		case 1:
		case 6:
		case 8:
			ans="pon";
			break;
		case 3:
			ans="bon";
			break;
		}
		out.println(ans);
	}
}


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

int main(){
	int A,B,C,D;
	int n,m; string s;
	while(cin >> n >> m){
		vector<int> cost,d[3];
		rep(i,n){
			getline(cin,s);
			getline(cin,s);
			cin >> A >> B >> C >> D;
			cost.push_back(A),
			d[0].push_back(B),
			d[1].push_back(C),
			d[2].push_back(D);
		}
		
		int ret = 0;
		
		rep(x,3){
			int dp[301]; rep(i,301)dp[i] = 0;
			rep(i,n){
				for(int j=cost[i];j<=m;j++){
					dp[j] = max(dp[j],dp[j-cost[i]]+d[x][i]);
					ret   = max(dp[j],ret);
				}
			}
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 936
#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;
int main()
{
    int n;
    double ave=0;
    cin>>n;
    int x[n];
    for(int i=0;i<n;i++){
        cin>>x[i];
        ave+=x[i];
    }
    ave=ave/n;
    if((double)ave-(int)ave<0.5)
        ave=(int)ave;
    else
        ave=(int)ave+1;
    int ans=0;
    for(int i=0;i<n;i++)
        ans+=(abs(ave-x[i])*abs(ave-x[i]));
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int a[32]={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,\
5,4,1,4,1,51};
int main()
{
	int k;
	cin>>k;
	cout<<a[k-1];
	return 0;
}

Measured memory_bytes: 256
/*
    SPFA ````
*/

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long ll;
const int N = 1e6+10;
int n,m,k,q,x,y;
int h[N],w[N],e[N],ne[N],idx;

ll dist[N];
bool st[N];

void add(int a,int b,int c)
{
    e[idx] = b,w[idx] = c,ne[idx] = h[a],h[a] = idx++;
}

void spfa()
{
    memset(dist,0x3f,sizeof dist);
    dist[k] = 0;
    queue<int>q;
    q.push(k);
    
    st[k] = true;
    
    while(q.size())
    {
        int t = q.front();
        q.pop();
        
        st[t] = false;
        
        for(int i = h[t];i!=-1;i=ne[i])
        {
            int j = e[i];
            if(dist[j]>dist[t] + w[i])
            {
                dist[j] = dist[t] + w[i];
                if(!st[j])
                {
                    q.push(j);
                    st[j] = true;
                }
            }

        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >>n;
    memset(h,-1,sizeof h);
    m = n-1;
    while(m--)
    {
        int a,b,c;
        cin >>a>>b>>c;
        add(a,b,c);
        add(b,a,c);
    }
    
    cin >> q>>k;
    spfa();
    while(q--)
    {
        cin >>x >>y;
        cout << dist[x] + dist[y] << endl;
    }
    return 0;
}


Measured memory_bytes: 19200
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

const int maxn = 51;
vector<long long> msks[maxn][maxn];

void gen(int cur, int x, long long msk) {
  msks[x][cur].push_back(msk);
  for (int d = 1; d <= cur; d++) {
    gen(cur % d, x, msk | (1ll << d));
  }
}

void precalc() {
  for (int x = 0; x < maxn; x++) {
    gen(x, x, 0);
  }
}

int n;
int a[maxn], b[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  return true;
}

bool check(long long res) {
  bool ok = true;
  for (int i = 0; i < n; i++) {
    bool found = false;
    for (int j = 0; j < sz(msks[a[i]][b[i]]); j++) {
      auto cur = msks[a[i]][b[i]][j];
      if ((res & cur) == cur) {
        found = true;
        break;
      }
    }
    if (!found) {
      ok = false;
      break;
    }
  }
  return ok;
}

void solve() {
  long long res = (1ll << maxn) - 2;
  if (!check(res)) {
    printf("-1\n");
    return;
  }
  for (int d = maxn - 1; d > 0; d--) {
    res ^= (1ll << d);
    if (!check(res)) {
      res ^= (1ll << d);
    }
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

vector<vector<int>> group;

int N,M;

vector<vector<int>> G;

int g(){
  vector<bool> vis(N,false);
  rep(i,0,N - 1){
    if(!vis[i]){
      queue<int> que;
      que.push(i);
      vis[i] = 1;
      vector<int> temp;
      while(!que.empty()){
        int v = que.front();
        que.pop();
        temp.push_back(v);
        for(int to : G[v]){
          if(!vis[to]){
            vis[to] = 1;
            que.push(to);
          }
        }
      }

      group.push_back(temp);
    }
  }
  return 0;
}

int isE[707][707];

int main(){
  cin >> N >> M;
  G.resize(N);

  rep(i,0,M - 1){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    isE[a][b] = 1;
    isE[b][a] = 1;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  g();

  if(group.size() > 2){
    cout << -1 << endl;
    return 0;
  }

  if(group.size() == 2){
    auto  temp = group[0];

    rep(i,0,(int)temp.size() - 1){
      rep(j,i + 1,(int)temp.size() - 1){
        if(!isE[temp[i]][temp[j]]){
          cout << -1 << endl;
          return 0;
        }
      }
    }
    temp = group[1];

    rep(i,0,(int)temp.size() - 1){
      rep(j,i + 1,(int)temp.size() - 1){
        if(!isE[temp[i]][temp[j]]){
          cout << -1 << endl;
          return 0;
        }
      }
    }

    int s = group[0].size();
    int t = group[1].size();

    cout << s * (s - 1) / 2 + t * (t - 1) / 2 << endl;
    return 0;
  }

  vector<vector<int>> rG(N);

  rep(i,0,N - 1){
    rep(j,0,N - 1){
      if(i == j) continue;
      if(!isE[i][j]){
        rG[i].push_back(j);
      }
    }
  }

  vector<int> vis(N,-1);


  bitset<101010> bit = 0;
  bit[5050] = 1;

  rep(start,0,N - 1){

    if(vis[start] != -1) continue;

    queue<pair<int,int>> que;
    que.push({start,0});

    vis[start] = 0;
    int cnt[2];
    cnt[0] = 0;
    cnt[1] = 0;

    while(!que.empty()){
      int v = que.front().first;
      int d = que.front().second;
      que.pop();
      cnt[d]++;
      for(int to : rG[v]){
        if(vis[to] != -1 && vis[to] != (d + 1) % 2){
          cout << -1 << endl;
          return 0;
        }
        if(vis[to] != -1) continue;
        vis[to] = (d + 1) % 2;
        que.push({to,(d + 1) % 2});
      }
    }

    int dif = abs(cnt[0] - cnt[1]);

    bit = (bit << dif) | (bit >> dif);

  }


  rep(i,0,50505){
    if(bit[5050 + i] || bit[5050 - i]){
      int a = (N + i) / 2;
      int b = N - a;
      cout << a * (a - 1) / 2 + b * (b - 1) / 2 << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 5376
def selectionSort(sort_list):
    count = 0

    for i in range(0, len(sort_list)):
        minj = i

        for j in range(i, len(sort_list)):
            if sort_list[j] < sort_list[minj]:
                minj = j

        if minj != i:
            tmp = sort_list[i]
            sort_list[i] = sort_list[minj]
            sort_list[minj] = tmp
            count += 1

    print(' '.join([str(i) for i in sort_list]))
    print(count)


if __name__ == "__main__":
    N = int(input())
    sort_list = [int(i) for i in input().split()]

    selectionSort(sort_list)



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

typedef long long ll;

int n;
ll x[1005], y[1005];

int main() {
	scanf("%d", &n);
	bool flag;
	for (int i = 1; i <= n; ++i) {
		scanf("%lld%lld", x + i, y + i);
		x[i] += y[i];
		if (i == 1) flag = !(x[i] % 2);
		else if (x[i] % 2 == flag) return puts("-1"), 0;
		y[i] = x[i] - 2 * y[i];
	}
	printf("%d\n", 31 + flag);
	for (int i = 0; i <= 30; ++i)
		printf("%d ", 1 << i);
	if (flag) printf("1");
	puts("");
	for (int i = 1; i <= n; ++i) {
		if (flag) ++x[i], ++y[i];
		x[i] += (1ll << 31) - 1 - flag, y[i] += (1ll << 31) - 1 - flag;
		for (int j = 0; j <= 30; ++j) {
			static char s[2][2] = {{'L', 'D'}, {'U', 'R'}};
			putchar(s[x[i] >> j + 1 & 1][y[i] >> j + 1 & 1]);
		}
		if (flag) putchar('R');
		puts("");
	}
}


Measured memory_bytes: 256
//https://abc113.contest.atcoder.jp/
#include<bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,p,y;
    cin >> n >> m;
    vector<pair<int,int> > kota[100001];
    for(int i=0; i<m; i++){
        cin >> p >> y;
        kota[p].push_back({y,i});
    }
    pair<int,int> ans[100001];
    for(int i=1; i<=n; i++){
        sort(kota[i].begin(),kota[i].end());
        for(int j=0; j<kota[i].size();j++){
            ans[kota[i][j].second] ={i,j+1};
        }
    }
    for(int i=0; i<m; i++){
        cout << setw(6) << setfill('0') << ans[i].first;
        cout << setw(6) << setfill('0') << ans[i].second <<endl;
    }

}


Measured memory_bytes: 7808
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif

int main(void) {
    int len, k;
    cin >> len >> k;
    string str;
    cin >> str;
    char prev = 'X';
    int cnt = 0;
    vector<int> arr;
    for(int i = 0; i < len; i++) {
        if(prev != str[i]) {
            cnt++;
        }
        prev = str[i];
    }
    debug("%d\n", cnt);
    while(cnt > 1 && k > 0) {
        k--;
        if(cnt == 2) {
            cnt--;
        } else {
            cnt -= 2;
        }
    }
    debug("after: %d\n", cnt);
    cout << len - cnt << endl;
    return 0;
}

Measured memory_bytes: 3672
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        q: usize,
        lr: [(usize, usize); m],
        pq: [(usize, usize); q],
    };

    let mut ans = String::with_capacity(500_000);

    let mut citys = [[0; 502]; 502];

    for &(l, r) in lr.iter() {
        citys[l][r] += 1;
    }

    for i in 0..502 {
        for j in 0..501 {
            citys[i][j + 1] += citys[i][j];
        }
    }

    for &(p, q) in pq.iter() {
        let mut sum = 0;
        for i in p..q + 1 {
            sum += citys[i][q] - citys[i][p - 1];
        }
        ans += &format!("{}\n", sum);
    }
    print!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 15864
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    a = LI()
    ans = 0
    for i in range(1, n):
        temp = max(a[i-1]-a[i], 0)
        ans += temp
        a[i] += temp
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 31420
class UF:
    def __init__(self, N):
        self.uf = [-1]*N
        self.n = N

    def find(self, x):
        if self.uf[x]<0: return x
        self.uf[x] = self.find(self.uf[x])
        return self.uf[x]

    def size(self, x):
        return -self.uf[self.find(x)]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x==y: return
        if self.size(x) > self.size(y): x, y = y, x
        self.uf[y] += self.uf[x]
        self.uf[x] = y
        self.n -= 1

N, M = list(map(int, input().split()))
E = [tuple(map(int, input().split())) for _ in range(M)]

ans = 0
for i in range(M):
    uf = UF(N)
    for j in range(M):
        if i==j: continue
        a, b = E[j]
        uf.union(a-1, b-1)
    if uf.n==2: ans+=1

print(ans)

Measured memory_bytes: 3192
#include <stdio.h>
int main()
{
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);

    if(c - a <= d && c-a >= d * -1){
        printf("Yes");
    }else if((c - b <= d && c- b >= d * -1)&&(b - a <= d && b - a >= d * -1)){
        printf("Yes");
    }else{
        printf("No");
    }


    return 0;
}

Measured memory_bytes: 128
#include <cstdlib>
#include <iostream>
#include <typeinfo>
//#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>

using namespace std;

int main()
{
  string s;
  cin >> s;
  vector<int> a(s.size());
  for (int i = 0; i < s.size();i++){
    a.at(i) = s.at(i) - '0';
  }
  int sum;
  int ans = INT_MAX;
  for (int i = 0; i < s.size() - 2; i++)
  {
    sum = 100 * a.at(i) + 10 * a.at(i + 1) + a.at(i + 2);
    ans = min(ans, abs(753 - sum));
  }
  cout << ans << endl;
  return 0;
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
// #define SORT(v, n) stable_sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

class DisjointSet {
   public:
    vi rank, p;
    DisjointSet() {}
    DisjointSet(int size) {
        rank.resize(size, 0);
        p.resize(size, 0);
        rep(i, size) makeSet(i);
    }

    void makeSet(int x) {
        p[x]    = x;
        rank[x] = 0;
    }

    bool same(int x, int y) { return findSet(x) == findSet(y); }

    void unite(int x, int y) { link(findSet(x), findSet(y)); }

    void link(int x, int y) {
        if (rank[x] > rank[y]) {
            p[y] = x;
        } else {
            p[x] = y;
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
    }

    int findSet(int x) {
        if (x != p[x]) {
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(5);

    int n, a, b, q;
    int t;

    cin >> n >> q;
    DisjointSet ds = DisjointSet(n);

    rep(i, q) {
        cin >> t >> a >> b;
        if (t == 0)
            ds.unite(a, b);
        else if (t == 1) {
            if (ds.same(a, b))
                cout << 1 << endl;
            else
                cout << 0 << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3288
#b
a,v = map(int,input().split())
b,w = map(int,input().split())
t=int(input())

if a>b:
    a_last = a-v*t
    b_last = b-w*t
else:
    a_last = a+v*t
    b_last = b+w*t

if (a-b)*(a_last-b_last)<=0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 61592
#include<bits/stdc++.h>
using namespace std;
int n,m,v,p,u,ans;
long long g,a[200005],sy,d,s[200005];
int main() 
{
	scanf("%d%d%d%d",&n,&m,&v,&p);
	for (int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	g=a[n-p+1];
	for (int i=1;i<=n;i++)
		s[i]=s[i-1]+a[i];
	ans=p;
	for (int i=1;i<=n-p;i++)
	{
		if (g>a[i]+m)
			continue;
		sy=(long long)m*(long long)(v-1);
		d=(long long)m*(long long)(n-1);
		d-=s[n-p+1]-s[i-1]-(long long)(n-p-i+2)*a[i];
		if (sy<=d)
			ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5340
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


long mod = 998244353;
/* C++の構造体 メンバがpublicなclass */
typedef struct mint
{
    ll x;
    mint(ll x = 0) : x(x % mod) {} //コンストラクタ
    /* 演算子オーバーロード */
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const
    {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const
    {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const
    {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const
    {
        return pow(mod - 2);
    }
    mint &operator/=(const mint a)
    {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const
    {
        mint res(*this);
        return res /= a;
    }
} mint_t;

ll intpow(mint_t m, int n)
{
    if (n == 0) return 1;
    mint_t ans(1);
    while (n >= 1)
    {
        if ((n % 2) == 0){
            m *= m.x;
            n /= 2;
        }else {
            ans *= m.x;
            n -= 1;
        }
    }
    return ans.x;
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


const int n_max = 3050;

mint dp[n_max][n_max] = {0};
int main()
{
    int n, s;
    cin >> n >> s;
    vector<int> a;
    rep(i, n){ int tmp; cin >> tmp; a.push_back(tmp);}

    dp[0][0] = 1;
    rep(i, n)rep(j, s+1){
        dp[i+1][j] += (j >= a[i]) ? dp[i][j-a[i]] : 0;
        dp[i+1][j] += dp[i][j]*2;
    }

    cout << dp[n][s].x << endl;
}



Measured memory_bytes: 76276
#include<bits/stdc++.h>
using namespace std;
long long a[305];
long long m, s;

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%lld", a + i);
    m = a[2];
    for (int i = 3; i < n; i++) m ^= a[i];
    s = a[0] + a[1];
    long long rem = s - m;
    if ((rem % 2) || (rem < 0)) {
        puts("-1");
        return 0;
    }
    rem /= 2;
    long long b = rem;
    int f = 1;
    for (long long i = 50; i >= 0; i--) {
        long long p = 1ll << i;
        if ((m & p) && (rem & p)) f = 0;
        if ((m & p) && ((b + p) <= a[0])) b += p;
    }
    b = a[0] - b;
    if ((b >= a[0]) || (b < 0)) f = 0;
    if (f) printf("%lld", b);
    else puts("-1");
}


Measured memory_bytes: 3824
#include <iostream>
#include <vector>

using namespace std;

int n;
vector<int> a;

void cut(int k)
{
	for (int i = 0; i < k; i++) {
		a.push_back(a[0]);
		a.erase(a.begin());
	}
}

void print_debug()
{
	for (int i = 0; i < 2 * n-1; i++) {
		cout << a[i] << " ";
	}
	cout << a[2 * n - 1] << endl;
}

void print()
{
	for (int i = 0; i < 2 * n; i++) {
		cout << a[i] << endl;
	}
}

void reshuffle()
{
	int j;
	for (int i = n, j = 1; i < 2 * n; i++, j+=2) {
		a.insert(a.begin() + j, a[i]);
		a.erase(a.begin() + i + 1);
	}
}


#if 0
int main()
{
	cin >> n;

	a.resize(2*n);

	// 初期化
	for (int i = 1; i <= 2 * n; i++) {
		a[i-1] = i;
	}

	int m;
	while ( cin >> m ) {
		if (m == 0) {
			break;
		} else {
			cut(m);
			print_debug();
		}
	}
	return 0;
}
#else
int main()
{
	cin >> n;

	a.resize(2*n);

	// 初期化
	for (int i = 1; i <= 2 * n; i++) {
		a[i-1] = i;
	}

	int m;
	cin >> m;
	for (int i = 0; i < m; i++) {
		int v;
		cin >> v;
		if (v == 0) {
			reshuffle();
		} else {
			cut(v);
		}
	}
	print();

	return 0;
}
#endif



Measured memory_bytes: 3140
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    int n, k; cin >> n >> k;
    string s; cin >> s;
    //1 0 1 0 1 という形にする
    vector<int> v;
    if (s[0] == '0') v.push_back(0);
    int c = 1;
    rrep(i, 1, s.size()) {
        if (s[i] != s[i - 1]) {
            v.push_back(c); //前の分を
            c = 1;
        } else {
            c++;
        }
    }
    if (c) v.push_back(c);
    if (s[s.size() - 1] == '0') v.push_back(0);
    //rep(i, v.size()) cout << v[i] << " "; cout << endl;
    int add = 2 * k + 1; //半開区間
    vector<int> acc(v.size() + 1);
    rep(i, v.size()) {
        acc[i + 1] = acc[i] + v[i];
    }
    int ans = 0;
    for (int i = 0; i < v.size(); i += 2) {
        int right = min((int)v.size(), i + add);
        //cout << right << " " << i << endl;
        int tmp = acc[right] - acc[i];
        ans = max(tmp, ans);
    }
    cout << ans << endl;
}



Measured memory_bytes: 1272
#include<stdio.h>
#define MAX 250
int main(){
  int n,i;
  int Heap[MAX];

  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&Heap[i]);
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,Heap[i]);
    if(i/2>=1)printf("parent key = %d, ",Heap[i/2]);
    if(i*2<=n)printf("left key = %d, ",Heap[i*2]);
    if(i*2+1<=n)printf("right key = %d, ",Heap[i*2+1]);
    printf("\n");
  }
  return 0;
}
  

Measured memory_bytes: 600
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
typedef vector<int> vi;
typedef vector<vector<int>> vi2;
int main(void)
{
    int A, B, N;
    cin >> N >> A >> B;
    int tmp = 0;
    int sum = 0;
    int suma = 0;
    int x = 1;
    for (int i = 1; i <= N; i++)
    {
        x = i;
        while (x)
        {
            tmp = x % 10;
            sum += tmp;
            x /= 10;
        }
        if (A <= sum && sum <= B)
        {
            suma += i;
        }
        tmp = 0;
        sum = 0;
        x = 0;
    }
    cout << suma << endl;
    return 0;
}

Measured memory_bytes: 256