akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int N;
	cin>>N;
	vec(A)
	pb(A,0)
	fx(N){
		vecp(A)
	}
	int i=1;
	int ans=0;
	while(true){
		if(A.at(i)!=0){
			ans++;
          int k=A.at(i);
          	A.at(i)=0;
			i=k;

			if(i==2){break;}
		}else{
			ans=-1;
			break;
		}
	}
	ce(ans)
}

Measured memory_bytes: 892
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
e = []
for i in a:
    for j in b:
        e.append(i + j)
e = sorted(e, reverse=True)[:k]
ans = []
for i in e:
    for j in c:
        ans.append(i + j)
ans = sorted(ans, reverse=True)[:k]
for i in ans:
    print(i)

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

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

ll N, M, R;
int main(){
    ios::sync_with_stdio(false);
    cin >> N >> M >> R;
    
    vector<vector<ll> > d(N, vector<ll>(N));
    REP(i,N)REP(j,N) {d[i][j]=INF*INF; if(i==j) d[i][j]=0;}
    
    vector<ll> r(R);
    REP(i, R) {
        cin >> r[i];
        r[i]--;
    }
    
    REP(i, M) {
        ll A, B, C;
        cin >> A >> B >> C;
        A--;B--;
        d[A][B] = min(d[A][B], C);
        d[B][A] = min(d[B][A], C);
    }
    REP(k,N)REP(i,N)REP(j,N) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    
    // 全探索
    ll ans = INF*INF;
    sort(r.begin(), r.end());
    do {
        ll tmp_ans = 0;
        REP(i, R-1) {
            tmp_ans+=d[r[i]][r[i+1]];
        }
        ans = min(tmp_ans, ans);
    } while( next_permutation(r.begin(), r.end()) );
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



struct Point{
	Point(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}

	Point(){
		x = y = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{
		return x != p.x? x < p.x: y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}

	double x,y;
};

struct Info{
	Info(Point arg_p,double arg_degree){
		p = arg_p;
		degree = arg_degree;
	}
	bool operator<(const struct Info &arg) const{

		return degree < arg.degree;
	}

	Point p;
	double degree;
};

typedef Point Vector;
typedef vector<Point> Polygon;

double norm(Vector a){
	return a.x*a.x+a.y*a.y;
}

double abs(Vector a){
	return sqrt(norm(a));
}

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

double dot(Vector a,Vector b){
    return a.x*b.x + a.y*b.y;
}

/*
 * IN 2
 * ON 1
 * OUT 0
 *
 */
int contains(Polygon g,Point p){
	int n = g.size();
	bool x = false;
	for(int i = 0; i < n; i++){
		Point a = g[i]-p,b = g[(i+1)%n]-p;
		if(abs(cross(a,b)) < EPS && dot(a,b) < EPS)return 1;
		if(a.y > b.y)swap(a,b);
		if(a.y < EPS && EPS < b.y && cross(a,b) > EPS) x = !x;
	}
	return (x ? 2:0);
}

int main(){

	int N;
	scanf("%d",&N);

	Polygon polygon;
	double x,y;

	Point center = Point(0,0);

	for(int i = 0; i < N; i++){

		scanf("%lf %lf",&x,&y);
		polygon.push_back(Point(x,y));

		center.x += x;
		center.y += y;
	}
	center.x /= N;
	center.y /= N;

	vector<Info> info;

	for(int i = 0; i < N; i++){

		polygon[i].x -= center.x;
		polygon[i].y -= center.y;

		double tmp_deg = atan2(polygon[i].x,polygon[i].y);

		info.push_back(Info(polygon[i],tmp_deg));
	}

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

	int num_query;
	scanf("%d",&num_query);

	int left,right,mid;
	int loc;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%lf %lf",&x,&y);
		x = x-x/10000.0;
		y = y-y/10000.0;

		Point work = Point(x,y)-center;
		double tmp_deg = atan2(work.x,work.y);

		left = 0,right = N-1,mid = (left+right)/2;
		loc = N-1;

		while(left <= right){

			if(info[mid].degree >= tmp_deg){

				loc = mid;
				right = mid-1;
			}else{

				left = mid+1;
			}
			mid = (left+right)/2;
		}

		bool FLG = false;
		for(int i = -10; i <= 10; i++){

			int tmp_loc = (loc+i+N)%N;
			int tmp_loc2 = (loc+i+1+N)%N;

			Polygon tmp_pol;
			tmp_pol.push_back(info[tmp_loc2].p);
			tmp_pol.push_back(Point(0,0));
			tmp_pol.push_back(info[tmp_loc].p);


			if(contains(tmp_pol,work) > 0){
				FLG = true;
				break;
			}
		}

		if(FLG){

			printf("1\n");
		}else{

			printf("0\n");
		}
	}

	return 0;
}



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

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;
const ll _INF = 1e18+7;

int main(){
	setIO();
	int x; cin >> x;
	if (x) cout << 0 << endl;
	else cout << 1 << endl;
}

Measured memory_bytes: 3648
#include <stdio.h>

int main(){
  int A,B;
  scanf("%d %d", &A, &B);
  
  int coin = 0;
  for(int i=0; i<2; i++){
    if(A>B){
      coin += A;
      A--;
    }else{
      coin += B;
      B--;
    }
  }
  printf("%d", coin);
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

ll ans;
ll n, m, q;
vector<tuple<ll,ll,ll,ll>> queries;

void backtrack(vector<ll>& now, ll i) {
  if (i == n) {
    ll score = 0;
    for (auto& query : queries) {
      ll a, b, c, d;
      tie(a, b, c, d) = query;
      if (now[b] - now[a] == c) {
        score += d;
      }
    }
    chmax(ans, score);
    return;
  }

  ll pre = now[i]; // prev value
  for (ll v = pre; v <= m; ++v) { // scan value in [pre, m]
    now.push_back(v);
    backtrack(now, i+1);
    now.pop_back();
  }
}

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  cin >> n >> m >> q;

  rep(iter,q) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    --a; --b; // 0-indexed
    queries.push_back(tuple<ll,ll,ll,ll>(a,b,c,d));
  }

  vector<ll> now;
  now.push_back(1); // start from 1.
  backtrack(now, 0);
  cout << ans << endl;
}


