akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int a, b, h; cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;

    return 0;
}


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

#define endl '\n'

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define BUFF ios::sync_with_stdio(0);

typedef long long int ll;
typedef long double ld;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef pair < int, int > ii;
typedef vector < ii > vii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const int MOD = 1e9+7;
const ld pi = acos(-1);

int main() { BUFF
  int n; ll k; cin >> n >> k;
  vi a(n+1, 0); for(int i=1; i<=n; i++) cin >> a[i];
  vi seen(n+1, 0);
  int pos = 1, cnt = 1;
  while(1) {
    if(seen[pos]) {
      if(k <= seen[pos]) {
        for(int i=1; i<=n; i++) {
          if(seen[i] == k) {cout << a[i] << endl; break;}
        }
        return 0;
      }

      k -= seen[pos];
      k = seen[pos] + (k % (cnt - seen[pos]));
      for(int i=1; i<=n; i++) {
        if(seen[i] == k) {cout << a[i] << endl; break;}
      }
      return 0;
    }
    else {
      seen[pos] = cnt++;
      pos = a[pos]; 
    }
  }
  return 0;
}


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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int ans=0;
  rep(i,n){
    int a;
    cin >> a;
    while(a%2==0) {
      a /=2;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
	int main(){
		int n,i=0;
		int s[10];
		while(scanf("%d",&n)!=EOF){
			if(n>0){
				s[i]=n;
				i++;
			}else{
				i--;
				printf("%d\n",s[i]);
			}
		}
		return 0;
	}

Measured memory_bytes: 1812
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  int n = s.size();
  if(n < 26) {
    vb k(26, false);
    rep(i, n) k[s[i] - 'a'] = true;
    cout << s;
    rep(i, n + 1) {
      if(!k[i]) {
        cout << char('a' + i) << endl;
        return 0;
      }
    }
  }
  string os = s;
  do {
    if(os == s) continue;
    rep(i, n) {
      cout << s[i];
      if(os[i] != s[i]) return 0;
    }
  } while(next_permutation(all(s)));
  cout << -1 << endl;
}

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

using namespace std;

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

  sort(vi.begin(), vi.end());
  for(int i=0; i<n-1; i++) vi[i+1] = (vi[i] + vi[i+1]) / 2.0;
  printf("%lf\n", vi[n-1] );
  return 0;
}


Measured memory_bytes: 256
program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,k,m,n,ans
    integer(8)::a,b,c,d
    integer(8),allocatable::x(:),y(:)
  
    read(*,*) n,k
    allocate(x(n))
    read(*,*)x
    a=0
    do i=1,n
        if(mod(x(i),2)==0)then
            a=a+1
        end if
    end do
    
    b=n-a
    if(k==0)then
        ans=2**a
        if(b>0)then
            ans=ans*2**(b-1)
        end if
    else
        if(b==0)then
            ans=0
        else
            ans=2**a*2**(b-1)
        end if
    end if
    write(*,*)ans


    stop
end program sample
  



Measured memory_bytes: 2804
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct TEMP_OMAZINAI_ { TEMP_OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } TEMP__omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void TEMP_INPUT_IMPL_() {};
template <class T, class... Args> void TEMP_INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; TEMP_INPUT_IMPL_(args...); }
void TEMP_OUTPUT_IMPL_() {};
template <class T, class... Args> void TEMP_OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); TEMP_OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; TEMP_INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (TEMP_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))
 
 // ^^^ Template ^^^ //

int main() {
	in(int, H, W);
	while(H--){
		in(string, s);
		cout << s << endl << s << endl;
	}
}



Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split(" ")))
abs_list = list(map(abs, A))
abs_list.sort()
pos = list(filter(lambda x: x > 0, A))
neg = list(filter(lambda x: x < 0, A))
pos.sort()
neg.sort()

# A has 0
if abs_list[0] == 0:
	print(sum(abs_list))
elif len(neg) % 2 == 0:
	print(sum(abs_list))
elif len(pos) > 0 and abs(pos[0]) < abs(neg[-1]):
	print(sum(abs_list) - 2*pos[0])
else:
	print(sum(abs_list[1:])-abs_list[0])



Measured memory_bytes: 14412
#include<stdio.h>

