akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
struct Node;
vector<Node> V;
int tmp = 0;
struct Node {
  int idx;
  vector<int> nbr;
  bool vst = false;
  void dfs() {
    vst = true;
    tmp++;
    for(int x : nbr) {
      if(!V[x].vst) {
        V[x].dfs();
      }
    }
  };
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N, M;
  cin >> N >> M;
  REP(i, N) V.emplace_back();
  REP(i, M) {
    int A, B;
    cin >> A >> B;
    A--; B--;
    V[A].nbr.push_back(B);
    V[B].nbr.push_back(A);
  }
  int ans = 0;
  REP(i, N) {
    tmp = 0;
    if(!V[i].vst) V[i].dfs();
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 23572
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int x = sc.nextInt();//头数量
        int y = sc.nextInt();//脚数量
        boolean flag = false;
        for(int i = 0; i <= x; i++){
            if ((x-i)*4+i*2==y) {
                flag = true;
                break;
            }
        }

        System.out.println(flag?"Yes":"No");
    }
}

Measured memory_bytes: 27004
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a,b;
  cin>>a>>b;
  if(a[0]==b[2] && a[1]==b[1] && a[2]==b[0]){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}


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

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

ans = len(str(Base_10_to_n(n, k)))
print(ans)

Measured memory_bytes: 2940
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n, k;
vector<int> a;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c;
    cin>>c;
    if(c>='a')cout<<'a'<<"\n";
    else cout<<'A'<<"\n";
}


Measured memory_bytes: 3580
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String N = scan.next();
		scan.close();
		String[] strarray = N.split("");


		int[] num = new int[strarray.length];
		int sum = 0;
		for(int i = 0; i < strarray.length; i++) {

			num[i] = Integer.parseInt(strarray[i]);
			sum = sum + num[i];

		}

		if(sum % 9 == 0) {
			System.out.println("Yes");
		}else if(sum % 9 != 0) {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 65668
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout << endl
#define sp(x) cout << setprecision(x);
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vpii vector<pair<int,int>> 
#define vl vector<ll> 
#define vvl vector<vector<ll>> 
#define vd vector<double> 
#define vvd vector<vector<double>> 
#define vb vector<bool> 
#define vvb vector<vector<bool>>
#define vs vector<string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
ll inf = 1001001000;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g; }
bool is_prime(ll x) { for (ll i = 2; i * i <= x; i++) { if (x % i == 0)return false; } return true; }


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h, n; cin >> h >> n;
	vl a(n), b(n);
	rep(i, n)cin >> a[i] >> b[i];
	vl dp(h+1, inf);
	dp[0] = 0;
	rep(i, n)rep(j, h + 1)
	{
		chmin(dp[min(h, j + a[i])], dp[j] + b[i]);
	}
	ll ans = dp[h];
	co(ans);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(void){
    char str[3];
    cin >> str;
    int num = 0;
    if(str[0] == 'R'){
        num++;
        if(str[0] == 'R' && str[1] == 'R'){
            num ++;
            if(str[1] == 'R' && str[2] == 'R'){       
                num ++;
            }
        }
    }
    else if(str[1] == 'R'){
        num++;
        if(str[1] == 'R' && str[2] == 'R'){
            num++;
        }
    }
    else if(str[2] == 'R'){
        num ++;
    }
    cout << num << endl;
}

Measured memory_bytes: 3568
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(in.readLine());
        System.out.println(x*x*x);
        
	}

}

Measured memory_bytes: 16860
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X=sc.nextInt();
		int N=sc.nextInt();
		int p[]=new int[N];
		for(int i=0;i<N;i++) 
			p[i]=sc.nextInt();
		sc.close();
		boolean result=true;
		for(int i=0;i<=100;i++) {
			result=true;
			for(int j=0;j<N;j++) {
				if(X-i==p[j]) {
					result=false;
				}
			}
			if(result==true) {
				System.out.println(X-i);
				System.exit(0);
			}
			result=true;
			for(int j=0;j<N;j++) {
				if(X+i==p[j]) {
					result=false;
				}
			}
			if(result==true) {
				System.out.println(X+i);
				System.exit(0);
			}
		}	
	}
}

