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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(M);
    vector<int> b(M);
    for(int i = 0; i < M; i++){
        cin >> a.at(i) >> b.at(i);
    }
    vector<int> way(N);
    for(int i = 0; i < M; i++){
        for(int j = 1; j <= N; j++){
            if(a.at(i) == j){
                way.at(j - 1)++;
            }
            if(b.at(i) == j){
                way.at(j - 1)++;
            }
        }
    }
    for(int i = 0; i < N; i++){
        cout << way.at(i) << endl;
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main() {
  Cin(int, n, a, b);
  Cin(string, s);

  int yosen = 0, kaigai = 1;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'a') {
      if (yosen < a + b) {
        puts("Yes");
        yosen++;
      } else
        puts("No");
    } else if (s[i] == 'b') {
      if (yosen < a + b && kaigai++ <= b) {
        puts("Yes");
        yosen++;
      } else {
        puts("No");
      }
    } else {
      puts("No");
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 848
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

const M: usize = 1_000_000_007;

fn main() {
    input! {
        s: chars,
    }

    let mut dp = vec![vec![0; 4]; s.len() + 1];
    dp[0][0] = 1_usize;

    for i in 0..s.len() {
        for j in 0..4 {
            let c = s[i];
            if c == '?' {
                dp[i + 1][j] += 3 * dp[i][j];
                dp[i + 1][j] %= M;
                if j < 3 {
                    dp[i + 1][j + 1] += dp[i][j];
                    dp[i + 1][j + 1] %= M;
                }
            } else {
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][j] %= M;
                if j < 3 && c == "ABC".chars().nth(j).unwrap() {
                    dp[i + 1][j + 1] += dp[i][j];
                    dp[i + 1][j + 1] %= M;
                }
            }
        }
    }
    println!("{}", dp[s.len()][3]);
}


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

using namespace std;
typedef long long ll;
int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        string s;ll k;
        cin>>k>>s;
        string ss=s.substr(0,k);
        cout<<ss;
        if(ss!=s)cout<<"...";
    }
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    int x;
    cin >> x;
    if(x<1200) cout << "ABC" << endl;
    else cout << "ARC" << endl;
    return 0;
}

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

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

    vector<lint> a(n);
    for(lint i=0; i<n; i++)  cin >> a[i];

    lint now = 1;
    lint ans = 0;
    for(auto e : a) {
        if(now == e) {
            now++;
        } else {
            ans++;
        }
    }

    cout << (ans == n ? -1 : ans) << endl;
}

Measured memory_bytes: 1792
import sys
from io import StringIO
import unittest

sys.setrecursionlimit(100**3)

def coloring(v, p, vs, cs, color):
	cs[v] = color
	for e in vs[v]:
		if e[0] == p:
			continue
		nc = color if e[1] % 2 == 0 else 1 - color
		coloring(e[0], v, vs, cs, nc)

def resolve():
	n = int(input())
	vs = [[] for _ in range(n)]
	cs = [None]*n
	for i in range(n-1):
		u, v, w = map(int, input().split())
		vs[u-1].append([v-1, w])
		vs[v-1].append([u-1, w])
	coloring(0, None, vs, cs, 1)
	for i in cs:
		print(i)
resolve()

Measured memory_bytes: 88548
import itertools

N, M, X = map(int, input().split())
List = [list(map(int, input().split())) for n in range(N)]
INF = 10**7
ans = INF
C_pro = list(itertools.product([0,1], repeat=N))

for c_pro in C_pro:
    count = 0
    cost = 0
    ans_list = [0 for i in range(M)]
    for c in c_pro:
        if c == 1:
            cost += List[count][0]
            ans_list = [answ+list for answ, list in zip(ans_list,List[count][1:])]
        count += 1
    ok = True
    for i in range(len(ans_list)):
        if ans_list[i] < X:
            ok = False
            break
    if ok:
        ans = min(ans, cost)
    

if ans == 10**7:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N;
int K;

struct Edge {
  int index, to;
};

vector<int> c;
vector<vector<Edge>> G;

void color(int u, int p, int pc) {
  int k = pc;
  for (Edge& e : G[u]) {
    if (e.to == p) continue;
    k = (k + 1) % K;
    c[e.index] = k;
    color(e.to, u, k);
  }
}

int main() {
  cin >> N;

  c.resize(N - 1, -1);
  G.resize(N);

  K = 0;

  rep(i, N - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(Edge{i, b});
    G[b].push_back(Edge{i, a});
  }

  rep(i, N) K = max(K, (int)G[i].size());

  color(0, -1, -1);

  cout << K << endl;
  rep(i, N - 1) cout << c[i] + 1 << endl;

  return 0;
}


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

