akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
 
    vector<ll>a(5005);
    vector<ll>b(5005);
    vector<ll>track;
    bool vis[5005];
 
    void dfs(int u , long long total_cycle){
        if(vis[u]) return ;
        vis[u]=true;
        total_cycle+=b[u];
        track.push_back(total_cycle);
        dfs(a[u],total_cycle);
    }
    void solve(){
        int n,k;
        cin>>n>>k;
        for(int i=0;i<n;i++){
            cin>>a[i];
            a[i]--;
        }
        for(int i=0;i<n;i++)
            cin>>b[i];
        ll ans=-(1e18);
        for(int i=0;i<n;i++){
            memset(vis,false,sizeof(vis));
            dfs(i,0);
            if(track.back()>0 && k>=(int)(track.size())){
                ll cycles=(ll)(k/(int)track.size());
                ll left=(ll)(k%(int)track.size());
                ll maxi=-1e18;
                for(int x=0;x<(int)track.size();x++)
                    maxi=max(maxi,track[x]);
                ans=max(ans,(cycles-1LL)*(track.back())+maxi);
                maxi=-1e18;
                for(int x=0;x<left;x++)
                    maxi=max(maxi,track[x]);
                ans=max(ans,(cycles*track.back()) + maxi);
            }
            else{
                for(int j=0;j<(min((int)track.size(),k));j++){
                    ans=max(ans,track[j]);
                }
            }
            track.clear();
        }
        cout<<ans;
        return;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }

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

using namespace std;

const int maxn = 1e3 + 5;
const int INF = 0x7f7f7f7f;

char g[maxn][maxn];
char vis[maxn][maxn];
int dist[maxn][maxn];

struct node {
	int x , y , d;
	node(int a , int b , int c):x(a) , y(b) , d(c){
	}
	bool operator < (const node b)const {
		return d > b.d;
	}
};

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

int main() {
	int h , w , ch , cw , dh , dw;
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> h >> w;
	cin >> ch >> cw;
	cin >> dh >> dw;
	for(int i = 1 ; i <= h ; i++) {
		for(int j = 1 ; j <= w; j++) {
			cin >> g[i][j];
		}
	}
	memset(dist , 0x7f , sizeof(dist));
	priority_queue <node> q;
	q.push(node(ch , cw , 0));
	dist[ch][cw] = 0;
	while(!q.empty()) {
		node u = q.top(); q.pop();
		vis[u.x][u.y] = 1;
		for(int i = 0 ; i < 4 ; i++) {
			int x = u.x + dx[i] , y = u.y + dy[i];
			if(x >= 1 && x <= h && y >= 1 && y <= w && !vis[x][y] && g[x][y] == '.' && dist[x][y] > dist[u.x][u.y]) {
				dist[x][y] = dist[u.x][u.y];
				q.push(node(x , y , dist[x][y]));
				//vis[u.x][u.y] = 1;
			}
		}
		for(int x = max(1 , u.x - 2) ; x <= min(h , u.x + 2) ; x++) {
			for(int y = max(1 , u.y - 2) ; y <= min(w , u.y + 2) ; y++) {
				if(x >= 1 && x <= h && y >= 1 && y <= w && !vis[x][y] && g[x][y] == '.' && dist[x][y] > dist[u.x][u.y] + 1) {
					dist[x][y] = dist[u.x][u.y] + 1;
					q.push(node(x , y , dist[x][y]));
					//vis[u.x][u.y] = 1;
				}
			}
		}
	}
	if(dist[dh][dw] >= INF)cout << -1 << "\n";
	else cout << dist[dh][dw] << "\n";
	return 0;
}

/*
while(!q1.empty()) {
			node u = q1.front(); q.pop();
			for(int i = max(u.x - 2 , 1) ; i <= min(u.x + 2 , h) ; i++) {
				for(int j = max(u.y - 2 , 1) ; j <= min(u.y + 2 , w) ; j++) {
					if(!vis[i][j] && g[i][j] == '.') {
						node v = node(i , j , u.d + 1);
						q1.push(v);
						if(i == dh && j == dw) {
							cout << v.d << "\n";
							return 0;
						}
					}
				}
			}
		}
		*/

Measured memory_bytes: 9532
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int n, m;
double ans;
bool fin;
double square(double x)
{
    return x * x;
}
double dist(vector<double> &a, vector<double> &b)
{
    return (square(a[0] - b[0]) + square(a[1] - b[1]) + square(a[2] - b[2]));
}

