akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
        #define ll    long long
        #define lld long double
        #define hell  998244353 
         
        using namespace std;
         
         
         
        int main()
        {
        	ios::sync_with_stdio(0);
        	cin.tie(0);
        	cout.tie(0);
     ll n;
	 cin>>n;
	 vector <ll> v(n+1);
	 vector <ll> q(n);
	 for(ll i=0;i<=n;i++)
	 cin>>v[i];
	 for(ll i=0;i<n;i++)
	 cin>>q[i];   
        
        ll ans=0;
        for(ll i=0;i<=n;i++)
        {
        	if(i==0)
        	{ans+=min(v[i],q[i]);
        	q[i]-=ans;
			}
			else if(i==n)
			{
				ans+=min(v[i],q[i-1]);
				
			}
        	else
        	{
        		ans+=min(v[i],q[i-1]);
        		v[i]-=min(v[i],q[i-1]);
        		ans+=min(v[i],q[i]);
        		q[i]-=min(v[i],q[i]);
			}
		}
        cout<<ans<<endl;
    }

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int b[200010] = {};
    int w[200010] = {};

    for(int i = 0;i < n;i++){
        b[i+1] += b[i];
        w[i+1] += w[i];
        if(s[i] == '#'){
            b[i+1]++;
        }else{
            w[i+1]++;
        }
    }

    int ans = INT_MAX;
    for(int i = 0;i <= n;i++){
        ans = min(ans, b[i]+w[n]-w[i]);
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
	
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
     
      long long n,i,j,k,sum=0,count=0,ans=0,x,y,l,r;
      cin>>n>>k;
      long long a[n];
      for(i=0;i<n;i++)
      {
          cin>>a[i];
      }
      sort(a,a+n);
      for(i=0;i<k;i++)
      sum+=a[i];
      cout<<sum;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a;
    cin >> a ;
    //*/
    
    /*
    vector<int> vec(4);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    
    sort(vec.begin(), vec.end());
    */
    
    /*
    if(a == 0){
        cout << "" << endl;
    } else if(a > 0){
        cout << "" << endl;
    } else {
        cout << "" << endl;
    }
    */
    
    cout << 48 - a << endl;

    return 0; 
}


Measured memory_bytes: 3580
while True:
    e=int(input())
    if e==0:
        break
    m=e
    z=0
    while z**3<=e:
        y=int((e-z**3)**.5)
        x=e-z**3-y**2
        m=min(m,x+y+z)
        z+=1
    print(m)

Measured memory_bytes: 7884
#include <bits/stdc++.h>
using namespace std;
const int MAX = 50;
int N, M;
bool graph[MAX][MAX];
bool visited[MAX];

void dfs(int v) {
  visited[v] = true;
  for (int i = 0; i < N; ++i) {
    if (graph[v][i] == false) continue;
    if (visited[i] == true) continue;
    dfs(i);
  }
}

int main() {
  cin >> N >> M;
  vector<int> a(M);
  vector<int> b(M);
  for (int i = 0; i < M; ++i) {
    cin >> a[i];
    cin >> b[i];
    a[i]--;
    b[i]--;
    graph[a[i]][b[i]] = true;
    graph[b[i]][a[i]] = true;
  }

  int ans = 0;
  for (int i = 0; i < M; ++i) {
    graph[a[i]][b[i]] = false;
    graph[b[i]][a[i]] = false;
    for (int j = 0; j < N; ++j) visited[j] = false;

    dfs(0);
    bool isBridge = false;
    for (int j = 0; j < N; ++j) {
      if (visited[j] == false) isBridge = true;
    }
    if (isBridge) ans += 1;
    graph[a[i]][b[i]] = true;
    graph[b[i]][a[i]] = true;    
  }

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


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  string s;
  cin >> s;
  cout << (s == "ABC" ? "ARC" : "ABC") << endl;
}


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

#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define fp(i,a,b) for(int i=a ; i<b ; i++)
#define fn(i,a,b) for(int i=a ; i>=b ; i--)
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

const int M=1e5+5;
const ll INF=1e15;
const int MOD=1e9+5;

int n,m,r;
int dp[M];
vi vec[M];

int DP(int x){
	if (dp[x] != -1) return dp[x];
	dp[x] = 0;
	fp(i,0,vec[x].size()) dp[x] = max(dp[x] , DP(vec[x][i]) + 1);
	return dp[x];
}

int main(){

	fastio;
	cin >> n >> m;
	fp(i,1,n+1) dp[i] = -1;

	while (m--){
		int x,y; cin >> x >> y;
		vec[x].pb(y);
	}

	fp(i,1,n+1)
		if (dp[i] == -1) r = max(r,DP(i));

	cout << r << "\n";

	return 0;
}


Measured memory_bytes: 11496
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
const int LIMIT = 1e9 + 7;
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()


namespace /* ZahyoComp.cpp */ {


  template<class T>
  vector<T> compress(vector<T> &V1, vector<T> &V2){
    //2つのVを一緒くたにして各々圧縮する 重複削除ソート列Sを返す
    vector<T> S;
    int N = V1.size();
    copy(V1.begin(), V1.end(), back_inserter(S));
    copy(V2.begin(), V2.end(), back_inserter(S));

    sort(S.begin(), S.end());
    S.erase( unique(S.begin(), S.end()), S.end() );
    for(int i=0; i<N; i++){
      V1[i] = lower_bound(S.begin(), S.end(), V1[i]) - S.begin();
      V2[i] = lower_bound(S.begin(), S.end(), V2[i]) - S.begin();
    }
    return S;
  }
}

