akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
template <typename T>inline T read()
{
	register T sum=0;
	char cc=getchar();
	int sym=1;
	while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
	if(cc=='-')sym=-1,cc=getchar();
	sum=sum*10+cc-'0';
	cc=getchar();
	while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
	return sym*sum;
}
template <typename T>inline T read(T &a)
{
	a=read<T>();
	return a;
}
int n,m;
bool isprim(int x,int &k)
{
	for(int i=(int)((double)x/n+0.5);i>=2;i--)
		if(x%i==0)
		{
			if(x/i>=n)
			{
				k=i;
				return false;
			}
		}
	return true;
}
int main()
{
	n=read<int>(),m=read<int>();
	int ans=0;
	if(isprim(m,ans))
		printf("1\n");
	else printf("%d\n",ans);
	return 0;
}


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

#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)

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

	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	int n;
	cin>>n;
	string s;
	cin>>s;
	int pos=s.find('W');
	if (pos==string::npos){
		cout<<0<<endl;
		return 0;
	}
	int cnt=0;
	for (int i=n-1; i>=pos; i--){
		if (s[i]=='R'){
			swap(s[i],s[pos]);
			cnt++;
			pos=s.find('W');
			if (pos==string::npos) break;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3760
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#define mod 1000000007
using namespace std;
typedef long long ll;
ll dp[40000][101][2]={},sum;
int main(){
    int n,k,rn;
    scanf("%d %d",&n,&k);
    dp[1][0][0]=1;
    rn=sqrt(n);
    for(int i=1;i<=k;i++){
        sum=0;
        for(int j=1;j<=rn;j++){
            sum+=dp[j][i-1][0];
            sum%=mod;
            if(j!=rn){
                dp[j][i][1]=sum*(ll)(n/j-n/(j+1));
            }
            else{
                dp[j][i][1]=sum*(ll)(n/j-j);
            }
            dp[j][i][1]%=mod;
        }
        for(int j=rn;j>0;j--){
            sum+=dp[j][i-1][1];
            sum%=mod;
            dp[j][i][0]=sum;
        }
    }
    sum=0;
    
    for(int i=1;i<=rn;i++){
        sum+=dp[i][k][0]+dp[i][k][1];
        sum%=mod;
    }
    printf("%lld\n",sum);
}

Measured memory_bytes: 51328
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,x,y;
    cin>>n>>m;
    ll a[n];
    vector<pair<ll,ll > > b;
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(ll i=0;i<m;i++){
        cin>>x>>y;
        b.pb(make_pair(y,x));
    }
    sort(be(b));
    reverse(be(b));
    ll index=0;
    for(ll i=0;i<m;i++){
        for(ll j=0;j<b[i].second&&index<n&&b[i].first>=a[index];j++){
            a[index]=b[i].first;
            
            index++;
        }
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+=a[i];
    }
    cout << ans<<endl;

    return 0;
}



Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX 1e7
int main(){
    int n;
    while(cin >> n,n){
        vi v(n+1,0);
        vi v2(n+1,0);
        int ans1 = 0; int ans2 =0;
        rep(i,n){
            cin >> v[i] >> v2[i];
            if(v[i]>v2[i])
                ans1+=v[i]+v2[i];
             if(v[i] < v2[i])
                ans2 += v[i]+v2[i];
             if(v[i] == v2[i]){
                ans1+=v[i]; ans2+= v2[i];}
        }
        cout << ans1 << " " << ans2 << endl;
    }
}

Measured memory_bytes: 3176
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<bitset>
typedef long long ll;
double pi=3.1415926535897931159979635;

using namespace std;
int main()
{
char a; cin>>a;
if(a>=97) cout<<"a\n";
else cout<<"A\n";

return 0;

}

Measured memory_bytes: 3628
import numpy as np

n,k,q=map(int,input().split())
li=np.array([k]*n)
li2=np.array([0]*n)

for i in range(q):
    a=int(input())
    li2[a-1]+=1
li3=li+li2-q

for i in li3:
    if i>=1:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 21408
using System;
using System.Linq;

class aizu_judge
{
    static void Main()
    {
        int[] length = System.Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine("{0} {1}",length[0] * length[1],length[0] * 2 + length[1] * 2);
    }
}

Measured memory_bytes: 9564
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
//int dx[4] = { 1,0,0,-1 };
//int dy[4] = { 0,1,-1,0 };
#define MOD 1000000007
#define ARRAY_MAX 55

const int INF = 1e9 + 7;


int main() {


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

	ll a, b;
	cin >> a >> b;


	if (a == b) {
		cout << a << endl;
		return 0;

	}
	ll ans = 0;

	//bit最大は45くらいで
	vector<ll> bit(ARRAY_MAX, 0);

	if ((((b + 1) / 2) % 2) == 1) {
		bit[0] ^= 1;
	}

	//bの各桁のビットを求める
	for (ll i = 45; i > 0; i--) {
		//1桁目は別で調べる
		//i桁目を見る
		ll high = 1LL << (i + 1);//これで割る
		ll low = 1LL << i;
		if (b%high >= low) {
			if ((b%high) % 2 == 0) {
				//この数字まで1が奇数個ある
				bit[i] ^= 1LL;
			}
		}
	}

	a--;//累積和の感覚

	//1桁目
	if ((((a + 1) / 2) % 2) == 1) {
		bit[0] ^= 1LL;
	}

	for (ll i = 45; i > 0; i--) {
		//1桁目は別で調べる
		//i桁目を見る
		ll high = 1LL << (i + 1);//これで割る
		ll low = 1LL << i;
		if (a%high >= low) {
			if ((a%high) % 2 == 0) {
				//この数字まで1が奇数個ある
				bit[i] ^= 1LL;
			}
		}
	}

	for (int i = 0; i <= 45; i++) {
		if (bit[i] == 1) {
			ans += (1LL << i);
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import numpy as np

D = int(input())
c = np.array(list(map(int, input().split())))
s = np.array([list(map(int, input().split())) for x in range(D)])

l_opt = list(range(1, 27)) * (D // 26) + list(range(1, D % 26 + 1))
for l in l_opt:
    print(l)

Measured memory_bytes: 27040
#include<bits/stdc++.h>
using std::cout;
using std::cin;
using std::endl;

int main()
{
    int x, n, C=1, i=0;
    std::vector<int> data(10);
        
    cin>>n>>x;

    while(!((n==0)&&(x==0)))
    {
        int  count=0;
        for (int j = 1; j <= n; j++)
        {
            for (int k = 1; k < j; k++)
            {
                for (int l = 1; l < k; l++)
                {
                    if (j+k+l==x)   
                    {
                        count++;
                    }   
                }   
            }   
        }
        data[i] = count;
   
        cin>>n>>x;    

        if(++i==C*10)
        {
            C++;
            data.resize(count*10);
        }
    }

    for (int j = 0; j < i; j++)
    {
        cout<<data[j]<<endl;
    }


    return 0;
}


Measured memory_bytes: 3120
N,M = [int(x) for x in input().split(' ')]
A=[]
for n in range(N):
    A.append([int(x) for x in input().split(' ')])
total = 0
for price,stock in sorted(A,key= lambda x:x[0]):
    if stock <= M:
        total += stock * price
        M -= stock
    else:
        total += M * price
        break
print(total)


Measured memory_bytes: 23520
MOD = 10**9 + 7

def factorial(x):
	retval = 1
	for i in range(2,x+1):
		retval = (retval * i)% MOD
	return retval

N, M = map(int, input().split())

if abs(N-M)>1:
    print(0)
    exit()


if N==M:
    ans = (factorial(N)*factorial(M)*2)%MOD
else:
    ans = (factorial(N)*factorial(M))%MOD
print(ans)

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

using namespace std;

template <typename T>
using vec1 = vector<T>;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

template <typename T>
vec1<T> cin2vec(size_t size)
{
    vec1<T> vec1;
    for (size_t i = 0; i < size; ++i) {
        vec1.push_back(cin2var<T>());
    }
    return vec1;
}

void sub()
{
    const auto N(cin2var<size_t>());
    const auto Bs(cin2vec<size_t>(N - 1));
    size_t sum = Bs.front();
    size_t prev = sum;
    for (size_t i = 1; i < N; ++i) {
        const auto b = Bs[i];
        sum += min(prev, b);
        prev = b;
    }
    sum += Bs.back();
    cout << sum << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    sub();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <limits>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <vector>
#include <deque>
#include <cmath>

using namespace std;
string s;

int main() {
    cin >> s;
    int mod = 0;
    for (auto c : s) {
        int x = c - '0';
        mod += (x % 9);
    }
    if (mod % 9 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3796
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
a = intl()
a = list(set(a))
if len(a) == 2:
    print("Yes")
else:
    print("No")

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

int main() {
  vector<vector<int>> A(4, vector<int>(4));
  for (int i = 1; i < 4; i++) {
    for (int j = 1; j < 4; j++) {
      cin >> A.at(i).at(j);
    }
  } 
  int N;
  cin >> N;
  vector<int> B(N);
  for (int k = 0; k < N; k++){
    cin >> B.at(k);
    for (int i = 1; i < 4; i++) {
      for (int j = 1; j < 4; j++) {
        if (B.at(k)==A.at(i).at(j)) A.at(i).at(j)=0;
      }
    }
  }
  int ans=0;
  if ((A.at(1).at(1)==0) && (A.at(1).at(2)==0) && (A.at(1).at(3)==0)) ans=1;
  if ((A.at(2).at(1)==0) && (A.at(2).at(2)==0) && (A.at(2).at(3)==0)) ans=1;
  if ((A.at(3).at(1)==0) && (A.at(3).at(2)==0) && (A.at(3).at(3)==0)) ans=1;
  if ((A.at(1).at(1)==0) && (A.at(2).at(1)==0) && (A.at(3).at(1)==0)) ans=1;
  if ((A.at(1).at(2)==0) && (A.at(2).at(2)==0) && (A.at(3).at(2)==0)) ans=1;
  if ((A.at(1).at(3)==0) && (A.at(2).at(3)==0) && (A.at(3).at(3)==0)) ans=1;
  if ((A.at(1).at(1)==0) && (A.at(2).at(2)==0) && (A.at(3).at(3)==0)) ans=1;
  if ((A.at(3).at(1)==0) && (A.at(2).at(2)==0) && (A.at(1).at(3)==0)) ans=1;
  if (ans==1) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <stack>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

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

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(vector<int> arr) {
    int result = arr[0];
    for (auto a: arr) {
        result = gcd(a, result);
    }
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


int dx[5] = {1, 0, -1, 0};
int dy[5] = {0, 1, 0, -1};

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};
ll euler_phi(ll n) {
    ll ret = n;
    for(ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            ret -= ret / i;
            while(n % i == 0) n /= i;
        }
    }
    if(n > 1) ret -= ret / n;
    return ret;
}
int main() {
    ll A, B, K; cin >> A >> B >> K;

    if(A>=K){
        cout << A-K << " " << B << endl;
        return 0;
    }

    if(A+B>=K){
        cout << 0 << " " << A+B-K << endl;
        return 0;
    }

    cout << 0 << ' ' << 0 << endl;
    return 0;
}

Measured memory_bytes: 888
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

int main() {
    int n,m,x;
    cin >> n >> m >> x;
    vector<vector<int>> alg(n,vector<int>(m));
    vector<int> price(n);
    vector<int> total(m,0);
    int ans = 1001001001;

    rep(i,n){
        cin >> price[i];
        rep(j,m){
            cin >> alg[i][j];
            total[j] += alg[i][j];
        }
    }

    for(int bit = 0; bit < (1 << n); bit++){
        bitset<12> s(bit);
        vector<int> sum(m,0);
        int mon = 0;
        rep(i,n){
            if(s.test(i)){
                rep(j,m){
                    sum[j] += alg[i][j];
                }
                mon += price[i];
            }
        }
        bool ok = true;
        rep(i,m){
            if(sum[i] < x) ok = false;
        }
        if(ok) ans = min(ans,mon);
    }
    if(ans == 1001001001) dunk(-1);
    else dunk(ans);
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
int main(){

 int a,b,c,ans[3];

	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);

	if(a < b){
		if(b < c){
			ans[0] = a;
			ans[1] = b;
			ans[2] = c;
		}
		else{
			if(a < c){
				ans[0] = a;
				ans[1] = c;
				ans[2] = b;
			}
			else{
				ans[0] = c;
				ans[1] = a;
				ans[2] = b;
			}
		}
	}else{
		if(a < c){
			ans[0] = b;
			ans[1] = a;
			ans[2] = c;
		}
		else{
			if(b < c){
				ans[0] = b;
				ans[1] = c;
				ans[2] = a;
			}
			else{
				ans[0] = c;
				ans[1] = b;
				ans[2] = a;
			}
		}

	}

	printf("%d %d %d\n",ans[0],ans[1],ans[2]);
	
return 0;
}

Measured memory_bytes: 1804
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

const double eps = 1e-8;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main(){
	ll N;
	cin >> N;
	ll now = 0;
	ll n = 0;
	for (ll i = 1;true;i++) {
		now += i;
		n = i;
		if (now >= N)
			break;
	}
	if (now != N) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
		vector<vector<ll> > ans(n + 1, vector<ll>(n));
		ll cnt = 1;
		for (int k = 0;k < ans[0].size();k++) {
			ans[0][k] = cnt;
			cnt++;
		}
		for (int y = 1;y <= n;y++) {
			for (int k = 0;k < y;k++) {
				ans[y][k] = ans[k][y - 1];
			}
			for (int k = y;k < n;k++) {
				ans[y][k] = cnt;
				cnt++;
			}
		}
		cout << ans.size() << endl;
		for (int y = 0;y < ans.size();y++) {
			cout << ans[y].size() << " ";
			for (int x = 0;x < ans[y].size();x++) {
				cout << ans[y][x];
				if (x == (ll)ans[y].size() - 1)
					cout << endl;
				else
					cout << " ";
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include <iterator>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vector<int> > 
#define vl vector<long long>
#define vc vector<char> 
#define vvc vector<vector<char> > 
#define vpi vector<pair<int,int> >
#define ll long long 
#define sz(a) int(a.size())
#define forn(i,n) for(int i = 0 ; i < int(n) ; i++)
#define all(x) x.begin(),x.end()
#define vpl vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define len(s) s.length()
#define un unsigned
# define M_PI           3.14159265358979323846  /* pi */
#define modulo 998244353ll
#define mod 1000000007ll
#define MAXN  1000001 
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
ll gcd(ll a,ll b){if(a==0 || b == 0) return max(a,b);if(a == 1 || b == 1)return 1;return gcd(max(a,b)%min(a,b),min(a,b));}



void solve()
{
    int x;
    cin>>x;
    int ans = x^1;
    cout<<ans<<endl;    
}


int main()
{
    fast();
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

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

inline int toInt(string s) {
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x) {
    ostringstream sout;
    sout << x;
    return sout.str();
}

#define reps(i, k, n) for (ll(i) = (k); (i) < (n); ++(i))
#define rep(i, n) reps(i, 0, n)
#define debug(x) cerr << x << " (L:" << __LINE__ << ")" << '\n';

#define pb push_back
#define mp make_pair
#define ALL(o) (o).begin(), (o).end()
#define sz(a) (int)((a).size())

#define ll long long
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vs = vector<string>;

const ll MAX = (ll)0x3f0000003f000000;
const int MOD = 1000000007;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
          dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

void solve();
ll ans = 0;

void setup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
}

int main() {
    setup();

    solve();
}

void solve() {
    string s;
    cin >> s;
    int n = (int)s.length();
    rep(i, n) { cout << "x"; }
}

Measured memory_bytes: 256
n,m,k = map(int,input().split())
f = [[] for _ in range(n)]
g = [[] for _ in range(n)]
for _ in range(m):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    f[a].append(b)
    f[b].append(a)
for _ in range(k):
    c,d = map(int,input().split())
    c,d = c-1,d-1
    g[c].append(d)
    g[d].append(c)
d = {}
parent = [-1]*n
seen = [False]*n
from collections import deque
for i in range(n):
    if seen[i]: continue
    stack = deque()
    d[i] = set([i])
    stack = [i]
    while stack:
        v = stack.pop()
        parent[v] = i #同じ連結成分をまとめる
        seen[v] = True
        for nv in f[v]:
            if seen[nv]: continue
            d[i].add(nv)
            stack.append(nv)
ans = [0]*n
for i in range(n):
    group = d[parent[i]]
    #連結成分-直接の友達関係-ブロックしてるけど連結成分にいる人-自分
    sum = len(group)-len(f[i])-len(set(g[i])&group) -1
    ans[i] = sum
print(*ans)

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

const int INF = 1001001001;

int main() {

    int n;
    cin >> n;

    int dig = log10(n) + 1;

    int sum = 0;
    for (int i = 1; i < dig; i++) {
        if (i % 2 == 0) {
            continue;
        }
        int p = round(pow(10, i - 1));
        int add = p * 9;
        sum += add;
    }

    if (dig % 2 == 1) {
        int other = n - pow(10, dig - 1) + 1;
        sum += other;
    }

    cout << sum << endl;

}


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

using namespace std;
using ll = long long int;

int main()
{
  ll a, b, c;
  cin >> a >> b >> c;
  ll ab = a + b;
  if (ab + 1 >= c) {
    cout << b + c << endl;
  }else{
    cout << b + ab + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>

using namespace std;

int main(){

	int n,start,goal,height,table[10],to_change,min_row,min_col;
	char buf[30][11];
	bool FLG;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i = 0; i < n; i++)table[i] = i;

		scanf("%d",&start);
		start--;

		scanf("%d",&goal);
		goal--;

		scanf("%d",&height);

		for(int i = 0; i < height; i++){
			scanf("%s",buf[i]);
			for(int k = 0; buf[i][k] != '\0';k++){
				if(buf[i][k] == '1'){
					swap(table[k],table[k+1]);
				}
			}
		}

		if(table[goal] == start){
			printf("0\n");
		}else{
			to_change = table[goal];

			for(int i = 0; i < n; i++)table[i] = i;

			FLG = false;
			for(int i = 0; i < height; i++){

				for(int k = 0; k <= n-2; k++){
					if((table[k] == start && table[k+1] == to_change) || (table[k] == to_change && table[k+1] == start)){
						if(k == 0){
							if((n == 2 && buf[i][k] == '0') || (n > 2 && buf[i][k] == '0' && buf[i][k+1] == '0')){
								min_row = i;
								min_col = k;
								FLG = true;
								break;
							}
						}else{
							if((k < n-2 && buf[i][k-1] == '0' && buf[i][k] == '0' && buf[i][k+1] == '0') ||
									(k == n-2 && buf[i][k-1] == '0' && buf[i][k] == '0')){
								min_row = i;
								min_col = k;
								FLG = true;
								break;
							}
						}
					}
				}
				if(FLG)break;

				for(int k = 0; buf[i][k] != '\0';k++){
					if(buf[i][k] == '1'){
						swap(table[k],table[k+1]);
					}
				}
			}

			if(!FLG)printf("1\n");
			else{
				printf("%d %d\n",min_row+1,min_col+1);
			}

		}

	}

	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
    int a, b;
    cin >> a >> b;
	if(a-2*b<0) cout << 0 << endl;
  	else cout << a-2*b << endl;   	 
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
#include<functional>
#include<memory>
template<typename S> class SegmentTreeD {
 public:
  using Size = long long;
  using FS = std::function<S(S, S)>;
  SegmentTreeD(Size L, Size R, FS fs, S es) : L(L), R(R), fs(fs), es(es), root(std::make_unique<Node>(es)) {}
  void set(Size a, S x) {set(a, x, root, L, R);}
  S query(Size a, Size b) {return query(a, b, root, L, R);}
 private:
  struct Node {
    S val;
    std::unique_ptr<Node> lchild, rchild;
    Node(S val) : val(val), lchild(nullptr), rchild(nullptr) {}
  };
  void set(Size a, S x, const auto &n, Size l, Size r) {
    if(l+1 == r) {
      n->val=x;
      return;
    }
    if(n->lchild == nullptr) n->lchild = std::make_unique<Node>(es);
    if(n->rchild == nullptr) n->rchild = std::make_unique<Node>(es);
    auto m = (l + r) / 2;
    if(a < m) set(a, x, n->lchild, l, m);
    else      set(a, x, n->rchild, m, r);
    n->val = fs(n->lchild->val, n->rchild->val);
  }
  S query(Size a, Size b, const auto &n, Size l, Size r) {
    if(n == nullptr)     return es;
    if(b <= l || r <= a) return es;
    if(a <= l && r <= b) return n->val;
    auto m = (l + r) / 2;
    auto vl = query(a, b, n->lchild, l, m);
    auto vr = query(a, b, n->rchild, m, r);
    return fs(vl, vr);
  }
  Size L, R;
  std::unique_ptr<Node> root;
  FS fs;
  S es;
};

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

using LL = long long;

const LL M = 998244353;
const LL INF = 1e9+1;

LL power(LL m, LL n) {
  if(!n) return 1;
  return (n & 1) ? (power(m, n - 1) * m % M) : power(m * m % M, n >> 1);
}

int main() {
  struct Point {LL x, y, ul, ur, ll, lr;};
  int N;
  cin >> N;
  vector<Point> P(N);
  for(auto& i: P) cin >> i.x >> i.y;

  sort(begin(P), end(P), [](auto& l, auto& r){
    if(l.x != r.x) return l.x < r.x;
    return l.y < r.y;
  });
  SegmentTreeD<int> rsq(-INF, INF, plus<int>(),0);
  for(auto& p: P) {
    p.ll = rsq.query(-INF,  p.y+1);
    p.ul = rsq.query(p.y+1, INF);
    rsq.set(p.y, 1);
  }

  sort(begin(P), end(P), [](auto& l, auto& r){
    if(l.x != r.x) return l.x > r.x;
    return l.y > r.y;
  });
  rsq = SegmentTreeD<int>(-INF, INF, plus<int>(),0);
  for(auto& p: P) {
    p.ur = rsq.query(p.y,  INF);
    p.lr = rsq.query(-INF, p.y);
    rsq.set(p.y, 1);
  }

  LL ans = 0;
  for(auto& p: P) {
    (ans += power(2,N-1)) %= M;
    auto urll = (power(2,p.ur)-1) * (power(2,p.ll)-1) % M;
    auto ullr = (power(2,p.ul)-1) * (power(2,p.lr)-1) % M;
    (ans += urll * power(2,N-1-p.ur-p.ll) % M) %= M;
    (ans += ullr * power(2,N-1-p.ul-p.lr) % M) %= M;
    (ans += M - (urll*ullr%M) * power(2,N-1-p.ur-p.ll-p.ul-p.lr)%M) %= M;
  }
  cout << ans << endl;
}


Measured memory_bytes: 180412
import sys
input = sys.stdin.readline
n, d = map(int,input().split())
C = [list(map(int,input().split())) for i in range(n)]

def dfs_numbering(st, M, V, ANS, cnt, v):
    ST = [st]
    while len(ST) > 0:
        i = ST[-1]
        if ANS[i] == -1:
            V[i] = v
            end = 1
            for x in M[i]:
                if V[x] == -1:
                    ST.append(x)
                    end = 0
            if end == 1:
                ST.pop()
                ANS[i] = cnt
                cnt += 1
        else:
            ST.pop()
    return cnt

class scc():  # 有向グラフを強連結成分分解（互いに行き来できる領域ごとに区切る）する。
    def __init__(self, n):  # 頂点数nのグラフを作成
        self.n = n
        self.M = [[] for i in range(n)]
        self.IM = [[] for i in range(n)]

    def add_edge(self, frm, to):  # frm->toの辺を追加
        self.M[frm].append(to)
        self.IM[to].append(frm)

    def scc_list(self):  # 連結成分ごとの頂点リストを返す
        n = self.n
        V = [-1] * n
        ANS = [-1] * n

        cnt = 0
        for i in range(n):
            if V[i] == -1:
                cnt = dfs_numbering(i, self.M, V, ANS, cnt, 0)

        ANS1 = [[ANS[i], i] for i in range(n)]
        ANS1.sort(reverse=True)

        V = [-1] * n
        ANS = [-1] * n
        v = 0
        for i in range(n):
            if V[ANS1[i][1]] == -1:
                dfs_numbering(ANS1[i][1], self.IM, V, ANS, 0, v)
                v += 1

        FANS = [[] for i in range(v)]
        for i in range(n):
            FANS[V[i]].append(i)

        return FANS

class twosat():
    def __init__(self, n):
        self.n = n
        self.S = scc(2*n)
        self.ANS = [True] * n

    def add_clause(self, i, f, j, g):
        fb = (int(f) + 1) % 2
        gb = (int(g) + 1) % 2
        self.S.add_edge(2*i + fb, 2*j + g)
        self.S.add_edge(2*j + gb, 2*i + f)

    def satisfiable(self):
        n = self.n
        sl = self.S.scc_list()
        A = [-1] * (2*n)
        for i in range(len(sl)):
            for j in range(len(sl[i])):
                A[sl[i][j]] = i
        
        for i in range(n):
            if A[2*i] == A[2*i+1]:
                return False
            self.ANS[i] = A[2*i] < A[2*i+1]
        return True

    def answer(self):
        return self.ANS

T = twosat(n)
for i in range(n):
    for j in range(i+1, n):
        # print(i,j)
        for k in range(2):
            for l in range(2):
                if abs(C[i][k] - C[j][l]) < d:
                    # print(i, (k+1)%2, j, (l+1)%2)
                    T.add_clause(i, (k+1)%2, j, (l+1)%2)

sa = T.satisfiable()
if sa:
    print("Yes")
    ANS = T.answer()
    for i in range(n):
        print(C[i][int(ANS[i])])
else:
    print("No")

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

class Line{
public:
  int x;
  int y;
  int d;
  Line(int _x,int _y,int _d){
	x=_x;
	y=_y;
	d=_d;
  }
};

int main(){
  int L;
  cin >> L;
  int r=0;
  int x=1;
  for(int i=0;i<20;i++){
	x*=2;
	r++;
	if(x*2>L){
	  break;
	}
  }

  vector<Line> v;
  for(int i=0;i<r;i++){
	Line t1(i,i+1,0);
	Line t2(i,i+1,1<<i);
	v.push_back(t1);
	v.push_back(t2);
  }
  for(int i=r-1;i>=0;i--){
	if(L-(1<<i)>=(1<<r)){
	  Line t(i,r,L-(1<<i));
	  v.push_back(t);
	  L-=(1<<i);
	}
  }
  cout << (r+1) << " " << v.size() << endl;
  for(int i=0;i<v.size();i++){
	cout << v[i].x+1 << " " << v[i].y+1 << " " << v[i].d << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int N;
   cin >> N;
   double ans = 0.;
   double a = 0.;
   for (int i = 0; i < N; i++) {
      cin >> a;
      ans += 1. / a;
   }
   
   cout << fixed << setprecision(6) << 1. / ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
//#include"stdc++.h"
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  ll n,k;
  cin>>n>>k;
  string s;
  cin>>s;

  auto t=s[0];

  auto idx=0;
  auto cnt=0;

  while(idx<n){

    auto c=s[idx];
    //cout << idx << "," << c << endl;
    if(c!=t){
      cnt++;
      //cout << "while start" << endl;
      while(s[idx]!=t && idx<n){
        //cout << "idx: " << idx << endl;
        s[idx]=t;
        idx++;
      }
      //cout << "while end" << endl;
    }
    if(cnt>=k) break;
    idx++;
  }
  //cout << s << endl;
  ll ans=n;
  char prev=-1;
  for(auto c:s){
    if(prev!=c){
      ans--;
    }
    prev=c;
  }

  cout << ans << endl;

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define io ios_base::sync_with_stdio(0);cin.tie(0);
#define mod 1000000009
#define pi 2*acos(0)
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
using namespace std;


int main()
{

	io;
	
	int a, b; cin >> a >> b;
	int arr[4] = { 0 };
	arr[a] = 1;
	arr[b] = 1;
	for (int i = 1; i <= 3; i++)
		if (!arr[i])
			cout << i;
}



Measured memory_bytes: 3656
#include <stdio.h>
int main(){
  int N,A[100000],i,j=0,k=0,x,temp,l;
  scanf("%d",&N);
  for(i=0;i<N;i++)
    scanf("%d",&A[i]);
  x=A[N-1];
  for(i=0;i<N;i++){
    if(A[i]>x)j++;
    else{
      if(i==N-1)
        l=k;
      temp=A[k];
      A[k]=A[i];
      A[i]=temp;
      k++;
    }
  }
  for(i=0;i<N;i++){
    if(l==i){
      printf("[");
      printf("%d",x);
      printf("]");
    }else printf("%d",A[i]);
    if(i==N-1){
      printf("\n");
      break;
    }
    printf(" ");
  }
  return 0;
}




Measured memory_bytes: 2104
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner input  = new Scanner(System.in);
		int N = input.nextInt();
		int A = input.nextInt();
		int B = input.nextInt();
		input.nextLine();
		String S = input.nextLine();
		input.close();	
		int curNum = 0;
		int overNum = 0;
		for(int i = 0; i < N;i++){
			if(S.charAt(i)=='c') {
				System.out.println("No");
			}else if (S.charAt(i)=='a'){
				if(curNum < (A+B)){
					System.out.println("Yes");
					curNum++;
				}else System.out.println("No");
			}else{
				if(curNum < (A+B) && overNum < B){
					System.out.println("Yes");
					curNum++;
					overNum++;
				}else System.out.println("No");
			}
		}
		
	}


}


Measured memory_bytes: 23920
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
allpat=[]
todo=[[]]
while todo:
  pat=todo.pop()
  if len(pat)==n//2:
    allpat.append(pat)
    continue
  s=0
  if pat:s=max(pat)+1
  for i in range(s,n):
    todo.append(pat+[i])

def func(pat):
  # カードを最終的に偶奇どちらのidxになるかで分類
  # pat内のidxが最後に奇数のidxになるとする
  ablev=[]
  ablod=[]
  for i in range(n):
    if i in pat:
      if i%2==0:
        ablod.append([i,b[i]])
      else:
        ablod.append([i,a[i]])
    else:
      if i%2==0:
        ablev.append([i,a[i]])
      else:
        ablev.append([i,b[i]])
  ablev.sort(key=lambda x:x[1]*20+x[0])
  ablod.sort(key=lambda x:x[1]*20+x[0])
  now=0
  ary=[]
  for i in range(n//2):
    if ablev[i][1]>=now:
      now=ablev[i][1]
      ary.append(ablev[i][0])
    else:
      return -1
    if ablod[i][1]>=now:
      now=ablod[i][1]
      ary.append(ablod[i][0])
    else:
      return -1
  if n%2==1:
    if ablev[n//2][1]>=now:
      now=ablev[i][1]
      ary.append(ablev[n//2][0])
    else:
      return -1
  ret=0
  for i in range(n-1):
    for j in range(i+1,n):
      if ary[i]>ary[j]:ret+=1
  return ret

ans=float('inf')
for pat in allpat:
  t=func(pat)
  if t>=0:
    ans=min(ans,t)
print(ans if ans!=float('inf') else -1)


Measured memory_bytes: 16504
/*
 
 
  author:@Prashant Singh
  created on :04/09/2019
 
 
 
*/
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
 
#define mod 1000000007
#define pb push_back
#define endl cout<<"\n";
#define prt1(a) cout<<a<<" ";
#define prt2(a,b) cout<<a<<" "<<b<<" ";
#define prt3(a,b,c) cout<<a<<" "<<b<<" "<<c<<" ";
#define rep(i,st,end) for(int i=st;i<(int)end;i++)
#define repv(i,st,end) for(int i=st;i>=end;i--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
int main()
 {
  fio;
     ll tc,n,k,t,j,l,i,d,e,r;
      tc=1;
     // cin>>tc;
      while(tc--)
      {
       cin>>n>>k;
       string na;
       cin>>na;
       ll c=0;
       rep(i,0,n-1)
       {
        if(na[i]!=na[i+1])
          c++;
       }
            ll it=0;
       cout<<n-1-max(it,c-2*k);

 
    }
  return 0;
}
  


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll inf=(ll)1e6*1e6;

struct info{
	ll len, val, up_min, down_min;
	info(): len(1), val(inf), up_min(val), down_min(val){}
	info(ll x): len(1), val(x), up_min(x), down_min(x){}
	info(info& a, info& b):
		len(a.len + b.len),
		val(-1),
		up_min(min({a.up_min, a.len + b.up_min, inf})),
		down_min(min({a.down_min + b.len, b.down_min, inf})){} };

struct arbint{
	ll n, big_delta = 0;
	vector<info> buf;
public:
	arbint(ll N): n(1 << (ll)ceil(log2(N))), buf(2*n){
		for(ll i = n-1; i; --i) buf[i] = info { buf[2*i], buf[2*i+1] }; }
	void update_delta(ll x){ big_delta += x; }
	void update(ll poz, ll new_val){
		buf[poz+=n] = info { new_val - big_delta };
		for(poz /= 2; poz; poz /= 2)
			buf[poz] = info { buf[2*poz], buf[2*poz+1] }; }
	info query(ll st, ll dr){
		info rez_st, rez_dr;
		rez_st.len = rez_dr.len = 0;
		for(st += n, dr += n+1; st < dr; st /= 2, dr /= 2){
			if(st%2) rez_st = info { rez_st, buf[st++] };
			if(dr%2) rez_dr = info { buf[--dr], rez_dr }; }
		auto rez = info { rez_st, rez_dr };
		rez.up_min += big_delta;
		rez.down_min += big_delta;
		return rez; }
	ll full_query(){
		ll rez = inf;
		for(ll i = n; i < 2*n; ++i) rez = min(rez, buf[i].val + big_delta);
		return rez; } };

int main(){
	ll n, q, a, b;
	cin >> n >> q >> a >> b;
	arbint aa(n + 100);
	ll p0 = a;
	aa.update(b, 0);

	for(ll i = 0, x; i < q; ++i){
		cin >> x;
		ll other_cost = min<ll>(
			aa.query(1, x).down_min,
			aa.query(x, n).up_min);
		ll prev_cost = max(p0 - x, x - p0);
		
		aa.update_delta(prev_cost);
		aa.update(p0, other_cost);
		p0 = x; }
	cout << aa.full_query() << endl;
	return 0; }


Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define deque vector
void Oli(){
    ll n;
    cin>>n;
    vector<ll> b(n);
    for(ll i=0;i<n;i++){
        cin>>b[i];
    }
    ll s=0;
    ll mn = b[0];
    for(ll i=1;i<n;i++){
        if (b[i]<=mn){
            s+=mn - b[i];
        }else {
            mn = b[i];
        }
    }
    cout<<s<<endl;
}
int main(){
int times = 1;
//cin>>times;
while(times--)
Oli();
}


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

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main() 
{
	int N, X;
	vector<int> x;
	cin >> N >> X;
	x.push_back(X);
	for (int i = 0; i < N; i++) {
		int xx;
		cin >> xx;
		x.push_back(xx);
	}
	sort(x.begin(), x.end());
	vector<int> diff;
	for (int i = 0; i < N; i++) diff.push_back(x[i + 1] - x[i]);
	int ans = diff[0];
	for (int i = 1; i < N; i++) ans = gcd(ans, diff[i]);
	cout << ans << "\n";
		
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	int n;
	int d[300000];
	string s;
	cin >> n;
	cin >> s;
	if(s[0] == 'W'){
		d[0] = 1;
	}else{
		d[0] = 0;
	}
	for(int i = 1;i < n;i++){
		if(s[i] == 'W'){
			d[i] = d[i - 1] + 1;
		}else{
			d[i] = d[i - 1];
		}
	}
	int a = (n - 1) - (d[n - 1] - d[0]);
	for(int i = 1;i < n - 1;i++){
		a = min(a, d[i - 1] + (n - (i + 1)) - (d[n - 1] - d[i]));
	}
	a = min(a, d[n - 2]);
	cout << a << endl;
}

Measured memory_bytes: 1796
S = gets.strip

o, e = S.chars.each_slice(2).each_with_object([[], []]){|(a, b), o| o[0] << a; o[1] << b }
puts o.all?{|c| c != 'L'} && e.all?{|c| c != 'R'} ? 'Yes' : 'No'

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

int main() {
	int n;
	int a, b, c;
	for(cin>>n; n>0; --n) {
		cin>>a>>b>>c;
		
		int p;
		if(a>b) {
			p=a;
			a=b;
			b=p;
		}

		if(b>c) {
			p=b;
			b=c;
			c=p;
		}
		if(a>b) {
			p=a;
			a=b;
			b=p;
		}

		//cout<<a<<b<<c<<endl;
		if(a*a + b*b == c*c) {
			cout<<"YES"<<endl;
		} else {
			cout<<"NO"<<endl;
		}
	}
}

Measured memory_bytes: 0
n, m = gets.chomp.split(" ")
n = n.to_i
m = m.to_i
l_max = 1
r_min = 100000
m.times do |i|
  l,r = gets.chomp.split(" ")
  if l.to_i > l_max
     l_max = l.to_i
  end
  if r.to_i < r_min
     r_min = r.to_i
  end
end

if r_min >= l_max
  puts( r_min-l_max+1)
else
  puts(0)
end

Measured memory_bytes: 3836
n,x,y = map(int, input().split())
k = [0] * n
for i in range(1,n):
  for j in range(i+1,n+1):
    index = min(j-i,abs(x-i)+abs(y-j)+1)
    k[index] += 1
for i in k[1:]:
  print(i)

Measured memory_bytes: 47324
package main

import (
    "bufio"
    "fmt"
    "os"
)

func scanBytes(scanner *bufio.Scanner) (bs []byte) {
    if scanner.Scan() {
        return scanner.Bytes()
    }
    return
}

func isBeautiful(w []byte) bool {
    if len(w) & 1 != 0 {
        return false
    }
    m := make(map[byte] bool)
    for _, b := range w {
        m[b] = !m[b]
    }
    for _, v := range m {
        if v {
            return false
        }
    }
    return true
}

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)

    w := scanBytes(scanner) // 1 <= |w| <= 100
    if isBeautiful(w) {
        fmt.Println("Yes")
    } else {
        fmt.Println("No")
    }
}


Measured memory_bytes: 640
for i in range (10000000000000):
    H,W = list(map(int,input().split()))
    if H == 0 and W == 0:
        break
    else:
        for i in range (H):
            for j in range(W):
                if (i + j) % 2 == 0:
                    print("#" ,end = "")
                else:
                    print("." ,end = "")
            print()
        print()    


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

using namespace std;

int main()
{
	long long n;
	cin >> n;
	
	vector<int> x;
	long long tmp = n;
	while(tmp != 0)
	{
		x.insert(x.begin(), tmp % 10);
		tmp /= 10;
	}
	
	int ans = 0;
	for(int i = 1; i < x.size(); i++)
	{
		if(x[i] == 9)
		{
			ans += x[i - 1];
			if(i == x.size() - 1)
			{
				ans += 9;
			}
		}
		else
		{
			ans += x[i - 1] - 1;
			ans += (x.size() - i) * 9;
			break;
		}
	}
	
	if(x.size() == 1)
	{
		ans = x[0];
	}
	
	cout << ans << endl;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    vector<int> h(n);
    vector<bool> used(n, false);
    priority_queue<pair<int,int>> tar;
    vector<vector<int>> edge(n, vector<int>());
    for(int i=0;i<n;i++){
        cin >> h[i];
        tar.push({h[i], i});
    } 
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    int ans = 0;
    while(!tar.empty()){
        int height, node;
        tie(height, node) = tar.top();tar.pop();
        if(used[node]) continue;
        bool good = true;
        for(auto e: edge[node]){
            if(h[e] >= height) good = false;
            if(h[e] <= height) used[e] = true;
        }
        if (good) ans ++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9684
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
//const int P=139;
const int p=1e9+7;
const int maxn=1e6+5;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int minn=0xc0c0c0c0;
ll ksm(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=ans*a%p;
		a=a*a%p;
		b>>=1;
	}
	return ans%p;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    cout<<(ksm(10,n)+ksm(8,n)-2*ksm(9,n)+2*p)%p<<endl;
    return 0;
}

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

int main() {
	int n, a[100], num = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		int tmp = a[i], j;
		for (j = i - 1; j >= 0 && tmp < a[j];j--) {
			a[j + 1] = a[j];
			num++;
		}
		a[j + 1] = tmp;
	}
	for (int i = 0; i < n - 1; i++) {
		cout << a[i] << " ";
	}
	cout << a[n - 1] << endl << num << endl;

	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int INF = 100000000;
int n, x[10001][2], list[4], save[10001], l1 = 0, l2 = 0, ans = INF;
vector<int> v1, v2, v3;
int solve(int a){
	l1 = 0; l2 = 0;
	for (int i = 1; i < v2.size(); i++){
		if (v2[a + i] == v2[a]){
			l1++;
		}
		else
			break;
	}
	for (int i = 1; i < v2.size(); i++){
		if (v2[a - i] == v2[a]){
			l2++;
		}
		else
			break;
	}
	if (l1 + l2 >= 3){
		v2.erase(v2.begin() + a - l2, v2.begin() + a + l1 + 1);
		solve(a - l2-1);
	}
	else{
		return v2.size();
	}
}
int main(){
	while (true){
		cin >> n;
		if (n == 0){
			break;
		}
		for (int i = 1; i <= n; i++){
			cin >> x[i][0];
			v1.push_back(x[i][0]);
			if (i - list[x[i][0]] == 2){
				save[i - 1] = 2;
			}
			list[x[i][0]] = i;
			if (x[i][0] == x[i - 1][0] && x[i][0] == x[i - 2][0]){
				save[i + 1] = 1;
				save[i - 3] = 1;
			}
		}
		for (int i = 1; i <= n; i++){
			if (save[i] == 1){
				v2 = v1;
				v2.erase(v2.begin() + i - 1);
				if (x[i + 1][0] == x[i + 2][0] && x[i + 1][0] == x[i + 3][0]){
					v2.insert(v2.begin() + i - 1, x[i + 1][0]);
				}
				else if (x[i - 1][0] == x[i - 2][0] && x[i - 1][0] == x[i - 3][0]){
					v2.insert(v2.begin() + i - 1, x[i - 1][0]);
				}
				ans = min(solve(i - 1), ans);
			}
			else if (save[i] == 2 && x[i + 1][0] == x[i + 2][0]){
				v2 = v1;
				v2.erase(v2.begin() + i - 1);
				v2.insert(v2.begin() + i - 1, x[i + 1][0]);
				ans = min(solve(i - 1), ans);
			}
			else if (save[i] == 2 && x[i - 1][0] == x[i - 2][0]){
				v2 = v1;
				v2.erase(v2.begin() + i - 1);
				v2.insert(v2.begin() + i - 1, x[i - 1][0]);
				ans = min(solve(i - 1), ans);
			}
			else save[i] = 0;
		}
		cout << ans << endl;
		for(int i=1;i<=n;i++){
			x[i][0]=0;
			save[i]=0;
		}
		list[0]=0;
		list[1]=0;
		list[2]=0;
		list[3]=0;
		ans=INF;
		v1=v3;
	}
	return 0;
}

Measured memory_bytes: 1440
n, a, b = map(int, input().split())
total = 0
for i in range(1,n+1):
    i_remember = i
    sum = 0
    for j in range(1, 6):
        if 10**(j-1) <= i <10**j:
            temp = 0
            for k in range(j,0,-1):
                temp = i // 10**(k-1)
                sum += temp
                i -= temp*(10**(k-1))
    if a <= sum <=b:
        total += i_remember
print(total)

Measured memory_bytes: 3316