akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

    string res = "No";
    for (int i = 0; i < 3; i++) {
        if (n % 10 == 7) res = "Yes";
        n /= 10;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3596
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)

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

int main()
{
	int n, c;
	string s1;
	
	cin >> s1 >> n;
	
	c = 0;
	
	while (n--){
		string s2;
		cin >> s2;
		
		for (int i = 0; i < s2.size(); i++){
			s2 += s2[0];
			s2.erase(s2.begin() + 0);
			if (s2.find(s1) != -1){
				c++;
				break;
			}
		}
	}
	
	cout << c << endl;
	return (0);
}

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


using namespace std;

typedef unsigned long long ull;
int main(void) {
	int n;
	while(cin >> n){
	int res = 0;
	for(int a = 0; a <= 9; a++){
	for(int b = 0; b <= 9; b++){
	for(int c = 0; c <= 9; c++){
	for(int d = 0; d <= 9; d++){
		if(a + b + c + d == n)res++;
	}	
	}	
	}	
	}
	cout << res << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
using ll = long long;
int main(){
	int N;
	cin>>N;
	ll s = 0;
	map<ll,ll> cnt;
	cnt[0]++;
	rep(i,N){
		ll a;
		cin>>a;
		s += a;
		cnt[s]++;
	}
	ll ans = 0;
	for(auto it:cnt){
		ans += it.sc*(it.sc-1)/2;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 12800
N = gets.chomp.to_i
a = gets.split(" ").map(&:to_i)

res = []
a.each_with_index do |x, i|
  next if (i.to_i+1) % 2 == 0
  next if x % 2 == 0

  res.append(x)
end

puts(res.count)

Measured memory_bytes: 14292
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
struct _IO { _IO() { ios::sync_with_stdio(0); cin.tie(0); } }_io;
typedef long long ll; typedef long double db;

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

	ll ans = 0;
	for (int i = 0; i < n - 1; ++i)
	{
		if (a[i] > a[i + 1])
		{
			ans += a[i] - a[i + 1];
			a[i + 1] += a[i] - a[i + 1];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3984
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

l,r,d = i2()
cnt = 0
for i in range(l,r+1):
	if i%d==0:
		cnt += 1
print(cnt)

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

using namespace std;

typedef long long int ll;

int main(void) {
    string buf;
    cin >> buf;
    int num = 0;
    for(int i = 0;i < 4;i++) {
        if(buf[i] == '+')
            num++;
        else
            num--;
    }
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 888
s = input()

n = len(s)

error = 0
for i in range(n):
    if i % 2 == 0:
        if s[i] == 'L':
            error += 1
    else:
        if s[i] == 'R':
            error += 1

if error == 0:
    print('Yes')
else:
    print('No')

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int n;
vector<int> a;

set<vector<int>> ans;
void f(vector<int> &vec, int idx, int k) {
    if (k == vec.size()) {
        ans.insert(vec);
    }
    rep(i, n + 1) if (idx < i) {
        vec.push_back(a[i]);
        f(vec, i, k);
        vec.pop_back();
    }
}
using P = pair<long long, long long>;
template <class T, size_t N, T MOD>
struct Combination {
    typedef T int_type;
    vector<int_type> fact, factr, inv;
    Combination() {
        fact.resize(2 * N + 1);
        factr.resize(2 * N + 1);
        inv.resize(2 * N + 1);
        fact[0] = factr[0] = 1;
        inv[1] = 1;
        for (int i = 2; i <= 2 * N; i++)
            inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
        for (int i = 1; i <= 2 * N; i++)
            fact[i] = fact[i - 1] * i % MOD,
            factr[i] = factr[i - 1] * inv[i] % MOD;
    }

    int_type C(int n, int r) {
        if (r < 0 || r > n) return 0;
        return factr[r] * fact[n] % MOD * factr[n - r] % MOD;
    }

    int_type P(int n, int r) {
        if (r < 0 || r > n) return 0;
        return fact[n] * factr[n - r] % MOD;
    }

    int_type H(int n, int r) {
        if (n == 0 && r == 0) return 1;
        return C(n + r - 1, r);
    }
};

int main() {
    cin >> n;
    a.resize(n + 1);
    rep(i, n + 1) cin >> a[i];
    int d = -1;
    map<int, int> pos;
    rep(i, n + 1) {
        if (pos.count(a[i]))
            d = i - pos[a[i]];
        else
            pos[a[i]] = i;
    }
    // cout << d << endl;
    const long long MOD = 1e9 + 7;
    Combination<long long, 100005, MOD> comb;
    rep(i, n + 2) if (i) {
        if (i == 1) {
            cout << n << endl;
            continue;
        }

        auto ret = comb.C(n + 1, i);
        auto c = comb.C(n - d, i - 1);
        // cout << n - d  << ", " << i - 1 << " = " << c << endl;
        // cout << ret << ", " << c << endl;
        ret -= c;
        // c += MOD;
        ret += MOD;
        ret %= MOD;
        cout << ret << endl;
        /*
        vector<int> vec;
        f(vec, -1, i);
        cout << i << ": " << ans.size() << ", " << ret << endl;
        // */
        /*
        for(auto e: ans) {
            rep(i, e.size()) cout << e[i] << " ";
            cout << endl;
        }
        */
        ans.clear();
    }

    return 0;
}


Measured memory_bytes: 11008
#include<bits/stdc++.h>
using namespace std;
int a[101][101];
int w,e,n,s;
bool judge()
{
	if(w==1&&e==1&&n==1&&s==1)return 1;
    if(w==1&&e==1&&n==0&&s==0)return 1;
    if(w==0&&e==0&&n==1&&s==1)return 1;
    if(w==0&&e==0&&n==0&&s==0)return 1;
	return 0;
}
int main() 
{
	//freopen("a.in","r",stdin);
	string ch;
	cin>>ch;
	
	for(int i=0;i<ch.size();i++)
	{
		if(ch[i]=='W') w=1;
		if(ch[i]=='E') e=1;
		if(ch[i]=='N') n=1;
		if(ch[i]=='S') s=1;
	}
	cout<<(judge()?"Yes":"No");
}

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


int main() {
    string s;
    cin >> s;
    int i = s.size();
    if(s.at(i-1) == 's'){
        cout << s + "es" << endl;
    }
    else cout << s + "s" << endl;
    return 0;
}

Measured memory_bytes: 3632
N = int(input())
n = input().rstrip().split(' ')
H = [int(i) for i in n]
c = 1
s = [0]*N
s[0] = H[0]
for i in range(1,N):
  if max(s)<= H[i] :
    c +=1
    s[i] = H[i]
  else:
    pass
print(c)
    
    

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

int main(){
    int n, m, l;
    cin >> n >> m >> l;
    int a[n][m], b[m][l];
    long long int c[n][l];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            c[i][j] = 0;
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < m; i++){
        for(int j = 0; j < l; j++){
            cin >> b[i][j];
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            for(int k = 0; k < m; k++){
                c[i][j] += a[i][k] * b[k][j];
            }
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            if(j == l -1) cout << c[i][j] << endl;
            else cout << c[i][j] << " ";
        }
    }
    return 0;
}


Measured memory_bytes: 3228
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int f(int val, int x){
    if(val < 0) return 0;
    return val / x + 1;
}

signed main(){
    int a, b, x; cin >> a >> b >> x;
    cout << f(b, x) - f(a - 1, x) << endl;
    return 0;
}



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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  ll p = 26, sz = 1;
  while (p < n) {
    n -= p;
    p *= 26;
    sz++;
  }
  string sol;
  n--;
  for (int i = 0; i < sz; i++) {
    sol += (char) ('a' + n % 26);
    n /= 26;
  }
  reverse(sol.begin(), sol.end());
  cout << sol << "\n";
  return 0;
}


Measured memory_bytes: 3656
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
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();}
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;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll X;
  cin>>X;
  co(1-X);
  return 0;
}

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

#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
#define pll pair<ll,ll> 
#define ld long double

const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);

ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}

int _runtimeTerror_()
{
    ll n;
    cin>>n;
    vector<ll> x(n),y(n);
    vector<pll> v(n);
    ll ans = 0;
    for(int i=0;i<n;++i)
    {
        cin>>v[i].F>>v[i].S;
        // cin>>x[i]>>y[i]
    }
    sort(all(v));
    set<ll> s1,s2;
    for(int i=0;i<n;++i)
    {
        if(!s1.empty())
        {
            amax(ans,v[i].F+v[i].S+(*s1.rbegin()));
        }
        if(!s2.empty())
        {
            amax(ans,v[i].F-v[i].S+(*s2.rbegin()));
        }
        s1.insert(-v[i].F-v[i].S);
        s2.insert(-v[i].F+v[i].S);
    }
    cout<<ans<<"\n";
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef runSieve
        sieve();
    #endif
    #ifdef NCR
        initialize();
    #endif
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
        _runtimeTerror_();
    return 0;
}

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

int main()
{
  int n, m, p, s, g;
  int t[8], edge[30][30];
  double dp[1 << 8][30];
  const double INF = 1e8;

  while(scanf("%d %d %d %d %d", &n, &m, &p, &s, &g), n){
    fill_n( *edge, 30 * 30, -1);
    fill_n( *dp, (1 << n) * 30, INF);
    s--, g--;

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

    for(int i = 0; i < p; i++){
      int a, b, c;
      scanf("%d %d %d", &a, &b, &c);
      a--, b--;
      edge[a][b] = c;
      edge[b][a] = c;
    }

    for(int i = 0; i < 1 << n; i++){
      dp[i][s] = 0.0;
    }

    double ret = INF;
    for(int i = (1 << n) - 1; i >= 0; i--){ //今のチケット
      ret = min( ret, dp[i][g]);
      for(int j = 0; j < m; j++){ //今の街
        if(dp[i][j] != INF){
          for(int k = 0; k < n; k++){ //使うチケット
            if(i >> k & 1){
              for(int l = 0; l < m; l++){ //次の街
                if(edge[j][l] != -1){
                  dp[i & ~(1 << k)][l] = min( dp[i & ~(1 << k)][l], dp[i][j] + (double)edge[j][l] / t[k]);
                }
              }
            }
          }
        }
      }
    }
    if(ret == INF) puts("Impossible");
    else printf("%.8f\n", ret);
  }
  return 0;
}

Measured memory_bytes: 1292
from collections import deque

N = int(input())

G, W = [[] for i in range(N)], [[] for l in range(N)]
check, dist = [0 for j in range(N)], [-1 for k in range(N)]


def bfs(s):
    q = deque()
    check[s], dist[s] = 1, 0
    q.append(s)

    while len(q) != 0:
        u = q.popleft()
        for v in range(len(G[u])):
            if check[G[u][v]] == 0:
                check[G[u][v]], dist[G[u][v]] = 1, dist[u] + W[u][v]
                q.append(G[u][v])

        check[u] = 2


def main():
    for i in range(N-1):
        a, b, c = map(int, input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)
        W[a-1].append(c)
        W[b-1].append(c)

    q, k = map(int, input().split())

    bfs(k-1)

    for i in range(q):
        x, y = map(int, input().split())
        print(dist[x-1]+dist[y-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 43536
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
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; }

ll dp[3005][3005];

int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    rep(i,n){
        rep(l, n-i){
            int r = l + i;
            dp[l][r] = a[l] - dp[l+1][r];
            if(r > 0) chmax(dp[l][r], a[r] - dp[l][r-1]);
        }
    }

    cout << dp[0][n-1] << endl;
}


Measured memory_bytes: 49784
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
bool a[2000000];
signed main() {
	for (int i = 2; i < 2000000; i++) {
		a[i] = 1;
	}
	for (int i = 2; i < 2000000; i++) {
		if (!a[i]) continue;
		for (int j = 2 * i; j < 2000000; j += i) {
			a[j] = 0;
		}
	}
	int n;
	while (cin >> n) {
		int ans = 0;
		for (int i = 2; i <= n; i++) {
			ans += a[i];
		}
		cout << ans << endl;
	}
}


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

int main()

{
    int n;
    string s = "";
    cin >> n;
    if (n == 0)
    {

        cout << "0";
        return 0;
    }
    while (n != 0)
    {
        if ((n % 2) == 0)
        {

            s = "0" + s;
        }
        else
        {
            n--;
            s = "1" + s;
        }
        n = n / (-2);
    }

    cout << s << endl;
}


Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int n = cin.nextInt();
    int m = cin.nextInt();
    int l=0;
    int r=0;
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    for (int i = 0; i < m; i++) {
      l = cin.nextInt();
      r = cin.nextInt();
      max = Math.max(l, max);
      min = Math.min(r, min);
    }
    min = Math.min(min,n);
    System.out.println(Math.max(min-max+1,0));

  }

}


