akhauriyash/Code-Regression huggingface dataset:
/**
*    created: 13.05.2020 18:05:33
**/
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n; cin >> n;
    vector<pair<string, int>> mp(n);
    vector<pair<string, int>> test(n); //添字ずらすのを忘れない
    rep(i,n) {
        string s; int a;
        cin >> s >> a;
        test[i] = make_pair(s,-a);
        mp[i] = make_pair(s,-a); //ひっくり返す
    }
    sort(mp.begin(), mp.end());
    rep(i,n) {
        rep(j,n) {
            if (mp[i] == test[j]) cout << j + 1 << endl; //ずらした
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map>
#include <map>
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
using namespace std;

int main(){
	char str[19];
    
    cin >> str;
    
    str[5] = ' ';
    str[13] = ' ';
    
    cout << str;
    
	return 0;
}

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

bool solve(vector<int>::iterator itr, vector<int>::iterator itr_last, int rest){
    if(rest==0) return true;
    if(itr>=itr_last) return false;
    return solve(itr+1, itr_last, rest) || solve(itr+1, itr_last, rest-*itr);
}

int main(void){
    int nb; cin>>nb;
    vector<int> elems; elems.resize(nb);
    for(auto& a:elems) cin>>a;
    cin>>nb;
    int num;
    while(cin>>num){
        if(solve(elems.begin(),elems.end(),num)) cout<<"yes\n";
        else cout<<"no\n";
    }
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<x<<endl;
#define ll long long int
#define pb push_back
#define in insert
#define mp make_pair
#define F first
#define S second
#define N 1000000
#define mod 1000000007
#define PI acos(-1)
int main()
{
	IOS
	int x,n;
	cin>>x>>n;
	int a[n],i;
	set<int> st;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		st.in(a[i]);
	}
	int ans;
	if(st.find(x)==st.end())
	cout<<x;
	else
	{
		int num;
		for(i=1;i<=100;i++)
		{
			num=x-i;
			if(st.find(num)==st.end())
			{
				cout<<num;
				return 0;
			}
			num=x+i;
			if(st.find(num)==st.end())
			{
				cout<<num;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

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

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

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    int n, m;
    cin>>n>>m;
    char a[n][m];
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++)
        {
            cin>>a[i][j];
        }
    }
    for (int i=0;i<2*n;i++)
    {
        for (int j=0;j<m;j++)
        {
            cout<<a[(i)/2][j];
        }
        cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
char s[100010];
int n, x = 1;
int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	if (s[1] == '0' || s[n] == '1')
		return printf("-1\n"), 0;
	for (int i = 1; i < n; i ++)
		if (s[i] ^ s[n - i]) 
			return printf("-1\n"), 0;
	for (int i = 2; i <= n; i ++) {
		printf("%d %d\n", x, i);
		if (s[i - 1] == '1')
			x = i;
	}
	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
string s;
bool check(int l,int r) {
	int len = (r - l + 1);
	for(int i=0;i<len;i++)
		if(s[l+i] != s[r-i])
			return false;
	return true;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
	int n = (int)s.size();
	if(check(0,n-1) && check(0,(n-1)/2-1) && check((n+3)/2-1,n-1))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;
 
string s, x;

int n;

bool check(int l) {
	for (int i = 0; i <= n - l; ++ i) {
		x = s.substr(i, l);
		if (s.find(x, i + l) != string::npos)
			return true;
	}
	return false;
}

main (){
	clog << "Ready\n";
	
	cin >> n >> s;
	int l = 1, r = n;
	while(l <= r) {
		int mid = (l + r) / 2;
		if (check(mid))
			l = mid + 1;
		else
			r = mid - 1;
	}
	
	cout << r;
	
	cerr << '\n';
	return 0;
}	

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A[]={
1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
};

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>x;
	cout<<A[x-1]<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
A, B, C, D, E, F = map(int, raw_input().split())

mx = 0
mx_x = 100*A
mx_y = 0
for i in xrange(31):
    for j in xrange(16):
        if i + j == 0 or 100*A*i + 100*B*j >= F: continue
        for k in xrange(101):
            for l in xrange(51):
                if 100*A*i + 100*B*j + C*k + D*l > F: continue
                if (A*i + B*j)*E < C*k + D*l: continue
                a = 100*A*i + 100*B*j
                b = C*k + D*l
                if 100.0*b/(a + b) > mx:
                    mx_x = a + b
                    mx_y = b
                    mx = 100.0*b/(a + b)
print mx_x, mx_y


Measured memory_bytes: 2692
#include <bits/stdc++.h>
#include <math.h>
#define _USE_MATH_DEFINES
using namespace std;

typedef long long ll;

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

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

    printf("%8f\n", 2*R*M_PI);
}


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

const int MOD = 1000000007;
const int MAXN = 1055;
const int MAXM = 2055;

int prt[10][MAXN], pmx[10][MAXN];
int ud[MAXN], dep[MAXN];
int TP[MAXM];

vector<int> G[MAXN];
int A[MAXM], B[MAXM], C[MAXM], O[MAXM], D[MAXM];
bitset<MAXM> isT;

int N, M; ll K, Sum;

int uf(int i) { return i == ud[i] ? i : (ud[i] = uf(ud[i])); }
void uf(int a, int b) { ud[uf(b)] = uf(a); }
int lca(int a, int b) {
	if(dep[a] > dep[b]) swap(a, b);
	const int dt = dep[b] - dep[a];
	int r = 0;
	for(int i = 0, t; i < 10; i++) if(dt & (1<<i)) {
		t = pmx[i][b];
		if(r < t) r = t;
		b = prt[i][b];
	}
	if(a == b) return r;
	for(int i = 10, t; i--;) if(prt[i][a] != prt[i][b]) {
		t = max(pmx[i][a], pmx[i][b]);
		if(r < t) r = t;
		a = prt[i][a]; b = prt[i][b];
	}
	return max({r, pmx[0][a], pmx[0][b]});
}

void dfs(int i) {
	for(int e : G[i]) {
		int v = A[e] + B[e] - i;
		if(dep[v]) continue;
		dep[v] = dep[i] + 1;
		prt[0][v] = i;
		pmx[0][v] = C[e];
		dfs(v);
	}
}

int main() {
	ios::sync_with_stdio(false);
	TP[0] = 1;
	for(int i = 1; i < 2055; i++) TP[i] = TP[i-1] * 2 % MOD;

	cin >> N >> M >> K;
	if(N < 3) {
		puts("0");
		return 0;
	}
	for(int i = 1; i <= M; i++)
		cin >> A[i] >> B[i] >> C[i];

	iota(O, O+M+1, 0); sort(O+1, O+M+1, [&](int a, int b) {
		return C[a] < C[b];
	});
	iota(ud, ud+N+1, 0);
	for(int oi = 1, i, a, b; oi <= M; oi++) {
		i = O[oi]; a = A[i]; b = B[i];
		if(uf(a) == uf(b)) continue;
		isT[i] = true;
		uf(a, b);
		G[a].eb(i);
		G[b].eb(i);
	}

	dep[1] = 1; dfs(1);
	for(int j = 1; j < 10; j++) for(int i = 1; i <= N; i++) {
		prt[j][i] = prt[j-1][prt[j-1][i]];
		pmx[j][i] = max(pmx[j-1][i], pmx[j-1][prt[j-1][i]]);
	}

	for(int i = 1; i <= M; i++) {
		if(isT[i]) Sum += C[i];
		else D[i] = C[i] - lca(A[i], B[i]);
	}

	K -= Sum;
	if(K < 0) {
		puts("0");
		return 0;
	} else if(!K) {
		int s = N-1, u = 0;
		for(int i = 1; i <= M; i++) if(!isT[i])
			(D[i] ? u : s)++;
		cout << ll(TP[u]) * (TP[s]-2+MOD) % MOD << endl;
	} else {
		int e = 0, u = 0;
		for(int i = 1; i <= M; i++)
			if(!isT[i] && K <= D[i])
				(D[i] == K ? e : u)++;
		cout << ll(TP[u]) * ll(TP[e]-1+MOD) * 2 % MOD << endl;
	}
	return 0;
}

Measured memory_bytes: 512
N = int(input())
X = [[int(i) for i in input().split()] for __ in range(N)]
X = sorted(X,key = lambda x:x[1])

a = [0] * N
a[0] = X[0][0]
for  i in range(1,N):
    a[i] = a[i-1] + X[i][0]
for i in range(N):
    if a[i] > X[i][1]:
        print('No')
        exit()
print('Yes')


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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf
#define sf(n) scanf("%d",&n)
#define sff(n1,n2) scanf("%d %d",&n1,&n2)
#define sfff(n1,n2,n3) scanf("%d %d %d",&n1,&n2,&n3)
#define sl(n) scanf("%lld",&n)
#define sll(n1,n2) scanf("%lld %lld",&n1,&n2)
#define slll(n1,n2,n3) scanf("%lld %lld %lld",&n1,&n2,&n3)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define nl puts("");
#define pb push_back
#define MOD 1000000007
#define fi first
#define se second
#define N 100005
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define sz(x) x.size()
#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >
#define line puts("-------");
#define db(x) cout<<#x<<" :: "<<x<<"\n";
#define dbb(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
typedef long long int ll;
using namespace std;
int main()
{
    string a;
    cin>>a;
    int i=0,j=sz(a)-1,cnt=0;
    while(i<j)
    {
        if(a[i]!=a[j])
            cnt++;
        i++;
        j--;
    }
    cout<<cnt;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll pt[200005][6]={0};
ll dist(int kth, int idx) {
    ll dist=0;
    for(int i=0;i<2;i++) {
        dist+=abs(pt[kth][i]-pt[idx][i]);
    }
    return dist;
}

ll f(ll cmbn[2], int n) {
    ll pk=0;ll idx=0;

   for(int i=0;i<n;i++) {
       ll val=0;
       for(int j=0;j<2;j++) {
           val+=(1-2*cmbn[j])*pt[i][j];
       }
       if(val>pk) {
           pk=val;
           idx=i;
       }
   }
   return idx;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, d = 2;
    cin >> n;
    for(int i=0;i<n;i++) {
        for(int j=0;j<2;j++)
            cin>>pt[i][j];
    }
   ll pk[2<<d];
   for(int j=0;j< 2;j++) {
       ll cmbn[2]={0};
       for(int dig=0;dig<2; dig++) {
           if(j & 1<<dig)
             cmbn[dig]=1;
       }
       pk[j]=f(cmbn, n);
   }

   ll maxd=0;
   for(int i=0;i<n;i++) {
       for(int j=0;j<2;j++)
       maxd=max(maxd, dist(i, pk[j]));
   }
   cout<<maxd;
}


Measured memory_bytes: 12980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    string S;
    int N;
    cin >> S;
    N = (int)S.size();
    vector<vector<ll>> dp(N + 1, vector<ll>(13, 0));
    dp[0][0] = 1;
    rep(i, N){
        rep(j, 13){
            if(S[i] == '?'){
                rep(k, 10){
                    dp[i + 1][(10 * j + k) % 13] = (dp[i + 1][(10 * j + k) % 13] + dp[i][j]) % mod;
                }
            } else {
                int c;
                c = S[i] - '0';
                dp[i + 1][(10 * j + c) % 13] = (dp[i + 1][(10 * j + c) % 13] + dp[i][j]) % mod;
            }
        }
    }
    cout << dp[N][5] << endl;
    
    return 0;
}


Measured memory_bytes: 13696
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    string s[2];
    cin >> s[0] >> s[1];

    reverse(s[0].begin(), s[0].end());

    if (s[0] == s[1])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
import collections
n = int(raw_input())
adj = collections.defaultdict(list)
for _ in range(n - 1):
	u, v, w = map(int, raw_input().split(' '))
	adj[u].append((v,w))
	adj[v].append((u,w))
h = [-1 for _ in range(n+1)]
h[1] = 0
def dfs(h, adj):
	stack = collections.deque([1])
	while(stack):
		u = stack.pop()
		for v,w in adj[u]:
			if h[v] == -1:
				h[v] = (1- h[u]) if (w % 2) else h[u]
				stack.append(v) #(v, h, adj)
dfs(h, adj)
for node in range(1, n + 1):  print h[node]

Measured memory_bytes: 60700
n = int(input())
s = input()
if n <= 3:
    sum = 0
else:
    sum = 0
    r = []
    g = []
    b = []
    if s[n-1] == "R":
        r.append(1)
        g.append(0)
        b.append(0)
    if s[n-1] == "G":
        r.append(0)
        g.append(1)
        b.append(0)
    if s[n-1] == "B":
        r.append(0)
        g.append(0)
        b.append(1)
    for i in range(1,n):
        if s[n-i-1] == "R":
            r.append(r[i-1]+1)
            g.append(g[i-1])
            b.append(b[i-1])
        if s[n-i-1] == "G":
            r.append(r[i-1])
            g.append(g[i-1]+1)
            b.append(b[i-1])
        if s[n-i-1] == "B":
            r.append(r[i-1])
            g.append(g[i-1])
            b.append(b[i-1]+1)
    for i in range(n-3):
        if s[i] == "R":
            j = i + 1
            while j <= n-2:
                if s[j] == "G":
                    sum += b[n-j-1]
                    if 2*j-i <= n-1 and s[2*j-i] == "B":
                        sum -= 1
                if s[j] == "B":
                    sum += g[n-j-1]
                    if 2*j-i <= n-1 and s[2*j-i] == "G":
                        sum -= 1
                j += 1
        if s[i] == "G":
            j = i + 1
            while j <= n-2:
                if s[j] == "R":
                    sum += b[n-j-1]
                    if 2*j-i <= n-1 and s[2*j-i] == "B":
                        sum -= 1
                if s[j] == "B":
                    sum += r[n-j-1]
                    if 2*j-i <= n-1 and s[2*j-i] == "R":
                        sum -= 1
                j += 1
        if s[i] == "B":
            j = i + 1
            while j <= n-2:
                if s[j] == "R":
                    sum += g[n-j-1]
                    if 2*j-i <= n-1 and s[2*j-i] == "G":
                        sum -= 1
                if s[j] == "G":
                    sum += r[n-j-1]
                    if 2*j-i <= n-1 and s[2*j-i] == "R":
                        sum -= 1
                j += 1
print(sum)
                    
    

Measured memory_bytes: 68848
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}


int f[1 << 26] , pattern[27];
string s;

int main(){
    rep(i,0,26) pattern[i] = 1 << i;
    memset(f , 0x37 , sizeof(f));
    f[0] = 0;
    cin >> s;
    int mask = 0;
    rep(i,0,sz(s)) {
        mask ^= 1 << (s[i] - 'a');
        int best = sz(s);
        rep(i,0,27) best = min(best , f[mask ^ pattern[i]] + 1);
        f[mask] = min(f[mask] , best);
        if(i == sz(s) - 1) cout << best << endl;
    }
    return 0;
}


Measured memory_bytes: 262912
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
#define MAXX 200010
 
#define PI   3.14159265358979323846264338327950
 
#define PB push_back 
#define F first
#define S second
 
#define ll 	long long int
 
#define mod  1000000007
 

 
int main()
{
	FAST;
	ll a,b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	ll fg = max(x,y)*c*2;
	ll h= 0;
	ll ans = x*a  + y*b;
		ll g = min(x, y);
		x -= g;
		y -= g;
		h += 2*g*c;
		
	
	h += (x*a + y*b);
	
	cout << min(ans, min(fg, h));
	return 0;
}

Measured memory_bytes: 3552
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<stack>
#include<vector>
#define INFTY 10000000000
using namespace std;

int main(){
  int n;
  cin>>n;
  int h[110000][3];
  long long dp[110000][3]={0};
  for(int i=1;i<=n;i++){
    cin>>h[i][0]>>h[i][1]>>h[i][2];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(j==k) continue;
        dp[i+1][j]=max(dp[i+1][j],dp[i][k]+h[i+1][j]);
      }
    }
  }
  int ans=max({dp[n][0],dp[n][1],dp[n][2]});
  cout<<ans<<endl;

}


Measured memory_bytes: 4096
//ABC079C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int n;
	cin >> n;
	int a, b, c, d;
	a = n/1000;
	b = (n%1000)/100;
	c = (n%100)/10;
	d = n%10;
	if(a+b+c+d == 7){
		cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
	}else if(a+b+c-d == 7){
		cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
	}else if(a+b-c+d == 7){
		cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
	}else if(a+b-c-d == 7){
		cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
	}else if(a-b+c+d == 7){
		cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
	}else if(a-b+c-d == 7){
		cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
	}else if(a-b-c+d == 7){
		cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
	}else if(a-b-c-d == 7){
		cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i,h) cin >> s[i];
    REP(i,h){
        REP(j,w){
            if(s[i][j]=='#') continue;
            int cnt = 0;
            REP(x,3){
                REP(y,3){
                    int xi = i+x-1;
                    int yj = j+y-1;
                    if(xi>=0&&xi<h&&yj>=0&&yj<w&&s[xi][yj]=='#') cnt++;
                }
            }
            s[i][j] = (char)('0'+cnt);
        }
    }
    REP(i,h){
        cout << s[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        int[] l = new int[n];
        for(int i=0;i<n;i++){
            l[i] = Integer.parseInt(sc.next());
        }
        int p = 0;
        int count =0;
        for(int i=0;i<n;i++){
            if(p<=x){
                count++;
                p+=l[i];
            }else{
                break;
            }
        }
        if(p<=x){
            count++;
        }
        System.out.println(count);
        sc.close();
    }
}

Measured memory_bytes: 21972
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
using namespace std;



int main(int argc, char *args[]) {
	int A,B,C;
	int K;
	
	cin >> A >> B>> C;
	cin >> K;
	for (int i = 0; i < K; i++) {
		int max = 0;
		if (max < A) max = A;
		if (max < B) max = B;
		if (max < C) max = C;
		if (max == A)A = A * 2;
		else if (max == B)B = B * 2;
		else C = C * 2;
	}
	cout << A + B + C << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
 
int main(){
  int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  vector<int> x(N),y(M);
  int xmax=-101,ymin=101;
  for(int i=0;i<N;i++){
    cin>>x.at(i);
    xmax=max(xmax,x.at(i));
  }
  for(int i=0;i<M;i++){
    cin>>y.at(i);
    ymin=min(ymin,y.at(i));
  }
  if((xmax<ymin)&&(X<ymin)&&(ymin<=Y)){
    cout<<"No War"<<endl;
  }else{
    cout<<"War"<<endl;
  }
}

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

int main(){
    int n, q;cin>>n>>q;
    string s;cin>>s;
    vector<int> acc(n);
    acc[0] = 0;
    for (int i=1;i<n;i++){
        if (s[i-1] == 'A' && s[i] == 'C'){
            acc[i] = acc[i-1] + 1;
        } else {
            acc[i] = acc[i-1];
        }
    }
    int l,r;
    vector<pair<int, int>> query;
    for (int i=0;i<q;i++){
        cin >> l >> r;
        query.push_back(make_pair(l, r));
    }

    for (auto item : query){
        if (s[item.first-1] == 'C'){
            cout << acc[item.second-1] - acc[item.first-1] << endl;

        } else {
            if (item.first == 1){
                cout << acc [item.second - 1] <<endl;
            } else {
                cout << acc[item.second-1] - acc[item.first-2] << endl;
            }
        }

    }

    return 0;
}

Measured memory_bytes: 2292
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)

int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    string str1,str2;
    cin>>str1>>str2;
    for(i=0;i<str1.size();i++)
    {
        if(str1[i]!=str2[i])
            x++;
    }
    cout<<x<<endl;

    return 0;
}



Measured memory_bytes: 3856
a, b, c, d = gets.split.map(&:to_i)

turn = true
loop do
	if turn
		c -= b
		turn = false
		if c <= 0
			puts "Yes"
			exit
		end
	else
		a -= d

		turn = true
		if a <= 0
			puts "No"
			exit
		end
	end
end


Measured memory_bytes: 14420
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

def main():
    N = [0] + list(map(int, tuple(input().rstrip("\n"))))
    Ncopy = N.copy()
    ans = 0

    flag = False
    for i in range(len(N)-1, 0, -1):
        if (Ncopy[i] <= 4) or (Ncopy[i] == 5 and N[i-1] <= 4):
            ans += Ncopy[i]
            flag = False
        else:
            Ncopy[i-1] += 1
            if not flag:
                ans += 10 - N[i]
            else:
                ans += 9 - N[i]
            Ncopy[i] = 0
            flag = True

    if Ncopy[0] == 1:
        ans += 1

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 20452
#include <bits/stdc++.h>
using namespace std;
 int dfs(long long x,vector<long long> &a){
   if(x>=1000000000) return 0;
   else{
   a.push_back(x);
   dfs(10*x+3,a);
   dfs(10*x+5,a);
   dfs(10*x+7,a);
   }
 }
  
 int main() {
   vector<long long> a;
   dfs(0,a);
   sort(a.begin(),a.end());
   vector<long long> b;
   
   for(long long i = 0;i<a.size();i++){
     bool flag1 = false;
     bool flag2 = false;
     bool flag3 = false;
     string S= to_string(a[i]);
     for(long long j = 0;j<S.size();j++){
       
       if(S[j] == '7') flag1 = true;
       if(S[j] == '5') flag2 = true;
       if(S[j] == '3') flag3 = true;
     }
     if(flag1 && flag2 && flag3) b.push_back(a[i]);
   }
   sort(b.begin(),b.end());
   int N;
   cin >> N;
   int c = 0;
   for(int i = 0;i<b.size();i++){
     if(b[i] >N) break;
     c++;
   }
   cout << c << endl;
 }


Measured memory_bytes: 892
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <regex>
#include <string>
#include <stack>
#include <utility>
#include <vector>

#include <random>

using namespace std;
using ll = long long;


int main()
{
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	int dx = tx - sx;
	int dy = ty - sy;


	for (int i = 0; i < dy; i++) printf("U");
	for (int i = 0; i < dx; i++) printf("R");

	for (int i = 0; i < dy; i++) printf("D");
	for (int i = 0; i < dx; i++) printf("L");

	printf("L");
	for (int i = 0; i < dy + 1; i++) printf("U");
	for (int i = 0; i < dx + 1; i++) printf("R");
	printf("D");

	printf("R");
	for (int i = 0; i < dy + 1; i++) printf("D");
	for (int i = 0; i < dx + 1; i++) printf("L");
	printf("U");


	cout << endl;

	return 0;

}

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

#define FAST_IO                       \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define SIZE(arr) ((int)arr.size())
#define debug(a) cout << #a << " " << a << endl;
#define debug(a, i) cout << #a << "[" << i << "]" << " = " << a[i] << endl;

using namespace std;

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

const int MOD = 1e9 + 7;
const int INF = 1e9 + 9;

int main()
{
	//#ifndef ONLINE_JUDGE
	//	(void)freopen("input.txt", "r", stdin);
	//	(void)freopen("output.txt", "w", stdout);
	//#endif
	FAST_IO;
	int n, k, c;
	cin >> n >> k >> c;
	string s;
	cin >> s;
	vector<int> L(200001), R(200001);
	L[0] = 0;
	R[0] = 0;
	int last = -INF;
	for (int i = 1; i <= n; ++i) {
		if (s[i - 1] == 'x') {
			L[i] = L[i - 1];
		}
		else if (i - c > last) {
			last = i;
			L[i] = L[i - 1] + 1;
		}
		else
			L[i] = L[i - 1];

	}
	last = -INF;
	for (int i = 1; i <= n; ++i) {
		if (s[n - i] == 'x') {
			R[i] = R[i - 1];
		}
		else if (i - c > last) {
			last = i;
			R[i] = R[i - 1] + 1;
		}
		else
			R[i] = R[i - 1];
	}
	
	for (int i = 0; i <= n; ++i) {
		if (s[i] == 'o') {
			int l = i;
			int r = n - i - 1;
			if (L[l] + R[r] + 1 == k)
				cout << i + 1 << endl;
		}
	}
	return 0;

}



Measured memory_bytes: 3348
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
string ss[100000];
set<string> sets;
int main() {
    ios::sync_with_stdio(false);
    string s; int k;
    cin >> s >> k;
    
    for (int i = 0; i < s.size(); i++) {
        for (int j = 1; j <= s.size()-i; j++) {
            string t = s.substr(i, j);
            if (t.size() <= k)
                sets.insert(s.substr(i, j));
        }
    }
    set<string>::iterator it = sets.begin();
    std::advance(it, k-1);
    string x = *it;
    cout << x << endl;
    
    
    return 0;
}


Measured memory_bytes: 2432
import math

class Vector:
    def __init__(self, x=None, y=None):
        self.x = x
        self.y = y

    def __add__(self, other):
        return Vector(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Vector(self.x - other.x, self.y - other.y)

    def __mul__(self, k):
        return Vector(self.x * k, self.y * k)

    def __truediv__(self, k):
        return Vector(self.x / k, self.y / k)

    def __gt__(self, other):
        return self.x > other.x and self.y > other.yb

    def __lt__(self, other):
        return self.x < other.x and self.y < other.yb

    def __eq__(self, other):
        return self.x == other.x and self.y == other.y

    def dot(self, other):
        return self.x * other.x + self.y * other.y

    # usually cross operation return Vector but it returns scalor
    def cross(self, other):
        return self.x * other.y - self.y * other.x

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        return math.sqrt(self.norm())

    def rotate(self, theta):
        return Vector(self.x * math.cos(theta)
                               - self.y * math.sin(theta),
                               self.x * math.sin(theta)
                               + self.y * math.cos(theta))

class Point(Vector):
    def __init__(self, *args, **kargs):
        return super().__init__(*args, **kargs)

class Segment:
    def __init__(self, p1=Point(0, 0), p2=Point(1, 1)):
        self.p1 = p1
        self.p2 = p2

class Line(Segment):
    def __init__(self, *args, **kargs):
        return super().__init__(*args, **kargs)

class Circle:
    def __init__(self, c=Point(0, 0), r=1):
        self.c = c
        self.r = r

def get_cross_point(c1, c2):
    v = c2.c - c1.c
    d = v.abs()
    assert d <= (c1.r + c2.r)
    a = math.acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r  * d))
    return c1.c + v.rotate(a) * (c1.r/d), c1.c + v.rotate(-a) * (c1.r/d)

