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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

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

    vector<ll>a(n),l(n),r(n);
    //ｌ=左から足した合計　r＝右から足した合計
    rep(i,n){
        cin>>a[i];
    }

    l[0]=a[0];
    r[n-1]=a[n-1];

    rep2(i,1,n-1){
        l[i]=l[i-1]+a[i];
    }
    for(int i=n-2;i>=0;i--){
        r[i]=r[i+1]+a[i];
    }

    ll ans=inf;

    rep(i,n-1){
        ans=min(ans,abs(l[i]-r[i+1]));
    }

    cout<<ans<<endl;

    /*
    rep(i,n){
        cout<<a[i]<<" ";
    }
    cout<<endl;

    rep(i,n){
        cout<<l[i]<<" ";
    }
    cout<<endl;

    rep(i,n){
        cout<<r[i]<<" ";
    }
    cout<<endl;
    */

}


Measured memory_bytes: 4992
#include <stdio.h>
int ans;
int main()
{
    int n,tenn[200][101] = {0},num[200][3];
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            scanf("%d",&num[i][j]);
            tenn[j][num[i][j]]++;
        }
    }
    for(int i = 0; i < n; i++)
    {
        ans = 0;
        for(int j = 0; j < 3; j++)
        {
            if(tenn[j][num[i][j]] == 1)ans += num[i][j];
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

using namespace std;

int const NMAX = 300;
int n;
double dp[1 + NMAX][1 + NMAX][1 + NMAX];
int s1, s2, s3;

double dfs(int i, int j, int k) {
  if(i+j+k == 0) {
    return 0.0;
  }
  if(dp[i][j][k] > -0.5) {
    return dp[i][j][k];
  }
  double x = (double)n/(i+j+k);
  double val = 0.0;
  if(i > 0) {
    val += (dfs(i-1, j, k) + x)*i/(i+j+k);
  }
  if(j > 0) {
    val += (dfs(i+1, j-1, k) + x)*j/(i+j+k);
  }
  if(k > 0) {
    val += (dfs(i, j+1, k-1) + x)*k/(i+j+k);
  }
  dp[i][j][k] = val;
  return val;
}

int main() {
  cin >> n;
  for(int i = 1; i <= n; i++) {
    int z;
    cin >> z;
    if(z == 1) {
      s1++;
    } else if(z == 2) {
      s2++;
    } else {
      s3++;
    }
  }
  for(int i = 0; i <= n; i++) {
    for(int j = 0; j <= n; j++) {
      for(int k = 0; k <= n; k++) {
        dp[i][j][k] = -1.0;
      }
    }
  }
  double ans = dfs(s1, s2, s3);
  cout << setprecision(12) << ans;
}


Measured memory_bytes: 213376
#include <iostream>
#include <cmath>
#include <string>
#include <string.h>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>

using namespace std;


int main(){

        int i=1,x;

        while(1){
                scanf("%d\n",&x);
                if(x==0)
                        return 0;
                printf("Case %d: %d\n",i,x);
                i++;
        }

}


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

string solve() {
    string S;
    ll K;
    cin >> S >> K;
    for ( int i = 0; i < S.size(); i++ ) {
        ll d = (26 - (S[i] - 'a')) % 26;
        if ( d <= K ) {
            S[i] = 'a';
            K -= d;
        }
    }
    S[S.size()-1] = (char)('a' + (K + (S[S.size()-1] - 'a')) % 26);
    return S;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 512
#include <iostream>

int main(){
    int x,y;
    while(1){
        std::cin >> x >> y;
        if((x==0) && (y==0)){break;}
        else{
            if(x<y){
                std::cout << x << " " << y <<std::endl;
            }
            else{
                std::cout << y << " " << x <<std::endl;
            }
        }
    }
}


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

int rel_c_c( double x1, double y1, double r1, double x2, double y2, double r2 ) {
	double d = hypot( x1 - x2, y1 - y2 );
	if ( d > r1 + r2 )
		return 0;
	if ( fabs( r1 - r2 ) <= d && d <= r1 + r2 )
		return 1;
	if ( d < fabs( r1 - r2 ) )
		return r1 > r2 ? 2 : -2;
}

int main( void ) {
	int n;
	double xa, ya, ra, xb, yb, rb;

	for ( scanf( "%d", &n ); n--; printf( "%d\n", rel_c_c( xa, ya, ra, xb, yb, rb ) ) )
		scanf( "%lf %lf %lf %lf %lf %lf", &xa, &ya, &ra, &xb, &yb, &rb );

	return 0;
}

Measured memory_bytes: 648
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

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

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

const int N = 80;

int h,w;
int arr[N][N];

bitset<4*N*N+5>btt[N][N]; // offset by 2*N*N
const int OFFSET = 2*N*N;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);
    
    cin>>h>>w;
    FOR(i,h){
    	FOR(j,w){
    		cin>>arr[i][j];
		}
	}
	FOR(i,h){
    	FOR(j,w){
    		int x;
    		cin>>x;
    		arr[i][j] -= x;
    		arr[i][j] = abs(arr[i][j]);
		}
	}
	
	btt[0][0][arr[0][0] + OFFSET] = 1;
	
	FOR(i,h){
		FOR(j,w){
			if(i+1 < h){
				auto curr = btt[i][j];
				curr = (curr >> arr[i+1][j]) | (curr << arr[i+1][j]);
				
				btt[i+1][j] |= curr;
			}
			if(j+1 < w){
				auto curr = btt[i][j];
				curr = (curr >> arr[i][j+1]) | (curr << arr[i][j+1]);
				
				btt[i][j+1] |= curr;
			}
			
//			printf("%d %d\n",i,j);
//			FOR(k,4*N*N+5){
//				if(btt[i][j][k] == 1)printf("%d ",k - OFFSET);
//			}printf("\n");
		}
	}
	
	int ans = OO;
//	cout << btt[h-1][w-1] << endl;
	FOR(i,4*N*N+5){
		if(btt[h-1][w-1][i] == 1){
//			printf("%d\n",i - OFFSET);
			ans = min(ans, abs(i - OFFSET));
		}
	}
	
	cout << ans << endl;
    
    return 0;
}

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

const int MAXN = 1e5 + 100 ; 

int n , a[MAXN] ; 

int main()
{
	cin >> n ; 
	for(int i=1 ; i<=n ; i++)
		cin >> a[i] ;
	sort(a+1 , a+n+1) ; 
	reverse(a+1 ,a+n+1); 
	int pos = 1 ;  
	for(;pos<=n ; pos++)
		if(a[pos]<pos)
			break ; 
	pos-- ; 
//	cout << pos << endl ; 
	int pos2 = pos ; 
	for(;pos2<=n ; pos2++)
		if(a[pos2] < pos)
			break ; 
	pos2--;
//	cout << pos2 << endl ; 
	cout << ( ((pos2-pos)%2||(a[pos]-pos)%2) ? "First" : "Second" )<< endl ; 
	
}

Measured memory_bytes: 768
#include<cstdio>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int M;

const int N_MAX=50;

template<class T>
void mul(int n,const T A[N_MAX][N_MAX],const T x[N_MAX],T y[N_MAX]){
	static T z[N_MAX];
	rep(i,n){
		z[i]=0;
		rep(j,n) z[i]=(z[i]+A[i][j]*x[j])%M;
	}
	rep(i,n) y[i]=z[i];
}

template<class T>
void mul(int n,const T A[N_MAX][N_MAX],const T B[N_MAX][N_MAX],T C[N_MAX][N_MAX]){
	static T tmp[N_MAX][N_MAX];
	rep(i,n) rep(j,n) {
		tmp[i][j]=0;
		rep(k,n) tmp[i][j]=(tmp[i][j]+A[i][k]*B[k][j])%M;
	}
	rep(i,n) rep(j,n) C[i][j]=tmp[i][j];
}

template<class T>
void pow(int n,const T A[N_MAX][N_MAX],int m,T B[N_MAX][N_MAX]){
	static T tmp[N_MAX][N_MAX];
	rep(i,n) rep(j,n) {
		tmp[i][j]=A[i][j];
		B[i][j]=(i==j?1:0);
	}
	for(int t=0;m>0;t++){
		if(m&(1LL<<t)){
			mul(n,B,tmp,B);
			m-=1LL<<t;
		}
		mul(n,tmp,tmp,tmp);
	}
}

int main(){
	for(int n,a,b,c,t;scanf("%d%d%d%d%d%d",&n,&M,&a,&b,&c,&t),n;){
		int x[N_MAX];
		rep(i,n) scanf("%d",x+i);

		int A[N_MAX][N_MAX]={};
		rep(i,n){
			if(i> 0 ) A[i][i-1]=a;
			A[i][i]=b;
			if(i<n-1) A[i][i+1]=c;
		}

		pow(n,A,t,A);
		mul(n,A,x,x);

		rep(i,n) printf("%d%c",x[i],i+1<n?' ':'\n');
	}

	return 0;
}

Measured memory_bytes: 1064
#include<iostream>
using namespace std;
int main()
{
string s;
cin>>s;
int n,p=0;
n=s.length();
n=(n-1)/2;

for(int i=0 ;i<n ; i++)
{
    if(s[i]!=s[n+i+1])
    {
        p=1;
        break;
    }
}
if(p==1) cout<<"No";
else cout<<"Yes";

}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define mst(a,b) memset(a,b,sizeof(a))
#define ALL(x) x.begin(),x.end()
#define pii pair<int,int>
#define lowbit(x) (x&(-x))
#define X first
#define Y second
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
const int maxn=1e5+50;
const int mod=998244353;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N = 1e5 + 5;
int a[N];
int n;
int vis[N << 1];
void update(int x){
    while(x < N * 2)vis[x]++,x += x & -x;
}
int query(int x){
    int a = 0;
    while(x)a += vis[x],x -= x & -x;
    return a;
}
ll solve(int m) {
    mst(vis,0);
    int cnt = n + 1;
    update(cnt);
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] >= m) {
            cnt++;
        } else {
            cnt--;
        }
        ans += query(cnt);
        update(cnt);
    }
    return ans;
}
int main(){
#ifdef local
    freopen("input","r",stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i = 1; i <= n; i++){
        cin>>a[i];
    }
    LL all = 1ll * (1 + n) * n / 2;
    all = (all + 1)/ 2;
    int l = 0,r = inf;
    while(l < r - 1){
        int mid = (r + l) >> 1;
        LL tmp = solve(mid);
        if(tmp >= all){
            l = mid;
        }
        else r = mid;
    }
    cout<<l<<endl;
}