Measured memory_bytes: 3660
fun main(args : Array<String>) {
    val first: List<Int> = readLine()!!.split(" ").map { it.toInt() }
    var enemy: List<Int> = readLine()!!.split(" ").map { it.toInt() }
    enemy = enemy.sorted()
    var answer  : Long= 0
    for (i in 0..first[0]-(first[1]+1)) {
        answer+=enemy[i]
    }
    println(answer)

}

Measured memory_bytes: 83972
n = int(input())
a = list(map(int, input().split()))
if 0 in a:
    print(0)
    exit()
b = 1
for i in a:
    b *= i
    if b > 10 ** 18:
        break
if b <= 10 ** 18:
    print(b)
else:
    print(-1)

Measured memory_bytes: 84436
#include<iostream>
#include<vector>
#include<queue>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define arep(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;

const int INF = 1 << 30;

void bfs(vector<vector<int> >& graph, vector<bool>& is_visited, vector<int>& dist, vector<int>& prev, int start, int last) {
    queue<int> Q;
    is_visited[start] = true;
    dist[start] = 0;
    prev[start] = last;
    Q.push(start);
    while (!Q.empty()) {
        int node = Q.front();
        Q.pop();
        rep(i, 0, graph[node].size()) {
            int next_node = graph[node][i];
            if (is_visited[next_node]) continue;
            is_visited[next_node] = true;
            dist[next_node] = dist[node] + 1;
            prev[next_node] = node;
            Q.push(next_node);
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    rep(i, 0, M) {
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
    }
    int min_dist = INF;
    vector<int> ans_node;
    rep(i, 0, M) {
        // i番目の辺を削除したグラフについて考える
        vector<vector<int> > graph(N);
        rep(j, 0, M) {
            if (i == j) continue;
            graph[A[j]].push_back(B[j]);
        }
        vector<bool> is_visited(N, false);
        vector<int> dist(N), prev(N);
        bfs(graph, is_visited, dist, prev, B[i], A[i]);
        if (!is_visited[A[i]]) continue;
        if (min_dist > dist[A[i]] + 1) {
            min_dist = dist[A[i]] + 1;
            ans_node.clear();
            int now_node = A[i];
            while (now_node != B[i]) {
                ans_node.push_back(now_node + 1);
                now_node = prev[now_node];
            }
            ans_node.push_back(B[i] + 1);
        }
    }
    if (min_dist == INF) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans_node.size() << endl;
    rep(i, 0, ans_node.size()) cout << ans_node[i] << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
	std::vector<string> s(0);
	string a;
	int n;
	int m = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		s.push_back(a);
	}
	for (int i = 0; i < n - 1; ++i) {
		if (s[i].substr(s[i].length() - 1, 1) != s[i + 1].substr(0, 1)) {
			m = 1;
			break;
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (s[i]==s[j]) {
				m = 1;
				break;
			}
		}
		if (m == 1)break;
	}
	if (m == 1)cout << "No"<<"\n";
	else cout << "Yes" << "\n";
	return 0;
}

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

D={}
for i in range(1,n+1):
    s=(str(i)[0],str(i)[-1])
    if s not in D:
        D[s]=1
    else:
        D[s]+=1
ans=0
for i in D:
    t=(i[1],i[0])
    if t in D:
        ans+=D[t]*D[i]
print(ans)

Measured memory_bytes: 42988
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
ll extgcd(ll a, ll b, ll &x, ll &y){
    if(b == 0){
        x = 1; y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
    return d;
}

//* calculate a^-1 mod m
ll mod_inverse(ll a, ll m){
    ll x, y;
    extgcd(a, m, x, y);
    return(m + x%m) % m;
}

//* calculate C(n, 0), C(n, 1), ... C(n, n) mod p in O(n) 
vll mod_comb_list(ll n, ll p){
    vll res(n+1, 1);
    for(ll k=1; k <= n; k++){
        res[k] = (res[k-1] * (n - k + 1)) % p;
        res[k] = (res[k] * mod_inverse(k, p)) % p;
    }
    return res;
}

const long long MOD = 1000000007;

void solve(long long n, long long k){
    vll clist1 = mod_comb_list(n, MOD);
    vll clist2 = mod_comb_list(n-1, MOD);
    ll ans = 0;
    REP(t, min(n, k+1)){
        ll tmp = (clist1[t]*clist2[n-t-1]) % MOD;
        ans = (ans + tmp) % MOD;
    }
    cout<<ans<<endl;
}

int main(){
    long long n;
    scanf("%lld",&n);
    long long k;
    scanf("%lld",&k);
    solve(n, k);
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
int main(){
  int n;cin>>n;
  bool ans=false;
  for(int i=0;i<=n/7;i++){
    int rest = n-i*7;
    for(int j=0;j<=rest/4;j++){
      if(rest==j*4){ans=true;break;}
    }
  }
  cout << (ans?"Yes":"No") << endl;
}


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

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

  long long n,m,r,ans=1e15,a,b,c;
  cin >> n >> m >> r;
  vector<long long> t(r);
  for(int i=0;i<r;i++){
    cin >> t[i];
    t[i]--;
  }
  sort(t.begin(), t.end());
  long long flo[n][n];
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i==j){
        flo[i][j]=0;
      }else{
        flo[i][j]=1e15;
      }
    }
  }
  for(int i=0;i<m;i++){
    cin >> a >> b >> c;
    a--; b--;
    flo[a][b]=c;
    flo[b][a]=c;
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
        flo[j][k] = min(flo[j][k], flo[j][i]+flo[i][k]);
      }
    }
  }
  do{
    long long sum=0;
    for(size_t i=1;i<t.size();i++){
      sum+=flo[t[i-1]][t[i]];
    }
    ans=min(ans, sum);
  }while(next_permutation(t.begin(), t.end()));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


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

    int left = 0;
    cout << left << endl;
    string s;
    cin >> s;
    if (s == "Vacant") return 0;

    int right = n;

    while(right - left > 1){
        int mid = (right + left) / 2;
        cout << mid << endl;
        string t;
        cin >> t;
        if (t == "Vacant") return 0;
        else{
            if (((mid - left)%2 == 1 && s != t) || ((mid - left)%2 == 0 && s == t)){
                left = mid;
                s = t;
            }
            else right = mid;
        }
    }

    return 0;
}


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