Measured memory_bytes: 36072
/*input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int c[10][10];
int main()
{
	int n,m;
	cin>>n>>m;
	REP(i,10) REP(j,10){
		cin>>c[i][j];
	}
	REP(j,10) REP(i,10) REP(k,10) c[i][k]=min(c[i][k],c[i][j]+c[j][k]);
	ll ans=0;
	REP(i,n) REP(j,m){
		int tmp;
		cin>>tmp;
		if(tmp==-1) continue;
		ans+=c[tmp][1];
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main() {
  string s;
  cin >> s;
  deque<char> d; //前からも後ろからも格納できる関数
  for (char c : s) d.push_back(c);  //文字列sを先に格納
  bool flip = false;   //反転の有無
  int q;
  cin >> q;
  rep(i,q) {
    int t;
    cin >> t;
    if (t == 1) {
      flip = !flip;  //false→true
    } else {
      int f; char c;
      cin >> f >> c;
      if(flip) f=3-f;
      if (f == 1) {
        d.push_front(c); //前に加える
      } else {
        d.push_back(c);  //後ろに加える
      }
    }
  }
  if (flip) reverse(all(d));  //deque関数はreverseができる
  string ans;
  for (char c : d) ans += c;
  cout << ans << endl;
}

Measured memory_bytes: 1412
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n,m,l = -1,r = 1<<30, l_tmp, r_tmp;
    cin >> n >> m;
    for(int i=0;i<m;++i){
        cin >> l_tmp >> r_tmp;
        l = max(l_tmp, l);
        r = min(r_tmp, r);
    }

    cout << max(0, r-l+1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,f,i,r=1;
int main(){
	cin>>n;
	vector<int>a(n);
	for(auto &x:a)cin>>x;
	sort(a.begin(),a.end());
	f=!(n%2&&(a[0]!=0||n>1&&a[1]==0)||!n%2&&a[0]==0);
	for(i=n%2;i<n;i++)if(a[i]!=a[++i])f=0;
	for(i=n/2;i--;)r=(r<<1)%(1000000007);
	cout<<r*f<<endl;
	return 0;
}

Measured memory_bytes: 640
from fractions import gcd
a,b,c,d=map(int,input().split())
lenth=b-a+1

def lcm(m,n):
	return (m*n)//gcd(m,n)

def divnumber(c):
	ans=lenth//c
	rem1=a%c
	if rem1==0:rem1+=c
	rem2=lenth%c-1
	if rem1+rem2>=c:
		ans+=1
	return ans

print(lenth-divnumber(c)-divnumber(d)+divnumber(lcm(c,d)))
	

Measured memory_bytes: 63852
#include <iostream>

using namespace std;

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

	if (n <= -1) {
		n = -1;
	}

	cout << n;
	return 0;
}

Measured memory_bytes: 3664
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <deque>
#define maxn 1000009
using namespace std;
char s[maxn],t[maxn];
int n,ans;
deque<int>Q;
bool check(){
	int p=n;
	for(int i=n;i>=1;i--){
		if(t[i]==t[i-1]) continue;
		
		p=min(p,i);
		while(p>0&&s[p]!=t[i]) p--;
		if(p==0) return 0;

		

		while(!Q.empty()){
			int x=Q.back(),sz=Q.size();
			if(x>=i+sz)
				Q.pop_back();
			else
				break;
		}
		Q.push_front(p);
		if(i!=p)
			ans=max(ans,(int)Q.size());
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	scanf("%s%s",s+1,t+1);
	if(strcmp(s+1,t+1)==0){
		puts("0");
	}
	else if(!check()){
		puts("-1");
	}
	else{
		printf("%d\n",ans+1);
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 6272
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

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

const int MAXN = 201024;

pair<int,int> pii[MAXN];
int res[MAXN];

int main() {
    int n; cin>>n;
    for(int i = 0; i < n; ++i) {
        int x; cin>>x;
        pii[i] = pair<int,int>(x, i);
    }
    sort(pii, pii + n);
    for(int i = 0; i < n; ++i) {
        int ii = pii[i].second;
        if(i < n/2) {
            res[ii] = pii[n/2].first;
        }
        else {
            res[ii] = pii[n/2 - 1].first;
        }
    }
    for(int i = 0; i < n; ++i) {
        cout << res[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 4480
S = input()
cnt = 0
if S.count("R") == 3:
  cnt = 3
elif S.count("R") == 1:
  cnt = 1
elif S.count("R") == 0:
  cnt = 0
else:
  if (S[0] == "R" and S[1] == "R") or (S[1] == "R" and S[2] == "R"):
    cnt = 2
  else:
    cnt = 1
print(cnt)

Measured memory_bytes: 9044
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>

namespace jm
{
	const int N=101000,M=N*2;
	int begin[N],next[M],to[M];
	std::deque<int> Q;
	int n,m,e;
	void add(int x,int y,bool k=1)
	{
		to[++e]=y;
		next[e]=begin[x];
		begin[x]=e;
		if(k)add(y,x,0);
	}
	void initialize()
	{
		scanf("%d%d",&n,&m);
		for(int i=1,u,v;i<=m;i++)
			scanf("%d%d",&u,&v),add(u,v);
	}
	bool vis[N];
	void solve()
	{
		initialize();
		Q.push_back(1),Q.push_back(to[begin[1]]);
		vis[1]=vis[to[begin[1]]]=1;
		
		while(1)
		{
			int p=Q.front(),q,flag=0;
			for(int i=begin[p];i;i=next[i])
				if(!vis[q=to[i]]){flag=1;break;}
			if(!flag)break;
			Q.push_front(q),vis[q]=1;
		}

		while(1)
		{
			int p=Q.back(),q,flag=0;
			for(int i=begin[p];i;i=next[i])
				if(!vis[q=to[i]]){flag=1;break;}
			if(!flag)break;
			Q.push_back(q),vis[q]=1;
		}

		printf("%d\n",(int)Q.size());for(auto it:Q)printf("%d ",it);printf("\n");
	}
}

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


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

int main(){
	char nums[1000000];
	int n;
	for(int i = 2; i < 1000000; i++)
		nums[i] = 1;
	for(int j = 2; j < 1000; j++)

		for(int k = 2; j * k <= 1000000; k++)
			nums[j * k] = 0;
	while(cin >> n){
		int count = 0;
		for(int l = 2; l <= n; l++)
			if(nums[l])
				count++;
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>

using namespace std;
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;

using ll = long long int;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    Real32 a, b;
    cin >> a >> b;
    cout << (Bint)(a*b) << endl;
    
    return 0;
}


Measured memory_bytes: 3816
#include <iostream>
#include <bitset>
#include <vector>
using namespace std;

int main() {

    int N;

    cin >> N;



    int a = N / 7;
    int b = (N / 4);

    if (N % 7 == 0 || N % 4 == 0 ){
        cout << "Yes" << endl;
        return 0;
    }


    // for (int i = 0; i <= b + 1; i++){
    //     int aa = 4 * i;
    //     int bb = 7 * (b - i);

    //     if (aa + bb == N){
    //         cout << "Yes" << endl;
    //         return 0;
    //     }
    // }
    int y4 = 1;
    int y7 = 1;

    int sum = 0;
 //do{
    do{
        sum = (y4 * 4) + (y7 * 7);

        if (sum == N){
            cout << "Yes" << endl;
            return 0;
        }
        if (sum > N){
            y4++;
            y7 = 1;
            continue;
        }
        
        y7++;


    } while (y4 <= b);
//} while (true);

    cout << "No" << endl;




}

Measured memory_bytes: 3580
#include<iostream>
#include<atcoder/all>
using namespace std;
int main(){int n,q,t,u,v,i;cin>>n>>q;atcoder::dsu uf(n);for(i=0;i<q;i++){cin>>t>>u>>v;if(t)cout<<uf.same(u,v)<<endl;else uf.merge(u,v);}}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define itrep(type, it, t) for(type::iterator it=t.begin(); it!=t.end(); it++)
using namespace std;

#define MOD (1000000007)

int main(void) {

    string S;
    cin >> S;

    int size = S.length();
    string ans = string(size, 'x');
    cout << ans;


    return 0;
}

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

int main(){
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

int main(){
    int n, k, count;
    cin >> n >> k;
    count = 0;

    for(int i = 0; i < n; i++ ){
        int h;
      cin >> h;
        if(h >= k){
            count += 1;
        }
    }
    cout << count << endl;
    return 0;
}

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

void str_swap(char str1[],char str2[])
{
	char str[128];
	strcpy(str,str1);
	strcpy(str1,str2);
	strcpy(str2,str);
}

int dictionary(char str1[],char str2[])
{
	int ans,i,len;
	if(strlen(str1) < strlen(str2))
	{
		len = strlen(str1);
		ans = 1;
	}else
	{
		len = strlen(str2);
		ans = 2;
	}
	
	for(i=0;i<len;i++)
	{
		if(str1[i]>str2[i])
		{
			ans = 2;
			break;
		}else if(str1[i]<str2[i])
		{
			ans = 1;
			break;
		}
	}
	return ans;
}
int main(void)
{
	int num,len,i,j;
	char str[128];
	
	fgets(str,sizeof(str),stdin);
	sscanf(str,"%d %d",&num,&len);
	
	char matrix[num+2][len+2];
	
	for(i=0;i<num;i++)
	{
		fgets(&matrix[i],len+2,stdin);
	}
	for(i=0;i<num-1;i++)
	{
		for(j=0;j<num-i-1;j++)
		{
			if(dictionary(&matrix[j],&matrix[j+1]) == 2)
			{
				str_swap(&matrix[j],&matrix[j+1]);
			}
		}
	}
		
	for(i=0;i<num;i++)
	{
		for(j=0;j<len;j++)
		{
			printf("%c",matrix[i][j]);
		}
	}
		
	return 0;
}


Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60
const mod int = 1e9 + 7

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n, x := ri(), ri()

	ans := 0
	sum := 0
	for i := 0; i < n; i++ {
		l := ri()
		sum += l
		if sum <= x {
			ans++
		}
	}

	ans++
	fmt.Println(ans)
}


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

#define PI 3.14159265358979323

int main(void)
{
  double deg = 30;
  double ang = 90;
  double len = 2;
  double ansx = 0, ansy = 0;
  while (1) {
    scanf("%lf,%lf", &len, &deg);
	if (len == 0 && deg == 0)
		break;
    double rad = ang * PI / 180.0;
    double x = len * cos( rad );
    double y = len * sin( rad );
	ang = ang - deg;
//    printf( "X=%f Y=%f\n", x, y );
	ansx = ansx + x;
	ansy = ansy + y;
  }
  printf( "%.0f\n%.0f\n", floor(ansx), ceil(ansy) );

  return 0;
}

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

void Main() {
  map<char,ll> m;
  int n;
  R n;
  rep(i,n) {
    string s;
    R s;
    if(s[0]!='M'&&s[0]!='A'&&s[0]!='R'&&s[0]!='C'&&s[0]!='H') continue;
    m[s[0]]++;
  }
  vector<ll> v;
  tr(it,m) v.pb(it->S);
  ll ans=0;
  rep(i,v.size()) {
    REP(j,i+1,v.size()) {
      REP(k,j+1,v.size()) ans+=v[i]*v[j]*v[k];
    }
  }
  pr(ans);
}

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


Measured memory_bytes: 256
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() []byte {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return buf
}

type TBytes []byte

func (obj TBytes) HasSuffix(keys []TBytes) int {
	for _, k := range keys {
		if bytes.HasSuffix(obj, k) {
			return len(k)
		}
	}
	return -1
}

func main() {
	s := TBytes(readLine())
	keys := []TBytes{TBytes("dreamer"), TBytes("eraser"), TBytes("dream"), TBytes("erase")}
	for klen := 0; klen >= 0; klen = s.HasSuffix(keys) {
		s = s[0 : len(s)-klen]
	}
	if len(s) == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  int tmp = 0;
  for (int i = 0; i < n; i++) {
    tmp += s[i] == 'E';
  }
  vector<int> res;
  char cur = 'E';
  for (int i = 0; i < n; i++) {
    if (cur == 'W') tmp++;
    if (s[i] == 'E') tmp--;
    res.push_back(tmp);
    cur = s[i];
  }
  cout << *min_element(res.begin(), res.end()) << '\n';
  return 0;
}

Measured memory_bytes: 3724
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {
			int n = sc.nextInt();
			if (n == 0) return;
			HashMap<String, Integer> stoi = new HashMap<String, Integer>();
			HashMap<Integer, String> itos = new HashMap<Integer, String>();
			for (int i = 0; i < n; i++) {
				String s = sc.next();
				int p = sc.nextInt();
				stoi.put(s, p);
				itos.put(p, s);
			}

			int m = sc.nextInt();
			HashMap<String, ArrayList<String>> mix = new HashMap<String, ArrayList<String>>();
			for (int i = 0; i < m; i++) {
				String s = sc.next();
				int o = sc.nextInt();
				ArrayList<String> l = new ArrayList<String>();
				for (int j = 0; j < o; j++) l.add(sc.next());
				mix.put(s, l);
			}

			for (int i = 0; i < m; i++) {
				for (String key : mix.keySet()) {
					int cost = 0;
					for (int j = 0; j < mix.get(key).size(); j++) cost += stoi.get(mix.get(key).get(j));
					if (cost < stoi.get(key)) stoi.put(key, cost);
				}
			}
			System.out.println(stoi.get(sc.next()));
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 25724
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N, L; 
	int A[100010] = {};  
	cin >> N >> L; 
	for(int i = 0; i < N; i++){
		cin >> A[i]; 
	}
	int it = 114514; 
	int mn = 2145141919; 
	for(int i = 0; i < N-1; i++){
		if(A[i] + A[i+1] < mn && A[i] + A[i+1] >= L){
			mn = A[i] + A[i+1]; it = i+1; 
		}
	}
	if(it == 114514) cout << "Impossible" << endl; 
	else{
		cout << "Possible" << endl; 
		for(int i = 1; i < it; i++){
			cout << i << endl; 
		}
		for(int i = N-1; i >= it; i--){
			cout << i << endl; 
		}
	}
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e9+1;
int main(){
	int a,b,c;
	cin>>a>>b;
	for(int i=0;i<=maxn;i++){
		if(abs(a-i)==abs(b-i)) {
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
} 

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

#define INF 100000000


int main() {
	string s;
	cin >> s;
	int l = s.size();
	rep(i, l-1) {
		if (s[i] == s[i + 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
  
using namespace std;

int main() {
	int m;
	cin >> m;
	cout << 48 - m << endl;
	return 0;	
}

Measured memory_bytes: 256
N = int(input())
h = list(map(int,input().split()))

import numpy as np
import copy

h_np = np.array(copy.deepcopy(h))
length = len(h)

tmp_i = -1
count = 0
while(True):
    
    if np.sum(h_np>0) == 0:
        print(count)
        break
    
    for i in range(length):
        
        if h_np[i] > 0:
            if tmp_i == -1:
                tmp_i = i
            continue
        else:
            if tmp_i == -1:
                continue
            count += np.min(h_np[tmp_i:i])
            h_np[tmp_i:i] -= np.min(h_np[tmp_i:i])
            tmp_i = -1
    else:
        count += np.min(h_np[tmp_i:])
        h_np[tmp_i:] -= np.min(h_np[tmp_i:])
        tmp_i = -1

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<double> v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    sort(v.begin(),v.end());
    double now=v[0];
    for(int i=1;i<n;i++) now=(now+v[i])/2;
    cout << fixed << setprecision(14) << now << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define rep(i,n) for(i=0;i<n;i++)
int main(){
    int x,n,i,e,dif,ans=200;
    scanf("%d%d",&x,&n);
    int a[n],p[102]={0};
    rep(i,n){
        scanf("%d",&a[n]);
        p[a[n]]=1;
    }
    for(i=0;i<102;i++){
        if(p[i]==1) continue;
        dif=abs(x-i);
        if(ans>dif){
            e=i;
            ans=dif;
        }
    }
    printf("%d",e);
    return 0;
}

Measured memory_bytes: 1736
/** author: __nishad__ **/
//#pragma GCC optimize(2)
//#pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a,b) for(ll i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    string s1, s2;
    cin>>s1>>s2;

    string s3 = s2.assign(s2, 0, s2.size()-1);

    if(s3 == s1)
        cout<<"Yes";
    else
        cout<<"No";




}


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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

