akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	read(n);
	int a[n + 1], b[n + 1];
	FOR (i, 1, n) cin >> a[i] >> b[i];
	sort(a + 1, a + n + 1);
	sort(b + 1, b + n + 1);
	
	int x, y;
	if (n % 2 == 0) x = a[n/2 + 1] + a[n/2], y = b[n/2 + 1] + b[n/2];
	else x = a[n/2 + 1], y = b[n/2 + 1];
	
	cout << abs(x - y) + 1;
}



















Measured memory_bytes: 6744
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
/* -- template -- */

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int cntL = 0, cntR = 0;
    rep(i, N) {
        if(S[i] == ')') {
            if(cntR > 0)
                --cntR;
            else
                ++cntL;
        }else if(S[i]== '(') {
            ++cntR;
        }
    }
    rep(i, cntL) {
        S = '(' + S;
    }
    rep(i, cntR) {
        S = S + ')';
    }
    cout << S << endl;
}


Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 3/ 6
// Problem:ABC 080 HarshadNumber b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

int harshad(int n, int sum)
{
  if (n < 10) return n;
  return harshad(n / 10, sum + n % 10);
}

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

  string N;
  cin >> N;

  int harshad = 0;
  int n = atoi(N.c_str());
  bool ok = false;
  REP(i, N.size()) {
    harshad += N[i] - '0';
  }
  
  if (n % harshad == 0) ok = true;

  cout << (ok ? "Yes" : "No") << endl;
  
  return 0;
}



Measured memory_bytes: 256
from collections import defaultdict
import math
mod = 1000000007

pos = defaultdict(int)
neg = defaultdict(int)
zero = 0

n = int(input())
for _ in range(n):
	a, b = list(map(int, input().split()))
	if a == b == 0:
		zero += 1
	elif a == 0:
		pos[(0, 1)] += 1
	elif b == 0:
		neg[(0, 1)] += 1
	else:
		c = a * b
		g = math.gcd(a, b)
		a, b = abs(a // g), abs(b // g)
		if c > 0:
			pos[(a, b)] += 1
		elif c < 0:
			neg[(b, a)] += 1

cnt = 1
for x in pos.keys():
	if x in neg.keys():
		cnt = (cnt * (pow(2, pos[x], mod) + pow(2, neg[x], mod) - 1)) % mod
		del neg[x]
	else:
		cnt = (cnt * pow(2, pos[x], mod)) % mod

for x in neg.keys():
	cnt = (cnt * pow(2, neg[x], mod)) % mod

print((zero + cnt - 1) % mod)

Measured memory_bytes: 44896
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	ll n;
	cin >> n;
	vector<ll> v_;
	rep(i, 0, n) {
		ll a;
		cin >> a;
		v_.pb(a);
	}
	vector<ll> v;
	v = v_;
	ll ans1 = 0;
	{
		ll tot = 0;
		rep(i, 0, n) {
			ll b = v[i];
			if (i % 2 == 1) {
				if (tot + b >= 0) {
					ll c = -1 - tot;
					ans1 += abs(b - c);
					v[i] = c;
				}
			}
			else {
				if (tot + b <= 0) {
					ll c = 1 - tot;
					ans1 += abs(b - c);
					v[i] = c;
				}
			}
			tot += v[i];
		}
	}
	v = v_;
	ll ans2 = 0;
	{
		ll tot = 0;
		rep(i, 0, n) {
			ll b = v[i];
			if (i % 2 == 0) {
				if (tot + b >= 0) {
					ll c = -1 - tot;
					ans2 += abs(b - c);
					v[i] = c;
				}
			}
			else {
				if (tot + b <= 0) {
					ll c = 1 - tot;
					ans2 += abs(b - c);
					v[i] = c;
				}
			}
			tot += v[i];
		}
	}
	printf("%lld\n", min(ans1,ans2));
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 10;
vector<vector<int > > graph;
const int M = 15;
pii color[N][M];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, m, q;
    cin >> n >> m;
    graph.resize(n);
    for (int i = 0; i < N; i++)
        for (int j = 0; j < M; j++)
            color[i][j] = pii(-1, 0);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
        int v, d, c;
        cin >> v >> d >> c;
        v--;
        color[v][d] = pii(i, c);
    }
    for (int i = 10; i >= 1; i--) {
        for (int v = 0; v < n; v++) {
            for (int u : graph[v]) {
                if (color[v][i].first > color[u][i - 1].first) {
                    color[u][i - 1] = color[v][i];
                }
            }
            if (color[v][i].first > color[v][i - 1].first) {
                color[v][i - 1] = color[v][i];
            }
        }
    }
    for (int i = 0; i < n; i++)
        cout << color[i][0].second << "\n";
    return 0;
}


