akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater <>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
using namespace std;
using ll = long long;
typedef std::pair<ll,ll> P;





// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
// combination mod prime
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};



int main(){
    int n,m;
    cin >> n >> m;
    
    if (n==m){
        cout << "Yes";
    }
    else cout << "No";
    rn 0;
}


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

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ii, null_type,less<ii>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>
#define Mod 1000000007
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define T int t;cin>>t;rep(i,t)



void solve() {

    ll n, d, x, y, ans = 0;
    cin >> n >> d;
    d = d*d;

    rep(i, n) {
        cin >> x >> y;
        if (x*x + y*y <= d)
            ans++;
    }

    cout << ans << "\n";
    
 }

int main()
{
    fastio;
    // T
    solve();
    //code
    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ls x<<1
#define rs x<<1|1
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
const ull hashp=1e7+19;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+100;

void solve()
{
	int a,b,c,d;
	scdd(a,b);
	scdd(c,d);
	if(a!=c)printf("1");
	else printf("0");
}
int main(){
    //IOS;
    solve();
    return 0;
}

Measured memory_bytes: 256
INF=10**6
f=lambda:map(int,input().split())
h,w=f()
ch,cw=f()
ch-=1
cw-=1
dh,dw=f()
dh-=1
dw-=1
g=[input() for _ in range(h)]
from collections import *
def grid_01_bfs(x,y):
  d=[[INF]*w for _ in range(h)]
  d[x][y]=0
  q=deque([(0,x,y)])
  while q:
    td,tx,ty=q.popleft()
    if d[tx][ty]<td: continue
    for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]:
      nx,ny=tx+dx,ty+dy
      if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]>td:
        d[nx][ny]=td
        q.appendleft((d[nx][ny],nx,ny))
    for dx in range(-2,3):
      for dy in range(-2,3):
        nx,ny=tx+dx,ty+dy
        if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]>td+1:
          d[nx][ny]=td+1
          q.append((d[nx][ny],nx,ny))
  return d
a=grid_01_bfs(ch,cw)[dh][dw]
print([-1,a][a<INF])

