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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    string ans = "";
    /*start*/
    int n, m;
    cin >> n >> m;

    if (n == m)
    {
        c("Yes");
    }
    else
    {
        c("No");
    }

    return 0;
}

Measured memory_bytes: 256
/*in the name of Allah the most beneficent the most merciful.*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
//#define mod2 20071027
//#define MOD 998244353
#define base 139
//#define mod 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case #%lld: ", ++c)
#define out(x) cout << #x << " -> " << x << endl;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FILE   freopen("input.txt", "r", stdin);  freopen("out.txt", "w", stdout);
using namespace std;
const int B = 16, N = 300010, M = 5000010;
ll n, k, a[N];
bool fun(ll val)
{
    ll K=k;
    for(int i=0;i<n;i++)
    {
        ll d = a[i]/val;
        if(a[i]%val) d++;
        d--;
        if(d>K)
            return 0;
        K-=d;
    }
    return 1;
}
int solve()
{
    in2(n,k);
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        in1(a[i]);
        ans=max(ans, a[i]);
    }
    ll high = MAX, low=1, mid;
    while(high>=low)
    {
        mid=(high+low)/2;
        if(fun(mid))
        {
            ans=mid;
            high=mid-1;
        }
        else low=mid+1;
    }
    printf("%lld\n", ans);
    return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    return solve();
}
/*

*/

Measured memory_bytes: 5280
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<string.h>
#include<cstring>
const long long INF=0x3f3f3f3f;
using namespace std;
long long ans;
long long n;
int  e[1001][1001];
//int ee[1001][1001];
int main()
{
    int n;
    while(scanf("%d",&n)&&n!=0)
    {
        int sum=0;
        int ssum=INF;
      //  int min=INF;
        int u,v,r;
        int falg;
        memset(e,INF,sizeof(e));
        int Max=0;
        for(int i=0;i<n;i++)
        {
            cin>>u>>v>>r;
            if(e[u][v]>r)
            e[u][v]=r;
            e[v][u]=r;
           Max=max(Max,max(u,v));
        }
        for(int i=0;i<=Max;i++)
        {
            e[i][i]=0;
        }

        for(int i=0;i<=Max;i++)
        {
            for(int j=0;j<=Max;j++)
            {
               for(int k=0;k<=Max;k++)
                if(e[k][i]>e[k][j]+e[j][i])
                {
                   //  sum+=ee[1][i];
                    e[k][i]=e[k][j]+e[j][i];
                    e[i][k]=e[k][j]+e[j][i];
                }
            }
        }
          for(int i=0;i<=Max;i++)
        {
            sum=0;
            for(int j=0;j<=Max;j++)
            {
            if(e[i][j]!=INF)
            sum+=e[i][j];
            }

            if(sum<ssum)
            {
                ssum=sum;
                falg=i;
            }
        }

        cout<<falg<<" "<<ssum<<endl;
    }
    return 0;
}

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

int main()
{
    int ans = 0;
    char c;

    for (int i = 0; i < 4; i++) {
        scanf("%1c", &c);

        if (c == '+') {
            ans++;
        } else {
            ans--;
        }
    }

    cout << ans << endl;
    

    return 0;
}


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

int N;