x1, y1, r1 = [ int(i) for i in input().split() ]
c1 = Circle(Point(x1, y1), r1)
x2, y2, r2 = [ int(i) for i in input().split() ]
c2= Circle(Point(x2, y2), r2)
p1, p2 = get_cross_point(c1, c2)
x1, y1 = min((p1.x, p1.y), (p2.x, p2.y))
x2, y2 = max((p1.x, p1.y), (p2.x, p2.y))
print("{0:0.8f} {1:0.8f} {2:0.8f} {3:0.8f}".format(x1, y1, x2, y2))


Measured memory_bytes: 5772
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n ;
  cin >> n ;
  vector < int > a( n );
  map < int , int > hashmap, expected ;
  
  for( int i = 0 ; i < n ; i++ ) {
    cin >> a[ i ] ;
    hashmap[ a[i] ]++ ;
  }
  
  if ( n %3 == 0 ) {
	for( int i = 1 ; i < n ; i++ ) {
      expected.clear();
      
      int x = a[ i ] ^ a[ 0 ];
      expected[ x ] +=  n/3 ;
      expected[ a[ 0 ] ] += n/3 ;
      expected[ a[ i ] ] += n/3 ;
      
      if ( expected[ x ] == hashmap[ x ] && expected[ a[ 0 ] ] == hashmap[ a[ 0 ] ] && expected[ a[ i ] ] == hashmap[ a[ i ] ] ) {
      	cout << "Yes";
        return 0 ;
      }
      
    }
    cout << "No" ;
  }
  else if ( n%3 == 1 ) {
    int x = *max_element( a.begin(), a.end());
    expected[ x ] += 2 * ( n / 3 ) + 1 ;
    expected[ 0 ] += n / 3 ;
    ( expected[ 0 ] == hashmap[ 0 ] && expected[ x ] == hashmap[ x ] ) ? cout << "Yes" : cout << "No";
  }
  else {
    hashmap[ 0 ] == n  ? cout << "Yes" : cout << "No" ;
  }
  
  return 0 ;
}

