akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};
bool b[200000] = { false };
int main() {
	vi pri;
	FOR(i,2, 200000) {
		if (!b[i]) {
			pri.push_back(i);
			for (int j = i * 2;j < 200000;j += i) {
				b[j] = true;
			}
		}
	}
	int n, p;
	while (cin >> n >> p, n != -1) {
		int l = 0;
		int r = pri.size();
		while (abs(l-r)>1) {
			if (pri[(l + r) / 2]>n) {
				r = (l + r) / 2;
			}else{
				l = (l + r) / 2;
			}
		}
		if (pri[l] > n)r = l;
		vi matsuzaki;
		REP(i, 100) {
			FOR(j,i, 100+i) {
				matsuzaki.push_back(pri[r+i]+ pri[r + j]);
			}
		}
		SORT(matsuzaki);
		cout << matsuzaki[p - 1] << endl;
	}
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define llrep(i,a,b) for(ll i=a;i<b;i++)
#define llrepd(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; const ll MOD = 1000000007;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

//---------------------------------------------------------------------------------------------------
void _main() {
    ll N; cin >> N;
    vector<ll> S(N); rep(i, 0, N) cin >> S[i];
    ll Q; cin >> Q;
    ll res = 0;
    rep(i, 0, Q) {
        ll t; cin >> t;
        ll start = 0, end = S.size()-1;
        // cout << "> " <<  t << endl;
        while(start <= end){
            ll diff = start + (end-start) / 2;
            // cout << start << " " << end << " " << diff << " " << S[diff] << endl;
            if (S[diff] == t) {res += 1; break;}
            else if(S[diff] < t) start = diff + 1;
            else end = diff - 1;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3532
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
typedef long long ll;
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    int a,b;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
//構造体降順
int comp( const void *c1, const void *c2 )
{
  data test1 = *(data *)c1;
  data test2 = *(data *)c2;
  int tmp1 = test1.b;   /* b を基準とする */
  int tmp2 = test2.b;
  return tmp2 - tmp1;
}


int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}

int main(){
    int N,T,A;
    int ans=0;
    scanf("%d%d%d",&N,&T,&A);
    int H[N];
    rep(i,N){
        scanf("%d",&H[i]);
    }
    double min=10000000;
    rep(i,N){
        double temp=0.0;
        temp=T-(double)H[i]*0.006;
        if(fabs(temp-A)<min){
            min=fabs(temp-A);
            ans=i;
        }
    }
    printf("%d",ans+1);
}


Measured memory_bytes: 1700
n, m = map(int, input().split())
lis = list(map(int, input().split()))

res = 10**9
for i in range(n - m + 1):
    res = min(res, lis[i + m - 1] - lis[i] + min(abs(lis[i]), abs(lis[i + m - 1])))
print(res)


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


using namespace std;

void func146b (){
	string s;
	int n;
	cin >> n;
	cin >> s;
	for (int i = 0; i < s.length(); i++)cout << (char)('A' + (s[i] - 'A' + n + 26) % 26);
	cout << "\n";
}



int main()
{
	func146b();
	return 0;	
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String str[] = br.readLine().split(" ");
            int a = Integer.parseInt(str[0]);
            int b = Integer.parseInt(str[1]);
            int c = Integer.parseInt(str[2]);
            int d = Integer.parseInt(str[3]);
            if (a * b > c * d) {
                System.out.println(a * b);
            } else {
                System.out.println(c * d);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 8148
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;
int w,h;
int dx[4] = {0,1,0,-1},dy[4] = {1,0,-1,0};
int main(void) {
	while (1) {
		int ans = 0;
		cin >> w >> h;
		vector<vector<int> > d(h,vector<int>(w,-1));
		vector<string> s(h);
		queue<pair<int,int> > q;
		if (w == 0 && h == 0) break;
		for(int i = 0;i < h;i++){
		    cin >> s[i];
		    for(int j = 0;j < w;j++){
		        if(s[i][j] == '@'){
		            d[i][j] = 0;
		            q.push(pair<int,int>(i,j));
		        }
		    }
		}
		
		while(!q.empty()){
		    pair<int,int> cur = q.front();
		    q.pop();
		    for(int k = 0;k < 4;k++){
		        int x = cur.first+dx[k];
		        int y = cur.second+dy[k];
		        if(x < 0 || x >= h || y < 0 || y >= w) continue;
		        if(s[x][y] == '#') continue;
		        if(d[x][y] == -1){
		            d[x][y] = d[cur.first][cur.second]+1;
		            ans++;
		            q.push(pair<int,int>(x,y));
		        }
		    }
		}
		cout << ans+1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3164
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;

int main()
{
	string S;
	cin >> S;

	int ans = 0;
	for (int i = 0; i < S.length()/2; ++i)
	{
		if (S[i] != S[S.length() - i - 1])++ans;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<string, int> P;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  queue<P> que;
  int n, q, t, time = 0;
  string s;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> s >> t;
    que.emplace(s, t);
  }
  while (!que.empty()) {
    P p = que.front();
    que.pop();
    if (p.second > q) {
      time += q;
      p.second -= q;
      que.push(p);
    } else {
      time += p.second;
      cout << p.first << " " << time << "\n";
    }
  }
}


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef pair<int,int> ii;

struct Edge{
  int to,cap,cost,rev;
  Edge(int to=0,int cap=0,int cost=0,int rev=0):to(to),cap(cap),cost(cost),rev(rev){}
};

const int MAX_V = 1100, IINF = INT_MAX;
int V;
vector<Edge> G[MAX_V];
int h[MAX_V],dist[MAX_V],prevv[MAX_V],preve[MAX_V];

inline void add_edge(int from,int to,int cap,int cost){
  G[from].push_back(Edge(to,cap,cost,G[to].size()));
  G[to].push_back(Edge(from,0,-cost,G[from].size()-1));
}

int min_cost_flow(int s,int t,int f){
  int res = 0;
  fill(h,h+V,0);
  while(f>0){
    priority_queue<ii,vector<ii>,greater<ii> > Q;
    fill(dist,dist+V,IINF);
    dist[s] = 0;
    Q.push(ii(0,s));
    while(!Q.empty()){
      ii p = Q.top(); Q.pop();
      int v = p.second;
      if( dist[v] < p.first ) continue;
      for(int i=0;i<G[v].size();i++){
        Edge &e = G[v][i];
        if( e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to] ) { 
          dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
          prevv[e.to] = v;
          preve[e.to] = i;
          Q.push(ii(dist[e.to],e.to));
        }
      }
    }
    if( dist[t] == IINF ) return -1;
    rep(v,V) h[v] += dist[v];
    int d = f;
    for(int v=t;v!=s;v=prevv[v]) d = min(d,G[prevv[v]][preve[v]].cap);
    f -= d;
    res += d * h[t];
    for(int v=t;v!=s;v=prevv[v]){
      Edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}

int n;
int p[110];

int main(){

  scanf("%d",&n);
  rep(i,n) { scanf("%d",p+i); --p[i]; }
  int source = 2 * n;
  int sink   = source + 1;
  V = sink + 1;
  rep(i,n) add_edge(source,i,1,0);
  rep(i,n) add_edge(n+i,sink,1,0);
  rep(i,n){
    rep(j,n) if( p[i] != j ){
      int cost = (p[i]+1)*abs(i-j);
      if( i == j ) cost = 0;
      add_edge(i,n+j,1,cost);
    }
  }
  printf("%d\n",min_cost_flow(source,sink,n));
  return 0;
}

Measured memory_bytes: 1668
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

//------------------------------------------------------

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

    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    int left[n + 1], right[n + 1];
    left[0] = right[n] = 0;
    rep(i, n) left[i + 1] = __gcd(left[i], a[i]);
    for (int i = n; i >= 1; i--) right[i - 1] = __gcd(right[i], a[i - 1]);
    int ans = 1;
    rep(i, n) ans = max(ans, __gcd(left[i], right[i + 1]));
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1408
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
signed main(){

	int N, K, S;
	cin>>N>>K>>S;
	vint ans;
	for(int i=0;i<K;i++)
		ans.pb(S);
	for(int i=K;i<N;i++){
		if(S==1000000000)
			ans.pb(1);
		else
			ans.pb(1000000000);
	}
	for(int i=0;i<N;i++){
		cout<<ans[i]<<(i==N-1?'\n':' ');
	}
	return 0;
}

Measured memory_bytes: 1784
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <utility>
#include <cmath>
#include <stdlib.h> 
#include <stdio.h>
#include <iterator>
#include <chrono>
#include <iomanip>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <deque>
#include <stack>
#include <queue>
#include <fstream>
#include <limits>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <sstream>
#include <random>
#include <cassert>

using namespace std;
#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n ; j++)
int INF = 1e9 + 7;


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

	int n, ans = 0;
	cin >> n;
	vector <int> v(n);
	ffor(n) cin >> v[i];
	for (int i = 0; i < v.size(); i++) {
		for (int j = i + 1; j < v.size(); j++) {
			for (int k = j + 1; k < v.size(); k++) {
				int x = v[i], y = v[j], z = v[k];
				if (x + y > z && x + z > y && y + z > x) {
					if (x != y && y != z && x != z) {
						ans++;
					}
				}
			}
		}
	}
	cout << ans;
}




/*
C:\Users\User\Desktop\comp_programming\final_straw_after_this_im_switching_to_vs_code\final_straw_after_this_im_switching_to_vs_code.cpp
*/

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

//D日目時点のスコアを計算
int score(int D, int c[], int s[][26], int t[]){
    int pen_day[26]={1};
    for(int i=0; i<26; i++){
        pen_day[i]=1;
    }
    int score=0;
    
    for(int i=0; i<D; i++){
        int type=t[i]-1;
        pen_day[type]=0;
        //満足度増加
        score+=s[i][type];
        //満足度低下
        for(int j=0; j<26; j++){
            int dec=c[j]*pen_day[j];
            score-=dec;
        }
        //日数追加
        for(int j=0; j<26; j++){
            pen_day[j]++;
        }        
    }
    return score;
}

void Greedy(int D, int c[], int s[][26]){
    int t[D], max_type=0, max_score=0;

    for(int i=0; i<D; i++){
        max_score=0;
        for(int j=0; j<26; j++){
            t[i]=j+1;
            int S=score(i+1, c, s, t);
            if(max_score < S){
                max_score = S;
                max_type=j+1;
            }
        }
        t[i]=max_type;
    }

    //局所探索
    int new=0;
    int roop_num=0;
    int MAX=max_score;
    while(1){
        int a=rand()%D;
        int b=rand()%D;

        //a,bを入れ替え
        int tmp;
        tmp=t[a];
        t[a]=t[b];
        t[b]=tmp;

        //scoreを計算
        int now_score=score(D, c, s, t);
        if(MAX<now_score) MAX=now_score;
        else{
            tmp=t[a];
            t[a]=t[b];
            t[b]=tmp;  
        }
        new++;
        roop_num++;
        if(new==D/10) break;
        if(roop_num==D) break;
    }

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

int main(void){
    int D, c[26], s[365][26], t[365];

    //入力
    scanf("%d", &D);
    for(int i=0; i<26; i++){
        scanf("%d", &c[i]);
    }
    for(int i=0; i<D; i++){
        for(int j=0; j<26; j++){
            scanf("%d", &s[i][j]);
        }
    }
    /*
    for(int i=0; i<D; i++){
        scanf("%d", &t[i]);
    }
    */

   /*ここから処理*/
   /*
    int num=1;
    for(int i=0; i<D; i++){
        printf("%d\n", num);
        num++;
        if(num>26) num=1;
    }
    */

   Greedy(D, c, s);


    return 0;
}

Measured memory_bytes: 1744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()	
{
	int n,m,x,y,a,b;
	vector<int>v,w;
	cin>>n>>m>>x>>y;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		v.push_back(a);
	}
	for(int i=0;i<m;i++)
	{
		cin>>b;
		w.push_back(b);
	}
	sort(v.begin(),v.end());
	sort(w.begin(),w.end());
	for(int i=max(x,v[v.size()-1])+1;i<=100;i++)
	{
		if(i<=min(y,w[0]))
		{
			cout<<"No War"<<endl;
			return 0;
		}
	}
	cout<<"War"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int) (n); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define maximize(a, b) ((a)<(b)?(a)=(b),1:0)
#define minimize(a, b) ((a)>(b)?(a)=(b),1:0)
void MAIN();
int main() {
//    freopen("input.txt", "r", stdin);

    MAIN();
    return 0;
}

const int N = 100032;
int n, a[N];

void MAIN() {
    scanf("%d", &n);
    REP(i, n) scanf("%d", a+i);
    long long ans = 1LL<<60;
    for (int s = 0; s < 2; s++) { //initial sign
        long long ps = 0, cost = 0;
        REP(i, n) {
            ps += a[i];
            if ((i&1) ^ s) {
                if (ps <= 0) cost += -ps + 1, ps = 1;
            } else {
                if (ps >= 0) cost += ps + 1, ps = -1;
            }
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;
}



Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    int n,h,w,ans=0;
    cin>>n>>h>>w;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(h<=a&&w<=b){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long

deque<ll> ans;

ll n;
bool bo[233];

inline ll rd()
{
	ll x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

int main()
{
	n=rd();ll hh=0;
	while (n)
	{
		if (n&1) bo[++hh]=true,n=(n-1)>>1;
		else bo[++hh]=false,n--;
	}
	printf("%lld\n",hh<<1);
	for (int i=hh;i;i--) if (bo[i]) ans.push_back(hh-i+1);else ans.push_front(hh-i+1);
	for (ll i=0;i<hh;i++) printf("%lld ",ans[i]);
	for (ll i=1;i<=hh;i++) printf("%lld ",i);
	puts("");
	return 0;
}

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

int main(void)
{
	double v, y;
	int n;
	
	while (scanf("%lf", &v) != EOF) {
		/* v = 9.8 * t
		   y = 4.9 * t^2 より
		   y = 4.9 * (v / 9.8)^2 */
		y = 4.9 * pow((v / 9.8), 2);

		/* 建物のＮ階の高さＹが
		   Y = 5 * N - 5 より
		   N = (Y + 5) / 5 */
		n = (int)ceil((y + 5) / 5);
		printf("%d\n", n);
	}

	return 0;
}

Measured memory_bytes: 632
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li n;
    cin >> n;
    vector<li> ds(n);
    for (int i = 0; i < n; ++i) {
        cin >> ds[i];
    }
    li ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < i; ++j) {
            ans += ds[i] * ds[j];
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
using namespace std;
#define sd(n) scanf("%d", &n)
#define sdd(n, m) scanf("%d%d", &n, &m)
#define sddd(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define pd(n) printf("%d\n", n)
#define pc(n) printf("%c", n)
#define pdd(n, m) printf("%d %d\n", n, m)
#define pddd(n, m, z) printf("%d %d %d\n", n, m, z)
#define pld(n) printf("%lld\n", n)
#define pldd(n, m) printf("%lld %lld\n", n, m)
#define plddd(n, m, z) printf("%lld %lld %lld\n", n, m, z)
#define sld(n) scanf("%lld", &n)
#define sldd(n, m) scanf("%lld%lld", &n, &m)
#define slddd(n, m, k) scanf("%lld%lld%lld", &n, &m, &k)
#define sf(n) scanf("%lf", &n)
#define sc(n) scanf("%c", &n)
#define sff(n, m) scanf("%lf%lf", &n, &m)
#define sfff(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)
#define ss(str) scanf("%s", str)
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = a; i >= n; i--)
#define mem(a, n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ce i == n ? '\n' : ' '
#define mod(x) ((x) % MOD)
#define gcd(a, b) __gcd(a, b)
#define lowbit(x) (x & -x)
typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
inline int read()
{
	int ret = 0, sgn = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
	{
		if (ch == '-')
			sgn = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		ret = ret * 10 + ch - '0';
		ch = getchar();
	}
	return ret * sgn;
}
inline void Out(int a) //ê?3?ía1ò
{
	if (a > 9)
		Out(a / 10);
	putchar(a % 10 + '0');
}

ll gcd(ll a, ll b)
{
	return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
///快速幂m^k%mod
ll qpow(ll x, ll n, ll mod)
{
	ll res = 1;
	while (n)
	{
		if (n & 1)
			res = (res * x) % mod;
		x = x * x % mod, n >>= 1;
	}
	return res;
}

int a,b,c;
int main()
{
	sddd(a,b,c);
	swap(a,b);
	swap(a,c);
	pddd(a,b,c);
	return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//
// https://atcoder.jp/contests/abc126/tasks/abc126_d

#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

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

struct UnionFind {
    vector<size_t> parent;
    vector<size_t> rank;
    size_t find_parent(size_t x) {
        if (parent[x] == x) {
            return x;
        } else {
            parent[x] = find_parent(parent[x]);
            return parent[x];
        }
    }
    explicit UnionFind(size_t size) {
        parent.resize(size);
        rank.resize(size);
        for (size_t i = 0; i < size; i++) {
            parent[i] = i;
            rank[i] = 0;
        }
    }
    virtual ~UnionFind() {}
    void unite(size_t x, size_t y) {
        size_t px = find_parent(x);
        size_t py = find_parent(y);
        if (px == py) {
            return;
        }
        if (rank[px] < rank[py]) {
            parent[px] = py;
        } else if (rank[px] > rank[py]) {
            parent[py] = px;
        } else { // rank[px] == rank[py]
            parent[py] = px;
            rank[px]++;
        }
    }
    bool is_same(size_t x, size_t y) {
        return find_parent(x) == find_parent(y);
    }
};

int main(int argc, char* argv[]) {
    #ifdef DEBUG
    if (argc >= 2) {
        assert(freopen(argv[1], "r", stdin));
    }
    #endif // DEBUG
    int N, M;
    cin >> N >> M;
    UnionFind comps(N);
    for (int i = 0; i < M; i++) {
        int X, Y, Z;
        cin >> X >> Y >> Z;
        comps.unite(X-1, Y-1);
    }
    set<int> parents;
    for (int i = 0; i < N; i++) {
        parents.insert((int)comps.find_parent(i));
    }
    cout << parents.size() << endl;
}



Measured memory_bytes: 6528
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };


signed main() {
	ll N, C, K;
	vector<ll>list;

	cin >> N >> C >> K;

	for (int i = 0; i < N; i++) {
		ll num;
		cin >> num;
		list.push_back(num);
	}

	sort(list.begin(), list.end());

	ll cnt = 0, hani = 0;

	for (int i = 0; i < list.size(); i++) {
		int index;
		hani = list[i] + K;
		for (int k = i, j = 0;  k < list.size() && list[k] <= hani  ; k++, j++) {
			if (j >= C ) {
				break;
			}
			index = k;
		}
		cnt++;
		i = index;
	}


	cout << cnt << endl;


	
	return 0;
}

Measured memory_bytes: 1400
N = int(input())
X = [input() for _ in range(N)]

ctr = [[], []]
for s in X:
    t = [0] * (len(s) + 1)
    for j in range(len(s)):
        t[j + 1] = t[j] + int(s[j] == "(") - int(s[j] == ")")

    if t[-1] > 0:
        ctr[0].append((min(t), t[-1]))
    else:
        ctr[1].append((min(t) - t[-1], -t[-1]))

flag = True
tmp = 0
for i in range(2):
    cur = 0
    for m, c in sorted(ctr[i], reverse=True):
        flag &= cur + m >= 0
        cur += c

    if i == 0:
        tmp = cur
    else:
        flag &= tmp == cur

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 234696
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::input;
use std::collections::*;

fn main() {
    input! {
        n:i32,
        m:usize,
        a:[i32;m],
    }
    let need = a.iter().fold(0, |sum, x| sum + x);
    let ans = if need <= n { n - need } else { -1 };
    println!("{}", ans);
}

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

int main(){
    int A, B, C, X, count;
    cin >> A >> B >> C >> X;
    for(int i = 0;i <= A;i++){
        for(int j = 0;j <= B;j++){
            for(int k = 0;k <= C;k++){
                if(i*500 + j*100 + k*50 == X)
                    count++;
            }
        }
    }
    cout << count << endl;
}

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


int main() {
    double l;
    cin >> l;
    double edge = l/3;
    cout << fixed << setprecision(19) << edge*edge*edge << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

using namespace std;

int main()
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		int A, B;
		scanf("%d%d", &A, &B);
		if(A > B)swap(A, B);
		long long fac = 1ll * A * B;
		int x = sqrt(1. * fac);
		int ans = 2 * x;
		if(1ll * x * x == fac)ans -= 2;
		else if((fac - 1) / x == x)ans--;
		if(A != B)ans--;
		if(A != 1 && (fac - 1) / ((fac - 1) / B) == B)ans--; 
		printf("%d\n", ans);
	}
}

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

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

  int l[m],r[m];

  for(int i=0;i<m;i++){
      cin >> l[i];
      cin >> r[i];
  }

  int ans=0;

  sort(l,l+m);
  sort(r,r+m);

  if(r[0] < l[m-1]){
      cout << 0 << endl;
  }

  else{
      cout << r[0]-l[m-1]+1 << endl;
  }
}

Measured memory_bytes: 1024
using System;

namespace ABC172B
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Trim();
            var b = Console.ReadLine().Trim();
            int ans = 0;
            for(int i=0;i<a.Length;i++){
                if(a[i] != b[i]) ans++;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27328
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;




signed main() {
	/*cin.tie(0);
	ios::sync_with_stdio(false);*/
	int N, A, B, C, D,E;
	cin >> N >> A >> B >> C >> D >> E;;
	int mn = min({A,B,C,D,E});
	int cnt = (N + mn - 1) / mn;
	print(5+cnt-1);


}


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

int main(){
    int ans=0,sum=0;
    int n;
    cin >> n;
    int data[n+2]={};
    data[0]=0;
    data[n+1]=0;
    for (int i = 1; i <= n+1; i++){
        cin >>data[i];
        sum += abs(data[i]-data[i-1]); 
    }

    for (int i = 1; i <= n; i++){
        ans = sum - abs(data[i+1]-data[i])-abs(data[i]-data[i-1]) + abs(data[i+1]-data[i-1]);
        cout << ans << '\n';
    }
    
    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;
    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];
    int c=0;
    int mmin=1000000009;
    ll sum=0;
    rep(i,n){
        if(a[i]<0) c++;
        mmin=min(mmin,abs(a[i]));
        sum+=abs(a[i]);
    }
    if(c%2==0) cout << sum << endl;
    else cout << sum-2*mmin << endl;
}

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

#define ll long long

using namespace std;

int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    int a,cur = 1,b;
    cin >> a >> b;
    int res = 0;
    while(cur < b)
    {
        cur += a - 1;
        res++;
    }
    cout << res;
}


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

using namespace std;

int const maxn = 2e5 + 5;
vector < int > g[2][maxn];
int cmp[2][maxn];
vector < int > comp[2][maxn];
int good[2], used[2][maxn];
map < pair < int, int >, int > get_ans;

void dfs(int j, int v) {
    cmp[j][v] = good[j];
    comp[j][good[j]].push_back(v);
    used[j][v] = 1;
    for (auto u : g[j][v]) {
        if (used[j][u] == 0) dfs(j, u);
    }
}

inline int check(int j, int i, int x) {
    int pos = lower_bound(comp[j][i].begin(), comp[j][i].end(), x) - comp[j][i].begin();
    if (pos != (int)comp[j][i].size() && comp[j][i][pos] == x) return 1;
    return 0;
}

inline int solve(int x, int y) {
    int ans = 0;
    if ((int)comp[0][x].size() < (int)comp[1][y].size()) {
        for (auto key : comp[0][x]) {
            if (check(1, y, key)) ans++;
        }
    }
    else {
        for (auto key : comp[1][y]) {
            if (check(0, x, key)) ans++;
        }
    }
    return ans;
}

main() {
    int n, k, l, u, v;
    cin >> n >> k >> l;
    for (int i = 1; i <= k; ++i) {
        cin >> u >> v;
        g[0][u].push_back(v);
        g[0][v].push_back(u);
    }
    for (int i = 1; i <= l; ++i) {
        cin >> u >> v;
        g[1][u].push_back(v);
        g[1][v].push_back(u);
    }
    for (int j = 0; j <= 1; ++j) {
        for (int i = 1; i <= n; ++i) {
            if (used[j][i] == 0) {
                good[j]++;
                dfs(j, i);
                sort(comp[j][good[j]].begin(), comp[j][good[j]].end());
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (get_ans.find({cmp[0][i], cmp[1][i]}) != get_ans.end()) {
            cout << get_ans[{cmp[0][i], cmp[1][i]}] << " ";
        }
        else {
            int d = solve(cmp[0][i], cmp[1][i]);
            get_ans[{cmp[0][i], cmp[1][i]}] = d;
            cout << d << " ";
        }
    }
}


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

int judge(int n) {
	int j = 400;
	int i;
	bool over = true;
	for (i = 0; i <= 8; i++) {
		if (n < i*j) {
			over = false;
			break;
		}
	}
	if (over) return 8;
	else return i-1;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int mini=0, maxi=0, a, n;
	cin >> n;
	vector<int> score(9, 0);
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (judge(a) == 8) maxi++;
		else {
			++(score[judge(a)]);
		}
	}
	
	for (int i = 0; i < 8; i++) {
		if (score[i] != 0) {
			mini++;
			maxi++;
		}
	}
	if (mini==0) {
		mini=1;
		maxi=n;
	}
	cout << mini << " " << maxi << '\n';
}


Measured memory_bytes: 256
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

n,m,s,t = myinput()
uvab = mylistinput(m)

# Dijkstra法(O(ElogV))
# edge[i] : iから出る道の[重み,行先]の配列
# import heapq
# def dijkstra_heap(n,s,edge):
#     #始点sから各頂点への最短距離
#     d = [float("inf")] * n
#     used = [True] * n # True:未確定
#     d[s] = 0
#     used[s] = False
#     edgelist = []
#     for e in edge[s]:
#         heapq.heappush(edgelist,e)
#     while len(edgelist):
#         minedge = heapq.heappop(edgelist)
#         # まだ使われてない頂点の中から最小の距離のものを探す
#         if not used[minedge[1]]:
#             continue
#         v = minedge[1]
#         d[v] = minedge[0]
#         used[v] = False
#         for e in edge[v]:
#             if used[e[1]]:
#                 heapq.heappush(edgelist,[e[0]+d[v],e[1]])
#     return d

# Dijkstra法(O(ElogV))
# edge[i] : iから出る道の[重み,行先]の配列
# 高速化版
import heapq
def dijkstra_heap(n,s,edge):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

g1 = [ [] for _ in range(n) ]
g2 = [ [] for _ in range(n) ]
for i in range(m):
    u = uvab[i][0] - 1
    v = uvab[i][1] - 1
    a = uvab[i][2]
    b = uvab[i][3]
    g1[u].append([a,v])
    g1[v].append([a,u])
    g2[u].append([b,v])
    g2[v].append([b,u])
# print(g1)
# print(g2)

d1 = dijkstra_heap(n,s-1,g1)
d2 = dijkstra_heap(n,t-1,g2)
# print(d1)
# print(d2)

yen = 10**15
ans = -1*float("inf")
ls_ans = [0]*n
for i in reversed(range(n)):
    snuke = yen - d1[i] - d2[i] 
    ans = max(ans,snuke)
    ls_ans[i] = ans

for i in range(n):
    print(ls_ans[i])

Measured memory_bytes: 130136
I = [int(_) for _ in open(0).read().split()]
N, U, V = I[:3]
A, B = I[3::2], I[4::2]
G = [set() for _ in range(N + 1)]
for a, b in zip(A, B):
    G[a].add(b)
    G[b].add(a)


def dfs(x):
    dist = [None] * (N + 1)
    dist[x] = 0
    stack = set([x])
    while stack:
        x = stack.pop()
        for xn in G[x]:
            if dist[xn] is None:
                dist[xn] = dist[x] + 1
                stack.add(xn)
    return dist


distt = dfs(U)
dista = dfs(V)
ans = 0
for t, a in zip(distt[1:], dista[1:]):
    if t < a:
        ans = max(ans, a - 1)
print(ans)


Measured memory_bytes: 45144
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

ll a,b,n;

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

    double x = (double) min(b-1, n);
    cout << floor(a*x/b) - a*floor(x/b) << '\n';

    return 0;
}


Measured memory_bytes: 3800
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
using namespace std;
int main () { 
	int a,b,c,d,e,f;
	cin >> a >> b >> c >> d;
	f = a*b;
	e = c*d;
		if(f > e){
			cout << f << endl;
		}else if (e > f){
			cout << e << endl;
		}else if (e == f){
			cout << e << endl;
		}
			
			
		
} 			


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>

using namespace std;

vector<string> judges = {"AC", "WA", "TLE", "RE"};

int main() {
  int judge_num;
  map<string, int> counts;

  cin >> judge_num;

  // Init count
  for(int i = 0; i < judges.size(); i++) {
    counts[judges[i]] = 0;
  }

  for(int i = 0; i < judge_num; i++) {
    string judge;
    cin >> judge;

    counts[judge]++;
  }

  cout << "AC x " << counts["AC"] << endl;
  cout << "WA x " << counts["WA"] << endl;
  cout << "TLE x " << counts["TLE"] << endl;
  cout << "RE x " << counts["RE"] << endl;
}

Measured memory_bytes: 3636
#
# 9c
#

def main():
    T = H = 0
    n = int(input())
    for i in range(n):
        t, h = input().split()
        if t > h:
            T += 3
        elif t < h:
            H += 3
        else:
            T += 1
            H += 1

    print(f"{T} {H}")


if __name__ == '__main__':
    main()



Measured memory_bytes: 5612
n, m = list(map(int, input().split()))
#b = list(map(int, input().split()))
l = []
r = []
for i in range(m):
    x, y = list(map(int, input().split()))
    l.append(x)
    r.append(y)
L = l[0]
R = r[0]
# print("--------")
for i in range(1, m):
    if not((R < l[i] and R < r[i]) or (r[i] < L and l[i] < L)):
        L = max(L, l[i])
        R = min(R, r[i])
    else:
        print(0)
        exit()
    #print(L, R)

print(R-L+1)


Measured memory_bytes: 11040
#include<bits/stdc++.h>
using namespace std;
#define F(n) for(int i=0;i<n;++i)
#define Fj(n) for(int j=0;j<n;++j)
const int MOD=1e9+7;

int main(){
    long m1,m2,d1,d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(m1==m2) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <cstdlib>
#define EVAL 1
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 1048576
#define PI 3.1415926535
int main() {
	int n;
	cin >> n;
	vector<int> a;
	REP(i, n) {
		int b;
		cin >> b;
		a.push_back(b);
	}
	if (n % 2 == 1) a.push_back(0);
	int ans = 0;
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0;i < n;i += 2) {
		ans += a[i] - a[i + 1];
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
    char s[100010],a[200]= {0};
    scanf("%s",s);
    string ss="";
    for(int i=0; s[i]!='\0'; i++)
        if(s[i]!='x')ss+=s[i];
    int l=ss.size();
    for(int i=0; i<l/2; i++)
    {
        if(ss[i]!=ss[l-i-1])
        {
            printf("-1\n");
            return 0;
        }
    }
    l=strlen(s)-1;
    int i=0,sum=0;
    while(i<l)
    {

        if(s[i]=='x'&&s[l]=='x')
        {
            while(s[i]=='x'&&s[l]=='x')i++,l--;
        }
        else if(s[i]==s[l])
        {
            while(s[i]==s[l])i++,l--;
        }
        else if(s[i]=='x')i++,sum++;
        else if(s[l]=='x')l--,sum++;
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<string> s;
string S, res;
int n, m;

void sol(string &s) {
    vector<int> p[2];
    string t = "";
    for (int i = 0; i < s.length(); ++i) p[s[i] == 'a'].push_back(i);

    if (s[0] == 'a') {
        int last = -1;
        for (int i = 0; i < p[1].size(); ++i)
            if (p[1][i] > last) last = p[0][i], t += "ab";
    } else {
        for (int i = 0; i < p[1].size(); ++i) {
            string tp = "";
            int x = i, y = i;
            while (1)
                if (x < p[1].size() && (y == p[0].size() || p[1][x] < p[0][y]))
                    tp += 'a', ++x;
                else if (y < p[0].size())
                    tp += 'b', ++y;
                else
                    break;
            if (tp > t) t = tp;
        }
    }
    s = t;
}

int main() {
    cin >> n >> S;
    int cnt = 0;
    string tmp;
    for (int i = 0; i < n * 2; ++i) {
        (S[i] == 'a') ? cnt++ : cnt--, tmp += S[i];
        if (cnt == 0) s.push_back(tmp), tmp = "";
    }
    for (int i = 0; i < s.size(); ++i) sol(s[i]);
    res = s.back();
    for (int i = (int)s.size() - 2; i >= 0; --i) {
        int flag = 1;
        for (int j = 0; j < min(s[i].length(), res.length()); ++j)
            if (s[i][j] != res[j]) {
                if (s[i][j] < res[j]) flag = 0;
                break;
            }
        if (flag) res = s[i] + res;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
using System.Collections.Generic;
using static System.Console;

class Program {
    static void Main() {
        var n = NextInt();
        var s = NextString();
        var t = NextString();

        var overlap = 0;
        for (var i = n; i >= 0; i--) {
            if (s.Substring(n - i, i) == t.Substring(0, i)) {
                overlap = i;
                break;
            }
        }
        WriteLine(2 * n - overlap);
    }

    static int NextInt() {
        return int.Parse(NextString());
    }

    static string NextString() {
        var result = new List<char>();
        while (true) {
            int next = Read();
            if (next < 0)
                break;
            var nextChar = (char)next;
            if (!char.IsWhiteSpace(nextChar))
                result.Add(nextChar);
            else if (nextChar != '\r')
                break;
        }
        return string.Join("", result);
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a.at(i);
    ll ans = 0;
    rep(i, N){
        if(i % 2 == 0 && a.at(i) % 2 == 1){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include<stdio.h>

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

    while(1){
        c = c - b;
        if(c <= 0){
            printf("Yes\n");
            break;
        }
        a = a - d;
        if(a <= 0){
            printf("No\n");
            break;
        }

    }
    return 0;
}

Measured memory_bytes: 1660
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int A[3][3];
  rep(i,3){
    rep(j,3) cin>>A[i][j];
  }
  
  if(A[0][1]-A[0][0]==A[1][1]-A[1][0] && A[0][1]-A[0][0]==A[2][1]-A[2][0] && A[0][2]-A[0][0]==A[1][2]-A[1][0] && A[0][2]-A[0][0]==A[2][2]-A[2][0]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;

inline ll read(){
	ll x=0,w=1;char c=getchar();
	while(c<'0'||c>'9')w=c=='-'?-1:1,c=getchar();
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*w;
}

ll n,k,ans,t;

int main(){
	n=read(),k=read();
	for(int b=k+1;b<=n;++b){
		t=n/b-1;
		ans+=(b-k)*(t+1)+max(n-b*(t+1)-k+1,0ll);
	}
	if(k==0)ans-=n;
	printf("%lld",ans);
	
	return 0;
}

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

char a[10][10];
char cpy[10][10];
int main() {
    int H, W, K;
    cin >> H >> W >> K;

    for(int i = 0; i < H; i++) {
        string row;
        cin >> row;
        
        for(int j = 0; j < W; j++) {
            a[i][j] = row[j];
        }
    }

    int ans = 0;
    for(int rmask = 0; rmask < (1<<H); rmask++) {
        for(int cmask = 0; cmask < (1<<W); cmask++) {
            for(int i = 0; i < H; i++) {
                for(int j = 0; j < W; j++) {
                    cpy[i][j] = a[i][j];
                }
            }

            for(int i = 0; i < H; i++) {
                if(rmask & (1 << i)) {
                    for(int j = 0; j < W; j++) {
                        cpy[i][j] = 'R';
                    }
                }
            }

            for(int i = 0; i < W; i++) {
                if(cmask & (1 << i)) {
                    for(int j = 0; j < H; j++) {
                        cpy[j][i] = 'R';
                    }
                }
            }   

            // cerr << rmask << " " << cmask << endl;

            int cnt = 0;
            for(int i = 0; i < H; i++) {
                for(int j = 0; j < W; j++) {
                    // cerr << cpy[i][j] << " ";
                    cnt += (cpy[i][j] == '#');
                }
                // cerr << endl;
            }

            ans += cnt==K;
            // cerr << "~~~~~~~~~~~~" << endl;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3624