akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,K;
int A[200010];
int F[200010];

signed main(){
	cin>>N>>K;
	REP(i,N){
		cin>>A[i];
	}
	REP(i,N){
		cin>>F[i];
	}
	sort(A,A+N);
	sort(F,F+N,greater<>());
	int ng=-1,ok=10000000000000;
	while(abs(ok-ng)>1){
		int mid=(ok+ng)/2;
		int num=0;
		REP(i,N){
			if(A[i]*F[i]>mid){
				num+=ceil2(A[i]*F[i]-mid,F[i]);
			}
		}
		if(num<=K){
			ok=mid;
		}
		else{
			ng=mid;
		}
	}
	cout<<ok<<endl;
	return 0;
}



Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (B < C || A > D) {
    cout << 0 << endl;
  }
  else {
    vector<int> data1 = {A, C};
    vector<int> data2 = {B, D};
    sort(data1.begin(), data1.end());
    sort(data2.begin(), data2.end());
    cout << data2.at(0) - data1.at(1) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int a=0,b=0,c=0,d=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='N')
        a++;
        if(s[i]=='S')
        b++;
        if(s[i]=='E')
        c++;
        if(s[i]=='W')
        d++;
    }
    if((a>0&&b>0&&c==0&&d==0)||(c>0&&d>0&&a==0&&b==0))
        {cout<<"Yes"<<endl;return 0;}
    if(a>0&&b>0&&c>0&&d>0)
        {cout<<"Yes"<<endl;return 0;}
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3616
n = int(input())
A = list(map(int, input().split()))
s =  1
f=0

if 0 in A:
    print(0)
else:
    for a in A:
        s = s*a
        if s > 10**18:
            f=1
            break
    if f==1:
        print(-1)
    else:
        print(s)


Measured memory_bytes: 21644
<?php
fscanf(STDIN, '%d', $n);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
$q = new SplPriorityQueue;
for ($i = 0; $i < $n; $i++) {
    $q->insert($i+1, -$a[$i]);
}
while ($q->count() > 0) {
    echo $q->extract().' ';
}

Measured memory_bytes: 54388
N=int(input())

A=[]
B=[]

