akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef pair<Pii,Pii> Ppp;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 606;
int n,d1,d2;vector<Pii> res;
void solve(int d1, int d2, vector<Ppp> s){//now,real
	vector<Ppp> a,b;
	rep(i,0,SZ(s)-1)if(!((s[i].fi.fi+s[i].fi.se)&1)){
		a.pb(Ppp(Pii((s[i].fi.fi+s[i].fi.se)/2,(s[i].fi.se-s[i].fi.fi)/2),s[i].se));
	}
	else{
		s[i].fi.fi++;
		b.pb(Ppp(Pii((s[i].fi.fi+s[i].fi.se)/2,(s[i].fi.se-s[i].fi.fi)/2),s[i].se));
	}
	if(SZ(a)<SZ(b))swap(a,b);
	if(d1&d2&1)rep(i,0,SZ(a)-1)res.pb(a[i].se);
	else{
		bool bo=0;if(d2&1)d2=d1,bo=1;if(d1&1)d1=d2,bo=1;
		if(bo)solve(d1/2,d2/2,a);
		else{solve(d1/2,d2/2,a);solve(d1/2,d2/2,b);}
	}
}
int getdis(Pii a, Pii b){return (a.fi-b.fi)*(a.fi-b.fi)+(a.se-b.se)*(a.se-b.se);}
int main() {
	read(n);read(d1);read(d2);
	vector<Ppp>d;rep(i,0,n*2-1)rep(j,0,n*2-1)d.pb(Ppp(Pii(i,j),Pii(i,j)));
	solve(d1,d2,d);
//	rep(i,0,SZ(res)-1)rep(j,i,SZ(res)-1)assert(d1!=(getdis(res[i],res[j]))&&d2!=(getdis(res[i],res[j])));
//	assert(SZ(res)>=n*n);
	rep(i,0,n*n-1)printf("%d %d\n",res[i].fi,res[i].se);
	return 0;
}


Measured memory_bytes: 34536
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll D,G;
    cin >> D >> G;
    vector<ll> p(D), c(D);
    rep(i,D){
        cin >> p[i] >> c[i];
    }
    ll ans = 1e18;
    for(ll i = 0; i<(1LL << D); i++){
        ll sum = 0;
        ll nsol = 0;
        rep(j,D){
            if((i >> j) & 1LL){
                sum += (j+1)*100*p[j] + c[j];
                nsol += p[j];
            }
        }
        if(sum >= G){
            cmin(ans,nsol);
        }else{
            for(ll j=D-1;j>=0;j--){            
                if(!((i >> j) & 1LL)){
                    rep(k,p[j]){
                        sum += (j+1)*100;
                        nsol++;
                        if(sum >= G){
                            break;
                        }
                    }
                    break;
                }
            }
            if(sum >= G){
                cmin(ans,nsol);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*

    author : s@if

*/

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

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			99999999
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)


bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)1e5+9;
struct node
{
    string s;
    int k, idx;

    node (string ss, int kk, int iidx)
    {
        s = ss;
        k = kk;
        idx = iidx;
    }

    bool operator <(const node &b)const
    {
        if(s==b.s)
        {
            return k>b.k;
        }
        else
            return s<b.s;
    }
};

vector<node>vec;

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    int i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    cin>>n;

    for(i=0; i<n; i++)
    {
        string s;
        cin>>s>>k;

        vec.push_back(node(s,k,i+1));
    }

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

    for(i=0; i<n; i++)
        cout<<vec[i].idx<<endl;

    return 0;
}