struct Program {
    int start, end;
    bool enable;
};

class CumulativeSum {
    vector<ll> numbers;
    vector<ll> sums;

public:
    CumulativeSum(int n) {
        numbers.resize(n);
        sums.resize(n);
    }

    void set(int i, ll value) {
        numbers[i] = value;
    }

    ll getSum(int i) {
        if (i == -1) return 0;
        if (i == sums.size()) return 0;
        return sums[i];
    }

    ll getSectionSum(int start, int end) {
        return getSum(end) - getSum(start - 1);
    }

    void calculate() {
        for (int i = 0; i < numbers.size(); i++) {
            sums[i] = getSum(i - 1) + numbers[i];
        }
    }

    int get_max() {
        return *max_element(sums.begin(), sums.end());
    }


};

int main() {
    int n, c;
    cin >> n >> c;
    vector<vector<Program>> programs(c);
    rep(i, n) {
        int s, t, ci;
        cin >> s >> t >> ci;
        ci--;
        Program p = {s, t, true};
        programs[ci].push_back(p);
    }

    rep(i, c) {
        sort(programs[i].begin(), programs[i].end(), [](Program &p, Program &q) {
            return p.start < q.start;
        });
    }

    rep(i, c) {
        for (int j = 1; j < programs[i].size(); j++) {
            if (programs[i][j - 1].end == programs[i][j].start) {
                programs[i][j].start = programs[i][j - 1].start;
                programs[i][j - 1].enable = false;
            }
        }
    }

    vector<int> times(200000, 0);
    rep(i, c) {
        for (Program &p : programs[i]) {
            if (!p.enable) continue;
            times[p.start - 1]++;
            times[p.end]--;
        }
    }

    CumulativeSum cs(200000);
    rep(i, 200000) cs.set(i, times[i]);
    cs.calculate();

    int ma = cs.get_max();
    cout << ma << endl;
}



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