Measured memory_bytes: 18168
#include <iostream>
#include <vector>
#include <algorithm>
//#include "../cxx-prettyprint/prettyprint.hpp"

int main() {
    std::string s;
    int K;
    std::cin >> s;
    std::cin >> K;

    std::vector<std::string> substrings;
    for (int length = 1; length <= std::min(K, (int)s.length()); length ++) {
        for (int i = 0; i <= s.length() - length; i++) {
            substrings.push_back(s.substr(i, length));
        }
    }
    std::sort(substrings.begin(), substrings.end());
    std::unique(substrings.begin(), substrings.end());
    std::cout << substrings[K - 1] << std::endl;
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
#define M 200005
#define P 998244353
#define ll long long
struct hh{
	int x,y;
	bool operator<(hh a)const{
		return x<a.x;
	}
}sk[M];
int a[M],b[M],pw[M],mx1[M],mx2[M],sum[M],n,mx3[M],mx4[M];
int query(int x){
	int ans=0;
	for(;x;x-=x&-x)ans+=sum[x];
	return ans;
}
void update(int x,int w){
	for(;x<=n;x+=x&-x)sum[x]+=w;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d%d",&sk[i].x,&sk[i].y);
		a[i]=sk[i].x;b[i]=sk[i].y;
	}sort(a+1,a+n+1);sort(b+1,b+n+1);
	for(int i=1;i<=n;++i)sk[i].x=lower_bound(a+1,a+n+1,sk[i].x)-a;
	for(int i=1;i<=n;++i)sk[i].y=lower_bound(b+1,b+n+1,sk[i].y)-b;
	sort(sk+1,sk+n+1);
	for(int i=1;i<=n;++i){
		mx1[i]=query(sk[i].y);
		mx2[i]=i-1-mx1[i];
		update(sk[i].y,1);
	}
	memset(sum,0,sizeof(sum));
	for(int i=n;i>=1;--i){
		mx3[i]=query(sk[i].y);
		mx4[i]=n-i-mx3[i];
		update(sk[i].y,1);
	}
	pw[0]=1;
	for(int i=1;i<=n;++i)pw[i]=pw[i-1]*2%P;
	ll ans=0;
	for(int i=1;i<=n;++i){
		ans+=pw[n];
		ans-=pw[sk[i].y-1];
		ans-=pw[n-sk[i].y];
		ans-=pw[sk[i].x-1];
		ans-=pw[n-sk[i].x];
		ans+=pw[mx1[i]];
		ans+=pw[mx2[i]];
		ans+=pw[mx3[i]];
		ans+=pw[mx4[i]];
		ans%=P;
	}ans=(ans-n+2*P)%P;
	printf("%lld",ans);
}

Measured memory_bytes: 8064
def nck(n):
    ret = 1
    for i in range(2):
        ret *= (n - i)
    return ret//2

N = int(input())
S = {}
for i in range(N):
    s = str(sorted(input()))
    if s not in S.keys():
        S[s] = 0
    S[s] += 1
ans = 0
for key in S.keys():
    if S[key] > 1:
        ans += nck(S[key])
print(ans)


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

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            var left = s.IndexOf('A');
            var right = s.LastIndexOf('Z');

            Console.WriteLine(right - left+1);


        }
    }
}


Measured memory_bytes: 11616
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define AB_BHI_NI_DEGI ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define N 500009
#define inf 1e18
//int mod=1e9+7;
int mod=998244353;
#define P pair<int,int>
#define F first
#define S second
#define ll long long
#define all(v) v.begin(),v.end()

#define ordered_set tree<P, null_type,less<P>, rb_tree_tag,tree_order_statistics_node_update> 

void end(int n=-1){
	cout<<n<<"\n";exit(0);
}
int n;
int a[N];
int dp[N];
int fun(int i){
	if(i>=n)return 0;
	if(dp[i]!=-1)return dp[i];
	int ans=inf;
	int f=0;
	if(i+1<n){
		ans=min(ans,abs(a[i+1]-a[i])+fun(i+1));
		f=1;
	}
	if(i+2<n){
		ans=min(ans,abs(a[i]-a[i+2])+fun(i+2));
		f=1;
	}
	if(!f)ans=0;
	return dp[i]=ans;
}

int32_t main(){
    AB_BHI_NI_DEGI
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	memset(dp,-1,sizeof(dp));
	cout<<fun(0)<<"\n";
    return 0;
}

Measured memory_bytes: 14452
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long LL;

int main(){
    int a,b;
    cin>>a>>b;
    if(b%a==0){
        cout<<a+b<<endl;
    }else{
        cout<<b-a<<endl;
    }
}