int main(void){
	int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	d = a/b;
	r = a%b;
	f =1.000000000*a/b;
	printf("%d %d %.8lf\n",d,r,f);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = __int64_t;

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

void solve(){
  char b;
  cin >> b;
  if(b == 'A'){
    cout << "T" << endl;
  }else if(b == 'C'){
    cout << "G" << endl;
  }else if(b == 'G'){
    cout << "C" << endl;
  }else if(b == 'T'){
    cout << "A" << endl;
  }
}

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

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <bitset>

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

using namespace std;

int main() {
	int N, count = 0, t;
	scanf("%d", &N);
	vector<int> a(N);
	rep(i, N) {
		scanf("%d", &a[i]);
	}
	rep(i, N) {
		if (i == 0) t = a[0];
		else t = a[t - 1];
		count++;
		if (t == 2) {
			break;
		}
	}
	if (count == N) count = -1;
	printf("%d", count);
}




Measured memory_bytes: 3800
n = int(input())
a = list(map(int, input().split()))

dp = [[0] * 2 for i in range(n + 1)]

# dp[i + 1][j] := i 番目までの最大値（j = 1 なら a[i] の符号反転）

dp[0][1] = -float("inf")
for i in range(n):
    dp[i + 1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i])
    dp[i + 1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i])

print(dp[n][0])

Measured memory_bytes: 25588
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using i64 = int64_t;
#define rep(i, s, n) for (i64 i = (s); i < (n); ++i)

template <typename T, T M> class modint {
public:
  T v{};
  modint(){}
  modint(T v) : v{v % M + (((v % M) < 0) ? M : 0)} {}
  modint operator+(modint other) { return modint{v + other.v}; }
  modint operator-(modint other) { return modint{v - other.v}; }
  modint operator*(modint other) { return modint{v * other.v}; }
  modint operator/(modint other) { return modint{v / other.v}; }
  modint operator+=(modint other) {
    *this = *this + other;
    return *this;
  }
  modint operator-=(modint other) {
    *this = *this - other;
    return *this;
  }
  modint operator*=(modint other) {
    *this = *this * other;
    return *this;
  }
  modint operator/=(modint other) {
    *this = *this / other;
    return *this;
  }
};

template<typename T, T M>
ostream& operator<<(ostream& os, modint<T, M> x){
  os << x.v;
  return os;
}

void run() {
  const i64 mod{998244353};
  i64 n, k;
  cin >> n >> k;
  vector<i64> ls(k), rs(k);
  rep(i, 0, k) { cin >> ls[i] >> rs[i]; }
  vector<modint<i64, mod>> counts(n + 1);
  vector<modint<i64, mod>> incs(n + 1);
  incs[1] = 1;
  incs[2] = -1;
  rep(i, 1, n + 1) {
    counts[i] = (counts[i - 1] + incs[i]);
    rep(ik, 0, k) {
      i64 il{i + ls[ik]}, ir{i + rs[ik] + 1};
      if (il < n + 1) {
        incs[il] += counts[i];
        if (ir < n + 1) {
          incs[ir] -= counts[i];
        }
      }
    }
  }
  cout << counts[n] << endl;
}

int main() {
  cin.tie(nullptr);
  run();
  return 0;
}