int main(){
	int N,K;cin>>N>>K;
  vi X1(N), X2(N), Y1(N), Y2(N), D1(N), D2(N);
  rep(i,N){
    cin>>X1[i]>>Y1[i]>>D1[i]>>X2[i]>>Y2[i]>>D2[i];
  }

  //座標圧縮
  vi X = compress(X1, X2);
  vi Y = compress(Y1, Y2);
  vi D = compress(D1, D2);

  int XX = X.size();
  int YY = Y.size();
  int DD = D.size();

  //DEBUG(XX,YY,DD);
  //DEBUG(X1);DEBUG(X2);DEBUG(Y1);DEBUG(Y2);DEBUG(D1);DEBUG(D2);

  vector<vector<vi>> sea(XX, vector<vi>(YY, vi(DD, 0)));

  rep(i,N){
    //いもす法3D
    //上面
    sea[X1[i]][Y1[i]][D1[i]]++;
    sea[X1[i]][Y2[i]][D1[i]]--;
    sea[X2[i]][Y1[i]][D1[i]]--;
    sea[X2[i]][Y2[i]][D1[i]]++;
    //下面
    sea[X1[i]][Y1[i]][D2[i]]--;
    sea[X1[i]][Y2[i]][D2[i]]++;
    sea[X2[i]][Y1[i]][D2[i]]++;
    sea[X2[i]][Y2[i]][D2[i]]--;
  }

  //累積和
  for(int i=1; i<XX; i++){
    for(int j=0; j<YY; j++){
      for(int k=0; k<DD; k++){
        sea[i][j][k] += sea[i-1][j][k];
      }
    }
  }
  for(int i=0; i<XX; i++){
    for(int j=1; j<YY; j++){
      for(int k=0; k<DD; k++){
        sea[i][j][k] += sea[i][j-1][k];
      }
    }
  }
  for(int i=0; i<XX; i++){
    for(int j=0; j<YY; j++){
      for(int k=1; k<DD; k++){
        sea[i][j][k] += sea[i][j][k-1];
      }
    }
  }

  /*
  rep(k,DD){
    rep(i,XX){
      rep(j,YY){
        cout<<sea[i][j][k];
      }
      cout<<endl;
    }
    cout<<"-----"<<endl;
  }
  //*/

  //実体積計算
  ll ans = 0;
  rep(i,XX)rep(j,YY)rep(k,DD){
    if(sea[i][j][k] >= K){
      ll lx = X[i+1] - X[i];
      ll ly = Y[j+1] - Y[j];
      ll ld = D[k+1] - D[k];
      ans += lx * ly * ld;
      //DEBUG(lx,ly,ld,ans);
    }
  }
  cout<<ans<<endl;
}


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

int main() {
  int A, B, M; cin >> A >> B >> M;
  vector<int> a(A), b(B), x(M), y(M), c(M);
  const int INF = 100005;
  int amin = INF, bmin = INF;
  rep(i,A) {
    cin >> a[i];
    amin = min(amin, a[i]);
  }
  rep(i,B) {
    cin >> b[i];
    bmin = min(bmin, b[i]);
  }
  int ans = amin + bmin;
  rep(i,M) {
    cin >> x[i] >> y[i] >> c[i];
    ans = min(ans, a[x[i]-1] + b[y[i]-1] -c[i]);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int n, ans=0, mx=0; cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i]; ans += p[i];
        mx = max(mx, p[i]);
    }
    cout << ans - mx/2 << endl;
    return 0;
}


Measured memory_bytes: 256
k = int(input())
import itertools
def GCD(a,b):
    if(a%b == 0):
        return b
    else:
        return GCD(b,a%b)
total = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            total += GCD(GCD(a,b),c)
print(total)

Measured memory_bytes: 79736
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<string>s(n);
  for (int i=0; i<n; i++) cin>>s[i];
  int AC=0;
  int WA=0;
  int TLE=0;
  int RE=0;
  for (int i=0; i<n; i++){
    if (s[i]=="AC") AC++;
    if (s[i]=="WA") WA++;
    if (s[i]=="TLE") TLE++;
    if (s[i]=="RE") RE++;
  }
  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
}

Measured memory_bytes: 6404
X,K,D = map(int,input().split())
cand = []
X=abs(X)
if X//D<=K and (X//D-K)%2==0:
    cand.append(X%D)
if X//D+1<=K and (X//D-K)%2==1:
    cand.append(abs(X%D-D) )
    
if cand:
    ans = min(cand)
else:
    ans = min(X-K*D, X+K*D)
print(ans)

Measured memory_bytes: 61608
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<climits>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    int x, y;
    int n; cin >> n;
    x = n * 800;
    y = n / 15 * 200;
    cout << x - y << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#define N_MAX (100000)
#define min(a,b) (((a)<(b))?(a):(b))
typedef struct {
	int pos,value;
} Info;