typedef pair<int, int> P;

int main() {

    int n;
    cin >> n;
    int a[n];
    int max = 0, semimax = 0;
    ll index;
    rep(i,n){
        cin >> a[i];
        if(max < a[i]){
            index = i;
            semimax = max;
            max = a[i];
        }else if(a[i] > semimax){
            semimax = a[i];
        }
    }

    rep(i,n){
        if(i!=index){
            cout << max << endl;
        }else{
            cout << semimax << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP_ll(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VREP_int(v) for(std::vector<int>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int N,M,C;

	cin >> N >> M >> C;
	int A,B[M];

	REP(i,M) cin >> B[i];
	int ret = 0;
	REP(i,N){
		int sum=0;
		REP(j,M) {
			cin >> A;
			sum += A * B[j];
		}
		if(sum+C > 0) ret++;
	}

	println(ret);

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
  ll N,cnt;
  cin >> N;
  ll a[3*N];
  for(ll i=0;i<3*N;i++) cin >> a[i];
  sort(a,a+3*N);
  for(ll i=0;i<N;i++) cnt +=a[3*N-2*(i+1)];
  cout << cnt;
}

Measured memory_bytes: 2560
def include?(arr, n)
  if arr.length == 1
    return arr[0] == n
  else
    if arr[arr.length / 2] <= n
      return include?(arr[arr.length / 2..arr.length - 1], n)
    else
      return include?(arr[0...arr.length / 2], n)
    end
  end
end
gets
arr = gets.split(" ").map(&:to_i)
gets
count = 0
gets.split(" ").map(&:to_i).each{|item|
  count += 1 if include?(arr, item)
}
puts count

Measured memory_bytes: 83840
#include<iostream>

int main(){
  int n,k;
  std::cin>>n>>k;
  int arr[n][k];

  for(int i=0; i<n; ++i)
    for(int j=0; j<k; ++j)
      arr[i][j] = 0;

  int ns, val;
  for(int i=0; i<k; ++i){
    std::cin>>ns;
    while(ns--){
      std::cin>>val;
      arr[val-1][i] = 1;
    }
  }

  int sum=0, count=0;
  for(int i=0; i<n; ++i){
    sum=0;
    for(int j=0; j<k; ++j){
      sum += arr[i][j];
    }
    if(sum == 0)
      ++count;
    }
  std::cout<<count;
}


Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.IO;

class Solve {
    static void Main(string[] args) {
        var N = int.Parse(Console.ReadLine());
        var abc = new List<int[]>(N);
        for (int i = 0; i < N; i++) abc.Add(Array.ConvertAll(Console.ReadLine().Split(), int.Parse));
        var dp = new int[N, 3];
        for (int i = 0; i < 3; i++) dp[0, i] = abc[0][i];
        for (int i = 1; i < N; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    if (j == k) continue;
                    dp[i, j] = Math.Max(dp[i, j], dp[i - 1, k] + abc[i][j]);
                }
            }
        }
        var answer = 0;
        for (int i = 0; i < 3; i++) {
            answer = Math.Max(answer, dp[N - 1, i]);
        }
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();
    }
}

Measured memory_bytes: 48360
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max = 0;
    int maxNum = 1;
    for (int i = 1; i <= n; i++) {
      int num = i;
      int count = 0;
      while (true) {
        if (num % 2 == 0) {
          num = num / 2;
          count++;
        } else {
          if (count > max) {
            max = count;
            maxNum = i;
          }
          break;
        }
      }
    }
    System.out.println(maxNum);
  }
}

Measured memory_bytes: 35624
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,D,ans=0;
  cin>>N>>D;
  REP(i,N){
    ll X,Y;
    cin>>X>>Y;
    if(X*X+Y*Y<=D*D) ans++;
  }
  co(ans);
  return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>

using namespace std;