Measured memory_bytes: 6052
#include<bits/stdc++.h>
using namespace std;
main(){
int i,j,k,l,m;
while(cin>>m){
    int x[m];
    for(i=0;i<m;i++)cin>>x[i];
    sort(x,x+i); k=0;
     for(i=0;i<m;i++) {k+=x[i];
     k--;}
     if(k<0)k=0;
    cout<<k<<endl;
} return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
    ll n,m;
    scanf("%lld%lld",&n,&m);
    ll ans=0;
    if(m>=2*n)
        ans+=n,m-=2*n,ans+=m/4;
    else
        ans+=m/2;
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define inline __inline__ __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
double readdb()
{
    R double x=0,y=0.1,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(x=ch-'0';(ch=getc())>='0'&&ch<='9';x=x*10+ch-'0');
    for(ch=='.'&&(ch=getc());ch>='0'&&ch<='9';x+=(ch-'0')*y,y*=0.1,ch=getc());
    return x*f;
}
const int N=1e5+5;
struct node{
    double x,y;
    inline node(){}
    inline node(R double xx,R double yy):x(xx),y(yy){}
    inline node operator +(const node &b)const{return node(x+b.x,y+b.y);}
    inline node operator -(const node &b)const{return node(x-b.x,y-b.y);}
    inline double operator *(const node &b)const{return x*b.y-y*b.x;}
    inline node operator *(const double &b)const{return node(x*b,y*b);}
    inline double operator ^(const node &b)const{return x*b.x+y*b.y;}
    inline double len2(){return x*x+y*y;}
    inline node rot(){return node(-y,x);}
}p[N],o;
struct Line{
    node p,v;
    inline Line(){}
    inline Line(R node pp,R node vv):p(pp),v(vv){}
    friend node cross(const Line &a,const Line &b){return a.p+a.v*(b.v*(b.p-a.p)/(b.v*a.v));}
};
node circle(const node &a,const node &b,const node &c){
    return cross(Line((a+b)*0.5,(b-a).rot()),Line((a+c)*0.5,(c-a).rot()));
}
int n;double r;
int main(){
    n=read();
    fp(i,1,n)p[i].x=readdb(),p[i].y=readdb();
    random_shuffle(p+1,p+1+n);
    r=0,o=node(0,0);
    fp(i,1,n)if((p[i]-o).len2()>r){
        o=p[i],r=0;
        fp(j,1,i-1)if((p[j]-o).len2()>r){
            o=(p[i]+p[j])*0.5,r=(p[j]-o).len2();
            fp(k,1,j-1)if((p[k]-o).len2()>r)
                o=circle(p[i],p[j],p[k]),r=(p[k]-o).len2();
        }
    }
    printf("%.10f\n",sqrt(r));
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <numeric>
#include <vector>

#define TRACE(x) std::cout << #x << " = " << x << "\n"
#define _ << " _ " <<

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);

  int N, M, V, P;
  cin >> N >> M >> V >> P;

  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end(), greater<int>());

  auto can = [&](int idx) -> bool {
    vector<int> B = A;
    int x = B[idx] + M;
    B.erase(B.begin() + idx);

    int votes_left = V - 1;

    int i = lower_bound(B.begin(), B.end(), x, greater<int>()) - B.begin();
    if (i >= P) return false;

    {
      int d = min(i, votes_left);
      for (int j = 0; j < d; ++j) B[j] += M;
      votes_left -= d;
    }

    vector<int> C;
    for (int j = i; j < (int)B.size(); ++j) {
      if (j < P - 1) {
        C.push_back(M);
      } else {
        C.push_back(min(M, x - B[j]));
      }
    }

    int64_t area = std::accumulate(C.begin(), C.end(), 0LL);
    return area >= static_cast<int64_t>(votes_left) * M;
  };

  int lo = 0, hi = (int)A.size() - 1;
  while (lo < hi) {
    int mid = (lo + hi + 1) / 2;
    if (can(mid)) {
      lo = mid;
    } else {
      hi = mid - 1;
    }
  }

  cout << lo + 1 << '\n';
  return 0;
}


Measured memory_bytes: 2004
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ar array
#define db double
#define pow pw
const db pi = 3.14159265358979323846;
int pw(int a,int b){
    int ans=1;
    while(b){
    if (b%2) ans*=a;
    a*=a;
    b/=2;
    }
    return(ans);
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<(int)(ceil(db(a)/b)*c);
    return 0;
}

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

using namespace std;

#define f(i, n) for(int i = 1; i <= n; i++ )
#define ff(i, n) for(int i = 0; i < n; i++ )
#define g(j, i)  for(auto j : matrix[i] )


const int N = 1000000000;
const int M = N + 7;
const int dim = 100005;


vector <vector <int> > matrix;
vector <vector<int>> dp;
int n, x, y;
bool viz[dim];


void dfs(int x){
  viz[x] = 1;
  dp[0][x] = 1;
  dp[1][x] = 1;
  g(j, x){
    if ( !viz[j] ){
      dfs ( j );
      dp[1][x] = (1LL * dp[1][x] * dp[0][j]) % M;
      dp[0][x] = (1LL * dp[0][x] * ( dp[1][j] + dp[0][j])) % M;
    }
  }
}



int main(){

  cin >> n;
  ff(i, n + 1)
    matrix.push_back (vector<int>());
  f (i, n - 1){
    cin >> x >> y;
    matrix[x].push_back ( y );
    matrix[y].push_back ( x );
  }

  // f(i, n){
  //   g(j, i)
  //     cout << j  << " ";
  //   cout << '\n';
  // }
  dp = vector<vector<int>> (2, vector<int> (n + 1, 1));
  dfs (1);

  cout << (dp[0][1] + dp[1][1]) % M;

  return 0;
}


Measured memory_bytes: 11760
from networkx import*
_,*s=open(i:=0)
g=[]
for t in s:
 i+=1;j=0
 for u in t:g+=[(k:=i*20+j,k+20)]*(u>'#'<(s+['#'*k])[i][j]);j+=1;g+=[(k,k+1)]*(u>'#'<t[j])
print(max(t[i]for _,t in shortest_path_length(Graph(g))for i in t))

Measured memory_bytes: 53684
#include <stdio.h>

int main(void)
{
 int a,b,c,d;

 scanf("%d%d%d",&a,&b,&c);
 d = 0;
 if((1 <= a <= 100) && (1 <= b <= 100) && (1 <= c <= 100))
 while(a <= b)
{
 b = b - a;
 d = d + 1;
}
  if (c < d) printf("%d\n", c);
  else printf("%d\n", d);
 return 0;
}


Measured memory_bytes: 128
package main

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