Measured memory_bytes: 1408
unittest
{
	assert( [ "5 4 1", "1 2", "2 3", "3 4", "3 5" ].parse.expand.solve == 2 );
	assert( [ "5 4 5", "1 2", "1 3", "1 4", "1 5" ].parse.expand.solve == 1 );
	assert( [ "2 1 2", "1 2" ].parse.expand.solve == 0 );
	assert( [ "9 6 1", "1 2", "2 3", "3 4", "4 5", "5 6", "4 7", "7 8", "8 9" ].parse.expand.solve == 5 );
}



import std.algorithm;
import std.container;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nuv = input.front.split.to!( long[] );
	nuv[ 1 .. $ ] -= 1;
	auto abs = new long[ 2 ][ nuv[ 0 ] - 1 ];
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
		ab[] -= 1;
	}
	return tuple( nuv[ 0 ], nuv[ 1 ], nuv[ 2 ], abs );
}

auto solve( long n, long u, long v, long[ 2 ][] abs )
{
	// 辺配列から隣接リストを作成
	auto nss = new long[][ n ];
	foreach( ab; abs )
	{
		nss[ ab[ 0 ] ] ~= ab[ 1 ];
		nss[ ab[ 1 ] ] ~= ab[ 0 ];
	}
	
	// 青木君の移動をシミュレート
	auto as = new long[ n ];
	as[] = -1;
	as[ v ] = 0;
	auto queue_a = make!DList( v );
	while( !queue_a.empty )
	{
		auto f = queue_a.front;
		queue_a.removeFront;
		
		foreach( t; nss[ f ] )
		{
			if( 0 <= as[ t ] ) continue;
			as[ t ] = as[ f ] + 1;
			queue_a.insertBack( t );
		}
	}
	
	// 高橋君の移動をシミュレート
	auto ans = 0L;
	auto ts = new long[ n ];
	ts[] = -1;
	ts[ u ] = 0;
	auto queue_t = make!DList( u );
	while( !queue_t.empty )
	{
		auto f = queue_t.front;
		queue_t.removeFront;
		
		auto d = ts[ f ] + 1;
		foreach( t; nss[ f ] )
		{
			if( 0 <= ts[ t ] ) continue;
			if( as[ t ] <= d )
			{
				// 捕まった
				ans = max( ans, as[ t ] );
			}
			else
			{
				// 捕まってない
				ts[ t ] = d;
				queue_t.insertBack( t );
			}
		}
	}
	
	// 行き止まりまで捕まらずに来れたら、うろうろして時間稼ぎする
	foreach( i, d; ts )
	{
		if( nss[ i ].length != 1 || d < 0 ) continue;
		ans = max( ans, as[ nss[ i ][ 0 ] ] );		// 絶対行き止まりの一つ前で捕まるので計算しなくていい
	}
	
	return ans;
}


