akhauriyash/Code-Regression huggingface dataset:
// Author: getharshkumar

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

double sq(double a)
{
    return a * a;
}
double dist(pair<ll, ll> a, pair<ll, ll> b)
{
    return sqrt(sq(a.first - b.first) + sq(a.second - b.second));
}
ll fact(ll a)
{
    if (!a)
        return 1;
    return a * fact(a - 1);
}
int main()
{
    int n;
    cin >> n;
    vector<pair<ll, ll>> x(n);
    vector<ll> v(n);
    iota(v.begin(), v.end(), 0);
    for (ll i = 0; i < n; i++)
        cin >> x[i].first >> x[i].second;
    double s = 0, c = 0;
    do
    {
        for (ll i = 1; i < n; i++)
            s += dist(x[v[i]], x[v[i - 1]]);
        c++;
    } while (next_permutation(v.begin(), v.end()));
    cout << setprecision(15) << s / fact(n);
    return 0;
}

Measured memory_bytes: 256
tmp =[]
for i in range(4):
    array = int(input())
    tmp.append(array)

A=tmp[0]
B=tmp[1]
C=tmp[2]
x=tmp[3]

ans=0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if 500*a + 100*b + 50*c == x:
                ans+=1
print(ans)

Measured memory_bytes: 3064
import sys
from itertools import accumulate

def solve():
    n, m, q = map(int, input().split())
    s = [[int(j) for j in input()] for i in range(n)]

    # 青マスの2次元累積和
    sxy = [list(accumulate(s[i])) for i in range(n)]

    for j in range(m):
        for i in range(n - 1):
            sxy[i + 1][j] += sxy[i][j]

    # 枝の2次元累積和(2n * 2mで管理)
    exy = [[0]*(2*m) for i in range(2*n)]

    for i in range(2*n - 1):
        if i % 2 == 0:
            for j in range(2*m - 1):
                exy[i][j + 1] += exy[i][j]
                if j % 2 == 0 and j < 2*m - 2:
                    exy[i][j + 1] += (s[i//2][j//2] == s[i//2][j//2 + 1] == 1)
        else:
            for j in range(2*m - 1):
                if j % 2 == 0:
                    exy[i][j] += (s[i//2][j//2] == s[i//2 + 1][j//2] == 1)

                exy[i][j + 1] += exy[i][j]

    for j in range(2*m):
        for i in range(2*n - 1):
            exy[i + 1][j] += exy[i][j]

    '''
    for i in range(2*n):
        print(exy[i], file=sys.stderr)
    '''

    for qi in range(q):
        x1, y1, x2, y2 = map(lambda x: x - 1, map(int, sys.stdin.readline().split()))

        nv = sxy[x2][y2]

        if x1 - 1 >= 0:
            nv -= sxy[x1 - 1][y2]
        if y1 - 1 >= 0:
            nv -= sxy[x2][y1 - 1]
        if x1 - 1 >= 0 and y1 - 1 >= 0:
            nv += sxy[x1 - 1][y1 - 1]

        ne = exy[2*x2][2*y2]

        if 2*x1 - 1 >= 0:
            ne -= exy[2*x1 - 1][2*y2]
        if 2*y1 - 1 >= 0:
            ne -= exy[2*x2][2*y1 - 1]
        if 2*x1 - 1 >= 0 and 2*y1 - 1 >= 0:
            ne += exy[2*x1 - 1][2*y1 - 1]

        ans = nv - ne

        print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 237192
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,o,p,q,i,j,k;
   char a[101][101],tmp[101];
   cin>>n>>m;
   getchar();
   for(i=0;i<n;i++)
   {
       scanf("%[^\n]%*c",a[i]);
   }
   for(i=0;i<n;i++)
    {
        for (j=i+1;j<n;j++)
        {
            if ((strcmp(a[i],a[j])>0))
            {
                strcpy(tmp,a[i]);
                strcpy(a[i],a[j]);
                strcpy(a[j],tmp);
            }
        }
    }
    for(i=0;i<n;i++)
    {
        cout<<a[i];
    }
    cout<<endl;


    return 0;
}


Measured memory_bytes: 256
#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 rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
            #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
            #define endl "\n"
            #define pb push_back
            #define F first
            #define S second
            #define print(a)       for(auto x : a) cout << x << " "; cout << endl
            #define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
            #define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl
            #define mk(x,y)  make_pair(x,y)
            typedef long long int ll;
            const ll N =  1e6+5;
            const ll mod = 1e9+7;
            const ll inf = 1e18;
            ll   n  , k  , m  , l , r  , x , y  , q , u , z  , a[N];

    ll pow_mod_m(ll a , ll n)
    {
        if(!n)
            return 1;
        ll pt =  pow_mod_m(a,n/2);
        pt *= pt ;
        if(n&1)
            pt *= a ;
        return pt;
    }

    int main()
    {
         IOS;
         int ts =1;
         ///  cin >> ts ;
         while(ts--)
         {
            cin >> n;
            string s;
            cin >> s;
            vector <ll > v;
            rep(i,0,n)
            {
                if(s[i] == 'R'){
                v.pb(i);
                }
            }
            m = v.size();
            ll ans = 0;
            bool f = 1;
            rep(i,0,n)
            {
                while(i < n and s[i] == 'W')
                {
                    if(m-1 >= 0 and v[m-1] >= i)
                    {
                        ///cout << " current i and v[m-1] : " << i << " " << v[m-1] << endl;
                        ans++ ,m--;
                    }
                    else
                    {
                        f = 0;
                        break;
                    }
                    i++;
                }
                if(!f)
                    break;
            }
            cout << ans << endl;
         }
    }


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

int main() {

    int n;
    using ll = long long;

    cin >> n;

    ll sum = 0;

    for(int i = 1; i <= n; ++i) {

        if(i % 3 == 0 || i % 5 == 0)
            continue;
        
        sum += i;

    }

    cout << sum << endl;

    return 0;


}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n;
  while(cin >> n,n) {
    vector<bool> card(2*n);
    REP(i,n) {
      int a;
      cin >> a;
      a--;
      card[a] = 1;
    }
    set<int> taro, hanako;
    REP(i,2*n) {
      if (card[i]) taro.insert(i+1);
      else hanako.insert(i+1);
    }
    int ba = 0;
    int ta = 0, ha = 0;
    while (taro.size() && hanako.size()) {
      // taro
      set<int>::iterator it = taro.lower_bound(ba);
      if (it != taro.end()) {
        ba = *it;
        taro.erase(it);
      } else ba = 0;
      // hanako
      if (taro.size() == 0) {
        ta = hanako.size();
        break;
      }
      it = hanako.lower_bound(ba);
      if (it != hanako.end()) {
        ba = *it;
        hanako.erase(it);
      } else ba = 0;
      if (hanako.size() == 0) {
        ha = taro.size();
        break;
      }
    }
    cout << ta << endl;
    cout << ha << endl;
  }
}

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

using namespace std;

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

	vector<string> S(N);

	for (int i = 0; i < N; i++) {
		cin >> S.at(i);
	}

	sort(S.begin(), S.end());
	S.erase(unique(S.begin(), S.end()), S.end());

	cout << S.size() << endl;

	return 0;
}

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

int main(){
	int n;
	cin >>n;
	if (n==3||n==5||n==7)
		cout <<"YES"<<endl;
	else
		cout <<"NO"<<endl;
}

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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e15;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

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

    int n, W;//, V = 0;
    cin >> n >> W;

    vector<int> w(n), v(n), dp(N, INF);
    for (int i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
        //V += v[i];
    }

    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = N - 1; j >= 0; j--) {
            if (dp[j] != INF and j + v[i] < N) {
                dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (dp[i] <= W) {
            ans = max(ans, i);
        }
    }

    cout << ans << "\n";
    return 0;
}


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