Measured memory_bytes: 123468
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main()
{
  string s, t;
  cin >> s >> t;
  int slen = s.size(), tlen = t.size();
  
  int dp[3030][3030] = {};
  for (int i = 0; i < slen; i++)
    for (int j = 0; j < tlen; j++)
      if (s[i] == t[j])
        dp[i+1][j+1] = dp[i][j] + 1;
      else if (dp[i][j+1] > dp[i+1][j])
        dp[i+1][j+1] = dp[i][j+1];
      else
        dp[i+1][j+1] = dp[i+1][j];
  
  int x = s.size(), y = t.size();
  string ans = "";
  while (x)
    if (s[x-1] == t[y-1]) {
      ans += s[x-1];
      x--;
      y--;
    } else if (x != 0 && dp[x][y] == dp[x-1][y])
      x--;
    else
      y--;
  
  reverse(ans.begin(), ans.end());
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 36096
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=1e6+10;
int dp[N][2][2];
int n;
int go(int pos,int f1,int f2)
{
	if(pos==n+1)
	{
		return (f1==1&&f2==1);
	}
	int &ans=dp[pos][f1][f2];
	if(ans!=-1)
		return ans;
	ans=0;
	for(int i=0;i<=9;i++)
	{
		ans+=go(pos+1,f1|(i==0),f2|(i==9));
		ans%=MOD;
	}
	return ans;
}
int32_t main()
{
	IOS;
	cin>>n;
	memset(dp,-1,sizeof(dp));
	cout<<go(1,0,0)<<endl;
}

Measured memory_bytes: 97292
#include<cstdio>
using namespace std;
typedef long long ll;
const int N=200200;
int i,j,k,n,m,ch,ff;
int a[N];
ll ans,s[N];
void R(int &x) {
	x=ff=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void W(int x) {
	if (x<0) putchar('-'),x=-x;
	if (x>=10) W(x/10);
	putchar(x%10+'0');
}
void R(ll &x) {
	x=ff=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void W(ll x) {
	if (x<0) putchar('-'),x=-x;
	if (x>=10) W(x/10);
	putchar(x%10+'0');
}
int main() {
	ans=1000000000000000000ll;
	R(n);
	for (i=1;i<=n;i++) R(a[i]);
	for (i=1;i<=n;i++) s[i]+=a[i]+s[i-1];
	for (i=1;i<n;i++) {
		ll sum1=s[i];
		ll sum2=s[n]-sum1;
		ll t=sum1-sum2;
		if (t<0) t=-t;
		if (t<ans) ans=t;
	}
	W(ans);puts("");
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdlib>

using namespace std;

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

int cost[100010];
int h[100010];

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

    cost[0] = 0;
    REP(i, N) {
        cin >> h[i+1];
        cost[i+1] = 0;
    }

    for(int i=1; i<N; i++) {
        if (i+1 >= 3) {
            cost[i+1] = min(cost[i]+abs(h[i]-h[i+1]),
                        cost[i-1]+abs(h[i-1]-h[i+1]));
        } else {
            cost[i+1] = cost[i] + abs(h[i]-h[i+1]);
        }
    }

    cout << cost[N] << endl;
}


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

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  ll x[100005];
  rep(i,n) cin>>x[i];
  ll ans=0;
  rep(i,n-1){
    if((x[i+1]-x[i])*a>b) ans+=b;
    else ans+=(x[i+1]-x[i])*a;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
a, v = [int(a) for a in input().split()]
b, w = [int(a) for a in input().split()]
t = int(input())


distance = abs(b-a)

ds = v - w


ans = ""
if (ds * t) < (distance):
  ans = "NO"
else:
  ans = "YES"
print(ans)


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

int main(){
	int p,q,r;
	cin >> p >> q >> r;
	
	cout << (p+q+r) - max(p,max(q,r)) << endl;

	return 0;
}

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

int main(){

    int a,b,c;
    cin >> a >> b >> c;
    int ab,bc,ca;
    ab = a+b;
    bc = b+c;
    ca = c+a;

    cout << min(ab,min(bc,ca)) << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    cout<<(n+110)/111*111<<endl;
    return 0;
}

Measured memory_bytes: 256
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g PROGRAM -o OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;

typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;


inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d,string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while(getline(ss,t,d))
    {
        words.pb(t);
    }

    return words;
}

int main(int argc, char *argv[])
{
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int x;
    cin >> x;
    cout << (int)!(x);

    return 0;
}


Measured memory_bytes: 3656
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
    WRITER:kakitamasziru/OxOmisosiru
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#define _GLIBCXX_DEBUG
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100100;
const int MOD = 1000000007;
typedef pair<int,int> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

//dp[i][j][k]:(i-1,j)から(i,j)なら[0],(i,j-1)から(i,j)なら[1].
long long dp[114][114][2];

int main() {
    int X;cin >> X;
    if(X >= 2000) {
        cout << 1 << endl;
        return 0;
    }
    int Z = X%100;
    X /= 100;
    int ans = 0;
    for(int i = 0;i<=X;i++){
        for(int j = 0;j<=X;j++){
            for(int k = 0;k<=X;k++){
                for(int l = 0;l<=X;l++){
                    for(int m = 0;m<=X;m++){
                        for(int n = 0;n<=X;n++){
                            if(i+j+k+l+m+n > X) continue;
                            if(j+k*2+l*3+m*4+n*5 == Z) ans = 1;
                        }
                    }
                }
            }
        }
    }

    cout << ans << endl;

    
    // PLEASE GIVE ME THE "ACCEPTED" !
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
using ll = long long;
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vi a(n);
  map<int, int> check;
  rep(i, n){
    cin >> a[i];
    check[a[i]]++;
  }
  vi temp;
  for(auto x : check){
    temp.push_back(x.second);
  }
  sort(temp.begin(), temp.end());
  reverse(temp.begin(), temp.end());
  int changes = 0;
  if(temp.size() > k){
    rep(i, k){
      changes += temp[i];
    }
  }else changes = n;
  cout << n - changes << endl;
}

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

char next(char x){
	if(x == '?')return x;
	if(x == 'Z')return 'A';
	return x+1;
}

char before(char x){
	if(x == '?')return x;
	if(x == 'A')return 'Z';
	return x-1;
}

string rev(string x){
	string res = "";
	for(int i = x.size() - 1;i >= 0;i--)res += x[i];
	return res;
}

char getletter(string &str, int &pos){
	if(str[pos] == '+'){
		pos++;
		return next(getletter(str, pos));
	}
	if(str[pos] == '-'){
		pos++;
		return before(getletter(str, pos));
	}
	return str[pos++];
}

string perse(string &str, int &pos);

string getstring(string &str, int &pos){
	if(str[pos] == '['){
		pos++;
		return rev(perse(str, pos));
	}
	string x = "";
	x += getletter(str, pos);
	return x;
	
}

string perse(string &str, int &pos){
	if(pos == str.size() || str[pos] == ']'){
		if(pos != str.size())pos++;
		return "";
	}
	string res = getstring(str, pos);
	return res + perse(str, pos);
}

int main(){
	string str;
	while(cin >> str, str != "."){
		int p = 0;	
		str = perse(str, p);
		for(int i = 0;i < str.size();i++){
			if(str[i] == '?')cout << 'A';
			else cout << str[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define U [100005]={}
typedef long long L;using namespace std;map<L,L> path U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p,r;char s U;L D(L a){Z[a]=1;for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){L d=I->first;if(d-P[a]){P[d]=a;E[d]=E[a]+1;C[d]=I->second;D(d);Z[a]+=Z[d];if(!H[a]|Z[H[a]]<Z[d])H[a]=d;}}}L G(L a){r=A[a]+A[P[a]]+C[a];return r%k?r:0;}L M(L i){for(r=0;i;r+=B[i],i-=i&-i);return r;}L S(L i,L x){for(x=G(x)-M(i+1)+M(i++);i<100005;B[i]+=x,i+=i&-i);}main(){for(cin>>n>>k;p<n-1;p++)cin>>a>>b>>c,path[a][b]=path[b][a]=c;D(0);for(c=p=0;p<n;p++)if(!p|H[P[p]]-p)for(a=p;!c|a;a=H[a])O[a]=c++,X[a]=p,S(O[a],H[a]);for(cin>>a;cin>>s>>a>>b;)if(*s&2){for(c=0;p=X[a],n=X[b],p-n;a=P[p])E[p]<E[n]?swap(p,n),swap(a,b),0:0,c+=M(O[a])-M(O[p])+G(p);cout<<c+abs(M(O[a])-M(O[b]))<<endl;}else A[a]+=b,S(O[a],H[a]),a?S(O[a]-1,a):0;}

Measured memory_bytes: 31888
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int num = 0;
		int max = 0;
		
		for(int i = 1; i <= N; i++) {
			int count = 0;
			int x = i;
			while(x % 2 == 0) {
				count++;
				x /= 2;
			}
			if(num <= count) {
				max = i;
				num = count;
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mpr make_pair
#define mt make_tuple
 
using namespace std;
 
const ll N = 100010;
const ll mod = 1e9 + 7;
ll power(ll x, ll   y, ll p){ ll res = 1; x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;} return res; }

ll dp[110][N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,w;
    ll arr[N][2];
    cin>>n>>w;
    memset(dp, 0, sizeof(dp));
    for(int i=1;i<=n;i++)    cin>>arr[i][0]>>arr[i][1];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            if(j >= arr[i][0])
                dp[i][j] = max({dp[i][j-1], dp[i-1][j], arr[i][1] + dp[i-1][j-arr[i][0]]});
            else    dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    cout<<dp[n][w]<<endl;
    return 0;
}

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

int main() {
    long long n, a, b, c, d, e, k;
    cin >> n >> a >> b >> c >> d >> e;
    k = min({a, b, c, d, e});
    cout << (n + k - 1) / k + 4 << endl;
}

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

int main(){
	int N,A,B,C,D;
	char S[200001];
	int min,max,fin,start;
	int i;
	int cross;
	scanf("%d %d %d %d %d",&N,&A,&B,&C,&D);
	scanf("%s",&S);
	if(A<B){
		min=A-1;
		start=B-1;
	}
	else{
		min =B-1;
		start= A-1;
	}
	if(C>D){
		max=C-1;
		fin=D-1;
	}
	else{
		max = D-1;
		fin =C-1;
	}
	if(A>B&&C>D || B>A&& D>C)cross=0;
	else cross = 1;
	
	for(i=min;i<max;i++){
		if(S[i]=='#'&&S[i+1]=='#'){
			printf("No\n");
			return 0;
			break;
		}
	}
	if(cross==0){
		printf("Yes\n");
	}
	if(cross == 1){
		for(i=start;i<fin;i++){
		if(i<fin-1&&S[i]=='.'&&S[i+1]=='.'&&S[i+2]=='.'){
			printf("Yes\n");
			return 0;
			break;
		}
		}
		if(S[fin-1] == '.' && S[fin+1] == '.'){
			printf("Yes\n");
		}
		else if(S[start+1] == '.' && S[start-1] == '.'){
			printf("Yes\n");
		}
		else printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ld long double
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

void print(Vl vec){
    rep(i, 0, sz(vec)){
        if(i) cout << " ";
        cout << vec[i];
    }
    coel;
}

////////////////////////////////////////////////////////


int main() {
    ll n; cin >> n;
    Vl a(n), b(n);
    rep(i, 0, n) cin >> a[i] >> b[i];
    ll t = a[0], ao = b[0];
    rep(i, 1, n){
        ll c = t/a[i], d = ao/b[i];
        if(t%a[i] == 0) c--;
        if(ao%b[i] == 0) d--;
        ll e = max(c+1, d+1);
        t = a[i]*e, ao = b[i]*e;
    }
    co(t+ao);

    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
const array<int, 3> NEXT = { 0, 2, 1 };
vector<int> POW3;
vector<vector<int>> poss;
vector<vector<string>> strs;
void init(int N, const string &T) {
    POW3.resize(N + 1);
    POW3[0] = 1;
    for (int i = 1; i <= N; i++) POW3[i] = POW3[i - 1] * 3;
    poss.resize(N + 1);
    strs.resize(N + 1);
    for (int i = 0; i <= N; i++) {
        poss[i].resize(POW3[i], -1);
        strs[i].resize(POW3[i]);
    }
    poss[0][0] = 0;
    strs[0][0] = T;
}
void f(int k, int p) {
    if (poss[k][p] != -1) return;
    f(k - 1, p % POW3[k - 1]);
    int t = p / POW3[k - 1];
    string U;
    for (auto c : strs[k - 1][p % POW3[k - 1]]) {
        if (c == 'S') {
            t = NEXT[t];
            if (!U.empty() && U.back() == 'S') {
                U.pop_back();
            } else {
                U.push_back('S');
            }
        } else {
            t = (t + 1) % 3;
            if (t == 0) {
                U.push_back('R');
            }
        }
    }
    poss[k][p] = t * POW3[k - 1] + poss[k - 1][p % POW3[k - 1]];
    strs[k][p] = U;
}
int main() {
    int N; string T; cin >> N >> T;
    init(N, T);
    for (int i = 0; i < POW3[N]; i++) {
        f(N, i);
        cout << poss[N][i] << " \n"[i + 1 == POW3[N]];
    }
    return 0;
}


Measured memory_bytes: 34964
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

const int N = 5e5 + 7;
const int inf = 1e9 + 7;

int t[4 * N];
int p[N];

void upd(int v, int l, int r, int i, int x)
{
    if (r - l == 1)
    {
        t[v] = x;
    }
    else
    {
        int m = (l + r) / 2;
        if (i < m)
        {
            upd(v * 2 + 1, l, m, i, x);
        }
        else
        {
            upd(v * 2 + 2, m, r, i, x);
        }
        t[v] = max(t[v * 2 + 1], t[v * 2 + 2]);
    }
}

int get(int v, int l, int r, int tl, int tr)
{
    if (tl >= r || tr <= l)
    {
        return -inf;
    }
    if (tl >= l && tr <= r)
    {
        return t[v];
    }
    else
    {
        int tm = (tl + tr) / 2;
        return max(get(v * 2 + 1, l, r, tl, tm), get(v * 2 + 2, l, r, tm, tr));
    }
}

int n, k;

bool check(int x)
{
    int l = max(0, x - k + 1);
    int r = min(n - 1, x + k - 1);
    return get(0, l, r + 1, 0, n) == p[x];
}

set <pair <int, int> > s[N];
int local[N];
set <int> q;

void upd_bucket(int ind)
{
    if (local[ind] != -1)
    {
        q.erase(local[ind]);
    }
    if (!s[ind].empty() && s[ind].rbegin()->first != -inf && check(s[ind].rbegin()->second))
    {
        local[ind] = s[ind].rbegin()->second;
        q.insert(local[ind]);
    }
    else
    {
        local[ind] = -1;
    }
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
        p[i]--;
        upd(0, 0, n, i, p[i]);
        s[i / k].insert({p[i], i});
        local[i / k] = -1;
    }
    for (int i = 0; i <= (n - 1) / k; i++)
    {
        upd_bucket(i);
    }
    vector <int> ans(n);
    int cur = n;
    while (!q.empty())
    {
        int v = *q.rbegin();
        q.erase(--q.end());
        ans[v] = cur--;
        s[v / k].erase({p[v], v});
        upd(0, 0, n, v, -inf);
        for (int it = max(0, v / k - 1); it <= min((n - 1) / k, v / k + 1); it++)
        {
            upd_bucket(it);
        }
    }
    for (int i = 0; i < n; i++)
    {
        cout << ans[i] << '\n';
    }
}


Measured memory_bytes: 85120
s = list(input())
slen = len(s)

count_0 = 0
count_1 = 0

#0-start

for i in s[0::2]:
	if i != '0':
		count_0 += 1
for i in s[1::2]:
	if i != '1':
		count_0 += 1

for i in s[0::2]:
	if i != '1':
		count_1 += 1
for i in s[1::2]:
	if i != '0':
		count_1 += 1

if count_1 > count_0:
	print(count_0)
else:
	print(count_1)

Measured memory_bytes: 4268
import java.util.*;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();


    if (a >= 1000) {
      System.out.println("ABD");
    }
    if (a<= 999) {
      System.out.println("ABC");
    }
  }
}


Measured memory_bytes: 21716
import java.util.Scanner;
import java.util.ArrayList;

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

		int x = sc.nextInt();

		while (!isPrime(x)) x++;

		System.out.println(x);
	}

	public static boolean isPrime(int x) {
		if (x <= 1 ) return false;
		else {
			for (int i = 2; i * i < x; i++){
				if (x % i == 0) return false;

			}	
			return true;

		}
	}
}

Measured memory_bytes: 23764
import sys

input = sys.stdin.readline

N = int(input())
A, B, AB = 'A', 'B', 'AB'
endA, startB, startB_endA = 0, 0, 0
ans = 0

for _ in range(N):
    S = input().rstrip()

    if S[0] == B:
        startB += 1

        if S[-1] == A:
            startB -= 1
            startB_endA += 1

    elif S[-1] == A:
        endA += 1
    

    for i in range(1,len(S)):
        if S[i-1] + S[i] == AB:
            ans += 1


if startB_endA == 0:
    ans += min(endA, startB)

elif endA == 0 and startB == 0:
    ans += max(0, startB_endA - 1)

else:
    ans += startB_endA + min(endA, startB)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned ll
#define F first                                                                                         
#define S second
#define mp make_pair
#define pb push_back
#define y1 variable
#define matrix vector<vector<double> > 

using namespace std;

const int MIN = 2e3 + 2;                                                                                                                                  
const int MXN = 2e6 + 3;
const int INF = 1e9 + 7;                                                                                                       
const int base = 1e9;
const ll LINF = 1e18 + 15;
const double EPS = 1e-15;                                                                                                                 

string n;
int sum;
int id;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);             
	cout.tie(0); 
   	#ifdef Pissoir              	
		//freopen("input.txt", "r", stdin);                                                                                                              
		//freopen("output.txt", "w", stdout);                       
	#else                                                                                           
		//freopen("typing.in", "r", stdin);
  		//freopen("typing.out", "w", stdout);			
    #endif
    cin >> n;
    int mx = 0;
    for (int i = 0; i < n.size(); ++i){
        if (n[i] - '0') mx = max(mx, sum + n[i] - '0' - 1 + ((int)n.size() - i - 1) * 9);
    	sum += n[i] - '0';
    }
    mx = max(mx, ((int)n.size() - 1) * 9);
    mx = max(mx, sum);
    cout << mx;
	return 0;	
}

Measured memory_bytes: 256
import heapq

def solve():
    N, M = map(int, input().split())
    A = list(map(lambda x: int(x) * -1, input().split()))
    
    heapq.heapify(A)
    
    for _ in range(M):
      t = heapq.heappop(A)
      heapq.heappush(A, -1*(-t//2))
    
    return -sum(A)

print(solve())

Measured memory_bytes: 14180
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("fma,avx")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

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

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(all(a));
    reverse(all(a));
    int ans = a[0];
    int cnt = 1;
    for (int i = 1; i < n && cnt < n - 1; i++) {
        if (n - cnt >= 3) ans += 2 * a[i];
        else ans += a[i];
        cnt += 2;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 4816
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	x := getNextInt(scanner)
	d := 0
	var i int
	for i = 1; i <= n; i++ {
		d += getNextInt(scanner)
		if d > x {
			break
		}
	}
	fmt.Fprintln(writer, i)

	writer.Flush()
}


Measured memory_bytes: 640
n=int(input())
a=[0]+list(map(int, input().split()))

dp=[10**10]*(n+1)

dp[0]=0
dp[1]=0

dp[2]=abs(a[1]-a[2])
for i in range(3,n+1):
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]))
print(dp[n])

Measured memory_bytes: 85640
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cassert>
using namespace std;

struct LowestCommonAncestor {
    size_t n;
    size_t size() const { return n; }
    vector<int> color, parent, depth, topDepth, goUp, visited;
    vector<vector<int>> g;
    LowestCommonAncestor(size_t n_) : n(n_), g(n) {}
    void addEdge(int u, int v){
        g[u].push_back(v); g[v].push_back(u);
    }
    void decomp(int root = 0, int B = 300){
        parent.assign(n, -1); depth.assign(n, 0);
        topDepth.assign(n, 0); goUp.assign(n, -1); visited.assign(n, false);
        vector<int> tord;
        vector<int> q(n+1); int l = 0, r = 0;
        q[r++] = root;
        while(l != r){
            int v = q[l++]; visited[v] = true;
            tord.push_back(v);
            for(int c : g[v]){
                if(!visited[c]){ parent[c] = v; depth[c] = depth[v] + 1; q[r++] = c; }
            }
        }
        swap(color, visited); // ?????¢????????±??????
        color.assign(n, 0);
        int c = 0;
        for(int u : tord){
            if(color[u]) continue;
            c++;
            l = 0, r = 0;
            q[r++] = u;
            for(int i = 0; i < B && l != r; i++){
                int v = q[l++];
                color[v] = c; goUp[v] = parent[u]; topDepth[v] = depth[u];
                for(int c : g[v]) if(!color[c]) q[r++] = c;
            }
        }
    }
    int solve(int u, int v){
        while(color[u] != color[v]){
            if(topDepth[u] > topDepth[v]) u = goUp[u];
            else v = goUp[v];
        }
        while(u != v){
            if(depth[u] > depth[v]) u = parent[u];
            else v = parent[v];
        }
        return u;
    }
};

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

int main(){
    int n;
    cin >> n;
    LowestCommonAncestor g(n);
    rep(i,n){
        int k;
        cin >> k;
        rep(j,k){
            int c;
            cin >> c;
            g.addEdge(i,c);
        }
    }
    g.decomp(0);
    int q;
    cin >> q;
    rep(i,q){
        int u,v;
        cin >> u >> v;
        cout << g.solve(u,v) << endl;
    }
}

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

bool solve() {
    int H, W;
    cin >> H >> W;
    int cnt[26] = {};
    for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) {
        char c;
        cin >> c;
        cnt[c - 'a']++;
    }

    int four = (H / 2) * (W / 2);
    int two = (H & 1 ? W / 2 : 0) + (W & 1 ? H / 2 : 0);
    int one = (H & 1) && (W & 1);
    for(int i = 0; i < 26 && four; i++) {
        int n = min(four, cnt[i] / 4);
        cnt[i] -= n * 4;
        four -= n;
    }
    for(int i = 0; i < 26 && two; i++) {
        int n = min(two, cnt[i] / 2);
        cnt[i] -= n * 2;
        two -= n;
    }
    for(int i = 0; i < 26 && one; i++) {
        if(cnt[i] & 1) {
            one = 0;
            cnt[i]--;
            break;
        }
    }
    return one == 0 &&
           two == 0 &&
           four == 0;
}

int main() {
    cout << (solve() ? "Yes" : "No") << endl;
    return 0;
}


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

using namespace std;

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

	int n;
	vector<int> A;
	int max_n, max_r;

	cin >> n;
	A.resize(n);

	max_n = -1;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		if (max_n < A[i]) {
			max_n = A[i];
		}
	}

	max_r = max_n;
	for (int i = 0; i < n; i++) {
		int r1, r2;

		if (max_r == A[i]) {
			continue;
		}

		if (max_r > A[i]) {
			r2 = max_r;
			r1 = A[i];
		} else {
			r2 = A[i];
			r1 = max_r;
		}

		if (r1 + r2 < max_n) {
			max_r = r2;
		} else {
			max_r = r1;
		}
	}

	cout << max_n << " " << max_r << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;

	if (u == s) a--;
	else b--;
	
	cout << a << " " << b << endl;
}

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() {
    int n;
    cin >> n;
    string tmp, p, q, o;
    rep(i, n) {
        cin >> tmp;
        p += tmp;
    }
    rep(i, n) {
        cin >> tmp;
        q += tmp;
        o += to_string(i + 1);
    }
    map<string, int> m;
    int cnt = 1;
    do {
        m[o] = cnt;
        cnt++;
        // cout << o << endl;
    } while(next_permutation(o.begin(), o.end()));
    cout << abs(m[p] - m[q]) << endl;
    return 0;
}

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

