akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <map>

using namespace std;

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

typedef vector<int> vi;

int main()
{
	double weights[] = {48.0, 51.0, 54.0, 57.0, 60.0, 64.0, 69.0, 75.0, 81.0, 91.0};
	const char* strs[] = {"light fly", "fly", "bantam", "feather", "light", "light welter", "welter", "light middle", "middle", "light heavy", "heavy"};

	double w;
	while(scanf("%lf", &w) != EOF){
		puts(strs[distance(weights, lower_bound(weights, weights+10, w))]);
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
 
 
int main()
{
    int n, t;
    std::cin >> n >> t;
    std::vector<std::pair<int, int>> p;
    for(int i=0; i<n; i++)
    {
        int a, b;
        std::cin >> a >> b;
        p.push_back(std::make_pair(a, b));
    }
    std::sort(p.begin(), p.end());
    int ans = 10000;
    for(int i=0; i<n; i++)
    {
        if(p[i].second <= t)
        {
            ans = std::min(p[i].first, ans);
        }
    }
    if(ans==10000) std::cout << "TLE" << std::endl;
    else std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
dp = Array.new(n+10){Array.new(3, 0)}
happy = []
n.times do |i|
  happy << gets.split.map(&:to_i) 
end

n.times do |i|
  3.times do |k|
    3.times do |l|
      dp[i+1][l] = [dp[i+1][l], dp[i][k]+happy[i][l]].max if k != l # k -> lへの遷移
    end
  end
end

#p happy
#p dp
p dp[n].max

Measured memory_bytes: 25596
#include<stdio.h>

int main(void) {
	unsigned int	iA, iB;
	int				ret;
	//a,bを入力
	ret = scanf("%d %d", &iA, &iB);
	//a,bの和が2で割り切れないとき、切り上げた答えを出力
	if ((iA + iB) % 2 != 0) {
		printf("%d", (iA + iB + 1)/2);
	}
	//そうでなければそのままの結果を出力
	else {
		printf("\n%d\n", (iA + iB)/2);
	}
	return 0;
}

Measured memory_bytes: 1700
#include<stdio.h>
#include<algorithm>
using namespace std;
int x[100];
int y[100];
int r[100];
bool CL_intersect(int ax,int ay,int bx,int by,int cx,int cy,int r){
	int acx=cx-ax;
	int acy=cy-ay;
	int bcx=cx-bx;
	int bcy=cy-by;
	int abx=bx-ax;
	int aby=by-ay;
	if(acx*acx+acy*acy>=r*r||bcx*bcx+bcy*bcy>=r*r){
		if(abx*acx+aby*acy<0){
			if(acx*acx+acy*acy<=r*r)return true;
		}else{
			if(abx*acx+aby*acy>abx*abx+aby*aby){
				if(bcx*bcx+bcy*bcy<=r*r)return true;
			}else if(acx*acx+acy*acy-(long long)(abx*acx+aby*acy)*(abx*acx+aby*acy)/(abx*abx+aby*aby)<=r*r)return true;
		}
	}
	return false;
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%d%d%d",x+i,y+i,r+i);
		int b;
		scanf("%d",&b);
		for(int i=0;i<b;i++){
			int c,d,e,f;
			scanf("%d%d%d%d",&c,&d,&e,&f);
			bool ok=false;
			for(int j=0;j<a;j++){
				if(CL_intersect(c,d,e,f,x[j],y[j],r[j]))ok=true;
			}
			if(ok)printf("Safe\n");
			else printf("Danger\n");
		}
	}
}

Measured memory_bytes: 1012
#include<iostream>
using namespace std;
int main()
{
    int n,y;
    cin >> n >> y;
    if(n*10000<y){cout << -1<<' '<<-1<<' '<<-1 <<endl;return 0;}
    if(n*1000>y){cout << -1<<' '<<-1<<' '<<-1 <<endl;return 0;}
    for(int i = 0;i <= y/10000;i++)
    {
        for(int j = 0;j <= (y-i*10000)/5000;j++)
        {
            if(i+j+(y-i*10000-j*5000)/1000 == n)
            {cout << i<<' '<<j<<' '<<(y-i*10000-j*5000)/1000<<endl;return 0;}
            
        }
    }
    cout << -1<<' '<<-1<<' '<<-1 <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9

/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */


int main(){
    
    ll n, m; cin >> n >> m;
    vector<bool> ac(n, false);
    vector<ll> wc(n, 0);
    
    rep(i,m){
        ll p;
        string s;
        cin >> p >> s;
        p--;
        if(s == "AC"){
            ac[p] = true;
            continue;
        }else{
            if(!ac[p]){
                
                wc[p]++;
            }
        }
    }
    ll ansAC = 0;
    ll ansWC = 0;
    rep(i,n){
        if(ac[i]){
            ansAC++;
        }
        if(ac[i]){
            ansWC += wc[i];
            
        }
    }
    
    cout << ansAC <<endl;
    cout << ansWC << endl;
    
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <algorithm> // sort
#include <utility> // pair
#include <cfloat> // DBL_MAX

typedef long long ll;
using namespace std;


struct node{
  ll idx;
  ll size;
  ll num;
  node(ll i, ll s, ll n): idx(i), size(s), num(n) {}
};

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

  map<ll, pair<ll,ll> > stnmap;
  for(ll i=0; i<N; i++){
    ll tmp;
    cin >> tmp;
    if(stnmap.find(tmp) == stnmap.end()){
      stnmap[tmp] = make_pair(i,1);
    } else {
      stnmap.at(tmp).second += 1;
    }
  }

  queue<node> q;
  for(auto itr = stnmap.rbegin(); itr!=stnmap.rend(); itr++){
    q.push(node(itr->second.first, itr->first, itr->second.second));
  }
  q.push(node(0,0,0));

  // while(!q.empty()){
  //   cerr << q.front().idx << " " << q.front().size << " " << q.front().num << endl;
  //   q.pop();
  // } return 0;

  vector<ll> ans(N,0);
  while(q.front().size != 0){
    //cerr << q.front().idx << " " << q.front().size << " " << q.front().num << endl;

    node crr = q.front();
    q.pop();

    // cerr << crr.idx << " " << crr.size << " " << crr.num << endl;
    // cerr << q.front().idx << " " << q.front().size << " " << q.front().num << endl;
    // cerr << crr.idx << " " << (crr.size - q.front().size) * crr.num << endl;

    ans[crr.idx] += (crr.size - q.front().size) * crr.num;
    ll tmp = min(q.front().idx, crr.idx);
    q.front().idx = tmp;
    q.front().num += crr.num;
  }

  for(ll i=0; i<N; i++){
    cout << ans[i] << endl;
  }


  return 0;
}


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

void solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(d == 1) cout << 1 << '\n';
    else cout << 0 << '\n';
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define mo 1000000007
#define mod2 1000000000
#define mod1 998244353
#define lol ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define F(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define ss second



int main()
{
    ll n;cin >> n;
    ll k;cin >> k;
    ll arr[n+1];
    arr[0] = 0;
    for(int i=1;i<=n;i++)
    {
        cin >> arr[i];
    }
    for(int i=k+1;i<=n;i++)
    {
        if(arr[i]>arr[i-k]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 5196
#include <stdio.h>
int main(){
	int a,b,c,escape;
	scanf("%d %d %d",&a,&b,&c);
	
	if(a>b){
		escape=a;
		a=b;
		b=escape;
	}

	if(b>c){
		escape=b;
		b=c;
		c=escape;
	}
	
	if(a>c){
		escape=a;
		a=c;
		c=escape;
	}
	
	if(a>b){
		escape=a;
		a=b;
		b=escape;
	}

	printf("%d %d %d\n",a,b,c);		

return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    String op = sc.next();
    int b = sc.nextInt();
    String str = "+";
    if(op.equals(str)){
      System.out.println(a+b);
    }else{
      System.out.println(a-b);
    }
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define fi first
#define se second
#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 srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vl a(n), a_sort(n),b(n);
  rep(i,n) cin >> a[i];
  map<ll,int> M;
  a_sort = a;
  sort(rng(a_sort));
  rep(i,n){
    M[a_sort[i]] = i;
  }
  rep(i,n) b[i] = M[a[i]];
  int ans = 0;
  rep(i,n){
    if(b[i] % 2 != i%2) ans++;
  }
  cout<<ans/2<<endl;
  return 0;
}

Measured memory_bytes: 8832
// AOJ 2418: Problem B War II
// 2017.12.2 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

int t[101], h[101];
int T, H;

int main()
{
	int n, L, i, tn, hn, sum, cng;

	scanf("%d%d%d%d", &n, &T, &H, &L);
	for (i = 0; i < n; i++) scanf("%d%d", t+i, h+i);
	for (tn = hn = 0, i = 0; ; i++) {
		if (i == n) i = 0;

		if (!t[i] && !h[i]) break;
		if (t[i]) tn++, t[i]--;
		else      hn++, h[i]--;

		if (T + tn > L) break;
		sum = tn + 10*hn;
		if (sum < 9) continue;

		T += tn, H += hn, tn = hn = 0;
		cng = sum - 9;

		if (cng <= T) { T -= cng, t[i] += cng; continue; }
		if (cng >= 10) {
			cng -= 10, H--, h[i]++;
		}
		if (cng <= T) T -= cng, t[i] += cng;
		else break;
	}
	printf("%d\n", i+1);
	return 0;
}

Measured memory_bytes: 1772
from heapq import heappop,heappush,heapify
import math

n,m = map(int,input().split())
a = list(map(int,input().split()))
a = list(map(lambda x:-x,a))

heapify(a)

for i in range(m):
    p = heappop(a)
    heappush(a,math.ceil(p/2))

ans = 0
for _ in range(n):
    p = heappop(a)
    ans += -p

print(ans)

Measured memory_bytes: 110744
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
 
int main(){
	int N,Q,i,j,count=0,Anscount=0,migi,hidari,Ans[100001],judge[100001];
	char S[100001];
	scanf("%d",&N);
	scanf("%d",&Q);
	scanf("%s",S);
 
	for(j=0;j<N;j++){
		if(S[j]=='A' && S[j+1]=='C'){
			judge[j]=1;
			count++;
		}else{
			judge[j]=0;
		}
		Ans[j]=count;
	}
 
	for(i=0;i<Q;i++){
		scanf("%d",&hidari);
		scanf("%d",&migi);
		printf("%d\n",Ans[migi-2]-Ans[hidari-1]+judge[hidari-1]);
	}
 
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;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 INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    V a {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;cin >>k;
    cout << a[k-1];

}

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

using namespace std;

#define ll long long 
#define REPL(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define radrad(a)  180.0 * a / M_PI
#define pow(x) x*x
static const int MAX = 10010;
static const ll INFTY = 1e12;
static const ll NUMMAX = 1000000007;
static const ll MOD = 1000000007;
 #define LOOP 10000000

int main() {

    string S1, S2, ans;

    cin >> S1 >> S2;

    ans = S2+S1;

    cout << ans << endl;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


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

using namespace std;

//#define int long long
#define FOR(i, j, k) for(int i = j; i < (int)k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

const int MOD = 1e9 + 7;
const int dy[] = {0, 0, 1, -1};
const int dx[] = {1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

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

    int n;
    int res = 0;
    cin >> n;
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        res += (b - a) + 1;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		
		String sz_input = br.readLine();
		String[] sz_number = sz_input.split(" ");
		
		for (int i = n-1; i>=0; i--) {
			System.out.print(Integer.parseInt(sz_number[i]));
			if (i > 0) {
				System.out.print(" ");
			}
		}
		
		System.out.println();
	}
}

Measured memory_bytes: 24196
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

const int MAX_N=200202;
const int mod=1000000007;
ll fact[MAX_N+1];
ll inv[MAX_N+1],finv[MAX_N+1];

int inv_init(ll n,ll p){
    inv[1]=1;
    FOR(i,2,n+1) inv[i]=p-(p/i)*inv[p%i]%p;
    fact[0]=finv[0]=1;
    FOR(i,1,n+1){
        fact[i]=fact[i-1]*i%p;
        finv[i]=finv[i-1]*inv[i]%p;
    }
    return 0;
}
ll comb_mod(ll n,ll k,ll p){
    if(k<0||n<k) return 0;
    return finv[k]*finv[n-k]%p*fact[n]%p;
}
pint rc[3005];
ll dp[3005][2];
int main(){
    int h,w,n;
    cin>>h>>w>>n;
    inv_init(h+w+10,mod);
    int ri,ci;
    rc[0]={1,1};
    rep(i,n){
        cin>>ri>>ci;
        rc[i+1]={ri,ci};
    }
    rc[n+1]={h,w};
    sort(rc,rc+(n+2));
    dp[0][0]=1;
    rep(i,n+1){
        int tr=rc[i].first,tc=rc[i].second;
        FOR(j,i+1,n+2)if(tr<=rc[j].first&&tc<=rc[j].second){
            ll co=comb_mod(rc[j].first-tr+rc[j].second-tc,rc[j].first-tr,mod);
            dp[j][1]+=(dp[i][0]*co)%mod;
            dp[j][0]+=(dp[i][1]*co)%mod;
            dp[j][1]%=mod;
            dp[j][0]%=mod;
        }
    }
    cout<<((dp[n+1][1]-dp[n+1][0])%mod+mod)%mod<<endl;
    return 0;
}


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

int n;
int a[101]={};
int b[101]={};
int c[101][100]={};
int cn[101]={};

int f(int i1,int i2,int used_ring[101],int l){
	int mc;
	int m=l;
	for(int i=0;i<cn[i1];i++){
		if(used_ring[c[i1][i]] == 0){
			used_ring[c[i1][i]]=1;
			mc=f(c[i1][i],i2,used_ring,l+1);
			used_ring[c[i1][i]]=0;
			if(mc>m){m=mc;}
		}
	}
	return m;
}
	
int main() {
	while(1){
		int mc;
		int m=0;
		for(int i=0;i<101;i++){
			cn[i]=0;
		}
		cin >> n;
		if(n==0){return 0;}
		for(int i=0;i<n;i++){
			cin >> a[i] >> b[i];
			c[a[i]][cn[a[i]]]=b[i];
			c[b[i]][cn[b[i]]]=a[i];
			cn[a[i]]++;
			cn[b[i]]++;
		}
		
		for(int i=0;i<n;i++){
			int used_ring[101]={};
			used_ring[a[i]]=1;
			used_ring[b[i]]=1;
			mc=f(a[i],b[i],used_ring,2);
			if(mc>m){m=mc;}
			mc=f(b[i],a[i],used_ring,2);
			if(mc>m){m=mc;}
		}
		cout << m << endl;
	}
}

Measured memory_bytes: 1204
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(void){
    char s[202], p[101], s2[101];
    cin >> s >> p;
    
    strcpy(s2, s);
    strcat(s, s2);

    if (strstr(s, p) != NULL){
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3116
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);
impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

const INF: usize = 1_000_000_000_000;

fn solve() {
    let (n,m) = get!(usize, usize);
    let mut dp = vec![vec![INF; 1<<n+1]; m+1];
    dp[0][0] = 0;
    for i in 0..m {
        let (a,_) = get!(usize, usize);
        let c = get!([usize]);
        let mut res = 0;
        for e in c {
            res |= 1<<(e-1);
        }
        for j in 0..(1<<n) {
            dp[i+1][j] = min!(dp[i+1][j], dp[i][j]);
            dp[i+1][j|res] = min!(dp[i+1][j|res], dp[i][j|res], dp[i][j]+a);
        }
    }
    if dp[m][(1<<n)-1] == INF {
        println!("-1");
    } else {
        println!("{}",dp[m][(1<<n)-1]);
    }
}


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

int L;

int main(){

    cin >> L;
    double a, b, c, ans;

    a = L/3.000;
    b = a;
    c = a;
    ans = a*b*c;

    cout << fixed << setprecision(15) << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
import math

def solve():
    n = int(input())
    a,b,c = [0]*n,[0]*n,[0]*n
    for i in range(n):
        a[i],b[i],c[i] = map(int, input().split())
    dp = [[0]*3 for i in range(n+5)]
    for i in range(1,n+1):
        dp[i][0] = max(dp[i-1][1]+a[i-1],dp[i-1][2]+a[i-1])
        dp[i][1] = max(dp[i-1][0]+b[i-1],dp[i-1][2]+b[i-1])
        dp[i][2] = max(dp[i-1][0]+c[i-1],dp[i-1][1]+c[i-1])
    print(max(dp[n]))
    return 0
 
if __name__ == "__main__":
    solve()


Measured memory_bytes: 43512
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define pdd pair < db , db >
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n,m;
    fi>>n>>m;
    m += 'A' - 1;
    for (int i = 1;i <= n;++i)
        for (int j = 'A';j <= m;++j)
        {
            string s;
            fi>>s;
            if (s == "snuke")
                return fo << char(j) << i << '\n',0;
        }
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}




Measured memory_bytes: 256
// Written by newbiechd
#include <cstdio>
#include <cctype>
#include <cstring>
using namespace std;

const int BUF = 1000003;
inline char getChar() {
  static char buf[BUF], *bufS, *bufT;
  if (bufS == bufT) {
    bufT = (bufS = buf) + fread(buf, 1, BUF, stdin);
    if (bufS == bufT) return EOF;
  }
  return *bufS++;
}
inline int read() {
  int f = 0;
  char ch;
  while (!isdigit(ch = getChar())) {}
  do f = f * 10 + (ch ^ 48);
  while (isdigit(ch = getChar()));
  return f;
}

const int maxN = 403, mod = 998244353;
int a[maxN], b[maxN], inv[maxN], fac[maxN], bin[maxN][maxN];
int p[maxN][maxN], temp[maxN][maxN];

inline int power(int x, int y) {
  int o = 1;
  while (y) {
    if (y & 1) o = 1ll * o * x % mod;
    x = 1ll * x * x % mod, y >>= 1;
  }
  return o;
}

int main() {
  int n = read(), i, j, k, t, A = 0, B = 0, ans = 0;
  for (i = 1; i <= n; ++i)
    A += a[i] = read(), b[i] = read();
  inv[1] = 1;
  for (i = 2; i < maxN; ++i)
    inv[i] = -1ll * (mod / i) * inv[mod % i] % mod;
  fac[0] = 1;
  for (i = 1; i < maxN; ++i)
    fac[i] = 1ll * fac[i - 1] * i % mod;
  k = power(A, mod - 2);
  for (i = 1; i <= n; ++i) {
    t = 1ll * k * a[i] % mod, bin[i][0] = 1;
    for (j = 1; j < b[i]; ++j)
      bin[i][j] = 1ll * bin[i][j - 1] * t % mod * inv[j] % mod;
  }
  
  p[0][0] = 1, A = 0;
  for (i = 1; i <= n; ++i) {
    for (j = 0; j <= A; ++j)
      for (k = 0; k <= B; ++k) {
        temp[j + a[i]][k] = (temp[j + a[i]][k] + p[j][k]) % mod;
        for (t = 0; t < b[i]; ++t)
          temp[j][k + t] = (-1ll * p[j][k] * bin[i][t] + temp[j][k + t]) % mod;
      }
    A += a[i], B += b[i];
    for (j = 0; j <= A; ++j) {
      memcpy(p[j], temp[j], sizeof(int) * B);
      memset(temp[j], 0, sizeof(int) * B);
    }
  }
  
  for (i = 0; i <= A; ++i)
    for (j = 0; j <= B; ++j)
      p[i][j] = -p[i][j];
  ++p[A][0];
  k = power(A, mod - 2);
  for (i = 0; i < A; ++i) {
    t = 1ll * k * i % mod;
    for (j = 0; j <= B; ++j)
      ans = (1ll * p[i][j] * fac[j] % mod * power(1 - t, mod - j - 2) + ans)
        % mod;
  }
  printf("%d\n", (ans + mod) % mod);
  return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


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

    string res = "No";
    for(int i = 1; i <= 9; ++i)
    {
        for(int j = 1; j <= 9; ++j)
        {
            if(N == i * j)
            {
                res = "Yes";
            }
        }
    }

    cout << res << endl;

    return 0;    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  double q = a / 2;
  if (a % 2 == 1){
    q += 1;
    double p = q / a;
    cout << p << endl;
  }
  else if (a % 2 == 0)
    cout << 0.5000000000 << endl;

  else
    cout << 1.0000000000 << endl;
}

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

int main(void)
{
    int a[5], i;
    for (i = 0; i < 5; i++)
    {
        cin >> a[i];
    }
    for (i = 0; i < 5; i++)
    {
        if (a[i] == 0)
        {
            cout << i + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3596
n,m,x = map(int,input().split())
c = []
a = []
for i in range(n):
  l = list(map(int,input().split()))
  c.append(l[0])
  a.append(l[1:])
result = -1
for i in range(2 ** n):
  ct = 0
  at = [0] * m
  for b in range(0, n):
    bb = 1 << b 
    if i & bb > 0:
      ct += c[b]
      for j in range(0, m):
        at[j] += a[b][j]
  if result == -1 or ct < result:
    r = 1
    for ati in at:
      if ati < x:
        r = 0
    if r == 1:
      result = ct
print(result)

Measured memory_bytes: 9148
#include <bits/stdc++.h>
#define INF 2147483647
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define MAX 100005
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int a, b;

    cin>>a>>b;

    cout<<max(a + b, max(a - b, a * b))<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define SENTINEL 1000000000

int c=0;
void merge(int A[],int left,int mid,int right){
  int n1,n2,i,j,k;
  int *L,*R;
  n1=mid-left;
  n2=right-mid;
  L=(int *)malloc(sizeof(int)*(n1+1));
  R=(int *)malloc(sizeof(int)*(n2+1));
  for(i=0;i<=n1-1;i++){
    L[i]=A[left+i];
  }
  for(j=0;j<=n2-1;j++){
    R[j]=A[mid+j];
  }
  L[n1]=SENTINEL;
  R[n2]=SENTINEL;
  i=0;
  j=0;
  for(k=left;k<=right-1;k++){
   if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
      c++;
    }
    else{
      A[k]=R[j];
      j++;
      c++;
    }
  }
  free(L);
  free(R);
}

void mergeSort(int A[],int left,int right){
  int i,mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

int main(){
  int A[500000];
  int i,num;
  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d",&A[i]);
  }
  mergeSort(A,0,num);
  for(i=0;i<num;i++){
    printf("%d",A[i]);
    if(i<num-1)printf(" ");
  }
  printf("\n%d\n",c);
  return 0;
}



Measured memory_bytes: 5428
// #include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repr(i,n) for (int i = 0; i < (f); --i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int INF = (1<<12);

int main() {
  int k, n;
  cin >> k >> n;
  vector<int> A(n);
  rep(i,n) cin >> A[i];
  int ans = k - (A[n-1] - A[0]);
  for (int i = 1; i < n; i++)
  {
    ans = max(ans, A[i] - A[i-1]);
  }
  cout << k - ans << endl; 
}

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

typedef long long ll;
#define PB push_back

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll n; cin >> n;
	ll ans = 1e18;
	for (ll i = 1; i <= sqrt(n); ++i) {
		if (n % i == 0) {
			ll x = i;
			ll y = n / i;
			ans = min(ans, (x - 1) + (y - 1));
		}
	}
	cout << ans; 
}


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

int main(){
  long long n, d;
  int ans = 0;
  cin >> n >> d;
  rep(i, n){
    long long x, y;
    cin >> x >> y;
    if(x*x+y*y<=d*d)ans++;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3628
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = sorted(A)  
max_A = B[N-1]
smax_A = B[N-2]

for i in range(N):
  if A[i] == max_A:
    print(smax_A)
  else:
    print(max_A)

Measured memory_bytes: 14112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int T;
  T = 1;
  while (T--) solve();
}

// https://atcoder.jp/contests/abc167/submissions/13006376
void solve() {
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  cin >> a;

  vector<int> c(n + 1), ord(n + 1, -1); // すでに訪れてたら ord != -1, debuged n to n + 1
  c[0] = 1;
  ord[1] = 0; // debuged
  rep3(i, 1, n + 1) {
    c[i] = a[c[i - 1] - 1];
    if (ord[c[i]] != -1) { // debuged, i to c[i]
      int becy = ord[c[i]]; 
      int cyc = i - ord[c[i]];
      // cout << "b c " << becy << " " << cyc << endl;
      // cout << c << endl << ord << endl;
      if (k <= becy) cout << c[k] << endl;
      else {
        (k = k - becy) %= cyc;
        // cout << k << endl;
        cout << c[becy + k] << endl; // debuged, k to becy + k
      }
      return;
    }
    ord[c[i]] = i;
    // cout << i << " " << c[i] << endl;
  }
}


Measured memory_bytes: 5576
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++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 cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 200005;
const long double epsilon = 1e-9;
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {

	fast
	ll n;
	cin >> n;
	vl a(n + 1);
	ain(a, n);
	a[n] = 0;
	ll ans = 1000;
	vl peak(n, 0);
	ll mn = inf, mx = 0;
	FOR(i, 0, n - 1)
	{
		if (a[i] > a[i + 1])
		{
			peak[i] = 1;
		}
	}
	loop(i, n)
	{
		mn = min(mn, a[i]);
		mx = max(mx, a[i]);
		if (peak[i] == 1)
		{
			if (mn < mx)
			{
				ll st = ans / mn;
				ans -= st * mn;
				ans += st * mx;
			}
			mn = inf , mx = 0;
		}
	}
	cout << ans << END;



// #ifndef ONLINE_JUDGE
// 	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;
class Main{
 public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   String s = sc.next();
   int n = s.length();
   String x , y;
   x = s.substring(0,n/2);
   y = s.substring(n/2+1,n);
   if(x.equals(y)){
     System.out.println("Yes");
   }else{
     System.out.println("No");
   }
 
 }
}

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

ll n,s,b,f;
vector<ll> fc;

int main(){

cin>>n>>s; 

if(n==s){
    cout<<++n<<endl; return 0;
}
if(n<s){
    cout<<-1<<endl; return 0;
}

int N=(int)sqrt(n); 

for(int i=2; i<=N; i++){
    ll m=n; f=0LL;
    while(1){
        f+=m%i;
        m/=i;
        if(m==0) break;
    }
    if(f==s){
        cout<<i<<endl; return 0;
    }
}

ll P=n-s;

for(ll i=1; i<=sqrt(P); i++){
    if(P%i==0){
        if(i<P/i){
        fc.push_back(i);
        fc.push_back(P/i);
        }
        if(i==P/i) fc.push_back(i);
    }
}
sort(fc.begin(),fc.end());

//for(int i=0; i<fc.size(); i++) cout<<fc[i]<<endl;

for(int i=0; i<fc.size(); i++){
    if(fc[i]<=N-1) continue;
    ll m=n;
    ll p=m/(fc[i]+1),q=m%(fc[i]+1);
    if(s==p+q){
        cout<<fc[i]+1<<endl; return 0;
    }
}

cout<<-1<<endl;

return 0;
 
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextDouble()) {
			double d = sc.nextDouble() * (double)211 / (double)27;
			System.out.println(d);
		}
		sc.close();
	}
}

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

struct st {
	int p, d, e;
};
bool operator<(st a, st b) {
	return a.e > b.e;
}
int d[100][101];
int main() {
	int n, m, l;
	while (scanf("%d%d%d", &n, &m, &l), n) {
		vector<st>E[100];
		rep(i, m) {
			int a, b, d, e; scanf("%d%d%d%d", &a, &b, &d, &e); a--; b--;
			E[a].push_back({ b,d,e }); E[b].push_back({ a,d,e });
		}
		priority_queue<st>que;
		memset(d, 0x3f, sizeof(d));
		d[0][l] = 0; que.push({ 0,l,0 });
		while (!que.empty()) {
			st p = que.top(); que.pop();
			if (d[p.p][p.d] != p.e)continue;
			for (st u : E[p.p]) {
				if (p.d >= u.d&&d[u.p][p.d - u.d] > p.e) {
					d[u.p][p.d - u.d] = p.e;
					que.push({ u.p,p.d - u.d,p.e });
				}
				if (d[u.p][p.d] > p.e + u.e) {
					d[u.p][p.d] = p.e + u.e;
					que.push({ u.p,p.d,p.e + u.e });
				}
			}
		}
		int Min = INT_MAX;
		rep(i, l + 1)Min = min(Min, d[n - 1][i]);
		printf("%d\n", Min);
	}
}

Measured memory_bytes: 3580
from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
from math import *
from collections import defaultdict as dd, deque
def data(): return sys.stdin.readline().strip()
def mdata(): return map(int, data().split())
#def print(x): return sys.stdout.write(str(x)+'\n')
#sys.setrecursionlimit(100000)
mod=int(1e9+7)

n,m=mdata()
A=list(mdata())
cnt=0
A.sort(reverse=True)
s=sum(A)/(4*m)
for i in range(m):
    if A[i]>=s:
        cnt+=1
    else:
        break
if cnt==m:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3444
#include <iostream>
using namespace std;
typedef long long ll;
ll n,a,b[200001],c[200001],ans;
int main(void){
    cin>>n;
    for(ll i=1LL;i<=n;i++){
        cin>>a;
        if(1<=i-a)b[i-a]++;
        if(i+a<=n)c[i+a]++;
    }
    for(int i=1;i<=n;i++){
        ans+=b[i]*c[i];
    }
    cout<<ans<<endl;
}


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

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

    int x;cin>>x;

    int ans=0;
    int sum=0;

    for(int i=1;i<=x;i++)
    {
        sum+=i;
        if(sum>=x){ans=i;break;}
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <list>
#include <unordered_map>

using namespace std;
typedef long long ll;


int main(void)
{
    int n,r;
    cin >> n >> r;

    if ( n >= 10)
    {
        cout << r<<endl;
    }else
    {
        cout << r + 100*(10-n)<<endl;
    }
    

    return 0;
}

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

void make_fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

void input_from_file() {
    freopen("input.inp", "r", stdin);
}

typedef long long cc;
const int oo = 1e9;

struct Segment {
    int l, r;
    Segment () {

    }
    Segment (int _l, int _r) {
        l = _l;
        r = _r;
    }
    int len() {
        return max( 0, r - l + 1);
    }
    int with(Segment other) {
        int start = max(l, other.l);
        int end = min(r, other.r);
        return max(0, end - start + 1);
    }
    bool operator < (Segment other) {
//        return len() > other.len();
        return r < other.r;
    }
    void merge(Segment other) {
        l = max(l, other.l);
        r = min(r, other.r);
    }
};

/*
    This is the end of template
*/
//59287301

int n;
vector <Segment> segs, segL, segR;
int res = 0;

void print() {

}

void reset() {

}

void read_inp() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        segs.emplace_back(Segment(l, r));
    }
}

void init() {
    sort(segs.begin(), segs.end());
    segL.resize(n);
    segR.resize(n);
    for (int i = 0; i < n; i++) {
        segL[i] = segs[i];
        if (i > 0) {
            segL[i].merge(segL[i - 1]);
        }
    }
    for (int i = n - 1; i >= 0; i--) {
        segR[i] = segs[i];
        if (i < n - 1) {
            segR[i].merge(segR[i + 1]);
        }
    }
}

void solve() {
    for (int i = 0; i < n - 1; i++) {
        res = max(res, segL[i].len() + segR[i + 1].len());
    }
    for (int i = 0; i < n; i++) {
        Segment segment_left = i > 0 ? segL[i - 1] : Segment(0, oo);
        Segment segment_right = i < n - 1 ? segR[i + 1] : Segment(0, oo);
        int len_two = segment_left.with(segment_right);
        res = max(res, segs[i].len() + len_two);
    }
}

void get_result() {
    cout << res;
}

int main() {
    make_fast_io();
//    input_from_file();
    read_inp();
    init();
    solve();
    get_result();
    return 0;
}


Measured memory_bytes: 2804
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

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

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

int main() {
  int n;
  cin >> n;
  int a[n], b[n], c[n];
  rep(i, n) { cin >> a[i] >> b[i] >> c[i]; }

  int dp[n][3];
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];

  for (int i = 1; i < n; i++) {
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
  }

  cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << endl;

  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
using namespace std;
typedef long long ll;
string S;
int N,Q,K[100];
ll sumd[1000010] = {0},summ[1000010] = {0},sumc[1000010] = {0},sumlmc[1000010] = {0};
int main(){
	cin >> N >> S >> Q;
	for(int i=0;i<Q;i++){
		cin >> K[i];
	}
	ll ans = 0;
	for(int i=1;i<=N;i++){
		sumd[i] = sumd[i-1]+(S[i-1]=='D');
		summ[i] = summ[i-1]+(S[i-1]=='M');
		sumc[i] = sumc[i-1]+(S[i-1]=='C');
	}
	for(int i=N-1;i>=1;i--){
		sumlmc[i] += sumlmc[i+1];
		if(S[i-1]=='M') sumlmc[i] += sumc[N]-sumc[i];
	}
	for(int i=1;i<=N;i++){
		if(S[i-1]=='M'){
			ans += sumd[i-1]*(sumc[N]-sumc[i]);
		}
	}
	for(int j=0;j<Q;j++){
		ll sub = 0;
		for(int i=1;i<=N;i++){
			if(S[i-1]=='D'){
				sub += (summ[min(i+K[j]-1,N)]-summ[i])*(sumc[N]-sumc[min(i+K[j]-1,N)]);
				sub += sumlmc[min(i+K[j],N)];
			}
		}
		cout << ans-sub << endl;
	}
}

Measured memory_bytes: 32644
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int MaxN = 1e5;

int main()
{
	int x,y,a,b;
	while(~scanf("%d %d",&a,&b))
	{
		y = (a + b)%2;
		if(y==0) x = (a+b)/2;
		else x = (a+b)/2+1;
		printf("%d\n",x);
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int[][] bingo = new int[3][3];
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
        bingo[i][j] = sc.nextInt();
      }
    }
    int N = sc.nextInt();
    int[] b = new int[N];
    for(int i=0;i<N;i++){
      b[i] = sc.nextInt();
    }
    
    for(int i=0;i<3;i++){
      if(checkbingo(bingo[i][0],bingo[i][1],bingo[i][2],b,N)){
        System.out.println("Yes");
        return;
      }
    }
    for(int i=0;i<3;i++){
      if(checkbingo(bingo[0][i],bingo[1][i],bingo[2][i],b,N)){
        System.out.println("Yes");
        return;
      }
    }
    
    if(checkbingo(bingo[0][0],bingo[1][1],bingo[2][2],b,N)){
      System.out.println("Yes");
      return;
    }
    
        if(checkbingo(bingo[0][2],bingo[1][1],bingo[2][0],b,N)){
      System.out.println("Yes");
      return;
    }
    
    
    System.out.println("No");
        
    
    
  }
  
  public static boolean check(int[] b,int a,int N){
    for(int i=0;i<N;i++){
      if(b[i] == a){
        return true;
      }
    }
    return false;
  }
      
  public static boolean checkbingo(int x,int y,int z,int[] b,int N){
    if(check(b,x,N) && check(b,y,N) && check(b,z,N))
      return true;
    return false;
  } 
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
    cin>>n;
  	int a[n];
  	for(int i =0;i<n;++i) {
    	cin>>a[i];
  	}
  	int dp[n]={0};
    if(n>1)
  	dp[1] = abs(a[1]-a[0]);
  	for(int i = 2; i < n; ++i) {
    	dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));
    }
  	cout<<dp[n-1];
}

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

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

  int64_t ansA= A;
  int64_t ansB= B;
  if(K < A){
    ansA-= K;
  }
  else if(K < A+B){
    ansA= 0;
    ansB-= K-A;
  }
  else{
    ansA= 0;
    ansB= 0;
  }
  
  cout << ansA <<" "<< ansB << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

	int n = in.nextInt();
	int max = 0;
	int ans = 0;

	for(int cnt = 0; cnt < n; cnt++){
		int a = in.nextInt();
		int b = in.nextInt();
		if(a > max){
			max = a;
			ans = b + a;
		}
	}
	System.out.println(ans);

	}
}

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

using namespace std;

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

    int n = s.size();
    int res = 1<<29; /*とりあえずの大きい数字(2^29) */

    for(int start = 0; start <=1; start++) {
        int val = start; /*startは0か1 */
        int count = 0;
        for(int i = 0; i < n; i++) {
            if(s[i] - '0' != val){
                count++;
            }
            val = 1 - val; /*0と1をスイッチする */
        }
        res = min(res, count); /*回答の更新 */
    }

    cout << res << endl;


    return 0;
}

Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, K) = Slice2<long>();
            var li = Sarray();
            Array.Sort(li);Array.Reverse(li);
            WriteLine(li.Take((int)K).Sum());
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28108