int main(void) {

	int n, c;

	cin >> n;

	for (int i = n;; i++) {
		if (i / 100 == i / 10 - (i / 100) * 10 && i / 10 - (i / 100) * 10 == i % 10) {
			cout << i << "\n";
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int exp(int a, int b)
{
    if (b == 0)
    {
        return 1;
    }
    return a * exp(a, b - 1);
}

int main()
{
    int X;
    cin >> X;
    int ans = 0;
    for (int i = 1; i <= X; i++)
    {
        for (int j = 2; j <= 10; j++)
        {
            if (exp(i, j) > X)
            {
                break;
            }
            ans = max(ans, exp(i, j));
        }
    }
    cout << ans << endl;
}

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

top = max(A)
out = [0]*(10**6+1)

for i in range(N):
  acm = A[i]
  while acm<=top:
    out[acm] += 1
    acm += A[i]
    
count = 0
for i in range(N):
  if out[A[i]] == 1:
    count += 1
print(count)

Measured memory_bytes: 31984
#include<bits/stdc++.h>
#define LL long long
#define db double

using namespace std;
const int N=2000+10;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
int to[N<<5],nt[N<<5],hd[N<<4],tot=1;
void adde(int x,int y)
{
	++tot,to[tot]=y,nt[tot]=hd[x],hd[x]=tot;
	++tot,to[tot]=x,nt[tot]=hd[y],hd[y]=tot;
}
int n,t,a[N],vs[N<<4],mk[N<<4],ti,ban[N<<4],dl[N],sq[N],ts,ff[N];
int findf(int x){return ff[x]==x?x:ff[x]=findf(ff[x]);}
vector<int> an[N],ls,nl;
map<int,int> id;
void clr(int x)
{
	mk[x]=ti,vs[x]=vs[0];
	for(int i=hd[x];i;i=nt[i])
	{
		int y=to[i];
		if(ban[i>>1]||mk[y]==ti) continue;
		clr(y);
	}
}

int main()
{
/////////////
	n=rd(),t=n;
	for(int i=1;i<=n;++i)
	{
		a[i]=rd();
		int x=a[i],sqt=sqrt(x);
		for(int j=2;j<=sqt;++j)
			if(x%j==0)
			{
				if(!id[j]) id[j]=++t;
				adde(i,id[j]);
				while(x%j==0) x/=j;
			}
		if(x>1)
		{
			if(!id[x]) id[x]=++t;
			adde(i,id[x]);
		}
	}
	memset(vs,0x3f3f3f,sizeof(vs));
	a[0]=1<<30;
	int rs=n;
	while(rs--)
	{
		int sx=0;
		for(int i=1;i<=n;++i)
			if(!dl[i]&&vs[sx]>vs[i]) sx=i;
		if(!sx)
		{
			for(int i=1;i<=n;++i)
				if(!dl[i]&&a[sx]>a[i]) sx=i;
		}
		else
		{
			for(int i=1;i<=n;++i)
				if(!dl[i]&&vs[i]==vs[sx]&&a[sx]>a[i]) sx=i;
		}
		dl[sx]=1,sq[++ts]=sx;
		++ti,clr(sx);
		for(int i=hd[sx];i;i=nt[i])
		{
			int y=to[i];
			ban[i>>1]=1;
			for(int j=hd[y];j;j=nt[j])
			{
				if(ban[j>>1]) continue;
				int z=to[j];
				vs[z]=ts;
			}
		}
	}
	for(int i=1;i<=n;++i) ff[i]=i,an[i].push_back(a[i]);
	while(ts)
	{
		int x=sq[ts--];
		ls.clear();
		for(int i=hd[x];i;i=nt[i])
		{
			int y=to[i];
			ban[i>>1]=0;
			for(int j=hd[y];j;j=nt[j])
			{
				if(ban[j>>1]) continue;
				int z=to[j];
				if((z=findf(z))!=findf(x))
				{
					int nn=ls.size(),mm=an[z].size(),p=0,q=0,r=0;
					nl.clear(),nl.resize(nn+mm);
					while(p<nn&&q<mm)
					{
						if(ls[p]>an[z][q]) nl[r++]=ls[p],++p;
						else nl[r++]=an[z][q],++q;
					}
					while(p<nn) nl[r++]=ls[p],++p;
					while(q<mm) nl[r++]=an[z][q],++q;
					ls=nl;
					ff[z]=x;
				}
			}
		}
		int nn=ls.size();
		for(int i=0;i<nn;++i) an[x].push_back(ls[i]);
	}
	ls.clear();
	for(int i=1;i<=n;++i)
		if(findf(i)==i)
		{
			int nn=ls.size(),mm=an[i].size(),p=0,q=0,r=0;
			nl.clear(),nl.resize(nn+mm);
			while(p<nn&&q<mm)
			{
				if(ls[p]>an[i][q]) nl[r++]=ls[p],++p;
				else nl[r++]=an[i][q],++q;
			}
			while(p<nn) nl[r++]=ls[p],++p;
			while(q<mm) nl[r++]=an[i][q],++q;
			ls=nl;
		}
	for(int i=0;i<n;++i) printf("%d ",ls[i]);
	return 0;
}


Measured memory_bytes: 13952
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  cout<<0<<endl;
  string s;cin>>s;
  int r;
  if(s=="Vacant")return 0;
  if(s=="Male")r=1;
  if(s=="Female")r=2;
  int u=n-1;
  int d=0;
  while(u-d>1){
    int mid=(u+d)/2;
    cout<<mid<<endl;
    string t;cin>>t;
    if(t=="Vacant")return 0;
    if(mid%2==0){
      if(t==s){
        d=mid;
      }
      if(t!=s){
        u=mid;
      }
    }
    else{
      if(t==s){
        u=mid;
      }
      if(t!=s){
        d=mid;
      }
    }
  }
  cout<<u<<endl;
  string l;cin>>l;
  return 0;
}

Measured memory_bytes: 852
n = int(input())
arr = list(map(int, input().split()))
dp = [0 for i in range(n)]
sum = 0
dp[1] = abs(arr[1]-arr[0])
for i in range(2, len(arr)):
    dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]))