for _ in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if N%2==0:
    mid_min=(A[N//2-1]+A[N//2])
    mid_max=(B[N//2-1]+B[N//2])
else:
    mid_min=A[N//2]
    mid_max=B[N//2]

print(mid_max-mid_min+1)

Measured memory_bytes: 25380
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;

//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
    
    int n;
    cin>>n;
    if(n%1000==0)
    cout<<0<<endl;
    else
    cout<<(1000-(n%1000))<<endl;
    
	return 0;
}

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


int main() {
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    reverse(a.begin(),a.end());
    vector<ll> asum(n);
    asum[0] = a[0];
    for(int i = 1; i < n; i++){
        asum[i] = asum[i-1] + a[i];
    }


    __int128 ans = LLINF;
    for(int i = 1; i <= n; i++){
        __int128 cost = (i+n)*x;
        cost += 5*asum[i-1];
        ll num = 2*i-1;
        ll cnt = 1;
        while(num < n){
            ll coef = 2*cnt+3;
            cost += coef*(asum[num]-asum[num-i]);
            cnt++;
            num += i;
        }
        cost += (2*cnt+3)*(asum[n-1]-asum[num-i]);
        ans = min(ans, cost);
    }
    cout << (ll)(ans) << endl;
    return 0;
}


Measured memory_bytes: 3328
#include "stdio.h"
#include "iostream"
#include "string"
using namespace std;
int main(int argc, char const *argv[]) {
  string s;
  int n;
  scanf("%d", &n);
  cin >> s;
  string ans = "No";
  int k = n/2;
  if (n%2 == 0 && s.substr(0,k)==s.substr(k,k)) {
    ans = "Yes";
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b,c,d;
  cin>>a;
  b=a;
  c=b;
  a=a/3600;
  b=(b%3600)/60;
  c=c%60;
  cout<<a<<":"<<b<<":"<<c<<"\n";
  return(0);
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define maxn 200005
#define INF 0x3f3f3f3f
#define mod 1000000007
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef long long ll;
using namespace std;

void slove()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while (a >= 0 && c >= 0) {
		c -= b;
		if (c <= 0) break;
		a -= d;
		if (a <= 0) break;
	}
	if (c <= 0) cout << "Yes";
	else cout << "No";
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef DEBUG
	freopen("C:\\Users\\Fish_Brother\\Desktop\\in", "r", stdin);
	//freopen("C:\\Users\\Fish_Brother\\Desktop\\out", "w", stdout);
#endif
	slove();

	return 0;
}

Measured memory_bytes: 3608
x,n=map(int,input().split())
p=set(list(map(int,input().split())))
ans=0
flag=0
while flag==0:
    if not x-ans in p:
        print(x-ans)
        flag=1
    elif not x+ans in p:
        print(x+ans)
        flag=1
    ans+=1


Measured memory_bytes: 61664
#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;
ll ans[101][100001];
int main() {
	IOS;
	ll n,w;
	const int num=100001;
	cin>>n>>w;
	ll wt[n+1],val[n+1];
//	for(int i=0;i<=num;i++)ans[0][i]=0;
	for(ll i=1;i<=n;i++){
		cin>>wt[i]>>val[i];
		for(int j=0;j<num;j++){
			if(val[i]>j)
			ans[i][j]=ans[i-1][j];
			else if(val[i]==j){
				ans[i][j]=wt[i];
				if(ans[i-1][j]!=0)
				ans[i][j]=min(wt[i],ans[i-1][j]);
				
				
			}
			else {
				
				if(ans[i-1][j-val[i]]!=0&&ans[i-1][j]!=0){
					ans[i][j]=min(ans[i-1][j],wt[i]+ans[i-1][j-val[i]]);
				}else if(ans[i-1][j-val[i]]!=0&&ans[i-1][j]==0){
					ans[i][j]=wt[i]+ans[i-1][j-val[i]];
				}else {
					ans[i][j]=ans[i-1][j];
				}
			}
				
		}
	}
	
	for(int i=num-1;i>0;i--){
		if(ans[n][i]!=0&&ans[n][i]<=w){
			cout<<i;
			break;
		}
	}
}


Measured memory_bytes: 78336
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
string S, ans;

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

  cin >> S;
  if (S == "Sunny")ans = "Cloudy";
  else if (S == "Cloudy") ans = "Rainy";
  else ans = "Sunny";
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int q;
  cin >> q;
  string X, Y;
  for (int _ = 0; _ < q; _++) {
    int mx = 0;
    cin >> X >> Y;
    X = ' ' + X;
    Y = ' ' + Y;
    int X_size = X.size();
    int Y_size = Y.size();
    vector<vector<int>> dp(X_size, vector<int>(Y_size));
    for (int i = 1; i < X_size; i++) {
      for (int j = 1; j < Y_size; j++) {
        if (X[i] == Y[j]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
        } else {
          dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
        mx = max(mx, dp[i][j]);
      }
    }
    cout << mx << endl;
  }
  return 0;
}


Measured memory_bytes: 6764
#pragma region macro
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

namespace std {
template <typename A, typename B>
string to_string(pair<A, B> p);

string to_string(const string &s) {
    return '"' + s + '"';
}

string to_string(const char *s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for(int i = 0; i < static_cast<int>(v.size()); i++) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for(size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
};  // namespace std
#pragma endregion

void solve() {
    std::string s;
    std::cin >> s;
    if(s == "ABC") {
        std::cout << "ARC" << std::endl;
    } else {
        std::cout << "ABC" << std::endl;
    }
}

int main() {
    // std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

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

int main(){
	
	int a,b,t;
	char c;
	
	while(1){
		cin>>a>>c>>b;

		if(c=='+')t=a+b;
		else if(c=='-')t=a-b;
		else if(c=='*')t=a*b;
		else if(c=='/')t=a/b;
		else if(c=='?')break;//????????????????¨????

		cout<<t<<"\n";
		
			}
	
	return 0;
	
	}

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


struct UnionFind {
  vector<int> par;
  UnionFind(int n) : par(n){
    for(int i = 0; n > i; i++)par[i] = i;
  }

  int root(int n){
    if(par[n] == n)return n;
    return par[n] = root(par[n]);
  }

  void unite(int a,int b){
    int ra = root(a);
    int rb = root(b);
    if(ra==rb)return;
    par[ra] = rb;
  }

  bool same(int a, int b){
    return root(a) == root(b);
  }
};

int main(){
    int n,q;cin>>n>>q;
    UnionFind a(n);
    for(int i = 0; q > i; i++){
        int x;cin>>x;
        int y,z;cin>>y>>z;
        if(x)cout << (a.same(y,z)?1:0) << endl;
        else a.unite(y,z);
    }
}


Measured memory_bytes: 3168
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    S = input()
    ans = S.count('.')
    score = ans
    for c in S:
        if c == '.':
            score -= 1
        else:
            score += 1
        ans = min(ans, score)
    print(ans)
resolve()

Measured memory_bytes: 73472
#include<cstdio>
#include<cstring>
#include<vector>
#define fo(x,a,b) for(int x=(a),_e=(b);x<=_e;x++)
#define fd(x,a,b) for(int x=(a),_e=(b);x>=_e;x--)
using namespace std;
typedef long long ll;
const int N=1005;
int d[N*N],z[N][N],q[N*N],n,m,sx,sy,tx,ty,cnt=0;
char c[N][N];
vector<int> v[N*N];
void dfs(int x,int y,int col){
	z[x][y]=col;
	fo(i,-1,1) fo(j,-1,1) if(i*j==0 && (i!=0 || j!=0)) {
		int dx=x+i, dy=y+j;
		if(dx<1 || dx>n || dy<1 || dy>m || c[dx][dy]=='#') continue;
		if(!z[dx][dy]) dfs(dx,dy,col);
	}
}
void flood(int x,int y,int col){
	int dx,dy;
	fo(i,-2,2) fo(j,-2,2) {
		dx=x+i, dy=y+j;
		if(dx<1 || dx>n || dy<1 || dy>m || c[dx][dy]=='#') continue;
		if(z[dx][dy]!=col) 
			v[col].push_back(z[dx][dy]);
	}
}
int main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	int l=0,r=1,x;
	scanf("%d %d",&n,&m);
	scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
	fo(i,1,n) scanf("%s",c[i]+1);

	fo(i,1,n) fo(j,1,m) if(c[i][j]=='.' && !z[i][j]) dfs(i,j,++cnt);
/*	fo(i,1,n) {
		fo(j,1,m) printf("%d ",z[i][j]);puts("");
	}
*/
	fo(i,1,n) fo(j,1,m) if(c[i][j]=='.') flood(i,j,z[i][j]);

	memset(d,0x3f,sizeof(d));
	d[z[sx][sy]]=0;
	q[1]=z[sx][sy];
	while(l<r) {
		x=q[++l];
		for(int go:v[x]) if(d[go]>d[x]+1) {
			d[go]=d[x]+1;
			q[++r]=go;
		}
	}
	printf("%d",d[z[tx][ty]]>cnt?-1:d[z[tx][ty]]);
	return 0;
}


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

int N;
vector<int> A(100001);

void solve(){
    map<int, int> mp;
    int ans = 1;
    mp[A[1]] = 1;
    for(int i = 2; i <= N; ++i){
        if(A[i] > mp.begin()->first) {
            auto itr = mp.lower_bound(A[i]);
            itr--;
            itr->second--;
            if(itr->second <= 0) mp.erase(itr);
        }
        else ans++;
        mp[A[i]] += 1;
    }
    cout << ans;
}
int main(){
    cin >> N;
    for(int i = 1; i <= N; ++i){
        cin >> A[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 5248
(defn formula [ X Y x y]
  (unchecked-add-int (Math/abs (unchecked-subtract-int X x)) (Math/abs (unchecked-subtract-int Y y))))
 
(defn zero-case [X Y zs]
  (apply min (map (fn [[x y _]] (formula X Y x y)) zs)))
 
(defn Pyramid [ls]
  (let [{lsn false zs true} (group-by (fn [[_ _ h]] (zero? h)) ls)
        ^const range_it (range (unchecked-int 0) (unchecked-int 101))]
    (first
      (for [X range_it
            Y range_it
            :let [Hs (map (fn [[x y h]] (unchecked-add-int h (formula X Y x y))) lsn)
                  H  (first Hs)]
            :when (and (every? #(= H %) (rest Hs))
                    (if (nil? zs)
                      (<= 1 H)
                      (>= (zero-case X Y zs) H)))]
        (format "%d %d %d" X Y H)))))
 
(defn input [N]
  (when-not (zero? N)
    (let [x (unchecked-int (read)) y (unchecked-int (read)) h (unchecked-int (read))]
      (cons [x y h] (input (unchecked-dec-int N))))))
(-> (read) int input Pyramid println) 

Measured memory_bytes: 74052
// https://atcoder.jp/contests/abc163/tasks/abc163_d

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DEBUG 0
#if DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

const int N_MAX = 2*1e5;
const int MOD = 1e9+7;

int N, K;

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

  ll ans = 0;
  FOR(i, K, N + 1) {
    ll tmp = i;
    tmp = tmp * (N + 1 - i) % MOD;;
    tmp = (tmp + 1) % MOD;
    ans = (ans + tmp) % MOD;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define all(vec) vec.begin(), vec.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl
#define isEven(t) t % 2 == 0

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

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

	int N;
	int L, R;
	cin >> N;
	vector<int> X(N);

	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}
	vector<int> Y = X;

	sort(all(Y));

	R = Y[N / 2];
	L = Y[N / 2 - 1];

	for (int i = 0; i < N; i++) {
		if(X[i]<R){
			cout << R << endl;
		}
		if(X[i]>L){
			cout << L << endl;
		}
		if(X[i]==R&&X[i]==L){
			cout << X[i] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 5376
#include <iostream>
using namespace std;
#define ll long long int
ll sum[26];
ll mod=1e9+7;
int main(){
  int n;
  string s;
  cin>>n>>s;
  for(int i=0;i<n;++i ){
    char x=s[i];
    for(int j=0;j<26;++j){
      char y='a'+ j;
      if(x==y)++sum[j];  
    }
  }
  ll ans=1;
  for(int i=0;i<26;++i){
    ans*=sum[i]+1;
    ans%=mod;
  }
  cout<<ans-1<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=1;i<=n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
using namespace std;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef pair<ll,ll> P;
int main(){
    int n; cin >> n;
    vector<P> v;
    ll maxl=0,minr=1001001001;
    rep(i,n){
        ll l,r;
        cin >> l >> r;
        v.push_back(P(l,r));
        chmin(minr,r);
        chmax(maxl,l);
    }
    vector<P> v2;
    rep(i,n){
        ll a = max((ll)0,v[i].se-maxl+1);
        ll b = max((ll)0,minr-v[i].fi+1);
        v2.push_back(P(a,b));
    }
    sort(v2.begin(),v2.end());
    
    ll mina[n],minb[n];
    mina[n-1]=v2[n-1].fi; minb[0]=v2[0].se;
    REP(i,n-1) mina[i]=min(mina[i+1],v2[i].fi);
    rep(i,n-1) minb[i+1]=min(minb[i],v2[i].se);
    ll ans = 0;
    rep(i,n){
        ans = max(ans,mina[i]+minb[i]);
    }
    //１個だけう使う場合の最適
    ll rmin[n],lmin[n],rmax[n],lmax[n];
    lmin[0]=v[0].se; lmax[0]=v[0].fi;
    rmin[n-1]=v[n-1].se; rmax[n-1]=v[n-1].fi;
    repp(i,n-1){
        lmin[i]=min(lmin[i-1],v[i].se);
        lmax[i]=max(lmax[i-1],v[i].fi);
    }
    REP(i,n-1){
        rmin[i]=min(rmin[i+1],v[i].se);
        rmax[i]=max(rmax[i+1],v[i].fi);
    }
    rep(i,n){
        ll res = v[i].se-v[i].fi+1;
        //i以外のminmax
        ll reb=0;
        if(0<i && i+1<n) reb = min(rmin[i+1],lmin[i-1])-max(rmax[i+1],lmax[i-1])+1;
        else if(i==0) reb = rmin[1]-rmax[1]+1;
        else if(i==n-1) reb = lmin[n-2]-lmax[n-2]+1;
        if(reb<0) reb=(ll)0;
        ans=max(ans,res+reb);
    }
    cout << ans << endl;
}


Measured memory_bytes: 8176
N, M = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(M)]

set1=set()
setn=set()

for s in S:
  a=min(s)
  b=max(s)
  if a==1 and b==N:
    print('POSSIBLE')
    break
  elif a==1:
    set1.add(b)
  elif b==N:
    setn.add(a)
  else:
    continue
else:
  if (set1 & setn):
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')
    
  

Measured memory_bytes: 58892
R,G,B,N = list(map(int,input().split(' ')))

count = 0

r_max = N // R
for r in range(0,r_max+1):
	N_N = N - R * r
	g_max = N_N//G+1
	for g in range(0,g_max):
		if (N-r*R - g*G)%B == 0:
			count += 1

print(count)


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

int main() {
	int N;
	ll H;
	cin >> N >> H;
	vector<ll> a(N), b(N);
	for(int i=0;i<N;i++) {
		cin >> a[i] >> b[i];
	}
	sort(a.rbegin(), a.rend());
	sort(b.rbegin(), b.rend());
	ll ans = LLONG_MAX;
	vector<ll> tb(N+1, 0);
	for(int i=1;i<=N;i++)
		tb[i] = tb[i-1] + b[i-1];
	// 刀をi本投げる
	for(int i=0;i<=N;i++) {
		if(H  >= tb[i]) {
			ans = min(ans, (H - tb[i] + a[0] - 1) / a[0] + i);
		} else {
			ans = min(ans, (ll)i);
		}
	}
	cout << ans << endl;
}

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

int main() {
  int M1, D1, M2, D2;
  cin >> M1 >> D1 >> M2 >> D2;

  if (D2 == 1)
    cout << 1 << endl;
  else
    cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 3536
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    string s,t; cin >> s >> t;
    if(SIZE(s) +1 != SIZE(t)){
        no();
        return 0;
    }
    int si = SIZE(s);
    rep(i,si){
        if(s[i] != t[i]){
            no();
            return 0;
        }
    }
    yes();
    return 0;
}


Measured memory_bytes: 3596
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

cum_E = [0] * (N+1)
for i in range(N):
  cum_E[i+1] = cum_E[i] + (A[i]+1)/2
  
k_cum_E = [0] * (N-K+1)
for i in range(N-K+1):
  k_cum_E[i] = cum_E[i+K] - cum_E[i]

print(max(k_cum_E))

Measured memory_bytes: 25060
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;
using ll =long long;
const int MOD = 1000000007;



vector<int> buf;
int sum;
void dfs(int *big,const vector<int>a,const vector<int>b,const vector<int>c,const vector<int>d ,const int Q,int i, const int size, const int range_start, const int range_end)
{
	
	if (i == size) {
		
		sort(buf.begin(), buf.end());
		 sum=0;
		
			for (int j = 0; j <Q; ++j) {
				if (buf[b[j]-1] - buf[a[j]-1] == c[j]) {
					sum += d[j];
				}
			}
			*big =(int)max(sum, *big);
		
	}
	else {
		if (i - 1 >= 0) {
			for (int j = buf[i - 1]; j <= range_end; ++j) {
				buf[i] = j;
				dfs(big, a, b, c, d, Q, i + 1, size, range_start, range_end);
			}
		}
		else {
			for (int j = range_start; j <= range_end; ++j) {
				buf[i] = j;
				dfs(big, a, b, c, d, Q, i + 1, size, range_start, range_end);
			}
		}
	}
}

int main() {
	int N, M, Q;
	vector<int>a, b, c, d;
	cin >> N >> M >> Q;
	int w, x, y, z;
	for (int i = 0; i < Q; i++) {
		cin >> w >> x >> y >> z;
		a.push_back(w);
		b.push_back(x);
		c.push_back(y);
		d.push_back(z);
	}
	int big = 0;
	buf.resize(N);
	
	dfs(&big, a, b, c, d, Q, 0, N, 1, M);
	
	cout << big;


}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
//#pragma comment(linker, "/STACK: 2000000")

using namespace std;

const int N = 2e6 + 5;

int h , w , a, b;
int m[1001][1001];

int main() {
    cin>>h>>w>>a>>b;
    for(int i = 0;i<b;i++)
    {
        for(int j = 0;j<w;j++)
        {
            cout<<(j<a);
        }
        cout<<"\n";
    }
    for(int i = 0;i<h-b;i++)
    {
        for(int j = 0;j<w;j++)
        {
            cout<<(j>=a);
        }
        cout<<"\n";
    }
    return 0;

}


Measured memory_bytes: 1280
#include<stdio.h>
typedef struct{
  char sign;
  int value;
}Card;
void BubbleSort(Card*,int);
void SelectionSort(Card*,int);
int isStable(Card*,Card*,int);
void output(Card*,int,int);

int main()
{
  Card a[36],b[36];
  int i,j,n;

  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf(" %c%d",&a[i].sign,&a[i].value);
    b[i] = a[i];
  }

  BubbleSort(a,n);
  SelectionSort(b,n);
  output(a,n,0);
  output(b,n,isStable(b,a,n));

  return 0;
}
  
void BubbleSort(Card a[],int n)
{
  int i,j;
  Card tmp;

  for(i=0; i<n; i++) 
    for(j=n-1; j>i; j--) 
      if(a[j].value < a[j-1].value){
	tmp = a[j];
	a[j] = a[j-1];
	a[j-1] = tmp;
      }
}

void SelectionSort(Card b[],int n)
{
  int i,j,minj;
  Card tmp;

  for(i=0; i<n-1; i++) {
    minj = i;
    for(j=i; j<n; j++) 
      if(b[j].value < b[minj].value) minj = j;
    if(minj != i) {
      tmp = b[i];
      b[i] = b[minj];
      b[minj] = tmp;
    }
  }
}

int isStable(Card in[],Card out[],int n) 
{
  int i,j,a,b;
  for(i=0; i<n; i++) 
    for(j=i+1; j<n; j++)
      for(a=0; a<n; a++)
	for(b=a+1; b<n; b++)
	  if(in[i].value == in[j].value && in[i].sign == out[b].sign && in[j].sign == out[a].sign && in[i].value == out[b].value && in[j].value == out[a].value)
	    return 1;
  return 0;
}

void output(Card a[], int n,int result)
{
  int i;
  
  for(i=0; i<n; i++) {
    printf("%c%d",a[i].sign,a[i].value);
    if(i<n-1) printf(" ");
  }
  if(!result) printf("\nStable\n");
  else printf("\nNot stable\n");
}

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b)a=b;};

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

  string a,b,c;
  while(cin>>a,a!="-"){
    cin>>b>>c;
    Int n=a.size(),m=b.size();

    set<char> sc(c.begin(),c.end());
    Int i=0,j=0;
    char t=b[j++];
    string ans;
    while(i<n||j<m){
      if(sc.count(t)){
        t=a[i++];
      }else{
        ans+=t;
        t=b[j++];
      }
    }

    if(!sc.count(t)) ans+=t;
    cout<<ans<<endl;
  }

  return 0;
}



Measured memory_bytes: 3100
//let a: [Int] = readLine()!.split(" ").map { Int($0)! }
//print(a)

extension String: CollectionType {} // splitを使うためのおまじない

func strToInt(c:String) -> Int {
    return Int((c.unicodeScalars).first!.value)
}

let S: String = readLine()!
let a = strToInt("a")
let z = strToInt("z")
var v: [Int] = (a...z).map { _ in 0 }

for char in S {
    v[strToInt(String(char))-a]++
}
var f: Bool = true
for x in v {
    if x%2 != 0 {
        f=false
    }
}
if f {
    print("Yes")
} else {
    print("No")
}

/*
for code in "abcd".unicodeScalars {
    print(code.value)
}*/

Measured memory_bytes: 4080
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
const int maxn=1e9;

int main()
{
    int n,t,minn=1010;cin>>n>>t;
    rep(i,0,n){
        int c,tt;scanf("%d%d",&c,&tt);
        if(tt<=t) minn=min(minn,c);
    }
    if(minn==1010) cout<<"TLE"<<endl;
    else cout<<minn<<endl;
    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s = "AGTC";
    string b;
    cin >> b;
    REP(i,4){
        if(b[0]==s[i]){
            cout << s[(i+2)%4] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        int A = sc.nextInt();
        int B = sc.nextInt();

        List<Integer> a = Arrays.asList(A + B, A - B, A * B);
        a.sort(Comparator.reverseOrder());
        System.out.println(a.get(0));
    }
}

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

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

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    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 { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
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() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >> n;
    map<ll, ll> r, l;
    rep(i,n) {
        int a; cin >> a;
        if (a > n) continue;
        if (i+1 + a <= n) r[i+1 + a]++;
        if (i+1 - a >= 0) l[i+1 - a]++;
    }

    ll ans = 0;
    rep(i,n+1) {
//        cout << i+1 << ": " << r[i+1] << ' ' << l[i+1] << endl;
        ans += r[i+1] * l[i+1];
    }

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


Measured memory_bytes: 28668
import java.util.Scanner;
 
class Main {
    Scanner sc = new Scanner(System.in);
 
    public void run() {
        while(true){
 
            String s=sc.nextLine();
            if("-".equals(s))break;
            int count=sc.nextInt();
            for(int i=0;i<count;i++){
                int index=sc.nextInt();
                s=s.substring(index)+s.substring(0,index);
            }sc.nextLine();
            ln(s);
        }
    }
 
    public static void main(String[] args) {
        new Main().run();
    }
 
    public static void pr(Object o) {
        System.out.print(o);
    }
 
    public static void ln(Object o) {
        System.out.println(o);
    }
 
    public static void ln() {
        System.out.println();
    }
}



Measured memory_bytes: 26408
#include <stdio.h>

int main(void){
        int a,b;
        scanf("%d %d",&a,&b);
        int n,ans;
        if(a>b){
                ans=16-b*2;
                n=(a-b)*2;
        }
        else{
                ans=16-a*2;
                n=(b-a)*2;
        }
        if(ans-n<0)printf(":(\n");
        else printf("Yay!\n");
        return 0;
}

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

#define mx 1000008
typedef long long int ll;
ll w[102],v[102];
ll dp[1009*100][103];
ll n;
typedef long long int ll;
ll cal(ll i,ll j)
{
    if(j==n+1){
        if(i==0) return 0;
        else  return 13123152832;

    }
    if(i<0) return 123239512312;
    if(i==0) return 0;
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    ll res=min(cal(i,j+1),cal(i-v[j],j+1)+w[j]);

    return dp[i][j]=res;
}
int main()
{
        ll k;
        cin>>n>>k;
        for(int i=1;i<=n;i++){
            cin>>w[i]>>v[i];
        }
        ll ans=0;
        memset(dp,-1,sizeof(dp));
        for(ll i=1;i<=100007;i++){
            ll x=cal(i,1);
            if(x<=k){
                ans=max(ans,i);
            }
        }
        cout<<ans<<endl;
}

Measured memory_bytes: 84764
N,A=map(int,input().split())
x=list(map(int,input().split()))
xx=max(max(x),A)

dp=[[[0]*(N*xx+1) for _ in range(N+1)] for _ in range(N+1)]

for j in range(N+1):
  for k in range(N+1):
    for s in range(N*xx+1):
      if j==k==s==0:
        dp[j][k][s]=1
      elif j>=1 and s<x[j-1]:
        dp[j][k][s]=dp[j-1][k][s]
      elif j>=1 and k>=1 and s>=x[j-1]:
        dp[j][k][s]=dp[j-1][k][s]+dp[j-1][k-1][s-x[j-1]]
      else:
        pass
ans=0
for k in range(1,N+1):
  ans+=dp[N][k][k*A]
print(ans)

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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  set<string> S;
  for(int i = 0; i < n; ++i) {
    string x; cin >> x;
    S.insert(x);
  } 
  cout << S.size() << '\n';
  return 0;
}


Measured memory_bytes: 19284
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(" ", $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int)$this->next();
    }

    public function nextDouble()
    {
        return (double)$this->next();
    }
}

class out
{
    public static function printIn($str = "")
    {
        echo $str . PHP_EOL;
    }
}

$sc = new Scanner;
$N = $sc->nextInt();
$nums = [];
for ($i = 0; $i < $N; $i++) {
  $nums[] = $sc->nextInt();
}

rsort($nums);
$Alice = 0;
$Bob = 0;
for ($i = 0; $i < $N; $i++) {
    if($i % 2 === 0){
        $Alice += $nums[$i];
    }else{
        $Bob += $nums[$i];
    }
}
echo $Alice - $Bob;


Measured memory_bytes: 4604
from collections import Counter

# 入力
N = int(input())
A = list(map(int, input().split()))

# 最大の整数が書かれているボールから順に貪欲的にペアを作成する。
C = Counter(A)
ans = 0
for m in sorted(C, reverse=True):
    p = (1 << m.bit_length()) - m
    if m == p:
        ans += C[m] // 2
    elif p in C:
        k = min(C[m], C[p])
        ans += k
        C[p] -= k

# 出力
print(ans)


Measured memory_bytes: 33296
package main

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

const (
	BUFSIZE   = 10000000
	MOD       = 1000000007
	INF_INT   = math.MaxInt32
	INF_INT64 = math.MaxInt64
)

var rdr *bufio.Reader

func main() {
	rdr = bufio.NewReaderSize(os.Stdin, BUFSIZE)
	solve()
}

func solve() {
	N := readint()
	A := readIntSlice(N)
	ans := 0
	now := 1
	for _, v := range A {
		if v != now {
			ans += 1
		} else {
			now += 1
		}
	}

	if ans == N {
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}
}

func readline() string {
	buf := make([]byte, 0, BUFSIZE)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			fmt.Println(e.Error())
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func readIntSlice(size int) []int {
	slice := make([]int, size)
	lines := strings.Split(readline(), " ")
	for i, v := range lines {
		slice[i] = s2i(v)
	}
	return slice
}

func readInt64Slice(size int) []int64 {
	slice := make([]int64, size)
	lines := strings.Split(readline(), " ")
	for i, v := range lines {
		slice[i] = s2i64(v)
	}
	return slice
}

func readint() int {
	return s2i(readline())
}

func readint64() int64 {
	return s2i64(readline())
}

// For int64
func b2i64(b bool) int64 {
	if b {
		return 1
	}
	return 0
}

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

func min64(values ...int64) int64 {
	ret := int64(INF_INT64)
	for _, v := range values {
		if ret > v {
			ret = v
		}
	}
	return ret
}

func max64(values ...int64) int64 {
	ret := -int64(INF_INT64)
	for _, v := range values {
		if ret < v {
			ret = v
		}
	}
	return ret
}

func s2i64(s string) int64 {
	v, ok := strconv.ParseInt(s, 10, 64)
	if ok != nil {
		panic("Faild : " + s + " can't convert to int64")
	}
	return v
}

// For int
func b2i(b bool) int {
	if b {
		return 1
	}
	return 0
}

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

func min(values ...int) int {
	ret := INF_INT
	for _, v := range values {
		if ret > v {
			ret = v
		}
	}
	return ret
}

func max(values ...int) int {
	ret := -INF_INT
	for _, v := range values {
		if ret < v {
			ret = v
		}
	}
	return ret
}

func s2i(s string) int {
	v, ok := strconv.Atoi(s)
	if ok != nil {
		panic("Faild : " + s + " can't convert to int")
	}
	return v
}

func lcm(v1, v2 int) int {
	if v1 > v2 {
		v1, v2 = v2, v1
	}
	for v1 != 0 {
		v1, v2 = v2%v1, v1
	}
	return v2
}

func gcd(v1, v2 int) int {
	return v1 * v2 / lcm(v1, v2)
}

/* ------------------------------------------------ */
/* Data stracture                                   */
/* ------------------------------------------------ */
type IntHeap []int

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }


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

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

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

}
int main(){
    int a, b; cin >> a >> b;
    if(a < b){
        int tmp = b;
        b = a;
        a = tmp;
    }
    int ans = gcd(a, b);
    cout << ans << endl;

}



Measured memory_bytes: 3108
#include <iostream>

using namespace std;

int main()
{
    int n , a;
    double ans;
    cin >> n;
    for (int i = 1 ; i <= n ; i++){
        if (i % 2 == 1){
            a++;
        }
    }
    ans = (double)a / (double)n;
    cout << ans;
    return 0;
}


Measured memory_bytes: 3788
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    scan.nextLine();
    String S;
    String[] sArray;
    String[][] sArray2 = new String[N][2];
    Set<String> key = new TreeSet<>();
    for (int i = 0; i < N; i++) {
      S = scan.nextLine();
      sArray = S.split(" ");
      sArray2[i][0] = sArray[0];
      sArray2[i][1] = sArray[1];
      key.add(sArray[0]);
    }
    Map<Integer, Integer> map = new TreeMap<>(new Comparator<Integer>() {
      public int compare(Integer k1, Integer k2) {
        return k2.compareTo(k1) ;
      }
    });
    for (String k : key) {
      for (int i = 0; i < N; i++) {
        if (k.equals(sArray2[i][0])) {
          map.put(Integer.parseInt(sArray2[i][1]), i + 1);
        }
      }
      for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
        System.out.println(entry.getValue());
      }
      map.clear();
    }
  }
}



Measured memory_bytes: 21972
#include <stdio.h>
#include <string.h>
int main()
{
	char s[1000000];
	long long int i, j, p = 0, a, k;
 scanf("%s",s);
	a = strlen(s);//printf("%d",a);
	for (i = 0; i < a; i++)
	{
		p = p + (s[i] - '0');
		p = p % 9;
	}
	if (p % 9 == 0)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


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

using namespace std;

int main(){
    vector<int> a(3);
    for (int i=0;i<3;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    for(int i=0;i<3;i++){
        cout << a[i];
        if(i!=2) cout << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3104
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
 
using namespace std;

int main()
{
	int n,k;
	cin>>n>>k;
	cout<< n - k + 1;

	return 0;
}

Measured memory_bytes: 256
N, L = map(int, input().split())
taste = [L + i - 1 for i in range(1, N+1)]
abs_diff_taste = [abs(x) for x in taste]
sum_taste = sum(taste)
min_diff = min(abs_diff_taste)
if sum_taste >= 0:
  print(sum_taste - min_diff)
else:
  print(sum_taste + min_diff)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;

  if( y+r <= H && y-r >= 0)
    if( x+r <= W && x-r >= 0){
      cout << "Yes" << endl;
      return 0;
    }
  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3112
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func check(h int, w int, grid [][]string) bool {
	if grid[h-1][w] == "#" {
		return true
	}

	if grid[h][w-1] == "#" {
		return true
	}

	if grid[h][w+1] == "#" {
		return true
	}

	if grid[h+1][w] == "#" {
		return true
	}

	return false
}

func main() {
	sc.Split(bufio.ScanWords)

	h, w := nextInt(), nextInt()

	grid := make([][]string, h+2)
	grid[0] = make([]string, w+2)
	grid[h+1] = make([]string, w+2)

	for i := 0; i < h; i++ {
		row := strings.Split(nextLine(),"")
		tmp := make([]string, w+2)
		for j := 0; j < w; j++ {
			tmp[j+1] = row[j]
		}
		grid[i+1] = tmp
	}

	for i := 1; i <= h; i++ {
		for j := 1; j <= w; j++ {
			if grid[i][j] == "." {
				continue
			}

			if !check(i, j, grid) {
				fmt.Println("No")
				return
			}
		}
	}

	fmt.Println("Yes")
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
    int n; std::cin >> n;
    std::vector<ll> a(n); REP(i,n) std::cin >> a[i];
    std::map<ll, ll> wa;

    ll ans = 0;

    REP(i,n) {
        ll temp_wa = i + 1 + a[i], temp_sa = (i+1)-a[i];
        wa[temp_wa]++;
        auto it = wa.find(temp_sa);
        if (it != wa.end()) {
            ans += it->second;
        }
    }


    std::cout << ans << "\n";
    return 0;
}


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

int main(){
    int N,K; cin >> N >> K;
    string S; cin >> S;
    if(S.at(K-1)=='A'){
        S.at(K-1)='a';
    }
    else if(S.at(K-1)=='B'){
        S.at(K-1)='b';
    }
    else{
        S.at(K-1)='c';
    }
    cout << S << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector< vector< long long > >tree(800009);

void make(int cur,int l,int r,vector<long long>&arr2)
{
    if(l==r)
    {
        tree[cur].push_back(arr2[l]);
        return;
    }
    int mid=(l+r)/2;
    make(2*cur+1,l,mid,arr2);
    make(2*cur+2,mid+1,r,arr2);
    for(int i=0;i<tree[2*cur+1].size()+tree[2*cur+2].size();i++)tree[cur].push_back(0);
    merge( tree[2*cur+1].begin(),tree[2*cur+1].end(),tree[2*cur+2].begin(),tree[2*cur+2].end() ,tree[cur].begin() );
}

int get(int cur,int l,int r,int s,int e,long long value)
{
    if(l>e || r<s)
        return 0;

    if(l>=s && r<=e)
    {
        int ret=upper_bound( tree[cur].begin(),tree[cur].end(),value-1)-tree[cur].begin();
        return tree[cur].size()-ret;
    }

    int mid=l+r >> 1;
    return get(2*cur+1,l,mid,s,e,value) + get(2*cur+2,mid+1,r,s,e,value);
}

int main()
{
    ios_base::sync_with_stdio(stdin);cin.tie(NULL);cout.tie(NULL);

    long long n,k,ans(0);
    cin>>n>>k;
    vector< long long > arr(n+1,0),arr2(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
        arr[i]+=arr[i-1];
        arr2[i]=arr[i]-i*k;
    }
    make(0,1,n,arr2);
    //for(int i=1;i<=n;i++)cout<<arr2[i]<<" ";
    //cout<<"\n";

    for(int i=1;i<=n;i++)
    {
       ans+=get(0,1,n,i,n,arr2[i-1]);
        //cout<<ans<<" "<<i<<"\n";
    }
    cout<<ans;
}


Measured memory_bytes: 66036