Measured memory_bytes: 7808
N,M = map(int,input().split())
A = list(map(int,input().split()))
sumA = 0

for i in range(N):
  sumA = sumA + A[i]

cnt = 0

for j in range(N):
  if sumA * (1/4/M) <= A[j]:
    cnt = cnt + 1

if cnt >= M:
  print('Yes')
else :
  print('No')


Measured memory_bytes: 3060
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 15
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


class Segtree:
    def __init__(self, A, ide_ele, segfunc, initialize=True):
        self.n = len(A)
        self.size = 2 ** (self.n - 1).bit_length()
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        if initialize:
            self.data = [ide_ele] * self.size + A + [ide_ele] * (self.size - self.n)
            for i in range(self.size - 1, 0, -1):
                self.data[i] = self.segfunc(self.data[2 * i], self.data[2 * i + 1])
        else:
            self.data = [ide_ele] * (2 * self.size)

    def update(self, k, x):
        k += self.size
        self.data[k] = x
        while k:
            k = k >> 1
            self.data[k] = self.segfunc(self.data[2 * k], self.data[2 * k + 1])

    def query(self, l, r):
        L, R = l + self.size, r + self.size
        s = self.ide_ele
        while L < R:
            if R & 1:
                R -= 1
                s = self.segfunc(s, self.data[R])
            if L & 1:
                s = self.segfunc(s, self.data[L])
                L += 1
            L >>= 1
            R >>= 1
        return s