print(dp[-1])


Measured memory_bytes: 90108
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n,m = inpm()
    g = [[] for _ in range(n)]
    for _ in range(m):
        u,v = inpm()
        u -= 1
        v -= 1
        g[u].append(v)
    s,t = inpm()
    s -= 1
    t -= 1
    que = deque()
    que.append(s)
    visited1 = [0 for _ in range(n)]
    visited2 = [0 for _ in range(n)]
    visited3 = [0 for _ in range(n)]
    visited3[s] = 1
    cnt = 1
    while True:
        tank1 = deque()
        tank2 = deque()
        tank3 = deque()
        while que:
            start = que.pop()
            for go in g[start]:
                if not visited1[go]:
                    visited1[go] = 1
                    tank1.append(go)
        while tank1:
            start = tank1.pop()
            for go in g[start]:
                if not visited2[go]:
                    visited2[go] = 1
                    tank2.append(go)
        while tank2:
            start = tank2.pop()
            for go in g[start]:
                if not visited3[go]:
                    visited3[go] = 1
                    tank3.append(go)
                if go == t:
                    print(cnt)
                    return
        que = tank3
        cnt += 1
        if que == deque():
            break
    print(-1)
    
if __name__ == "__main__":
    main()

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

#ifdef LOCAL
#define dbg(x) (cerr << "ln " << __LINE__ << ": " << #x << " = " << (x) << '\n')
#else
#define dbg(x) {}
#endif

int n;
int a[100005];
int c[16];
int sol;

int d[65536];
set<pair<int, int>> pq;

inline int heur(int x) {
	int z = __builtin_popcount(x);
	return (z + 1) >> 1;
}

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

	cin >> n;
	for (int i=1; i<n; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		a[u] ^= w;
		a[v] ^= w;
	}

	for (int i=0; i<n; i++) {
		c[a[i]]++;
	}

	for (int i=1; i<16; i++) {
		sol += c[i] / 2;
		c[i] %= 2;
	}

	// a-star
	int mask = 0;
	for (int i=1; i<16; i++) {
		if (c[i]) {
			mask += 1 << i;
		}
	}

	fill(d, d+65536, 10000);
	d[mask] = 0;

	dbg(mask);

	pq.insert({heur(mask), mask});

	while (!pq.empty()) {
		auto xmask = pq.begin()->second;
		pq.erase(pq.begin());

		if (xmask == 0) {
			cout << sol + d[xmask] << '\n';
			return 0;
		}

		for (int i=1; i<16; i++) if (xmask & (1 << i)) {
			for (int j=i+1; j<16; j++) if (xmask & (1 << j)) {
				for (int k=1; k<16; k++) {

					int ldis = 1;

					int m2 = xmask;
					m2 -= 1 << i;
					m2 -= 1 << j;

					if (i != k && (m2 & (1 << (i ^ k)))) {
						ldis++;
					}
					if (j != k && (m2 & (1 << (j ^ k)))) {
						ldis++;
					}

					m2 ^= (1 << (i ^ k));
					m2 ^= (1 << (j ^ k));

					m2 &= ~1;

					if (d[xmask] + ldis < d[m2]) {
						pq.erase({heur(m2) + d[m2], m2});
						d[m2] = d[xmask] + ldis;
						pq.insert({heur(m2) + d[m2], m2});
					}
				}
			}
		}		

	}



}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5, INF = 1e9;

int n, k, a[N];

int main() {
    cin >> n >> k;
    for(int i=0; i<n; i++)  cin >> a[i];
    int l = 1, r = INF;
    while(l < r) {
        int mid = (l+r)/2,
            tot = 0;
        for(int i=0; i<n; i++) {
            int r = a[i] % mid;
            tot += a[i]/mid + (r>0) - 1;  
        }
        if(tot <= k) {
            r = mid;
        } else {
            l = mid+1;
        }
    }
    cout << l;
}

