akhauriyash/Code-Regression huggingface dataset:
//                        Bismillahir Rahmanir Rahim
//ALGO:
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define FILL(a, x) memset(a, x, sizeof(a))
#define ll long long
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define INF INT_MAX
#define mx 1000010
#define mod 1000000007
#define dout if(debug) cout
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<pair<int, int>, null_type,less<pair<int, int> >, rb_tree_tag,tree_order_statistics_node_update>
*/
const double Pi=acos(-1);
using namespace std;
int debug=01;

ll c[mx];
int main() {
    Fast
    ll n, x, y;
    ll sum=0;
    cin>>n;
    while(n--){
        cin>>x;
        c[x]++;
        sum+=x;
    }
    cin>>n;
    while(n--){
        cin>>x>>y;
        sum-=x*c[x];
        sum+=y*c[x];
        c[y]+=c[x];
        c[x]=0;
        cout<<sum<<"\n";
    }
}


Measured memory_bytes: 4388
/*program by mangoyang*/
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#include<bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
    int f = 0, ch = 0; x = 0;
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    if(f) x = -x;
}

#define int ll

const int N = 1605005, L = 200005, P = 924844033, G = 5;
vector<int> g[N];
int inv[N], iv[N], s[N], f[N], tot[N], sz[N], js[N], n;
inline int Pow(int a, int b){
	int ans = 1;
	for(; b; b >>= 1, a = a * a % P)
		if(b & 1) ans = ans * a % P;
	return ans;
}
namespace NTT{
	int rev[N];
	inline int Getrev(int ned){
		int lg = 0, len = 1;
		for(; len <= ned; len <<= 1, lg++);
		for(int i = 0; i < len; i++) 
			rev[i] = (rev[i>>1] >> 1) | ((i & 1) << (lg - 1));
		return len;	
	}
	inline void DFT(int *A, int len, int type){
		for(int i = 0; i < len; i++) if(i < rev[i]) swap(A[i], A[rev[i]]);
		for(int k = 2; k <= len; k <<= 1){
			int w = Pow(G, (P - 1) / k); if(type == -1) w = Pow(w, P - 2);
			for(int i = 0; i < len; i += k){
				int now = 1;
				for(int j = i; j < i + (k >> 1); j++, (now *= w) %= P){
					int x = A[j], y = (now * A[j+(k>>1)]) % P;
					A[j] = (x + y) % P, A[j+(k>>1)] = (x - y + P) % P;
				}
			}	
		}
		if(type == -1){
			int now = Pow(len, P - 2);
			for(int i = 0; i < len; i++) (A[i] *= now) %= P;
		}
	}
	inline void Times(int *A, int *B, int lena, int lenb){
		int len = Getrev(lena + lenb + 1);
		DFT(A, len, 1), DFT(B, len, 1);
		for(int i = 0; i < len; i++) A[i] = A[i] * B[i] % P;
		DFT(A, len, -1);
	}  
}
inline void dfs(int u, int fa){
	sz[u] = 1, f[u] = fa;
	for(int i = 0; i < g[u].size(); i++)
		if(g[u][i] != fa) dfs(g[u][i], u), sz[u] += sz[g[u][i]];
}
inline int C(int x, int y){ 
	return js[x] * inv[y] % P * inv[x-y] % P; 
}
signed  main(){
	read(n), js[0] = 1, inv[0] = iv[L] = 1;
	for(int i = 1; i <= n; i++){
		js[i] = js[i-1] * i % P;
		iv[L-i] = inv[i] = Pow(js[i], P - 2);
	}
	for(int i = 1, x, y; i < n; i++){
		read(x), read(y);
		g[x].push_back(y), g[y].push_back(x);
	}
	dfs(1, 0);
	for(int i = 2; i <= n; i++) tot[sz[i]]++;
	for(int i = 1; i <= n; i++) 
		s[L+i] = (tot[i] + tot[n-i]) * js[i] % P;
	//for(int i = 0; i <= n; i++) cout << sz[i] << " "; cout << endl;
	//for(int i = 0; i <= n; i++) cout << js[i] << " "; cout << endl;
	//for(int i = 0; i <= n; i++) cout << tot[i] << " "; cout << endl;
	//for(int i = 0; i <= n; i++) cout << s[L+i] << " "; cout << endl;
	//for(int i = 0; i <= n; i++) cout << iv[L-i] << " "; cout << endl;
	NTT::Times(s, iv, L + n + 1, L + n + 1);
	//for(int i = 2*L+1; i <= 2*L+n+1; i++) cout << s[i] << " ";
	//cout << endl;
	for(int i = 1; i <= n; i++){
		int A = n * C(n, i) % P;
		int B = inv[i] * s[2*L+i] % P;
		//cout << A << " " << B << endl;
		printf("%lld\n", ((A - B) % P + P) % P);
	}
	return 0;
}

Measured memory_bytes: 104704
import numpy as np
n,k=map(int,input().split())
h=np.array(input().split(), dtype=int)
dp=np.zeros(n, dtype=int)
for i in range(1, n):
    left=max(0, i - k)
    dp[i]=min(abs(h[i]-h[left:i])+dp[left:i])
print(dp[-1])


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