template <int MOD>
class Modular {
public:
    Modular(long long v=0) {
        value = v % MOD;
        if (value < 0)
            value += MOD;
    }

    Modular(long long a, long long b) : value(0) {
        *this += a;
        *this /= b;
    }

    Modular& operator+=(Modular const& b) {
        value += b.value;
        if (value >= MOD)
            value -= MOD;
        return *this;
    }

    Modular& operator-=(Modular const& b) {
        value -= b.value;
        if (value < 0)
            value += MOD;
        return *this;
    }

    Modular& operator*=(Modular const& b) {
        value = (long long)value * b.value % MOD;
        return *this;
    }

    friend Modular power(Modular a, long long e) {
        Modular res = 1;
        while (e) {
            if (e & 1)
                res *= a;
            a *= a;
            e >>= 1;
        }
        return res;
    }

    friend Modular inverse(Modular a) {
        return power(a, MOD - 2);
    }

    Modular& operator/=(Modular const& b) {
        return *this *= inverse(b);
    }

    friend Modular operator+(Modular a, Modular const b) {
        return a += b;
    }

    friend Modular operator-(Modular a, Modular const b) {
        return a -= b;
    }

    friend Modular operator-(Modular const a) {
        return 0 - a;
    }

    friend Modular operator*(Modular a, Modular const b) {
        return a *= b;
    }

    friend Modular operator/(Modular a, Modular const b) {
        return a /= b;
    }

    friend std::ostream& operator<<(std::ostream &os, Modular const& a) {
        return os << a.value;
    }

    friend bool operator==(Modular const& a, Modular const& b) {
        return a.value == b.value;
    }

    friend bool operator!=(Modular const& a, Modular const& b) {
        return a.value != b.value;
    }

    int value;
    static const int MOD_value = MOD;
};