Measured memory_bytes: 15356
function Main(input) {
  input = input.split("\n");
  var L = parseInt(input[0].split(" ")[0]);
  var R = parseInt(input[0].split(" ")[1]);
  var map = new Array(2019).fill(0);
  for(var i=0;i<2019;i++){
    tmp=new Array(2019).fill(0);
    for(var j=0;j<2019;j++){
      tmp[j]=(i*j)%2019;
    }
    map[i]=tmp;
  }
  var ans =2018;
  var min =2018;
  var max =0;
  for(var i=L;i<Math.min(R+1,L+2020);i++){
    min=Math.min(min,i%2019);
    max=Math.max(max,i%2019);
  }
  for(var i=min;i<max;i++){
    for(var j=i+1;j<=max;j++){
      ans=Math.min(ans,map[i][j]);
    }
  }

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 68912
N = int(input())
vote = [1,1]
for i in range(N):
    ratio = list(map(int, input().split()))
    for j in range(2):
        while(vote[j] % ratio[j] != 0):
            vote[j] += 1
    if vote[0] * ratio[1] < vote[1] * ratio[0]:
        vote[0] = vote[1] // ratio[1] * ratio[0];
    if vote[0] * ratio[1] > vote[1] * ratio[0]:
        vote[1] = vote[0] // ratio[0] * ratio[1];
print(vote[0] + vote[1])

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > P;
int main()
{
  char s,t,u,v;
  cin>>s>>t>>u>>v;
  int a=s-'0',b=t-'0',c=u-'0',d=v-'0';

  if(a+b+c+d==7) printf("%d+%d+%d+%d=7",a,b,c,d);
  else if(a+b+c-d==7) printf("%d+%d+%d-%d=7",a,b,c,d);
  else if(a+b-c+d==7) printf("%d+%d-%d+%d=7",a,b,c,d);
  else if(a-b+c+d==7) printf("%d-%d+%d+%d=7",a,b,c,d);
  else if(a+b-c-d==7) printf("%d+%d-%d-%d=7",a,b,c,d);
  else if(a-b-c+d==7) printf("%d-%d-%d+%d=7",a,b,c,d);
  else if(a-b+c-d==7) printf("%d-%d+%d-%d=7",a,b,c,d);
  else printf("%d-%d-%d-%d=7",a,b,c,d);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  vector<int> u(n);
  u[n-1] = 1;
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (a == 0) v[b]++;
    if (b == n-1) u[a]++;
  }

  rep(i,n) {
    if (v[i] && u[i]) {
      cout << "POSSIBLE" << endl;
      return;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 4692
m,e,j,s;main(n){for(;--n||scanf("%d",&n)*n;puts(m>99|e>99|j>99|m+e>179|s>239?"A":s>209|s>149&m>79?"B":"C"))scanf("%d%d%d",&m,&e,&j),s=m+e+j;}

Measured memory_bytes: 0
#coding:utf-8                           
                                        
ABK = [int(i) for i in input().split()] 
A, B, K = ABK[0], ABK[1], ABK[2]        
                                        
if (B - A)/2 >= K:                       
  for i in range(A, A+K):               
    print(i)                            
  for i in range(B-K+1, B+1):           
    print(i)                            
                                        
else:                                   
  for i in range(A, B+1):               
    print(i)                            
                                       

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vector<pair<ll,pll>> P(N);
    REP(i,0,N) {
        ll x, y, h;
        cin >> x >> y >> h;
        P[i].first = h;
        P[i].second = {x, y};
    }

    DESC(P);
    ll x1 = P[0].second.first;
    ll y1 = P[0].second.second;
    ll h1 = P[0].first;
    ll x2 = P[1].second.first;
    ll y2 = P[1].second.second;
    ll h2 = P[1].first;
    queue<pair<ll,pll>> Q;
    REP(Cx,0,101) {
        REP(Cy,0,101) {
            ll H1 = abs(x1-Cx) + abs(y1-Cy) + h1;
            if(h2 > 0) {
                ll H2 = abs(x2-Cx) + abs(y2-Cy) + h2;
                if(H1 == H2) Q.push({H1, {Cx, Cy}});
            }
            else {
                ll H2 = abs(x2-Cx) + abs(y2-Cy);
                if(H1 <= H2) Q.push({H1, {Cx, Cy}});
            }
        }
    }

    while(SZ(Q) > 1) {
        auto v = Q.front(); Q.pop();
        ll Cx = v.second.first;
        ll Cy = v.second.second;
        ll H = v.first;
        bool f = true;
        REP(i,2,N) {
            ll x = P[i].second.first;
            ll y = P[i].second.second;
            ll h = P[i].first;
            if(h > 0) {
                if(abs(x-Cx) + abs(y-Cy) + h != H) {
                    f = false;
                    break;
                }
            }
            else {
                if(abs(x-Cx) + abs(y-Cy) < H) {
                    f = false;
                    break;
                }
            }
        }
        if(f) Q.push({H, {Cx, Cy}});
    }

    auto v = Q.front();
    PS(v.second.first); PS(v.second.second); PR(v.first);

    

    return 0;
}

/*



*/

Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
struct unionfind{
  int par[100010]; // 親ノード  必要に応じて要素数を変えよう
  int rank[100010]; // ランク　必要に応じて要素数を変えよう
  unionfind(int n){
    init(n);
  }
  void init(int n){
    for(int i=0;i<=n;i++){
      par[i]=i;
      rank[i]=1;
    }
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    }
    else {
      return par[x] = root(par[x]);
    }
  }
  int size(int x){
    return rank[root(x)];
  }
  bool same(int x,int y) {
    return root(x) == root(y);
  }
  void unite(int x,int y) {
    x=root(x);
    y=root(y);
    if(x==y){
      return;
    }
    if(rank[x]<rank[y]){
      swap(x,y);
    }
    rank[x]=rank[x]+rank[y];
    par[y]=x;
  }
};
int main(){
  int n,m;
  cin >> n >> m;
  unionfind tree(n);
  int i;
  for(i=0;i<m;i++){
    int x,y,z;
    cin >> x >> y >> z;
    x--,y--;
    tree.unite(x,y);
  }
  int ans=0;
  vector<int> g(100010,0);
  for(i=0;i<n;i++){
    if(g[tree.root(i)]==0){
      ans++,g[tree.root(i)]=1;
    }
  }
  cout << ans << endl;
}

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

int main()
{
  int n,T;
  cin >> n >> T;
  
  int c[n],t[n];
  rep(i,n) cin >> c[i] >> t[i];
  
  int ans = 1001;
  rep(i,n){
    if(t[i] <= T && c[i] < ans){
      ans = c[i];
    }
  }
  
  if(ans == 1001){
    cout << "TLE" << endl;
  }else{
    cout << ans << endl;
  }
      
}

Measured memory_bytes: 3596
W, H, N = map(int, input().split())
lx, rx, uy, dy = 0, W, H, 0
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        lx = max(lx, x)
    if a == 2:
        rx = min(rx, x)
    if a == 3:
        dy = max(dy, y)
    if a == 4:
        uy = min(uy, y)
# print(lx, rx, uy, dy)
print(max(0, uy - dy) * max(0, rx - lx))


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

int c,d,w,x;
int E[16][31], F[16][31];
int SF[16][31], SE[16][31];
int dp[6][51], tmp[6][51];

int main() {
    while(cin>>c>>d>>w>>x, c|d|w|x) {
        for(int i=0; i<c; ++i)
            for(int j=0; j<d; ++j)
                cin>>E[i][j];

        for(int i=0; i<c; ++i)
            for(int j=0; j<d; ++j)
                cin>>F[i][j];

        memset(dp, 0, sizeof(dp));
        for(int i=0; i<d; ++i) {
            memset(tmp, 0, sizeof(tmp));
            for(int k=0; k<=x; ++k)
                for(int p=0; p<=w; ++p)
                    tmp[k][p] = dp[k][p];

            for(int j=0; j<=x; ++j)
                for(int k=0; k<=w; ++k) {
                    int p = dp[j][k];
                    for(int to=0; to<c; ++to) {
                        if(E[to][i] > 0 && k + F[to][i] <= w)
                            tmp[j][k+F[to][i]] = max(tmp[j][k+F[to][i]],
                                                     p+E[to][i]);

                        if(j == x) continue;
                        for(int from=0; from<to; ++from) {
                            int f=0,e=0;
                            for(int q=from; q<=to; ++q)
                                if(E[q][i] == 0) {
                                    e = -1; break;
                                }else e += E[q][i], f += F[q][i];
                            if(e >= 0 && k + f <= w) {
                                tmp[j+1][k+f] = max(tmp[j+1][k+f], p+e);
                            }
                        }
                    }
                }

            for(int k=0; k<=x; ++k)
                for(int p=0; p<=w; ++p)
                    dp[k][p] = tmp[k][p];
        }

        int ans = 0;
        for(int k=0; k<=x; ++k)
            for(int p=0; p<=w; ++p)
                ans = max(dp[k][p], ans);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 876
from collections import deque


def BFS(x,y):
    color=[["white" for i in range(w+2)] for j in range(h+2)]
    D=[[-1 for i in range(w+2)] for j in range(h+2)]

    color[x][y]="gray"
    D[x][y],dis=0,0
    queue=deque([[x,y]])

    while len(queue)!=0:
        a,b=queue.popleft()
        for c,d in [[0,1],[0,-1],[1,0],[-1,0]]:
            X,Y=a+c,b+d
            if S[X][Y]=="." and color[X][Y]=="white":
                color[X][Y]="gray"
                D[X][Y]=D[a][b]+1
                dis=max(dis,D[X][Y])
                queue.append([X,Y])
        color[a][b]="black"
    
    return dis


h,w=map(int,input().split())
S=[["#"]+list(input())+["#"] for i in range(h)]
S.insert(0,["#"]*(w+2))
S.append(["#"]*(w+2))

ans=0
for i in range(1,h+1):
    for j in range(1,w+1):
        if S[i][j]!="#":
            ans=max(ans,BFS(i,j))

print(ans)

Measured memory_bytes: 3316
j = int(input())
i = list(map(int, input().split()))
#print(i,j)
cnt = 0
for n in range(j):
  #print('n=',n)
  if (n+1) % 2  == 1:
    #print('n%2=',n%2)
    #print(n)
    if i[n] % 2 ==1:
      cnt += 1
print(cnt)

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

int main(){
  int K;
  cin >> K;
  if((K%2==0)||(K%5==0)){
    cout << -1 << endl;
  }else{
    if(K%7==0){
      K/=7;
    }
    int mod=9*K;
    int x=1%mod;
    for(int i=1;;i++){
      x=(x*(10%mod))%mod;
      if(x==1){
        cout << i << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
int n,K;
int main()
{
	n=read();K=read();
	for(int i=-1000000;i<=1000000;i++)if(abs(i-K)+1<=n)pr1(i);
	return 0;
}


Measured memory_bytes: 128
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

//マクロ
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
//定数
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
//略記
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MX = 1e18;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n; cin >> n;
    ll has_zero = false;
    ll a[n]; for (int i = 0; i < n; ++i) {
        ll tmp; cin >> tmp;
        if (tmp == 0) has_zero = true;
        a[i] = tmp;
    }

    if (has_zero) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    for (int i = 0; i < n; ++i) {
        ll a_i = a[i];

        if (ans > MX / a_i) {
            cout << -1 << endl;
            return 0;
        }

        ans *= a_i;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4440
/*
    Author : DemonStar
*/

#pragma GCC optimize("Ofast")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define loop(i, n) for(ll i = 0; i < n; i++)
#define pl pair<ll, ll>
#define vl vector<ll>
#define endl '\n'
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};


template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t) {
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t) {
    for (auto &i : t) os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &t : v) is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
    for (pair<T1, T2> &t : v) is >> t.first >> t.second;
    return is;
}

const ll mod = 1e9 + 7;

int main()
{

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll n, ans = 0;
    cin >> n;
    for (ll i = 1; i <= n; i++) {
        ll num = n / i;
        ans += num * (2 * i + (num - 1) * i) / 2;
    }

    cout << ans << endl;


#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s";
#endif

    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    int x;
    cin >> x;
    int cnt = x / 100;
    int remain = x - cnt * 100;
    if (remain <= (5 * cnt)) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
total = 0
for i in range(n-1):
  if a[i]+1==a[i+1]:
    total += c[a[i]-1]
total += sum(b)
print(total)

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=1000000000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> divisor(ll x){vector<ll> div;
	for(ll i=1;i*i<=x;i++){if(x%i==0){div.pb(i);if(i*i!=x)div.pb(x/i);}}
	sort(div.bg,div.ed);return div;}


int main(){
	string s; cin>>s;
	bool N=false;
	bool S=false;
	bool W=false;
	bool E=false;
	rep(i,s.sz){
		if(s[i]=='N') N=true;
		if(s[i]=='W') W=true;
		if(s[i]=='S') S=true;
		if(s[i]=='E') E=true;
	}
	if(N==S && W==E) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
while True:
    A, B, C = map(int, raw_input().split())
    if A == 0: break;   
    n = input()
    r = min([((A**2)+(B**2))**0.5, ((A**2)+(C**2))**0.5, ((B**2)+(C**2))**0.5])
    for i in range(n):
        if (input()*2 > r): print "OK"
        else: print "NA"

Measured memory_bytes: 4292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Nmax=200010;
//ll a[Nmax];
//int* P = new int[N];

int main() {
	int N,x=0,y=0,z=0;
	cin >> N;
	ll Y;
	cin >> Y;
	
	//for(int z=0;z < 100000;z++){
	//	if(x*10000+y*5000+z*1000 > Y) break;
		for(int y=0;y < 20000;y++){
			if(x*10000+y*5000+(N-y-x)*1000 > Y) break;
			for(int x=0;x < 10000;x++){
				if(N-y-x>=0){
					if(10000*x+5000*y+1000*(N-y-x)==Y){
						cout <<x<<" "<<y<<" "<<N-y-x<<endl;
						return 0;
					}
				}else break;
			}
		}
	//}

	cout <<"-1 -1 -1"<< endl; 
	
	return 0;
}

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

int A, B, C, D, E, F, ans1, ans2;
double ans = -1;

int main() {    
    cin >> A >> B >> C >> D >> E >> F;
    for (int a = 0; a <= F; a += 100 * A) {
        for (int b = 0; a + b <= F; b += 100 * B) {
            int water = a + b;
            if (water == 0) continue;
            for (int c = 0; water + c <= F; c += C) {
                for (int d = 0; water + c + d <= F; d += D) {
                    int sugar = c + d;
                    double cur = 100.0 * sugar / (water + sugar);
                    int e = water / 100 * E;
                    if (sugar <= e && cur > ans) {
                        ans = cur;
                        ans1 = water + sugar;
                        ans2 = sugar;
                    }
                }
            }
        }
    }
    printf("%d %d\n", ans1, ans2);
}

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

int main() {
    int x[3];
    cin>>x[0]>>x[1]>>x[2];
    sort(x, x+3);
    int tmp=(x[2]-x[0])+(x[2]-x[1]);
    cout<<((tmp%2==0)?tmp/2:tmp/2+2)<<endl;

    return 0;
}

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

void solve()
{
  int n;
  cin>>n;
  int res = n/1.08;
  //cout<<res<<endl;
  if(int((res+1)*1.08)==n) cout<<res+1<<endl;
  else if(int(res*1.08)==n) cout<<res<<endl;

  else cout<<":("<<endl;
}

int main()
{
    int t;
    t=1;
    while(t--)
    {
        solve();

    }
return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u32 = read();
    let s: String = read();

    for ch in s.chars() {
        let d = ((ch as u8 - b'A' + n as u8) % 26) + b'A';
        print!("{}", d as char);
    }
    println!("");
}


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

int main(){
    string s;  cin >> s;
    string t;
    int N = s.length();
    for(int i=0; i<N; i++){
        if(i + 1 < N && s.substr(i, 2) == "BC"){
            t += '$';
            i++;
        }else{
            t += s[i];
        }
    }

    ll ans = 0;
    ll cnt = 0;
    for(char c : t){
        if(c == 'A') cnt++;
        else if(c == '$') ans += cnt;
        else cnt = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll a[200005];

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;
	vector<pll>v,g;
	cin >> n;
	for(i=1;i<=n;i++)
		cin >> a[i];
	ll mx=0,ans=0;
	x=0,y=0;
	map<ll,ll>M;
	
	for(i=1;i<=n;i+=2)
		M[a[i]]++,x++;
	
	for(auto it:M)
		v.pb({it.ss,it.ff});
	M.clear();
	
	for(i=2;i<=n;i+=2)
		M[a[i]]++,y++;
	
	for(auto it:M)
		g.pb({it.ss,it.ff});	

	sort(all(v)),sort(all(g));
	reverse(all(v)),reverse(all(g));

	if(v[0].ss!=g[0].ss)
		cout<<x+y-v[0].ff-g[0].ff<<endl;
	else
	{
		if(sz(v)==1 && sz(g)==1)
			cout<<min(v[0].ff,g[0].ff)<<endl;
		else
		{
			if(sz(v)==1)
				cout<<min(v[0].ff+y-g[0].ff,y-g[1].ff)<<endl;
			else if(sz(g)==1)
				cout<<min(x-v[1].ff,g[0].ff+x-v[0].ff)<<endl;
			else
				cout<<min(x+y-v[0].ff-g[1].ff,x+y-v[1].ff-g[0].ff)<<endl;
		}
	}
}

Measured memory_bytes: 9312
#include <stdio.h>

int main() {
  int W, H, N;
  int i;
  int sx = 0, sy = 0;
  
  scanf("%d %d %d", &W, &H, &N);
  for(i = 0; i < N; i++) {
    int x, y, a;
    scanf("%d %d %d", &x, &y, &a);
    if(a == 1 && sx < x) sx = x;
    if(a == 2 && x < W) W = x;
    if(a == 3 && sy < y) sy = y;
    if(a == 4 && y < H) H = y;
  }
  
  if(sx < W && sy < H) printf("%d\n", (W-sx)*(H-sy));
  else printf("0\n");
  
  return 0;
}
    

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))
total = sum(A)
total *= 2
mindif = 1e12
sub = 0
for i in range(N):
    sub += 2 * A[i]
    dif = abs(total//2-sub)
    if dif < mindif:
        mindif = dif

print(mindif)


Measured memory_bytes: 105164
#include <stdio.h>

int main(void)
{
	int N,a4=0,a2=0,a0=0,i;
	scanf("%d",&N);
	long int a[N];
	for(i=0;i<N;i++)
	{
	  scanf("%ld",&a[i]);
	  if(a[i]%4==0)
	    a4++;
	  else if(a[i]%2==0)
	    a2++;
	  else
	    a0++;
    }
    if(a2)
      a0=a0+1;
    
    if(a4>=a0-1)
      printf("Yes");
    else
      printf("No");
      
    return 0;
	
	
 } 

Measured memory_bytes: 896
# -*- coding: utf-8 -*-

N, = map(int, input().split())
lower = 'abcdefghijklmnopqrstuvwxyz'

ans = ''
while True:
    a = N % 26
    ans = lower[a-1] + ans
    if a==0:
        N = (N-1) // 26
    else:
        N = N // 26
    if N==0 :
        break

print(ans)


Measured memory_bytes: 9172
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner in = new Scanner(System.in);
		String A = in.next();
		LinkedList<Integer[]> alph = new LinkedList<>();
		HashSet<Integer> set = new HashSet<>();
		
		Integer[] list = new Integer[52]; // 0-25 right, 26-51 left
		
		
		for(int i=A.length();i>0;i--){
			int cr = A.charAt(i-1) - 'a';
			if(set.contains(cr)){
				list[26+cr] = i;
			}else{
				list[cr] = i;
				list[26 + cr] = i;
				set.add(cr);
				if(set.size()==26){
					alph.push(list);
					list = new Integer[52];
					set = new HashSet<Integer>();
				}
			}
		}
		
		StringBuffer buf = new StringBuffer();
		int left = 1;
		for(int i=0;i<26;i++){
			if(list[i]==null || list[i]<left){
				buf.append((char)('a'+i));
				if(alph.isEmpty()){
					System.out.println(buf.toString());
					return;
				}
				list = alph.pop();
				left = list[26+i] + 1;
				i = -1;
			}
		}
		
		
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
}

Measured memory_bytes: 47208
#include <bits/stdc++.h>
#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 1

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

string S;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);

	cin >> S;

	if (S=="Sunny") {
		cout << "Cloudy";
	}
	else if(S=="Cloudy") {
		cout << "Rainy";
	}
	else if(S=="Rainy") {
		cout << "Sunny";
	}
	cout << endl;

	return 0;
}




Measured memory_bytes: 256
// https://atcoder.jp/contests/abc169/tasks/abc169_e
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int const maxn = 2e5;
int A[maxn], B[maxn];

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

  rep(i, N) { cin >> A[i] >> B[i]; }
  sort(A, A + N);
  sort(B, B + N);

  int ml = A[N / 2], mh = B[N / 2];
  if (N % 2 == 0) {
    ml += A[N / 2 - 1];
    mh += B[N / 2 - 1];
  }

  cout << mh - ml + 1;
}

Measured memory_bytes: 5104
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int main() {
	int A, B, K; cin >> K >> A >> B;
	for (int i = A; i <= B; i++) {
		if (i % K == 0) { cout << "OK" << endl; return 0; }
	}
	cout << "NG" << endl;
	return 0;
}

Measured memory_bytes: 3540
// D - Coloring Edges on Tree
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define NMAX 100000

int K = 1;
int C[NMAX+1];//child
int S[NMAX+1];//sibling
int colors[NMAX+1];

void dfs(int p, int p_color){
	int color = 1;
	for(int c=C[p]; c; c=S[c]){
		colors[c] = color==p_color? ++color: color;
		K = max(K, color);
		dfs(c, color++);
	}
}

int main(){
	int N; cin>>N;
	int Q[N];
	for(int i=1; i<=N-1; ++i){
		int p,c; scanf("%d%d",&p,&c);
		Q[i] = c;
		S[c] = C[p];
		C[p] = c;
	}
	dfs(1, 0);
	printf("%d\n", K);
	rp(i, 1, N) printf("%d\n", colors[Q[i]]);
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
#define VI vector<int>
#define VL vector<LL>
#define VII vector< vector<int> >
#define VLL vector< vector<LL> >
#define VS vector<string>
#define PII pair<int,int>
#define PIS pair<int,string>
#define PSI pair<string,int>
#define PLL pair<ll,ll>
LL facctorialMethod(int k);
int main(){
    LL n,n_sen;
    cin >> n;
    if(n%1000 == 0) {
        cout << "0" << endl;
    }else{
        cout << 1000 - (n%1000) << endl;
    }



    return 0;
}

LL facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i){
        sum *= i;
    }
    return sum;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<list>
using namespace std;

int main() {
	    int x;
	    cin >> x;
	    if (x<1200)  cout << "ABC\n";
	    else    cout << "ARC\n";
	
}

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

public class Main
{
    public static void main(String[] args)
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try{
            int i;
            int n = Integer.parseInt(br.readLine());
            ArrayDeque<String> list = new ArrayDeque<String>();
            String[] num = new String[2];
            String command;
            char c;
            for(i=0; i<n; i++)
            {
                command = br.readLine();
                c = command.charAt(0);

                if(c == 'd')
                {
                    c = command.charAt(6);
                    if(c == 'F')
                    {
                        list.pollFirst();
                    }
                    else if(c == 'L')
                    {
                        list.pollLast();
                    }
                    else
                    {
                        num = command.split(" ",0);
                        list.remove(num[1]);
                    }
                }
                else
                {
                    num = command.split(" ",0);
                    list.offerFirst(num[1]);
                }
            }

            StringBuilder s = new StringBuilder();
            s.append(list.poll());
            while(list.size()>0)
            {
                s.append(" ").append(list.poll());
            }
            System.out.println(s);
        }
        catch(Exception e)
        {
        }
    }
}

Measured memory_bytes: 221668
#include<map>
#include<queue>
#include<cstdio>
#include<bitset>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
using namespace std;
inline char nc() {
	static char b[100000],*s=b,*t=b;
	return s==t&&(t=(s=b)+fread(b,1,100000,stdin),s==t)?-1:*s++;
}
inline void read(int &x) {
	char b = nc(); x = 0;
	for (; !isdigit(b); b = nc());
	for (; isdigit(b); b = nc()) x = x * 10 + b - '0';
}
int n, m, N;
int dis[500005];
map < pair < int , int > , int > h;
vector < pair < int , int > > g[500005];
bitset < 500005 > vis;
queue < int > q;
inline void aE(int u, int v, int w) {
	g[u].pb(mp(v, w)); g[v].pb(mp(u, w));
}
inline int idx(int u, int c) {
	return h.count(mp(u, c)) ? h[mp(u, c)] : h[mp(u, c)] = ++N;
}
int spfa() {
	memset(dis, 0x3f, sizeof(dis));
	q.push(1); dis[1] = 0;
	while (!q.empty()) {
		int u = q.front(); q.pop(); vis[u] = 0;
		for (int v, w, i = 0; i < g[u].size(); ++i) {
			v = g[u][i].fir, w = g[u][i].sec;
			if (dis[v] > dis[u] + w) {
				dis[v] = dis[u] + w;
				if (!vis[v]) q.push(v), vis[v] = 1;
			}
		}
	} return dis[n] == 0x3f3f3f3f ? -1 : dis[n] / 2;
}

int main() {
	read(n); read(m); N = n;
	for (int u, v, c, a, b, i = 0; i < m; ++i) {
		read(u); read(v); read(c);
		a = idx(u, c); b = idx(v, c);
		aE(u, a, 1); aE(v, b, 1); aE(a, b, 0);
	}
	printf("%d\n", spfa());
	return 0;
}

Measured memory_bytes: 57600
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);
    String ans;
    int n;

    void run(){
	while(sc.hasNext()){
	    ans = "3C";
	    n = sc.nextInt();
	    if(n!=0) solve();
	}
    }

    void solve(){
	while(n>=39) n = n-39;
	if(n==0) ans += "39";
	else if(n<10) ans += "0"+Integer.toString(n);
	else ans += Integer.toString(n);
	System.out.println(ans);
    }
}