signed main(){
	long long damage_total[N_MAX]={};
	Info deque[N_MAX];
	int head=0,tail=0;
	int N,H;
	long long answer = 0;

	scanf("%d%d",&N,&H);	
	int currentHP = H;
	for(int i = 0 ; i < N-1 ; i++){
		int d,h;
		scanf("%d%d",&d,&h);
		while( head != tail && deque[tail-1].value <= h ) tail--;

		deque[tail++] = (Info){i,h};
		while( head != tail ){
			long long maximumRecover = H - (damage_total[i] - damage_total[deque[head].pos]);
			if( maximumRecover > 0 ) break;
			head++;
		}

		for(int j = head ; j < tail && currentHP <= d ; j++){
			// ????????§???????????§????????????
			int maximumRecover = H - (damage_total[i] - damage_total[deque[j].pos]);
			// ??¨???????????§????????????????£???°???
			if( maximumRecover <= currentHP) continue;

			// j??????????????§?????????????????? needRecover ????¨????
			int needRecover = min( maximumRecover - currentHP , d - currentHP + 1);  
			// ???????????? needRecover ?????????????????????????????° useCount ????±????????????????????????????
			int useCount = (needRecover+deque[j].value-1) / deque[j].value - 1;
			answer += useCount;
			currentHP += useCount*deque[j].value;

			// ???j?????????????????§????°???????????????????j????????£?????´?????¨???j+1????????£?????´?????????????????????j+1????????£????????????????????????j?????????????????????
			// ??¨) ???????????¶???????????\??£?????????????????¨???????????? currentHP > d ???????????????
			if( j+1 ==  tail || maximumRecover > currentHP + deque[j+1].value ){
				currentHP = min(currentHP+deque[j].value,maximumRecover);
				answer++;
			}
		}
		currentHP -= d;
		damage_total[i+1] = damage_total[i] + d;
	}
	printf("%lld\n",answer);

}

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