using ModInt = Modular<1'000'000'007>;

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

    int n;
    cin >> n;
    vector<int> v(n);
    for (auto& x : v)
        cin >> x;

    vector<int> w;
    w.push_back(-1);
    for (auto& x : v) {
        if (x != w.back())
            w.push_back(x);
    }
    n = w.size();

    vector<ModInt> dp(n, 0);
    dp[0] = 1;
    map<int, ModInt> sum;
    sum[w[1]] = 1;

    for (int i = 1; i < n; i++) {
        // last one ended at i
        // if (sum.count(w[i]))
            dp[i] = sum[w[i]];
        // else
            // dp[i] = dp[i-1];
        // for (int j = 1; j <= i; j++) {
        //     if (w[i] == w[j]) {
        //         dp[i] += dp[j-1];
        //     }
        // }
        if (i + 1 < n)
            sum[w[i+1]] += dp[i];
    }
    cout << dp.back() << '\n';
    
}


Measured memory_bytes: 12020
N,X,M=map(int,input().split())
t=[]
t.append(X)
temp=X
ans=X
for i in range(10**5+100):
    temp=temp**2%M
    if temp in t:
        firstindex=t.index(temp)
        currentindex=len(t)
        firstsum=0
        for i in range(firstindex):
            firstsum+=t[i]
        repeatsum=0
        for i in range(firstindex,currentindex):
            repeatsum+=t[i]
        repetition=(N-firstindex)//(currentindex-firstindex)
        lastrep=        (N-firstindex)%(currentindex-firstindex)
        lastsum=0
        for i in range(firstindex,firstindex+lastrep):
            lastsum+=t[i]
        print(firstsum+repetition*repeatsum+lastsum)
        exit()

    else:
        t.append(temp)



Measured memory_bytes: 68696
n,m=map(int,input().split())
if n==1 and m==0:
  print(0)
  exit()
c=[list(map(int,input().split())) for i in range(m)]
if [1,0] in c and n>1:
  print(-1)
  exit()
num=[1]+[0]*(n-1)
try:
  for i in c:
  	num[i[0]-1]=i[1]
except:
  print(-1)
  exit()
for i in c:
  if num[i[0]-1]!=i[1]:
    print(-1)
    exit()
print(int("".join(map(str,num))))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int ar[323456];
int main()
{
    int n;
    scanf("%d",&n);
    n *= 3;
    for(int i = 0; i < n; i++)
        scanf("%d",&ar[i]);
    sort(ar, ar+n);

    int i = 0, j = n - 2;
    long long ans = 0;

    while(i < j)
    {
        ans += ar[j];
        i++;
        j -= 2;
    }
    cout << ans << endl;

}


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

int main() {
    int N ;
    int H[100000];
    cin >> N;
    for (int i = 0; i < N; ++i){
        cin >> H[i];
    }
    
    int max_step = 0;
    int step = 0;
    for (int i = 0; i < N-1; ++i ){
        if ( H[i] >= H[i+1] ){
            step += 1;
        } else {
            max_step = max(step,max_step);
            step = 0;
        }
    }
    cout << max(max_step,step) << endl ;
    
    return 0;
}



Measured memory_bytes: 768
import java.util.*;
  
public class Main{
    public static void main(final String[] args){
       
        final Scanner sc = new Scanner(System.in);

        String abc = "abcdefghijklmnopqrstuvwxyz";
        Long alf = 26l;
        Long N = sc.nextLong();
        String ans = "";

        for(;N>0;){
            Long Num = N-1;
            int tStr = (int)(Num%alf);
            ans = abc.substring(tStr,tStr+1)+ans;
            N =  Num/alf;
        }
        System.out.println(ans);
    }
}

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