double score(vector<vector<double>> &v)
{
    double ret = 0.0;
    rep(i, v.size()) rep(j, i + 1, v.size())
    {
        ret += dist(v[i], v[j]);
    }
    return ret;
}
void dfs(vector<vector<double>> &col, vector<vector<double>> &now, int index)
{
    cerr << index << endl;
    if (now.size() == m)
    {
        ans = max(ans, score(now));
        return;
    }
    if (index == n)
    {
        return;
    }
    rep(i, index, n)
    {

        now.push_back(col[index]);
        dfs(col, now, index + 1);
        now.pop_back();
        dfs(col, now, index + 1);
    }
    return;
}

void update(vector<int> &g, int pos)
{
    //cerr << pos << endl;
    g[pos]++;
    if ((pos == m - 1 && g[pos] == n) || (g[pos] == g[pos + 1]))
    {
        if (pos == 0)
        {
            fin = true;
            return;
        }
        g[pos]--;
        update(g, pos - 1);
        g[pos] = g[pos - 1] + 1;
        return;
    }
}

int main(int argc, char const *argv[])
{
    fin = false;
    cin >> n >> m;
    if (m == 0)
    {
        printf("0.000000\n");
        return 0;
    }
    vector<vector<double>> col(n, vector<double>(3, 0));
    rep(i, n) cin >> col[i][0] >> col[i][1] >> col[i][2];
    ans = -1.0;
    vector<int> g(m, 0);
    rep(i, m) g[i] = i;
    do
    {
        // rep(i, m) cerr << g[i] << " ";
        // cerr << endl;
        vector<vector<double>> now = {};
        rep(i, m) now.push_back(col[g[i]]);
        ans = max(ans, score(now));
        update(g, m - 1);
    } while (fin != true);
    printf("%lf\n", ans);

    return 0;
}



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

vl = list(map(int,input().split()))

ans = 0
for a in range(k+1):
    suba = vl[:a]
    for b in range(min(n+1-a, k+1-a)):
        subb = vl[-b:]
        if b == 0:
            subb = []
        sub = suba + subb
        ssub = sorted(sub)
        for _ in range(k-a-b):
            if len(ssub) == 0:
                break
            if ssub[0] < 0:
                ssub.pop(0)
            else:
                break
        if sum(ssub) > ans:
            ans = sum(ssub)

print(ans)