// func fib(n int) int{
// 	if n == 0 || n == 1{
// 		return 1
// 	} else {
// 		return fib(n-1) + fib(n-2)
// 	}
// }

// func main(){
// 	sc := bufio.NewScanner(os.Stdin)
// 	sc.Scan()
// 	n, _ := strconv.Atoi(sc.Text())
// 	fmt.Println(fib(n))
// }

import (
	"fmt"
)

func main(){
	var n, pre1, pre2, now int
	fmt.Scan(&n)
	if n == 0 || n == 1{
		fmt.Println(1)
	} else {
		pre1, pre2 = 1, 1
		for i:=1; i<n; i++{
			now = pre1 + pre2
			pre2 = pre1
			pre1 = now
		}
		fmt.Println(now)
	}

}


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

const string Yes = "Yes";
const string No = "No";

void solve(string S)
{
    if(S[3]==S[2] && S[5] == S[4])
    {
        cout<<Yes<<endl;
    }else
    {
        cout<<No<<endl;
    }
}


int main()
{
    string S;
    cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <random>
#include <string.h>      //文字列の代入に使う
#include <bits/stdc++.h> //piの利用で必要(M_PI)
#include <algorithm>
#include <climits>
#define rep(i, c) for (int i = 0; i < (int)c; i++) //atcoderの解説コードに利用されていたので，ある程度一般生があるかと思われる．
#define ll long long

int main()
{
    int a1, a2, a3;
    std::cin >> a1 >> a2 >> a3;
    if (a1 + a2 + a3 >= 22)
    {
        std::cout << "bust" << std::endl;
    }
    else
    {
        std::cout << "win" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

/* トランプの絵柄と数字 */
typedef struct card{
  char suit;
  int value;
}CARD;

void BubbleSort(CARD*, int);
void SelectionSort(CARD*,int);
void swap(CARD*, CARD*);
int isStable(CARD*, CARD*);

main(){
  CARD c1[36], c2[36];
  int i, n;
  char dummy;

  scanf("%d%c", &n, &dummy);

  for( i = 0; i < n; i++){
    scanf("%c%d%c", &c1[i].suit, &c1[i].value, &dummy);
  }

  for( i = 0; i < n; i++) c2[i] = c1[i];

  BubbleSort(c1, n);
  printf("Stable\n");

  SelectionSort(c2, n);
  for( i = 0; i < n; i++){
    if( c1[i].value == c2[i].value && c1[i].suit != c2[i].suit ){
      printf("Not stable\n");
      break;
    }
    if( i == n-1 ) printf("Stable\n");
  }

  return 0;

}

void BubbleSort(CARD *c, int n){
  int i, j;

  for( i = 0; i < n; i++){

    for( j = n-1; i < j; j--){

      if( c[j].value < c[j-1].value ) swap(&c[j], &c[j-1]);

    }

  }

  for( i = 0; i < n; i++){
    if( i == n-1 ) printf("%c%d\n", c[i].suit, c[i].value);
    else printf("%c%d ", c[i].suit, c[i].value);
  }

}

void SelectionSort(CARD *c, int n){
  int i, j, minj;

  for( i = 0; i < n; i++){
    minj = i;

    for( j = i; j < n; j++){

      if( c[j].value < c[minj].value ) minj = j;

    }

    if( c[i].value != c[minj].value ) swap(&c[i], &c[minj]);

  }

  for( i = 0; i < n; i++){
    if( i == n-1 ) printf("%c%d\n", c[i].suit, c[i].value);
    else printf("%c%d ", c[i].suit, c[i].value);
  }

}

void swap(CARD *c1, CARD *c2){
  CARD c_ex;

  c_ex = *c1;
  *c1 = *c2;
  *c2 = c_ex;

}

Measured memory_bytes: 608
import java.util.*
 
fun main(args: Array<String>) {
  var a = readLine()!!.toInt()-1
  var num = readLine()!!.split(" ").map{ it -> it.toFloat() }.toMutableList()
  var counter = 0f
  
  for (i in 0..a) {
    counter = counter + (1/num[i])
  }
  println((1/counter).toFloat())
}

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

void sort(char a[], int n)
{
    int i, j;

    for(i = 0; i < n; i++){//descending
        for(j = 1; j < n - i; j++){
            if(a[j] > a[j - 1]){
                char temp = a[j];
                a[j] = a[j - 1];
                a[j - 1] = temp;
            }
        }
    }
}

int main(void)
{
    char a[8];
    char min[8];
    char max[8];
    int num;
    int L;

    while(1){
        int i, j;
        char a_n[21][8];

        scanf("%d %d", &num, &L);

        if(num == 0 && L == 0)
            break;

        sprintf(a + 1, "%d", num);
        strcpy(&a_n[0][1], a + 1);
        i = 1;
        j = 0;
        while(1){
            int k, l;
            int index;
            int len = strlen(a + 1);

            sort(a + 1, len);

            for(k = 0; k <= L; k++){
                max[k] = min[k] = '0';
            }
            max[k] = min[k] = '\0';


            index = 1;
            for(k = 1; k <= len; k++){
                max[index++] = a[k];
            }

            index = L - len + 1;
            for(k = len; k > 0; k--){
                min[index++] = a[k];
            }


            sprintf(a + 1, "%d", atoi(max) - atoi(min));


            index = 0;//use index as a flag
            for(k = 0; k < i; k++){
                if(strcmp(a + 1, &a_n[k][1]) == 0){
                    j = k;
                    index = 1;
                }
            }

            if(index)
                break;

            strcpy(&a_n[i++][1], a + 1);
        }

        printf("%d %s %d\n", j, a + 1, i - j);
    }

    return 0;
}

Measured memory_bytes: 640
num = list(map(int,list(str(input()))))

for i in range(2**3):
  temp = 0
  
  for j in range(len(num)):
    if j == 0:
      temp = num[j]
      ans = str(num[j])
      continue
    
    if ((i >> j-1)&1):
      temp = temp + num[j]
      ans = ans + "+" + str(num[j])
      
    elif not ((i >> j-1)&1):
      temp = temp - num[j]
      ans = ans + "-" + str(num[j])
      
  if temp == 7:
    ans = ans + "=7"
    print(ans)
    break

Measured memory_bytes: 3064
def main():
    n = int(input())
    a_s = list(map(int, input().split(' ')))
    results = [0]*n
    for i, a in enumerate(reversed(a_s)):
        idx = (n-1) - i
        if sum(results[idx::(idx+1)]) % 2 != a:
            results[idx] = 1
    print(sum(results))
    idxs = [str(i+1) for i, r in enumerate(results) if r == 1]
    if results:
        print(' '.join(idxs))


if __name__ == '__main__':
    main()


Measured memory_bytes: 17208
#include <iostream>
using namespace std;
int main(void){
    int H,W;
    while(1){
        cin>>H>>W;
        if(H==0&&W==0)break;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(i==0||i==H-1||j==0||j==W-1){
                    cout<<"#";
                }else{
                    cout<<".";
                }
            }cout<<"\n";
        }cout<<endl;
    }
 return 0;   
}

Measured memory_bytes: 3084
from math import gcd

N = int(input())
num_lis = list(map(int, input().split()))
c1 = True #setwise
c2 = True #pairwise

def osa_k(max_num):
  lis = [i for i in range(max_num+1)]
  p = 2
  while p**2 <= max_num:
    if lis[p] == p:
      for q in range(2*p, max_num+1, p):
        if lis[q] == q:
          lis[q] = p
    p += 1
  return lis

hoge = 0
for i in num_lis:
  hoge = gcd(hoge, i)
if hoge > 1:
  c1 = False

if c1:
  d_lis = osa_k(max(num_lis))
  tmp = set()
  for i in num_lis:
    num = i
    new_tmp = set()
    while num > 1:
      d = d_lis[num]
      new_tmp.add(d)
      num //= d
    for j in new_tmp:
      if j in tmp:
        c2 = False
        break
      else:
        tmp.add(j)
    else:
      continue
    break
else:
  c2 = False

if c2:
  print("pairwise coprime")
elif c1:
  print("setwise coprime")
else:
  print("not coprime")

Measured memory_bytes: 126940
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  ll n,k;
  cin>>n>>k;

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

  ll ans=0,i=0;
  while(1){
    ans++;
    i+=k;
    if(n<=i)break;
    i--;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n); i >= 0; i--)