int main()
{
    scanf("%d",&N);
    if(N == 2)
    {
        printf("-1\n");
        return 0;
    }
    for(int i = 0; i < N - 1; i++)
    {
        printf("%d",i + 2);
        if(i != N - 2)printf(" ");
    }printf("\n");

    for(int i = 2; i <= N; i++)
    {
        int now = N - 1;
        for(int j = 0; j < N - 1; j++)
        {
            if(i == now + 1)printf("1");
            else printf("%d",now + 1);
            if(j != N - 2)printf(" ");
            now++;
            now %= N;
            if(now == 0)now++;
        }printf("\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N,M,X,Y;
	cin>>N>>M>>X>>Y;
	vector<int> x(N);
	vector<int> y(M);
	int sum=0;
	for(int i=0; i<N; i++){
		cin>>x[i];
	}
	for(int i=0; i<M; i++){
		cin>>y[i];
	}
	//入力終了
	sort(x.begin(),x.end());
	sort(y.begin(),y.end());
	if(x[N-1]<y[0]){
		sum++;
	}

	if(y[0]>X){
		sum++;
	}

	if(x[N-1]<Y){
		sum++;
	}
		
	if(sum==3){
		cout<<"No War"<<endl;
	}
	else{
		cout<<"War"<<endl;
	}
}

Measured memory_bytes: 256
S = input()

S1 = S[: (len(S) - 1) // 2]
S2 = S[(len(S) + 3) // 2 - 1 :]
# print(S, S1, S2)


def f(a):
    res = "".join(list(reversed(a)))
    return res


if S == f(S) and S1 == f(S1) and S2 == f(S2):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const ll INF = (1LL << 63);


int main() {
	int a, b,c;
	cin >> a >> b>>c;
	int ans = 0;
	ans = b * c;
	Yes(ans >= a);
	return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<math.h>
using namespace std;
typedef long long ll;

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
    
    ll n;
    string s;
    cin >> n >> s;
    ll b=0;
    for (auto i:s){
        if(i!='.'){
            b+=(i-'0');
            b*=10;
        }
    }
    b/=10;
    //cout << b << " ";
    n=n*b/100;
    cout << n;
    return 0;
}


Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace C_ABC135
{
    class MainClass
    {

        static int[] s;
        static long[] a;
        static long[] b;
        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            a = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
            b = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
            long boss = 0;
            for (int i = 0; i < s[0]; i++)
            {

                if(a[i]>=b[i]){
                    boss+=b[i];
                }else{
                    boss+=a[i];
                    long diff = b[i]-a[i];
                    if(diff>=a[i+1]){
                        boss+=a[i+1];
                        a[i+1]=0;
                    }else{
                        boss+=diff;
                        a[i+1]-=diff;
                    }

                }

            }

            WriteLine(boss);
        }
    }
}


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

using namespace std;

#define DIM 100007

const long long MODULO = 1000000007;

long long n,k,i,j,res;
long long p[DIM], sum[DIM], f[3][DIM];
vector<int> a[DIM];

void dfs(int v, int par) {
    f[0][v] = f[1][v] = 1;
    int c = 0;
    for(auto to : a[v]) {
        if(to == par) continue;
        c++;
        dfs(to,v);
        f[0][v] = (f[0][v] * f[1][to]) % MODULO;
        f[1][v] = f[1][v] * (f[0][to] + f[1][to]) % MODULO;
    }
    //if(c == 0) f[0][v] = f[1][v] = 1;
}


int main() {
    //freopen("input.txt", "r", stdin);
    cin >> n;
    int v1,v2;
    for(int i = 1; i < n; i++) {
        cin >> v1 >> v2;
        a[v1].push_back(v2);
        a[v2].push_back(v1);
    }
    dfs(1,0);
    cout<<(f[0][1]+f[1][1]) % MODULO<<endl;

    return 0;
}


Measured memory_bytes: 14464
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
	string S;
	while(cin >> S){
		int n = S.size();
		vector<int> used(n, 0);
		int res = 0;
		while(true){
			bool end = true;
			int c = n-1;
			while(c >= 0 && used[c]) --c;
			int b = c-1;
			while(b >= 0 && used[b]) --b;
			int a = b-1;
			while(a >= 0 && used[a]) --a;
			while(a >= 0){
				if(S[a] != S[c]){
					++res;
					used[b] = 1;
					end = false;
				} else {
					c = b;
				}
				b = a;
				--a;
				while(a >= 0 && used[a]) --a;
			}
			if(end) break;
		}
		cout << (res%2 ? "First" : "Second") << endl;
	}
}



Measured memory_bytes: 896
import fractions

A, B, C, D = list(map(int, input().split()))

r = A % C
min_c = A if r == 0 else A + C - r
r = A % D
min_d = A if r == 0 else A + D - r
lcm = (C * D) // fractions.gcd(C, D)
r = A % lcm
min_cd = A if r == 0 else A + lcm - r

num_c = max(0, (B - min_c) // C) + (1 if min_c <= B else 0)
num_d = max(0, (B - min_d) // D) + (1 if min_d <= B else 0)
num_cd = max(0, (B - min_cd) // lcm) + (1 if min_cd <= B else 0)
#print(min_c, min_d, min_cd, num_c, num_d, num_cd)
print(B - A + 1 - (num_c + num_d - num_cd))

Measured memory_bytes: 5048
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}
function Main(input) {
  input = myconv(input,5);
  var N = input[0];
  input.shift();
  var output = 0;
  var access = 0;
  var accessed = new Set();
  accessed.add(access);
  while(true){
    access = input[access] -1;
    output++;
     if(accessed.has(access)){
        myout(-1);
       return;
     }else if(access == 1){
              myout(output);
       return;
              }
    accessed.add(access);
  }
}
Main(myin());

Measured memory_bytes: 30792
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 2e5 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

map<ll, ll> freq;

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int n, a;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    freq[a]++;
  }
  ll total = 0;
  for(auto it: freq) {
    if(it.second < it.first)
      total += it.second;
    else if(it.second > it.first)
      total += it.second - it.first;
  }
  cout << total;
  return 0;
}


Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int A, B, C;

int main(){
    cin >> A >> B >> C;
    cout << max((B + C - A), 0) << endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;


int main(){
  int n;
  cin >> n;
  
  map<string, int> memo;
  int mx = 0;
  
  rep(i, n){
    string s;
    cin >> s;
    memo[s]++;
    if(memo[s] > mx)	mx = memo[s];
  }
  
  for(auto i = memo.begin(); i != memo.end(); i++){
    if((i -> se) == mx)
      cout << i->fi << endl;
  }
  
}




Measured memory_bytes: 25216
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

int main() {
   int N;
   cin >> N;
   char S[N];
   bool four = false;
   for (int i = 0; i < N; i++) {
      cin >> S[i];
      if (S[i] == 'Y') four = true;
   }

   if (four) cout << "Four" << endl;
   else cout << "Three" << endl;
   return 0;
}


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


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

	int table[n][n];
	//??£??\??????????¢????

	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			table[i][j] = 0;
		}
	}
	//??£??\??????????????????


	for(int i=0; i<n; i++){
		cin >> a >> b;
		if(b != 0){
			for(int j=0; j<b; j++){
				cin >> c;
				table[a-1][c-1] = 1;
			}
		}
	}

	for(int i=0; i<n; i++){
		for(int j=0; j<n-1; j++){
			cout << table[i][j] << " ";
		}
		cout << table[i][n-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)

using namespace std;

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

    string S, T;
    cin >> S >> T;

    S += S;
    if (S.find(T) != string::npos) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

int W_Length(char *str){
	int length = 0;
	while(*str++ != '\0')
		length++;
	return length;
}

void swap(int *a, int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}
//swap(&a, &b)

double deg(double theta){//deg to theta
return theta*(2*3.14159265359)/360;
}

int cmp( const void *p, const void *q ) {
    return *(int*)p - *(int*)q;
}//ちいさい順
//qsort(a,n,sizeof(int),cmp);
//char s[n][11]

int cmp_s(const void * left, const void * right)
{
	char *left_char = (char *)left;
  char *right_char = (char *)right;
  return strcmp(left_char, right_char);
}
//qsort(s,n,sizeof(s[0]),cmp_s);


int main (void)
{
	int a,b,c,n,i,d,L,R,count=0;

scanf("%d%d%d",&L,&R,&d);
	
  for(i=L;i<=R;i++){
  
  if(i%d==0){
  count++;
  }
  }
  
    printf("%d",count);
return 0;
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int main(){
    IOS();
    ll s[4];
    cin >> s[0] >> s[1] >> s[2];

    for (int i=0;i<3;++i) {
        if (s[i] % 2 == 0) {
            return cout << 0 << endl,0;
        }
    }
    sort(s,s+3);
    cout << s[0] * s[1] << endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
using namespace std;
#define MAX 2000001
#define VMAX 10000

int main() {
    int c[VMAX + 1];
    int n;
    cin >> n;
    vector<int> a(n + 1);
    vector<int> b(n + 1);

    for (int i = 0; i <= VMAX; i++) c[i] = 0;

    for (int i = 0; i < n; i++) {
        cin >> a.at(i + 1);
        c[a.at(i + 1)]++;
    }

    for (int i = 1; i <= VMAX; i++) c[i] += c[i - 1];

    for (int j = 1; j <= n; j++) {
        b.at(c[a.at(j)]) = a.at(j);
        c[a.at(j)]--;
    }

    for (int i = 1; i <= n; i++) {
        if (i > 1) cout << " ";
        cout << b.at(i);
    }
    cout << endl;
}



Measured memory_bytes: 18396
import java.io.*;
import java.util.*;
import java.util.Map.*;

public class Main {
	static final int MOD = (int)1e9+7;

	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		
		out.print(n + ":");
		
		for(Entry<Long,Integer> ent : prime_factor(n).entrySet()) {
			for(int i = 0; i < ent.getValue(); i++) {
				out.print(" " + ent.getKey());
			}
		}
		out.println();
	}

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}

	public static long factorial(int n) {
		long a;

		if(n > 0) {
			a = n * factorial(n - 1);
		}else{
			a = 1;
		}

		return a;
	}
	
	public static LinkedHashMap<Long, Integer> prime_factor(long n){
		LinkedHashMap<Long, Integer> res = new LinkedHashMap<Long, Integer>();
		
		for(long i = 2; i * i <= n; i++) {
			while(n % i ==0) {
				res.put(i, res.containsKey(i) ? res.get(i) + 1  : 1);
				n /= i;
			}
		}
		
		if(n != 1) res.put(n, 1);
		
		return res;
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(K key, V value) {
        super(key, value);
    }

    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}


Measured memory_bytes: 24440
import sys
from collections import deque

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def paint_col(adj, cols, i, col):
    nxt = deque([i])

    while nxt:
        u = nxt.popleft()
        cols[u] = col
        for child in adj[u]:
            if cols[child] == 0:
                nxt.append(child)

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

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

    cols = [0] * n
    col = 1

    for i in range(n):
        if cols[i] == 0:
            paint_col(adj, cols, i, col)
            col += 1

    q = int(input())

    for i in range(q):
        s, t = map(int, input().split())

        if cols[s] == cols[t]:
            ans = 'yes'
        else:
            ans = 'no'

        print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 26960
import java.util.*;

class Main{
  static int[] dy={-1,0,0,1};
  static int[] dx={0,-1,1,0};
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int h=sc.nextInt();
    int w=sc.nextInt();
    int walls=0;
    String[] a=new String[h];
    for(int i=0;i<h;i++){
      a[i]=sc.next();
      for(int j=0;j<w;j++){
        if(a[i].charAt(j)=='#'){
          walls++;
        }
      }
    }
    boolean[][] vid=new boolean[h][w];
    Deque<C> dq=new ArrayDeque<>();
    vid[0][0]=true;
    dq.addLast(new C(0,0,1));
    int dist=-1;
    while(!dq.isEmpty()){
      C he=dq.pollFirst();
      if(he.x==w-1&&he.y==h-1){
        dist=he.d;
        break;
      }
      for(int i=0;i<4;i++){
        if(he.x+dx[i]<0||w<=he.x+dx[i]||he.y+dy[i]<0||h<=he.y+dy[i]){
          continue;
        }
        int nx=he.x+dx[i];
        int ny=he.y+dy[i];
        if(!vid[ny][nx]&&a[ny].charAt(nx)=='.'){
          dq.addLast(new C(nx,ny,he.d+1));
          vid[ny][nx]=true;
        }
      }
    }
    if(dist==-1){
      System.out.println(-1);
    }else{
      System.out.println(h*w-dist-walls);
    }
  }
  static class C{
    int x,y,d;
    C(int x,int y,int d){
      this.x=x;
      this.y=y;
      this.d=d;
    }
  }
}

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

int main() {
	int N, K;
	cin >> N >> K;
	int R, S, P;
	cin >> R >> S >> P;
	string T;
	cin >> T;
	vector<string>H(K);
	for (int n = 0;n<N;++n) {
		H[n%K].push_back(T[n]);
	}
	int ans = 0;
	for (int n = 0;n < K;++n) {
		vector<int>DP(3);
		for (int m = 0;m<H[n].size();++m) {
			vector<int>DPtmp(3);
			if (0 == m) {
				if ('r' == H[n][m]) {
					DPtmp[0] = 0; 
					DPtmp[1] = 0; 
					DPtmp[2] = P;
				}
				else if ('s' == H[n][m]) {
					DPtmp[0] = R;
					DPtmp[1] = 0;
					DPtmp[2] = 0;
				}
				else {
					DPtmp[0] = 0;
					DPtmp[1] = S;
					DPtmp[2] = 0;
				}
			}
			else {
				if ('r' == H[n][m]) {//あいてグー
					DPtmp[0] = max(DP[1],DP[2]);
					DPtmp[1] = max(DP[0],DP[2]);
					DPtmp[2] = max(DP[0],DP[1])+P;
				}
				else if ('s' == H[n][m]) {
					DPtmp[0] = max(DP[1], DP[2])+R;
					DPtmp[1] = max(DP[0], DP[2]);
					DPtmp[2] = max(DP[0], DP[1]) ;
				}
				else {
					DPtmp[0] = max(DP[1], DP[2]);
					DPtmp[1] = max(DP[0], DP[2])+S;
					DPtmp[2] = max(DP[0], DP[1]);
				}
			}
			DP = DPtmp;
		}
		ans += max(DP[0], max(DP[1], DP[2]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5976
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll r, g;
    cin >> r >> g;
    out(2*g - r);
    re0;
}

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

const ll YMAX = (1ll << 31) - 1;
vector<ll> dat;
int N;

void update(int k, int a) {
  k += N - 1;
  dat[k] += a;
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] += a;
  }
}

int find(int a, int b, int k, int l, int r) {
  // [a, b) での最小値。[l, r) と節点kが対応
  if (r <= a || b <= l) return 0;
  if (a <= l && r <= b) return dat[k];
  else {
    int vl = find(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = find(a, b, k * 2 + 2, (l + r) / 2, r);
    return vl + vr;
  }
}

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

  cin >> N;
  ll Q; cin >> Q;
  ll N_ = N;
  N = 1;
  while (N < N_) N *= 2;
  dat = vector<ll>(2 * N - 1, 0);

  for (ll i = 0; i < Q; i++) {
    int q, x, y;
    cin >> q >> x >> y;
    x--;
    if (q == 0) {
      update(x, y);
    } else {
      y--;
      int ans = find(x, y + 1, 0, 0, N);
      cout << ans << '\n';
    }
  }

  return 0;
}


Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define fir first
#define sec second
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define maxd 1000000007
#define eps 1e-6
typedef long long ll;
const int N=100000;
const double pi=acos(-1.0);
int n,m,tim[1010][1010];
char s[1010];
const int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
struct node{
	int x,y;
};
bool operator<(const node &p,const node &q)
{
	return tim[p.x][p.y]>tim[q.x][q.y];
}
priority_queue<node> q;

int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

int main()
{
	n=read();m=read();
	rep(i,1,n)
	{
		rep(j,1,m) tim[i][j]=maxd;
	}
	rep(i,1,n)
	{
		scanf("%s",s+1);
		rep(j,1,m)
		{
			if (s[j]=='#')
			{
				q.push((node){i,j});
				tim[i][j]=0;
			}
		}
	}
	int ans=0;
	while (!q.empty())
	{
		node now=q.top();q.pop();
		rep(i,0,3)
		{
			int nx=now.x+dx[i],ny=now.y+dy[i];
			if ((nx<0) || (nx>n) || (ny<0) || (ny>m)) continue;
			if (tim[nx][ny]==maxd) q.push((node){nx,ny});
			tim[nx][ny]=min(tim[nx][ny],tim[now.x][now.y]+1);
		}
	}
	rep(i,1,n)
	{
		rep(j,1,m) ans=max(ans,tim[i][j]);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 14060
/**
 *  Kaiwen Zhou,
 *  CUHK
**/
#include <bits/stdc++.h>
using namespace std;
#define INS ios::sync_with_stdio(false);cin.tie(0)
typedef long long LINT;
#define INF 1000000000000

int main(void) {
    INS;
    string s, t;
    vector<char> ans(3001, '.');
    cin >> s >> t;
    int ls = s.length(), lt = t.length();
    int dp[ls + 1][lt + 1];
    memset(dp, 0, (ls + 1) * (lt + 1) * sizeof(int));

    for(int i = 1; i <= ls; i ++)
        for(int j = 1; j <= lt; j ++) {
            if(s[i - 1] == t[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else {
                dp[i][j] = max({dp[i][j], dp[i - 1][j], dp[i][j - 1]});
            }
        }
    int li = ls, lj = lt;
    while(li > 0 && lj > 0) {
        if(dp[li][lj] == dp[li - 1][lj - 1] + 1 && s[li - 1] == t[lj - 1]) {
            ans[dp[li][lj]] = s[li - 1];
            li --;
            lj --;
        }
        else if(dp[li][lj] == dp[li - 1][lj])
            li --;
        else if(dp[li][lj] == dp[li][lj - 1])
            lj --;
    }
    if(dp[ls][lt] == 0) cout << ' ';
    else
        for(int i = 1; i <= dp[ls][lt]; i ++)
            cout << ans[i];
    cout << '\n';
    return 0;
}


Measured memory_bytes: 35456
n,k=map(int,input().split())
a=[]
d=[]
for i in range(k):
    D=int(input())
    A=list(map(int,input().split()))
    a.append(A)
    d.append(D)
l=[0]*n
for i in range(k):
    for j in range(d[i]):
        l[a[i][j]-1]+=1
print(l.count(0))

Measured memory_bytes: 9200
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
 
using namespace std;


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

	vector<int> p(n),a(n), b(n);
	int i;
	for (i = 0; i < n; i++) {
		p[i] = i;
		scanf("%d", &a[i]); a[i]--;
	}
	for (i = 0; i < n; i++) {
		scanf("%d", &b[i]); b[i]--;
	}

	int aa = 0, bb = 0;
	int cnt = 0;
	do {
		if (p == a) aa = cnt;
		if (p == b) bb = cnt;
		cnt++;
	} while (next_permutation(p.begin(),p.end()));

	printf("%d\n", abs(bb - aa));

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 256
import heapq
N, K, Q = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
sA = sorted(set(A))
A += [-1]
ans = float('inf')

for amin in sA:
    cand = []
    fr = 0
    to = -1
    for i in range(N + 1):
        a = A[i]
        if a >= amin:
            if fr == -1:
                fr = i
        elif a < amin and fr >= 0:
            cand += sorted(A[fr:i])[:max(0, i - fr - K + 1)]
            fr = -1
    if len(cand) < Q:
        break
    ans = min(ans, sorted(cand)[Q - 1] - amin)
print(ans)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX = (long long)1e16 + 1000ll;
int nor,v,n = 50,t,m,k,ans[55];
signed main() {
  scanf("%lld",&k);
  t = k % n;
  m = k / n;
  nor = n - 1 + m - t;
  ans[1] = n - 1 + m + n * t;
  for (int i = 2 ; i <= n ; ++ i)
    ans[i] = nor;
  for (int i = 1 ; i <= n ; ++ i) {
    while (ans[i] > MAX)
      ans[i] -= n+1, ans[i+1] += n+1;
  }
  printf("%lld\n",n);
  for (int i = 1 ; i <= n ; ++ i)
    printf("%lld ",ans[i]);
  puts("");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int h, w; cin >> h >> w;
	int ans = INF;
	rep(i, 2) {
		rep(j, w-1) {
			int a = (j +1)*h;
			int b = (h / 2)*(w - j - 1);
			int c = ((h+1) / 2)*(w - j - 1);
			chmin(ans, max({ a,b,c }) - min({a,b,c}));
		}
		swap(h, w);
	}
	chmin(ans, (h + 2) / 3 * w - (h/3)*w);
	chmin(ans, (w + 2) / 3 * h-(w/3)*h);
	cout << ans << endl;
	return 0;
}

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

signed main() {
  std::vector<int> v(1e6+5,0);
  int a;cin>>a;int i=0;
  while(true){
    i++;
    //cout<<a;
    if(v[a])break;
    v[a]++;
    if(a%2)a=a*3+1;
    else a/=2;
  }
  cout<<i<<endl;
}


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

using lint = long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
template <typename T> using VVV = vector<vector<vector<T>>>;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repu(i, a, b, s) for(int i = int(a); i < int(b); i += int(s))
#define repd(i, a, b, s) for(int i = int(a); i > int(b); i += int(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

void solve() {
    int N;
    cin >> N;

    int t[9] = {1, 2, 3, 5, 6, 9, 10, 13, 17};
    string ans = "Yes";
    rep(i, 9) {
        if(t[i] == N) {
            ans = "No";
        }
    }
    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}

Measured memory_bytes: 3612
n = int(input())
# mapはcallable, iterator
# input().split()でリストを作成する
a = [int(i) for i in input().split()]
iSSequence = [False] * (len(a) - 1)

# a[i]のあとにa[i+1]を食べたならフラグを立てる
for i in range(len(a) - 1):
    if(a[i] + 1 == a[i + 1]):
        iSSequence[a[i] - 1] = True

sum = 0
# bは必ずすべて足される
for b in input().split():
    sum += int(b)

index = 0
for c in input().split():
    if(iSSequence[index]):
        sum += int(c)
    index += 1

print(sum)

Measured memory_bytes: 9136
#include "bits/stdc++.h"
using namespace std;
using ll =long long;
using ld = long double;
using P =pair<ld,int>;

struct myCircle{
    ld x,y,r;
    myCircle(){}
    myCircle(ld xa, ld ya, ld ra) : x(xa),y(ya),r(ra){}
};
using Circles=vector<myCircle>;

ld calc(myCircle p,myCircle q){
    ld dif=(p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y);
    if(dif<=(p.r+q.r)*(p.r+q.r)) return 0;
    else return sqrt(dif)-p.r-q.r;
}

struct Edge{
    using Cost = ld;
    int to;
    Cost cost;
    Edge(int t,Cost c) : to(t),cost(c){}
};
using  Graph = vector<vector<Edge>>;

vector<ld> dijkstra(const Graph &g,int s){
   vector<ld> d(g.size(),1e30);
   d[s]=0;
   priority_queue<P,vector<P>,greater<P>> que;
   que.push(P(0,s));
   while(!que.empty()){
       ld dist=que.top().first;
       int v=que.top().second;
       que.pop();
       if(d[v]<dist)continue;
       for(const auto &e: g[v]){
           if(d[e.to]<=d[v]+e.cost) continue;
           d[e.to]=d[v]+e.cost;
           que.push(P(d[e.to],e.to));
       }
   }
   return d;
}

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

    ld xs,ys,xt,yt;cin>>xs>>ys>>xt>>yt;
    int n;cin>>n;
    Circles barrier(n+2);
    Graph g(n+2);
    barrier[0]=myCircle(xs,ys,0.0);
    barrier[n+1]=myCircle(xt,yt,0.0);
    for(int i=1;i<=n;i++){
        ld xi,yi,ri;cin>>xi>>yi>>ri;
        barrier[i]=myCircle(xi,yi,ri);
    }
    for(int i=0;i<n+2;i++){
        for(int j=0;j<n+2;j++){
            ld tmp=calc(barrier[i],barrier[j]);
            g[i].push_back(Edge(j,tmp));
            g[j].push_back(Edge(i,tmp));
        }
    }
    vector<ld> dist=dijkstra(g,0);
    cout<<fixed<<setprecision(10)<<dist[n+1]<<endl;
}


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

int main(){
    int N, X, i, in, r, a, b;
    vector <int> data, data2;
    int min = 1000000000, flag = 0, min2 = 1000000000;

    cin >> N >> X;
    for(i = 0; i < N; i++){
        cin >> in;
        data.push_back(in);
    }
    data.push_back(X);

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

    for(i = 0; i < N + 1; i++){
        if(i > 0){
            if(data[i] - data[i - 1] < min){
                min = data[i] - data[i - 1];
            }
            data2.push_back(data[i] - data[i - 1]);
        }

    }
    sort(data2.begin(), data2.end());
    //cout << data2.size() << endl;
    for(i = 0; i < data2.size(); i++){
        // if(data2[i]%min != 0){
        //     flag = 1;
        //     break;
        // }

        if(i > 0){
            a = data2[i];
            b = data2[i - 1];
            r = a%b;
            while(r != 0){
                a = b;
                b = r;
                r = a % b;
            }
            //cout << data2.size() << endl;
            if(b < min2){
                min2 = b;
            }
        }else if(data2.size() == 1){
            min2 = data2[i];
        }
    }

    // if(flag == 0){
    //     cout << min << endl;
    // }else{
    //     cout << 1 << endl;
    // }
    cout << min2 << endl;

    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<string, string> sP;
typedef pair<ll, pair<ll, ll>> PP;

const ll mod = 1e4;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second



int main() {
	ll n, a[200010], sum = 0, sumb = 0;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		a[i] -= i + 1;
	}
	sort(a, a + n);
	int it = n / 2;
	int it2 = it - 1;
	for (int i = 0;i < n;i++) {
		sum += abs(a[i] - a[it]);
	}
	for (int i = 0;i < n;i++) {
		sumb += abs(a[i] - a[it2]);
	}
	cout << min(sum, sumb) << endl;
	return 0;
}

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

using Edge = pair<ll, ll>;
using Graph = vector<vector<Edge>>;
Graph G;

vector<bool> color;
void dfs(ll v, ll p, bool c){
    color[v] = c;
    for(auto e: G[v]){
        if(e.first == p) continue;
        if(e.second % 2 == 0){
            dfs(e.first, v, c);
        }else{
            dfs(e.first, v, !c);
        }
    }
}


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

    G.assign(n, vector<Edge>());
    color.assign(n, 0);

    rep(i, n-1){
        ll tmp1, tmp2, tmp3;
        cin >> tmp1 >> tmp2 >> tmp3;
        tmp1--;
        tmp2--;
        G[tmp1].push_back(Edge(tmp2, tmp3));
        G[tmp2].push_back(Edge(tmp1, tmp3));
    }

    dfs(0, -1, 0);

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

    return 0;
}


Measured memory_bytes: 12160
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		long N = int.Parse(Console.ReadLine());
		long ans = 0;
		for(var i=1;i<=N;i++){
			if(i%3!=0 && i%5!=0){
              ans += i;
            }
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 17652
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from itertools import accumulate

    n, m = map(int, readline().split())
    c = [0] * n

    for i in range(m):
        a, b = map(int, readline().split())
        a, b = a - 1, b - 1
        a, b = min(a, b), max(a, b)
        c[a] += 1
        c[b] -= 1

    d = list(accumulate(c))

    if all((x % 2 == 0 for x in d)):
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
    int n,m;
    int k,a;
    int co=0;
    cin >>n>>m;
    vector<int>t(m,0);
    for(int i=0;i<n;i++){
        cin >>k;
        for(int j=0;j<k;j++){
            cin >> a;
            t[a-1]++;
        }
    }
    for(int i=0;i<m;i++){
        if(t[i]==n)co++;
    }
    cout <<co<< endl;
    return 0;
}


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

bool solve(int N, int M, int *H, int *A,int *B, int n) {

	for (int m = 0; m < M; m++) {
		if (A[m] == n + 1) {
			int bm = B[m] - 1;
			if (H[bm] >= H[n]) {
				return false;
			}
		}
		if (B[m] == n + 1) {
			int am = A[m] - 1;
			if (H[am] >= H[n]) {
				return false;
			}
		}

	}
	return true;
}


int main() {
	int N, M;
	cin >> N >> M;
	//vector<int> H(N), A(M), B(M);
	int *H, *A, *B;
	H = new int[N];
	A = new int[M];
	B = new int[M];
	for (int n = 0; n < N; n++) {
		cin >> H[n];
	}
	bool* is_high;
	is_high = new bool[N];
	for (int n = 0; n < N; n++) {
		is_high[n] = true;
	}
	for (int m = 0; m < M; m++) {
		cin >> A[m] >> B[m];
		if (H[A[m] - 1] < H[B[m] - 1]) {
			is_high[A[m] - 1] = false;
		}
		else if (H[A[m] - 1] > H[B[m] - 1]) {
			is_high[B[m] - 1] = false;
		}
		else if (H[A[m] - 1] == H[B[m] - 1]) {
			is_high[A[m] - 1] = false;
			is_high[B[m] - 1] = false;

		}

	}

	int cnt = 0;
	for (int n = 0; n < N; n++) {
		if (is_high[n] == true) {
			cnt++;
		}
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 4916
b1,b2,b3 = map(int,input().split())
if b1==1:
    if b2==1:
        print("Open")
    else:
        print("Close")
if b1==0:
    if b2==0:
        if b3==1:
            print("Open")
        else:
            print("Close")
    if b2==1:
        print("Close")


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  int B=0;
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    B^=A.at(i);
  }
  for(int i=0;i<N;i++){
    int C=B^A.at(i);
    cout << C;
    if(i==N-1){
      cout << endl;
    }
    else{
      cout << " ";
    }
  }
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll X;
    cin >> X;

    if(X == 3 || X == 5 || X == 7){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int p=0, p0=0, v=0, j=0;
	int a[1000]={};
	scanf("%d",&p);
	while (p0<p) {
		scanf("%d",&a[p0]);
		p0++;
	}
	for(int i=1;i<p;i++)  {
		for (p0=0;p0<p;p0++) {
			if ((p0+1)<p) printf("%d ",a[p0]);
			else printf("%d\n",a[p0]);
		}
		v=a[i];
		j=i-1;
		while (j>=0&&a[j]>v) {
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=v;
		p0=0;
	}
	for (p0=0;p0<p;p0++) {
		if ((p0+1)<p) printf("%d ",a[p0]);
		else printf("%d\n",a[p0]);
	}
	return 0;
}

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

using ll = long long;

int main() {
    int N;
    cin >> N;
    if (N == 0) {
        cout << 0 << endl;
        return 0;
    }
    vector<int> S(0);
    while (N != 0) {
        int x = abs(N % 2);
        S.push_back(x);
        N -= x;
        N /= -2;
    }
    rep(i, S.size()) {
        cout << S[S.size() - 1 - i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cctype>
#include<stdio.h>
using namespace std;

int main(){

	char ch[1200];

	int i = 0, a = 0;
	while (i<1200){
		scanf("%c", &ch[i]);
		if (isupper(ch[i]))ch[i] += 32;
	else if (islower(ch[i])) ch[i]-=32;
	else if (ch[i] == '\n')break;
	
	i++;
	}
	while (a <=i){
		printf("%c", ch[a]);
		a++;

	}

	return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
    int n,i; cin>>n>>i;
    cout<<n-i+1<<endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String args[]){
	    int cnt=0;
		Scanner sc = new Scanner(System.in);

		String str = sc.next();
		char[] charArray = str.toCharArray();
		
		for (char ch : charArray) {
		    if(ch=='1')
	            cnt++;
        }

		System.out.println(cnt);
		
	}
}

Measured memory_bytes: 21716
from bisect import *
from collections import *
from fractions import gcd
from math import factorial
from itertools import *
from heapq import *



N=int(input())
LR=[list(map(int,input().split())) for i in range(N)]
for i in range(N):
    LR[i][1]+=1

value=max([R-L for L,R in LR])
#LR=sorted(LR,key=lambda x:x[1])
LR=sorted(LR,key=lambda x:x[0]*10**9+x[1])
a=2*(10**9)
minRlst=[a for i in range(N)]
minRlst[-1]=LR[-1][1]
maxLlst=[0 for i in range(N)]
maxLlst[0]=LR[0][0]
for i in range(N-2,-1,-1):
    minRlst[i]=min(minRlst[i+1],LR[i][1])
for i in range(1,N):
    maxLlst[i]=max(minRlst[i-1],LR[i][0])
L1,R1=LR[0]
L2,R2=LR[-1][0],minRlst[1]
maxR=min([R for L,R in LR])
for i in range(0,N-1):
    L,R=LR[i]
    a=max(R-L,0)
    b=max(maxR-LR[-1][0],0)
    value=max(value,a+b)
    L1=L
    R1=min(R1,R)
    R2=minRlst[i+1]
    a=max(R1-L1,0)
    b=max(R2-L2,0)
    value=max(value,a+b)
print(value)


Measured memory_bytes: 101588
#include <iostream>
using namespace std;
int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(((a^b) == 0 && (a^c) != 0) || ((a^c) == 0 && (a^b) != 0) || ((b^c) == 0 && (b^a) != 0)) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
s = [input() for i in range(2)]

n = int(s[0])
x = [int(s) for s in s[1].split()]

mina = 0
a = max(x)
b = min(x)
for i in range(b,a+1):
    tem = 0
    for j in range(n):
        tem += (x[j]-i)*(x[j]-i)
    if(i==b or tem<mina):
        mina = tem
print(mina)

Measured memory_bytes: 3064