akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
const int mod = 1000000007;

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

    int N;
    while (1)
    {
        cin >> N;
        if (N == 0)
            break;
        bool f[110][110] = {};
        rep(i, N)
        {
            int M;
            cin >> M;
            rep(j, M)
            {
                int p;
                cin >> p;
                p--;
                f[i][p] = true;
            }
        }
        int K;
        cin >> K;
        vector<int> l(K);
        rep(i, K) cin >> l[i], l[i]--;
        int ans = -1;
        rep(i, N)
        {
            bool che = true;
            rep(j, K) if (!f[i][l[j]]) che = false;
            if (che)
            {
                if (ans == -1)
                    ans = i + 1;
                else
                {
                    ans = -1;
                    break;
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3180
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1,Dbg&>::type operator<<(const C &x) {os<<x; return *this;}
template<class C> Dbg &dump(C b, C e) {
    for (struct{C i;int j;} i={(*this<<"\n[",b),0}; i.i!=e and i.j<26; i.i++, i.j++) *this<<", "+2*(i.i==b)<<*i.i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator<<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator<<(const pair<B, C> &x) {return *this<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 300005;

int n, a[mxn], cnt[mxn], sum[mxn];
vector<int> v;

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
/*
Group cards by type.
If we want to take x groups of size K, no single type can contribute more than x. If after that sum is >= x*K, then ok.
*/
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i], ++cnt[a[i]];
    }
    for (int i = 1; i <= n; i++) {
        if (cnt[i]) v.push_back(cnt[i]);
    }

    sort(begin(v), end(v));
    int lst = 0, baki = sz(v);
    for (auto &i : v) {
        for (int j = lst+1; j <= i; j++) {
            sum[j] = sum[lst]+(j-lst)*baki;
        }
        lst = i, --baki;
    }
    for (int i = lst+1; i <= n; i++) {
        sum[i] = sum[lst];
    }
    for (int i = 1; i <= n; i++) {
        int lo = 1, hi = n, ans = 0;
        while (lo<=hi) {
            auto mid = (lo+hi)>>1;
            if (sum[mid] >= mid*ll(i)) ans = mid, lo = mid+1;
            else hi = mid-1;
        }
        cout << ans << '\n';
    }
}

Measured memory_bytes: 5488
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>
#include <map>

using namespace std;
#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define fast_io() ios::sync_with_stdio(false); cin.tie(nullptr)
#define fix(n) fixed << setprecision(n)

#define PI 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;

ll f (ll n){
    if(n % 2 == 0) return n/2;

    return (3 * n) + 1;
}


int main(void){
    fast_io();
    
    ll s;
    cin >> s;
    
    map<ll,bool> is_found;
    ll count = 1;
    while(!is_found[s]){
        is_found[s] = true;
        s = f(s);
        count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3128
// SeeAlso:
// - https://img.atcoder.jp/abc145/editorial.pdf
// - http://drken1215.hatenablog.com/entry/2018/06/08/210000
package main

import (
	"fmt"
)

const MAX = 1000000
const MOD = 1000000007

var fac = make([]int, MAX)
var finv = make([]int, MAX)
var inv = make([]int, MAX)

func knight(x, y int) int {
	// 1回の移動でX座標+Y座標の値は3増える。
	// よって、　X＋Yが3の倍数でない時答えは0
	if (x+y)%3 != 0 {
		return 0
	}
	// 3の倍数のとき、
	//(1,2)の移動の回数をn
	//(2,1)の移動の回数をmとすると
	// n + 2m = X
	// 2n + m = Y
	// が得られる
	m := (2*x - y) / 3
	n := x - 2*m
	return com(n+m, m)
}

// テーブルを作る前処理
func cominit() {
	fac[0] = 1
	fac[1] = 1

	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i := 2; i < MAX; i++ {
		fac[i] = fac[i-1] * i % MOD
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD
		finv[i] = finv[i-1] * inv[i] % MOD
	}
}

// 二項係数計算
func com(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	cominit()
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}

func main() {
	var x, y int
	fmt.Scan(&x, &y)
	fmt.Println(knight(x, y))
}


Measured memory_bytes: 25472
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int a,b;
	cin >> a >> b;
	cout << (a-1)*(b-1) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int a,b;
    string s;
    cin>>s;
    string t;
    cin>>t;
    if(s.size()+1==t.size()){
        rep(i,0,s.size()){
            if(s[i]!=t[i]){
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout<<"Yes"<<endl;
        return 0;
    }
                cout<<"No"<<endl;
    return 0;
}




Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define ll long long

int main(void){
    pair<string, int> ball1, ball2;

    cin >> ball1.first >> ball2.first;
    cin >> ball1.second >> ball2.second;

    string u;
    cin >> u;

    if(ball1.first == u){
        ball1.second--;
    }else if(ball2.first == u){
        ball2.second--;
    }

    cout << ball1.second << " " << ball2.second << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  int A,B;
  cin>>A>>B;
  if(A<=9&&B<=9) cout<<A*B<<endl;
  else cout<<-1<<endl;

  return 0;
}


Measured memory_bytes: 256
let num = readLine()!.map({$0})
    var r: Int = 0
    
    for i in 0 ..< num.count {
      
      if num[i] == "7" {
        r += 1
      }
    }
    
    if r >= 1 {
      
      print("Yes")
    } else {
      print("No")
    }

Measured memory_bytes: 7712
import math
import sys
import bisect
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    stList = [list(map(str, readline().rstrip().split())) for _ in range(n)]
    x = readline().rstrip()
    sumT = 0
    flg = False

    for i in range(n):
        s, t = stList[i][0], int(stList[i][1])
        if flg != True:
            if s == x:
                flg = True
                continue
        if flg == False:
            continue
        sumT += t
    print(sumT)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
//by achhhy
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
inline int in()
{
	char ch=getchar();
	int f=1,x=0;
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return f*x;
}
//need changing
const int inf=(1<<30);
const int mod=1e9+7;
const int N=200010;

int n,m;
int a[N],s[N],x[N];

int main()
{
	n=in();
	LL ans=0;
	rep(i,1,n) a[i]=in();
	rep(i,1,n) s[i]=s[i-1]+a[i],x[i]=x[i-1]^a[i];
	int l=1,r=1;
	while(l<=n)
	{
		while(r<=n&&(s[r]-s[l-1])==(x[r]^x[l-1])) r++;
		ans+=r-l;
		l++;
	}
	cout<<ans<<endl;
	return 0;
}




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

int main() {
  string s;
  cin >> s;
  int m = stoi(s.substr(5,2));
  if (m <= 4) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
  return 0;
}


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

vector<int> v(100000 + 1, 0);

int res(int index, int K) {
  if (index >= K) return 0;
  if (v.at(index) > 0) return v.at(index);
  v.at(index) = res(index * 2, K) + 1;
  return v.at(index);
}

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

  for (int i = 1; i <= N; i++) {
    res(i, K);
  }

  double p = 0.0;
  for (int i = 1; i <= N; i++) {
    p += (1.0 / N) * (1.0 / (1 << v.at(i)));
  }

  cout << setprecision(12);
  cout << p << endl;
}
/* 3 10 */

 


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

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;
}

int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll b_down = b - b/c - b/d + b/lcm(c,d);
    ll a_1_up  = (a-1) - (a-1)/c - (a-1)/d + (a-1)/lcm(c,d);
    cout << b_down - a_1_up << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

using namespace std;

int main() {
  string signals[] = {
    "0111111",
    "0000110",
    "1011011",
    "1001111",
    "1100110",
    "1101101",
    "1111101",
    "0100111",
    "1111111",
    "1101111"
  };
  while (true) {
    int n, k;
    string cur(7, '0');
    cin >> n;
    if (n < 0) {
      return 0;
    }
    for (int i = 0; i < n; ++i) {
      cin >> k;
      for (int j = 0; j < 7; ++j) {
        cout << (cur[j] == signals[k][j]? '0': '1');
      }
      cout << endl;
      cur = signals[k];
    }
  }
}

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

using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll int 
#define pb push_back
#define pll pair<ll,ll>
#define ff first
#define ss second
#define N 2000001
#define M 1000000007
#define INF 1000000000000000
ll Arr[200001],size1[200001];


ll gcd(ll a,ll b)
{
      if (b == 0) 
        return a; 
    return gcd(b, a % b);
}
int main()
{
  ll n;
  cin>>n;
  ll a[n];
  cin>>a[0];
  ll i,j,k,gcdo=a[0];
  //cout<<"RR"<<endl;
  unordered_map<ll,ll> mp;
  mp[a[0]]++;
  for(i=1;i<n;i++){cin>>a[i];mp[a[i]]++;gcdo=gcd(gcdo,a[i]);}
  //cout<<"RR"<<endl;
  if(gcdo>1)
  {
      cout<<"not coprime";
  }
  else
  {
      //cout<<"RR"<<endl;
      ll prime[1000001]={0},flag=0,flag1=0;
      for(i=2;i<1000001;i++)
      {
          if(!prime[i])
          {
              for(j=i;j<1000001;j+=i)
                {
                 //   cout<<j<<" ";
                
                    if(mp[j]>=1){flag+=mp[j];}
                    prime[j]=1;
                }
               // cout<<endl;
                if(flag>1)flag1=1;
                flag=0;
          }
      }
      if(flag1==1)
      {
          cout<<"setwise coprime";
      }
      else
      cout<<"pairwise coprime";
  }
  
  

   
    
}

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

int main() {
	int N;
	cin >> N;
  vector<double> v(N);
  rep(i,N) cin >> v[i];

  sort(all(v));

  double ans = v[0];
  for(int i = 1;i<N;i++){
    ans = (v[i] + ans)/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def dfs(v):
    visited[v] = True
    for v2 in range(n):
        if G[v][v2]==1 and visited[v2]==False:
            dfs(v2)
    

n, m = map(int, input().split())
a = [0]*m
b = [0]*m
G = [[0]*n for _ in range(n)]
visited = [False]*n

for i in range(m):
    a[i], b[i] = map(int, input().split())
    a[i] -= 1
    b[i] -= 1
    G[a[i]][b[i]] = G[b[i]][a[i]] = 1

cnt = 0
for i in range(m):
    G[a[i]][b[i]] = G[b[i]][a[i]] = 0
    for j in range(n):
        visited[j] = False
    
    dfs(0)

    if False in visited:
        cnt += 1

    G[a[i]][b[i]] = G[b[i]][a[i]] = 1

print(cnt)

Measured memory_bytes: 3064
#include<stdio.h>
#define SIZE 1000000

int linearSearch(int s[],int n,int t){
  int i;
  i=0;
  s[n]=t;
  while(s[i]!=t){
    i++;
  }
    if(i==n){
      return 0;
    }
    else {
      return 1;
    }
}
  

int main(){
  int n,i,q,t,s[SIZE],c,count=0;;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&t);
    c=linearSearch(s,n,t);
    if(c==1){
      count++;
    }
  }

  printf("%d\n",count);


  return 0;
}


    
  



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll a[100010], b[100010];
int main(){
    ll n;
    while(cin>>n){
        ll ans=0;
        vector<pair<ll, ll>> v1, v2;
        set<ll> s;
        multiset<ll> ms;
//        set<ll> st;
//        map<ll, ll> mp;
//        int cnt=0;
        for(ll i=0; i<n; ++i){
            scanf("%lld%lld",a+i,b+i);
            v1.push_back(mk(a[i], i));
            v2.push_back(mk(b[i], i));
            s.insert(i);
            ms.insert(a[i]-b[i]-1);
//            st.insert(a[i]);
//            st.insert(b[i]);
        }
//        for(auto it:st){
//            mp[it]=cnt++;
//        }
//        for(int i=0; i<n; ++i){
//            cout<<mp[a[i]]<<" "<<mp[b[i]]<<endl;
//            a[i]=mp[a[i]];
//            b[i]=mp[b[i]];
//            v1.push_back(mk(a[i], i));
//            v2.push_back(mk(b[i], i));
//            s.insert(i);
//            ms.insert(a[i]-b[i]-1);
//        }
        sort(v1.begin(), v1.end());
        sort(v2.begin(), v2.end());
        reverse(v2.begin(), v2.end());
        ll tmp=v1.back().sc, tmp1, tmp2;
        for(ll i=0; i<v2.size(); ++i){
            if(v2[i].fs<a[tmp])
                break;
            tmp1=i;
        }
        for(ll i=0; i<n; ++i){
            if(a[i]<=a[tmp]&&b[i]>=v2[tmp1].fs){
                s.erase(i);
            }
        }
        ll mn=0, mx=1e9+10;
        for(auto it:s){
            mx=min(mx, b[it]);
            mn=max(mn, a[it]);
        }
        if(s.empty()){
            tmp2=v2[tmp1].fs-a[tmp]+1;
            tmp2=-tmp2;
            if(tmp2==*ms.begin() && v2[tmp2].sc==tmp){
                ans=-tmp2-(*++ms.begin());
            }
            else{
                ans=-tmp2-*ms.begin();
            }
        }
        else{
            ans=v2[tmp1].fs-a[tmp]+1+max(0ll, (mx-mn+1));
//            cout<<ans<<endl;
        }
        ans=max(ans, -*ms.begin());
//        cout<<mx<<" "<<mn<<endl;cout<<ans<<endl;
        for(ll i=tmp1-1; i>=0; --i){
            tmp2=v2[i+1].sc;
            mx=min(mx, b[tmp2]);
            mn=max(mn, a[tmp2]);

//            cout<<mx<<" "<<mn<<endl;
            ans=max(ans, v2[i].fs-a[tmp]+1+max(0ll, (mx-mn+1)));
        }
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 15328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n), b(m);
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, m) cin >> b[i];
    vector<ll> suma(n + 1, 0), sumb(m + 1, 0);
    rep(i, 0, n) suma[i + 1] = suma[i] + a[i];
    rep(i, 0, m) sumb[i + 1] = sumb[i] + b[i];
    ll ans = 0;
    rep(i, 0, n + 1) {
        ll tmp = k - suma[i];
        if (tmp < 0) continue;
        ll p = upper_bound(all(sumb), tmp) - sumb.begin() - 1;
        ans = max(ans, i + p);
    }
    cout << ans << endl;
    return 0;
}


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

const int INF = 1001001001;

int main(){
  ll n;
  cin >> n;
  ll maxl = 0,minr = 10e9,distmax = 0,case1 = 0,case2 = 0;
  vector<pair<ll,ll>> lr;
  for(int i=0;i<n;i++){
    ll l; cin >> l;
    ll r; cin >> r;
    maxl = max(l,maxl);
    minr = min(r,minr);
    lr.push_back(make_pair(l,r));
    distmax = max(distmax,r-l);
  }

  //右端が一番左側にあるpairと左端が一番右がわにあるpairを同じ集合に含む
  case1 = max(minr - maxl + 1 + distmax + 1,distmax+1);

  //別々の集合に含まれる
  {
    for(int i=0;i<n;i++){
      lr.at(i).first = max(minr-lr.at(i).first + 1,0ll);
      lr.at(i).second = max(lr.at(i).second-maxl + 1,0ll);
      lr.at(i).second *= -1;
    }
    sort(lr.begin(),lr.end());
    for(int i=0;i<n;i++){
      lr.at(i).second *= -1;
    }
    ll mina = INF,minb = INF;
    for(int i=0;i<n-1;i++){
      mina = lr.at(i+1).first;
      minb = min(minb,lr.at(i).second);
      case2 = max(case2,mina + minb);
    }
  }
  cout << max(case1,case2) << endl;
}

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

int main() {
	string S,T;
	int difmin=753;
	cin >> S;
	for (int i = 0; i < S.size() - 2; i++) {
		T = S.substr(i, 3);
		int X = stoi(T);
		int dif = abs(753 - X);
		if (difmin >= dif) {
			difmin = dif;
		}
	}
	cout << difmin << endl;
}


Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

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

	double r;
	cin >> r;
	double area = r * r * M_PI;
	double circumference = r * 2 * M_PI;
	cout << PREC(6) << area << " " << circumference << endl;
}


Measured memory_bytes: 3248
#include<stdio.h>

int main(){
	int a[4];
	int b[4];
	int s=0,t=0;
	scanf("%d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3]);
	for(int i=0;i<4;i++){
		s+=a[i];
		t+=b[i];
	}
	if(s>=t){
		printf("%d\n",s);
	}else{
		printf("%d\n",t);
	}
}

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

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> t) {
  if(t.size() == n+1) {
    int p = 0;
    rep(i, q) {
      if(t[b[i]] - t[a[i]] == c[i]) p += d[i];
    }
    ans = max(ans, p);
    return;
  }
  
  t.push_back(t.back());
  while(t.back() <= m) {
    dfs(t);
    ++t.back();
  }
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];
  dfs(vector<int>(1, 1));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <stack>
using namespace std;

typedef long long ll;

// dp[a][b]ÉÍfrom a to bÌ¶ððÍµ½Æ«A½¶Ì¶ªoÄ­é©ðL^µÄ¨­
ll dp[101][101];

ll cp=-1;
ll idx;
char result=0;
bool fin=false;

// ðÍµÈªçJEgµÄ¢­
int dfs(const string str,const int from,const int to){
	string res;
	ll pos=0;
	ll resCnt=0;
	while(1){
		ll initPos=pos;
		if(pos>=str.size())
			break;
		if(str[pos]>='0'&&str[pos]<='9'){
			for(ll i=pos+1; ; i++){
				if(!(str[i]>='0'&&str[i]<='9')){
					pos=i;
					break;
				}
			}
			ll cnt=atoi(str.substr(initPos,pos-initPos).c_str());
			if(str[pos]=='('){
				stack<ll> s;
				s.push(0);
				ll start=pos;
				while(1){
					pos++;
					if(str[pos]=='(')
						s.push(0);
					else if(str[pos]==')')
						s.pop();
					if(s.size()==0)
						break;
				}
				string subs=str.substr(start+1,pos-start-1);
				for(int i = 0; i < cnt; i++){
					//if(dp[start+1][pos-1]!=-1){
					//	ll sum=cp+dp[start+1][pos-1];
					//	if(sum<idx){
					//		cp=sum;
					//		resCnt+=dp[start+1][pos-1];
					//		continue;
					//	}
					//}
					resCnt+=dfs(subs,start+1,pos-1);
					if(result!=0||fin)
						return 0;
				}
				pos++;
			}
			// ¶Ìê
			else{
				for(int i = 0;i < cnt; i++){
					cp++;
					if(cp>idx){
						fin=true;
						return 0;
					}
					if(cp==idx){
						result=str[pos];
						return 0;
					}
				}
				resCnt+=cnt;
				pos++;
			}
		}
		else{
			for(ll i = initPos; ; i++){
				if(i>=str.size()){
					pos=i+1;
					break;
				}
				else if(!(str[i]>='A'&&str[i]<='Z')){
					pos=i;
					break;
				}
				else{
					resCnt++;
					cp++;
					if(cp>idx){
						fin=true;
						return 0;
					}
					if(cp==idx){
						result=str[i];
						return 0;
					}
				}
			}
		}
	}
	dp[from][to]=resCnt;
	return resCnt;
}

int main(){
	string str;
	while(cin>>str>>idx&&!(str=="0"&&idx==0)){
		for(int i = 0; i < 101; i++)
			for(int j = 0; j < 101; j++)
				dp[i][j]=-1;
		fin=false;
		cp=-1;
		result=0;
		dfs(str,0,str.size()-1);
		if(result==0)
			cout<<0<<endl;
		else
			cout<<result<<endl;
	}
	return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

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

  double L;
  cin >> L;

  double a = L / 3.0;

  double ans = a * a * a;
  Decimal(ans);

  return 0;
};


Measured memory_bytes: 256
A,B,C,X,Y = map(int,(input().split()))
if A+B <= C*2:
    print(A*X + B*Y)
else:
    m = min(X,Y)
    M = max(X,Y)
    r = M-m
    cost = C*m*2
    
    if X > Y:
        cost += min(A*r,C*r*2)
    elif X < Y:
        cost += min(B*r,C*r*2)
    
    print(cost)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int n;
long long x[100001],a,b;
int main(){
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	  cin>>x[i];
	long long ans=0;
	for(int i=2;i<=n;i++)
	  if((x[i]-x[i-1])*a>b) ans+=b;
	  else ans+=(x[i]-x[i-1])*a;
	cout<<ans;
}

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

int main(){
    string s;
    while(getline(cin, s)){
        if(s == "END OF INPUT") break;
        int cnt = 0;
        for(int i = 0; i < s.length(); i++){
            if(s[i] != ' ') cnt++;
            else            cout << cnt, cnt = 0;
        }
        cout << cnt << endl;
    }   
    return 0; 
}


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

template <class T>
inline void read(T &res)
{
	char ch;
	while (ch = getchar(), !isdigit(ch));
	res = ch ^ 48;
	while (ch = getchar(), isdigit(ch))
		res = res * 10 + ch - 48;
}

template <class T>
inline T Max(T x, T y) {return x > y ? x : y;}
template <class T>
inline T Min(T x, T y) {return x < y ? x : y;}

using std::vector;
const int N = 2e5 + 5;
int a[N], n;

struct seg
{
	int l, r;

	seg() {}
	seg(int L, int R):
		l(L), r(R) {}

	inline bool Empty()
	{
		return l > r;
	}

	inline seg operator & (const seg &a) 
	{
		return seg(Max(l, a.l), Min(r, a.r)); 
	}

	inline seg operator ^ (const seg &a)
	{
		return a.l == l ? seg(a.r + 1, r) : seg(l, a.l - 1);
	}
};

struct node
{
	seg a;
	int v;

	node() {}
	node(seg A, int V):
		a(A), v(V) {}

	inline bool operator < (const node &a) const
	{
		return v < a.v;
	}
};

vector<node> now, nxt, cur;

int main()
{
	read(n);
	for (int i = 1; i <= n; ++i)
		read(a[i]);
	now.push_back(node(seg(0, 0), 0));
	for (int i = 1; i <= n + 1; ++i)
	{
		int det = a[i] - a[i - 1];
		seg lim = seg(0, a[i]), tmp;

		cur.clear();
		for (node x : now)
		{
			tmp = seg(0, Min(det + x.a.r - 1, x.a.r - 1)) & lim;
			if (!tmp.Empty())
				cur.push_back(node(tmp, x.v + 2));
			tmp = seg(det + x.a.l, x.a.r - 1) & lim;
			if (!tmp.Empty())
				cur.push_back(node(tmp, x.v + 1));
			tmp = seg(x.a.l, det + x.a.r - 1) & lim;
			if (!tmp.Empty())
				cur.push_back(node(tmp, x.v + 1));
			tmp = seg(Max(x.a.l, det + x.a.l), a[i]) & lim; 
			if (!tmp.Empty())
				cur.push_back(node(tmp, x.v));
		}
		std::sort(cur.begin(), cur.end());
		now.clear();
		for (node x : cur)
		{
			seg res = x.a;
			for (node y : now)
			{
				tmp = res & y.a;
				if (!tmp.Empty())
					res = res ^ tmp;
				if (res.Empty())
					break ;
			}
			if (!res.Empty())
				now.push_back(node(res, x.v));
		}
	}
	printf("%d\n", now[0].v);
	return 0;
}

Measured memory_bytes: 1024
import math
A,B,H,M = map(int,input().split())
r = 30*H+M/2-6*M
if r >= 180:
    r = 360 - r
c = math.cos(math.radians(r))
l = math.sqrt(A*A+B*B-2*A*B*c)
print(l)

Measured memory_bytes: 9432
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
use std::collections::{HashMap, HashSet};
fn main() {
    let n: usize = read();
    let a: Vec<i32> = read_vec();
    let mut l = HashMap::with_capacity(n);
    let mut r = HashMap::with_capacity(n);
    let mut x = HashSet::with_capacity(n);
    for i in 0..n {
        let t = vec![i as i32 + 1 + a[i], i as i32 + 1 - a[i]];
        *l.entry(t[0]).or_insert(0) += 1;
        *r.entry(t[1]).or_insert(0) += 1;
        x.insert(t[0]);
        x.insert(t[1]);
    }
    let mut ans: i64 = 0;
    for i in x {
        if l.contains_key(&i) && r.contains_key(&i) {
            ans += l[&i] * r[&i];
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 15284
#include <iostream>
using namespace std;
int main(){
  int n,a,b,c,d[2];
  cin >> a >> b >> c;
  d[0]=b-a;d[1]=c-a;
  for(int i=1;i<3;i++){
    cin >> a >> b >> c;
    if(d[0]!=b-a || d[1]!=c-a){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int minDist(const vector<vector<int> >& plane, char road, int y1, int x1, int y2, int x2)
{
    int dy[] = {0, 0, -1, 1};
    int dx[] = {-1, 1, 0, 0};

    int h = plane.size();
    int w = plane[0].size();

    queue<pair<int, int> > q;
    vector<vector<bool> > check(h, vector<bool>(w, false));
    q.push(make_pair(y1, x1));
    check[y1][x1] = true;
    int ret = 0;
    while(!q.empty()){
        queue<pair<int, int> > q1;
        while(!q.empty()){
            int y = q.front().first;
            int x = q.front().second;
            q.pop();
            if(y == y2 && x == x2)
                return ret;
            for(int i=0; i<4; ++i){
                int y0 = y + dy[i];
                int x0 = x + dx[i];
                if(0 <= y0 && y0 < h && 0 <= x0 && x0 < w && plane[y0][x0] == road && !check[y0][x0]){
                    q1.push(make_pair(y0, x0));
                    check[y0][x0] = true;
                }
            }
        }
        ++ ret;
        q = q1;
    }
    return -1;
}

int main()
{
    for(;;){
        int w, h;
        cin >> w >> h;
        if(w == 0)
            return 0;

        int xs, ys, xg, yg;
        cin >> xs >> ys >> xg >> yg;

        int n;
        cin >> n;
        vector<vector<int> > grid(h+2, vector<int>(w+2, 0));
        for(int i=0; i<n; ++i){
            int c, d, x, y;
            cin >> c >> d >> x >> y;
            if(d == 0){
                for(int j=0; j<2; ++j){
                    for(int k=0; k<4; ++k){
                        grid[y+j][x+k] = c;
                    }
                }
            }else{
                for(int j=0; j<4; ++j){
                    for(int k=0; k<2; ++k){
                        grid[y+j][x+k] = c;
                    }
                }
            }
        }

        if(grid[ys][xs] != grid[yg][xg] || grid[ys][xs] == 0)
            cout << "NG" << endl;
        else if(minDist(grid, grid[ys][xs], ys, xs, yg, xg) == -1)
            cout << "NG" << endl;
        else
            cout << "OK" << endl;
    }
}

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

A = sorted(A)

ans = 0

for a in A:
    x -= a
    ans += 1
    if x < 0:
        ans -= 1
        break
    if x == 0:
        break
if x > 0:
    ans -= 1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll n,k;
	cin>>n>>k;
	cout<<min(n%k,k-n%k)<<'\n';
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n; string s;
    cin >> n; 
        cin >> s;
    auto curr = s[0];
    int ans = 1;
    for (auto c : s)
    {
        if (c != curr)
        {
            curr = c;
            ans++;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 3720
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
  tmp0 = input[0].split(" ");
  T = tmp0[0]
  X = tmp0[1]

  console.log(T/X)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod
 
 
 
signed main(){
 
    int N; cin >> N;
    vec d(N); cin >> d;
    int ans = 0;
    REP(i, N) REP(j, i) ans += d[i] * d[j];
    Out(ans);
 
    return 0;
}

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

#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define MOD 1000000007
#define INF 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y) 
#define mem(a,val) memset(a,val,sizeof(a))
#define f first
#define s second
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll h;
	cin>>h;
	ll sum=0;
	ll j=1;
	while(h>0){
		h/=2;
		sum+=j;
		j*=2;
	}
	cout<<sum;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

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

Measured memory_bytes: 256
k = int(input())
given_list = [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]
print(given_list[k - 1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;;

  if (a+b < 2*c) {
    cout << x*a + y*b<< endl;
  } else {
    if (x==y){
      cout << 2*c*x << endl;
    } else if(x < y){
      int total = 0;
      total = 2*c*x;
      int diff = y - x;
      total += min(diff*b, diff*c*2);
      cout << total << endl;
    } else {
      int total = 0;
      total = 2*c*y;
      int diff = x - y;
      total += min(diff*a, diff*c*2);
      cout << total << endl;
    }
  }
}

Measured memory_bytes: 3496
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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 H, N;

	cin >> H >> N;

	int sum = 0;

	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;

		sum += tmp;
	}

	yn(H <= sum);

	return 0;
}

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

int main()  
{   
    cin.tie(0); ios::sync_with_stdio(false);  
	//freopen("input.txt", "rt", stdin);
	int n; cin >> n;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a+n);
	int ans = 0, i;
	for (i = 0; i < n-1; i++)
		ans += a[i];
	ans += a[i]/2;
	cout << ans << "\n";

	return 0;   
}  


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

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

  int n, m;
  cin >> n >> m;
  priority_queue <int> pq;
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    pq.push(x);
  }
  while(m > 0 && pq.top() > 0){
    int tp = pq.top();
    pq.pop();
    pq.push(tp / 2);
    m--;
  }
  ll ans = 0;
  while(pq.size()){
    ans += pq.top();
    pq.pop();
  }
  cout << ans;
}

Measured memory_bytes: 892
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n, k;
	vector<int> vec;
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		int j;
		cin >> j;
		vec.push_back(j);
	}
	sort(vec.begin(), vec.end());
	int a = 0;
	for (int i = 0; i < n; ++i) {
		if (i <= n - k - 1) {
			continue;
		}
		a = a + vec[i];
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main(int argc, char* argv[]) {
  double N, K;
  cin >> N >> K;

  double ret = 0;
  for (double i = 1; i <= N; ++i) {
    int c = 0;
    double cur = i;
    while (true) {
      if (cur >= K)
        break;
      cur *= 2;
      ++c;
    }
    ret += (1 / N) * pow(0.5, c);
  }

  cout << std::fixed << std::setprecision(15) <<  ret << endl;

  return 0;
}

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

using namespace std;

typedef long long ll;

ll counter[100001] = {0};

int main()
{
    int n;

    cin >> n;

    int arr[n];
    ll sum = 0;

    for(ll i = 0; i < n; i++)
    {
        cin >> arr[i];
        sum += arr[i];
        counter[arr[i]]++;
    }

    int q;

    cin >> q;

    for(ll i = 0; i < q; i++)
    {
        ll b, c;

        cin >> b >> c;

        sum = sum - counter[b] * b + counter[b] * c;
        counter[c] += counter[b];
        counter[b] = 0;

        cout << sum << endl;
    }
}


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

int n;
ll ttt, ans;

int main() {
  int t;
  cin >> n;
  vector<int> spf(n+1);
  rep(i, n+1) spf[i] = i;
  for (int i = 2; i * i <= n; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j <= n; j += i) {
        if (spf[j] == j) {
          spf[j] = i;
        }
      }
    }
  }
  ans = 0;
  map<int, int> m;
  for (int c = 1; c < n; c++) {
    t = n-c;
    m.clear();
    while (t != 1) {
      if (m.find(spf[t]) == m.end()) m[spf[t]] = 1;
      else m[spf[t]]++;
      t /= spf[t];
    }
    ttt = 1;
    for (auto itr = m.begin(); itr != m.end(); ++itr) {
      ttt *= ((itr->second)+1);
    }
    ans += ttt;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7144
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int n;
    long long int res = 1;

    cin >> n;

    for (int i = 1; i <= n; i++) {
        res *= i;
        res %= 1000000007l;
    }

    cout << res << endl;

}



Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string.h>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <math.h>
#include <assert.h>
#define ff first
#define ss second
#define ll long long
#define mod 998244353
using namespace std;
int a, b, c, k;
int main () {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>a>>b>>c>>k;
    if(a >= k)
        cout<<k;
    else {
        int dif = max(0, k - a - b);
        a -= dif;
        cout<<a;
    }
}
/*
 2
 1 1
 1 0
 1 1
 1 1
 */


Measured memory_bytes: 3656
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  int a,b,c;
  C3(a,b,c);
  int aa=a;
  rep(i,0,b+1){
    if(a % b == c){
      YES;
      ret 0;
    }
    a += aa;
  }
  NO;
  ret 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 100001
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int solve(int n, int a, int b){
	int tmp = n, ans = 0;
	while(tmp != 0){
		ans += (tmp%10);
		tmp /= 10;
	}
	//cout << ans << " ";
	if(a <= ans && ans <= b)return n;
	else return 0;
}

int main(){
	int n, a, b, ans = 0;
	cin >> n >> a >> b;
	for(int i = 1;i <= n;i++){
		ans += solve(i, a, b);
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;

class Program
{

	//numC2を計算する関数
	static long Combi(long num){
			if(num < 2){
					return 0;
			}else{
					return num * (num-1) / 2;
			}
	}

	//Main
	static void Main(string[] args)
	{
		//読み込む
		long N = long.Parse(Console.ReadLine());
		Dictionary<long, long> combiTable = new Dictionary<long, long>();
		long[] An = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

		//バケツを用意
		long[] bucket = new long[N];
		for(long i=0; i<N; i++){
				//バケツに追加
				bucket[An[i]-1] ++;
		}

		//全て揃っているときの場合の数を格納する配列
		long[] combiFull = new long[N];
		//一つ足りないときの場合の数を格納する配列
		long[] combiMin = new long[N];

		//上記2つの配列を埋める
		for(long i=0; i<N; i++){
				combiFull[i] = Combi(bucket[i]);
				combiMin[i] = Combi(bucket[i] - 1);
		}

		//合計値を出しておく
		long fullSum = combiFull.Sum();

		//各玉が抜かれたときの、場合の数の合計を、ディクショナリに追加
		//iは抜かれた玉の番号（i+1の整数が書かれた玉が抜かれる）
		for(long i=0; i<N; i++){
				long sum = fullSum - combiFull[i];
				sum += combiMin[i];

				//ディクショナリに追加
				combiTable.Add(i+1, sum);
		}

		//それぞれの玉につき、ループ処理
		for(long i=0; i<N; i++){
				long ball = An[i];
				long answer = combiTable[ball];
				Console.WriteLine(answer);
		}
	}
}



Measured memory_bytes: 50140