#define revrepr(i, a, b) for (int i = (a); i >= b; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

int main() {
    int n;
    cin >> n;
    vector<int> ans;
    do {
        if (n % 2 == 0) ans.push_back(0);
        else {
            ans.push_back(1);
            n--;
        }
        n /= -2;
    } while (n != 0);

    reverse(ans.begin(), ans.end());
    for (int i: ans) cout << i;
    cout << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int main( ){
  while(1){
    double n,s[1000],heikin=0,hensa=0;
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>s[i];
    heikin+=s[i];
    }
    heikin/=n;
    for(int i=0;i<n;i++){
      s[i]=pow(s[i]-heikin,2);
      hensa+=s[i];
    }
    printf("%f\n",sqrt(hensa/n));
  }
  return 0;
}

Measured memory_bytes: 3212
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

int main() {
    SS(int,n,m)
    p(n*(n-1)/2+m*(m-1)/2);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
vector<long long> calc_divisor(long long n) {
    vector<long long> res;
    for (long long i = 1LL; i*i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            long long j = n / i;
            if (j != i) res.push_back(j);
        }
    }
    sort(res.rbegin(), res.rend());
    return res;
}
int main(){
	int N;
	ll A[501],K,sum=0;
	scan(N>>K);
	rep(i,N){
		scan(A[i]);
		sum+=A[i];
	}
	sort(A,A+N);
	vll yakusu=calc_divisor(sum);
	rep(i,yakusu.size()){
		ll m=yakusu[i];
		int flag=1;
		ll abssum=0;
		vll absm,absu;
		rep(j,N){
			ll low=A[j]/m*m,upp=(A[j]/m+1)*m;
			absm.push_back(A[j]-low);
			absu.push_back(upp-A[j]);
			//printf("A:%lld low:%lld upp:%lld abs:%lld\n",A[j],low,upp,min(A[j]-low,upp-A[j]));
		}
		sort(absm.begin(),absm.end());
		sort(absu.rbegin(),absu.rend());
		ll msum[501]={};
		rep(j,N) msum[j+1]=msum[j]+absm[j];
		ll usum=0;
		for(int j=N-1;j>=0;j--){
			usum+=absu[j];
			if(usum>=msum[j]) break;
		}
		//sort(absm.begin(),absm.end());
		//rep(j,N-1) abssum+=absm[j];
		//
		//abssum/=2;
		//printf("m:%lld usum:%lld\n",m,usum);
		if(usum<=K){
			prin(m);
			return 0;
		}
	}
	return 0;
}


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