using namespace std;

int main(){
	int n, m, s, t, q, i, j;
	int id, color = 0;
	bool answer_yes = false;

	// enter
	cin >> n >> m;
	vector< vector<int> > Adj(n);
	vector<int> Stack;
	vector<int> Check(n, 0);
	vector<int>::iterator it, itend;
	for (i = 0; i < m; i++) {
		cin >> s >> t;
		Adj[s].push_back(t);
		Adj[t].push_back(s);
	}

	// calculate
	for (i = 0; i < n; i++) {
		if (Check[i] == 0) {
			color++;
			Stack.push_back(i);
			Check[i] = color;
			while (!Stack.empty()) {
				id = Stack.back();
				itend = Adj[id].end();
				for (it = Adj[id].begin(); it != itend; it++) {
					if (!Check[*it]) {
						Stack.push_back(*it);
						Check[*it] = color;
						break;
					}
				}
				if (it == itend) {
					Stack.pop_back();
				}
			}
		}
	}

	//find
	cin >> q;
	for (i = 0; i < q; i++) {
		cin >> s >> t;		
		if (Check[s] == Check[t]) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	
	return 0;
}

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

int main(){
  string S;
  cin >> S;
  int N = S.size();
  int mi = 1e9;	
  for(int i=0; i<N-2; i++){
    string T = S.substr(i,3);
    int X = stoi(T);
    mi = min(mi,abs(753-X));
  }
  cout << mi << endl;
  return 0;
}


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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k,p;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>n>>m>>k>>p;

	if((k>=n && k<=m) && (m>=k && m<=p)) cout<<m-k<<endl;
	else if((k>=n && k<=m) && (m>=k && m>=p)) cout<<p-k<<endl;
	else if((n>=k && k<=p) && (p>=n && p<=m)) cout<<p-n<<endl;
	else if((n>=k && n<=p) && (p>=n && p>=m)) cout<<m-n<<endl;
	else cout<<0<<endl;




}