Measured memory_bytes: 17316
#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 FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

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

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int w,h,x,y;cin>>w>>h>>x>>y;
  cout<<(double)w*h/2<<" ";

  if(x*2==w&&y*2==h){
    cout<<1<<endl;
  }else{
    cout<<0<<endl;
  }

 

  return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
    int N, M;
    cin >> N >> M;

    vector<vector<int>> g(N, vector<int>());
    for (int i = 0; i < M; i++) {
        int from, to;
        cin >> from >> to;
        g[from - 1].push_back(to - 1);
        g[to - 1].push_back(from - 1);
    }

    queue<pair<int, int>> q;
    q.push(make_pair(0, 0));
    vector<int> ans(N);
    vector<int> visited(N, 0);
    while (!q.empty()) {
        auto p = q.front();
        q.pop();
      	if (visited[p.first] == 1) continue;
        visited[p.first] = 1;
      	ans[p.first] = p.second;

        for (int j = 0; j < g[p.first].size(); j++) {
            if (visited[g[p.first][j]] != 1) {
                q.push(make_pair(g[p.first][j], p.first));
            }
        }
    }

    cout << "Yes" << endl;
    for (int k = 1; k < N; k++) {
        cout << ans[k] + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 11212
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

int main()
{
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k % 2 == 0) {
    cout << a - b << endl;
  } else {
    cout << b - a << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin >> h >> w;
    char aq[h+2][w+2];
    for(int i = 1;i < h+1;i++){
        for(int j = 1;j < w+1;j++){
            cin >> aq[i][j];
        }
    }
    bool judge = true;
    for(int i = 1;i < h+1;i++){
        for(int j = 1;j < w+1;j++){
            if(aq[i][j] == '#' && aq[i-1][j] != '#' && aq[i+1][j] != '#' && aq[i][j+1] != '#' && aq[i][j-1] != '#'){
                judge = false;
            }
        }
    }
    if(judge == true) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256