int main(){
	int a,b;
  	cin >> a >> b;
  
  	if ((a*b)%2==0){
    	cout << "Even" << endl;
    }
  
  	else{
    	cout << "Odd" << endl;
    }
  
  return 0;
}

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

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

using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<char> alp(0);
	for (char c = 'a'; c <= 'z'; c++) { alp.push_back(c); }
	for (char c = 'A'; c <= 'Z'; c++) { alp.push_back(c); }
	int n; while ( cin >> n && n != 0 )
	{
		vector<int> dat(n + 2, 0);
		rep(i, n) { cin >> dat[i]; }
		string str; cin >> str;
		int lp1 = 0, lp2 = 0;
		while (1)
		{
			if (lp1 == n) { lp1 = 0; }
			if (lp2 == (int)str.size()) { break; }
			cout << alp[(find(all(alp), str[lp2]) - alp.begin() - dat[lp1] + alp.size()) % alp.size()];
			lp1++; lp2++;
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 3144
n = int(input())
a = [int(i) for i in input().split()]
sum_a = sum(a)
x = [0]*(n+1)
for i in range(n):
    x[i+1] = x[i] + a[i]
x = [abs(sum_a - (2*xx)) for xx in x]
x = x[1:n]
print(min(x))

Measured memory_bytes: 26684
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {  
    int n;
    cin >> n;
    string s;
    cin >> s;
    int res = 0;
    int c = 0;
    for (auto ss : s) {
        if (ss == 'I') {
            c++; 
        } else {
            c--;
        }
        res = max(res, c);
    }
    cout << res << endl;
}




Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();	
	int M, K;
	cin >> M >> K;
	if (K >= (1 << M)) {
		cout << -1 << endl;
	}
	else if (M == 1) {
		if (K == 0) {
			for (int i = 0; i <= 1; i++) {
				cout << i << " " << i << " ";
			}
			cout << endl;
		}
		else {
			cout << -1 << endl;
		}
	}
	else {
		vector<int> ans;
		vector<int> rans;
		for (int i = 0; i < (1 << M); i++) {
			if (i == K)  continue;
			ans.push_back(i);
		}
		rans = ans;
		reverse(rans.begin(), rans.end());
		cout << K << " ";
		for (int num : ans) cout << num << " ";
		cout << K << " ";
		for (int num : rans) cout << num << " ";
		cout << endl;
	}
}

Measured memory_bytes: 5284
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;

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

    int n;
    cin>>n;

    vector<int> x(n+1);
    long long sum=0;
    for(int i=1;i<=n;i++){
        cin>>x[i];
        sum+=x[i];
    }

    sum/=n;
    int ans=0,ans1=0;
    for(int i=1;i<=n;i++){
        ans+=(sum-x[i])*(sum-x[i]);
        ans1+=(sum+1-x[i])*(sum+1-x[i]);
    }

    cout<<min(ans,ans1)<<"\n";

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for(int i=(l); i<(r); ++i)
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

// 逆からみるのは一応典型っぽい
// あとはあまり手がかりがないので、綺麗な形が答えとして採用できるのかな

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

    ll k; cin >> k;
    vector<ll> ans(50, 0);
    ll n = 50;

    rep(i, 0, n) ans[i] = i + k/n;

    ll r = k%n;
    rep(i, 0, n){
        if(i < r) ans[i] += n-r+1;
        else ans[i] -= r;
    }

    cout << 50 << '\n';
    rep(i, 0, n){
        if(i) cout << ' ';
        cout << ans[i];
    }
    cout << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <algorithm>

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
inline int lcm(int a,int b){return a*b/gcd(a,b);}
typedef long long ll;
typedef std::vector<int> VI;
typedef std::pair<int, int> PII;

double EPS = 0.000001;

using namespace std;

const ll mod = 2019;
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x+=a.x)>=mod) x-=mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x+=mod-a.x)>=mod) x-= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};