Measured memory_bytes: 256
n, k = map(int, input().split())
A = list(map(int, input().split()))
mod = 10**9+7

C1 = [0]*n
C2 = [0]*n

for i in range(n):
    for j in range(n):
        if A[i] > A[j]:
            if j >= i:
                C1[i] += k*(k+1)//2
            else:
                C2[i] += (k-1)*k//2
ans = 0
#print(C1)
#print(C2)
for i in range(n):
    ans += C1[i]+C2[i]
print(ans%mod)


Measured memory_bytes: 3280
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if(a <= 8 && b <= 8) cout << "Yay!" << endl;
  else cout << ":(" << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))

h.sort(reverse=True)
ans = []
for i in range(n):
    if i+k-1 >= n:
        break
    ans.append(abs(h[i] - h[i+k-1]))
print(min(ans))


Measured memory_bytes: 11244
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>


using namespace std;

#define rep(i,N) for(int i=0;i<N;i++) //0から
#define REP(i,N) for(int j=i;j<N;j++) //iから

typedef long long ll;




ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
    vector<ll> p(n,0);
    p[0]=1;
    p[1]=1;
    for(ll i=2;i<n;i++){
        if(p[i]==0){
            prime.push_back(i);
            p[i]=i;
        }
        ll k=prime.size();
        for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
            p[i*prime[j]]=prime[j];
        }
    }
}