Measured memory_bytes: 4316
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  int memo=1,ans=0;
  rep(i,0,N){
    int X=(A[i]-1)/memo;
    ans+=X;
    if(X==0){
      memo=max(A[i]+1,memo);
    }
    else memo=max(2ll,memo);
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 1024
N = int(input())

f = [0] * (N + 1)

for x in range(1, 101):
  for y in range(1, 101):
    for z in range(1, 101):
      n = x**2 + y**2 + z**2 + x * y + y * z + z * x
      if n <= N:
        f[n] += 1

for i in range(1, N + 1):
  print(f[i])

Measured memory_bytes: 9248
a = []
for i in range(3):
    a.extend(list(map(int, input().split())))
n = int(input())
for i in range(n):
    b = (int(input()))
    if b in a:
        a[a.index(b)] = 0

if ((a[0]==a[1]==a[2]==0) or (a[3]==a[4]==a[5]==0) or (a[6]==a[7]==a[8]==0)):
    print('Yes')
elif ((a[0]==a[3]==a[6]==0) or (a[1]==a[4]==a[7]==0) or (a[2]==a[5]==a[8]==0)):
    print('Yes')
elif ((a[0]==a[4]==a[8]) or (a[2]==a[4]==a[6])):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n, y; cin >> n >> y;
	y /= 1000;
	for (int a = 0; a <= n; a++) {
		for (int b = 0; b <= n-a; b++) {
			int c = n - (a + b);

			int sum = 10 * a + 5 * b + c;

			if (sum == y) {
				cout << a <<" "<< b <<" "<<c<< endl;
				return 0;
			}
			
		}
	}

	cout << -1 <<" "<< -1 <<" "<< -1<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i,k) for(i=0;i<k;i++)


int main() {
	ll a[100000], b = 0 , i, j, k, l, n, z = 100, sum = 0;
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		b = b + abs(a[i]);
	}
	sort(a, a + n);
	if (a[0] >= 0)cout << b - 2*a[0] << "\n";
	else {
		if (a[n - 1] < 0)cout << b + 2 * a[n - 1] << "\n";
		else cout << b << "\n";
	}

	k = a[0]; l = a[n - 1];
	for (i = 1; i < n - 1; i++) {
		if (a[i] < 0) {
			cout << l << " " << a[i] << "\n";
			l = l - a[i];
		}
		else {
			cout << k << " " << a[i] << "\n";
			k = k - a[i];
		}
	}
		cout << l << " " << k << "\n";

	return 0;
}

Measured memory_bytes: 2688
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) throws Exception {
        /**           入力                    **/
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Set<Integer> aData = new HashSet<Integer>();
 
        for(int i = 0; i < n; i++){
            aData.add(scanner.nextInt());
        }
        
        //デバッグ
        //for(String aTxt : aInput) {
        //  System.out.println(aTxt);
        //}
        
        /********** ここから問題 ********/
        
        /**           出力                    **/
        System.out.println(aData.size());
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 314159
#define  vi vector<int>
#define  v  vector

signed main() 
{
        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
        int n,k;
        cin>>n>>k;
        cout<<n-k+1;



        return 0;

}

//       g++ -g c.cpp ; ./a.exe

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    VL A(N);
    REP(i,N){
        cin >> A[i];
    }
    VL B(N),C(N);

    B[0] = A[0];
    C[N-1] = A[N-1];
    FOR(i,1,N){
        B[i] = max(B[i-1],A[i]);
    }
    for(int i = N-2; i >= 0; i--){
        C[i] = max(C[i+1],A[i]);
    }
    LL ans;
    REP(i,N){
        if(i == 0) ans = C[1];
        else if(i == N-1) ans = B[N-2];
        else{
            ans = max(B[i-1],C[i+1]);
        }
        cout << ans << endl;
    }

}


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