using namespace std;

const int maxn = 1e5 + 10;

long long m, n;
char s[maxn], t[maxn];
map <long long, char> f;

int main() {
	scanf("%lld%lld%s%s", &m, &n, s, t);
	
	long long k = n / __gcd(m, n) * m;
	long long x = k / m, y = k / n;
	
	for (int i = 0; i < m; ++i) f[i * x] = s[i];
	for (int i = 0; i < n; ++i) if (f.count(i * y) && f[i * y] != t[i]) {
		puts("-1");
		return 0;
	}
	cout << k << "\n";
	return 0;
}

Measured memory_bytes: 6144
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

index = 1
co = 0
for i in range(len(A)):
	if A[i] == index:
		index += 1
	else:
		continue

if index == 1:
	print(-1)
else:
	print(N - (index -1))

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

int main() {
    int n;
    cin >> n;
    vector< tuple<ll, ll, ll> > h(n+1);

    h[0] = make_tuple(0, 0, 0);
    for(int i = 1; i <= n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        ll a_prev, b_prev, c_prev;
        a_prev = get<0>(h[i-1]);
        b_prev = get<1>(h[i-1]);
        c_prev = get<2>(h[i-1]);
        h[i] = make_tuple(a + max(b_prev, c_prev),
                          b + max(c_prev, a_prev),
                          c + max(a_prev, b_prev));
    }
    cout << max({get<0>(h[n]), get<1>(h[n]), get<2>(h[n])}) << endl;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll X, K, D; cin >> X >> K >> D;
    if(X < 0) X = -X;
    // X - nD >= 0
    // n <= X/D
    ll n = X/D;
    if(n >= K) cout << X - K*D << endl;
    else{
        X = X - n*D;
        K -= n;
        if(K % 2) cout << abs(X-D) << endl;
        else cout << X << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    _ = int(input())
    A = list(map(int, input().split()))

    D = [[0, 0] for _ in range(70)]
    for a in A:
        for i in range(70):
            if (a >> i) & 1:
                D[i][1] += 1
            else:
                D[i][0] += 1

    res = 0
    for i in range(70):
        res += D[i][0] * D[i][1] * 2 ** i
        res %= 10 ** 9 + 7
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 123224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ull x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll l(n), r(n);
    ll max_width = 0;
    rep(i, n){
        cin >> l[i] >> r[i];
        r[i]++;
        chmax(max_width, r[i]-l[i]);
    }
    vp lr(n);
    rep(i, n){
        lr[i] = {l[i], r[i]};
    }
    ll mir = *min_element(ALL(r));
    ll mal = *max_element(ALL(l));
    ll ans1 = max(mir-mal, 0ll)+max_width;
    sort(ALL(lr), [](auto& a, auto& b){if(a.first == b.first) return a.second > b.second; else return a.first < b.first;});
    
    
    vll ans(n-1);
    vll a(n), b(n);
    rep(i, n){
        a[i] = max(lr[i].second-mal, 0ll);
        b[i] = max(mir-lr[i].first, 0ll);
    }
    vll a_acc(n), b_acc(n);
    a_acc[n-1] = a[n-1];
    repb(i, n-1){
        a_acc[i] = min(a_acc[i+1], a[i]);
    }
    b_acc[0] = b[0];
    repr(i, 1, n){
        b_acc[i] = min(b_acc[i-1], b[i]);
    }
    rep(i, n-1){
        ans[i] = a_acc[i+1] + b_acc[i];
    }
    cout << max(ans1, *max_element(ALL(ans))) << endl;
    dump(ans1, ans, a, b, a_acc, b_acc);
    return 0;
}

Measured memory_bytes: 7296
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

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

func main() {
	defer stdout.Flush()
	H := readInt() + 2
	W := readInt() + 2
	A := make([][]byte, H)
	dist := make([][]int, H)
	q := make([]struct{ y, x int }, 0)
	push := func(y, x int) {
		q = append(q, struct{ y, x int }{y, x})
	}
	pop := func() (int, int) {
		res := q[0]
		q = q[1:]
		return res.y, res.x
	}

	for i := range A {
		A[i] = append(A[i], 'x')
		if i == 0 || i == H-1 {
			for j := 0; j < W-2; j++ {
				A[i] = append(A[i], 'x')
			}
		} else {
			A[i] = append(A[i], readBytes()...)
		}
		A[i] = append(A[i], 'x')
		dist[i] = make([]int, W)
		for j := range dist[i] {
			if A[i][j] == '#' {
				dist[i][j] = 0
				push(i, j)
			} else {
				dist[i][j] = 1000000007
			}
		}
	}

	dx := []int{-1, 0, 1, 0}
	dy := []int{0, -1, 0, 1}
	var ans int
	for len(q) != 0 {
		y, x := pop()
		d := dist[y][x]
		ans = max(ans, d)
		nd := d + 1
		for i := range dx {
			nx := x + dx[i]
			ny := y + dy[i]
			if A[ny][nx] != '.' || dist[ny][nx] <= nd {
				continue
			}
			dist[ny][nx] = nd
			push(ny, nx)
		}
	}
	println(ans)
}

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


Measured memory_bytes: 72192
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

int n;
int p[800], d[800];
vector<P> e[800];
bool unuse[800];

ll dfs(int t, int ori){
	ll ret = 0;
	rep(i,e[t].size()){
		if(unuse[e[t][i].first]) continue;
		if(e[t][i].first == ori) continue;
		ret = max(ret,dfs(e[t][i].first,t)+e[t][i].second);
	}
	return ret;
}

void solve(){
	rep(i,800) e[i].clear();
	rep(i,800) unuse[i] = false;
	ll ans = 0;
	rep(i,n-1){
		e[i+1].push_back(P(p[i],d[i]));
		e[p[i]].push_back(P(i+1,d[i]));
		ans += d[i]*3;
	}
	ll del = 0;
	rep(i,n) if(e[i].size() == 1) unuse[i] = true;
	rep(i,n){
		if(e[i].size() == 1){
			 del = max(del,dfs(e[i][0].first,-1));
			 ans -= e[i][0].second*2;
		}
	}
	cout << ans-del << endl;
}

int main(){
	while(cin >> n){
		if(n == 0) break;
		rep(i,n-1) cin >> p[i];
		rep(i,n-1) p[i]--;
		rep(i,n-1) cin >> d[i];
		solve();
	}
}

Measured memory_bytes: 1360
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
    ll n,i;
    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    ll ans=0;
    ll flag=0;
    while(1)
    {
        for(i=0;i<n;i++)
        {
            if(arr[i]%2==0)
            {
                arr[i]/=2;
            }
            else
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
        {
            ans++;
        }
        else
        {
            break;
        }
    }

    cout<<ans<<endl;
}


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

int main() {
	int n;
	cin >> n;
	vector<int> in(n);
	for(int i = 0; i < n; i++) {
		cin >> in[i];
	}
	vector<int> ans(n);
	int index = 0;
	for(int i = in.size()-1; i >= 0; i--) {
		ans[index] = in[i];
		index += i*(((n-i)%2!=0)?1:-1);
	}
	cout << ans[0];
	for(int i = 1; i < n; i++) {
		cout << " " << ans[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3712
N, M = map(int, input().split())
PY = [tuple(list(map(int, input().split()))+[i]) for i in range(M)]
PY.sort(key=lambda x: x[1])
ans = ['']*M
P = [0]*N
for p, y, i in PY:
    ret = ''
    p -= 1
    P[p] += 1
    ret += '{:0=6}'.format(p+1)
    ret += '{:0=6}'.format(P[p])
    ans[i] = ret
print(*ans, sep='\n')


Measured memory_bytes: 31304