int main(){
    int n, m;
    cin >> n >> m;

    vector<int> a(n), b(n), c(n), d(m), e(m), f(m);
    map<int, int> x, y;
    x[0] = 0;
    y[0] = 0;

    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i] >> c[i];
        x[a[i]] = 0;// value will be determined later
        x[b[i]] = 0;
        y[c[i]] = 0;
    }
    for(int i=0; i<m; i++){
        cin >> d[i] >> e[i] >> f[i];
        x[d[i]] = 0;
        y[e[i]] = 0;
        y[f[i]] = 0;
    }

    vector<int> xs, ys;
    for(auto& xi : x){
        xi.second = xs.size();// value = order (since sorted in map)
        xs.push_back(xi.first);
    }
    for(auto& yi : y){
        yi.second = ys.size();
        ys.push_back(yi.first);
    }

    int h = xs.size() * 2;
    int w = ys.size() * 2;

    vector<vector<int>> grid(h, vector<int>(w));// 1: visited, 0: not yet, -1 : wall
    for(int i=0; i<n; i++){
        int ai = x[a[i]] * 2;
        int bi = x[b[i]] * 2;
        int ci = y[c[i]] * 2;
        for(int xx=ai; xx<=bi; xx++){
            grid[xx][ci] = -1;
        }
    }
    for(int i=0; i<m; i++){
        int di = x[d[i]] * 2;
        int ei = y[e[i]] * 2;
        int fi = y[f[i]] * 2;
        for(int yy=ei; yy<=fi; yy++){
            grid[di][yy] = -1;
        }
    }

    // BFS
    queue<pair<int, int>> q;
    int sx = x[0] * 2;
    int sy = y[0] * 2;
    grid[sx][sy] = 1;
    q.push({sx,sy});

    vector<int> dx = {1, 0, -1, 0};
    vector<int> dy = {0, 1, 0, -1};

    while(q.empty() == false){
        int x_current = q.front().first;
        int y_current = q.front().second;
        q.pop();

        for(int i=0; i<4; i++){
            int nx = x_current + dx[i];
            int ny = y_current + dy[i];
            if(0 <= nx && nx < h
            && 0 <= ny && ny < w
            && grid[nx][ny] == 0){
                grid[nx][ny] = 1;
                q.push({nx, ny});
            }
        }
    }

    /*
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cout << setw(3) << grid[i][j];
        }
        cout << endl;
    }
    */

    long long int ans = 0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(grid[i][j] == 0 || grid[i][j] == -1) continue;// unreachable

            // else (reachable)
            if(i == 0 || i == h-1
            || j == 0 || j == w-1){
                cout << "INF" << endl;
                return 0;
            }

            if(i % 2 == 0 || j % 2 == 0) continue;// wall, regarded as (area) = 0
            long long int lx = xs[i/2+1] - xs[i/2];
            long long int ly = ys[j/2+1] - ys[j/2];
            ans += lx * ly;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N;
  cin >> N;
  vector <int> A(N);
  rep(i,N) cin >> A[i];
  int s = 0;
  rep(i,N) s ^= A[i];
  rep(i,N){
    A[i] ^= s;
    cout << A[i] << endl;
  }
}


Measured memory_bytes: 3868
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a,const void *b){
  return *(int*)a - *(int*)b;
}
int main(){
  int  d[100001],n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&d[i]);
  qsort(d,n,sizeof(int),cmp);
  int ans;
  ans=d[n/2]-d[n/2-1];
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
using namespace std;
double dp[2][3000];
int main(){
    int n;
    scanf("%d", &n);
    double te;
    dp[0][0] = 1;
    for (int i = 1; i <= n; ++i){
        scanf("%lf", &te);
        dp[i&1][0] = dp[i-1&1][0]*(1-te);
        for (int j = 1; j <= i; ++j){
            dp[i&1][j] = dp[i-1&1][j-1]*te + dp[i-1&1][j]*(1-te);
        }
    }
    te = 0;
    for (int i = (n>>1)+1; i <= n; ++i)
        te += dp[n&1][i];
    printf("%0.10lf", te);
    return 0;
}


Measured memory_bytes: 888
#include<iostream>

using namespace std;

int main(void){
  int i=0,n=0,a,b=0;
  while(cin >> i >> n){
    a = i+n;
    while(a>0){
      a = a/10;
      b++;
  }
    cout << b <<endl;
    b = 0;
  }
}

Measured memory_bytes: 3020
#include <iostream>

 

using namespace std;

 

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


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

vector<vector<ll>> net;
vector<ll> tgt, color;

// white = 1, black = -1, undefined = 0
void coloring(ll v, ll par){
    if(par == -1){
        color.at(v) = 1;
    }else{
        color.at(v) = color.at(par) * -1;
    }

    for(ll nxt : net.at(v)){
        if(tgt.at(nxt) == v || tgt.at(v) == nxt){
            if(color.at(nxt) == 0){
                coloring(nxt, v);
            }
        }
    }
}

void solve(long long N, long long M, std::vector<long long> D, std::vector<long long> U, std::vector<long long> V){
    net.resize(N);
    REP(i, M){
        U.at(i)--;
        V.at(i)--;
        net.at(U.at(i)).push_back(V.at(i));
        net.at(V.at(i)).push_back(U.at(i));
    }

    tgt.resize(N);
    REP(i, N){
        ll min_idx = net.at(i).front();
        for(ll j : net.at(i)){
            if(D.at(min_idx) > D.at(j)){
                min_idx = j;
            }
        }
        if(D.at(min_idx) > D.at(i)){
            cout << -1 << endl;
            return;
        }
        tgt.at(i) = min_idx;
    }

    color.resize(N);
    fill(color.begin(), color.end(), 0);
    REP(i, N){
        if(color.at(i) != 0){ continue; }
        coloring(i, -1);
    }

    REP(i, N){
        if(color.at(i) == 1){
            cout << 'W';
        }else{
            assert(color.at(i) == -1);
            cout << 'B';
        }
    }
    cout << endl;

    REP(i, M){
        ll x = U.at(i);
        ll y = V.at(i);
        if(tgt.at(x) == y){
            cout << D.at(x) << endl;
        }else if(tgt.at(y) == x){
            cout << D.at(y) << endl;
        }else{
            cout << 1000000000 << endl;
        }
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> D(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&D[i]);
    }
    std::vector<long long> U(M);
    std::vector<long long> V(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&U[i]);
        scanf("%lld",&V[i]);
    }
    solve(N, M, std::move(D), std::move(U), std::move(V));
    return 0;
}