Measured memory_bytes: 256
/* ex2_3
    nnasy   */

#include <stdio.h>

int main(void) {
    int length_N, white;

    //入力の受け取り（N, A）
    scanf("%d%d", &length_N, &white);

    //黒色のマスの個数(N*N-A)の出力
    printf("%d\n", length_N*length_N-white);
  
	return 0;
}


Measured memory_bytes: 128
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,m;
	cin >> n >> m;
	ll a[n];
	rep(i,0,n){
		cin >>a[i];
	}
	sort(a,a+n);
	vector<pii> v;
	rep(i,0,m){
		ll x,y;
		cin >> x >> y;
		x--;
		v.push_back({y,x});
	}
	sort(all(v));
	reverse(all(v));
	ll k=0;
	rep(i,0,m){
		ll x=v[i].first;
		ll y=v[i].second;
		while(y>=0 && k<n){
			a[k]=max(a[k],x);
			k++;
			y--;
		}
	}
	ll ans=0;
	rep(i,0,n){
		ans+=a[i];
	}
	cout << ans;
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe


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

double n,a[110]={},sum = 0,ssum = 1,ans;

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


rep(i,n){
    sum += 1/a[i]; 
}
/*rep(i,n){
    ssum = ssum * a[i];
}
*/

ans = 1/sum;

cout << ans << endl;

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

long long int L,R;