#define MOD ((ll)1e+9 + 7)




//cout<<fixed<<setprecision(10);
int main(){
    int a,p,n;
    cin>>a>>p;
    n=3*a+p;
    cout<<n/2<<endl;

    return 0;
}



Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp(a,b) std::make_pair(a,b)
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::pair<int,ll> pil;
typedef std::vector<int> vi;
typedef std::vector<pil> vil;
const int INF=1e+9;
const ll INFLL=1e+17;
int N;
int u[100010],v[100010];
ll w[100010];
vil edge[100010];
ll d[100010];
bool F[100010];
void add_edge(int from,int to,ll cost){
  edge[from].push_back(mp(to,cost));
  edge[to].push_back(mp(from,cost));  
}
void bfs(){
  rep1(i,N) d[i]=INFLL;
  std::queue<pil> q;
  q.push(mp(u[0],0));
  d[u[0]]=0;
  while(!q.empty()){
    pil p=q.front();q.pop();
    int f=p.first;
    ll s=p.second;
    rep(i,edge[f].size()){
      pil pp=edge[f][i];
      int ff=pp.first;
      ll ss=pp.second;
      if(d[ff]==INFLL){
	d[ff]=s+ss;
	q.push(mp(ff,d[ff]));
      }
    }
  }
}
void solve(){
  rep(i,N-1) add_edge(u[i],v[i],w[i]);
  bfs();
  rep1(i,N){
    if(d[i]%2==0) prin(0);
    else prin(1);
  }
}
int main(){
  cin>>N;
  rep(i,N-1) cin>>u[i]>>v[i]>>w[i];
  solve();
  // rep1(i,N) prin2(i,d[i]);
  return 0;
}