int main() {
  int a, b;
  std::cin >> a >> b;
  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
    std::cout << "Possible" << std::endl;
  } else {
    std::cout << "Impossible" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>pi;
#define elif else if
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vouble vector<double>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define vvhar vector<vector<char>>
#define mis map<int,str>
#define msi map<str,int>
#define mid map<int,double>
#define mod 100000007
#define elif else if
#define str string
int digitsum(int a){
  int b=0;
  while(a){
    b+=a%10;
    a/=10;
  }
  return b;
}
signed main(){
  int n,k,m,c=0,c2=0;
  string S,t;
  char C;
  double d;
  cin>>n>>m;
  int H[n],score[n]={};
  rep(0,n)cin>>H[i];
  int A[m],B[m];rep(0,m)cin>>A[i]>>B[i];
  rep(0,m){
    if(H[A[i]-1]>H[B[i]-1])score[B[i]-1]--;
    else if(H[A[i]-1]<H[B[i]-1])score[A[i]-1]--;
    else{
      score[A[i]-1]--;
      score[B[i]-1]--;
    }
  }
  rep(0,n){if(score[i]==0)c++;}
  cout<<c<<endl;
}


Measured memory_bytes: 6752
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n), f(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> f[i];
    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());
    ll ok = 1e18, ng = -1;
    while(ok - ng > 1){
        ll mid = (ok + ng) / 2;
        ll cost = 0;
        rep(i,n){
            ll add = a[i] - mid / f[i];
            chmax(add, 0LL);
            cost += add;
        }
        if(cost <= k) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 6368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int N;
    cin >> N;

    vector<vector<pii>> x;
    x.resize(N);

    int tmp;
    int a, b;
    REP(i, N)
    {
        cin >> tmp;
        x[i].resize(tmp);
        REP(j, tmp)
        {
            cin >> a >> b;
            x[i][j] = make_pair(a, b);
        }
    }

    int ans = 0;
    for (int bit = 0; bit < (1 << N); ++bit) //bit全探索
    {
        bool mujyun = false;        //矛盾チェック用
        tmp = 0;                    //正直者カウンタ
        for (int i = 0; i < N; ++i) //全員分ループ
        {
            if (bit & (1 << i)) //正直者の話をきく
            {
                tmp++;
                REP(j, x[i].size()) //矛盾がないか調べる
                {
                    int who = x[i][j].first - 1;
                    int which = x[i][j].second;
                    if (which == 1)
                    {
                        if (!(bit & (1 << who)))
                            mujyun = true;
                    }
                    else
                    {
                        if (bit & (1 << who))
                            mujyun = true;
                    }
                }
            }
        }
        if (!mujyun) //矛盾なし
        {
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
    // system("pause");
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<typename T, typename U>
class mymap {
private:
	size_t n;
	vector<T> key;
	vector<U> val;
	U dummy;
	void compress(vector<T> &v) {
		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());
	}
	size_t index(const T &i) {
		auto e = lower_bound(key.begin(), key.end(), i);
		assert(e != key.end() && *e == i);
		return e - key.begin();
	}
public:
	mymap(const vector<T> &key_) :key(key_), dummy() {
		compress(key);
		n = key.size();
		val.assign(n, U());
	}
	bool key_exists(const T &i) {
		auto e = lower_bound(key.begin(), key.end(), i);
		if (e == key.end())
			return false;
		else
			return *e == i;
	}
	U &operator[](const T &i) {
		if (key_exists(i))
			return val[index(i)];
		else {
			dummy = U();
			return dummy;
		}
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, V; cin >> N >> V;
	vector<int> a(N); rep(i, 0, N) { cin >> a[i]; }
	vector<int> b(N); rep(i, 0, N) { cin >> b[i]; }
	vector<int> c(N); rep(i, 0, N) { cin >> c[i]; }
	vector<int> d(N); rep(i, 0, N) { cin >> d[i]; }
	vector<int>	A, B;
	rep(i, 0, N)rep(j, 0, N) {
		A.emplace_back(a[i] + b[j]);
		B.emplace_back(c[i] + d[j]);
	}
	sort(all(A));
	sort(all(B));
	mymap<int, int> cntA(A), cntB(B);
	rep(i, 0, A.size()) {
		cntA[A[i]]++;
		cntB[B[i]]++;
	}
	A.erase(unique(A.begin(), A.end()), A.end());
	int ans = 0;
	rep(i, 0, A.size()) {
		ans += cntA[A[i]] * cntB[V - A[i]];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 49948
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<long long int> vint;
typedef vector<string> vstr;
typedef long long int llint;

llint gct(llint x,llint y){
	while (y != 0){
		if (x > y){
			llint r = x%y;
			x = y;
			y = r;
		}
		else {
			llint r = y%x;
			y = r;
		}
	}
	return x;
}

int main(void) {
	llint N, X,ans;
	cin >> N >> X;
	vint x(N+1), xdif(N);
	for (int i = 0; i < N + 1; i++){
		cin >> x[i];
		if (i == N)x[i] = X;
	}
	sort(x.begin(), x.end());
	for (int i = 1; i < N+1; i++)xdif[i - 1] = x[i] - x[i - 1];

	ans = gct(xdif[0], xdif[1]);

	if (N >1)for (int i = 2; i < N; i++)ans = gct(ans, xdif[i]);
 cout<<ans<<endl;
}


Measured memory_bytes: 1792
N=int(input())
r=[list(map(int,input().split())) for i in range(N)]
b=[list(map(int,input().split())) for i in range(N)]

ans = 0
r,b = sorted(r, key=lambda x:x[1],reverse=True), sorted(b)
for i in b:
    for j in r:
        if i[1]>j[1] and i[0] >j[0]:
            ans += 1
            r.remove(j)
            break
 
print(ans)

Measured memory_bytes: 38896
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    
    cout << min({a+b,a+c,b+c}) << endl;
    
    return 0;
}



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

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(size_t i=0;i<(b);i++)
#define rREP(i,b) for(int i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(int i=(b)-1;i>=0;i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))
#define Yes out("Yes")
#define No out("No")
#define NO out("NO")
#define YES out("YES")
#define INF 2e10;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define IfOut(condition,text) if((condition)){out(text);return 0;}
#define IfeOut(condition,itext,etext) if(condition){out(itext);return 0;}else{out(etext);return 0;}
#define Select(collection,condition,result) Foreach(i,collection){result+=condition;}
template<typename T> pair<vector<T>,int> getAuto() {int N; cin >> N; pair<vector<T>, int> rt;rt.first.resize(N);rt.second = N;REP(i, N) cin >> rt.first[i];return rt;}
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }

ll length(ll N) {
	ll ans = 0;
	while (N)
	{
		ans++;
		N /= 10;
	}
	return ans;
}

int main() {
	ll N;
	cin >> N;
	ll ans = length(N);
	rREP(i, sqrt(N)+1) {
		ll rem = N%i;
		ll div = N / i;
		if (rem == 0) {
			ans = length(div);
			break;
		}
	}
	out(ans);
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[4][13]={};
	int n;
	char op;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x;
		scanf(" %c%d",&op,&x);
		if(op=='S')
			a[0][x-1]=1;
		else if(op=='H')
			a[1][x-1]=1;
		else if(op=='C')
			a[2][x-1]=1;
		else
			a[3][x-1]=1;
	}
	for(int i=0;i<4;i++){
		for(int j=0;j<13;j++){
			if(a[i][j]==0){
				if(i==0) printf("S %d\n",j+1);
				else if(i==1) printf("H %d\n",j+1);
				else if(i==2) printf("C %d\n",j+1);
				else printf("D %d\n",j+1);
			}
		}
	}
	return 0;
}


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

using namespace std;



int main(){
int n;
    cin>>n;
    double arr[n];
    int i,j,k;
    for(i=0;i<n;i++) cin>>arr[i];
    double dp[n+1][n+1];
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(i=1;i<=n;i++) dp[0][i]=0;
    dp[1][0]=(1-arr[0]);
    for(i=2;i<=n;i++){
        dp[i][0]=(1-arr[i-1])*dp[i-1][0];
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=i;j++){
            double head=dp[i-1][j-1]*arr[i-1];
            double tail=dp[i-1][j]*(1-arr[i-1]);
            dp[i][j]=head+tail;
        }
    }
    double ans=0;
    for(i=(n+1)/2;i<=n;i++) ans+=dp[n][i];
        //cout<<dp[1][1]<<endl;
   cout<<setprecision(10)<<ans<<endl;
   

	return 0;
}

Measured memory_bytes: 70528
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();

        if(N % K == 0){
            System.out.println(0);
        }else{
            System.out.println(1);

        }

    }

}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define esp 1e-6
using namespace std;
long long  read(){
	long long x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,m,num[2000];
char s[110];

int main(){
    n=read();m=read();
    for (int i=1;i<=n;i++){
        scanf("%s",s+1);
        for (int j=1;j<=m;j++){
            num[s[j]]++;
        }
    }
    if (n%2==1&&m%2==1){
        for (int i='a';i<='z';i++){
            if (num[i]%2==1){
                num[i]--;
                break;
            }
        }
    }
    if (n%2==1){
        int m2=m/2;
        for (int i=1;i<=m2;i++){
            int boolean=0;
            for (int j='a';j<='z';j++){
                if (num[j]%4==2){
                    num[j]-=2;
                    boolean=1;
                    break;
                }
            }
            if (!boolean)
                for (int j='a';j<='z';j++){
                    if (num[j]%4==0&&num[j]){
                        num[j]-=2;
                        boolean=1;
                        break;
                    }
                }
            if (!boolean){
                printf("No");
                return 0;
            }
        }
    }
    if (m%2==1){
        int m2=n/2;
        for (int i=1;i<=m2;i++){
            int boolean=0;
            for (int j='a';j<='z';j++){
                if (num[j]%4==2){
                    num[j]-=2;
                    boolean=1;
                    break;
                }
            }
            if (!boolean)
                for (int j='a';j<='z';j++){
                    if (num[j]%4==0&&num[j]){
                        num[j]-=2;
                        boolean=1;
                        break;
                    }
                }
            if (!boolean){
                printf("No");
                return 0;
            }
        }
    }
    for (int i=1;i<=n/2;i++){
        for (int j=1;j<=m/2;j++){
            int boolean=0;
            for (int k='a';k<='z';k++){
                if (num[k]>=4){
                    num[k]-=4;
                    boolean=1;
                    break;
                }
            }
            if (!boolean){
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
      ios::sync_with_stdio(false),cin.tie(0), cout.tie(0);
      long long x;
      cin >> x;
      for (long long i=-200; i<=200; i++)
      {
            for (long long j=-200; j<=200; j++)
            {
                  if (i*i*i*i*i-j*j*j*j*j==x)
                  {
                        cout << i << " " << j <<endl;
                        return 0;
                  }
            }
      }
 	return 0;
}


Measured memory_bytes: 3612
fun main(args: Array<String>) {
    val s = readLine()!!
    val (n, p) = s.split(" ").map(String::toInt)        // 1≤N≤50, P=0,1
    val s2 = readLine()!!
    val a = s2.split(" ").map(String::toInt).toList()   // ≤Ai≤100

    val evenCount = a.count { it % 2 == 0 }
    val oddCount = n - evenCount

    /**
     * a個の中からb個を選ぶ組み合わせの数
     */
    fun combination(a: Int, b: Int): Long {
        var result = 1L
        val max = Math.max(b, a - b)
        val min = Math.min(b, a - b)
        for (i in max + 1..a) {
            result *= i
        }
        for (i in 1..min) {
            result /= i
        }
        return result
    }

    fun sum(a: Int, b: Int, start: Int): Long {
        var result = 0L
        for (i in start..b step 2) {
            result += combination(a, i)
        }
        return result
    }

    /**
     * p=0 食べた数が偶数
     * 偶数は任意 2^evenCount, 奇数は0, 2,..  <=oddCount
     */
    fun even(): Long {
        val ev = 1L.shl(evenCount)
        //val od = oddCount / 2
        return  ev * sum(oddCount, oddCount, 0)
    }

    /**
     * p=1 食べた数が奇数
     * 偶数は任意 2^evenCount, 奇数は1, 3,..  <=oddCount
     */
    fun odd(): Long {
        val ev = 1L.shl(evenCount)
        //val od = (oddCount + 1) / 2
        return  ev * sum(oddCount, oddCount, 1)
    }

    val result = when (p) {
        0 -> even()
        1 -> odd()
        else -> throw Exception()
    }
    println(result)
}


Measured memory_bytes: 37820
#include <stdio.h>
#include <stdlib.h>
long xxx[10][1001][101];

long pattern(int n,int s,int from){
	long i,x=0;
	if(s>100*n)return 0;
	if(xxx[n][s][from]>=0)x=xxx[n][s][from];
	else{
		for(i=(s-100*(n-1)>from?s-100*(n-1):from); i<100 && i<=s ;i++){x+=pattern(n-1,s-i,i+1);}
		xxx[n][s][from]=x;
	}
	return x;
}

int main(void){
	int n,s,i,j,k;
	for(j=0;j<101;j++){for(k=0;k<101;k++){xxx[1][j][k]=( (j<=100 && k<=j)?1:0 );}}
	for(j=0;j<201;j++){for(k=0;k<101;k++){xxx[2][j][k]=( (2*k<=j && j<=200) ? ((100-k+1)-abs((100-k)-(j-k*2)))/2 : 0 );}}
	for(i=3;i<10;i++){for(j=0;j<1001;j++){for(k=0;k<101;k++){xxx[i][j][k]=-1;}}}
    while(scanf("%d %d",&n,&s)*(n+s)){
	printf("%ld\n",pattern(n,s,0));}
    return 0;
}

Measured memory_bytes: 6700
use std::fmt::Debug;
use std::str::FromStr;

#[allow(dead_code)]
#[allow(deprecated)]
fn read_line_from_stdin() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).unwrap();
    buffer.trim_right().to_owned()
}

#[allow(dead_code)]
#[allow(deprecated)]
fn parse_line_to_single<T>() -> T
where
    T: FromStr,
    T::Err: Debug,
{
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).unwrap();
    T::from_str(buffer.trim_right()).unwrap()
}

#[allow(dead_code)]
#[allow(deprecated)]
fn parse_line_to_multiple<T>() -> Vec<T>
where
    T: FromStr,
    T::Err: Debug,
{
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).unwrap();
    buffer
        .trim_right()
        .split_whitespace()
        .flat_map(|s| T::from_str(s))
        .collect()
}