Measured memory_bytes: 15872
import java.util.Scanner;

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

		int thp = sc.nextInt();
		int ta = sc.nextInt();
		int ahp = sc.nextInt();
		int aa = sc.nextInt();

		while (thp > 0) {
			ahp -= ta;
			if (ahp <= 0)
				break;
			thp -= aa;
		}
		if (thp <= 0)
			System.out.println("No");
		else
			System.out.println("Yes");
	}

}


Measured memory_bytes: 27076
#include<stdio.h>
#define N 100
#define W 0
#define G 1
#define B 2

int n,A[N][N];
int d[N],f[N],color[N],t;

void dfs(int u){
  int v;
  color[u]=G;
  d[u]=++t;
  for(v=0;v<n;v++){
    if(A[u][v]==0) continue;
    if(color[v]==W){
      dfs(v);
    }
  }
  color[u]=B;
  f[u]=++t;
}

void dfs1(){
  int u;
  for(u=0;u<n;u++) color[u]=W;
  t=0;

  for(u=0;u<n;u++){
    if(color[u]==W){
      dfs(u);
    }
  }
  for(u=0;u<n;u++){
    printf("%d %d %d",u+1,d[u],f[u]);
    printf("\n");
  }
 
}    

main(){
  
  int i,j,k,u,v;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      A[u][v]=1;
    }
  }
 
  dfs1();
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>


int main(void)
{
	int n, i, j,v;
	int A[100];

	 scanf("%d", &n);
	 for (i = 0; i < n; i++)
	 {
		 scanf("%d", &A[i]);
	 }

	 for (i = 0; i < n; i++)
	 {
		 v = A[i];
		 j = i - 1;

		 while (j >= 0 && A[j] > v)
		 {
			 A[j + 1] = A[j];
			 j--;
		 }
		 A[j + 1] = v;

		 for (j = 0; j < n; j++)
		 {
			 if (j != 0)
			 {
				 printf(" ");
			 }

			 printf("%d", A[j]);
		 }

		 printf("\n");
	 }
			

		
		return 0;
}