int main()
{
  int L, R;
  cin >> L >> R;
  ll ans = 2018;
  R = min(L+2030, R);
  for (ll i = L; i < R; i++)
    for (ll j = i+1; j<= R;j++)
    {
      mint t = mint(i)*mint(j);
      if (t.x < ans) ans = t.x;
      if (ans == 0) break;
    }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
#define MOD 1000000007

int main()
{

  ll x;
  cin >> x;

  long long a = 100;
  ll cnt = 0;
  while (true)
  {
    a *= 1.01;
    cnt++;
    if (a >= x)
    {
      cout << cnt << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 3636
n,k=map(int,input().split())
a=list(input().split())
ans=0
for i in range(n,100001):
  cnt=list(str(i))
  for j in range(len(cnt)):
    if cnt[j] in a:
      ans=1
      break
  if ans==0:
    print(i)
    exit()
  else:
    ans=0
    continue
    
  
  

Measured memory_bytes: 9116
#include <iostream>
#include <string>

class Baseball{
	int point,out_count,runner;
public:
	Baseball(){
		point = 0;
		out_count = 0;
		runner = 0;
	}
	void game();
	void single_hit();
	void homerun();
	void out();
	int get_point(){ return point; }
	int get_out(){ return out_count; }
};

void Baseball::game(){
	std::string event;
	while(std::cin >> event){
		if(event == "HIT"){
			single_hit();
		}else if(event == "HOMERUN"){
			homerun();
		}else if(event == "OUT"){
			out();
		}
		if(get_out() == 3){
			break;
		}
	}
}

void Baseball::single_hit(){
	++runner;
	if(runner == 4){
		++point;
		--runner;
	}
}

void Baseball::homerun(){
	++runner;
	point += runner;
	runner = 0;
}

void Baseball::out(){
	++out_count;
}

int main(){
	int inning;
	std::cin >> inning;
	for(int i = 0; i < inning; ++i){
		Baseball baseball;
		baseball.game();
		std::cout << baseball.get_point() << std::endl;
	}
	return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string n;
  cin >> n;
  rep(i, n.size()-2) {
    if(n[i] == n[i+1] && n[i] == n[i+2]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, n, m, ans = 0, a, b, t, nowx, nowy;
  scanf("%lld%lld", &n, &m);
  set<ll> x, y;
  set<ll>::iterator it;
  pair<ll, pair<ll, ll> > vx[m], vy[n];
  for(i = 0; i < n; ++i) {
    scanf("%lld%lld%lld", &vy[i].second.first, &vy[i].second.second, &vy[i].first);
    x.insert(vy[i].second.first), x.insert(vy[i].second.second);
    y.insert(vy[i].first);
  }
  for(i = 0; i < m; ++i) {
    scanf("%lld%lld%lld", &vx[i].first, &vx[i].second.first, &vx[i].second.second);
    y.insert(vx[i].second.first), y.insert(vx[i].second.second);
    x.insert(vx[i].first);
  }
  a = x.size(), b = y.size();
  ll px[a], py[b];
  ll lx[a][b], ly[a][b], flg[a][b];
  for(i = 0, it = x.begin(); it != x.end(); ++i, ++it) px[i] = *it;
  for(i = 0, it = y.begin(); it != y.end(); ++i, ++it) py[i] = *it;
  for(i = 0; i < a; ++i) for(j = 0; j < b; ++j) lx[i][j] = ly[i][j] = flg[i][j] = true;
  for(i = 0; i < m; ++i) {
    t = lower_bound(px, px + a, vx[i].first) - px;
    for(j = lower_bound(py, py + b, vx[i].second.first) - py; j < b && py[j] < vx[i].second.second; ++j) lx[t][j] = false;
  }
  for(i = 0; i < n; ++i) {
    t = lower_bound(py, py + b, vy[i].first) - py;
    for(j = lower_bound(px, px + a, vy[i].second.first) - px; j < a && px[j] < vy[i].second.second; ++j) ly[j][t] = false;
  }
  queue< pair<ll, ll> > q;
  nowx = lower_bound(px, px + a, 0) - px - 1, nowy = lower_bound(py, py + b, 0) - py - 1;
  q.push(make_pair(nowx, nowy));
  while(q.size()) {
    nowx = q.front().first, nowy = q.front().second;
    q.pop();
    if(nowx < 0 || nowx > a - 2 || nowy < 0 || nowy > b - 2) {
      printf("INF");
      return 0;
    }
    if(!flg[nowx][nowy]) continue;
    flg[nowx][nowy] = false;
    ans += (px[nowx + 1] - px[nowx]) * (py[nowy + 1] - py[nowy]);
    if(lx[nowx][nowy]) q.push(make_pair(nowx - 1, nowy));
    if(ly[nowx][nowy]) q.push(make_pair(nowx, nowy - 1));
    if(lx[nowx + 1][nowy]) q.push(make_pair(nowx + 1, nowy));
    if(ly[nowx][nowy + 1]) q.push(make_pair(nowx, nowy + 1));
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 214556
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;
const int inf = 2e9;

void print() { cout << endl; }
template <typename Head, typename... Tail>
void print(Head head, Tail... tail) {
    int size = sizeof...(Tail);
    cout << head;
    if (size > 0) {
        cout << " ";
    }
    print(tail...);
}

using edge = pair<int, int>;
void dfs(int u, vector<vector<edge>>& edges, vector<int>& a, vector<bool>& done, vector<int>& dp, stack<pair<int, int>>& reverse, vector<int>& result) {
    done[u] = true;
    int toinsert = lower_bound(dp.begin(), dp.end(), a[u]) - dp.begin();

    reverse.push({toinsert, dp[toinsert]});
    dp[toinsert] = a[u];

    result[u] = lower_bound(dp.begin(), dp.end(), inf) - dp.begin();

    for (auto e : edges[u]) {
        if (!done[e.second]) {
            dfs(e.second, edges, a, done, dp, reverse, result);
        }
    }

    pair<int, int> r = reverse.top();
    reverse.pop();
    dp[r.first] = r.second;
}

int main() {
    int N;
    cin >> N;
    vector<int> a(N, -1);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    vector<vector<edge>> edges(N);
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        edges[u].push_back(make_pair(u, v));
        edges[v].push_back(make_pair(v, u));
    }

    vector<bool> done(N, false);
    vector<int> result(N, -1);
    vector<int> dp(N, inf);
    stack<pair<int, int>> reverse;
    dfs(0, edges, a, done, dp, reverse, result);
    for (int i = 0; i < N; i++) {
        print(result[i]);
    }
}


Measured memory_bytes: 41012
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

struct Range {
    int len, left, right;
};

bool sort_by_len(const Range &a, const Range &b) {
    return a.len < b.len;
}

struct LazySegmentTree {
private:
    int n;
    vector <ll> node, lazy;
public:
    LazySegmentTree(int sz) {
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);
    }
    void eval(int k, int l, int r) {
        if (lazy[k] > 0) {
            node[k] += lazy[k];
            if (r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }
    void add(int a, int b, int val, int k=0, int l=0, int r=-1) {
        if (r < 0) r = n;
        eval(k, l, r);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b) {
            lazy[k] += val * (r - l);
            eval(k, l, r);
        } else {
            add(a, b, val, 2*k+1, l, (l+r)/2);
            add(a, b, val, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }
    ll get(int a, int k=0, int l=0, int r=-1) {
        if (r < 0) r = n;
        eval(k, l, r);
        if (r <= a || a < l) return 0;
        if (a == l && r == a + 1) return node[k];
        ll vl = get(a, 2*k+1, l, (l+r)/2);
        ll vr = get(a, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;

    vector <Range> vec(n);
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        vec[i] = (Range) {r-l+1, l, r};
    }

    sort(vec.begin(), vec.end(), sort_by_len);

    int idx = 0;
    LazySegmentTree seg(m + 1);
    for (int d = 1; d <= m; d++) {
        while (idx < n && vec[idx].len < d) {
            seg.add(vec[idx].left, vec[idx].right + 1, 1);
            idx++;
        }

        int ans = n - idx;
        for (int i = d; i <= m; i += d) ans += seg.get(i);
        cout << ans << "\n";
    }

    return 0;
}

Measured memory_bytes: 10624
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

int main() {
	ll N; cin >> N;
	vector<ll> A(N); rep(i, N)cin >> A[i];

	ll cnt[N + 1] = {};
	rep(i, N)cnt[A[i]]++;

	ll ans = 0;
	rep(i, N+1) {
		ans += C(cnt[i]);
	}

	ll tmp = ans;
	for (int k = 0; k < N; k++) {
		ans = tmp;
		ans -= C(cnt[A[k]]);
		ans += C(cnt[A[k]] - 1);
		cout << ans << endl;
	}
}

Measured memory_bytes: 5760
#include<stdio.h>

int main(){
    int a[3], i, buff;
    scanf("%d %d %d", &a[0], &a[1], &a[2]);

	int task[6];
	int dis[3];//1: 2-1 ,2: 3-1, 3: 3-2 	


	if(a[0] >= a[1]){
		dis[0] = a[0] -a[1];
	}else{
		dis[0] = a[1] - a[0];
	}

	if(a[2] >= a[0]){
		dis[1] = a[2] -a[0];
	}else{
		dis[1] = a[0] - a[2];
	}

	if(a[1] >= a[2]){
		dis[2] = a[1] -a[2];
	}else{
		dis[2] = a[2] - a[1];
	}

	for(i=0; i<2; i++){
		if(dis[i+1]<dis[i]){
			buff = dis[i];
			dis[i] = dis[i+1];
			dis[i+1] = buff;
		}
	}

	printf("%d\n", dis[0] + dis[1]);

    return 0;
}

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


int main() {

	int N;
    cin >> N;

    string S;
    cin >> S;

    if((int)S.size() % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }

    int size = (int)S.size() / 2;
    string a = S.substr(0, size);
    string b = S.substr(size);

    if(a == b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }



	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void)
{
	int a,b,c,d,e,f,g,h;
	cin>>a>>b>>c>>d>>e;
	f=a*e;
	if (e<c)
	{
		g=b;
	}
	else if(e>c)
	{
		g=b+(e-c)*d;
	}
	if (g<f)
	{
		cout<<g<<endl;
	}
	else if (g>f)
	{
		cout<<f<<endl;
	}
	return 0;
}

Measured memory_bytes: 3076
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element? {
        return self.maxElement()
    }
    func min() -> Element? {
        return self.minElement()
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
//    func enumerated() -> [(Int, Element)] {
//        return self.enumerate()
//    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/

//func gcd(x: Int, _ y: Int) -> Int {
//    if y == 0 {
//        return x
//    } else {
//        return gcd(y, x%y)
//    }
//}
//func lcm(x: Int, _ y: Int) -> Int {
//    return x * y / gcd(x, y)
//}

/*************** メインプログラム ***************/

let input = readIntSplit(by: " ")
var (r, D, x) = (input[0], input[1], input[2])
for _ in 0..<10 {
    x = r * x - D
    print(x)
}


Measured memory_bytes: 7908
s = input().rstrip("\n")
t = input().rstrip("\n")

# dp[i][j]: sのi文字目までとtのj文字目まででのLCSの長さ
dp = [[0] * (len(t)+1) for _ in range(len(s)+1)]

# 任意のwについて、
# 初期条件は、dp[0][w] = 0, dp[w][0] = 0

# 貰うdpでLCSを求める
for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1)
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])

# LCSとなる文字列の復元
answer = ""
i,j = len(s),len(t)
while i > 0 and j > 0:
    # dp[i-1][j] -> dp[i][j]と更新されていた場合
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    # dp[i][j-1] -> dp[i][j]と更新されていた場合
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    # dp[i-1][j-1] -> dp[i][j]と更新されていた場合
    else:
        # s[i-1] == t[i-1] なので
        # char = t[i-1]でも OK
        char = s[i-1]
        answer = char + answer
        i -= 1
        j -= 1

print(answer)

Measured memory_bytes: 113628
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define fo(i,n) for(int i=0;i<n;i++)
#define eb emplace_back
#define M 1000000007
#define vi vector<int>
#define vlli vector<lli>
#define pi pair<int,int>
#define mp make_pair
#define mapi map<int,int>
int main()
{
  //ios_base::sync_with_stdio(false);
  //cin.tie(NULL);
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	lli b[n+1];
	for(int i=0;i<n;i++)
	   b[i]=10000000001;
	b[0]=0;;
	int x,diff;
	for(int i=1;i<n;i++)
	{
		x=1;
		while(x<=k && i-x>=0 )
		{
			diff=abs(a[i]-a[i-x]);
			b[i]=min(b[i],b[i-x]+diff);
			x++;
		}
	}
	cout<<b[n-1];
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

template<typename T> class BinaryIndexedTree2D {
  vector< vector<ll> > vec;
  const ll m, n;

public:
  BinaryIndexedTree2D(ll _m, ll _n) : vec(_m + 1, vector<T>(_n + 1)), m(_m), n(_n) {}

  T query(ll y, ll x) { /* query for [(1, 1), (y, x)] */
    T ret = 0;
    for(ll i = y; i > 0; i -= i & (-i))
      for(ll j = x; j > 0; j -= j & (-j))
        ret += vec[i][j];
    return ret;
  }

  void update(ll y, ll x, T k) { /* update for [(1, 1,), (y, x)] */
    for(ll i = y; i <= m; i += i & (-i))
      for(ll j = x; j <= n; j += j & (-j))
        vec[i][j] += k;
  }
};

struct event {
  ll t, c, h1, w1, h2, w2;

public:
  bool operator<(const event &e) const { return t > e.t; }
};

ll H, W, T, Q;

int main(void) {
  priority_queue<event> q;

  cin >> H >> W >> T >> Q;
  REP(i, 0, Q) {
    ll t, c, h1, w1, h2, w2;
    cin >> t >> c >> h1 >> w1;
    if(c == 2) cin >> h2 >> w2;
    else h2 = 0, w2 = 0;
    q.push((event) { t * 2, c, h1, w1, h2, w2 });
  }

  BinaryIndexedTree2D<ll> bit1(H, W);
  BinaryIndexedTree2D<ll> bit2(H, W);
  ll f[H + 1][W + 1];
  REP(i, 1, H + 1) REP(j, 1, W + 1) f[i][j] = 0;

  while(!q.empty()) {
    event e = q.top();
    q.pop();

    // cout << e.t << " " << e.c << " " << e.h1 << " " << e.w1 << " " << e.h2 << " " << e.w2 << endl;

    if(e.c == 0) { // set
      bit1.update(e.h1, e.w1, 1);
      q.push((event) { e.t + T * 2 - 1, 3, e.h1, e.w1, 0, 0 });
      f[e.h1][e.w1] = 1;
    }
    if(e.c == 1) { // remove
      if(f[e.h1][e.w1] == 2) {
        bit2.update(e.h1, e.w1, -1);
        f[e.h1][e.w1] = 0;
      }
    }
    if(e.c == 2) { // query
      ll ans1 = bit1.query(e.h2, e.w2) - bit1.query(e.h1 - 1, e.w2) - bit1.query(e.h2, e.w1 - 1) + bit1.query(e.h1 - 1, e.w1 - 1);
      ll ans2 = bit2.query(e.h2, e.w2) - bit2.query(e.h1 - 1, e.w2) - bit2.query(e.h2, e.w1 - 1) + bit2.query(e.h1 - 1, e.w1 - 1);
      cout << ans2 << " " << ans1 << endl;
    }
    if(e.c == 3) { // complete
      if(f[e.h1][e.w1] == 1) {
        bit1.update(e.h1, e.w1, -1);
        bit2.update(e.h1, e.w1, 1);
        f[e.h1][e.w1] = 2;
      }
    }
  }
}

Measured memory_bytes: 101464
#include <iostream>
using namespace std;
 
int r, g, b;
 
int main(){
  std::cin >> r >> g >> b;
  if((100 * r + 10 * g + b)%4 == 0) std::cout << "YES" << std::endl;
  else std::cout << "NO" << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
import sys

n, m = map(int, input().split())

s = [0]*m
c = [0]*m

for i in range(m):
    s[i], c[i] = map(int, input().split())

flag = 0

if n == 1:
    x = 10
elif n == 2:
    x = 100
else:
    x = 1000

if m == 0 and n == 1:
    print(0)
    sys.exit()
elif m == 0 and n == 2:
    print(10)
    sys.exit()
elif m == 0 and n == 3:
    print(100)
    sys.exit()
    
for i in range(x):
    flag = 0
    for j in range(m):
        if len(str(i)) == n and str(i)[s[j]-1] == str(c[j]):
            flag += 1
    if flag == m:
        print(i)
        sys.exit()
print(-1)

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

enum {
  MAXN = 100000 + 5
};

typedef std::vector<int> vi;

int n;
vi e[MAXN];
int msk[MAXN];

void dfs(int u, int pa) {
  int d, c;
  for (int v: e[u]) if (v != pa) dfs(v, u);
  for (d=20; ~d; --d) {
    c = 0;
    for (int v: e[u]) if (v != pa && msk[v]>>d&1) ++c;
    if (c >= 2) {
      msk[u] += (1<<(d+1));
      break;
    } else if (c == 1)
      msk[u] |= 1<<d;
  }
  if (d == -1) ++msk[u];
}

void clear() {
  memset(msk, 0, sizeof msk);
}

void exec() {
  int i, u, v, ans;
  clear();
  scanf("%d", &n);
  for (i=0; i<n-1; ++i) {
    scanf("%d%d", &u, &v), --u, --v;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  dfs(0, -1);
  ans = 0;
  while ((1<<(ans+1)) <= msk[0]) ++ans;
  printf("%d\n", ans);
}

int main() {
  if (fopen("D.in", "r") != NULL) {
    freopen("D.in", "r", stdin);
    freopen("D.out", "w", stdout);
  }
  exec();
  return 0;
}


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

int main(){
  int a[3];
  for(int i = 0; i < 3; i++)
    cin >> a[i];
  
  
  sort(a, a+3);
  
  cout << a[2]*10+a[1]+a[0] << endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int i, n, m;
  scanf("%d%d", &n, &m);
  
  int a[m];
  int l = 0;
  for(i=0; i<=m-1; i++){
    scanf("%d", &a[i]);
    l = l + a[i];
  }
  if(l > n)
    printf("-1\n");
  else
    printf("%d", n-l);
  
  return 0;
}

Measured memory_bytes: 1700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <queue>
#include <math.h>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
#include <cstdlib>
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	if (a <= c && c <= b)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll T;

int main()
{
  std::cin >> T;

  rep( t, T ) {
    ll N;
    std::cin >> N;

    std::vector<ll> A(N);
    for( auto &x : A )
      std::cin >> x;

    std::string S;
    std::cin >> S;

    std::vector<ll> bases;

    repd( i, N ) {
      for( auto b : bases )
        chmin( A[i], A[i]^b );

      if( A[i] ) {
        if( S[i] == '1' ) {
          std::cout << 1 << std::endl;

          goto end;
        }

        bases.emplace_back( A[i] );
      }
    }

    std::cout << 0 << std::endl;

end:;
  }

  return 0;
}

Measured memory_bytes: 3604
object Main {
  
  def main(args: Array[String]) = {
    
    val input: String = readLine()
    val list: Array[Int] = input.split(" ").map((a: String) => a.toInt)
    
    val W: Int = list(0)
    val H: Int = list(1)
    val x: Int = list(2)
    val y: Int = list(3)
    val r: Int = list(4)
    
    val left = x - r
    val right = x + r
    val top = y + r
    val bottom = y - r
    
    var ans = "No"
    if (left >= 0 && right <= W) {
      if (bottom >= 0 && top <= H) {
        ans = "Yes"
      }
    }
    println(ans)
  }
  
  //def readLine(): String = {"5 4 2 4 1"}
}


Measured memory_bytes: 43768
def dot(vec1,vec2):
  res = 0
  for i in range(len(vec1)): res += vec1[i]*vec2[i]
  return res

N, M, C = map(int,input().split())
B = list(map(int,input().split()))
count = 0
for _ in range(N):
  A = list(map(int,input().split()))
  if dot(A,B) + C > 0: count += 1
print(count)

Measured memory_bytes: 3060
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;



int main()
{
	double x1,x2,y1,c1,y2,c2,y,x;
	while((scanf("%lf %lf %lf %lf %lf %lf",&x1,&x2,&y1,&y2,&c1,&c2))!=EOF)
	{
		x=((c1*y1-x2*c2)/(x1*c1-x2*y2));
		y=((-(y2*y1)+x1*c2)/(x1*c1-x2*y2));
		if(x==0)
		{
			x=0;
		}
		if(y==0)
		{
			y=0;
		}
		printf("%.3lf %.3lf\n",x,y);
	}
	return 0; 
}

Measured memory_bytes: 1236
from queue import Queue
N = int(input())
G = [[] for _ in range(N)]
C = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    C[a].append(w)
    G[b].append(a)
    C[b].append(w)
ans = [-1] * N
ans[0] = 0
que = Queue()
que.put(0)
while not que.empty():
    v = que.get()
    l = len(G[v])
    for i in range(l):
        u = G[v][i]
        w = C[v][i]
        if ans[u] != -1:
            continue
        ans[u] = (ans[v] + w) % 2
        que.put(u)
print(*ans, sep='\n')

Measured memory_bytes: 40488
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long llong;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

llong f(llong s) {
   if (s == 1) return 1;
   return 2 * f(s / 2) + 1;
}

int main() {
   llong s;
   cin >> s;
   cout << f(s) << endl;
   return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

void solve() {
    int n, w;
    cin >> n >> w;
    vector<vector<ll>> dp(n+1, vector<ll>(100001, LINF));
    vector<pair<ll, ll>> ob(n+1);
    for (int i=1; i<=n; i++) {
        cin >> ob.at(i).first >> ob.at(i).second;
    }
    int res = 0;
    for (int i=0; i<n+1; i++) dp.at(i).at(0) = 0;
    for (int i=1; i<=n; i++) {
        for (int j=0; j<100001; j++) {
            if (j >= ob.at(i).second) {
                dp.at(i).at(j) = min(dp.at(i-1).at(j), dp.at(i-1).at(j-ob.at(i).second) + ob.at(i).first);
                if (dp.at(i).at(j) <= w) chmax(res, j);
            } else {
                dp.at(i).at(j) = dp.at(i-1).at(j);
            }
        }
    }
    cout << res << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 80256
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
A, B, K = map(int, input().split())

for k in range(K):
  if k % 2 == 0:
    a = int(A /2)
    A = a
    B = a + B
  else:
    b = int(B /2)
    B = b
    A = b + A

print("{} {}".format(int(A),int(B)))
  

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
typedef long long ll;
#define trace(x)  cerr << #x << ": " << x << endl;
#define rep(i,a)  for(ll i=0; i< a; i++)
#define pb push_back
#define vl vector<ll> 
#define rep(i,a)  for(ll i=0; i< a; i++)
const int N=1e7+5;ll c[N];
int main()
{
	fast;
	ll n;cin>>n;
	for(ll i=1;i<=n;i++)
	{
		for(ll j=0;j<=n;j+=i)
		{
			c[j]++;
		}
	}
	ll sum=0;
	for(ll i=1;i<=n;i++)sum+=i*c[i];
	cout<<sum;

}

Measured memory_bytes: 81732
#include <iostream>

using namespace std;

int main(void) {
	int K,T;
	cin >> K >> T;
	int a,sum,cmax;
	sum = cmax = 0;
	for (int i = 0; i < T; ++i) {
		cin >> a;
		cmax = max(cmax,a);
		sum += a;
	}
	sum -= cmax;
	if (cmax > sum) {
		cout << cmax-sum-1 << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
struct Pox
{
  int to,cost;
  Pox(int to,int cost):to(to),cost(cost){}
};
typedef vector<Pox> vp;
typedef vector<vp> vvp;
int n,m;

template<typename T>
bool visit(const T& G,int v,vector<int>& order,vector<int>& color)
{
  color[v] = 1;
  for(__typeof((G[v]).begin()) e = G[v].begin();e != G[v].end();e++)
    {
      if(color[e->to] == 2)continue;//このvisit以外のvisitで訪れた
      if(color[e->to] == 1)return false;//このvisitで訪れた
      if(!visit(G,e->to,order,color))return false;
    }
  order.push_back(v);
  color[v] = 2;
  return true;
}

template<typename T>
bool topologicalSort(const T& G,vector<int>& order)
{
  int SizeG = G.size();
  vector<int> color(SizeG); 
  for(int u=0;u<n;u++)
    if(!color[u] && !visit(G,u,order,color))
      return false;
  reverse(order.begin(),order.end());
  return true;
}

int main()
{
  vvp G;
  cin >> n >> m;
  G.resize(n);
  for(int i=0;i<m;i++)
    {
      int a,b,c;
      cin >> a >> b >> c;
      G[a].push_back(Pox(b,c));
    }
  vector<int> order;
  topologicalSort(G,order);
  int dp[n+1];
  for(int i=0;i<n;i++)
    dp[i] = 0;

  for(int i=0;i<n;i++)
    {
      int v = order[i];
      for(int j=0;j<G[v].size();j++)
	{
	  int to = G[v][j].to;
	  int cost = G[v][j].cost;
	  dp[to] = max(dp[to],dp[v]+cost);
	}
    }

  cout << dp[n-1] << endl;

  return 0;
}

Measured memory_bytes: 1244
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Tide {
	int Point;
	Tide *prev, *next;
};

Tide *nil;

Tide* listFinding(int Point) {
	Tide *cur = nil->next;
	while ( cur != nil && cur ->Point !=Point ){
		cur = cur->next;
	}
	return cur;
}

void reset() {
	nil = (Tide *)malloc(sizeof(Tide));
	nil->next = nil;
	nil->prev = nil;
}

void printList() {
	Tide *cur = nil->next;
	int isf = 0;
	while ( 1 ) {
		if ( cur == nil ) break;
		if ( isf++ > 0 ) printf(" ");
		printf("%d", cur->Point);
		cur = cur->next;
	}
	printf("\n");
}

void insert(int Point) {
	Tide *x = (Tide *)malloc(sizeof(Tide));
	x->Point = Point;
	
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

void retide(Tide *a) {
	if ( a == nil ) return;
	a->prev->next = a->next;
	a->next->prev = a->prev;
	free(a);
}

void deleteFirst() {
	retide(nil->next);
}

void deleteLast() {
	retide(nil->prev);
}

void deletePoint(int Point) {
	retide(listFinding(Point));
}



int main() {
	int Point, m, i;
	int h = 0;
	char com[20];
	int s = 0, k =0;
	scanf("%d", &m);
	reset();
	for ( i = 0; i < m; i++ ) {
		scanf("%s%d", com, &Point);
		if ( com[0] == 'i' ) { insert(Point); k++; h++; }
		else if ( com[0] == 'd' ) {
			if (strlen(com) > 6 ) {
				if ( com[6] == 'F' ) deleteFirst();
				else if ( com[6] == 'L' ) deleteLast();
			}else {
				deletePoint(Point); k++;
			}
			h--;
		}
	}
	printList();
		
	return 0;
}









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

ll ppow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
struct Point{int x,y;};
int cross(Point a,Point b){
	return a.x*b.y-a.y*b.x;
}
Point operator-(Point a,Point b){
	return {a.x-b.x,a.y-b.y};
}

Point p[300];
int main(){
	int n;cin>>n;
	rep(i,n){
		scanf("%d%d",&p[i].x,&p[i].y);
	}
	sort(p,p+n,[](Point a,Point b){
		if(a.x==b.x)return a.y<b.y;
		return a.x<b.x;
	});
	int ans=(ppow(2,n)+MOD-(1+n)%MOD)%MOD;
	rep(i,n){
		for(int j=i+1;j<n;j++){
			Point pp=p[j]-p[i];
			bool ok=true;
			int cnt=2;
			rep(k,n){
				if(k==i||k==j)continue;
				if(cross(pp,p[k]-p[j])==0){
					if(k<j){ok=false;break;}
					else cnt++;
				}
			}
			if(ok){
				ans=(ans+MOD-(ppow(2,cnt)+MOD-(1+cnt)%MOD)%MOD)%MOD;
			}
		}
	}
	cout<<ans<<endl;
}

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

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

    string s1, s2;
    s1 = s; s2 = s;

    int cnt1 = 0, cnt2 = 0;
    int index1 = 0, index2 = 0;
    while(cnt1 < k && index1 < n){
        if(s1[index1] == 'L') {
            s1[index1] = 'R';
            while(index1 < n){
                if(s1[++index1] == 'L') s1[index1] = 'R';
                else break;
            }
            cnt1++;
        }
        else index1++;
    }

    while(cnt2 < k && index2 < n){
        if(s2[index2] == 'R') {
            s2[index2] = 'L';
            while(index2 < n){
                if(s2[++index2] == 'R') s2[index2] = 'L';
                else break;
            }
            cnt2++;
        }
        else index2++;
    }

    int ans1=0, ans2=0, ans=0;
    rep(i,n-1){
        if(s1[i] == s1[i+1]) ans1++;
        if(s2[i] == s2[i+1]) ans2++;
    }

    ans = max(ans1, ans2);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3844
#include<stdio.h>
#include<string.h>
int main()
{
  char c[3];
  int stock=0;
  int flag=1;
  int n;
  scanf("%d",&n);
  for(;n>0;n--)
    {
      scanf("%s",c);
      if(strcmp(c,"A")==0) stock++;
      if(strcmp(c,"Un")==0)
	{
	  if(stock>0) stock--;
	  else flag=0;
	}
    }
  if((flag==1)&&(stock==0)) printf("YES\n");
  else printf("NO\n");
  return 0;
}

Measured memory_bytes: 1732