#[allow(unused_macros)]
macro_rules! parse_line {
    [$( $x:tt : $t:ty ),+] => {
        //declare variables
        $( let $x: $t; )+
        {
            use std::str::FromStr;
            // read
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            #[allow(deprecated)]
            let mut splits = buf.trim_right().split_whitespace();
            // assign each variable
            $(
                $x = splits.next().and_then(|s| <$t>::from_str(s).ok()).unwrap();
            )+
            // all strs should be used for assignment
            assert!(splits.next().is_none());
        }
    };
}

struct State {
    a: i32,
    b: i32,
    c: i32,
}

fn main() {
    let mut inputs = parse_line_to_multiple::<i32>();
    inputs.sort();

    let mut operation_count = 0;

    while inputs[1] != inputs[2] {
        inputs[0] += 1;
        inputs[1] += 1;
        operation_count += 1;
    }

    while inputs[0] < inputs[1] {
        inputs[0] += 2;
        operation_count += 1;
    }

    if inputs[0] > inputs[1] {
        inputs[1] += 1;
        inputs[2] += 1;
        operation_count += 1;
    }

    assert_eq!(inputs[0], inputs[1]);
    assert_eq!(inputs[1], inputs[2]);

    println!("{}", operation_count);
}


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

ll n;
string ans, alph="abcdefghijklmnopqrstuvwxyz";