Measured memory_bytes: 1796
#include <cstdio>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	int t=n,sum=0;
	while(t)
	{
		sum+=(t%10);
		t/=10;
	}
	if(n%sum)
		printf("No");
	else
		printf("Yes");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int N,i;
	scanf("%d",&N);
	
	for(i = 0 ; i < N; i ++){
		int max ;
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		if(((a*a + b*b) == c*c) ||((a*a + c*c) == b*b)||((b*b + c*c) == a*a)){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int r; scanf("%d", &r);
	
	printf("%d\n", r * r);
	return 0;
}


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

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

bool isMatch( string str, string patt ){
	rep(i,8){
		if( patt[i] != '?' && str[i]!=patt[i] ){
			return false;
		}
	}
	return true;
}

int main(){
	int n, m;
	while(cin >> n >> m, n||m){
		vector<string> rules[3];
		vector<string> pass[3];
		rep(i,n){
			string r, src, dst;
			cin >> r >> src >> dst;
			rules[0].push_back(r);
			rules[1].push_back(src);
			rules[2].push_back(dst);
		}
		rep(i,m){
			string src, dst, mess;
			cin >> src >> dst >> mess;
			for(int j=rules[0].size()-1; j>=0; j--){
				if( isMatch(src,rules[1][j]) && isMatch(dst,rules[2][j]) ){
					if( rules[0][j][0]=='p' ){
						pass[0].push_back(src);
						pass[1].push_back(dst);
						pass[2].push_back(mess);
					}else	break;
				}
			}
		}
		cout << pass[0].size() << endl;
		rep(i,pass[0].size()){
			cout << pass[0][i] << " " << pass[1][i] << " " << pass[2][i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1444
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a[]=new int[n];
        int i;
        for(i=0;i<n;i++)a[i]=sc.nextInt();
        for(i=n-1;i>0;i--)System.out.printf("%d ",a[i]);
        System.out.printf("%d\n",a[0]);
    }
}



Measured memory_bytes: 26480
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
   int sx, sy, tx, ty;
   cin >> sx >> sy >> tx >> ty;
   for (int i = 0; i < tx - sx; i++) {
       cout << 'R';
   }
   for (int i = 0; i < ty - sy; i++) {
       cout << 'U';
   }
   for (int i = 0; i < tx - sx; i++) {
       cout << 'L';
   }
   for (int i = 0; i < ty - sy; i++) {
       cout << 'D';
   }
   cout << "D";
   for (int i = 0; i < tx - sx + 1; i++) {
       cout << 'R';
   }
   for (int i = 0; i < ty - sy + 1; i++) {
       cout << 'U';
   }
   cout << "L" << "U";
   for (int i = 0; i < tx - sx + 1; i++) {
       cout << 'L';
   }
   for (int i = 0; i < ty - sy + 1; i++) {
       cout << 'D';
   }
   cout << "R" << endl;





}


Measured memory_bytes: 256
#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>;
const int NUM=100002;

int main(){
    int N;
    cin >> N;
    int A[N];
    rep(i, N) cin>>A[i];
    int Q;
    cin >> Q;
    int B[Q], C[Q];
    rep(i, Q) cin>>B[i]>>C[i];

    ll num[NUM]={0};
    rep(i, N) num[A[i]]++;
    ll sum=0;
    rep(i, NUM) sum+=i*num[i];

    rep(i, Q){
        sum-=num[B[i]]*B[i];
        sum+=num[B[i]]*C[i];
        num[C[i]]+=num[B[i]];
        num[B[i]]=0;
        cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 5536
#include <bits/stdc++.h>  // ver2.2.5
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define COUNT(a,i) upper_bound(ALL(a),i)-lower_bound(ALL(a),i)
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define _ <<' '<<
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define Verr(a) rep(iZ,0,a.size()-1)cerr<<a[iZ]<<' ';cerr<<a.back()<<endl
#define VVerr(a) rep(iY,0,a.size()){Verr(a[iY]);}
#define VPerr(a) rep(iX,0,a.size())cerr<<a[iX].FI<<' '<<a[iX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void press(auto &v){v.erase(unique(ALL(v)),v.end());}  //  圧縮
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}


VVi gr;
Vi dist;

void shortest(int s){
  int n = dist.size();
  rep(i,0,n) dist[i]=INF;
  dist[s] = 0;
  
  priority_queue<Tiii,vector<Tiii>,greater<Tiii>> q;
  q.push(make_tuple(0,s,-1));
  
  while(!q.empty()){
    int nowdist,now,past;
    tie(nowdist,now,past) = q.top();
    q.pop();
    
    if(nowdist>dist[now]) continue;
    
    dist[now]=nowdist;
    
    rep(i,0,n){
      if(gr[now][i]==-1) continue;
      int next = i,cost = gr[now][i];
      if(next!=past && nowdist+cost<dist[next]){
        q.push(make_tuple(nowdist+cost,next,now));
        dist[next]=nowdist+cost;
      }
    }
  }
  return;
}


signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n,m;
  cin >> n >> m;
  int qw,er,ty;
  
  gr = VVi(n,Vi(n,-1));
  
  rep(i,0,m){
    cin >> qw >> er >> ty;
    qw--,er--;
    gr[qw][er] = ty;
    gr[er][qw] = ty;
  }
  
  dist = Vi(n,0);
  
  VVi smap(n,Vi(n));
  rep(i,0,n){
    shortest(i);
    smap[i] = dist;
  }
  
  VVerr(smap);
  cerr << endl;
  VVerr(gr);
  int ans=0;
  
  rep(i,0,n){
    rep(j,i+1,n){
      if(gr[i][j]!=-1){
        if(gr[i][j]!=smap[i][j]) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ARB ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pp __builtin_popcount
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e5+5;

int main()
{
    ARB
    ll n,k;
    cin >> n >> k;
    ll res = n % k;
    res = min(res,abs(k - res));
    cout << res;
}

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

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

    cin>>a>>b>>c;

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

    return 0;
}


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

int main(){
    long long a, b, x;
    cin >> a >> b >> x;
    long long count;
    if (a != 0){
        count = b / x - ( a - 1 )/ x;
    }
    else {
        count = b / x + 1;
    }
    cout << count << endl;
}

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

using namespace std;

struct Vertex {
    int cnt;
    vector<int> to;
};

int ans[300000];

void dfs(vector<Vertex> &g, int v, int p = -1) {
    for(auto u: g[v].to) {
        if(u == p) continue;
        ans[u] = ans[v] + g[u].cnt;
        dfs(g, u, v);
    }
    return;
}

int main(void) {
    int N, Q;
    cin >> N >> Q;

    vector<Vertex> g(N);
    for(auto e: g) {
        e.cnt = 0;
    }
    for(int i=0; i<N-1; i++) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].to.emplace_back(b);
        g[b].to.emplace_back(a);
    }

    while(Q--) {
        int p, x;
        cin >> p >> x;
        --p;
        g[p].cnt += x;
    }

    ans[0] = g[0].cnt;
    dfs(g, 0);

    for(int i=0; i<N; i++) {
        cout << ans[i] << ' ';
    }
    return 0;
}


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

int main()
{
	int h = 0, w = 0;

	cin >> h >> w;

	while ((h != 0) | (w != 0)) {
		for (int j = 0; j < h; j++) {
			for (int i = 0; i < w; i++)
				cout << "#";
			cout << endl;
		}
		cout << endl;
		cin >> h >> w;
	}

    return 0;
}

Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
#define de cout<<"test"<<endl;
#define st system("pause");
#define M_PI 3.1415926
LL l[300005]={};
LL r[300005]={};
LL A[300005]={};
int main()
{
    int a;
    while(cin>>a){
    	priority_queue <LL, vector<LL>, greater<LL> >num;
	priority_queue <LL>num1;
for(int i=1;i<=a*3;i++){
    cin>>A[i];
}
LL sum=0;
for(int i=1;i<=a*3;i++){
    sum+=A[i];
    num.push(A[i]);
    if(num.sz>a){
        sum-=num.top();
        num.pop();
    }
    l[i]=sum;
}
sum=0;
for(int i=a*3;i>=1;i--){
    sum+=A[i];
    num1.push(A[i]);
    if(num1.sz>a){
        sum-=num1.top();
        num1.pop();
    }
    r[i]=sum;
}
LL ans=-ll;
for(int i=a;i<=2*a;i++){
    ans=max(ans,l[i]-r[i+1]);
}
cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 9716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long K, long long Q, std::vector<long long> A){
    vector<ll> points(N,0);

    for (int i = 0; i < Q; i++)
    {
        points[A[i]-1]++;
    }

    for (int i = 0; i < N; i++)
    {
        if(K - (Q -points[i])  <= 0){
            cout << NO << endl;
        }else{
            cout << YES << endl;
        }
    }
    
    
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> A(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, K, Q, std::move(A));
    return 0;
}


Measured memory_bytes: 2176
def main():
    S = input()
    c = [0, 0]
    
    for i in range(len(S)):
        if S[i] == "1":
            c[0] += 0 if i % 2 == 0 else 1
            c[1] += 0 if i % 2 == 1 else 1
        else:
            c[1] += 0 if i % 2 == 0 else 1
            c[0] += 0 if i % 2 == 1 else 1
    
    print(min(c))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string.h>
#include<limits.h>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define P pair<int,int>
#define x first
#define y second

using namespace std;
const int maxn = 25;
char str[maxn][maxn];
int num[maxn][maxn];
int dir[][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int n,m,ans,res;

queue<P>Q;

int main(void) {
	int BFS(int start_x,int start_y);
	scanf("%d%d",&n,&m);
	for(int i = 1; i <= n; i ++) {
		for(int j = 0; j <= m; j ++) {
			scanf("%c",&str[i][j]);
		}
	}
	ans = 0,res = 0;
	for(int i = 1; i <= n; i ++) {
		for(int j = 1; j <= m; j ++ ) {
			if(str[i][j] == '#') continue;
			res = BFS(i,j);
			ans = max(ans,res);
		}
	}
	cout << ans << endl;
	return 0;
}

bool Check(int x,int y) {
	if(x < 1 || y < 1 || x > n || y > m) return false;
	if(str[x][y] == '#' || num[x][y]) return false;
	if(str[x][y] == '.') return true;
}

int BFS(int start_x,int start_y) {
	P a,b;
	int count = 0;
	memset(num,0,sizeof(num));
	while(!Q.empty()) Q.pop();
	a.x = start_x,a.y = start_y;
	Q.push(a);
	while(!Q.empty()) {
		a = Q.front();
		Q.pop();
		count = max(count,num[a.x][a.y]);
		int v = num[a.x][a.y];
		for(int i = 0; i < 4; i ++) {
			b.x = a.x + dir[i][0];
			b.y = a.y + dir[i][1];
			if(!Check(b.x,b.y)) continue;
			if(b.x != start_x || b.y != start_y) {
				num[b.x][b.y] += v + 1;
				Q.push(b);
			}
		}
	}
	return count;
}

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

int main() {

    int K;
    string S;
    cin >> K >> S;

    if (S.length() <= K) cout << S << endl;
    else cout << S.substr(0, K) << "..." << endl;    

    return 0;
}

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

int main(){

	int a;
	int i = -1, j = -1;
	std::vector<int> array1;
	std::vector<int> array2;


	while(std::cin >> a){
		if(a != 0){
			array1.push_back(a);
			i++;
		}else{
			array2.push_back(array1[i--]);
			array1.pop_back();
			j++;
		}
	}
	
	for(i=0;i<=j;i++){
		std::cout << array2[i] <<  std::endl;
	}
}

Measured memory_bytes: 1216
#include<vector>
#include<iostream>
#include<algorithm>
#include<tuple>
#include<string>
#include<bits/stdc++.h>
using namespace std;

string str;
void solve(){
   int N,ans,res;
   ans=0;
   cin>>N>>str;
   for(int i=1;i<N;i++){
        if(str[i]=='E')ans++;
   }
   res=ans;
   for(int i=1;i<N;i++){
        if(str[i-1]=='W')ans++;
        if(str[i]=='E')ans--;
        res=min(res,ans);
   }
    cout<<res<<endl;
}

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

Measured memory_bytes: 900
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    cout << (n == m ? "Yes" : "No") << "\n";
    return 0;
}


Measured memory_bytes: 256