Measured memory_bytes: 41196
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

    private static List<Point> start = new ArrayList<>();
    private static List<Point> end = new ArrayList<>();

    private static class Point {
        int x;
        int y;

        public Point(final int x, final int y) {
            this.x = x;
            this.y = y;
        }
    }

    private static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }


    public static void main(String[] args) {
        FastReader in = new FastReader();
        solve(in);

    }


    private static void solve(final FastReader in) {
        int n = in.nextInt();
        int m = in.nextInt();
        coordinateBuilder(in, n, start);
        coordinateBuilder(in, m, end);
        for (int i = 0; i < n; i++) {
            int res = 0;
            for (int j = 0; j < m; j++) {
                if (distance(i, j) < distance(i, res)) {
                    res = j;
                }
            }
            System.out.println(res + 1);
        }
    }

    private static int distance(final int i, final int j) {
        return Math.abs(start.get(i).x - end.get(j).x) + Math.abs(start.get(i).y - end.get(j).y);
    }

    private static void coordinateBuilder(final FastReader in, final int range, final List<Point> coordinates) {
        for (int i = 0; i < range; i++) {
            coordinates.add(new Point(in.nextInt(), in.nextInt()));
        }
    }
}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;

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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
void debug(set<int>& s){
    cerr<<"set: ";
    for(auto x:s){
        cerr<<x<<" ";
    }
    cerr<<endl;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N,Q;
    cin>>N>>Q;
    vector<pair<int, pair<int, int>>> stx(N);
    rep(i,N){
        cin>>stx[i].second.first>>stx[i].second.second>>stx[i].first;
    }
    //xでソート
    sort(all(stx));
    vector<int> S(N), T(N), X(N);
    rep(i,N){
        S[i] = stx[i].second.first;
        T[i] = stx[i].second.second;
        X[i] = stx[i].first;
    }
    //print(S);print(T);print(X);
    vector<int> D(Q), ans(Q, -1);
    set<int> set;
    map<int, int> idx;
    rep(i,Q){
        cin>>D[i];
        idx[D[i]] = i;
        set.insert(D[i]);
    }
    /*
    for(auto p:idx){
        cerr<<p.first<<" "<<p.second<<endl;
    }*/
    rep(i,N){
        //cerr<<"S,T,X: "<<S[i]<<" "<<T[i]<<" "<<X[i]<<endl;
        //cerr<<"["<<S[i]-X[i]<<", "<<T[i] - X[i]<<")"<<endl;
        auto l_itr = set.lower_bound(S[i] - X[i]);
        //auto r_itr = set.upper_bound(T[i] - X[i]);
        //debug(set);
        while(l_itr != set.end()){
            if(*l_itr >= T[i] - X[i])break;
            //cerr<<"D: "<<*l_itr<<endl;
            ans[idx[*l_itr]] = X[i];
            set.erase(l_itr++);
        }
    }
    //print(ans);
    rep(i,Q){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 27904
/* Coached by Dukkha */
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

#define N 50

int max(int a, int b) { return a > b ? a : b; }

void srand_() {
	struct timeval tv;

	gettimeofday(&tv, NULL);
	srand(tv.tv_sec ^ tv.tv_usec);
}

int rand_(int n) {
	return (rand() * 76543LL + rand()) % n;
}

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ia - ib;
}

void sort(int *aa, int n) {
	int i;

	srand_();
	for (i = 0; i < n; i++) {
		int j = rand_(i + 1), tmp;

		tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
	}
	qsort(aa, n, sizeof *aa, compare);
}

int main() {
	static int vv[N];
	int n, k, i, p, ans;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &vv[i]);
	ans = 0;
	for (p = 0; p <= n && p <= k; p++) {
		int q;

		for (q = 0; p + q <= n && p + q <= k; q++) {
			static int vv_[N];
			int r = k - p - q;
			int cnt = 0;
			int h;
			int sum;

			for (i = 0; i < p; i++)
				vv_[cnt++] = vv[i];
			for (i = n - q; i < n; i++)
				vv_[cnt++] = vv[i];
			sort(vv_, cnt);
			sum = 0;
			for (h = 0; h < cnt; h++) {
				if (h < r && vv_[h] < 0)
					continue;
				sum += vv_[h];
			}
			ans = max(ans, sum);
		}
	}
	printf("%d\n", ans);
	return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int K; cin >> K;
	int cur = 0;
	int base = 7;
	F0R(i, K) {
		if (base % K == 0) {
			print(i+1); return 0;
		}
		base = (base * 10 + 7) % K;
	}
	print(-1);
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <math.h>
#include <map>
#include <list>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <sstream>
#include <bitset>
#include <string.h>
// #include <limits.h>

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

typedef long long        ll;
typedef unsigned long long    ull;

#define INTMAX  99999999

#define DEBUG 0

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

using namespace std;

#define MAX_TA (1000)

ll N;
ll T[MAX_TA], A[MAX_TA];

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

	ll sum = 0;
	ll sumA = 0;
	ll sumT = 0;
	cin >> N;
	FOR(n,N) {
		cin >> T[n] >> A[n];
		ll tmpsum = T[n]+A[n];
		ll factor = 1;

		if(factor*tmpsum<sum) {
			factor = sum%tmpsum ? max(factor, sum/tmpsum + 1) : max(factor, sum/tmpsum);
			DOUT << "factor(1)="<<factor<<endl;
		}
		if(factor*T[n]<sumT) {
			factor = sumT%T[n] ? max(factor, sumT/T[n] + 1) : max(factor, sumT/T[n]);
			DOUT << "factor(2)="<<factor<<endl;
		}
		if(factor*A[n]<sumA) {
			factor = sumA%A[n] ? max(factor, sumA/A[n] + 1) : max(factor, sumA/A[n]);
			DOUT << "factor(3)="<<factor<<endl;
		}

		sum = factor*tmpsum;
		sumT = factor*T[n];
		sumA = factor*A[n];
		DOUT << " ### sumT="<<sumT<<endl;
		DOUT << " ### sumA="<<sumA<<endl;
		DOUT << " ### sum="<<sum<<endl;
	}

	cout << sum << endl;

	return 0;
}
 


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


int main() {
	int N;
	scanf("%d", &N);
	while (1) {
		if (N >= 0 && N <= 10) {
			break;
		}
		N = N - 10;
	}
	if (N == 2 || N == 4 || N == 5 || N == 7 || N == 9)printf("hon");
	else if (N == 3)printf("bon");
	else printf("pon");
	return 0;
}


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

using namespace std;

int a, b, ans;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> a >> b;
    if (a <= 3) {
        ans += 4 - a;
    }
    if (b <= 3) {
        ans += 4 - b;
    }
    if (a == 1 && b == 1) {
        ans += 4;
    }
    ans *= 100000;
    cout << ans << endl;
    return 0;
}


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

Atable = [[0 for i in range(m)] for j in range(n)]
Btable = [0 for i in range(m)]

for i in range(n):
    lst = list(map(int,input().split()))
    for j in range(m):
        Atable[i][j] = lst[j]

for j in range(m):
    Btable[j] = int(input())

for i in range(n):
    ans = 0
    for j in range(m):
        ans += (Atable[i][j] * Btable[j])
    print(ans)