int main(void) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    while (n>0) {
        --n;
        ans+=alph[n%26];
        n/=26;
    }
    for (int i=ans.size()-1; i>=0; --i)
        cout << ans[i];
    cout << '\n';
}


Measured memory_bytes: 3660
#include<iostream>

using namespace std;

int main(){

  bool player[1010];
  int n, m;

  while(cin >> n >> m,n+m){
    fill(player, player+1010, true);
    player[0] = false;
    int position = 0, num = n, countpotato  = m;
    for(int i = 0; ; i++){
      if(num == 1) break;
      if(countpotato == 1 && player[i%(n+1)]){
	//cout << i%n << endl;
	player[i%(n+1)] = false;
	countpotato = m;
	num--;
      }else if(player[i%(n+1)]){
	countpotato--;
      }
    }
    for(int i = 0; ; i++){
      if(player[i]){
	cout << i << endl;
	break;
      }
    }
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define ll long long int
using namespace std;

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;

    ll i;
    vector <ll> v(n);
    for(i = 0; i < n; i ++)
    	cin >> v[i];

    ll totalCost = 0;

    for(i = 0; i < n - 1; i ++)
    {
    	totalCost = totalCost + min(b, (v[i + 1] - v[i]) * a);
    }
    cout << totalCost << endl;
}


Measured memory_bytes: 1024
n,m=map(int,input().split())
h=input().split()


a=[]
b=[]
for i in range(0,m):
    ay,by=map(int,input().split())
    a.append(ay)
    b.append(by)

hlen=len(h)
for i in range(0,hlen):
    h[i]=int(h[i])
ans=[]

for i in range(0,m):
    
    if h[a[i]-1]>=h[b[i]-1]:
        ans.append(b[i])
    if h[a[i]-1]<=h[b[i]-1]:
        ans.append(a[i])


num=len(set(ans))
print(n-num)


Measured memory_bytes: 27772
X = int(input())

if 360 % X == 0:
    print(360 // X)
    exit()
else:
    mod = 0
    cnt = 0
    while (360 + mod) % X != 0:
        cnt += (360 + mod) // X
        mod = (360 + mod) % X
    cnt += (360 + mod) // X

print(cnt)


Measured memory_bytes: 9100
#include <iostream>
#include <algorithm>
#define INF 10000000000
#define MOD 1000000007

using namespace std;
int main(void){
    int N;
    cin>>N;
    char s[N+1],t[N+1];
    cin>>s>>t;
    int check=0; long ans=1; int i=0;
    while(i<N){
       if(i==0){
           if(s[i]==t[i]){check=1; ans=(ans*3)%MOD; i++;}
           else {check=0; ans=(ans*6)%MOD; i+=2;}
       }
       else{
           if(s[i]==t[i]&&check==1){check=1; ans=(ans*2)%MOD; i++;}
           else if(s[i]!=t[i]&&check==1){check=0; ans=(ans*2)%MOD; i+=2;}
           else if(s[i]!=t[i]&&check==0){check=0; ans=(ans*3)%MOD; i+=2;}
           else if(s[i]==t[i]&&check==0){check=1; i++;}
       }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
using namespace std;

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



int main() {
	int n, m;
	cin >> n >> m;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	set<int> s;

	vector<vector<int>> g(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;

		a--;
		b--;
		if (h[a] >= h[b]) {
			s.insert(b);
		}
		if (h[b] >= h[a]) {
			s.insert(a);
		}


	}

	cout << n - s.size() << endl;


}

Measured memory_bytes: 8720
n = gets.to_i
a = gets.split.map(&:to_i)
cnt = a.select{|x| x <= 0}.size % 2
b = a.map{|x| x.abs}.sort_by{|x| x}
if cnt == 1
  c = b.shift
  puts b.inject(:+) - c
else
  puts b.inject(:+)
end

Measured memory_bytes: 13312
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    vector<int> a(5);
    rep(0, i, 5)
    {
        cin >> a.at(i);
        if (a.at(i) == 0)
        {
            cout << i + 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3616
//Solution by Tima
#include <bits/stdc++.h>
 
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
 
using namespace std;    
const int N = int(3e5) + 12, mod = int(1e9)  + 7; 

int main () {
	string s;
	int ans = 0;
	cin >> s;
	for(int i = 0; i < s.size(); i++){
		if(s[i] != s[s.size() - 1 - i]) ans++;
	}
	cout << ans / 2;
 
return 0;
}

Measured memory_bytes: 764
// Dmitry _kun_ Sayutin (2019)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;
using std::queue;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    int h, w, a, b;
    cin >> h >> w >> a >> b;

    for (int i = 0; i != h; ++i, cout << "\n")
        for (int j = 0; j != w; ++j)
            cout << int((i < b) xor (j < a));

    return 0;
}


Measured memory_bytes: 1280
N, A, B, C = [int(_) for _ in input().split()]
L = [int(input()) for i in range(N)]

max_loop_count = 4 ** N
K = [0, A, B, C]


def func(count):
    comb = [0] * N
    i = 0
    while count > 0:
        comb[i] = count % 4
        i += 1
        count //= 4

    tmp = 0
    for k in range(1, 4):
        num = 0
        sum_ = 0
        for i in range(N):
            if comb[i] == k:
                num += 1
                sum_ += L[i]

        if num == 0:
            return 3100

        tmp += 10 * (num - 1) + abs(sum_ - K[k])

    return tmp


ans = 3100
for lp in range(max_loop_count):
    ans = min(ans, func(lp))

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int x;

int func(int b){
  int p = 2;
  int ret = 0;
  if (x == 1) return 1;
  
  while(true){
    if(pow(b,p) > x) return ret;
    ret = pow(b,p);
    p++;
  }
}


int main(){
  cin >> x;
  int ans = 0;
  for(int i = 2; i <= 1000;i++){
    chmax(ans,func(i));
  }
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
N = input()
lst = []
for i in N:
    lst.append(i)
    

for i in range(2**3):
    op = ['+','+','+']
    for j in range(3):
        #print(i,j)
        #print((i>>j) & 1)
        if (i>>j)&1 == 1:
            #print((i>>j) & 1)
            op[j] = '-'
    tes = [0]*7
    tes[::2] = lst
    tes[1::2] = op
    
    if eval(''.join(tes)) == 7:
        print(''.join(tes)+'=7')
        sys.exit()
    #print(op)


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

int main()
{
  int	n, flag = 0;
  
  cin >> n;
  for (int i = 1; i <= 9; i++)
  {
    for (int j = 1; j <= 9; j++)
    {
      if (i * j == n)
        flag = 1;
    }
  }
  if (flag == 1)
    cout << "Yes\n";
  else
    cout << "No\n";
  return (0);
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int)N;i++)
#define p(s) cout<<(s)<<endl
#define ck(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf=1e9;

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

	if(A==B) ans=1;
	else if(A<B&&N==1) ans=0;
	else if(A>B) ans=0;
	else if(N==2) ans=1;
	else{
		ans=(N-2)*(B-A)+1;
	}
	p(ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		while (sc.hasNext()) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			System.out.println(gcd(A, B));
		}
	}

	static int gcd(int A, int B) {
		return A % B == 0 ? B : gcd(B, A % B);
	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int ans=1000;
  for(int i=0;i<s.size()-2;i++){
    int a=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
    int b;
    if(a>=753){
      b=a-753;
    }
    else{
      b=753-a;
    }
    if(b<ans){
      ans=b;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 200005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
#define forn(i,a,b) for (int i = a; i <= b; i ++ )
#define mod(n,k) (((n%k)+k)%k)
using namespace std;
typedef long long ll;

ll H1, H2, S1, S2;

int main()
{
    optimiza_io
    cin >> H1 >> S1 >> H2 >> S2;
    while( H1 > 0 && H2 > 0 ) {
        H2 -= S1;
        if( H2 <= 0 )
            break;
        H1 -= S2;
    }
    if( H1 > 0 )
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

// CHECAR LIMITES 

Measured memory_bytes: 3612
def examC():
    X, Y = LI()
    ans = (Y//X).bit_length()
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


Measured memory_bytes: 38672
d = gets.to_i

ans = 0
20.downto(2) do |n_keta|
	cur = -d
	cnt = 1
	if -cur % 10 == 1
		break
	elsif -cur % 10 == 0
		cnt *= 9
	else
		sa = 10 - (-cur % 10)
		cnt *= 9 - sa
		cur += sa * (10 ** (n_keta - 1) - 1)
	end
	if cur > 0
		cur /= 10
	else
		cur = -(-cur / 10)
	end
	1.upto(n_keta / 2 - 1) do |i|
		if cur == 0
			cnt *= 10
		elsif cur > 0
			sa = (10 - cur % 10) % 10
			cnt *= 10 - sa
			cur = cur - sa * (10 ** (n_keta - 1 - i * 2) - 1)
		else
			sa = (10 - (-cur % 10)) % 10
			cnt *= 10 - sa
			cur = cur + sa * (10 ** (n_keta - 1 - i * 2) - 1)
		end
		if cur > 0
			cur /= 10
		else
			cur = -(-cur / 10)
		end
	end
	next if cur != 0
	if n_keta % 2 == 1
		ans += cnt * 10
	else
		ans += cnt
	end
end
p ans

Measured memory_bytes: 3836
while 1:
    n, m = map(int, input().split())
    if n == 0: break
    price = sorted(list(map(int, input().split())))
    maxx = 0
    for i in range(len(price)):
        for j in range(i + 1, len(price)):
            temp = price[i] + price[j]
            if maxx < temp and temp <= m: maxx = price[i] + price[j]
    if maxx == 0: print("NONE")
    else: print(maxx)



Measured memory_bytes: 5632
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		
		if(B%A == 0) {
			out.println(A+B);
		}else {
			out.println(B-A);
		}
		
		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int N,arr[13]={0,1,6,9,36,81,216,729,1296,6561,7776,46656,59049},Min[1000010];
int main(){
    scanf("%d",&N);
    for(int i=1;i<=100000;i++) Min[i]=1000000;
    Min[0]=0;
    for(int i=0;i<N;i++){
        for(int j=1;j<=12;j++)
        {
            if(Min[i]+1<Min[i+arr[j]] && i+arr[j]<=100000) Min[i+arr[j]]=Min[i]+1;
        }
    }
    printf("%d",Min[N]);
}


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

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;



int main()
{
    char N[4];
    cin >> N;

    bool ans = false;
    for (int i = 0; i < 3; i++)
    {
        ans = ans || N[i] == '7';
    }
    
    cout << YesNo(ans) << endl;
}

Measured memory_bytes: 3596
A, B, M = map(int, input().split(' '))

an = list(map(int, input().split(' ')))
bn = list(map(int, input().split(' ')))

mn = []
for _ in range(M):
    mn.append(list(map(int, input().split(' '))))

# print(A, B, M)
# print(an)
# print(bn)
# print(mn)


total = min(an) + min(bn)

for a,b,c in mn:
    total = min(total, an[a-1]+bn[b-1]-c)
print(total)

Measured memory_bytes: 38564
a,b,c=gets.split.map(&:to_i)
if a==b && b==c && a.even?
  puts -1
  exit(0)
elsif a==b && b==c && a.odd?
  puts 0
  exit(0)
end
ans = 0
while a.even? && b.even? && c.even?
  _a, _b, _c = a,b,c
  a = (_b+_c)/2
  b = (_a+_c)/2
  c = (_a+_b)/2
  ans += 1
end
p ans




Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#define maxn 100005
#define int long long
using namespace std;
struct node {
	int w, b;
};
vector<int> G[maxn];
const int mod = 1000000007;
node dfs(int x, int fa) {
	int w = 1, b = 1;
	for ( int i : G[x] ) {
		if ( i == fa )	continue;
		node tmp = dfs(i,x);
		w *= (tmp.w+tmp.b)%mod;
		w %= mod;
		b *= tmp.w;
		b %= mod;
	}
	return node{w,b};
}
main() {
	ios::sync_with_stdio(false);
	//   sync_with_YinHsuan(true);
	cin.tie(0);
	int n;
	cin >> n;
	for ( int i=1; i<n; ++i ) {
		int u, v;
		cin >> u >> v;
		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}
	node ans = dfs(1,1);
	cout << (ans.w+ans.b)%mod << '\n';
	return 0;
}


Measured memory_bytes: 12672
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: u64, k: u64
    }
    const M: u64 = 1_000_000_007;
    let mut ans = 0;
    for i in k..=n + 1 {
        let a = i * (i - 1) / 2;
        let b = n * i - a;
        ans += b - a + 1;
        ans %= M;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2172
#include <iostream>
#include <string>

using namespace std;

int main() {
	string s;
	cin >> s;
	int y = (s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0');
	int m = (s[5] - '0') * 10 + (s[6] - '0');
	int d = (s[8] - '0') * 10 + (s[9] - '0');

	if (y < 2019) {
		cout << "Heisei" << endl;
		// cout << 1 << endl;
	} else if (m < 5 && d < 31) {
		cout << "Heisei" << endl;
		// cout << 2 << endl;
	} else {
		cout << "TBD" << endl;
		// cout << 3 << endl;
	}
}

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

long long n,k,a=0,arr[100005];
int main(){
	cin >>  n >> k;
	for (int i=1;i<=n;i++){
		cin >> arr[i];
		if (arr[i]>=k){
			a++;
		}
	}
	cout << a << endl;
	
}

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

void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}

int main(){
    int m;
    cin >> m;
    call(m);
    
    return 0;
}


Measured memory_bytes: 3108