int main(){
  int64_t N,K;
  cin>>N>>K;
  vector<pair<int,int>> p(N);
  for(int i=0;i<N;++i){
    cin>>p.at(i).first>>p.at(i).second;
  }
  sort(p.begin(),p.end());
  int64_t sum=0;
  int index=0;
  while(sum+p.at(index).second<K){
    sum += p.at(index).second;
    ++index;
  }

  cout<<p.at(index).first<<endl;
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int n;
string str[555];

map< char, set< char > > arc;
vector< bool > vis;

bool dfs(char c) {
	//cerr << c << endl;
	if (vis[c - 'a']) return true;
	vis[c - 'a'] = true;
	
	for (char nc : arc[c]) if (dfs(nc)) return true;
	
	vis[c - 'a'] = false;
	
	return false;
}

void solve() {
	for_(i,1,n) {
		for_(j,0,i) {
			if (str[j].size() <= str[i].size()) continue;
			
			if (str[j].substr(0, str[i].size()) == str[i]) {
				cout << "no" << endl;
				return;
			}
		}
	}
	
	for_(k,0,10) {
		int p = -1;
		
		for_(i,0,n) {
			if ((int)str[i].size() < k + 1) continue;
			
			if (p != -1) {
				if (str[p].substr(0, k) == str[i].substr(0, k)) {
					if (str[p][k] != str[i][k]) {
						arc[str[i][k]].insert(str[p][k]);
					}
				}
			}
			
			p = i;
		}
	}
	
	for_(i,0,26) {
		//cerr << "-----" << endl;
		if (dfs('a' + i)) {
			cout << "no" << endl;
			return;
		}
	}
	
	cout << "yes" << endl;
}

int main() {
	while (cin >> n, n) {
		for_(i,0,n) cin >> str[i];
		arc.clear();
		vis.assign(26, false);
		solve();
	}
}

Measured memory_bytes: 3232
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define remove_duplicate(a) sort(a.begin(), a.end()); a.resize(distance(a.begin(), unique(a.begin(), a.end())));

typedef long long longint;



longint n;
deque<int> q;
int main(){
    #define file "in"
    //freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);

    cin >> n;
    vector<int> op;
    while (n) { if (n % 2 == 1) op.push_back(0), n /= 2; else op.push_back(1), n--; }
    deque<int> q;
    int value = 1;
    for (int i = op.size() - 1; i >= 0; i--) {
        if (op[i] == 1) q.push_front(value);
        else q.push_back(value);
        value++;
    }
    cout << q.size() * 2 << endl;
    for (int value = 1; value <= q.size(); value++) cout << value << " ";
    for (int value : q) cout << value << " ";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
                                    #include <iomanip>
                                    #include <sstream>
                                    #include <cstring>
                                    #include <vector>
                                    #include <deque>
                                    #include <queue>
                                    #include <set>
                                    #include <map>
                                    #include <valarray>
                                    #include <iterator>
                                    #include <functional>
                                    #include <limits>
                                    #include <algorithm>
                                    #include <numeric>
                                    #include <cmath>
                                    #include <cassert>
                                    #include <unordered_map>
                                    #include <unordered_set>
                                    #include <stack>
                                    using namespace std;
                                    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
                                     #define trace(x) cerr << #x << ": " << x << " " << endl;
                                 
                                    typedef int64_t ll;
                                 
                                    #define endl '\n'
                                    #define int ll
                                    ll mod=1e9+7;
                                    ll mod1=1e9+5;
                                    
                                    ll power(ll a,ll b)
                                    {
                                        if(b==0) return 1;
                                        else if(b%2==0)
                                            return power((((a%mod)*(a%mod))%mod),b/2)%mod;
                                        else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
                                    }
                                
                                    
                                int32_t main()
                                {
                                    IOS
                                   

                                
                                int a,b,c;
                                cin>>a>>b>>c;
                                if(a+b+c>=22)
                                {
                                    cout<<"bust";
                                }
                                else
                                    cout<<"win";

                                }                       


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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;ver<(n);ver++)
#define loop while(true)
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

typedef long long ll;
typedef pair<int, int> P;

int main(){
  int n;
  string s;
  cin >> n;
  if(n % 2 == 1){
    cout << "No";
    return 0;
  }
  
  cin >> s;
  
  n /= 2;
  
  rep(i, n){
    if(s[i] != s[i + n]){
      cout << "No";
      return 0;
    }
  }
  
  cout << "Yes";
  
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

N = int(input())
adjL = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    u, v = u-1, v-1
    adjL[u].append((v, w))
    adjL[v].append((u, w))

colors = [0] * N
def dfs(vNow, vPar):
    color = colors[vNow]
    for v2, wt in adjL[vNow]:
        if v2 == vPar: continue
        if wt%2:
            colors[v2] = 1-color
        else:
            colors[v2] = color
        dfs(v2, vNow)

dfs(0, -1)

print('\n'.join(map(str, colors)))


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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n; cin >> n;
	string s; cin >> s;
	bool ok=1;
	for(int i=0; i<n/2; i++){
		if(s[i]!=s[i+n/2])ok=0;
	}
	if(n%2==1)ok=0;
	if(!ok)cout << "No" << endl;
	else cout << "Yes" << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 256
n = int(input())
c = list(input())

l = 0
r = n-1
count = 0
while r > l:
    while r >= 0 and c[r] != "R":
        r -= 1
    while l < n and c[l] != "W":
        l += 1
    
    if r < 0 or l >= n:
        break
    elif r < l:
        break
    else:
        count += 1
        r -= 1
        l += 1
    
print(count)

Measured memory_bytes: 10772
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

#define BUG (cout << "Sehen Sie mich!" << endl)

int main()
{
        int n;
        int minv;
        int maxv = -2000000000;
        int tmp;
        cin >> n;
        cin >> tmp;
        minv = tmp;
        for (int i = 1; i < n; i++) {
                cin >> tmp;
                maxv = max(maxv, tmp - minv);
                minv = min(minv, tmp);
        }

        cout << maxv << endl;
}



Measured memory_bytes: 3092
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
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;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> L(N+1);
    L[0] = 2; L[1] = 1;
    rep(i,N-1) L[i+2] = L[i+1] + L[i];

    cout << L[N] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	bool ans = true;
	int n;
	cin >> n;
	for(int i=1,val;i<=n;i++) {
		cin >> val;
		if(~val&1) {
			if(val % 3 != 0 && val % 5 != 0)
				ans = false;
		}
	}
	cout << (ans ? "APPROVED" : "DENIED") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cassert>
#include <cstring>
#include <climits>
 
using namespace std;
 
#define FOR(k,a,b) for(int k=(a); k < (b); k++)
#define FORE(k,a,b) for(int k=(a); k <= (b); k++)
#define REP(k,a) for(int k=0; k < (a); k++)
 
#define ALL(c) (c).begin(), (c).end()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define RANGE(lb, x, ub) ((lb) <= (x) && (x) < (ub))
 
#define dump(x) cerr << #x << ": " << (x) << endl;
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
 
const int INF = 1000000000;
const double EPS = 1e-10;
const double PI = acos(-1.0);

bool dfs(int x, vector<vector<PII> > &ls, vector<vector<PII> > &rs, vector<ll> &pos) {
	if (pos[x] == LONG_MAX) {
		pos[x] = 0;
	}

	for (auto pair : ls.at(x)) {
		int r = pair.first; int d = pair.second;
		if (pos[r] == LONG_MAX) {
			pos[r] = pos[x] + d;
			if (!dfs(r, ls, rs, pos)) return false;
		} else {
			if (pos[r] - pos[x] != d) return false;
		}
	}

	for (auto pair : rs.at(x)) {
		int l = pair.first; int d = pair.second;
		if (pos[l] == LONG_MAX) {
			pos[l] = pos[x] - d;
			if (!dfs(l, ls, rs, pos)) return false;
		} else {
			if (pos[x] - pos[l] != d) return false;
		}
	}

	return true;
}
 
int main(void) {
    int n, m;
    cin >> n >> m;

	vector<ll> pos(n, LONG_MAX);
	vector<vector<PII> > ls(n), rs(n);
	for (int i = 0; i < m; i++) {
		int l, r, d; cin >> l >> r >> d;
		l--; r--;
		ls[l].push_back(make_pair(r, d));
		rs[r].push_back(make_pair(l, d));
	}

	for (int x = 0; x < n; x++) {
		if (!dfs(x, ls, rs, pos)) {
			printf("No\n");
			return 0;
		}
	}

	ll L=0, R=0;
	for (ll p : pos) {
		if (p != LONG_MAX) {
			L = min(L, p);
			R = max(R, p);
		}
	}
	if (R - L > 1000000000) {
		printf("No\n");
	} else {
		printf("Yes\n");
	}

    return 0;
}


Measured memory_bytes: 20992
package main
import (
	"fmt"
	"bufio"
	"os"
	"strings"
)

func craetea2z() string {
	alphabet := make([]rune, 0)
	for cur := []rune("a"); ; cur[0] += 1 {
		alphabet = append(alphabet, cur[0])
		if string(cur[0]) == "z" {
			break
		}
	}
	return string(alphabet)
}

var alphabetmap map[string]int

func main() {
	alphabetmap = map[string]int{}
	alphabet := craetea2z()
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for scanner.Scan(){
		s := strings.ToLower(scanner.Text())
		for _, v := range []rune(s){
			if _, ok := alphabetmap[string(v)]; ok{
				alphabetmap[string(v)]+=1
			}else{
				//fmt.Println(string(v))
				alphabetmap[string(v)]=1
			}
		}
	}
	for _, v := range []rune(alphabet){
		fmt.Printf("%s : %d\n", string(v), alphabetmap[string(v)])
	}
}


Measured memory_bytes: 1092
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define mp make_pair
#define ll long long
#define pb push_back

void solve()
{
  int x;
  cin>>x;
  
  cout<<1-x<<endl;
    
}

int main()
{
    int t = 1;
    //cin>>t;
    
    while(t--)
    {
        solve();
    }
}


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

using namespace std;
vector < vector <char> > matrica;
vector < vector <int> > vrijednosti;
vector <char> pomocMatrice;
vector <int> pomocVrijednosti;
const int modulo=1e9+7;
int main(){
	char a;
	int H , W;
	cin>>H>>W;
	pomocVrijednosti.insert(pomocVrijednosti.begin(),W+1,0);
	vrijednosti.insert(vrijednosti.begin(),H+1,pomocVrijednosti);
	for (int i=0;i<H;i++){
		for (int j=0;j<W;j++){
			cin>>a;
			pomocMatrice.push_back(a);
		}
		matrica.push_back(pomocMatrice);
		pomocMatrice.clear();
	}
	vrijednosti[0][0]=1;
	for (int i=0;i<H;i++)
		for (int j=0;j<W;j++) {
			//cout << i << " " << j << endl;
			if (matrica[i][j]!='#'){
				if (i-1>=0 && matrica[i-1][j]!='#'){
					//cout << "wtf prvi" << endl;
					vrijednosti[i][j]+=(vrijednosti[i-1][j]);
					vrijednosti[i][j]%=modulo;
					//cout << "prezivio sam!!!!!!" << endl;
				}
				if (j-1>=0 && matrica[i][j-1]!='#'){
					//cout << "wtf drugi" << endl;
					vrijednosti[i][j]+=(vrijednosti[i][j-1]);
					vrijednosti[i][j]%=modulo;
				}
			}
		}
	
	/*for (int i=0;i<H;i++){
		for (int j=0;j<W;j++){
			cout<<vrijednosti[i][j]<<' ';
		}
		cout<<endl;
	}*/
	
	cout<<vrijednosti[H-1][W-1];

	
	return 0;
}


Measured memory_bytes: 5248
import java.util.*;
import java.math.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        int[] A = new int[N];

        int sum = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            sum += A[i];
        }

        Arrays.sort(A);
        if (sum >  4 * M * A[N - M]) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int countDeta;
		int[] detaX = new int[3000];
		int[] detaY = new int[3000];
		for (countDeta = 0; true; countDeta++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			if (x == 0 && y == 0) {
				break;
			}
			detaX[countDeta] = x;
			detaY[countDeta] = y;
		}
		for (int i = 0; i < countDeta; i++) {
			if (detaX[i] <= detaY[i]) {
				System.out.println(detaX[i] + " " + detaY[i]);
			} else {
				System.out.println(detaY[i] + " " + detaX[i]);
			}
		}
		sc.close();
	}
}