int main() {
	int n;
	int A[100005];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	
	int c=1;
	int t=1000000;
	if(A[0]==2){
		cout<<1;
		return 0;
	}
	int temp=A[0];
	while(t--){
		c++;
		if (A[temp-1]==2){
		
			cout<<c;
			return 0;
		}
	
		temp=A[temp-1];
		
	}
	
	cout<<-1;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if((a==b&&b==c)||(a!=b&&b!=c&&a!=c)){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}

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

//------------------------------------------------------------
using ll = long long;
#define int ll

#define FOR(i, s, e) for (ll i = ll(s); i < (ll)e; ++i)
#define RFOR(i, s, e) for (ll i = ll(e) - 1; i >= ll(s); --i)
#define REP(i, n) for (ll i = 0, i##_size = n; i < i##_size; ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)

//------------------------------------------------------------
template <class T>
struct arr : public vector<T> {
	arr() {}
	arr(ll n, T v = T()) : vector<T>(n, v) {}
	void init(ll n, T v = T()) {
		this->clear();
		this->resize(n, v);
	}
	ll sz() const { return (ll)this->size(); }
	void pb(T v) { this->push_back(v); }
	void sort() { std::sort(this->begin(), this->end()); }
	void rsort() { std::sort(this->begin(), this->end(), greater<T>()); }
};
using ints = arr<ll>;
using intss = arr<arr<ll>>;

template <class T>
struct que : public queue<T> {
	ll sz() const { return (ll)this->size(); }
	T popfront() {
		T v = this->front();
		this->pop();
		return v;
	}
};

//------------------------------------------------------------
#if defined(TEST)
extern istream& myInputStream;
extern ostream& myOutputStream;
#else
istream& myInputStream = cin;
ostream& myOutputStream = cout;
#endif
struct input_ar {
	ll n;
	input_ar(ll n_) : n(n_) {}
	template <class T>
	operator arr<T>() {
		arr<T> var(n);
		REP(i, n) {
			myInputStream >> var[i];
		};
		return var;
	}
};

struct input {
	template <class T>
	operator T() {
		T var;
		myInputStream >> var;
		return var;
	}
	input_ar operator()(ll N) { return input_ar(N); }
} input;

template <class T>
void output(T var) {
	myOutputStream << (var) << '\n';
}

//------------------------------------------------------------
template <class T> void chmin(T& a, T b) { if (b < a) { a = b; } }
template <class T> void chmax(T& a, T b) { if (b > a) { a = b; } }

struct bfs {
	ints froms;
	ints steps;

	bfs(int N, intss const& adjacency) {
		froms.init(N, -1);
		steps.init(N, -1);

		que<ll> queue;
		queue.push(0);
		froms[0] = 0;
		steps[0] = 0;

		while (queue.empty() == false) {
			ll p = queue.popfront();

			for (ll n : adjacency[p]) {
				if (froms[n] != -1) {
					continue;
				}

				froms[n] = p;
				steps[n] = steps[p] + 1;
				queue.push(n);
			}
		}
	}
};

//------------------------------------------------------------
#if !defined(TEST)
void myMain();
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(16);
	myMain();
	return 0;
}
#endif

//------------------------------------------------------------
void myMain() {
	int N = input;
	ints mins;
	ints maxs;
	REP(i, N) {
		int a = input;
		int b = input;
		mins.pb(a);
		maxs.pb(b);
	}
	mins.sort();
	maxs.rsort();

	if (N % 2 == 0) {
		int l = mins[N / 2 - 1] + mins[N / 2];
		int r = maxs[N / 2 - 1] + maxs[N / 2];
		int c = r - l + 1;
		output(c);
	}
	else {
		int l = mins[N / 2];
		int r = maxs[N / 2];
		int c = r - l + 1;
		output(c);
	}
}


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