Measured memory_bytes: 256
def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor: GCD)を求める
    計算量: O(log(min(a, b)))
    """
    if b == 0:
        return a
    return gcd(b, a%b)


class Ruiseki_lr:
    """左右からの畳み込みをそれぞれ計算する"""
    def __init__(self, array, op, e):
        self.op = op
        self.e = e

        n = len(array)
        self.left = [e] * (n + 1)
        self.right = [e] * (n + 1)
        for i in range(n):
            self.left[i + 1] = self.op(self.left[i], array[i])
        for i in reversed(range(n)):
            self.right[i] = self.op(self.right[i + 1], array[i])

    def get_left(self, p):
        """区間[0, p)の畳み込み結果を返す"""
        return self.left[p]

    def get_right(self, p):
        """区間[p, n)の畳み込み結果を返す"""
        return self.right[p]

    def fold(self, p):
        """p番目を除いた区間[0, n)の畳み込み結果を返す"""
        return self.op(self.left[p], self.right[p + 1])


n = int(input())
a = list(map(int, input().split()))
ru = Ruiseki_lr(a, gcd, 0)

ans = 0
for i in range(n):
    ans = max(ru.fold(i), ans)
print(ans)

Measured memory_bytes: 63984
using System;

class Program {
  static void Main() {
    String[] input1 = Console.ReadLine().Split(' ');
    int x = Int32.Parse(input1[2]);
    String[] input2 = Console.ReadLine().Split(' ');
    int y = 1;
    int l = 0;
    int r =0;
    while (y <= input2.Length){
      if (x > Int32.Parse(input2[y-1])){
        l++;
      } else {
        r++;
      }
      y++;
    }
    if (l > r){
      Console.Write(r);
    } else {
      Console.Write(l);
    }
  }

}


Measured memory_bytes: 11092
#include <iostream>

using namespace std;

int main(){
  char c;
  cin >> c;
  if(c == 'A') cout << "T" << endl;
  if(c == 'T') cout << "A" << endl;
  if(c == 'G') cout << "C" << endl;
  if(c == 'C') cout << "G" << endl;
  return 0;
}


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

using namespace std;

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

	int ans = 0;
	while (N > 0) {
		++ans;
		N /= K;
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)
int* calc(int a, vector<int> v1, vector<int> v2, int (&n)[10]) {
	int x;
	if(v1.size() > a) {
		x = v1[a];
		n[x]--, n[x+1]--, n[x+2]--;
	} else {
		x = v2[a - v1.size()];
		rep(j,3) n[x]--;
	}
	return n;
}

bool judge(int j, int k, int l, int m, vector<int> v1, vector<int> v2, int *n) {
	int nn[10];
	rep(i,10) {
		nn[i] = n[i];
	}
	calc(j,v1,v2, nn);
	calc(k,v1,v2, nn);
	calc(l,v1,v2, nn);
	calc(m,v1,v2, nn);
	bool f = 0;
	rep(i,10) {
		if(nn[i] < 0) {
			f = 0;
			break;
		}
		if(nn[i] == 2) f = 1;
	}
	if(f) return true;
	return false;
}
int main() {
	string s;
	while(cin >> s) {
		bool bl = 1;
		int n[10];
		rep(i,10) {
			n[i] = 0;
		}
		rep(i,s.length()) {
			n[s[i] - '0']++;
		}
		rep2(i,1,10) {
			n[i]++;
			bool f = 0;
			rep(j,10) {
				if(n[j] > 4) f = 1;
			}
			if(f) {
				n[i]--;
				continue;
			}
			vector<int> v1;
			rep2(j,1,8) {
				int c = min(n[j],min(n[j+1], n[j+2]));
				if(c > 0) {
					rep(k,c) {
						v1.push_back(j);
					}
				}
			}
			vector<int> v2;
			rep2(j,1,10) {
				if(n[j] >= 3) v2.push_back(j);
			}
			int len = v1.size() + v2.size();
			f = 0;
			rep(j,len) {	
				rep2(k,j+1,len) {
					rep2(l,k+1,len) {
						rep2(m,l+1,len) {
							if(judge(j, k, l, m, v1, v2, n)) {								
								if(bl) cout << i;
								else cout << " " << i;
								bl = 0;
								f = 1;
								break;
							}
						}
						if(f) break;
					}
					if(f) break;
				}
				if(f) break;
			}
			n[i]--;
		}
		if(bl) cout << 0 << endl;
		else cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int main() {
	int N, K;
	scanf("%d%d", &N, &K);
	vector<int> p(N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &p.at(i));
	}
	sort(p.begin(), p.end());
	int ans = 0;
	for (int i = 0; i < K; i++) {
		ans += p.at(i);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3232
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

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

	const long long mod = 1E9 + 7;
	vector<long long> table(max(N, M)+1, 0);
	table[0] = 1;
	for(int i=1; i<=max(N, M); i++)
	{
		table[i] = table[i-1] * i;
		table[i] %= mod;
	}

	long long ret = 0;
	if(N-M >= 0 && N-M < 2)
		ret += table[N] * table[M] % mod;

	if(M-N >= 0&& M-N < 2)
		ret += table[M] * table[N] % mod;

	ret %= mod;
	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 1024
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#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>
#include<chrono>
#include<string>

using namespace std;

#define ll long long int
#define pb push_back
#define ff first
#define ss second
#define ins insert

/*int main()
{
	ll t;
	cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		vector<ll>v;
		ll val=-1;
		while(n--)
		{
			ll temp;
			cin>>temp;
			v.pb(temp);
		}

		ll mini=10000000;

		if(v.size()==1)
		{
			cout<<val<<endl;
			continue;
		}

		else{
		for(ll i=0;i<v.size();i++)
		{
			set<ll>s;
			ll cnt=0;
			ll j;
			for(j=i;j<v.size();j++)
			{
				auto temp=s.find(v[j]);
				if(temp==s.end())
				{
					s.insert(v[j]);
					cnt++;
				}

				else
				{
					cnt++;
					break;
				}
			}
			//cout<<cnt<<endl;

			if(cnt>1)
			mini=min(mini,cnt);

			i=j-1;
		}

			cout<<mini<<endl;
		}

	}
}*/




int main() {
	

	ios_base::sync_with_stdio(false);
	cin.tie();
	ll r;
	cin>>r;
	ll val=r*r;
	cout<<val;
	

}


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

int a[507][507];

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (argc == 2 && atoi(argv[1]) == 123456789)
        freopen("d:\\code\\cpp\\stdin", "r", stdin);

    int H, W;
    cin >> H >> W;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> a[i][j];
        }
    }

    vector<pair<pii, pii>> moves;
    for(int i=0; i<H-1; i++){
        for(int j=0; j<W; j++){
            if (a[i][j]%2){
                moves.push_back( make_pair(make_pair(i+1,j+1), make_pair(i+2,j+1)));
                a[i+1][j]++;
            }
        }
    }

    for(int j=0; j<W-1; j++){
        if (a[H-1][j]%2){
            moves.push_back( make_pair(make_pair(H,j+1), make_pair(H,j+2)));
            a[H-1][j+1]++;
        }
    }

    cout << moves.size() << endl;
    for(auto q : moves)
        cout << q.first.first << " "  << q.first.second << " "  << q.second.first << " "  << q.second.second<< endl;

    return 0;
}

Measured memory_bytes: 5232
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String s="";
		while((s=br.readLine())!=null){
			StringTokenizer st=new StringTokenizer(s," ");
			ArrayList<Integer> list=new ArrayList<Integer>();
			while(st.hasMoreTokens()){
				list.add(Integer.parseInt(st.nextToken()));
			}
			Collections.sort(list);
			for (int i = list.size()-1; i >=0; i--) {
				System.out.print(list.get(i));
				if(i>0){
					System.out.print(" ");
				}
			}
			System.out.println();
			
		}
	}

}

Measured memory_bytes: 16868
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


void yakusu(int num, vector<int>& yaku){
    yaku.push_back(1);
    for (int i = 2; i*i <= num; i++)
    {
        if (num%i == 0) {
            yaku.push_back(i);
            if (i*i != num) yaku.push_back(num/i);
        } 
    }
    yaku.push_back(num);
}

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a;
    int sum = 0;
    rep(i, n){ int tmp; cin >> tmp; a.push_back(tmp); sum+=tmp;}
    vector<int> yaku;
    yakusu(sum, yaku);
    sort(yaku.begin(), yaku.end());
    //show(yaku);
    int t_ans;
    int s = yaku.size();
    for (int i = s-1; i >= 0; i--)
    {
        int ans = 0;
        vector<int> y_len(n);
        rep(j, n){
            y_len[j] = a[j]%yaku[i];
        }
        sort(y_len.begin(), y_len.end());
        vector<int> y_len_sum(n+1, 0);
        vector<int> y_len_sum_inv(n+1, 0);
        rep(j, n){
            y_len_sum[j+1] += y_len[j] + y_len_sum[j];
        }
        rep(j, n){
            y_len_sum_inv[n-1-j] += (yaku[i] - y_len[n-1-j]) + y_len_sum_inv[n-j];
        }
        // cout << yaku[i] << endl;
        // show(y_len);
        // show(y_len_sum);
        // show(y_len_sum_inv);

        rep(j, n){
            if (y_len_sum[j] == y_len_sum_inv[j]) {ans = y_len_sum[j]; break;}
        }
        if (ans <= k){
            t_ans = yaku[i];
            break;
        }
    }
    cout << t_ans << endl;
}



Measured memory_bytes: 256
/*　　　　　　　{:i:i:|i:i:/l/l--　 　 　--l/li:i:i|i:i:i:i}
　　　　　　 　 {:rx|:i:i ィi芥ミ 　 　 .ィi芥ミｉ:ｉ|ﾍ:i:i:}
.　　　 　 　 　 ｛ﾏ|ｉ:  {::’:} 　 　 　{:‘::} :ｉ:i:|〉｝:/
　　 　 　 　 　 乂|:i:| ｀¨¨¨¨´ 　 　　｀¨¨¨´  :i:ｉ:|ｼ/
　 　 　 　 　 　 ﾉ:|:i|　　　　　　′　　　 　   |:i:i:|ﾂ
　　　　　　　　/:/|:i:| ､　　　 　_ _ 　　　　  |:i:i:|
　 　 　　 　 /:/ .|:i:|/ ＼　　　 　 　     ｨ〔|:i:/
　　 　 　  　 〈;/ く刈＿ 个 　   -   　＜}　./|/_〉
　　     　　 r-っ'~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ|___
　　 　     /／ニつ　　　　　　 ､　　　　　　　ノﾆﾆ　＼
.　　　     |　　ニ⊃ 　./　/　 ──   /　/　　..⊆ﾆﾆ　　:|
.　　　     |　　丁´　 /|￣|￣  ─‐ /|￣|￣ 　 .￣|丁 　|
.　　　     |　　ﾉ.  　 |￣|￣  ─‐  |￣|￣ 　 　.|八 　|
.　　　     |　　||. 　 |￣|￣ |￣| |￣|￣ 　   .|　|
.　 　 　   |  　||   　￣￣￣　￣ 　￣￣￣　　  .|　|  |
.　 　 　  　    ||＿＿＿＿＿＿＿＿＿＿＿＿______|__　　 ',
　 　      ,′　 | ７ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ}  ,′
.　　     {　　　|/　}ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ{/ 　 　
*///讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐。
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>

using namespace std;

#define rep(a) _rep(0,int(a))
#define repj(a) for(int j=0;j<int(a);j++)
#define _rep(a,b) for(int i=int(a);i<int(b);i++)
#define ll long long
#define fst first
#define snd second
#define pf(b) printf("%.12f\n",(double)b)
#define _GLIBCXX_DEBUG
const double pai = 3.1415926535897;
#define _cos(n) cos(n*pai/180)

//factorial(練習)　階乗
int fact(int n) {
	int a = 1;
	for (int i = 1;i <= n;i++) a *= i;
	return a;
}
int sa(int n, int m) {      //差！
	if (n < m)return m - n;
	else return n - m;
}

int a, b;
signed main() {
	cin >> a >> b;
	if ((a* b) % 2 == 0)cout << "No" << endl;
	else cout << "Yes" << endl;
}

Measured memory_bytes: 256
program name
    implicit none
    character(10):: s
    integer(8):: bmax,i,ni,j,ans,nans
    integer(8),allocatable:: bit(:)

    read*, s
    bmax = 2**(len_trim(s)-1)-1
    allocate(bit(len_trim(s)-1))
    ans=0
    do i=0,bmax
        ni=i
        do j=1,size(bit)
            bit(j) = and(ni,1)
            ni = rshift(ni,1)
        end do
        
        nans = ichar(s(1:1)) - ichar('0')

        do j=1,size(bit)
            if (bit(j) == 0)then
                nans=nans*10 + ichar(s(j+1:j+1)) - ichar('0')
            else
                ans=ans+nans
                nans=ichar(s(j+1:j+1)) - ichar('0')
            end if
        end do
        ans=ans+nans
    end do
    
    print*, ans
end program name

Measured memory_bytes: 384
n,m = map(int,input().split())
h =  list(map(int,input().split()))
adj = [[] for _ in range(n)]
for i in range(m):
    s1,s2 = map(int,input().split())
    adj[s1-1].append(s2-1)
    adj[s2-1].append(s1-1)
total = 0
for i in range(n):
    if (len(adj[i]) == 0):
        total += 1
    else:
        total += int(all(h[i]>h[j] for j in adj[i]))
print(total)
    


Measured memory_bytes: 29472
#include <bits/stdc++.h>  // ver2.2.2
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#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 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 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 uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ

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



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n;
  cin >> n;
  vector<Tiii> dish(n);
  int qw,er,ty;
  rep(i,0,n){
    cin >> qw >> er;
    ty = qw+er;
    dish[i] = mt(ty,qw,er);
  }
  sortr(ALL(dish));
  int suma=0,sumb=0;
  
  rep(i,0,n){
    if(i%2==0){
      suma += get<1>(dish[i]);
    }
    else {
      sumb += get<2>(dish[i]);
    }
  }
  cout << suma-sumb << endl;
  return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include <vector>
using namespace std;
int main(){
  string S;
  cin >> S;
  long long sum=0;
  int l = S.length();
  for(int bit=0; bit< (1<<(l-1)); ++bit){
    vector<int> tmp;
    for(int i=0; i<l-1; ++i){
      if(bit & (1<<i)){
        tmp.push_back(i);
      }
    }
    
    if(tmp.size() == 0) sum += stol(S);
    else{
      sum += stoi(S.substr(0, tmp[0]+1));
      for(int i=1; i<tmp.size(); ++i){
        sum += stol(S.substr(tmp[i-1]+1, tmp[i]-tmp[i-1]));
      }
      sum += stol(S.substr(tmp[tmp.size()-1]+1));
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#define x first
#define y second
using namespace std;
typedef pair<int,int> pii;
inline void check_max(int a,int &b){if(a>b)b=a;}
priority_queue<int,vector<int>,greater<int>>Q;
const int N=201000;
pii s[N*3];
int f[N*2];
int n,m,tot,ans;
int main()
{
//	freopen("in","r",stdin);
	scanf("%d%d",&n,&m);
	tot=0;
	for(int i=1,x,y;i<=n;i++)
	{
		scanf("%d%d",&x,&y);
//		if(x>0)s[++tot]=pii(1,x);
//		if(y<=m)s[++tot]=pii(y+m,m+m);
		x+=m;std::swap(x,y);
		if(x>y)continue;
		if(x<=0)x=1;
		s[++tot]=pii(x,y);
		if(x+m>y)s[++tot]=pii(x+m,std::min(y+m,m+m));
//		if(y-m<x)s[++tot]=pii(std::max(x-m,1),y-m);
	}
//	for(int i=1;i<=tot;i++)
//		printf("%d -- %d\n",s[i].x,s[i].y);
	std::sort(s+1,s+tot+1);
	ans=0;
	for(int i=1,ind=1,m2=m*2;i<=m2;i++)
	{
		while(s[ind].x<=i && ind<=tot)Q.push(s[ind].y),ind++;
		while(!Q.empty() && Q.top()<i)Q.pop();
		if(!Q.empty())ans++,Q.pop();
		f[i]=ans;
	}
//	for(int i=1;i<=m*2;i++)printf("%d ",f[i]);
//	printf("\n");
	ans=0;
	for(int i=m,m2=m*2;i<=m2;i++)
		check_max(f[i]-f[i-m],ans);
	printf("%d\n",n-ans);
	return 0;
}


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

int main(){	
	long long N;
	long long M;
	scanf("%lld",&N);
	vector<long long> A(N-1+1);
	scanf("%lld",&M);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	map<ll, ll> m;
	ll sum = 0;
	m[sum]++;
	for(int i = 0 ; i <= N-1 ; i++){
		sum += A[i];
		m[sum%M]++;
	}
	ll res = 0;
	for(auto x : m) {
        res += x.second*(x.second-1)/2;
    }
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 4992
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut counts = vec![0; n + 1];
    for num in a {
        counts[num] += 1;
    }

    let mut a = vec![];
    for count in counts {
        if count != 0 {
            a.push(count);
        }
    }
    a.sort();

    let mut sum = vec![0; a.len() + 1];
    sum[0] = 0;
    for i in 1..a.len() + 1 {
        sum[i] = a[i - 1] + sum[i - 1];
    }

    for k in 1..n + 1 {
        let criterion = |mid: usize| -> bool {
            let idx = a.lower_bound(&mid);
            (a.len() - idx) * mid + sum[idx] >= mid * k
        };
        let (ok, _) = binary_search(0, n + 1, criterion);
        println!("{}", ok);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn binary_search<F>(lb: usize, ub: usize, criterion: F) -> (usize, usize)
where
    F: Fn(usize) -> bool,
{
    let mut ok = lb;
    let mut ng = ub;
    while ng - ok > 1 {
        let mid = (ng + ok) / 2;
        if criterion(mid) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    (ok, ng)
}

pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}


Measured memory_bytes: 12404
fun main(args: Array<String>) {
    val (n, w) = readLine()!!.split(' ').map(String::toInt)
    val wList = mutableListOf<Int>()
    val vList = mutableListOf<Long>()
    (1..n).forEach {
        val (w, v) = readLine()!!.split(' ').map(String::toLong)
        wList.add(w.toInt())
        vList.add(v)
    }
    val dp = Array(n + 1) { LongArray(w + 1) { 0L } }
    for (i in 0 until n) {
        for (sum_w in 0..w) {
            if (sum_w - wList[i] >= 0) {
                if (dp[i + 1][sum_w] < dp[i][sum_w - wList[i]] + vList[i]) {
                    dp[i + 1][sum_w] = dp[i][sum_w - wList[i]] + vList[i]
                }
            }
            if (dp[i + 1][sum_w] < dp[i][sum_w]) {
                dp[i + 1][sum_w] = dp[i][sum_w]
            }
        }
    }
    println(dp.maxBy { it.max()!! }!!.max())
}

Measured memory_bytes: 155996
import java.util.Scanner;
class Main{
	static String map[][];
	static boolean judge[][];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int h = sc.nextInt();
			int w = sc.nextInt();
			if((h|w) == 0)break;
			map = new String[h][w];
			judge = new boolean[h][w];
			for(int i = 0; i < h; i++){
				char[]temp = sc.next().toCharArray();
				for(int j = 0; j < w; j++){
					map[i][j] = String.valueOf(temp[j]);
				}
			}
			BoolFalse(0, 0);
		}
	}



	static void BoolFalse(int i,int j){
		if(judge[i][j] == true){
			System.out.println("LOOP");
		}else if(map[i][j].equals(".")){
			System.out.println(j + " " + i );
		}else{
			judge[i][j] = true;
			if(map[i][j].equals(">")){
				BoolFalse(i, j + 1);
			}else if(map[i][j].equals("<")){
				BoolFalse(i, j - 1);
			}else if(map[i][j].equals("^")){
				BoolFalse(i - 1, j);
			}else if(map[i][j].equals("v")){
				BoolFalse(i + 1, j);
			}
		}
	}
}

Measured memory_bytes: 30576
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;

typedef long long ll;
ll mod = 1000000007;

int main() {
    cout << fixed << setprecision(7);
    double a,b,x; cin >> a >> b >> x;
    double ans;
    if (x <= a * a * b / 2) {
        double alp = x * 2 / (a * b);
        double res =  M_PI / 2 - atan(alp / b); 
        ans = res * 180 / M_PI;
    } else {
        x -= a * a * b / 2;
        double alp = x * 2 / (a * a);
        double res = atan((b - alp) / a);
        ans = res * 180 / M_PI;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 512
import bisect

D=[]
N=[]
count=0

def insert(D,N,count,key,x):
    y=bisect.bisect_left(D,key)
    if y<count and D[y]==key:
        N[y]=x
    else:
        D.insert(y,key)
        N.insert(y,x)
        count+=1
    return D,N,count

def get(D,N,key):
    y=bisect.bisect_left(D,key)
    print(N[y])

q=int(input())
for i in range(q):
    query=list(map(str,input().split()))
    query[0]=int(query[0])
    if query[0]==0:
        D,N,count=insert(D,N,count,query[1],int(query[2]))
    else:
        get(D,N,query[1])



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

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
    ll r;
    cin >> r;
    cout << r*r <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int mod=1000000007;
    int m,n;
    cin>>m>>n;
    vector <string> v(m);
    for(int i=0;i<m;i++)
    {
        cin>>v[i];
    }
    int dp[m][n];
    dp[0][0]=1;
    for(int i=1;i<m;i++)
    {
        if(v[i][0]=='#')
            dp[i][0]=0;
        else
            dp[i][0]=dp[i-1][0];
    }
    for(int i=1;i<n;i++)
    {
        if(v[0][i]=='#')
            dp[0][i]=0;
        else
            dp[0][i]=dp[0][i-1];
    }
    for(int i=1;i<m;i++)
    {
        for(int j=1;j<n;j++)
        {
            if(v[i][j]=='#')
            {
                dp[i][j]=0;
            }
            else
                dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
        }
    }
    cout<<dp[m-1][n-1]%mod<<endl;
}


Measured memory_bytes: 5248
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_137A
{
    class Program
    {
        static void Main(string[] args)
        {
            double A, B,max;

            var word = Console.ReadLine().Split(' ');

            A = double.Parse(word[0]);
            B = double.Parse(word[1]);

            max = A + B;


            if (max < A - B) max = A - B;

            if (max < A * B) max = A * B;  

            Console.WriteLine(max);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>  
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod=1e9+7;
const ll longINF=3e18;
const double eps=1e-8;
const double dinf=190.0;
const double pi=acos(-1);
const int INF=2e9+1;

int a,b;
        
int main() 
{        
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
        cin>>a>>b;
        if (a%3==0 || b%3==0 || (a+b)%3==0)
                cout<<"Possible";
        else
                cout<<"Impossible";
        return 0;
}

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

int main(){
	int N;
	cin >> N;
	long long A = 1, B = 1;
	for(int i = 0; i < N; i++){
		long long t ,a ;
		cin >> t >> a;
		long long n = max((A+t-1)/t, (B+a-1)/a);
		A = n*t;
		B = n*a;
	}
	cout << A+B << endl;
}

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

using ll=long long;



void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    if(c<=a+b){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	const int mod = 1e9 + 7;
	int N;
	cin >> N;

	int dp[N][64]; // 末尾がstringの奴の数で違反していない
	rep(i, N) {rep(j, 64) dp[i][j] = 0;}

	/* init */
	rep(j, 64) dp[2][j] = 1;
	// 違反しているので　ゼロ
	dp[2][0b001001] = 0; // AGC, ACG, GAC
	dp[2][0b000110] = 0;
	dp[2][0b100001] = 0;

	for(int i=3; i<N; i++) {
		for(int j=0; j<64; j++) {
			rep(end, 4) {
				int tail = (j << 2) + end;
				if((tail>>6)%4==0 && (tail>>2)%4==2 && tail%4==1) continue; // A*GC;
				else if((tail>>6)%4==0 && (tail>>4)%4==2 && tail%4==1) continue; // AG*C;
				
				tail %= 64;
				if(tail==0b00001001) continue; // AGC;
				else if(tail==0b00100001) continue; // GAC;
				else if(tail==0b00000110) continue; // ACG;
				else {
					dp[i][tail] += dp[i-1][j];
					dp[i][tail] %= mod;
				}
			}
		}
	}

	int ans = 0;
	rep(j, 64) {
		ans += dp[N-1][j];
		ans %= mod;
	}

	cout << ans << endl;
		
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll facm(ll a) { return a > 1 ? facm(a - 1) * a % INF : 1; }
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  int n,m;
  cin >> n >> m;
  if(abs(n - m) > 1){
    puts("0");
    return 0;
  }
  if(n - m == 0){
    cout << facm(n) % INF * facm(m) * 2 % INF << endl;
  }
  else{
    cout << facm(n) % INF * facm(m) % INF << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
      
        if (a > b) {
          // 出力
		  System.out.println(c > b && a > c ? "Yes" : "No");
        } else {
          // 出力
		  System.out.println(c < b && a < c ? "Yes" : "No");
        }
	}
}


Measured memory_bytes: 24404
a=65280; b=61680; c=52428; d=43690; e=65535
base = [a, b, c, d, e, 0]
L = {el: 1 for el in base}
for i in range(6):
    R = dict(L)
    for p in R:
        if R[p] < 16:
            L[p ^ e] = min(L.get(p ^ e, 16), R[p] + 1)
        if R[p]+3 < 16:
            for q in R:
                if R[p] + R[q] + 3 <= 16:
                    L[p & q] = min(L.get(p & q, 16), R[p] + R[q] + 3)
                    L[p ^ q] = min(L.get(p ^ q, 16), R[p] + R[q] + 3)
while 1:
    s = input()
    if s == '.':
        break
    print(L[e & eval(s.replace("-", "~").replace("*", "&").replace("1", "e"))])

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n, q;
  string s;
  cin >> n >> q >> s;
  vector<char> t(q);
  vector<char> d(q);
  rep(i, q) cin >> t[i] >> d[i];

  int lok = -1, lng = n;
  while(abs(lok-lng) > 1) {
    int mid = (lok+lng)/2;
    int now = mid;
    rep(i, q) {
      if(s[now] == t[i]) {
        if(d[i] == 'L') --now;
        else ++now;
      }
      if(now < 0 || now >= n) break;
    }
    if(now < 0) lok = mid;
    else lng = mid;
  }

  int rok = n, rng = -1;
  while(abs(rok-rng) > 1) {
    int mid = (rok+rng)/2;
    int now = mid;
    rep(i, q) {
      if(s[now] == t[i]) {
        if(d[i] == 'L') --now;
        else ++now;
      }
      if(now < 0 || now >= n) break;
    } 
    if(now >= n) rok = mid;
    else rng = mid;
  }
  int ans = n;
  ans -= lok+1;
  ans -= (n-rok);
  cout << ans << endl;
}

Measured memory_bytes: 3876
n = int(input())
a = list(map(int,input().split()))
asum = sum(a)
cnt = [0] * (10**5+1)
q = int(input())

for i in a:
    cnt[i] += 1

for i in range(q):
    b, c = map(int,input().split())
    asum = asum + (c-b)*cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(asum)

Measured memory_bytes: 21020
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#define MAXN 100010

int n, m, a[MAXN], b[MAXN], c[MAXN], p[MAXN];
struct edge {
    int u, v, w;
    inline friend bool operator<(const edge &a, const edge &b) {
        return a.w < b.w;
    }
} e[MAXN];
inline int find(int x) { return x == p[x] ? x : p[x] = find(p[x]); }
std::vector<int> next[MAXN];
long long sum[MAXN];

long long dp(int x) {
    long long ret = c[x];
    sum[x] = b[x];
    for (int y : next[x]) {
        long long res = dp(y);
        ret = std::min(ret, std::max(0LL + c[x], res) - sum[y]);
        sum[x] += sum[y];
    }
    return ret + sum[x];
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &a[i], &b[i]);
        a[i] = std::max(a[i], b[i]);
        c[i] = a[i] - b[i];
        p[i] = i;
    }
    for (int i = 1; i <= m; i++) {
        scanf("%d%d", &e[i].u, &e[i].v);
        e[i].w = std::max(c[e[i].u], c[e[i].v]);
    }
    std::sort(e + 1, e + m + 1);
    for (int i = 1; i <= m; i++) {
        int u = e[i].u, v = e[i].v;
        if (find(u) == find(v)) continue;
        if (c[u] < c[v]) std::swap(u, v);
        next[find(u)].push_back(find(v));
        p[find(v)] = find(u);
    }
    printf("%lld\n", dp(find(1)));
    return 0;
}

Measured memory_bytes: 11520
#[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")
    };
}

fn main() {
    input!{
        n:i64,
    }
    let s = n.to_string().len();
    let mut ans = 0;
    if s%2==0 {
        let mut con = 1;
        for _ in 0..(s/2) {
            ans+=9*con;
            con*=100;
        }
    }else{
        let mut con = 1;
        for _ in 0..(s/2) {
            ans+=9*con;
            con*=100;
        }
        ans+=n-(10u32.pow((s-1) as u32) as i64) + 1;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN=5e4+10,MAXM=1e6+10;
const int INF=~(1<<31),MOD=1e9+7;

map<string,string> m;

int main()
{
    m["Sunny"]="Cloudy";
    m["Cloudy"]="Rainy";
    m["Rainy"]="Sunny";
    string s;
    cin>>s;
    cout<<m[s];
	return 0;
}

/*
10 2
18871879 371157535
911194990 941687917
512812663 754127003
102892004 601753470
573361634 301301161
674476989 484047358
846200469 976893832
296955730 717187208
374661589 663330509
645291887 484517704
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define speed_up ios_base::sync_with_stdio(false); cin.tie(NULL)
    #define ll long long
    #define ara(A,N) sort(A,A+N)
    #define rev(A,N) sort(A,A+N,greater<long long>())
    using namespace std;
    int main()
    {
    long long int i,n,sum=0,p;
    cin>>n;
    long long int z[n];
    for(i=0;i<n;i++)
    {
        cin>>z[i];
    }
    for(i=0;i<n;i++)
    {
        sum+=z[i];
    }
    long long int x=(sum/n);
    p=ceil(sum*1.000/n);
   // cout<<p<<endl;

    long long san=0,pan=0;
    for(i=0;i<n;i++)
    {
        san+=pow((z[i]-p),2);
        pan+=pow((z[i]-x),2);
    }
    cout<<min(san,pan)<<endl;

    }


Measured memory_bytes: 3716
import java.util.*;

public class Main {
    static Scanner sc;
    public static void main(String[] args) {
        sc=new Scanner(System.in);
        A();
        //B();
        //C();
        //D();
    }
    public static void A(){
        int n=sc.nextInt();
        int m=sc.nextInt();
        System.out.println((n-2*m>0)?n-2*m:0);
    }
    public static void B(){
        int n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)a[i]=sc.nextInt();
        int sum=0;
        for(int i=0;i<n-1;i++)
            for(int j=i+1;j<n;j++)
                sum+=a[i]*a[j];
        System.out.println(sum);
    }
    public static void C(){
        int n=sc.nextInt();
        char []po=sc.next().toCharArray();
        char c=po[0];
        String a=""+c;
        for(int i=1;i<n;i++)
            if(c!=(c=po[i]))
                a+=c;
        System.out.println(a);
    }
    public static void D(){
        int n=sc.nextInt();
        int []a=new int[n];
        for(int i=0;i<n;i++)
            a[i]=sc.nextInt();
        Arrays.sort(a);
        long ans=0;
        for(int i=0;i<n-2;i++){
            int kk=i+1;
            for(int j=i+1;j<n-1;j++){
                for(int k=(Math.max(kk,j));k<n;k++)
                    if(!(a[i]+a[j]>a[k]))
                        break;
                    else kk=k;
                ans+=kk-j;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21588
#include<bits/stdc++.h>
#define fo(i,a,b) for(register int (i)=(a);(i)<=(b);++(i))
#define rd read()
#define maxn 200001
#define gc getchar()
#define mem(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define pb push_back
#define db double
#define pu puts(" ")
using namespace std;
const int p=998244353;
int read()
{
	int x=0,f=1;
	char ch=gc;
	while(!isdigit(ch))
	{
		if(ch=='-')f=-1;
		ch=gc;
	}
	while(isdigit(ch))x=x*10+ch-48,ch=gc;
	return x*f;
}
void print(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)print(x/10);
	putchar(x%10+48);
}
int qp(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=(ll)ans*a%p;
		a=(ll)a*a%p;
		b>>=1;
	}
	return ans;
}
int ans,a[maxn],n;
int main()
{
    n=rd;fo(i,1,n)
    {
    	a[i]=rd;ans+=a[i];
	}
	printf("%d\n",ans-n);
	return 0;
}

Measured memory_bytes: 256
import Control.Monad (forM_)
import Data.List (sortBy)

splitBy _ [] = []
splitBy w cs = take w cs:splitBy w (drop w cs)

main :: IO ()
main = do
  [h,w] <- map read.words <$> getLine :: IO [Int]
  n <- read <$> getLine :: IO Int
  as <- map read.words <$> getLine :: IO [Int]
  let ls = splitBy w $ concatMap (uncurry replicate) $ sortBy (flip compare) $ zip as [1..]
  forM_ (zip ls [1..])$ \(l,i) ->
    putStrLn $ unwords $ map show $ if odd i then l else reverse l


Measured memory_bytes: 2940
#include<iostream>

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

int main () {
  int n, i, j, min_len;
  string taro, hanako;
  int score_t = 0, score_h = 0;

  cin >> n;
  rep(i,n) {
    cin >> taro >> hanako;
    if (taro == hanako) {
      score_t += 1;
      score_h += 1;
      continue;
    }
    min_len = (taro.length() < hanako.length())? taro.length() : hanako.length();
    rep(j,min_len) {
      if (taro[j] - hanako[j] > 0) {
	score_t += 3;
	break;
      } else if (taro[j] - hanako[j] < 0) {
	score_h += 3;
	break;
      } else if (j == min_len-1) {
	if (taro.length() > hanako.length()) score_t += 3;
	else score_h += 3;
      }
    }
  }
  cout << score_t << " " << score_h << endl;
  return 0;
}

Measured memory_bytes: 1208
#include<iostream>
using namespace std;
int main(){

  int N;
  cin>>N;
  if(N%10==9){
    cout<<"Yes"<<endl;
  }
    else if(N>=90){
      cout<<"Yes"<<endl;
    }
      else{
	cout<<"No"<<endl;
      }	

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
N, X, Y = [int(str) for str in input().strip().split()]

X -= 1
Y -= 1
dists = [0] * N
for i in range(N - 1):
    for j in range(i + 1, N):
        d = min(j - i, abs(X - i) + abs(Y - j) + 1)
        dists[d] += 1

for k in range(1, N):
    print(dists[k])

Measured memory_bytes: 3444
#!/usr/bin/python3
# -*- coding: utf-8 -*-

P, Q, R = map(int, input().split())

x = P + Q
y = Q + R
z = R + P

if x < y:
    if x < z:
        print(x)
    else:
        print(z)
else:
    if y < z:
        print(y)
    else:
        print(z)

Measured memory_bytes: 2940