n, x = LI()
A = LI()
ans = INF
seg = Segtree(A, INF, min)
for i in range(n):
    ret = i * x
    for j in range(n):
        if j - i >= 0:
            ret += seg.query(j - i, j + 1)
        else:
            ret += min(seg.query(0, j + 1), seg.query(n - (i - j), n))
    ans = min(ans, ret)


print(ans)


Measured memory_bytes: 55644
#include<bits/stdc++.h>
using namespace std;
vector<int>n;
int dp[109][9][9];

int main(){
  string s;
  int m;
  cin>>s>>m;
  int len=s.size();
  for(int i=0;i<len;i++){
    n.push_back(s[i]-'0');
  }
  dp[0][0][0]=1;

  for(int i=0;i<len;i++){
    for(int smaller=0;smaller<2;smaller++){
      for(int j=0;j<=m;j++){
        for(int x=0;x<=(smaller?9:n[i]);x++){
          dp[i+1][smaller||x<n[i]][j+(x!=0)] += dp[i][smaller][j];
        }
      }
    }
  }

  cout<<dp[len][0][m]+dp[len][1][m]<<endl;

  return(0);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> v1;
int main(){
    int k,n;
    int a,b,c;
    int i,j;
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>a;
        v1.push_back(a);
    }
    sort(v1.rbegin(),v1.rend());
    for(i=0,j=0;i<k;i++){
        j+=v1[i];
    }
    cout<<j<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    d=a/b;
    r=a%b;
    f=(double)a/(double)b;
    printf("%d %d %f\n",d,r,f);
    return 0;
}