Measured memory_bytes: 36800
/*****************************************************
 *     created by: nayakashutosh9
 * "Winners Never Quit and Quitters Never Win".
*****************************************************/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define endl '\n'
#define mod 1000000007
#define inf 1e18
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const int N = 300005;
/**********************************************************************************************/

unordered_map<int, set<int>> g;
vector<bool> vis; int cnt;
void dfs(int node) {
	vis[node] = 1; cnt++;
	for (int j : g[node]) {
		if (!vis[j]) dfs(j);
	}
}
void solve() {
	int n, m; cin >> n >> m;
	g.clear();
	for (int i = 0; i < m; i++) {
		int x, y; cin >> x >> y;
		g[x].insert(y);
		g[y].insert(x);
	}
	vis.clear(); vis.resize(n + 1, 0);
	vector<int> a;
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) {
			cnt = 0;
			dfs(i);
			a.push_back(cnt);
		}
	}
	int ans = 0;
	sort(a.begin(), a.end(), greater<int>());
	while (a.size() > 0) {
		int cur = a.back();
		ans += cur;
		while (a.size() > 0 && a.back() == cur)
			a.pop_back();
		for (int i = 0; i < a.size(); i++) a[i] -= cur;
	}
	cout << ans << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1, z = 1;
	// cin >> t; cin.ignore();
	while (t--) {
		// cout << "Case #" << (z++) << ": ";
		// clock_t start = clock();
		solve();
		// clock_t end = clock();
		// cout << (end-start) << endl;
		//print execution time in ms
	}

	return 0;
}

Measured memory_bytes: 52108