Measured memory_bytes: 10240
from itertools import combinations
nx = []
while 1:
    i = list(map(int, input().split()))
    if i[0]==0:
        break
    nx.append(i)

for j in nx:
    ans = 0
    n,x = j[0], j[1]
    for i in combinations(range(1,n+1), 2):
         c = x - sum(i)
         if c<=0 or c>n: continue
         if c==i[0] or c==i[1]: continue
         ans += 1
    print(int(ans/3))




Measured memory_bytes: 5640
#include <stdio.h>
int main(void)
{
	int a,b;

	scanf("%d %d",&a,&b);

	if(a<b)
	{
		printf("a < b\n");
	}

	if(a>b)
	{
		printf("a > b\n");
	}

	if(a==b)
	{
		printf("a == b\n");
	}

	return 0;
}

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

string S;

int main() {
	cin >> S;
	string ans;
	for (int i = 0; i < S.size(); i++) {
		if ((i + 1) % 2 == 1) {
			ans += S.substr(i, 1);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
/*AOJ 0025*/

#include<iostream>

using namespace std;

int Hit(int *a,int *b){
	int sum=0;

	for(int i=0;i<4;i++){
		if(a[i] == b[i]){
			sum++;
		}
	}

	return sum;
}

int Blow(int *a,int *b){

	int sum = 0;
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			if(i==j){
				continue;
			}
			if(a[i] == b[j]){
				sum++;
				break;
			}
		}
	}

	return sum;
}

int main(){

	int a[4],b[4];

	while(cin>>a[0]){
		for(int i=1;i<4;i++){
			cin>>a[i];
		}
		for(int i=0;i<4;i++){
			cin>>b[i];
		}

		cout<<Hit(a,b)<<" "<<Blow(a,b)<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#encoding: utf-8

$map = []
$vis = [false] * 100
$depth = [-1] * 100
$vis = [false] * 100
def build_map
  $n = gets.rstrip.to_i
  $map = []
  $n.times { $map << [0] * $n}
  (1..$n).each do |node|
    arr = gets.rstrip.split(/\s/).map(&:to_i)
    u, k = arr[0], arr[1]
    node = arr[2..-1]
    node.each { |v| $map[u - 1][v - 1] = 1}
  end
end

def bfs(x)
  $depth[x] = 0
  que = [x]
  $vis[x] = true
  while not que.empty?
    u, que = que.first, que.drop(1)
    $map[u].each_with_index do |node, idx|
      if node == 1 and not $vis[idx]
        $depth[idx] = $depth[u] + 1
        $vis[idx] = true
        que << idx
      end
    end
  end
end

def solve
  build_map
  bfs(0)
end

solve

(0..$n - 1).each do |node|
  puts "#{node + 1} #{$depth[node]}"
end

Measured memory_bytes: 6192
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long h, long long a){
    cout << (h + a - 1) / a << endl;
}


signed main(){
    long long H;
    scanf("%lld",&H);
    long long A;
    scanf("%lld",&A);
    solve(H, A);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#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 MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(void){
    int N;cin>>N;
    V<pair<int,int>> a(N);
    REP(i,N){
        int b;cin>>b;
        a[i].F=b;
        a[i].S=i+1;
    }
    sort(All(a));
    REP(i,N)cout<<a[i].S<<endl;
}

Measured memory_bytes: 1536
"use strict"

//最大公約数を求める
const gcd = (m, n) => {
  if (n === 0) return m

  return gcd(n, m % n)
}

function main(input) {
  input = input.split(/\n/).map(v => v.split(/\s/).map(v => ~~v))
  const X = input[0][1]
  const distance = input[1].sort((a, b) => a - b).map(v => {
    return v - X
  })
  const ans = distance.reduce((a, b) => {
    return gcd(a, b)
  })
  console.log(Math.abs(ans))
}
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 26956
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    int c = 1;
    rep(i, M) c *= 2;
    cout << (1900 * M + 100 * (N - M)) * c << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		int n;
		cin>>n;
		int a[n+1];
		rep(i,1,n+1) cin>>a[i];
		int dp[n+1][n+1];
		rep(i,0,n+1){
			rep(j,0,n+1)
				dp[i][j] = INF;
			dp[i][i]=0;
		}
		int cum[n+1];
		cum[0] = 0;
		rep(i,1,n+1) cum[i] = cum[i-1]+a[i];
		rep(i,1,n)
			dp[i][i+1] = a[i]+a[i+1];
		rep(gap,2,n){
			rep(l,1,n-gap+1){
				int r = l+gap;
				// dp[l][r] = INF;
				rep(k,l,r)
				dp[l][r] = min(dp[l][r], dp[l][k]+dp[k+1][r]+cum[r]-cum[l-1]);
			}
		}
		// rep(i,1,n){
		// 	rep(j,i+1,n+1)
		// 		cout<<dp[i][j]<<" ";
		// 		cout<<endl;
		// }
		cout<<dp[1][n];
	}   
}     


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