Measured memory_bytes: 2096
#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
using namespace std;

int main() {

int H,W,x,y;

do{
cin >> H >> W;
for(x=1;x<=H;++x){

if(x==1 || x==H){

for(y=1;y<=W;++y){
if(H==0 && W==0){break;}
cout << "#";
}

}else{

cout << "#";
for(y=2;y<=W-1;++y){
if(H==0 && W==0){break;}
cout << ".";
}
cout << "#";

}

if(H==0 && W==0){break;}
cout << endl;
}
if(H==0 && W==0){break;}
cout << endl;
}while(H>0 && W>0);

}


Measured memory_bytes: 3008
use proconio::input;
use proconio::marker::Usize1;
use std::collections::HashMap;

#[allow(dead_code)]
struct UFT {
    par: Vec<usize>,
    size: Vec<usize>,
    n: usize,
}

#[allow(dead_code)]
impl UFT {
    fn new(n: usize) -> Self {
        let par = (0..n).collect();
        let size = vec![1; n];
        Self { par, size, n }
    }
    fn find(&mut self, a: usize) -> usize {
        if self.par[a] == a {
            a
        } else {
            self.par[a] = self.find(self.par[a]);
            self.par[a]
        }
    }
    fn unite(&mut self, a: usize, b: usize) -> usize {
        let mut x = self.find(a);
        let mut y = self.find(b);
        if x == y {
            x
        } else {
            if self.size[x] < self.size[y] {
                std::mem::swap(&mut x, &mut y);
            }
            self.size[x] += self.size[y];
            self.par[y] = x;
            x
        }
    }
    fn same(&mut self, a: usize, b: usize) -> bool {
        self.find(a) == self.find(b)
    }
}