int main()
{
	scanf("%lld%lld",&L,&R);
	if(R-L>=2019)
	    printf("0\n");
	else
	{
		L=L%2019;
		R=R%2019;
		if(L>=R)
		    printf("0\n");
		else
		{
			int ans=2019;
			for(int i=L;i<=R;i++)
			{
				for(int j=i+1;j<=R;j++)
				{
					ans=min(ans,i*j%2019);
				}
			}
		    printf("%d\n",ans);
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define N 200000
bool sx[N+1], xe[N+1];
int n, m, a, b;
int main() {
    cin >> n >> m;
    REP(i, m) {
        cin >> a >> b;
        if (a == 1) {
            sx[b] = true;
        } else if (b == n) {
            xe[a] = true;
        }
    }
    string ans = "IMPOSSIBLE";
    REP(i, n) {
        if (sx[i] && xe[i]) {
            ans = "POSSIBLE";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

int main(void) {
    int N, K;
    cin >> N >> K;
    vector<int> x(N), y(N);
    for(int i=0; i<N; i++) {
        cin >> x[i] >> y[i];
    }

    int64_t ans = INT64_MAX;
    for(int i=0; i<N; i++) {
        for(int j=0; j<N; j++) {
            for(int k=0; k<N; k++) {
                for(int l=0; l<N; l++) {
                    int64_t x_min = x[i];
                    int64_t x_max = x[j];
                    int64_t y_min = y[k];
                    int64_t y_max = y[l];
                    int cnt = 0;
                    for(int m=0; m<N; m++) {
                        if(x_min <= x[m] && x[m] <= x_max && y_min <= y[m] && y[m] <= y_max) {
                            cnt++;
                        }
                    }
                    if(cnt == K) {
                        ans = min(ans, (x_max-x_min)*(y_max-y_min));
                    }
                }
            }
        }
    }

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


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

int dfs(int p, int q)
{
    if (p > q)
    {
        return 0;
    }
    if (dp[p][q] != -1)
    {
        return dp[p][q];
    }
    dp[p][q] = dfs(p, q - 1) + dfs(p + 1, q) - dfs(p + 1, q - 1) + v[p][q];
    return dp[p][q];
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m, q;
    cin >> n >> m >> q;
    memset(dp, -1, sizeof dp);
    rep(i, m)
    {
        int x, y;
        cin >> x >> y;
        v[x][y]++;
    }
    rep(i, q)
    {
        int p, q;
        cin >> p >> q;
        cout << dfs(p, q) << endl;
    }
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;
typedef long long LL;

const int maxn = 200005;
int c[maxn], p[maxn], n, cnt, t;
vector<int> pos[26];
char s[maxn];
LL ans;

#define lowbit(x) ((x)&(-(x)))
void update(int x) {
	for (; x<=n; x+=lowbit(x)) c[x]++;
}

int query(int x) {
	int res = 0;
	for (; x; x-=lowbit(x)) res += c[x];
	return res;
}

int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	rep (i, 1, n)
		pos[s[i]-'a'].push_back(i);
	rep (i, 0, 25) {
		int m = pos[i].size(), a = 0, b = m - 1;
		cnt += (m & 1);
		if (cnt >= 2) return puts("-1"), 0;
		while (a <= b) {
			p[pos[i][a]] = pos[i][b];
			a++; b--;
		}
	}
	rep (i, 1, n) if (p[i] && p[i] != i) {
		ans += query(p[i]) + query(i);
		update(p[i]);
	}
	else if (p[i] == i) t = i;
	if (n & 1) {
		rep (i, 1, n) if (p[i])
			if (i < t && p[i] < t || i > t && p[i] > t)
				ans++;
	}
	cout << ans << endl;
	
	return 0;
}

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

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

	return 0;
}

Measured memory_bytes: 3072
#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 < (int)(x); i++)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;


int main(){
    ll a,b,k; cin >> a >> b >> k;
    ll temp = 0;
    ll res;
    for(int i = 100;0 < i;i--){
        if(!i)continue;
        if(a%i == 0 && b%i == 0){
            temp++;
            if(temp == k){
                res = i;
                break;
            }
        }
        
    }
    cout << res << endl;
}

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

int n,K,ans;
char s[105];
int f[105];

int main(){

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

    cin>>s+1;
    cin>>K;
    n=strlen(s+1);
    for(int i=1;i<=n;i++){
        f[i]=(s[i]!='0')+f[i-1];
    }
    if(K==3){
        for(int i=1;i<n;i++){
            for(int j=i+1;j<n;j++){
                for(int k=j+1;k<=n;k++){
                    if(f[i-1]){
                        ans+=729;
                    }else if(f[j-1]-f[i]>0){
                        if(s[i]>'0')ans+=(s[i]-'0')*81;
                    }else if(f[k-1]-f[j]>0){
                        if(s[i]>'1')ans+=(s[i]-'1')*81;
                        if(s[i]>'0')ans+=(s[j]-'0')*9;
                    }else{
                        //num i == s i
                        //num j == s j
                        if(s[i]>'0'&&s[j]>'0')ans+=s[k]-'0';
                        //num j < s j
                        if(s[i]>'0'&&s[j]>'1')ans+=(s[j]-'1')*9;
                        //num i < s i
                        if(s[i]>'1')ans+=(s[i]-'1')*81;
                    }
                }
            }
        }
    }
    if(K==2){
        for(int i=1;i<n;i++){
            for(int j=i+1;j<=n;j++){
                if(f[i-1]){
                    ans+=81;
                }else if(f[j-1]-f[i]>0){
                    ans+=(s[i]-'0')*9;
                }else{
                    if(s[i]>'1')ans+=(s[i]-'1')*9;
                    if(s[i]>'0')ans+=s[j]-'0';
                }
            }
        }
    }
    if(K==1){
        for(int i=1;i<=n;i++){
            if(f[i-1]){
                ans+=9;
            }else{
                ans+=s[i]-'0';
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{
    string a,b;
    int n,m;
    cin >> n >> m;
    for(int i=1;i<=n;i++) b+=(char)(m+48);
    for(int i=1;i<=m;i++) a+=(char)(n+48);
    if(a>b)
        cout << b;
    else cout << a;
    return 0;
}


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

#define int long long
#define ll unsigned long long
#define pb push_back
#define mp make_pair
#define veci vector<int>
#define pii pair<int,int>
#define reset(a, b) memset(a, b, sizeof(a))
#define rep(i,b) for(int i=0; i<b; i++)
#define repi(i,a,b) for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define fi first 
#define se second
#define all(v) v.begin(),v.end()

int mod=1e9+7;

int powerm(int x,int y, int M){ int res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
int  power(int x,int y){ int res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
bool isprime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; }
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int T;
    T=1;
//    cin>>T;
while(T--){
    int n;
    cin>>n;
    cout<<(n+n*n+n*n*n)<<endl;
}
    
    return 0;
}

Measured memory_bytes: 3612
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    x = 800*N
    y = N//15*200
    print(x-y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9136
#include <iostream>
#include <sstream>
#include <stdio.h>
//#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;

int main(void)
{
	string N; cin >> N;
	if (N[0] == '7' || N[1] == '7' || N[2] == '7')cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,i,j,k,n,m,x,y,z,t;
    double a1,a2;
    cin>>n;
    string s;
    cin>>s;
    if(n%2==1)
    {
        cout<<"No"<<endl;
    }
    else
    {
        for(i=0;i<n/2;i++)
        {
            if(s[i]!=s[(n/2)+i])
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout<<"Yes"<<endl;
    }
}


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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;
typedef std::queue<long> QI;
#define rep(i,n) for(long i = 0; i < (long)n; ++i)
const double pi = M_PI;
const long mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      long x; scan(x);
      while( x-(x&-x) != 0 ) x = x - (x&-x);
      printf("%ld\n", x);
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

string str, str2;
int mp[100];
bool ok(string s){
	next_permutation(all(s));
	cout << s << endl;
}

signed main(){
	rep(i,'z'-'a'+1)str2.push_back((char)('z'-i));
	cin >> str;
	int n = str.size();
	
	rep(i,n){
		mp[str[i]-'a']++;
	}
	rep(i,'z'-'a'+1){
		if(mp[i] == 0){
			cout << str << (char)(i+'a') << endl;
			return 0;
		}
	}
	
	/*int f = 0;
	rep(i,n){
		if(str[i] != str2[i])f = 1;
	}
	if(f == 0){
		cout << -1 << endl;
		return 0;
	}*/
	
	drep(i,n-1,0){
		char c = str[i];
		repi(j,c-'a','z'-'a'+1){
			if(mp[j] == 0){
				cout << str.substr(0, i) << (char)('a'+j) << endl;
				return 0;
			}
		}
		mp[c-'a'] = 0;
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,mmm,a[100000];
int main(){
    scanf("%d",&n);
    for (int i=1;i<=2*n;i++){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+2*n);
    for (int i=1;i<=2*n;i+=2){
        mmm+=min(a[i],a[i+1]);
    }
    cout<<mmm;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N;
  cin >> N;
  
  vector<char>arare(N);
  
  for(int i=0;i<N;i++){
    cin >> arare[i];
  }
  
  int ans = 0;
  
  for(int i=0;i<N;i++){
    if(arare[i] == 'Y')
      ans++;
  }
  
  if(ans == 0)
    cout << "Three" << endl;
  else
    cout << "Four" << endl;
  
  return 0;
}


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

x = int(total/10000)
y = int(total/5000)
 
arr = []
for i in range(x+1):
    for j in range(y+1):
        if (9000*i + 4000*j == total - 1000*N) and (N-i-j >= 0):
            arr.append([i,j,N-i-j])
 
if len(arr) == 0:
    print('-1 -1 -1')
else:
    print(arr[0][0], arr[0][1], arr[0][2])

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

long long int mod=1000000007;


long long int n,w,wei[205],v[205],res[4][105]={},fin=0;
int main() {
    const long long int INF=99999999999999;
	map<long long int, long long int>mp;
    
    priority_queue<long long int>pq[4];
    priority_queue<long long int>tmp[4];
	cout << fixed << setprecision(10);
    cin>>n>>w;
    for(int i=1;i<=n;i++){
        cin>>wei[i]>>v[i];
        pq[wei[i]-wei[1]].push(v[i]);

    }
    tmp[0]=pq[0];
    tmp[1]=pq[1];
    tmp[2]=pq[2];
    tmp[3]=pq[3];

    for(int i=0;i<4;i++){
        for(int j=1;j<=pq[i].size();j++){
            res[i][j]=res[i][j-1]+tmp[i].top();
            tmp[i].pop();
        }
    }




    for(int i=0;i<=pq[0].size();i++){
        for(int j=0;j<=pq[1].size();j++){
            for(int k=0;k<=pq[2].size();k++){
                for(int l=0;l<=pq[3].size();l++){
                    if((i+j+l+k)*wei[1]+j+2*k+3*l<=w){
                        fin=max(res[0][i]+res[1][j]+res[2][k]+res[3][l],fin);
                    }
                }
            }
        }
    }
    cout<<fin<<endl;
} 


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	int i, j, n, len, num = 0;
	char search[11], str[21];
	
	scanf("%s", search);
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%s", str);
		
		len = strlen(str);
		strcat(str, str);
		
		for (j = 0; j < len; j++){
			if (strncmp(&str[j], search, strlen(search)) == 0){
				num++;
				break;
			}
		}
	}
	
	printf("%d\n", num);
	
	return (0);
}

Measured memory_bytes: 620
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

    for (int x = 0; x <= M; ++x) {
        for (int y = 0; y <= N; ++y) {
            int c = x*N + y*M - 2*y*x;
            if (c == K) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::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 trace(...) 
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod =1e9+7;
const int maxn = 100005;
#define endl '\n'
#define ld long double
#define int ll
#define all(x) (x).begin(),(x).end()

int32_t main()
{ 
   IOS
  
   int n;
   cin >> n;
   string s;
   cin >> s;
   int p[n+1] = {0};
   for(int i = 0;i<n;i++){
     p[i+1] = p[i] + (s[i] == 'R');
   }
    int ans = 1e15;
   for(int i = 0;i<=n;i++){
     int rleft = p[i];
     int wleft = i - p[i];
     int rright = p[n] - p[i];
     int wright = n-i-rright;
     int swaps = min(wleft,rright);
     ans = min(ans, wleft + rright - swaps);
   }
   cout << ans << endl;
    


  
  

 
}

Measured memory_bytes: 5360
#!usr/bim/python
#! -*- coding: utf-8 -*-

abcd = raw_input()
abcd = abcd.split()
a,b,c,d = map(int,abcd)

l = a+b
r = c+d

if l > r:
    ans = "Left"
elif l < r:
    ans = "Right"
else:
    ans = "Balanced"

print ans


Measured memory_bytes: 2568
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

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

ll func(int n,vector<ll> x){
  int front=0,back=n-1;
  deque<ll> res;
  bool is_front = false;
  int cnt = 0;
  res.push_front(x[0]);
  front++;
  while(front<=back){
    if(is_front){
      if(cnt == 0){
        res.push_front(x[front]);
        cnt++;
        front++;
      }else if(cnt == 1){
        res.push_back(x[front]);
        front++;
        is_front = false;
        cnt = 0;
      }
    }else{
      if(cnt == 0){
        res.push_front(x[back]);
        cnt++;
        back--;
      }else if(cnt == 1){
        res.push_back(x[back]);
        back--;
        is_front = true;
        cnt = 0;
      }
    }
  }
  vector<ll> ress;
  ll ans = 0;
  for(auto itr = res.begin(); itr != res.end(); ++itr){
    ress.push_back(*itr);
  }
  for(int i = 1; i < n; i++){
    ans += abs(ress[i]-ress[i-1]);
  }

  return ans;
}

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

  sort(all(a));
  ll x = func(n,a);
  reverse(all(a));
  ll y = func(n,a);
  cout << max(x,y) << endl;


  return 0;
}

Measured memory_bytes: 4440
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s= sc.next();
		int count =0;
		for (int i=0;i<s.length();i++) {
			if (s.charAt(i)=='1') {
				count ++;
			}
		}
		System.out.println(count);

	}
}

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

static const int LEN = 100005;

struct P {
	string name;
	int t;
};

P Q[LEN];
int head, tail;

void enqueue(P X) {
	Q[tail] = X;
	tail = (tail + 1) % LEN;
} 

P dequeue() {
	P X = Q[head];
	head = (head + 1) % LEN;
	return X;
}

int min(int a, int b) {
	return a < b ? a : b;
}


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

	for (int i = 1; i <= n; i++) {
		cin >> Q[i].name;
		cin >> Q[i].t;
	}
	head = 1;
	tail = n + 1;
	int elaps = 0;

	while(head != tail) {
		P a;
		int c;
		a = dequeue();
		c = min(q, a.t);
		a.t -= c;
		elaps += c;
		if (a.t > 0) enqueue(a);
		else cout << a.name << " " << elaps << endl;
	}
	return 0;
}
	

Measured memory_bytes: 5112
#include <bits/stdc++.h>
#include <iostream>
#include <string>

using namespace std;

const long long int INF = 1 << 17;
const long long int MAX = 1000000007;
const long long int MOD = 1000000007;


long long int multi1(long long int n,long long int a){
  long long int res = 1;
  for(long long int i=n;i>=n-a+1;i--){
    res *= i;
    res %= MOD;
  }
  
  return res;
}

long long int multi2(long long int n){
  long long int res = 1;
  for(long long int i=1;i<=n;i++){
    res *= i;
    res %= MOD;
  }
  
  return res;
}

long long int RepeatSquaring(long long int N, long long int P, long long int M){
  long long int res = 1;
    while(P>0){
        if(P & 1) res = res * N % M;
        N = N * N % M;
        P >>= 1;
    }
    return res;
}
 




int main(){
  long long int n , a , b ;
  
  cin >> n >> a >> b;
  
  long long int ma = multi2(a);
  long long int mb = multi2(b);
  long long int nota = (multi1(n,a)*RepeatSquaring(ma,MOD-2,MOD))%MOD;
  long long int notb = (multi1(n,b)*RepeatSquaring(mb,MOD-2,MOD))%MOD;
  
  cout << (RepeatSquaring(2,n,MOD) - (nota+notb)%MOD -1 + 2*MOD)%MOD  << endl;
  
}

  
  


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int MOD = 1000000007;

long long mul(long long &a, long long b) {
    a *= b;
    if (a >= MOD) a %= MOD;
}

int main() {
    long long N, M; cin >> N >> M;
    if (abs(N - M) > 1) { 
        cout << 0 << endl;
        return 0;
    }
    long long ans = 1;
    for (int i = 1; i <= N; i++) mul(ans, i);
    for (int i = 1; i <= M; i++) mul(ans, i);
    if (N == M) mul(ans, 2);
    cout << ans << endl;
}

Measured memory_bytes: 256
// <head>
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
// </head>

// <library>
    template<typename T>
    struct BIT {
    int n;
    vector<T> d;
    BIT(int n=0):n(n),d(n+1) {}
    void add(int i, T x=1) {
        for (i++; i <= n; i += i&-i) {
        d[i] += x;
        }
    }
    T sum(int i) {
        T x = 0;
        for (i++; i; i -= i&-i) {
        x += d[i];
        }
        return x;
    }
    T sum(int l, int r) {
        return sum(r-1) - sum(l-1);
    }
    };
// </library>
const int MX = 200005;
int in[MX], out[MX], k;
vector<int> to[MX];
void dfs(int v, int p=-1){
    in[v] = k++;
    for (int u: to[v]){
        if (u==p) continue;
        dfs(u,v);
    }
    out[v] = k;
}
    vector<ll> vs[MX];
ll f(ll n){
    return n*(n+1)/2;
}
int main(){
    int n; cin >> n;
    vector<ll> c(n);

    for (int i = 0; i < n; i++){
        cin >> c[i];
        vs[c[i]-1].emplace_back(i);
        
    }
    for (int i = 0; i < n-1; i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        to[a].emplace_back(b);
        to[b].emplace_back(a);
    }
    dfs(0);
    ll tot=f(n);
    BIT<int> d(n);
    for (int i = 0; i < n; i++){
        d.add(i,1);
    }
    for (int i = 0; i < n; i++){
        ll ans = tot;
        vector<ll> nvs = vs[i];
        sort(nvs.begin(), nvs.end(), [&](int a, int b){
            return in[a] > in[b];
        });
        vector<pair<ll, ll>> history;
        for (auto j: nvs){
            ll cnt = 1;      
            for(auto k: to[j]){
                if(in[j]>in[k])continue;
                ll num = d.sum(in[k],out[k]);
                ans -= f(num);
                cnt += num;
            }
            d.add(in[j],-cnt);
            history.emplace_back(make_pair(in[j],cnt));
        }
        ans -= f(d.sum(0,n));
        cout << ans << '\n';
        for (auto p:history){
            d.add(p.first,p.second);
        }
    }
    
}

Measured memory_bytes: 37284
#include <bits/stdc++.h>
using namespace std;
int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long n,m,a,s;
    s=0;
    cin >> n >> m;
    while(m--)
    {
        cin >> a;
        s=s+a;
    }
    if(s>n)
    {
        cout << -1 <<endl;
    }
    else
    {
        cout << n-s << endl;
    }
    return 0;
}

Measured memory_bytes: 3652
import java.math.*;
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] rate = new int[n][2];
        for (int i = 0; i < n; ++i) {
            rate[i][0] = sc.nextInt();
            rate[i][1] = sc.nextInt();
        }

        long[] count = new long[2];
        count[0] = rate[0][0];
        count[1] = rate[0][1];

        for (int i = 1; i < n; ++i) {
            count = nextCount(rate[i], count);
        }
        System.out.println(count[0] + count[1]);
    }
    private static long[] nextCount(int[] rate, long[] count) {
        int r0 = rate[0];
        int r1 = rate[1];

        long n = Math.max((count[0] + r0 - 1) / r0, (count[1] + r1 - 1) / r1);
        count[0] = r0 * n;
        count[1] = r1 * n;

        return count;
    }
    private static int gcd(int v1, int v2) {
        BigInteger b1 = BigInteger.valueOf(v1);
        BigInteger b2 = BigInteger.valueOf(v2);
        return b1.gcd(b2).intValue();
    }
}

Measured memory_bytes: 13224
#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;
    //ll ngroup = -1;
    
    ll m = 0;
    while(m*(m-1)/2 < N) ++m;
    if(m*(m-1) != N*2){
        cout << "No" << endl;
        return 0;
    }
    /*
    REP(i,0,N+1){
        if(2*N == i*(i-1)){
            ngroup = i;
            break;
        }
    }
    if(ngroup == -1){
        cout << "No" << endl;
        return 0;
    }else{*/
    ll ngroup = m;
        cout << "Yes"<< endl;
        cout << ngroup << endl;
        vector<vector<ll>> v(ngroup+1);
        ll num = 1;
        rep(i,ngroup){
            REP(j,i+1,ngroup){
                v[i].push_back(num);
                v[j].push_back(num);
                num++;
            }
        }
        rep(i,ngroup){
            cout << v[i].size() << " ";
            PR(v[i],v[i].size());
        }
        /*
        cout << ngroup << endl;
        cout << ngroup -1;
        t = 1;
        REP(i,1,N+1){
            cout << " " << i;
            i += t;
            t++;
        }
        cout << endl;

        t=0;
        ll u=1;
        ll st=1;
        rep(i,ngroup-1){
            ll cur = st;
            rep(j,t){
                cout << " " << cur+j;
                u++;
            }
            cur += 
            rep(j,ngroup-1-t){
                cout << " " << cur;
                cur += u;
            }
        }
        /*
        rep(i,ngroup){
            cout << ngroup-1;
            rep(j,M-1){
                cout << " " << << endl;
                
            }
        }*/
    //}
}



Measured memory_bytes: 3200
#include<cstdio>
#include<algorithm>

int main()
{
  int A, B;
  scanf("%d%d", &A, &B);
  if(A > B)
    std::swap(A, B);
  if(A == B)
    printf("%d\n", B * 2);
  else
    printf("%d\n", B * 2 - 1);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int a, b;
    cin >> a >> b;
    string f(a, '0' + b);
    string s(b, '0' + a);
    if (f.size() > s.size() || (f.size() == s.size() && f > s)) cout << f;
    else cout << s;
}   


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)

int dp[2005][2];
int a[2000];
int n;

int dfs(int pos, int turn){
    if(dp[pos][turn] != -1) return dp[pos][turn];

    int ret;
    if(turn){
        ret = 1e9;
    }else{
        ret = -1;
    }

    for(int i = pos + 1; i < n; i++){
        int tmp;
        if(i < n-1){
            tmp = dfs(i, 1-turn);
        }else{
            tmp = abs(a[pos] - a[i]);
        }

        if(turn){
            ret = min(ret, tmp);
        }else{
            ret = max(ret, tmp);
        }
    }

    dp[pos][turn] = ret;
    return dp[pos][turn];
}

int main(){
    rep(i,2005)rep(j,2)dp[i][j] = -1;
    cin >> n >> a[0] >> a[1];
    rep(i,n) cin >> a[i+2];
    n+=2;
    cout << dfs(1,0) << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[300200];
int t[1300200];

void upd(int v, int tl, int tr, int pos, int val)
{
    if (tl == tr)
        t[v] = val;
    else
    {
        int m = tl + tr >> 1;
        if (pos <= m) upd(2 * v, tl, m, pos, val);
        else upd(2 * v + 1, m + 1, tr, pos, val);
        t[v] = max(t[2 * v], t[2 * v + 1]);
    }
}

int get(int v, int tl, int tr, int l, int r)
{
    if (l > r)
        return 0;
    if (l == tl && r == tr)
        return t[v];
    int m = tl + tr >> 1;
    return max(get(2 * v, tl, m, l, min(r, m)), get(2 * v + 1, m + 1, tr, max(l, m + 1), r));
}

signed main()
{
    int n;
    cin >> n;
    vector<int>v;
    for(int i = 0; i < n; ++i)
    {
        cin >> a[i];
        v.push_back(a[i]);
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    for(int i = 0; i < n; ++i)
        a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
    int ma = 0;
    for(int i = 0; i < n; ++i)
    {
        int cur = a[i];
        int lst = get(1, 0, 3e5, cur, 3e5);
        lst++;
        upd(1, 0, 3e5, cur, lst);
        ma = max(ma, lst);
    }
    cout << ma << '\n';
    return 0;
}


Measured memory_bytes: 9972
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define SUM(n) ((n)+1)*(n)/2
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = (1e9)+7;
#define all(v) v.begin(),v.end()
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  int n,r;
  cin >> n >> r;
  if(n<10){
    r += 100*(10 - n);
  }
  cout << r << '\n';
  return 0;
}


Measured memory_bytes: 256
m,d = map(int, input().split())

count = 0
for i in range(m):
  for j in range(d):
    j = j+1
    sj = str(j)
    if j >= 22:
      j1 = int(sj[-1])
      j2 = int(sj[-2])
      if j1 >= 2 and j2 >= 2:
        if i+1 == j1*j2:
          count += 1

print(count)

Measured memory_bytes: 39408
import sys 
n = int(input())
arr = input()
ans = 1
arr = list(map(int,arr.split(' ')))
arr.sort()
for i in range(n):
    t = arr[i]
    ans *= t
    if (ans > 1000000000000000000):
        print(-1)
        sys.exit()
print(ans)


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

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	cin >> N;

	string n_str(to_string(N));
	int fx = 0;
	for (int i = 0; i < n_str.size(); i++) {
		fx += (n_str[i] - '0');
	}

	cout << ((N % fx == 0) ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256