Measured memory_bytes: 5956
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N;
	cin >> N;
	vector<int> A(N*3);
	for (int i = 0; i < N*3; i++)
		cin >> A[i];
	sort(all(A));
	ll sum = 0;
	for (int i = N; i < N*3; i+=2)
		sum += (ll)A[i];
	cout << sum << endl;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define repi(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)
#define rep(i, n) repi(i, 0, n)
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
// using P = pair<int, int>;
struct Vec{
    double x, y;
};
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;
int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    int x;
    cin >> x;
    if (x == 0) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> vec(M,vector<int>(2));
  for(int i=0; i<M; i++){
    for(int j=0; j<2; j++){
      cin >> vec.at(i).at(j);
    }
  }
  int ans = -1;
  for(int i=0; i<10000; i++){
    bool flag = true;
    string S = to_string(i);
    if(S.size() != N){
      continue;
    }
    for(int j=0; j<M; j++){
      int a = vec.at(j).at(0)-1;
      int b = vec.at(j).at(1);
      int x = S.at(a) - '0';
      if(x != b){
        flag = false;
      }
    }
    if(flag){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int on_path, N, Q, ans[100009], ap[30][30];
char curr[400009], ord[100009][26];
vector < int > v[100009];

struct nod
{
    int id, cnt;
    nod *urm[26];
    nod ()
    {
        memset (urm, 0, sizeof (urm));
        cnt = id = 0;
    }
}*R;

void solve (nod *&R)
{
    on_path += (R->id != 0);
    if (R->id)
    {
        for (auto it = v[R->id].begin (); it != v[R->id].end (); it ++)
        {
            int i = *it; ans[i] = on_path;
            for (int j=0; j<26; j++)
                for (int k=0; k<j; k++)
                    ans[i] += ap[ ord[i][j] ][ ord[i][k] ];
        }
    }
    for (int i=0; i<26; i++)
        if (R->urm[i] != 0)
        {
            for (int j=0; j<26; j++)
                if (R->urm[j] != 0) ap[i][j] += R->urm[j]->cnt;
            solve (R->urm[i]);
            for (int j=0; j<26; j++)
                if (R->urm[j] != 0) ap[i][j] -= R->urm[j]->cnt;
        }
    on_path -= (R->id != 0);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d\n", &N), R = new nod;
for (int i=1; i<=N; i++)
{
    int l;
    scanf ("%s", curr + 1), l = strlen (curr + 1);
    nod *q = R;
    for (int j=1; j<=l; j++)
    {
        int k = curr[j] - 'a';
        q->cnt ++;
        if (q->urm[k] == 0) q->urm[k] = new nod;
        q = q->urm[k];
    }
    q->cnt ++, q->id = i;
}
scanf ("%d", &Q);
for (int i=1; i<=Q; i++)
{
    int p;
    scanf ("%d ", &p), v[p].push_back (i);
    for (int j=0; j<26; j++)
        scanf ("%c", &ord[i][j]), ord[i][j] -= 'a';
}
solve (R);
for (int i=1; i<=Q; i++)
    printf ("%d\n", ans[i]);
return 0;
}


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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

using namespace std;
using lli = long long int;

lli diff(lli hA, lli wA, lli hB, lli wB, lli hC, lli wC) {
    lli areas[]{hA * wA, hB * wB, hC * wC};

    lli mx = *max_element(areas, areas + 3);
    lli mn = *min_element(areas, areas + 3);
    return mx - mn;
}

int main() {

//    freopen("input.txt", "r", stdin);

    int H, W;
    cin >> H >> W;

    if (H % 3 == 0 || W % 3 == 0) {
        cout << 0;
    } else {
        int A, B, C;
        lli ans = 10e+5;
        int hA, wA, hB, wB, hC, wC;

        wA = W;
        for (hA = 1; hA <= (H / 2) + 1; hA++) {

            // Try case 1
            hB = hC = H - hA;
            wB = (W + 1) / 2;
            wC = W / 2;
            ans = min(ans, diff(hA, wA, hB, wB, hC, wC));

            // Try case 2
            hB = (H - hA) / 2;
            hC = (H - hA + 1) / 2;
            wB = wC = W;
            ans = min(ans, diff(hA, wA, hB, wB, hC, wC));
        }

        hA = H;
        for (wA = 1; wA <= (W / 2) + 1; wA++) {
            // Try case 3
            hB = hC = H;
            wB = (W - wA) / 2;
            wC = (W - wA + 1) / 2;
            ans = min(ans, diff(hA, wA, hB, wB, hC, wC));

            // Try case 4
            wB = wC = W - wA;
            hB = H / 2;
            hC = (H + 1) / 2;
            ans = min(ans, diff(hA, wA, hB, wB, hC, wC));
        }
        cout << ans;
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[int(input()) for _ in range(n)]
a.sort(reverse=True)
if n%2==0:
  print(sum(a[:n//2])-sum(a[n//2:])+sum(a[:n//2-1])-sum(a[n//2+1:]))
else:
  c=sum(a[:n//2+1])+sum(a[:n//2-1])-2*sum(a[n//2+1:])
  d=2*sum(a[:n//2])-sum(a[n//2:])-sum(a[n//2+2:])
  print(max(c,d))


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

int main()
{
	string strNumber;
	long long int iNumberA=0,iNumberB,iLength[256]={0},i=0;
	
	while( cin >> iNumberA ){
		cin >> iNumberB;

		strNumber = to_string( iNumberA+iNumberB );

		iLength[i] = strNumber.length();
		i++;
	}

	for( int j=0;j<i;j++ ){
		cout << iLength[j] << endl;
	}

	return 0;
}

Measured memory_bytes: 1220
#include <cstdio>
#include <vector>
#include <algorithm>

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

using namespace std;

typedef vector<int> V;
typedef vector<V> M;

int n, m;
int p[3];
int t;

M mul(const M& A, const M& B){
	M C(n, V(n, 0));
	rep(i, n){
		rep(j, n){
			rep(k, n){
				C[i][j] += A[i][k] * B[k][j];
			}
			C[i][j] %= m;
		}
	}
	return C;
}

V mul(const M& A, const V& b){
	V c(n, 0);
	rep(i, n){
		rep(j, n){
			c[i] += A[i][j] * b[j];
		}
		c[i] %= m;
	}
	return c;
}

M pow(const M& A, int k){
	M B(n, V(n, 0));
	rep(i, n){
		B[i][i] = 1;
	}
	M P = A;
	while(k > 0){
		if(k & 1){
			B = mul(B, P);
		}
		P = mul(P, P);
		k >>= 1;
	}
	return B;
}

int main(){
	while(scanf("%d%d%d%d%d%d", &n, &m, &p[0], &p[1], &p[2], &t), n){
		M A(n, V(n, 0));
		rep(i, n){
			for(int j = i - 1; j <= i + 1; ++j){
				if(0 <= j && j < n){
					A[i][j] = p[j - i + 1];
				}
			}
		}
		V b(n);
		rep(i, n){
			scanf("%d", &b[i]);
		}
		A = pow(A, t);
		b = mul(A, b);
		rep(i, n){
			if(i != 0){
				putchar(' ');
			}
			printf("%d", b[i]);
		}
		putchar('\n');
	}
	return 0;
}

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

bool cmp(int a, int b) {
    return abs(a) > abs(b);
}

const int MOD = 1e9 + 7;

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end(), cmp);
    int afterpos = -1337, afterneg = 1337, insidepos = -1337, insideneg = 1337;
    int cntneg = 0, cntpos = 0;
    for (int i = 0; i < k; i++) {
        if (a[i] < 0) insideneg = a[i], cntneg++;
        else insidepos = a[i], cntpos++;
    }
    for (int i = n - 1; i >= k; i--) {
        if (a[i] < 0) afterneg = a[i];
        else afterpos = a[i];
    }

    int prod = 1;
    if (cntneg % 2 == 0) {
        for (int i = 0; i < k; i++) prod *= abs(a[i]), prod %= MOD;
        cout << prod;
        return 0;
    }
    else {
        int f = 0;
        if ((afterpos == -1337 && insidepos == -1337) || n == k) { /// If all are negative
            for (int i = n - k; i < n; i++) prod *= a[i] + MOD, prod %= MOD;
            cout << prod;
            return 0;
        }
        else if ((afterpos == -1337 || insideneg == 1337) && afterneg != 1337 && insidepos != -1337) { /// If only pos -> neg
            for (int i = 0; i < k; i++) {
                if (!f && a[i] == insidepos) f = 1, prod *= abs(afterneg), prod %= MOD;
                else prod *= abs(a[i]), prod %= MOD;
            }
            cout << prod;
            return 0;
        }
        else if ((afterneg == 1337 || insidepos == -1337) && insideneg != 1337 && afterpos != -1337) { /// If only neg -> pos
            for (int i = 0; i < k; i++) {
                if (!f && a[i] == insideneg) f = 1, prod *= abs(afterpos), prod %= MOD;
                else prod *= abs(a[i]), prod %= MOD;
            }
            cout << prod;
            return 0;
        }
        else if (afterneg != 1337 && insidepos != -1337 && insideneg != 1337 && afterpos != -1337) { /// If both possible
            int a1 = abs(insidepos * afterpos);
            int a2 = abs(insideneg * afterneg);
            if (a1 > a2) {
                for (int i = 0; i < k; i++) {
                    if (!f && a[i] == insideneg) f = 1, prod *= abs(afterpos), prod %= MOD;
                    else prod *= abs(a[i]), prod %= MOD;
                }
                cout << prod;
                return 0;
            }
            else {
                for (int i = 0; i < k; i++) {
                    if (!f && a[i] == insidepos) f = 1, prod *= abs(afterneg), prod %= MOD;
                    else prod *= abs(a[i]), prod %= MOD;
                }
                cout << prod;
                return 0;
            }
        }
    }
    assert(false);
}


Measured memory_bytes: 4780
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    string t;
    cin >> t;
    rep(i, t.size()) {
        if (t[i] == '?')t[i] = 'D';
    }
    cout << t << endl;
    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h,w,m; cin >> h >> w >> m;
  static vector<P<int,int>> b(m);
  int cntr[300001] = {};
  int cntc[300001] = {};
  int maxr=0,maxc=0;
  for(int i = 0; i < m; ++i){
    cin >> b[i].first >> b[i].second;
    ChangeMax(maxr,++cntr[b[i].first]);
    ChangeMax(maxc,++cntc[b[i].second]);    
  }
  static uset<int>r,c;
  for(int i = 1; i <= h; ++i)if(maxr == cntr[i])r.insert(i);
  for(int i = 1; i <= w; ++i)if(maxc == cntc[i])c.insert(i);
  int cntd = 0;
  for(auto e:b)
    cntd += r.count(e.first)&&c.count(e.second);
  cout << maxr + maxc - (cntd == (ll)r.size()*(int)c.size()) << endl;
}


Measured memory_bytes: 35424
using System;
using System.Linq;
using System.Collections.Generic;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var n = long.Parse(_[0]);
            var k = long.Parse(_[1]);
            var q = long.Parse(_[2]);

            var d = new Dictionary<int,long>();
            for(var i = 0; i < q; i++){
                var a = int.Parse(Console.ReadLine());
                if(d.ContainsKey(a)){
                    d[a] += 1;
                }else{
                    d.Add(a, 1);
                }
            }

            for(var i = 1; i < n + 1; i++){
                var p = q;
                if(d.ContainsKey(i)){
                    p -= d[i];
                }
                Console.WriteLine(k - p > 0 ? "Yes" : "No");
            }
        }
    }
}


Measured memory_bytes: 19036
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int k = in.nextInt();
            for (int i = 0; i <= n; i++) {
                for (int j = 0; j <= m; j++) {
                    if (m * i + n * j - 2 * i * j == k) {
                        out.println("Yes");
                        return;
                    }
                }
            }
            out.println("No");
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}



Measured memory_bytes: 22868
# 必要なライブラリのインポート
import queue


def f(x,y):
    if x < 0 or y < 0 or x >= r or y >= c:
        return False
    if m[x][y] == "#":
        return False
    elif not (x,y) in done:
        if (x,y) == (gx,gy):
            return True
        else:
            done.add((x,y))
            q.put((x,y))
            return False
    else:
        return False          

# FIFOキューの作成
q = queue.Queue()

r,c = map(int,input().split())
sx,sy = 1,1
gx,gy = r,c

sx -= 1
sy -= 1
gx -= 1
gy -= 1


m = ["" for _ in range(r)] 
sharp_counter = 0
for i in range(r):
    m[i] = input()
    sharp_counter += m[i].count("#")
    
    
q.put((sx,sy))
done = set()
counter = 1
while True:
    q_list = []
    for _ in range(q.qsize()):
        tx,ty = q.get()
        q_list.append((tx,ty))
        
    for one in q_list:
        tx,ty = one
        flags = [f(tx,ty-1),f(tx,ty+1),f(tx-1,ty),f(tx+1,ty)]
        if sum(flags) == 1:
            print(r*c -sharp_counter -(counter-1)-2)
            break
            
    if sum(flags) == 1:
        break
    if q_list == []:
        print(-1)
        break
    else:
        counter += 1
        

Measured memory_bytes: 4200
s = list(input())
t = list(input())
for i in range(len(s)):
    r = s[0]
    for j in range(len(s) - 1):
        s[j] = s[j + 1]
    s[j + 1] = r
    if (''.join(s) == ''.join(t)):
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using i64 = int64_t;
#define rep(i, s, n) for (i64 i = (s); i < (n); ++i)

i64 modexp(i64 b, i64 e, i64 m) {
  i64 ret = 1;
  while (0 < e) {
    if (e % 2 == 1) {
      ret = (ret * b) % m;
    }
    e /= 2;
    b = (b * b) % m;
  }
  return ret;
}

void run() {
  const i64 mod{1000000007};
  i64 n;
  cin >> n;
  vector<i64> cs(n + 1);
  cs[0] = 1;
  for (i64 i = 3; i < n + 1; ++i) {
    for (i64 j = 0; j < i - 2; ++j) {
      cs[i] += cs[j];
    }
    cs[i] %= mod;
  }
  cout << cs[n] << endl;
}

int main() {
  cin.tie(nullptr);
  run();
  return 0;
}


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

int main() {
  int M;
  int D;
  int d1;
  int d10;
  int value;
  int count=0;

  cin >> M >> D;

  for(int i=1;i<=M;i++){
    for(int j=1;j<=D;j++){
      d1=j%10;
      d10=j/10;
      value=d1*d10;
      if(d1>=2 & d10 >=2 & value==i){
        count++;
      }
    }
  }
  
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int fa[100005],fa1[100005],a[100005],n,m;
int find(int x){
	if(fa[x]==x) return x;
	else return fa[x]=find(fa[x]);
}
int find1(int x){
	if(fa1[x]==x) return x;
	else return fa1[x]=find(fa1[x]);
}
void uni(int x,int y){
	int f1=find(x),f2=find(y);
	if(f1!=f2) fa[f1]=f2;
}
void uni1(int x,int y){
	int f1=find1(x),f2=find1(y);
	if(f1!=f2) fa1[f1]=f2;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++) fa[i]=fa1[i]=i;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1,x,y;i<=m;i++){
		cin>>x>>y;
		uni(a[x],a[y]);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(find(a[i])==find(i)) ans++;
	}
	cout<<ans<<endl;
} 

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

#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#define endl        '\n'
#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

namespace InOp{
template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
}
using namespace InOp;

namespace ModOp{
template<class x,class y,class z> z add(x a,y b,z m){return (a+b)%m;}
template<class x,class y,class z> z sub(x a,y b,z m){return (a-b+m)%m;}
template<class x,class y,class z> z mul(x a,y b,z m){return ((ll)a*b)%m;}
template<class y,class z> z expo(ll b,y e,z m){ll a=1;b%=m;while(e!=0){if((e&1)==1){a=a*b;a=a%m;}b=b*b;b%=m;e>>=1;}return a%m;}
template<class x,class z> z inv(x b,z m){return expo(b,m-2,m);}
template<class x,class y> x invGeneral(x a,y b){if(a==0)return b==1?0:-1;x m=invGeneral(b%a,a);return m==-1?-1:((1-(ll)b*m)/a+b)%b;}
template<class x,class y,class z> z div(x a,y b,z m){ll c=inv(b,m);return mul(a,c,m);}
}
using namespace ModOp;

namespace Debug{
template<class x> void deb(x a){cerr<<"a"<<": "<<a<<endl;}
template<class x,class y> void deb(x a,y b){cerr<<"a"<<": "<<a<<" | "<<"b"<<": "<<b<<endl;}
template<class x,class y,class z> void deb(x a,y b,z c){cerr<<"a"<<": "<<a<<" | "<<"b"<<": "<<b<<" | "<<"c"<<": "<<c<<endl;}
template<class x,class y,class z,class xy> void deb(x a,y b,z c,xy d){cerr<<"a"<<": "<<a<<" | "<<"b"<<": "<<b<<" | "<<"c"<<": "<<c<<" | "<<"d"<<": "<<d<<endl;}
}
using namespace Debug;

#define N  1000005

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
        ll i,j,k,l,r,x,y,m,n;
        cin>>n;
        string s;
        cin>>s;
        ll ans=0;
        l=0;r=n-1;
        while(r>l)
        {
            while(l<n&&s[l]=='R')
            {
                l++;
            }
            while(r>=0&&s[r]=='W')r--;
            if(r<l)break;
            ans++;
            l++;
            r--;
        }
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 3728
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
-- import Data.List
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace
-- trace _ = id

solve :: Int -> Int -> Int
solve n m = ans
  where
    ans | m <= 2*n = m `div` 2
        | otherwise = n + ((m - 2*n) `div` 4)

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n,bs_m]:remLines1 = remLines0
      n = readBInt bs_n
      m = readBInt bs_m
  in solve n m

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


-------------------------------------------------------------------------------

inp1 = "1 6\n"
inp2 = "12345 678901\n"
tv1 = tmain $ B.pack inp1
tv2 = tmain $ B.pack inp2
test1 = tv1 == 2
test2 = tv2 == 175897
alltest = test1 && test2



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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

struct Edge{
    int to;
    int cost;
};
vector<Edge> g[100'000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    for(int i = 0; i < n-1; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        g[a].push_back({b, c});
        g[b].push_back({a, c});
    }

    queue<int> que;
    vector<char> c(n, 2);
    c[0] = 0;
    que.push(0);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        for(auto && i : g[v]){
            if(c[i.to] != 2) continue;
            c[i.to] = (c[v] + i.cost) % 2;
            que.push(i.to);
        }
    }
    for(int i = 0; i < n; ++i){
        cout << int(c[i]) << "\n";
    }
    return 0;
}