int main()
{
	string s1, s2;
	int n = 0;
	int a = 0;
	int b = 0;

	cin >> n;
	for ( int i = 0; i <n; i++ )
	{
		cin >> s1 >> s2;
		if ( s1 > s2 )
		{
			a = a + 3;
		}
		else
		{
			if ( s1 < s2 )
			{
				b = b + 3;
			}
			else
			{
				a++;
				b++;
			}
		}
	}

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

	return 0;
}


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

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)1e5 + 5;

ll a[MAXN], b[MAXN];

int n;

void solve() {                   
	scanf("%d", &n);

    for (int i = 1; i <= n; ++i) {
    	scanf("%lld %lld", &a[i], &b[i]);
    }

    ll sum = 0;

    for (int i = n; i > 0; --i) {
		a[i] += sum;

		if (a[i] % b[i]) {
			ll nxt = (a[i] / b[i] + 1) * b[i];
			sum += (nxt - a[i]);
		}                   
    }

    printf("%lld\n", sum);
}    	

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))

total_costs = {}
if( len(set(A)) == 1 ):
    print(0)
else:
    for i in range(-100, 101):
        cost = 0
        for a in A:
            cost += (a - i)**2
        total_costs[i] = cost
    print(min(total_costs.values()))

Measured memory_bytes: 3064
n = gets.to_i
g = Array.new(n+1){Array.new}
(n-1).times do |i|
  u,v,w = gets.chomp.split(" ").map(&:to_i)
  g[u].push([v,w])
  g[v].push([u,w])
end
dist = Array.new(g.length,-1)
dist[1] = 0
queue = [1]
while !queue.empty?
  v = queue[0]
  queue.shift
  g[v].each{|des|
    if dist[des[0]] == -1
      #if des[1]%2 == 0 && dist[v] == 0
      dist[des[0]] = des[1]%2 ^ dist[v]
      queue.push(des[0])
    end
   }
 end
 n.times do |i|
   puts dist[i+1]
 end


Measured memory_bytes: 33860
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> t(N+1), x(N+1), y(N+1);
	t[0] = 0;
	x[0] = 0;
	y[0] = 0;
	for (int i = 1; i <= N; i++) cin >> t[i] >> x[i] >> y[i];
	for (int i = 0; i < N; i++) {
		int distance = abs(x[i] - x[i + 1]) + abs(y[i] - y[i + 1]);
		int tt = t[i + 1] - t[i];
		if (tt - distance < 0 || (tt - distance) % 2 != 0) {
			cout << "No" << endl;
			system("pause");
			return 0;
		}
	}

	cout << "Yes" << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 1656