Measured memory_bytes: 63992
# :20
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


x, y, a, b, c = LI()
p = sorted(LI())[::-1][:x]
q = sorted(LI())[::-1][:y]
r = sorted(LI())[::-1][:x+y]
bucket = []
bucket += [i for i in p]
bucket += [i for i in q]
bucket += [i for i in r]
bucket = sorted(bucket)[::-1]
ans = sum(bucket[:x+y])
print(ans)


Measured memory_bytes: 29844
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max(min(b, d) - max(a, c), 0) << endl;
}



Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};



signed main(){
  string s;
  cin>>s;
  int ans=0;
  rep(i,s.size()-1){
    if(s[i]!=s[i+1])ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >>n;
  ll a[n];
  for(ll i=0;i<n;i++){
    cin >> a[i];
  }
  ll bre=0,sin=0;
  for(ll i=0;i<n;i++){
    if(a[i]==sin+1)sin++;
    else bre++;
  }
  if(sin==0)cout << -1 <<endl;
  else cout << bre <<endl;
}

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

int main() {
	string S;
	int W;
	cin >> S;
	cin >> W;
	string ans = "";
	for (int i=0; i < S.length(); i += W) {
		ans += S.at(i);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T &a){int t = 0;for(auto itr :a){if(t++)cout << " "; cout << itr;} cout <<endl; }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    //    std::ios_base::sync_with_stdio(false);
    //    cin.tie(NULL);
    int a,b,c;
    cin >> a >> b >> c;
    cout <<(a == b and b == c ? "Yes":"No") << endl;
}




Measured memory_bytes: 256
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int n1=n;
    int ans=0;
    while(n>0){
        ans+=n%10;
        n/=10;
    }
    if(n1%ans){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
    return 0;  
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10,p=1e9+7;
int inc(int x,int y){x+=y;return x>=p?x-p:x;}
const int M=5e6+10;
struct node{int l,r,v;}nd[M];
int rootx[N],rooty[N],id;
int add(int x,int l,int r,int p,int d){
	int now=++id;
	nd[now]=nd[x];
	nd[now].v=inc(nd[now].v,d);
	if (l==r) return now;
	int mid=(l+r)>>1;
	if (p>mid) nd[now].r=add(nd[x].r,mid+1,r,p,d);
		else nd[now].l=add(nd[x].l,l,mid,p,d);
	return now;
}
int query(int x,int l,int r,int L,int R){
	if (l>=L&&r<=R) return nd[x].v;
	int mid=(l+r)>>1,ans=0;
	if (L<=mid) ans=inc(ans,query(nd[x].l,l,mid,L,R));
	if (R>mid) ans=inc(ans,query(nd[x].r,mid+1,r,L,R));
	return ans;
}
int n,l[N],L[N];ll A,B,s[N];
int main()
{
	scanf("%d%lld%lld",&n,&A,&B);
	for (int i=1;i<=n;i++) scanf("%lld",&s[i]);
	s[0]=-1e18;s[n+1]=2e18;
	l[0]=L[0]=1;
	for (int i=1;i<=n;i++){
		for (l[i]=l[i-1];s[l[i]]-s[i]<A;l[i]++);
		for (L[i]=L[i-1];s[L[i]]-s[i]<B;L[i]++);
	}
	rootx[1]=add(0,0,n-1,0,1);
	rooty[1]=add(0,0,n-1,0,1);
	for (int i=1,p1=0,p2=0;i<n;i++){
		if (i+1>=l[i]) rootx[i+1]=rootx[i];
		if (i+1>=L[i]) rooty[i+1]=rooty[i];
		while (i+1>=l[p1+1]) p1++;
		rootx[i+1]=add(rootx[i+1],0,n-1,i,query(rooty[i],0,n-1,0,p1));
		while (i+1>=L[p2+1]) p2++;
		rooty[i+1]=add(rooty[i+1],0,n-1,i,query(rootx[i],0,n-1,0,p2));
	}
	printf("%d\n",inc(query(rootx[n],0,n-1,0,n-1),query(rooty[n],0,n-1,0,n-1)));
	return 0;
}

Measured memory_bytes: 45312
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <deque>
#include <cstring>
#include <functional>
#include <climits>
#include <list>
#include <ctime>
#include <complex>

#define F1(x,y,z) for(int x=(y);x<(z);x++)
#define F2(x,y,z) for(int x=(y);x<=(z);x++)
#define F3(x,y,z) for(int x=(y);x>(z);x--)
#define F4(x,y,z) for(int x=(y);x>=(z);x--)
#define mp make_pair
#define pb push_back
#define LL long long
#define co complex<double>
#define fi first
#define se second

#define MAX 100005
#define AMAX 53
#define MOD 1000000007

#define f(c,d) ((1<<(c))*(d))

using namespace std;

int n,x,y;
char z[MAX];

int main(){
	scanf("%d%d%d%s",&n,&x,&y,z);
	x+=y;
	F1(a,0,n){
		if(z[a]=='a'&&x)printf("Yes\n"),x--;
		else if(z[a]=='b'&&x&&y)printf("Yes\n"),x--,y--;
		else printf("No\n");
	}
	#ifdef LOCAL_PROJECT
	system("pause");
	#endif
	return 0;
}


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

using namespace std;

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

  const int K = 50;
  int grid[2*K][2*K] ;

  for (int y = K; y<2*K; y++) {
    for (int x = 0; x < 2*K; x++) {
      grid[y][x] = 1; // 1 is for white, 0 is for black.
    }
  }

  // A is for white, .
  // B is for black, #
  
  int restA = A-1;
  int beforeA = 0;
  for (int y = 0; y<K-1; y++) {

    if (beforeA == 0) {
      for (int x = 0; x < 2*K;x++ ) {
        
          if ( (restA!=0) && (x%4==0)) {
            restA--;
            grid[y][x+2] = 1;
            grid[y][x+1+2] = 1;
            beforeA = 1;
          }
      }
    } else {
      beforeA = 0;
    }
  }
  int restB = B-1;
  int beforeB = 0;

  for (int y = K+1; y<2*K; y++) {
    if (beforeB == 0) {
      for (int x = 0; x < 2*K; x++) {
          if ( (restB!=0) && (x%4==0)) {
            restB--;
            grid[y][x+2] = 0;
            grid[y][x+1+2] = 0;
            beforeB = 1;
          }
      }
    } else {
      beforeB = 0;
    }
  }


  cout << "100 100" << endl;
  for (int y = 0; y < 2*K; y++) { 
    for (int x = 0; x < 2*K ; x++){
      if (grid[y][x] == 0) {
        cout << "#";
      } else {
        cout << ".";
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
class Node:
    def __init__(self, key):
        self.key = key
        self.left = self.right = self.parent = None
    
class BST:
    def __init__(self):
        self.root = None

    def insert(self, key):
        new = Node(key)
        parent = None
        current = self.root
        while current != None:
            parent = current
            if key < current.key:
                current = current.left
            else:
                current = current.right
        if parent == None:
            self.root = new
        elif key < parent.key:
            parent.left = new
        else:
            parent.right = new

    def find(self, k):
        x = self.root
        while x != None and k != x.key:
            if k < x.key:
                x = x.left
            else:
                x = x.right
        if x != None:
            print('yes')
        else:
            print('no')
        
    def print(self):
        self.print_in_order(self.root)
        print()
        self.print_pre_order(self.root)
        print()

    def print_in_order(self, node):
        if node != None:
            self.print_in_order(node.left)
            print(' ' + str(node.key), end = '')
            self.print_in_order(node.right)
    
    def print_pre_order(self, node):
        if node != None:
            print(' ' + str(node.key), end = '')
            self.print_pre_order(node.left)
            self.print_pre_order(node.right)
        
n = int(input())
bst = BST()
for i in range(n):
    cmd = list(map(str, input().split()))
    if cmd[0] == 'print':
        bst.print()
    elif cmd[0] == 'find':
        bst.find(int(cmd[1]))
    else:
        key = int(cmd[1])
        if cmd[0] == 'insert':
            bst.insert(int(cmd[1]))


Measured memory_bytes: 85228
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(void)
{
	//変数の宣言
	int n;
	int a[100010];
	int num[100010];
	int left;
	int right;

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	long int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	//データの読み込み
	
	scanf("%d",&n);
	
	for(i=0;i<n+1;i++){
		scanf("%d",&a[i]);
		num[i]=-1;
	}


//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	COMinit();

	for(i=0;i<n+1;i++){
		if(num[a[i]]!=-1){
			left=num[a[i]];
			right=i;
//			printf("2kaidetekurunoha%d\n",a[i]);
			break;
		}
		num[a[i]]=i;
	}
	
	for(i=1;i<=n+1;i++){
		ans=COM(n+1,i);
//		printf("tag1 ans=%d\n",ans);
		if(n-right+left+1>=i){
			ans=ans-COM(n-right+left,i-1);
		}
//		printf("tag2 ans=%d\n",ans);
		if(ans<0) ans=ans+1000000007;
		printf("%ld\n",ans);
	}
	
	
//	printf("計算部分終了\n");
	//出力
	
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



Measured memory_bytes: 13824
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define LL long long

using namespace std;

int a[100005],b[100005],c[100005],dp[100005][4];

int solve(int x,int type) {
    if (x<0) return -1*MOD;
    if (x==0) return 0;
    if (dp[x][type]!=-1) return dp[x][type];
    if (type==1) {
        return dp[x][type]=max(solve(x-1,2)+b[x],solve(x-1,3)+c[x]);
    } else if (type==2) {
        return dp[x][type]=max(solve(x-1,1)+a[x],solve(x-1,3)+c[x]);
    } else if (type==3) {
        return dp[x][type]=max(solve(x-1,1)+a[x],solve(x-1,2)+b[x]);
    } else {
        return dp[x][type]=max(max(solve(x-1,1)+a[x],solve(x-1,2)+b[x]),solve(x-1,3)+c[x]);
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    for (int i=1;i<=n;i++) cin >> a[i] >> b[i] >> c[i];
    memset (dp,-1,sizeof(dp));
    cout << solve(n,0) << endl;
    return 0;
}


Measured memory_bytes: 7680
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

typedef struct 
{
    unsigned int uiLeft;
    unsigned int uiArea;
}AreaInfo_t;

#define CALC_AREA(x,y) ((x) - (y))

stack<unsigned int> stuiArealeftIdx;
vector<AreaInfo_t> vectAreaInfo;

unsigned int Decision(char, unsigned int);
void Fusion(AreaInfo_t);

int main(void){
    char ch = '\0';
    unsigned int uiIdx = 0;
    unsigned int uiTotal = 0;
    
    while(cin >> ch)
    {
        uiTotal += Decision(ch, uiIdx);
        uiIdx++;
    }
    
    cout << uiTotal << endl;
    cout << vectAreaInfo.size();
    for(vector<AreaInfo_t>::iterator it = vectAreaInfo.begin(); it != vectAreaInfo.end(); it++)
    {
        cout << ' ' <<  it->uiArea;
    }
    cout << endl;
    
    return 0;
    
}

unsigned int Decision(char ch, unsigned int uiIdx)
{
    unsigned int rslt = 0;
    
    switch(ch)
    {
        case '\\':
            stuiArealeftIdx.push(uiIdx);
            break;
        case '/':
            if(!stuiArealeftIdx.empty())
            {
                AreaInfo_t tInfo;
                tInfo.uiLeft = stuiArealeftIdx.top();
                tInfo.uiArea = CALC_AREA(uiIdx, stuiArealeftIdx.top());
                rslt =  tInfo.uiArea;
                stuiArealeftIdx.pop();
                Fusion(tInfo);
            }
            break;
        case '_':
            // pass
            break;
        default:
            // unreachable
            break;
    }

    return rslt;
}

void Fusion(AreaInfo_t tInfo)
{
    
    while(1)
    {
        if(!vectAreaInfo.empty())
        {
            AreaInfo_t tmp = vectAreaInfo.back();
            if(tmp.uiLeft > tInfo.uiLeft)
            {
                tInfo.uiArea += tmp.uiArea;
                vectAreaInfo.pop_back();
                continue;
            }
        }
        vectAreaInfo.push_back(tInfo);
        break;
    }

    return;
}



Measured memory_bytes: 3260
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"

using namespace std;
typedef long long ll;

int main()
{
  string s;
  cin >> s;
  string ans;
  int size=s.size();
  for (int i = 0; i < size; i++)
  {
    if (i % 2 == 0)
    {
      ans += s[i];
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 512
(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let n, m, c = Scanf.sscanf (read_line ()) "%d %d %d" (
        fun n m c -> 
                n, m, c
)
let blst = 
        Str.split (Str.regexp " ") (read_line ())
        |> List.map int_of_string
let alst =
        List.init n (
                fun _ -> 
                        Str.split (Str.regexp " ") (read_line ())
                        |> List.map int_of_string
        )

let dot_product = List.fold_left2 (fun a b c -> a + b * c) 0
let rec f lst =
        match lst with
                [] -> 0
                | first :: rest -> 
                        let fdot = c + dot_product first blst in
                                if fdot > 0 then
                                        1 + (f rest)
                                else
                                        f rest

let () =
        f alst
      |> Printf.printf "%d\n"


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

#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(),(a).rend())
#define ll long long
#define pb(a) push_back(a)

#define PRINTV(v) {for(ll deB=0; deB<(v).size(); deB++){cout << (v)[deB] << " ";}cout << endl;}

int main(){
	ll N;
	cin >> N;
	
	vector<ll> a(N);
	REP(i,N) cin >> a[i];
	
	ll ret = 2;
	
	REP(i,N){
		if(a[i]%2==1) ret = 1;
	}
	
	cout << (ret==1?"first":"second") << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>


int
main(void)
{
	int group[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
	int x, y;

	scanf("%d %d", &x, &y);
	puts(group[x] == group[y] ? "Yes" : "No");
	return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int K, N; cin >> K >> N;
	vint A(N); cin >> A;
	
	int minv = K;
	A.push_back(A[0]+K);
	for (int i = 0; i < N; i++) {
		chmin(minv, K - (A[i+1] - A[i]));
	}
	cout << minv << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 1792
def nxto(u):
  for val in m[u]:
    if c[val] == 0:
      return val
    
  return None

def dfs(ix):
  stk = [ix]
  c[ix] = 1
  while stk != []:
    l = stk[-1]
    nxt = nxto(l)
    if nxt is not None:
      c[nxt] = 1
      stk.append(nxt)
    else:
      stk.pop()

N, M = list(map(int, input().split(" ")))
c = [0 for _ in range(N+1)]
m = [[] for _ in range(N+1)]
for _ in range(M):
  a, b = list(map(int, input().split(" ")))
  m[a].append(b)
  m[b].append(a)

cnt = -1
for i in range(1, N+1):
  if c[i] == 0:
    dfs(i)
    cnt += 1
print(cnt)

Measured memory_bytes: 26264
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int a=0;
  for(int i=1; i<s.length(); i++){
    if(i%2==1){
      if(s[0]==s[i])a++;
    }
    else{
      if(s[0]!=s[i])a++;
    }
  }
  int b=1;
  for(int i=1; i<s.length(); i++){
    if(i%2==1){
      if(s[0]!=s[i])b++;
    }
    else{
      if(s[0]==s[i])b++;
    }
  }
  cout << min(a,b) << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

void solve()
{
    ll a,b,k;
    cin>>a>>b>>k;
    if(a>=k)
    {
        cout<<a-k<<" "<<b<<endl;
        return;
    }
    if(k-a>=b)
    {
        cout<<"0 0"<<endl;
        return;
    }
    cout<<0<<" "<<b-k+a<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3520
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair

using namespace std;
const int N=1e5+5;
int n,m,k,x,y,a[N],b[N],c[N],s[N];

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>x>>y>>n>>m>>k;
    priority_queue<int,vector<int>,greater<int>>pq;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=n;i>=n-x+1;i--) pq.push(a[i]);
    for(int i=1;i<=m;i++) cin>>b[i];
    sort(b+1,b+m+1);
    for(int i=m;i>=m-y+1;i--) pq.push(b[i]);
    for(int i=1;i<=k;i++)
    {
        cin>>c[i];
        if(c[i]>pq.top())
        {
            pq.pop();
            pq.push(c[i]);
        }
    }
    int res=0;
    while(!pq.empty())
    {
        res+=pq.top();
        pq.pop();
    }
    cout<<res;
}


Measured memory_bytes: 4208
#include<stdio.h>

int main(){
    long int n,k,a,b,x,y,i;

    scanf("%ld",&n);
    scanf("%ld%ld",&x,&y);
    for(i=1;i<n;i++){
        scanf("%ld%ld",&a,&b);
        if((x-1)/a<(y-1)/b){
            k=(y-1)/b+1;
        }else{
            k=(x-1)/a+1;
        }
        x=a*k;
        y=k*b;
    }
    printf("%ld",x+y);
    return 0;
}

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

int main() {
  while (true) {
    int m, f, r;
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1) break;
    if (m == -1 || f == -1) cout << "F" << endl;
    else if (m + f >= 80) cout << "A" << endl;
    else if (m + f >= 65) cout << "B" << endl;
    else if (m + f >= 50) cout << "C" << endl;
    else if (m + f >= 30) {
      if (r >= 50) cout << "C" << endl;
      else cout << "D" << endl;
    }
    else cout << "F" << endl;
  }
}


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

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

    int a[n];

    int s = 0;

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

    double k = s * (1 / (4.0 * m));

    //cout << k << " ";

    for(int i = 0; i < n; i++){
        if(k <=  a[i])
            m--;
    }

    if(m > 0)
        cout << "No";
    else
        cout << "Yes";

    return 0;

}


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

int main() {
  int N; cin >> N;
  vector<ll> A(N);
  rep(i, 0, N) cin >> A[i];
  sort(A.begin(), A.end());
  vector<ll> S, L;
  copy(A.begin(), A.begin() + N / 2, back_inserter(S));
  copy(A.begin() + N / 2, A.end(), back_inserter(L));
  ll ans = 0;
  ll s = accumulate(S.begin(), S.end(), 0LL);
  ll l = accumulate(L.begin(), L.end(), 0LL);
  if(N & 1) {
    ans = 2 * (l - s) - L[0] - L[1];
    s += L[0], l -= L[0];
    ll tmp = 2 * (l - s) + S.back() + L[0];
    ans = max(ans, tmp);
  } else {
    ans = 2 * (l - s) + S.back() - L[0];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,i,a[101010],ma;
map<ll,bool> b;
int main()
{
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]==m)
		{
			cout<<"POSSIBLE\n";
			return 0;
		}
		b[a[i]]=1;
		ma=max(ma,a[i]);
	}
	if(ma>m)
	{
		for(i=1;i<=n;i++)
		{
			if(b[m-a[i]]==1)
			{
				cout<<"POSSIBLE\n";
				return 0;
			}
		}
	}
	cout<<"IMPOSSIBLE\n";
}

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

int main() {
  int N,K;
  cin >> N >> K;
  int count = 0;
  int x;
  for(int i = 0; i < N; i++){
    cin >> x;
    if(x < K - x) count += x;
    else count += K - x;
  }
  cout << count * 2 << endl;
}


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

upper_concentration = E / (100 + E)

def concentration(sugar, water):
    if sugar == 0 and water == 0:
        return False
    c = sugar / (sugar + water)
    if c > upper_concentration:
        return False
    else:
        return c

AB = []
for ia in range(0, int(F / 100 / A) + 1):
    ib = 0
    if ia == 0 and ib == 0:
        continue
    while 100 * (A * ia + B * ib) <= F:
        AB.append([ia, ib])
        ib += 1

c_max = 0
sugar_max = 0
sugar_water_max = 0
water_max = 0

for ia, ib in AB:
    water = 100 * (A * ia + B * ib)
    water_max = max(water_max, water)
    res_water = F - water
    for ic in range(0, int(res_water / C) + 1):
        for id in range(0, int(res_water / D) + 1):
            sugar = C * ic + D * id
            if sugar > res_water:
                break
            c = concentration(sugar, water)
            if not c:
                continue
            if c_max <= c:
                c_max = c
                sugar_max = sugar
                sugar_water_max = sugar + water
if sugar_max == 0:
    print(water_max, 0)
else:
    print(sugar_water_max, sugar_max)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
const int INF = 100100100;
using namespace std;

int main()
{
  char c1[4], c2[4];
  char c1r[4], c2r[4];
  cin >> c1 >> c2;

  strcpy(c1r, c1);
  strcpy(c2r, c2);
  reverse(c1r, c1r+3);
  reverse(c2r, c2r+3);

  if(strcmp(c1, c2r) == 0 && strcmp(c2, c1r) ==0) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256