Measured memory_bytes: 6528
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        boolean flag = false;
        for(int i = 1;i<100;i++){
            if(a*i % b == c){
                flag = true;
                break;
            }
        }
        if(flag == true){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

template <typename T>
vector<T> _divisor(T a){
    vector<T> res;
    for(T i=1; i*i<=a; i++){
        if(a%i==0){
            res.push_back(i);
            if(i!=1&&i*i!=a) res.push_back(a/i);
        }
    }
    return res;
}

void func(long long x){
    for (long long a = -200; a <= 200; a++) {
        for (long long b = -200; b <= a; b++) {
            long long t = pow(a, 5) - pow(b, 5);
            if (t == x) {
                cout << a << " " << b << endl;
                return;
            }
        }
    }
}

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

    long long x;
    cin >> x;

    func(x);
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 以下から
const int MAX_N = 100000;
struct Edge {
    int to;
    int id;
};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c=-1, int p=-1) {
    int k=1;
    rep(i,g[v].size()) {
        int u = g[v][i].to, ei = g[v][i].id;
        if (u==p) continue;
        if (k == c) ++k;
        ans[ei] = k; ++k;
        dfs(u,ans[ei],v);
    }
}
int main() {
    int n;cin >> n;
    g.resize(n);
    ans.resize(n-1);
    rep(i,n-1) {
        int a,b;cin >> a >> b;
        --a; --b;

        g[a].push_back((Edge){b,i});
        g[b].push_back((Edge){a,i});
    }
    dfs(0);
    int mx = 0;
    rep(i,n) mx = max(mx, int(g[i].size()));
    cout << mx << endl;
    rep(i, n-1) {
        cout << ans[i] << endl;
    }

}