int main(){
  int L,R,d,count;
  cin >> L >> R >> d;
  count = 0;
  
  for(int i = L; i<R+1; i++){
    if(i%d == 0) count++;
  }
  
  cout << count;
  return 0;
}


Measured memory_bytes: 3540
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10**9)

readline=stdin.readline
n,w=map(int,readline().split())
INF=10**9
G=[[INF]*n for _ in range(n)]

for _ in range(w):
    s,t,d=map(int,readline().split())
    G[s][t]=d

dp=[[-1]*n for _ in range(1<<n)]

def func(s,v):
    if dp[s][v]>=0: return dp[s][v]

    if (s==(1<<n)-1) and v==0:
        dp[s][v]=0
        return dp[s][v]

    tmp=INF
    for u in range(n):
        t=(1<<u)|s
        if t==s: continue
        tmp=min(tmp,func(t,u)+G[v][u])
    dp[s][v]=tmp
    return dp[s][v]

ans=func(0,0)
print(ans if ans<INF else -1)


Measured memory_bytes: 15452
#include <stdio.h>

void MRoy(){
	char s[10];
	scanf("%s",s);
	if(s[0]=='S') printf("Cloudy\n");
	else if(s[0]=='C') printf("Rainy\n");
	else printf("Sunny\n");
	return;
}
int main(){
	MRoy();
	return 0;
}


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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const int INF = 1e9;

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    string s;
    cin >> s;

    int n = (int)s.size();

    int f = 0;
    for (auto i : s){
      if (i == '7') f = 1;
    }

    if (f) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define LD long double