int main()
{
    string s;
    cin >> s;

    sort(s.begin(), s.end());
    if (s == "abc") cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;

#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;

int h[100001];
int dp[100100];


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

    rep(i,100100){
        dp[i] = INT_MAX;
    }

    rep(i,n){
        cin >> h[i];
    }


    dp[n-1] = 0;
    for(int i=n-2; i>=0; i--){
        int mind = INT_MAX;
        for(int j=1; j<=k&&i+j<n; j++){
            mind = min(mind, dp[i+j] + abs(h[i+j] - h[i]));
        }

        dp[i] = mind; 
    }

    cout << dp[0] << endl;
    
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 998244353


//edit
Int modadd(Int a, Int b) {
    Int ret = (a + b) % MOD;
    if (ret < 0) ret += MOD;
    return ret;
}

Int modsub(Int a, Int b) {
    Int ret = (a - b) % MOD;
    if (ret < 0) ret += MOD;
    return ret;
}

Int modmul(Int a, Int b) {
    Int ret = (a * b) % MOD;
    if (ret < 0) ret += MOD;
    return ret;
}

class Solve {
public:
    void solve() {
        Int N;
        string S;
        cin >> N >> S;

        vector<Int> divs;
        for (int i = 1; i <= N; ++i) {
            if (N % i == 0 && (N / i) % 2 == 1) {
                divs.push_back(i);
            }
        }
        vector<Int> kei(N + 1);
        for (int i = divs.size() - 1; i >= 0; --i) {
            kei[divs[i]] = 2 * divs[i];
            for (int j = divs[i] * 2; j <= kei.size(); j += divs[i]) {
                if (N % j == 0 && N / j % 2 == 1) {
                    kei[divs[i]] -= kei[j];
                }
            }
        }
        for (int i = 0; i < N + 1; ++i) {
            kei[i] = modadd(kei[i], 0);
        }

        Int ans = 0;
        for (auto e : divs) {
            Int cnt = 0;
            for (int i = 0; i < e; ++i) {
                cnt = 2 * cnt + S[i] - '0';
                cnt = modadd(cnt, 0);
            }

            string T = S;
            for (int i = e; i < N; ++i) {
                T[i] = static_cast<char>(T[i - e] ^ 1);
            }

            if (T <= S) {
                cnt++;
            }

            ans = modadd(ans, modmul(cnt, kei[e]));
        }

        cout << ans << endl;


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


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

using namespace std;

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n;
    string s,t;
    string a;
    cin >>n>>s>>t;

    for (int i = 0; i < n; i++){
        a.push_back(s[i]);
        a.push_back(t[i]);
    }
    



    //cout <<fixed<<setprecision(16)<< << endl;
    cout << a << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

const int maxn=2005;

int n, k;
vector < int > ms[maxn];
bitset < maxn > bio;
queue < pair < int, int > > q;
int branch[maxn];
int zbroj[maxn];

void bfs(int x){
	pair < int, int > p;
	bio[x]=1;
	q.push({x, 0});
	while(!q.empty()){
		p=q.front();
		if(p.second==k/2){
			break;
		}
		q.pop();
		x=p.first;
		for(int i=0; i<ms[x].size(); i++){
			if(!bio[ms[x][i]]){
				if(!p.second){
					branch[ms[x][i]]=ms[x][i];
				}
				else{
					branch[ms[x][i]]=branch[x];
				}
				bio[ms[x][i]]=1;
				q.push({ms[x][i], p.second+1});
			}
		}
	}
}

int solve(int x){
	bfs(x);
	int br=bio.count();
	if(k%2){
		int maksi=0;
		while(!q.empty()){
			zbroj[branch[q.front().first]]+=ms[q.front().first].size()-1;
			maksi=max(maksi, zbroj[branch[q.front().first]]);
			q.pop();
		}
		br+=maksi;
	}
	return n-br;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k;
	int a, b;
	for(int i=0; i<n-1; i++){
		cin >> a >> b;
		a--;
		b--;
		ms[a].push_back(b);
		ms[b].push_back(a);
	}
	if(k==1){
		cout << n-2 << '\n';
		return 0;
	}
	int sol=n;
	for(int i=0; i<n; i++){
		sol=min(sol, solve(i));
		while(!q.empty()){
			q.pop();
		}
		memset(zbroj, 0, sizeof(zbroj));
		bio.reset();
	}
	cout << sol << '\n';
	return 0;
}

Measured memory_bytes: 888
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    Int ans = 0;
    vector<int> v(n), c(n), z(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        z[i] = v[i] - c[i];
        ans += max(0, z[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.io.PrintWriter;

@SuppressWarnings("unchecked")
public class Main {

    static long N;
    static final String s753 = "753";

    static int dfs(String s) {
        long num = Long.parseLong(s);

        if (N < num) return 0;

        int ret = 1;

        for (int i = 0; i < s753.length(); i++) {
            boolean flg = false;

            for (int j = 0; j < s.length(); j++) {
                if (s.charAt(j) == s753.charAt(i)) {
                    flg = true;
                    break;
                }
            }

            if (!flg) ret = 0;
        }


        for (int i = 0; i < s753.length(); i++) {
            long tmp
                = 10 * num
                    + Long.parseLong(
                        String.valueOf(s753.charAt(i)));

            ret += dfs(String.valueOf(tmp));
        }

        return ret;
    }

    public static void main(String[] args) throws IOException {
        final String s;

        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            s = reader.readLine();
        }

        PrintWriter out = new PrintWriter(System.out);

        N = Long.parseLong(s);

        out.println(dfs("0"));

        out.flush();
    }
}


Measured memory_bytes: 34244
object Main extends App {
	val n = scala.io.StdIn.readInt
	var s = scala.io.StdIn.readLine.toList.map{case 'W' => 1; case 'E' => 0}

	var a = 0
	var b = n - s.sum
	var ans = n

	for(x <- s){
		if(x == 1){
			ans = math.min(ans, a + b)
			a += 1
		}else{
			b -= 1
			ans = math.min(ans, a + b)
		}
	}

	println(ans)
	
}

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


int main() {
    char a,b;cin >> a >> b;
    if (a == 'H'){
        cout << b << endl;
    }else{
        if (b == 'H'){
            cout << 'D' << endl;
        }else{
            cout << 'H' << endl;
        }
    }

}       

Measured memory_bytes: 256
/*author : Yashvardhan
Wednesday, May 08, 2019
9:25 PM
*/

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

typedef long long ll;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define endl '\n'

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int pow(int a, int b, int m)
{
	int ans = 1;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int n,q;
	string s;
	cin>>n>>q;
	cin>>s;

	string inp = "*";
	inp += s;
	int ans[n+1] = {0};
	for(int i = 2; i <= n ; i++){
		ans[i] = ans[i - 1];
		if(inp[i] == 'C'){
			if(inp[i-1] == 'A'){
				ans[i]++;
			}
		}
		
	}



	for(int i = 0; i < q ; i++){
		int x,y;
		cin>>x>>y;
		int tot = ans[y];
		tot -= ans[x-1];
		if(inp[x] == 'C'){
			if(inp[x-1] == 'A') tot--;
		}
		cout<<tot<<endl;
		//cout<<ans[y]-ans[x]<<endl;
	}
	

	t2 = clock();
	cerr<<endl<<t2-t1<<endl;
	
	return 0;
}



Measured memory_bytes: 1872
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cout << fixed;
    cout << setprecision(12);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll W, H, x, y;
    cin >> W >> H >> x >> y;
    double ans = (W * H) * 1.0 / 2.0;
    ll num = 0;
    if (W % 2 == 0 && H % 2 == 0 && x == W / 2 && y == H / 2) {
        num = 1;
    }
    cout << ans << " " << num << endl;
}


Measured memory_bytes: 256
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    N, S = map(int, input().split())
    A = list(map(int, input().split()))

    #output
    mod = 998244353
    dp = [[0] * ( S+1) for _ in range(N+1)]
    #dp[i, j]を、A[0]...A[i]までを使って、Tの空でない部分集合
    #{x_1, x_2, ..., x_k}であって、Ax_1 + A_x_2 + ... + A_x_k = jを満たすものの個数とする。
    dp[0][0] = 1
    #iまででjが作られている時、i+1ではA[i]がどのような値であっても、部分集合としてjは作れる。
    #iまででjが作られない時、j-A[i]が作られていれば、A[i]を足せばjは作れる。
    for i in range(N):
        for j in range(S+1):
            dp[i+1][j] += dp[i][j] * 2 
            dp[i+1][j] %= mod
            if j >= A[i]:
                dp[i+1][j] += dp[i][j-A[i]]
                dp[i+1][j] %= mod
                    
    print(dp[N][S] % mod)

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Measured memory_bytes: 132468
# ABC142D - Disjoint Set of Common Divisors
from fractions import gcd


# cf. AtCoder ARC067C, Euler 012
def prime_factorization(x: int) -> dict:
    """
    Prime factorization of a number (trial division)
    
    Args: x (int): a number to be resolved
    Return: ret (dict): {prime factor: power}
    
    e.g., n = 2^a * 3^b -> {2: a, 3: b}
    """
    max_prime = 0
    ret = {}

    # Divide x by 2 as much as possible
    cnt = 0
    while x % 2 == 0:
        x //= 2
        cnt += 1
    if cnt > 0:
        max_prime = 2
        ret[max_prime] = cnt

    # x must be odd -> skip even numbers
    cnt = 0
    for i in range(3, int(x ** 0.5) + 1, 2):
        cnt = 0
        while x % i == 0:
            x //= i
            max_prime = i
            cnt += 1
        if cnt > 0:
            ret[max_prime] = cnt

    # To handle the case when x is prime greater than 2
    if x > 2:
        max_prime = x
        ret[max_prime] = 1
    return ret


def main():
    A, B = map(int, input().split())
    g = gcd(A, B)
    ans = len(prime_factorization(g).keys()) + 1
    print(ans)


if __name__ == "__main__":
    main()

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

class Solution
{
    static long Calc(long[] array)
    {
        long sum = 0;

        var i = 0;
        var j = array.Length - 1;
        var left = array[i];
        var right = array[i];
        i++;
        while (i <= j)
        {
            sum += Math.Abs(left - array[j]);
            left = array[j];
            j--;
            if (i > j)
            {
                break;
            }

            sum += Math.Abs(right - array[j]);
            right = array[j];
            j--;
            if (i > j)
            {
                break;
            }

            sum += Math.Abs(left - array[i]);
            left = array[i];
            i++;
            if (i > j)
            {
                break;
            }

            sum += Math.Abs(right - array[i]);
            right = array[i];
            i++;
            if (i > j)
            {
                break;
            }
        }

        return sum;
    }

    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = new long[N];
        for (int i = 0; i < N; i++)
        {
            A[i] = long.Parse(Console.ReadLine());
        }
        Array.Sort(A);
        var a = Calc(A);
        var b = Calc(A.AsEnumerable().Reverse().ToArray());

        var sum = Math.Max(a, b);
        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 19420
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;

int n;
int a[N];

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


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

using namespace std;

void print_chessboard(int H, int W, char c1, char c2)
{
	for(int i = 0; i < H; i++)
	{
		for(int j = 0; j < W; j++)
		{
			switch((i + j) % 2)
			{
			case 0: cout << c1; break;
			case 1: cout << c2;
			}
		}

		cout << endl;
	}
}

int main()
{
	vector<int> W, H;

	while(true)
	{
		int H1, W1;

		cin >> H1 >> W1;

		if(H1 == 0 && W1 == 0) { break; }

		H.push_back(H1);
		W.push_back(W1);
	}

	for(vector<int>::size_type i = 0; i < H.size(); i++)
	{
		print_chessboard(H[i], W[i], '#', '.');

		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1212
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String r = sc.next();
        String g = sc.next();
        String b = sc.next();
        String f = r+g+b;

        int fi = Integer.parseInt(f);
        if (fi%4 == 0)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


Measured memory_bytes: 38892
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORr(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORr(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

vector<vector<int>> to(200000);
vector<int> c(200000, 0);
vector<bool> visited(200000, false);


void dfs(int v, int from = -1){
  for(int u : to[v]){
    if(u == from) continue;
    c[u] += c[v];
    dfs(u, v);
  }
}

int main(void){
  int n, q;
  cin >> n >> q;

  to.resize(n);
  c.resize(n);

  REP(i, n-1){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].emplace_back(b);
    to[b].emplace_back(a);
  }

  REP(i, q){
    int p, x;
    cin >> p >> x;
    p--;
    c[p] += x;
  }
  
  dfs(0);

  REP(i, n) cout << c[i] << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 23552
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

ll f[1000000], finv[1000000];

ll modpow(ll a,ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a) {
  return modpow(a, mod - 2);
}

void init() {
  f[0] = 1, finv[0] = 1;
  FOR(i, 1, 1000000) {
    f[i] = f[i - 1] * i % mod;
    finv[i] = modinv(f[i]);
  }
}

ll comb(ll n, ll r) {
  if (r < 0 || r > n) return 0;
  return f[n] * finv[r] % mod * finv[n - r] % mod;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n, m;
  cin >> n >> m;
  vector<ll> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];

  init();
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  rep(i, n - 1) {
    if (a[i] == a[i + 1]) {
      cout << 0 << '\n';
      return 0;
    }
  }
  rep(i, m - 1) {
    if (b[i] == b[i + 1]) {
      cout << 0 << '\n';
      return 0;
    }
  }
  ll ans = 1, idxa = 0, idxb = 0, cnt = 0;
  while (idxa < n && idxb < m && ans > 0) {
    if (a[idxa] < b[idxb]) {
      ans = ans * comb(a[idxa] - 1 - cnt, m - idxb - 1) % mod * f[m - idxb] % mod;
      cnt += m - idxb;
      idxa++;
    }
    else if (a[idxa] > b[idxb]) {
      ans = ans * comb(b[idxb] - 1 - cnt, n - idxa - 1) % mod * f[n - idxa] % mod;
      cnt += n - idxa;
      idxb++;
    }
    else {
      ans = ans * comb(a[idxa] - 1 - cnt, n - idxa - 1 + m - idxb - 1) % mod * f[m - idxb - 1 + n - idxa - 1] % mod;
      cnt += n - idxa + m - idxb - 1;
      idxa++, idxb++;
    }
  }
  cout << ans << '\n';


  
  return 0;
}

Measured memory_bytes: 16000
import Control.Applicative 
import Data.Char
import Debug.Trace
import Data.List

splitInt :: String -> [Integer]
splitInt "" = [] :: [Integer]
splitInt str =
    let charToInt :: Integer -> Char -> Integer
        charToInt d c = d * 10 + (fromIntegral $ digitToInt c) :: Integer
        checkInt :: Integer -> String -> (Integer, String)
        checkInt d "" = (d, "")
        checkInt d (' ':rest) = (d, rest)
        checkInt d (c:rest) = checkInt (charToInt d c)  rest
        (num, rest) = checkInt 0 str
        in num : splitInt rest

check :: [[Integer]] -> Bool
check [[aa, ab, ac], [ba, bb, bc], [ca, cb, cc]] = 
    let z = ((aa - ab) == (ba - bb)) && ((aa - ab) == (ca - cb))
        y = ((aa - ac) == (ba - bc)) && ((aa - ac) == (ca - cc))
        x = ((ab - ac) == (bb - bc)) && ((ab - ac) == (cb - cc))
        w = ((aa - ba) == (ab - bb)) && ((aa - ba) == (ac - bc))
        v = ((ba - ca) == (bb - cb)) && ((ba - ca) == (bc - cc))
        u = ((ca - aa) == (cb - ab)) && ((ca - aa) == (cc - ac))
        in z && y && x && w && v && u

getMat :: Int -> IO [[Integer]]
getMat 0 = return [] :: IO [[Integer]]
getMat n = (:) <$> (splitInt <$> getLine) <*> getMat (n - 1)

main = do
    a <- check <$> getMat 3
    putStrLn (if a then "Yes" else "No")


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

int main() {
    int R, G, B, N; cin >> R >> G >> B >> N;
    int count = 0;

    for(int i = 0; i <= N; i++) {
        for(int j = 0; j <= N; j++) {
            // cout << "r, g :" << i << j << endl;
            if(N - R * i - G * j < 0) break;

            if((N - R * i - G * j) % B == 0) {
                count++;
                // cout << "OK: rest is" << N - R * i - G * j  << endl;
            }
        }
        if(N - R * i <= 0) break;
    }

    cout << count << endl;
}


Measured memory_bytes: 888
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll N;
    cin >> N;
    VV<ll> edges(N);
    for(ll i = 1; i < N; i++) {
        ll a, b;
        cin >> a >> b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    V<ll> cnt(N);
    queue<PLL> que;
    for(ll i = 0; i < N; i++) if(edges[i].size() == 1) que.emplace(i, -1);
    while(que.size()) {
        ll cur, pre;
        tie(cur, pre) = que.front();
        que.pop();
        for(ll nxt : edges[cur]) {
            if(nxt == pre) continue;
            if(2 < edges[nxt].size()) cnt[nxt]++;
            else que.emplace(nxt, cur);
        }
    }
    ll ans = 0;
    for(ll c : cnt) ans += max<ll>(0, c - 1);
    chmax(ans, (ll)1);
    cout << ans << endl;
    return 0;
}


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

int main(void){
    int n;cin >> n;
    string s;cin >> s;
    
    int p = 0;
    string t = "";
    for(int i = 0;i < n;i++){
        if(s[i] == '('){
            t += '(';p++;
        }else{
            if(p == 0){
                t = '(' + t + ')';
            }else{
                t += ')';
                p--;
            }
        }
        //cout << t << endl;
    }
    cout << t;
    for(int i = 0;i < p;i++)cout << ')';
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define inf 1e18
using namespace std;
const int N=5100;
int n,a,b,p[N],dp[N][N];
signed main()
{
	scanf("%lld%lld%lld",&n,&a,&b);
	for (int i=1;i<=n;i++) scanf("%lld",&p[i]);
	memset(dp,0x3f,sizeof(dp));
	dp[0][0]=0;
	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<=n;j++)
		{
			if (p[i]>j)
			{
				dp[i][j]=min(dp[i][j],dp[i-1][j]+a);
				dp[i][p[i]]=min(dp[i][p[i]],dp[i-1][j]);
			}
			else dp[i][j]=min(dp[i][j],dp[i-1][j]+b);
		}
	}
	int ans=inf;
	for (int i=0;i<=n;i++) ans=min(ans,dp[n][i]);
	printf("%lld\n",ans);
}

Measured memory_bytes: 207036
#include <stdio.h>

int main()
{
	int N, c[2][3];
	scanf("%d", &N);
	scanf("%d %d %d", &(c[0][0]), &(c[0][1]), &(c[0][2]));
	scanf("%d %d %d", &(c[1][0]), &(c[1][1]), &(c[1][2]));
	if (c[0][0] * c[1][1] > c[0][1] * c[1][0]) {
		c[0][0] += c[0][1];
		c[0][1] = c[0][0] - c[0][1];
		c[0][0] -= c[0][1];
		c[1][0] += c[1][1];
		c[1][1] = c[1][0] - c[1][1];
		c[1][0] -= c[1][1];
	}
	if (c[0][1] * c[1][2] > c[0][2] * c[1][1]) {
		c[0][1] += c[0][2];
		c[0][2] = c[0][1] - c[0][2];
		c[0][1] -= c[0][2];
		c[1][1] += c[1][2];
		c[1][2] = c[1][1] - c[1][2];
		c[1][1] -= c[1][2];
	}
	if (c[0][0] * c[1][1] > c[0][1] * c[1][0]) {
		c[0][0] += c[0][1];
		c[0][1] = c[0][0] - c[0][1];
		c[0][0] -= c[0][1];
		c[1][0] += c[1][1];
		c[1][1] = c[1][0] - c[1][1];
		c[1][0] -= c[1][1];
	}
	
	long long g, s, b, max = 0;
	if (c[0][2] < c[1][2]) {
		for (g = N / c[0][0]; g >= 0; g--) {
			for (s = (N - g * c[0][0]) / c[0][1]; s >= 0; s--) {
				b = (N - g * c[0][0] - s * c[0][1]) / c[0][2];
				if (g * (c[1][0] - c[0][0]) + s * (c[1][1] - c[0][1]) + b * (c[1][2] - c[0][2]) + N > max) max = g * (c[1][0] - c[0][0]) + s * (c[1][1] - c[0][1]) + b * (c[1][2] - c[0][2]) + N;
			}
		}
	} else if (c[0][1] < c[1][1]) {
		for (g = N / c[0][0]; g >= 0; g--) {
			s = (N - g * c[0][0]) / c[0][1];
			if (g * (c[1][0] - c[0][0]) + s * (c[1][1] - c[0][1]) + N > max) max = g * (c[1][0] - c[0][0]) + s * (c[1][1] - c[0][1]) + N;
		}
		b = max / c[1][2];
		max += b * (c[0][2] - c[1][2]);
	} else if (c[0][0] < c[1][0]) {
		g = N / c[0][0];
		N += g * (c[1][0] - c[0][0]);
		for (s = N / c[1][1]; s >= 0; s--) {
			b = (N - s * c[1][1]) / c[1][2];
			if (s * (c[0][1] - c[1][1]) + b * (c[0][2] - c[1][2]) + N > max) max = s * (c[0][1] - c[1][1]) + b * (c[0][2] - c[1][2]) + N;
		}
	} else {
		for (g = N / c[1][0]; g >= 0; g--) {
			for (s = (N - g * c[1][0]) / c[1][1]; s >= 0; s--) {
				b = (N - g * c[1][0] - s * c[1][1]) / c[1][2];
				if (g * (c[0][0] - c[1][0]) + s * (c[0][1] - c[1][1]) + b * (c[0][2] - c[1][2]) + N > max) max = g * (c[0][0] - c[1][0]) + s * (c[0][1] - c[1][1]) + b * (c[0][2] - c[1][2]) + N;
			}
		}
	}
	
	printf("%lld\n", max);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1708
import queue
h, w = map(int,input().split())
s = ["#"*(w+2) for i in range(h+2)]
for i in range(1,h+1):
    s[i] = "#"+str(input())+"#"

d = [[-1 for i in range(w+2)] for j in range(h+2)]
d[1][1] = 1
q = queue.Queue()
q.put([1,1])

while not q.empty():
    i = q.get()
    r = d[i[0]][i[1]]
    if d[i[0]+1][i[1]] == -1 and s[i[0]+1][i[1]] == ".":
        d[i[0]+1][i[1]] = r+1
        q.put([i[0]+1,i[1]])
    if d[i[0]-1][i[1]] == -1 and s[i[0]-1][i[1]] == ".":
        d[i[0]-1][i[1]] = r+1
        q.put([i[0]-1,i[1]])
    if d[i[0]][i[1]+1] == -1 and s[i[0]][i[1]+1] == ".":
        d[i[0]][i[1]+1] = r+1
        q.put([i[0],i[1]+1])
    if d[i[0]][i[1]-1] == -1 and s[i[0]][i[1]-1] == ".":
        d[i[0]][i[1]-1] = r+1
        q.put([i[0],i[1]-1])

if d[h][w] == -1:
    print(-1)
else:
    num = 0
    for i in range(h+2):
        for j in range(w+2):
            if s[i][j] == ".":
                num += 1
    print(num-d[h][w])


Measured memory_bytes: 3952
import sys
import math
N, D = map(int, input().split())
X = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

def distance(Y, Z, D):
    double_sum = 0
    for i in range(D):
        double_sum += (Y[i] - Z[i]) ** 2
    distance = math.sqrt(double_sum)
    return distance
    
    
count = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        dist = distance(X[i], X[j], D)
        if dist.is_integer():
            count += 1

print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;

struct UnionFind{
  vector<int> par,num;

  UnionFind(int N) : par(N),num(N){
    for(int i=0;i<N;i++){
      par[i] = i;
      num[i] = 1;
    }
  }

  int root(int x){
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
    num[ry] = num[ry]+num[rx]; 
  }

  int get_num(int x){
    int rx = root(x);
    return num[rx];
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};


int main(void){
  string s,t;
  cin >> s >> t;
  bool flag = true;
  for(int i=0;i<s.length();i++){
    if(s[i] != t[i]){
      flag = false;
    }
  }

  if(flag && s.length()+1 == t.length() ){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


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

#define int long long
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); i++)  
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rap(i,a,n) for (int i = a; i < (n); i++) 
#define rrap(i,n,a) for (int i = (n)-1; i >= a; i--) 
#define LL_MAX 9223372036854775807

typedef vector<int> vi;  
typedef pair<int,int> ii;  
typedef vector<ii> vii;  
typedef list<int> li;  
typedef unordered_map<int,int> mii;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c;
    cin >> a;
    cin >> b;
    if (a!=1 && b!=1) cout << 1 << '\n';
    else if (a!=2 && b!=2) cout << 2 << '\n';
    else cout << 3 << '\n';

    return 0;
    //compile: g++ -std=c++14 -O2 -Wall NAME.cpp -o NAME
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

int main(){
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	//insert code
	int n;
	cin>>n;
	vi a(n),b(n),c(n);
	rep(i,0,n)cin>>a[i]>>b[i]>>c[i];
	int dp[3][n];
	dp[0][0]=a[0];
	dp[1][0]=b[0];
	dp[2][0]=c[0];
	for (int i=1;i<n;i++){
		dp[0][i]=a[i]+max(dp[1][i-1],dp[2][i-1]);
		dp[1][i]=b[i]+max(dp[0][i-1],dp[2][i-1]);
		dp[2][i]=c[i]+max(dp[0][i-1],dp[1][i-1]);
	}
	cout<<max(max(dp[0][n-1],dp[1][n-1]),dp[2][n-1])<<endl;
	return 0;
}

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

typedef long long ll;

int max(int a, int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

int main(){

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

  while(n > 1000){
    n -= 1000;
  }

  printf("%d",1000 - n);

  return 0;
}


Measured memory_bytes: 1736
main :: IO ()
main = do
  [a,b,c,d] <- map read . words <$> getLine :: IO [Integer]

  let k = ((c * d) `div` gcd c d)
      l = a `mod` c
      m = a `mod` d
      n = a `mod` k
      l1 = a `div` c
      l2 = b `div` c
      m1 = a `div` d
      m2 = b `div` d
      n1 = a `div` k
      n2 = b `div` k
      l' = l2 - l1 + if l == 0 then 1 else 0
      m' = m2 - m1 + if m == 0 then 1 else 0
      n' = n2 - n1 + if n == 0 then 1 else 0
  print $ (b - a + 1) - (l' + m' - n')


Measured memory_bytes: 508
#include<iostream>
#include<algorithm>
#include<cmath>
#include <numeric>
using ll = long long;
using namespace std;

ll x[100050] = {};

int main()
{
	ll n, k;
	ll ans = 0;
	ll m = 1000000007;

	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> x[i];
	}

	for (int i = 0; i < n - k + 1; i++)
	{
		ll tmp;
		tmp = x[i + (k - 1)] - x[i];
		tmp += min(abs(x[i]), abs(x[i + (k - 1)]));

		if (tmp < m) {
			ans = tmp;
			m = tmp;
		}
	}

	cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pii;
typedef double ld;
typedef pair<ld, ld> pdd;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = (int)1005;
char g[N][N];

vector<vector<char>> sol[4];
void init(){  
  sol[0].resize(4);
  sol[1].resize(5);
  sol[2].resize(6);
  sol[3].resize(7);
  sol[0][0] = {'a', 'a', 'b', 'c'};
  sol[0][1] = {'d', 'd', 'b', 'c'};
  sol[0][2] = {'b', 'c', 'a', 'a'};
  sol[0][3] = {'b', 'c', 'd', 'd'};
  sol[1][0] = {'.','.','a','b','c'};
  sol[1][1] = {'.','.','a','b','c'};
  sol[1][2] = {'a','a','d','d','e'};
  sol[1][3] = {'b','b','g','.','e'};
  sol[1][4] = {'c','c','g','f','f'};
  sol[2][0] = {'.','.','.','a','b','c'};
  sol[2][1] = {'.','.','.','a','b','c'};
  sol[2][2] = {'a','a','d','d','.','e'};
  sol[2][3] = {'.','.','a','a','b','e'};
  sol[2][4] = {'c','c','b','.','b','.'};
  sol[2][5] = {'a','a','b','.','c','c'};
  sol[3][0] = {'.','.','.','.','a','b','c'};
  sol[3][1] = {'.','.','.','.','a','b','c'};
  sol[3][2] = {'.','.','.','.','d','a','d'};
  sol[3][3] = {'.','.','.','.','d','a','d'};
  sol[3][4] = {'a','a','d','d','.','.','b'};
  sol[3][5] = {'b','b','a','a','.','.','b'};
  sol[3][6] = {'c','c','d','d','a','a','.'};
  
}

int main(){
  fastIO;
  init();
  int n;
  cin >> n;
  if(n == 2){
    cout << -1;
    return 0;
  }
  if(n == 3){
    cout << "..a\n..a\naa.";
    return 0;
  }
  for(int i = 0 ; i < n; i ++ ){
    for(int j = 0 ; j < n ; j ++ ){
      g[i][j] = '.';
    }
  }
  int p = 0;
  int d;
  while(n > 0){
    d = n%4 + 4;
    for(int i = 0 ; i < d; i ++ ){
      for(int j = 0 ; j < d; j ++ ){
        g[p + i][p + j] = sol[n%4][i][j];
      }
    }
    p += d;
    n -= d;
  }
  for(int i = 0 ; i < p; i ++ ){
    for(int j = 0 ; j < p; j ++ ){
      cout << g[i][j];
    }
    cout << "\n";
  }
  return 0;
}

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

using namespace std;

int main(){
	int n;
	long long ant = -1,atual,resp = 0;
	
	scanf("%d",&n);
	for(int i = 0;i < n;i++){
		scanf("%lld",&atual);
		if(ant == -1){
			ant = atual;
		}else if(ant > atual){
			resp += ant-atual;
		}else{
			ant = atual;
		}
		// printf("%lld %lld %lld\n",ant,atual,resp);
	}
	printf("%lld\n",resp);
}

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

public class UnionFind<T>
{
    private int m_height;
    private UnionFind<T> m_parent;

    public T Item { get; private set; }
    public int NumberOfChildren { get; private set; }

    public UnionFind(T item)
    {
        m_height = 0;
        m_parent = this;
        Item = item;
        NumberOfChildren = 1;
    }

    public UnionFind<T> Root()
    {
        if (m_parent == this)
        {
            return this;
        }

        UnionFind<T> parent = m_parent.Root();
        m_parent = parent;
        return parent;
    }

    public static void Unite(UnionFind<T> a, UnionFind<T> b)
    {
        UnionFind<T> p = a.Root();
        UnionFind<T> q = b.Root();
        if (p.m_height < q.m_height)
        {
            p.m_parent = q;
            q.m_height = Math.Max(p.m_height + 1, q.m_height);
            q.NumberOfChildren += p.NumberOfChildren;
        }
        else
        {
            q.m_parent = p;
            p.m_height = Math.Max(q.m_height + 1, p.m_height);
            p.NumberOfChildren += q.NumberOfChildren;
        }
    }
}

class Program
{
    public static void Main(string[] args)
    {
        MainModule(Console.In);
    }

    public static void MainModule(TextReader In)
    {
        var l1 = In.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList();
        int N = l1[0];
        int M = l1[1];

        var makeLinks = new Tuple<int, int>[M];
        for (var i = 0; i < M; i++)
        {
            var line = In.ReadLine();
            var l2 = line.Split(' ').Select(n => int.Parse(n)).ToList();
            int A = l2[0];
            int B = l2[1];
            makeLinks[i] = new Tuple<int, int>(A - 1, B - 1);
        }

        var nodes = new UnionFind<int>[N];
        for (int i = 0; i < N; i++)
            nodes[i] = new UnionFind<int>(i);

        var answers = new List<long>();
        long answer = ((long)N * (N - 1)) / 2;//((long)N * (long)(N - 1)) / 2;
        answers.Add(answer);
        for (int i = M - 1; i > 0; i--)
        {
            var node1 = nodes[makeLinks[i].Item1];
            var node2 = nodes[makeLinks[i].Item2];
            var r1 = node1.Root();
            var r2 = node2.Root();
            
            if (r1 == r2)
            {
            }
            else
            {
                var nc1 = r1.NumberOfChildren;
                var nc2 = r2.NumberOfChildren;
                answer -= nc1 * nc2;

                UnionFind<int>.Unite(r1, r2);
            }
            answers.Add(answer);
        }
        answers.Reverse();
        foreach (var s in answers)
        {
            Console.WriteLine(s);
        }
    }
}


Measured memory_bytes: 30644
#include <bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main()
{
	cin>>a>>b>>c>>d;
	int t1=(c+b-1)/b;
	int t2=(a+d-1)/d;
	if (t1<=t2)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3612