Measured memory_bytes: 8320
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = Integer.parseInt(sc.next());
		int ans = Integer.MAX_VALUE;
		for (int i = -100; i <= 100; i++) {
			int cost = 0;
			for (int j = 0; j < n; j++)
				cost += Math.pow(a[j] - i, 2);
			if (cost < ans)
				ans = cost;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, k;
    string s;
    cin >> n >> k >> s;
    vector<int> c;
    int p = 0;
    while(1){
        int cnt = 0;
        while(p < n && s[p] == '1'){
            cnt++;
            p++;
        }
        c.push_back(cnt);
        if(p >= n) break;
        cnt = 0;
        while(p < n && s[p] == '0'){
            cnt++;
            p++;
        }
        c.push_back(cnt);
        if(p >= n) break;
    }
    if(s.back() != '1') c.push_back(0);
    int t = 2 * k + 1;
    if(c.size() <= t){
        cout << n << endl;
    }else{
        int sum = accumulate(c.begin(), c.begin() + t, 0);
        int ans = sum;
        for(int i = t; i < c.size() - 1; i += 2){
            sum -= (c[i - t] + c[i - t + 1]);
            sum += c[i] + c[i + 1];
            ans = max(ans, sum);
        }
        cout << ans << endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;

// #define DEBUG

vector<string> perm_enum(string s, int n)
{
    vector<string> a;
    string t;
    if (n == 1)
    {
        a.push_back(s);
        return a;
    }
    else
    {
        for (int i = 0; i < n; i++)
        {
            t = "";
            for (int j = 0; j < n; j++)
            {
                if (i != j)
                    t += s[j];
            }
            vector<string> b = perm_enum(t, n - 1);
            for (string r : b)
                a.push_back(s[i] + r);
        }

        return a;
    }
}

void printperm(string s, int n)
{
    for (int i = 0; i < n - 1; i++)
        cout << s[i] << " ";
    cout << s[n - 1] << endl;
}

int frac(int n){
    int ret = 1;
    for (int i = 1; i <= n; i++)
        ret *= i;
    return ret;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif
    int n, index;
    cin >> n;
    string t, target;
    char x;
    for (int i = 0; i < n; i++){
        cin >> x;
        target += x;
    }

    for (int i = 0; i < n; i++)
        t += i + '1';
    vector<string> ans = perm_enum(t, n);
    for (int i = 0; i < frac(n); i++)
        if (ans[i] == target)
            index = i;

    for (int i = -1; i <= 1; i++)
        if (0 <= index+i && index+i <frac(n))
            printperm(ans[index+i],n);
    
    return 0;
}


Measured memory_bytes: 24872
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] h = new int[n];
        for(int i = 0; i < n; i++) h[i] = scan.nextInt();
        for(int i = n - 2; i >= 0; i--){
            if(h[i] <= h[i + 1]){
                
            }else if(h[i] - h[i + 1] == 1){
                h[i]--;
            }else if(h[i] != h[i + 1]){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
        scan.close();
    }
}

Measured memory_bytes: 49236