int n;
LD a;
priority_queue<LD>Q;
int main() {
	scanf("%d",&n);
	while(n--) {
		cin>>a;
		Q.push(-a);
	}
	while(Q.size()>1) {
		LD x=-Q.top();
		Q.pop();
		LD y=-Q.top();
		Q.pop();
		Q.push(-(x+y)/2);
	}
	printf("%.10Lf",-Q.top());
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;


int main(void){

    int n,y;
    cin>>n>>y;
    int man=0,go=0,sen=0;
    for(man=0;man<=n;man++){
        if(10000*man>y)continue;
        for(go=0;go<=n;go++){
            if(10000*man+5000*go>y)continue;
            int rest=y-10000*man-5000*go;
            int sen=rest/1000;
            if(man+go+sen==n&&10000*man+5000*go+1000*sen==y){
                cout<<man<<" "<<go<<" "<<sen<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;

}

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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N,A; cin >> N >> A;
    cout << N*N-A << endl;
    return 0;
}

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

const int M = 1000005;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  vector<int> cnt(M); //カウント用の変数：数列Aの倍数のイテレータを+１
  for(int x : a){
    if(cnt[x] != 0){
      cnt[x] = 2;
      continue;
      //重複している数列の処理（cnt[x] が１以上　ー>　重複する数字orその約数がすでに存在
      //それ以降は更新する必要ないためcontinueでスキップする
    }

    for(int i = x; i < M; i += x) cnt[i]++; //数字の倍数をインクリメント

  }

  //output
  int ans = 0;
  for(int x : a){
    if(cnt[x] == 1) ans++;
  }

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

Measured memory_bytes: 7944
class Array
  def medmed
    if size.odd?
      self[size/2]
    else
      self[size/2] + self[size/2-1]
    end
  end
end

n = gets.to_s.to_i
a, b = Array.new(n){ gets.to_s.split.map{|e| e.to_i } }.transpose

a.sort!
b.sort!

ans = [0, b.medmed - a.medmed + 1].max

puts ans

Measured memory_bytes: 32760
#include<bits/stdc++.h>
#define ll long long
#define pp pair<int,int>
#define ss second
#define ff first
using namespace std;

int main()
{
     int n,m,k,c=0;
     cin>>n>>m>>k;
     for(int i=n;i<=m;i++)
     {
          if(i%k==0)
          c++;
     }
     cout<<c;
}

Measured memory_bytes: 3624
def A():
    ab, bc, ca = map(int, input().split())
    print(int(bc * ab / 2))
#A()

def B():
    s = int(input())
    f_data = [s]
    i = 0
    tmp = [0 for i in range(1000001)]
    def f(n):
        if n % 2 == 0:
            return n // 2
        else:
            return 3 * n + 1
    ans = 0
    while True:
        if i == 0:
            f_data.append(s)
            tmp[s] = 1
        else:
            key = f(f_data[-1])
            f_data.append(key)
            if tmp[key] == 1:
                ans = i + 1
                break
            tmp[key] = 1
            
        if ans != 0:
            break
        i += 1
    #print(f_data)
    print(ans)
B()



Measured memory_bytes: 10904
// Created by Nikolay Budin

#ifdef DEBUG
#  define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ff first
#define ss second
#define szof(x) ((int)x.size())
#ifndef LOCAL
#  define cerr __get_ce
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

int const INF = (int)1e9 + 1e3;
ll const INFL = (ll)1e18 + 1e6;
#ifdef LOCAL
	mt19937 tw(9450189);
#else
	mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
uniform_int_distribution<ll> ll_distr;
ll rnd(ll a, ll b) { return ll_distr(tw) % (b - a + 1) + a; }

pii comb(pii const& a, pii const& b) {
	return {max(a.ff, b.ff), min(a.ss, b.ss)};
}

void solve() {
	int n;
	cin >> n;
	vector<pii> arr;
	for (int i = 0; i < n; ++i) {
		int l, r;
		cin >> l >> r;
		--l;
		arr.push_back({l, r});
	}
	sort(arr.begin(), arr.end());
	vector<pii> pref = {{-INF, INF}}, suff = {{-INF, INF}};

	for (int i = 0; i < n; ++i) {
		pref.push_back(comb(pref.back(), arr[i]));
		suff.push_back(comb(suff.back(), arr[n - 1 - i]));
	}

	int ans = 0;
	for (int i = 1; i < n; ++i) {
		ans = max(ans, max(0, pref[i].ss - pref[i].ff) + max(0, suff[n - i].ss - suff[n - i].ff));
	}

	for (int i = 0; i < n; ++i) {
		auto tmp = comb(pref[i], suff[n - 1 - i]);
		ans = max(ans, arr[i].ss - arr[i].ff + max(0, tmp.ss - tmp.ff));
	}

	sort(arr.begin(), arr.end(), [&](auto& a, auto& b) {
		return a.ss < b.ss;
	});

	pref = {{-INF, INF}}, suff = {{-INF, INF}};

	for (int i = 0; i < n; ++i) {
		pref.push_back(comb(pref.back(), arr[i]));
		suff.push_back(comb(suff.back(), arr[n - 1 - i]));
	}

	for (int i = 1; i < n; ++i) {
		ans = max(ans, max(0, pref[i].ss - pref[i].ff) + max(0, suff[n - i].ss - suff[n - i].ff));
	}

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


int main() {
#ifdef LOCAL
	auto start_time = clock();
	cerr << setprecision(3) << fixed;
#endif
	cout << setprecision(15) << fixed;
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int test_count = 1;
	// cin >> test_count;
	for (int test = 1; test <= test_count; ++test) {
		solve();
	}

#ifdef LOCAL
	auto end_time = clock();
	cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}

Measured memory_bytes: 3444
// Problem : D - Knight
// Contest : AtCoder Beginner Contest 145
// URL : https://atcoder.jp/contests/abc145/tasks/abc145_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 2e6 + 5;
const ll MOD = 1e9 + 7;

ll fact[maxN], invFact[maxN];

ll pow2(ll a, ll b) {
	if (b == 0) return 1;
	if (b == 1) return a;
	ll d = pow2(a, b / 2);
	d = (d * d) % MOD;
	if (b % 2) return (d * a) % MOD;
	return d;
}

void facts() {
	fact[0] = 1;
	invFact[0] = 1;
	fact[1] = 1;
	invFact[1] = 1;
	FOR(i, 2, 1e6) {
		fact[i] = (fact[i - 1] * (ll)i) % MOD;
		invFact[i] = pow2(fact[i], MOD - 2);
	}	
}

int main() {
	ios_base::sync_with_stdio(0);
	int x, y;
	facts();
	cin >> x >> y;
	if ((x + y) % 3 != 0) {cout << 0 << endl; return 0;}
	if (x > y) swap(x, y);
	int rzad = (x + y) / 3;
	int ktory = x - rzad;
	if (ktory < 0) {cout << 0 << endl; return 0;}
	cout << (((fact[rzad] * invFact[ktory]) % MOD) * invFact[rzad - ktory]) % MOD;
	return 0;
}



Measured memory_bytes: 18688
#include<stdio.h>
//#include <stdlib.h>
//#include<string.h>
using namespace std;
int main()
{
    int N,K;
    int cnt=0;
    scanf("%d %d", &N, &K);
    while(N>=K){
        cnt+=1;
        N/=K;
               
    }
    printf("%d", cnt+1);
    return 0;
}

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

using namespace std;

int main(){
  string S, T, ans = "Yes";

  cin >> S >> T;

  for (size_t i = 0; i < S.size(); i++) {
    if (S[i] != T[i]) {
      ans = "No";
    }
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> b(n - 1);
    for (int i = 0; i < n - 1; i++) {
        cin >> b[i];
    }

    ll ans = b.front() + b.back();
    for (int i = 1; i < n - 1; i++) {
        ans += min(b[i], b[i-1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

pref_lst = [[] for _ in range(N)]

i = 0
for print_order in range(M):
	pref, year = map(int, input().split())
	pref_lst[pref - 1].append([i, year])
	i += 1
	
ret_lst = []

for i in range(N):
	pref_lst[i] = sorted(pref_lst[i], key = lambda x : x[1])
	for j in range(len(pref_lst[i])):
		p = str(i + 1).zfill(6)
		y = str(j + 1).zfill(6)
		pref_lst[i][j].append(p + y)
	ret_lst.extend(pref_lst[i])
		
ret_lst = sorted(ret_lst, key = lambda x : x[0])

for elm in ret_lst:
	print(elm[2])

Measured memory_bytes: 106016
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
mod=10**9+7

dp=[0]*(2**n)
dp[0]=1

for i in range(1,2**n):
    x=bin(i)[2:]
    y=x.count('1')
    for j in range(len(x)):
      if x[-j-1]=='1':
        if a[y-1][j]==1:
            dp[i]+=dp[i-(2**j)]
            dp[i]%=mod


print(dp[-1])

Measured memory_bytes: 90396
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <cstdio>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;(i)>=0;(i)--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

typedef long long ll;

int main(){
    
    while(true){
        int n,m,a;
        cin>>n>>m>>a;
        if(n==0&&m==0&&a==0)break;
        
        vector<pair<int,pair<int,int>>> M;
        REP(i,m){
            int h,p,q;
            cin>>h>>p>>q;
            M.push_back(make_pair(h,make_pair(p,q)));
        }
        
        sort(M.begin(),M.end());
        reverse(M.begin(),M.end());
        
        int a_h=1000;
        int a_p=a;
        
        REP(i,M.size()){
            if(a_h>=M[i].first){
                a_h=M[i].first;
                if(M[i].second.first==a_p)a_p=M[i].second.second;
                else if(M[i].second.second==a_p)a_p=M[i].second.first;
            }
        }
        
        cout<<a_p<<endl;
        
    }
    
    return 0;
}

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

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

    int n;
    cin >> n;
    double ans = 0;
    for(int i = 0; i < n; i++){
        double x;
        string u;
        cin >> x >> u;
        if(u == "JPY") ans += x;
        else{
            ans += x * (380000.00);
        }
    }

    cout << fixed << setprecision(5) << ans << endl;

    return 0;
}

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


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define pb push_back
#define mp make_pair
#define snd second
#define fst first
#define debug printf("--%d--\n",__LINE__)
#define ll long long int

string S;
static int dp[1000000];
string s[4] = {"dream", "dreamer", "erase", "eraser"};
int main(void){
	cin >> S;
	dp[0] = 1;
	for(int i=0;i<S.size();i++){
		if (dp[i]){
			for(int j=0;j<4;j++){
				if (S.substr(i,s[j].size())==s[j]){
					dp[i + s[j].size()] = 1;
				}
			}
		}
	}
	if (dp[S.size()]) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}


Measured memory_bytes: 896