#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
        K: usize,
        L: usize,
        PQ: [(Usize1, Usize1); K],
        RS: [(Usize1, Usize1); L],
    }

    let mut uft1 = UFT::new(N);
    let mut uft2 = UFT::new(N);

    for &(a, b) in &PQ {
        uft1.unite(a, b);
    }

    for &(a, b) in &RS {
        uft2.unite(a, b);
    }

    let mut map = HashMap::new();

    for i in 0..N {
        let a = uft1.find(i);
        let b = uft2.find(i);
        let cnt = map.entry((a, b)).or_insert(0);
        *cnt += 1;
    }

    for i in 0..N {
        let a = uft1.find(i);
        let b = uft2.find(i);
        print!("{} ", map.get(&(a, b)).unwrap());
    }

}


Measured memory_bytes: 23060
#include "bits/stdc++.h"
using namespace std;

int n;
int a[105];

int b[105];

int main(){

  cin >> n;

  for(int i = 0; i < n; i++)
    cin >> a[i];
  for(int i = 0; i < n; i++)
    cin >> b[i];
  int ans = 0;
  int tmp = 0;
  for(int i = 0; i < n; i++){
    tmp += a[i];
    int cur = tmp;
    for(int j = i; j < n; j++)cur += b[j];
    ans = max(ans, cur);
  }
  cout << ans << '\n';

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <tuple>
using namespace std;
template<class T>
bool equal(T x, T y) { return x==y;}

template<>
bool equal(const char* x, const char* y) {return std::strcmp(x, y);}

template<class Iterator, class Compare>
void selection_sort(Iterator first, Iterator last, Compare comp)
{
    for(Iterator p = first; p != last; ++p)
    {
        Iterator min_position = p;
        for(Iterator q = p; q != last; ++q)
        {
            if(comp(*q, *min_position))
                min_position = q;
        }
        auto tmp = *min_position;
        *min_position = *p;
        *p = tmp;
    }
}

int main()
{
    
    long N, A, B; cin >> N >> A >>B;


        cout << max(0L, (A+B*(N-1)) - (B+ A*(N-1)) +1)<< endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		Map<Integer, List<Integer>> map = new HashMap<Integer, List<Integer>>();
		for (int i = 0; i < n - 1; i++) {
			String[] sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			int b = Integer.parseInt(sa[1]) - 1;
			putMap(map, a, b);
			putMap(map, b, a);
		}
		String[] sa = br.readLine().split(" ");
		List<Integer> c = new ArrayList<Integer>(n);
		for (int i = 0; i < n; i++) {
			c.add(Integer.parseInt(sa[i]));
		}
		br.close();

		Collections.sort(c);
		Collections.reverse(c);

		PrintWriter pw = new PrintWriter(System.out);

		long m = 0;
		for (int i = 1; i < c.size(); i++) {
			m += c.get(i);
		}
		pw.println(m);

		int[] d = new int[n];
		Queue<Integer> que = new ArrayDeque<Integer>();
		que.add(0);
		d[0] = c.get(0);
		int idx = 1;
		while (!que.isEmpty()) {
			Integer cur = que.poll();
			List<Integer> list = map.get(cur);
			for (int i = 0; i < list.size(); i++) {
				if (d[list.get(i)] == 0) {
					que.add(list.get(i));
					d[list.get(i)] = c.get(idx);
					idx++;
				}
			}
		}

		pw.print(d[0]);
		for (int i = 1; i < d.length; i++) {
			pw.print(" " + d[i]);
		}
		pw.println();
		pw.flush();
	}

	static void putMap(Map<Integer, List<Integer>> map, int a, int b) {
		List<Integer> listA = map.get(a);
		if (listA == null) {
			listA = new ArrayList<Integer>();
			map.put(a, listA);
		}
		listA.add(b);
	}
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[100005];
ll B[100005];
ll C[100005];

int main()
{
    ll N;
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }
    ll max = 0;

    REP(i, N)
    {
        B[i] = A[i] - A[(N + i - 1) % N];
        max = std::max(max, B[i]);
    }
    //! A[i]はmax回の操作で似たものを作れる
    REP(i, N)
    {
        ll k = (B[i] + (N - 1) * max) / N;
        C[i] = max - k;
    }
    //! C[i]にはA[i]が何回1から始まったかが入っている
    //! C[0]をとりあえず求める
    FOR(i, N, 1)
    {
        C[0] += (N + 1 - i) * C[i];
    }
    FOR(i, N, 1)
    {
        C[i] = C[i - 1] + (max - C[i]) - (N - 1) * C[i];
    }

    string ans = "YES";
    REP(i, N)
    {
        if (A[i] < C[i])
        {
            ans = "NO";
            break;
        }
        if ((A[i] - C[i]) % (N * (N + 1) / 2) != 0)
        {
            ans = "NO";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define watch(x) cerr << (#x) << " is " << (x) << endl
const int mod = 1e9 + 7;

using namespace std;



int main()
{
	#ifdef ME
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	long double b; long long a;
	cin >> a >> b;
	cout << (long)(a*b) << endl;

	
	return 0;
}

Measured memory_bytes: 3732
#include <stdio.h>
 
int main(void){
    int x,y,h,w;
     
    while(1){
        scanf("%d %d\n",&x,&y);
        if(0 == x && 0 == y){
            break;
        }else{
            for(h = 1; h <= x; h++){
                for(w = 1; w <= y; w++){
                    if(h % 2 == 1 ){
                        if(w % 2 == 1){
                            printf("#");
                        }else{
                            printf(".");
                        }
                    }else{
                        if(w % 2 == 1){
                            printf(".");
                        }else{
                            printf("#");
                        }
                    }
                    
                }
                printf("\n");
            }
            printf("\n");
        }
    }
     
    return 0;
}
 

Measured memory_bytes: 1808
#include<bits/stdc++.h>
#define mod 998244353
#define ll long long
using namespace std;

struct ca
{
  long  si,ei;
};


int binarySearch(vector<int> arr, int l, int r, int x) 
{ 
    if (r >= l) { 
        int mid = l + (r - l) / 2; 
  
        if (arr[mid] == x) 
            return mid; 
  
         
        if (arr[mid] > x) 
            return binarySearch(arr, l, mid - 1, x); 
  
       
        return binarySearch(arr, mid + 1, r, x); 
    } 
  
    
    return -1; 
} 

int prime[1000001]={};

long power(long x,  long y, long p)  
{  
    long res = 1;     
  
    x = x % p; 
   
    if (x == 0) return 0; 
  
    while (y > 0)  
    {  
         
        if (y & 1)  
            res = (res*x) % p;  
  
        
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}  

void pr()
{
  prime[1]=0;

 for(int i=2;i*i<1000001;i++)
  if(prime[i]==0)
  for(int j=i*i;j<1000001;j+=i)
  prime[j]=1;

}

int countSetBits( int n) 
{ 
     int count = 0; 
    while (n) { 
        count += n & 1; 
        n >>= 1; 
    } 
    return count; 
} 

long sum=0;




int main()
{

  //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

   //pr();
  int t;
   //cin>>t;
  t=1;
  int id=1;

  while(t--)
{
  int a,b,c,d;
    cin>>a>>b>>c>>d;

   int i=1;
  while(true)
{

     if(i&1)
       {
         c-=b;
          if(c<=0)
            break;
        }

     else
  {
        a-=d;
       if(a<=0)
        break;
   }

   i++;
 }

  if(i&1)
 cout<<"Yes";

  else
 cout<<"No";
}

     
   


return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << "-->" << x << endl;
#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        cout << it << " ";        \
    }                             \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
    #define mod 998244353
 
#define fi first
#define se second

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    fo(i, s.size())
            cout
        << 'x';

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N;
	int ans=0;
	cin>>N;
	for(int i=1;i<=9;i++) 
	{
		if(i<=N) ans++;
		else 
		{
			cout<<ans; return 0;
		}
	}
	
	for(int i=100;i<=999;i++) 
	{
		if(i<=N) ans++;
		else 
		{
			cout<<ans; return 0;
		}
	}
	
	for(int i=10000;i<=99999;i++) 
	{
		if(i<=N) ans++;
		else 
		{
			cout<<ans; return 0;
		}
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256