akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
const ll inf = 1e18;
const int mod = 1e9+7;

int N;
ll a[200005];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll s = 0, _s = 0, ans;
  cin >> N;
  FOR(i, 0, N){
    cin >> a[i];
    s += a[i];
  }
  _s = a[0];
  ans = abs(s - _s*2ll);
  FOR(i, 1, N-1){
    _s += a[i];
    ans = min(ans, abs(s - _s*2ll));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

int n, ans, s[105], a[10];
vector<int> b;
bool v[105], v1[2000005];
int main()
{
	int i, j, k, z;
	cin >> n;
	for (i= 2; i <= n; i++) {
		if (v[i]) continue;
		b.push_back(i);
		for (j = i * 2; j <= n; j += i) v[j] = 1;
		for (j = i; j <= n; j *= i) s[i] += n / j;
	}
	for (i = 0; i < b.size(); i++) {
		if (s[b[i]] >= 74) ans++;
		for (j = 0; j < b.size(); j++) {
			if (i == j) continue;
			if (s[b[i]] >= 2 && s[b[j]] >= 24) {ans++;}
			if (s[b[i]] >= 4 && s[b[j]] >= 14) {ans++;}
			for (k = 0; k < b.size(); k++) {
				if (i == k || j == k) continue;
				a[0] = j;
				a[1] = k;
				sort(a, a + 2);
				z = i * 10000 + a[0] * 100 + a[1];
				if (s[b[i]] >= 2 && s[b[j]] >= 4 && s[b[k]] >= 4 && !v1[z]) {ans++; v1[z] = 1;}
			}
		}
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 256
def solve():
	N,A = map(int,raw_input().split())
	x = map(int,raw_input().split())
	ofs = N*50; M = ofs*2 + 1
	DP = [[0]*M for i in xrange(N+1)]
	DP[0][ofs] = 1
	for i in xrange(N):
		for j in xrange(M):
			if DP[i][j] == 0: continue
			DP[i+1][j+x[i]-A] += DP[i][j]
			DP[i+1][j] += DP[i][j]
	print DP[N][ofs] - 1
solve()

Measured memory_bytes: 4996
#include <bits/stdc++.h>
using namespace std;
const int MAXN=100010;
int N,cnt,s[MAXN<<1];
int P[MAXN],A[MAXN],B[MAXN],F[MAXN];
struct Bit
{
	int a[MAXN<<1];
	void modify(int x,int v) {for (int i=x;i<=cnt;i+=i&(-i)) a[i]=max(a[i],v);}
	int ask(int x)
	{
		int ans=0;
		for (int i=x;i;i-=i&(-i)) ans=max(ans,a[i]);
		return ans;
	}
}T;
bool cmp(const int &a,const int &b) {return B[a]<B[b];}
int main()
{
	cin>>N;
	for (int i=1;i<=N;++i)
	{
		int x,v;
		scanf("%d%d",&x,&v);
		A[i]=x-v;
		B[i]=x+v;
		s[++cnt]=A[i];
		s[++cnt]=B[i];
		P[i]=i;
	}
	sort(s+1,s+1+cnt);
	cnt=unique(s+1,s+1+cnt)-s-1;
	sort(P+1,P+1+N,cmp);
	int Ans=0;
	for (int i=1;i<=N;++i)
	{
		int l=A[P[i]];
		int r=B[P[i]];
		l=lower_bound(s+1,s+1+cnt,l)-s;
		r=lower_bound(s+1,s+1+cnt,r)-s;
		F[i]=T.ask(l)+1;
		Ans=max(Ans,F[i]);
		T.modify(r,F[i]);
	}
	cout<<Ans<<endl;
	return 0;
} 

Measured memory_bytes: 3328
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
# from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var): sys.stdout.write('\n'.join(map(str, var)) + '\n')
def out(var): sys.stdout.write(str(var) + '\n')
from decimal import Decimal
# from fractions import Fraction
# sys.setrecursionlimit(100000)
mod = 998244353
INF=float('inf')




def find(x):
    while Group[x] != x:
        x = Group[x]
    return x

def Union(x, y):
    if find(x) != find(y):

        if Nodes[find(x)] < Nodes[find(y)]:
            Nodes[find(y)] += Nodes[find(x)]
            Nodes[find(x)] = 0
            Group[find(x)] = find(y)

        else:
            Nodes[find(x)] += Nodes[find(y)]
            Nodes[find(y)] = 0
            Group[find(y)] = find(x)




n,m=mdata()
Group = [i for i in range(n + 1)]
Nodes = [1] * (n + 1)
for i in range(m):
    a,b=mdata()
    Union(a,b)
s=set()
for i in Group[1:]:
    s.add(find(i))
out(len(s)-1)

Measured memory_bytes: 92312
#include<stdio.h>
#include<math.h>

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

  scanf("%lld%lld%lld",&a,&b,&c);
  
  
  long long ans=0;

  if((a*b*c)%2==0){
    printf("0\n");
  }
  else{
    if(a*b<=b*c&&a*b<=c*a){
      printf("%lld\n",a*b);
    }
    else if(b*c<=a*b&&b*c<=c*a){
      printf("%lld\n",b*c);
    }
    else{
      printf("%lld\n",c*a);
    }
  }

  return 0;
}
 

Measured memory_bytes: 128
// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<ll,ll> 
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(ll a,ll b){if(a<b)return a; return b;}
ll Max(ll a,ll b){if(a>b)return a; return b;}
int32_t main() {
    IOS;

        ll n,m,i;
        double sum=0.0;
        cin>>n>>m;
        vll v(n);
        rep(i,0,n-1) {cin>>v[i];sum+=v[i];} sort(all(v)); reverse(all(v));
 		if(v[m-1]>=(sum/(4*m)))cout<<"Yes";
 		else cout<<"No";       



        cout<<'\n';
    return 0;
}

Measured memory_bytes: 256
import sys

abcd = input()
a = [int(i) for i in abcd]

for i in range(2**3) :
  bit = i
  v = a[0]
  ans = str(v)
  for j in range(1,4) :
    c = bit%2
    bit = bit//2
    if c == 0 :
      v -= a[j]
      ans += '-' + str(a[j])
    else :
      v += a[j]
      ans += '+' + str(a[j])
  if v == 7 :
    print(ans+'=7')
    sys.exit()

Measured memory_bytes: 3064
#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 N;
    cin >> N;
    vector<ll> a(N), b(N);
    ll suma = 0;
    ll sumb = 0;
    rep(i,N){
        cin >> a[i];
        suma += a[i];
    }
    rep(i,N){
        cin >> b[i];
        sumb += b[i];
    }
    if(suma > sumb){
        cout << "No" << endl;
        return 0;
    }
    ll M = sumb - suma;
    ll manua=0;
    ll manub=0;
    rep(i,N){
        if(a[i] == b[i]) continue;
        if(a[i] < b[i]){
            M -= (a[i] - b[i])/2 + ((a[i] - b[i])%2);
            manua += (a[i] - b[i])/2 + ((a[i] - b[i])%2);
            manub += ((a[i] - b[i])%2);
        }else{
            M -= b[i] - a[i];
            manub += b[i] - a[i];
        }
        if(M < 0){
            cout << "No" << endl;
            return 0;
        }
    }
    ll MM = sumb-suma;
    if(manua <= MM && manub <= MM && manua <= manub){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 512
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr> () -> T {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();

    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    let mut a: Vec<i64> = vec![0; (N+2) as usize];
    let mut flag: bool = true;
    for i in 0..N {
        a[i as usize] = read::<i64>();
    }
    let last = a[(N-1) as usize].clone();

    for i in (1..N).rev() {
        if a[i-1] <= a[i] {
            continue;
        }
        else if a[i-1] -1 <= a[i] {
            a[i-1] -= 1;
            continue;
        }
        else {
            flag = false;
            break;
        }
    }


    if flag {
        println!("Yes");
    }
    else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fcout cout << fixed << setprecision(18)

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

  double R; cin >> R;
  
  fcout << (2.0 * R * 3.14159265358979) << '\n';
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0;i < N;i++) {
    cin >> vec.at(i);
  }
  int count = 0;
  for(int i = 0;i < N - 1;i++) {
    if(vec.at(i) == vec.at(i + 1)) {
      count++;
      vec.at(i + 1) = 10001;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll N = 1e9+7;
const int n_max = 1e5+10;

int main(){
    string s;cin >> s;
    int len = s.size();
    int count = 0;
    string pre = "",now = "";
    int state = 0;
    while(len){
        now += s[state];
        // cout << "now" << ' ' << now  << ' ' << "pre" << ' ' << pre << endl;
        if(now == pre){
            state++;
            len--;
            continue;
        }
        count++;
        pre = now;
        now = "";
        state++;
        len--;
    }
    cout << count << endl;
    return 0;

}

Measured memory_bytes: 640
n, m = input().split()
N = int(n)
M = int(m)

listL = []
listR = []
card = N
for i in range(M):
    l, r = input().split()
    L = int(l)
    R = int(r)

    listL.append(L)
    listR.append(R)

maxL = max(listL)
minR = min(listR)

if minR < maxL:
    result = 0
else:
    result = minR - maxL + 1
print(result)


Measured memory_bytes: 11000
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int c = 0;
  string s;
  while (cin >> s) {
    regex r(R"(\d+)");
    for (sregex_iterator iter(all(s), r), end; iter != end; iter++) {
      c += stoi(iter->str());
    }
  }
  cout << c << endl;
}

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

const double pi = 3.141592653589793;
#define YESNO(x) x ? printf("YES") : printf("NO")
#define YesNo(x) x ? printf("Yes") : printf("No")
#define rep(i,a,b) for (int (i) = (a); (i) < (b); ++(i))
#define scani(x) scanf("%d", &x)
#define scanll(x) scanf("%lld", &x)
#define printi(x) printf("%d", x)
#define printll(x) printf("%lld", x)
typedef long long ll;
using namespace std;

long long GCD(long long x, long long y) {
	return y ? GCD(y, x % y) : x;
}

long long LCM(long long x, long long y) {
	return x * y / GCD(x, y);
}

//give up(TLE)
int ABC168D() {
	int n, m;
	scani(n);
	scani(m);

	vector<int> graph[100001];
	int ans[100001];
	rep(i, 0, m) {
		int a, b; cin >> a >> b;
		a--; b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	vector<bool> visit(n, false);
	visit[0] = true;
	queue<int> q;
	q.push(0);
	while (!q.empty()) {
		int cur = q.front();
		q.pop();

		for (auto& itr : graph[cur]) {
			if (!visit[itr]) {
				ans[itr] = cur;
				visit[itr] = true;
				q.push(itr);
			}
		}
	}

	bool isOk = true;
	for (auto itr : visit) {
		if (!itr) {
			YesNo(0);
			return 0;
		}
	}

	YesNo(1);
	printf("\n");
	rep (i, 1, n) {
		printf("%d\n", ans[i] + 1);
	}


	return 0;
}

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

Measured memory_bytes: 10628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int n, q, c[210000];
vector<vector<int> > v(210000);

void dfs(int x) {
  if (v[x].size() == 0) {
    return;
  }
  for (int i = 0; i < v[x].size(); i++) {
    c[v[x][i]] = c[x] + c[v[x][i]];
    dfs(v[x][i]);
  }
  return;
}

int main() {
  cin >> n >> q;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
  }
  for (int i = 0; i < q; i++) {
    int p, x;
    cin >> p >> x;
    c[p] += x;
  }
  dfs(1);
  for (int i = 1; i < n; i++) {
    cout << c[i] << " ";
  }
  cout << c[n] << endl;
  return 0;
}

Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a=-1e9,b=1e9+7,n,x;
  cin>>n;
  while(n--){
    cin>>x;
    b=min(b,x);
    a=max(a,x);
  }
  cout<<a-b<<endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

const int MOD = 1000000007;

struct mint { int n; mint(int n_ = 0) : n(n_) {} };
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};

void check_fact(int n) {
  for (int i = I_.size(); i <= n; i++) {
    I_.push_back(I_[MOD % i] * (MOD - MOD / i));
    F_.push_back(F_[i - 1] * i);
    R_.push_back(R_[i - 1] * I_[i]);
  }
}

mint I(int n) { check_fact(abs(n)); return n >= 0 ? I_[n] : -I_[n]; }
mint F(int n) { check_fact(n); return n < 0 ? 0 : F_[n]; }
mint R(int n) { check_fact(n); return n < 0 ? 0 : R_[n]; }
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  // xoxoxoxoxox
  int N, K;
  cin >> N >> K;
  for (int i = 1; i <= K; i++) {
    cout << H(i, K-i) * H(i+1,N-K-(i-1)) << '\n';
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long kq,f[200005],n,u,v;
deque<int> dq;
pair<int,int> a[200005];
int phin(int u)
{
    return f[u]<=0 ? u : f[u]=phin(f[u]);
}
void uni(int u,int v)
{
    if (f[u]>f[v]) swap(u,v);
    f[u]+=f[v];
    f[v]=u;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for (int i=1;i<=n;++i)
    {
        cin>>a[i].first;
        a[i].second=i;
        dq.push_back(i);
    }

    sort(a+1,a+n+1);
    memset(f,-1,sizeof(f));
    for (int i=1;i<=n;++i)
    {
        while (1)
        {
            u=phin(a[i].second);
            v=phin(dq.front());dq.pop_front();
            if (u==v) break;
            uni(u,v);
        }
        u=phin(a[i].second);
        kq=kq-f[u]-1;
        f[u]++;
        if (f[u]<0) dq.push_back(u);
    }
    cout<<kq<<endl;
    return 0;
}



Measured memory_bytes: 6808
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
#define P pair<int,int>
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
int sankaku(int a){
	return a*(a+1)/2;
} 
int XOR(int a,int b){
	int ni=1;
	rep(0,i,41){
		n2[i]=ni;
		ni*=2;
	}
	rep(0,i,41)nis[i]=0;
	for(int i=40;i>=0;i-=1){
		if(a>=n2[i]){
			nis[i]++;
			a-=n2[i];
		}
		if(b>=n2[i]){
			nis[i]++;
			b-=n2[i];
		}	
	}
	int sum=0;
	rep(0,i,41)sum+=(nis[i]%2*n2[i]);
	return sum;
}
signed main(){
	ic(x) ic(y)
	if(x>=0&&y>0&&x>y)c(2+x-y)
	else if(x>=0&&y>0&&x<y)c(y-x)
	else if(x>=0&&y<0&&x<=-y)c(-x-y+1)
	else if(x>=0&&y<0&&x>-y)c(x+y+1)
	else if(x<0&&y>0&&-x<=y)c(x+y+1)
	else if(x<0&&y>0&&-x>y)c(-x-y+1)
	else if(x<0&&y<0&&-x<=-y)c(x-y+2)
	else if(x>0&&y==0)c(x+1)
	else if(x<=0&&y==0)c(-x)
	else c(y-x)
}	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using in = int64_t;
 
int main(){
int n;
  cin >>n;
  int x;
  map<int,int> a;
rep(i,n){
cin>>x;
  a[x] = i;
}
  
  for (auto p : a) {
  auto key = p.first;
  auto value = p.second;
  cout<<value+1<<" ";
}
  
}

Measured memory_bytes: 5504
#pragma GCC optimize("Ofast")
#include<stdio.h>
int main(void)
{
    int n = 0;
    char c=getchar_unlocked();
    while(c<='9'&&c>='0') {n=(n<<1)+(n<<3)+c-'0'; c=getchar_unlocked();}
    int a = 0, b = 0, e = 0, d = 0;
    do
    {
        switch(getchar_unlocked())
        {
          case 'A': ++a;break;
          case 'W': ++b;break;
          case 'R': ++d;break;
          default: ++e;getchar_unlocked();
        }
        getchar_unlocked();
        getchar_unlocked();
    } while(--n);
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d", a, b, e, d);
    return 0;
}


Measured memory_bytes: 1600
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
using namespace std;

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;


 const int N = 50 + 5;
 long long x[N];
 long long c[N][N];
int main(){
    int n, a, b;
    rep(i,0,N) c[i][0] = 1;
    rep(i,1,N) rep(j,1,i+1) c[i][j] = c[i-1][j] + c[i-1][j-1];
    while(cin >> n >> a >> b) {
        rep(i,0,n) cin >> x[i];
        sort(x, x+n, greater<long long>());
//        rep(i,0,n) cout << x[i] << " "; cout << endl;
        long long sum = 0;
        rep(i,0,a) sum += x[i];
        int e = 0, d = 0;
        rep(i,0,a) if(x[i] == x[a-1]) e++;
        rep(i,0,n) if(x[i] == x[a-1]) d++;
//        cout << a << " " << b <<endl;
//        cout << e << " " << d <<endl;
        long long num = 0;
        if(x[0] == x[a-1]) {
            int cnt = 0;
            rep(i,0,n) if(x[i]==x[0]) cnt++;
            rep(i,a,min(a+cnt, b+1)) {
                num += c[cnt][i];
            }
        } else {
            num = c[d][e];
        }
        printf("%.15lf\n%lld\n", (double)sum / a, num);
    }
	return 0;
}


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

int main(){
    int n;
    int a[100];
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    cout<<abs(a[0]-a[n-1])<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  for(int i=0;i<(tx-sx);i++)
    cout<<"R";
  for(int i=0;i<(ty-sy);i++)
    cout<<"U";
  for(int i=0;i<(tx-sx);i++)
    cout<<"L";
  for(int i=0;i<(ty-sy+1);i++)
    cout<<"D";
  for(int i=0;i<(tx-sx+1);i++)
    cout<<"R";
  for(int i=0;i<(ty-sy+1);i++)
    cout<<"U";
  cout<<"L";
  cout<<"U";
  for(int i=0;i<(tx-sx+1);i++)
    cout<<"L";
  for(int i=0;i<(ty-sy+1);i++)
    cout<<"D";
  cout<<"R"<<endl;

   return 0;
}

Measured memory_bytes: 256
import math 
def using_sqrt(k):  
    factor = 0
        
    # 2以外の偶数は素数ではないので無視する
    if k % 2 == 0 and k != 2:
        return False
        
    # 繰り返しの上限を対象の平方根にする
    for divisor in range(2, math.floor(math.sqrt(k))+1):
        if k % divisor == 0:
            factor += 1
                
    if factor == 0:
        return True
    else:
        return False
            
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

def make_codivisors(n):
    divisors = []
    n0divisors = make_divisors(n[0])
    n0len = len(n0divisors)
    for i in n0divisors:
        for j in range(1, len(n)):
            if n[j] % i != 0:
                break
            if j == len(n)-1:
                divisors.append(i)
            
    # divisors.sort()
    return divisors

a, b =map(int, input().split())
div = make_codivisors([a, b])
ans = 0
for i in div:
  if i==1:
    ans+=1
  else:
    if using_sqrt(i):
      ans+=1
print(ans)

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

    void solve() {
        ll h, n;
        cin >> h >> n;
        ll a[n], b[n], x, y;
        ll dp[h+1] ;    dp[0] = 0;
        for(ll i = 0; i <= h; i++)   dp[i] = 999999999;
        for(ll i = 0; i < n; i++){
            cin >> x >> y;
             for(ll j = 0; j <= h; j++){
                dp[j] = min(dp[j], (j > x ? dp[j - x] : 0) + y);
               // cout << i <<  " " << j << " " << dp[j] << endl;
        }
        }
        cout << dp[h] << endl;
    }

    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      //ll ti;   cin >> ti;  while(ti--)
      solve();
      return 0;
    }

/*
9 3
8 3
4 2
2 1
*/


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int INF = 1e9;

int main(void){

	int N, M, K; cin >> N >> M >> K;

	string ans = "No";
	REP(x,M+1){
		REP(y,N+1){
			if(x*N + y*M - 2*x*y == K) ans = "Yes";
		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "damage", long, "cost");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto a = aryread();
    a.sort();
    a.length -= a.uniq.copy(a).length;
    if(a.length == n)
        writeln("YES");
    else
        writeln("NO");
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 11320
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n,k,dp[100005][2],a[105];
ll f(ll k,ll p)
{
	if(dp[k][p]!=-1)
		return dp[k][p];
	ll ans=1-p;
	rep(i,0,n)
	{
		if(k-a[i]<0)
			break;
		if(f(k-a[i],1-p)==p)
		{
			ans=p;
			break;
		}
	}
	dp[k][p]=ans;
	return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    rep(i,0,n)
    cin>>a[i];
    memset(dp,-1,sizeof(dp));
    if(f(k,0)==0)
    	cout<<"First\n";
    else
    	cout<<"Second\n";
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  string b;
  cin >> a >> b;
  if(a % 2 == 1){
    cout << "No" << endl;}
  else{
    bool f = true;
    for(int i = 0;i < (a/2);i++){
      if(b.at(i) != b.at(i+(a/2))){f = false;}
    }
    if(f == true){
      cout << "Yes" << endl;}
    else{cout << "No" << endl;}
  }}

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

char field[3][3];

char judge(){
	for(int i=0; i < 3; i++){
		if(field[i][0] == field[i][1] && field[i][0] == field[i][2] && field[i][0] != 's'){
			return field[i][0];
		}
		else if(field[0][i] == field[1][i] && field[0][i] == field[2][i] && field[0][i] != 's'){
			return field[0][i];
		}
	}
	if(field[0][0] == field[1][1] && field[0][0] == field[2][2] && field[0][0] != 's'){
		return field[0][0];
	}
	else if(field[0][2] == field[1][1] && field[0][2] == field[2][0] && field[0][2] != 's'){
		return field[0][2];
	}
	else return 'd';
}

int main(){
	while(cin >> field[0][0]){
		for(int i=0; i < 3; i++){
			for(int j=0; j < 3; j++){
				if(i == 0 && j == 0) continue;
				cin >> field[i][j];
			}
		}

		cout << judge() << endl;
	}
}

Measured memory_bytes: 1132
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
B=[0]*40
for i in range(n):
  nn=A[i].bit_length()
  for j in range(nn):
    if bin(A[i])[-j-1]=="1":
      B[j]+=1

ans=sum(A)
kk=bin(k)[2:].zfill(40)
for i in range(40):
  if kk[i]=="0":
    continue
  else:
    ans1=0
    for j in range(40):
      if j<i:
        if kk[j]=="1":
          ans1+=2**(39-j)*(n-B[39-j])
        else:
          ans1+=2**(39-j)*B[39-j]
      elif j==i:
        ans1+=2**(39-j)*B[39-j]
      else:
        ans1+=2**(39-j)*max((n-B[39-j]),B[39-j])
    ans=max(ans,ans1)
ans1=0
for j in range(40):
  if kk[j]=="1":
    ans1+=2**(39-j)*(n-B[39-j])
  else:
    ans1+=2**(39-j)*B[39-j]
ans=max(ans,ans1)


print(ans)

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

int main(){
  string s,t;
  cin >> s >> t;
  int a = -1;
  
  for(int i=0;i<(((s.size())-(t.size()))+1);i++){
    int sub=0;
    for(int j=0;j<t.size();j++){
      if(s.at(i+j) != t.at(j))
        sub++;
    }
    if(a==-1)
      a = sub;
    else
      a = min(a,sub);
  }
  
  cout << a << endl;
}
    

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
class Program
    {
        static void Main(string[] args)
        {   
            string[] s1 = Console.ReadLine().Split(' ');
            int n = int.Parse(s1[0]), m = int.Parse(s1[1]);
            
            string[] s2 = Console.ReadLine().Split(' ');
            int[] a = new int[n];
            for (int i=0; i<n; i++)
            {
                a[i] = int.Parse(s2[i]);
            }
            Array.Sort(a);

            Dictionary<int, int> dic = new Dictionary<int, int>();

            for (int i=0; i<m; i++)
            {
                string[] s3 = Console.ReadLine().Split(' ');
                int b = int.Parse(s3[0]), c = int.Parse(s3[1]);
                if (dic.ContainsKey(c)) dic[c] += b;
                else dic.Add(c, b);
            }
            List<KeyValuePair<int, int>> pairs = new List<KeyValuePair<int, int>>(dic);
            pairs.Sort((x, y) => y.Key - x.Key);

            int point = 0;
            foreach(KeyValuePair<int, int> p in pairs)
            {
                //onsole.Error.WriteLine(p.Key + " " + p.Value);
                for (int i=0; i<p.Value; i++)
                {
                    if (a[point] < p.Key)
                    {
                        a[point] = p.Key;
                        point++;
                        if (point >= n)
                        {
                            long ans = 0;
                            foreach (int j in a)
                            {
                                //Console.Error.WriteLine(j);
                                ans += (long) j;
                            }
                            Console.WriteLine(ans);
                            return;
                        }
                    }
                    else
                    {
                        long ans = 0;
                        foreach (int j in a)
                        {
                            //Console.Error.WriteLine(j);
                            ans += (long) j;
                        }
                        Console.WriteLine(ans);
                        return;
                    }
                }
            }
            {
                long ans = 0;
                foreach (int j in a)
                {
                    //Console.Error.WriteLine(j);
                    ans += (long) j;
                }
                Console.WriteLine(ans);
            }
            
        }
    }
    //mcs Main.cs
    //mono Main.exe

Measured memory_bytes: 33216
while True:
    s = 0
    a = input().split()
    X = [int(i) for i in a]
    N,A,B = str(X[0]), X[1], X[2]
    if (int(N) < 1 or int(N) >10001) or (A > B or B > 36 or A < 1):
        continue
    for i in range(1,int(N)+1):
        a = 0
        l = []
        l = list(map(int,list(str(i))))
        for j in l:
            a = a + j
        if a >= A and a <= B:
            s = s + i
    print(s)
    break

Measured memory_bytes: 3188
n,m,x,y = map(int,input().split())
xi = list(map(int,input().split()))
yi = list(map(int,input().split()))
x_max = max(xi)
x_min = min(xi)
y_max = max(xi)
y_min = min(yi)
a = 0
if x_max < y_min:
    if x < y_min and y > x_max:
        a += 1
if a >= 1:
    print("No War")
else:
    print("War")

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

typedef long long ll;
using namespace std;

int main() {
    int N, V[20], C[20];
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> V[i];
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> C[i];
        if (V[i] - C[i] > 0) {
            ans += V[i] - C[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int I=X;I<Y;I++)
#define REP(I,X,Y) for(int I=Y-1;I>=X;I--)
#define INF 1000000007
using namespace std;

int main(){
  int n,a;
  cin >> n;
  deque<int> deq;
  FOR(i,0,n){
    cin >> a;
    if(i%2)deq.push_back(a);
    else deq.push_front(a);
  }
  if(n%2)FOR(i,0,n)cout << deq[i] << " ";
  else REP(i,0,n)cout << deq[i] << " ";
  cout << endl;
}


Measured memory_bytes: 2944
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

template<typename T>
map<T, long long> factorize(T x) {
  map<T, long long> res;
  for (long long i = 2; i * i <= x; ++i) {
    while (x % i == 0) {
      x /= i;
      res[i] += 1;
    }
  }
  if (x != 1) res[x]++;
  return res;
}

// x以上の要素の数を数える
template<typename T>
long long o_count(T x, vector<T> v) {
  long long cnt = 0;
  for (auto itr : v) {
    if (itr >= x){
      cnt++;
    }
  }
  return cnt;
}

int main() {
  int n; cin >> n;
  vector<int> cnt(n+1, 0);
  for (int i = 1; i <= n; ++i) {
    for (auto itr : factorize(i)) {
      cnt[itr.first] += itr.second;
    }
  }

  // 75, 25, 15, 5, 3
  int a,b,c,d,e;
  a = o_count(74, cnt);
  b = o_count(24, cnt);
  c = o_count(14, cnt);
  d = o_count(4, cnt);
  e = o_count(2, cnt);

  int res = 0;
  // 75
  res += a;
  // 24 * 3
  res += b * (e - 1);
  res += c * (d - 1);
  res += (d * (d - 1) * (e - 2)) / 2;

  cout << res << endl;
}


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

using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, K;
    cin >> N >> K;
    long long h[N];
    for (int i = 0; i < N; ++i) {
        cin >> h[i];
    }
    
    sort(h, h + N);
    
    long long res = 1LL << 30;
    
    for (int i = 0; i < (N - K + 1); ++i) {
        res = min(res, h[i+K-1]-h[i]);
    }
    
    cout << res << endl;
    
    
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int M = sc.nextInt();
            int[] A = new int[M];
            for (int i = 0; i < A.length; i++) {
                A[i] = sc.nextInt();
            }

            int rest = N;
            for (int i = 0; i < A.length; i++) {
                rest -= A[i];
            }
            System.out.println(rest < 0 ? -1 : rest);
        }
    }
}


Measured memory_bytes: 38056
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int ans = 0;
  cin >> s;
  string t = "CODEFESTIVAL2016";
  for(int i=0;i<16;i++){
    if(s.at(i)!=t.at(i)){
      ans++;
    }
  }
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

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

  string res;

  for (int i = 0; i < 3; ++i) {
    string s; cin >> s;
    res += toupper(s[0]);
  }
  cout << res << "\n";
}


Measured memory_bytes: 3628
// 2020-08-22 21:04:38
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll cur = 0, ans = 0;
  rep(i, n) {
    if(cur > a[i]) ans += cur - a[i];
    else cur = a[i];
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	vector<int> a(3);
	rep(i,3)cin>>a[i];
	cout<<(accumulate(all(a),0)>=22?"bust":"win")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int n;
  scanf("%d", &n);
  vector<float> v(n);

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

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

  for(int i=0;i<n-1;i++){
    float result = (v[0] + v[1]) / 2;
    v[0] = result;
    v[1] = 10000;
    sort(v.begin(),v.end());
  }

  cout << v[0];

  return 0;
}

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

ll n,w,c[105],v[105],dp[100005];
int main()
{
	cin >> n >> w;
	for(int i=1; i<=n; i++) cin >> c[i] >> v[i];
	for(int i=1; i<=n; i++){
		for(int j=w; j>=c[i]; j--) dp[j]=max(dp[j],dp[j-c[i]]+v[i]);
	}
	cout << dp[w];
}

Measured memory_bytes: 4404
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
const int Maxn = 2010;
struct node {
	int y, next;
}a[Maxn<<1]; int first[Maxn], len;
void ins(int x, int y) {
	a[len].y = y;
	a[len].next = first[x]; first[x] = len;
	len++;
}
int _min(int x, int y) { return x < y ? x : y; }
int n, m;
int u[Maxn], v[Maxn];
int sum[Maxn];
bool used[Maxn], vis[Maxn<<1];
vector <int> pat[Maxn], vec[Maxn];
bool dfs(int x, int fa, int t, int p) {
	if(x == t) return true;
	for(int k = first[x]; k != -1; k = a[k].next){
		int y = a[k].y;
		if(y == fa) continue;
		if(dfs(y, x, t, p) == true){
			pat[p].push_back(k^1);
			sum[k>>1]++;
			vec[k>>1].push_back(p);
			return true;
		}
	}
	return false;
}
int main() {
	int i, j, k;
	scanf("%d%d", &n, &m);
	for(i = 1; i <= n; i++) first[i] = -1;
	for(i = 1; i < n; i++){
		int x, y;
		scanf("%d%d", &x, &y);
		ins(x, y); ins(y, x);
	}
	for(i = 1; i <= m; i++){
		scanf("%d%d", &u[i], &v[i]);
		dfs(v[i], 0, u[i], i);
	}
	int ans = 0;
	for(i = 0; i < n-1; i++) ans += _min(sum[i], 2);
	while(1){
		int id = -1;
		for(i = 0; i < n-1; i++){
			if(sum[i] == 1 && (vis[i<<1]^vis[i<<1|1]) == 1){ id = vis[i<<1] == 1 ? i<<1|1 : i<<1; break; }
		}
		if(id == -1){
			for(i = 0; i < n-1; i++) if(sum[i] > 0){ id = i<<1; break; }
			if(id == -1) break;
		}
		int p = id>>1;
		while(used[vec[p].back()]) vec[p].pop_back();
		int t = vec[p].back();
		used[vec[p].back()] = true;
		vec[p].pop_back();
		bool rev = false;
		for(i = 0; i < pat[t].size(); i++){
			if((pat[t][i]^id) == 1){ rev = true; break; }
		}
		if(rev == true){
			for(i = 0; i < pat[t].size(); i++) pat[t][i] ^= 1;
			swap(u[t], v[t]);
		}
		for(i = 0; i < pat[t].size(); i++) sum[pat[t][i]>>1]--, vis[pat[t][i]] = true;
	}
	printf("%d\n", ans);
	for(i = 1; i <= m; i++) printf("%d %d\n", u[i], v[i]);
	return 0;
}

Measured memory_bytes: 13824
#[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, usize1) => {
        read_value!($next, usize) - 1
    };

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

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

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      a: usize,
      mut xs: [usize; n],
    }
    xs.sort();
    const U: usize = 50*50;
    let mut dp = vec![vec![0u64; U+1]; 2];
    let mut flag = 0;
    let mut ans = 0;
    dp[flag][a] = 1;
    for i in 0..n {
        let x = xs[i];
        ans += dp[flag][x];

        for rem in 0..U {
            dp[1-flag][rem] = dp[flag][rem];
        }
        for rem in 0..U {
            let nx = rem as i64 - x as i64 + a as i64;
            if nx >= 0 && nx <= U as i64 {
                let nx = nx as usize;
                dp[1-flag][nx] += dp[flag][rem];
            }
        }
        flag = 1 - flag;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
struct UnionFind
{
	vector<int> par;
	vector<int> sizes;
	UnionFind(int N):par(N),sizes(N,1)
	{
		for(int i=0;i<N;i++)
		{
			par[i]=i;
		}
	}
	int root(int x)
	{
		if(par[x]==x)
		{
			return x;
		}
		else
		{
			return par[x]=root(par[x]);
		}
	}
	int size(int x)
	{
		return sizes[root(x)];
	}
	void unite(int x,int y)
	{
		int rx=root(x);
		int ry=root(y);
		if(rx==ry)
		{
			return;
		}
		par[ry]=rx;
		sizes[rx] += sizes[ry];
	}
	bool same(int x,int y)
	{
		int rx=root(x);
		int ry=root(y);
		return rx==ry;
	}
};
 
int main()
{
    long long N,M;
    cin >> N >> M;
    vector<pair<int,int>> AB(M);
    for(int i=0;i<M;i++)
    {
        int a,b;
        cin >> a >> b;
        AB[i].first=a-1;
        AB[i].second=b-1;
    }
    vector<long long> ans(M);
    UnionFind uf(N);
    ans[M-1]=N*(N-1)/2;
    for(int i=M-1;i>0;i--)
    {
        if(uf.same(AB[i].first,AB[i].second))
        {
            ans[i-1]=ans[i];
        }
        else
        {
            long long asize =(long long)uf.size(AB[i].first);
            long long bsize =(long long)uf.size(AB[i].second);
            uf.unite(AB[i].first,AB[i].second);
            ans[i-1]=ans[i]-asize*bsize;
        }
    }
 
    for(int i=0;i<M;i++)
    {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
void Yes() {
    cout << "Yes" << endl;
}
void No() {
    cout << "No" << endl;
}
int main(void) {
    string s; cin >> s;
    int n = s.size();
    if (s[n-1] == 's') s+= "es";
    else s+="s";
    cout << s << endl;
}


Measured memory_bytes: 3596
#include<stdio.h>
int main(void)
{
	int H,W,i,j;
	
	
	do{
		
		scanf("%d %d",&H,&W);
		if(H==0&&W==0){
			break;
		}
			for(i=0;i<H;i++){
				for(j=0;j<W;j++){
			printf("#");
					}
				printf("\n");
			}
		
		printf("\n");
		}while(H!=0||W!=0);
	return 0;
}

Measured memory_bytes: 572
N = int(input())
HS = list(map(int, input().split()))

if N == 1:
    print(0)
    exit()

c = 0
max_c = 0
for i in range(N - 1):
    if HS[i] >= HS[i + 1]:
        c += 1
        max_c = max(max_c, c)
    else:
        c = 0

print(max_c)


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

int main() {
  int i=0,j,g,a;
  int N;
  int answer=0;

  cin >> N ;

  int *d = new int[N];

  for ( i = 0; i < N; i++)
  {
      cin >> d[i];
  }

  for ( i = 0; i < N; i++)
  {
      for ( j = i+1; j < N; j++)
      {
          answer+=d[i]*d[j];
      }
      
  }
  
  

  cout << answer <<endl;
  
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    int n, v[212345], ans;
    cin >> n;

    bool h = true;
    REP(i, n)
    {
        cin >> v[i];
        if (i > 0)
        {
            if (v[i] != v[i - 1])
                h = false;
        }
    }

    if (h)
    {
        cout << n / 2 << endl;
        return 0;
    }

    M mp;
    V a, b;

    ans = 0;

    for (int i = 0; i < n; i += 2)
    {
        if (mp[v[i]] == 0)
            a.push_back(v[i]);
        mp[v[i]]++;
    }

    int ma = 0;
    int mai;

    REP(i, a.size())
    {
        b.push_back(mp[a[i]]);
        ma = max(ma, mp[a[i]]);
        if (ma == mp[a[i]])
            mai = i;
    }

    SORT(b);

    M mp1;
    V a1, b1;

    for (int i = 1; i < n; i += 2)
    {
        if (mp1[v[i]] == 0)
            a1.push_back(v[i]);
        mp1[v[i]]++;
    }

    int ma1 = 0;
    int mai1;

    REP(i, a1.size())
    {
        b1.push_back(mp1[a1[i]]);
        ma1 = max(ma1, mp1[a1[i]]);
        if (ma1 == mp1[a1[i]])
            mai1 = i;
    }

    SORT(b1);

    //cout << ma << " " << ma1 << endl;

    if (a[mai] != a1[mai1])
    {
        ans = n - ma - ma1;
    }
    else
    {
        //cout << 1 << endl;
        int tmp;

        tmp = max(b1[b1.size() - 2] + b[b.size() - 1], b1[b1.size() - 1] + b[b.size() - 2]);

        ans = n - tmp;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6396