akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#define fast                     ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int                      long long 
#define pb                       push_back
#define pii                      pair<int,int>
#define vi                       vector<int>
#define vii                      vector<pii>
#define mi                       map<int,int>
#define mii                      map<pii,int>
#define all(a)                   (a).begin(),(a).end()
#define F                        first
#define S                        second
#define sz(x)                    (int)x.size()
#define endl                     '\n'
#define MOD                      1000000007
#define loop(i,a,b)              for(int (i)=(a);(i)<(b);(i)++)
#define rloop(i,a,b)             for(int (i)=(a);(i)>=(b);(i)--)
#define Unique(A)                (A).resize(distance((A).begin(),unique(all((A)))))
#define MXe(A)                   *max_element(all(A))
#define MNe(A)                   *min_element(all(A))
#define SP(val,precision)        fixed << setprecision((precision)) << (val)
#define setBits(x)               __builtin_popcountll(x)
#define zroBits(x)               __builtin_ctzll(x)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define mem(name,val)            memset(name,val,sizeof(name))
#define traceA(A,x)              cerr<<#A<<": ";loop(i,0,x)cerr<<A[i]<<' ';cerr<<endl
#define traceV(A)                cerr<<#A<<": ";for(auto i:A)cerr<<i<<' ';cerr<<endl
#define maxheap                  priority_queue<int>
#define minheap                  priority_queue<int,vector<int>,greater<int>>

using namespace std;

const int N = 2e5+77;
int A[N];
string s, a;
int32_t main(){
    int n ; cin >> n ;
    cin >> s;
    a = s;
    sort(all(s));
    int c = 0;
    loop(i,0,n){
        if(a[i]!=s[i])c++;
    }
    cout << c/2 << endl;
    return 0;
}

Measured memory_bytes: 3852
#include <algorithm>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <ctime>
using namespace std;

#ifdef __APPLE__
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...)
#endif

const int N = (int)1e6 + 123;
const int MOD = (int)1e9 + 7;
const int inf = (int)5e8;
const long long infll = (long long)1e17;

int base = 255;

int add(int a, int b) {
    long long r = a * 1ll + b;
    return (r % MOD + MOD) % MOD;
}

int mul(int a, int b) {
    return (a * 1ll * b) % MOD;
}

int get_hash(const string& s) {
    int res = 0;
    for (auto c : s) {
        res = add(mul(res, base), c);
    }
    return res;
}

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;

    map<pair<int, int>, int> cnt;
    for (int mask = 0; mask < (1 << n); ++mask) {
        int h[2] = {0, 0};
        for (int i = 0; i < n; ++i) {
            int t = (mask & (1 << i)) > 0;
            h[t] = add(mul(h[t], base), s[n + i]);
        }
        ++cnt[{h[0], h[1]}];
    }

    long long ans = 0;
    for (int mask = 0; mask < (1 << n); ++mask) {
        int h[2] = {0, 0};
        for (int i = n - 1; i >= 0; --i) {
            int t = (mask & (1 << i)) > 0;
            h[t] = add(mul(h[t], base), s[i]);
        }
        ans += cnt[{h[1], h[0]}];
    }

    printf("%lld\n", ans);
}

int main() {
#ifdef __APPLE__
#endif
    srand(time(0));
    base += rand() % 255;
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}



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

int n,a[1000005],cnt[1000005],cnt2[1000005]; 
bool can[1000005];
inline int read(){
	int s=0,w=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*w;
}

int main()
{
	n=read();
	for(register int i=1;i<=n;i++)
		a[i]=read(),can[i]=cnt2[a[i]]==0,cnt2[a[i]]++;
	for(register int i=1;i<=n;i++)
		if(can[i])
			for(register int j=1;j*j<=a[i];j++)
				if(a[i]%j==0)
				{
					int num1=j,num2=a[i]/j,num3=cnt2[a[i]];
					cnt[num1]+=num3,cnt[num2]+=num3;
					if(num1==num2) cnt[num1]-=num3;
				}
	bool f=true;
	for(register int i=2;i<=1000000;i++)
	{
		if(cnt[i]==n)
		{
			printf("not coprime\n");
			return 0;
		}
		f&=(cnt[i]==1||cnt[i]==0);
	}
	if(f) printf("pairwise coprime\n");
	else printf("setwise coprime\n"); 
	return 0;
}

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

#define trav(a, A) for (auto & a : A)
#define f first
#define s second

typedef long long ll;

ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;

#define fits(i, j, n, m) \
	(0 <= (i) && (i) < (n) && 0 <= (j) && (j) < (m))

int main ()
{
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	ll i, j, n, m, cn, cm, dn, dm;
	cin >> n >> m >> cn >> cm >> dn >> dm;
	--cn, --cm, --dn, --dm;
	vector <string> inp (n);
	vector <vector <ll>> cost (n, vector <ll> (m, INF));
	trav (s, inp) cin >> s;
	set <pair <ll, ll>> bfs;
	cost[cn][cm] = 0, bfs.insert ({cn, cm});
	vector <pair <ll, ll>> jump, adj = {
		{-1, 0},
		{1, 0},
		{0, -1},
		{0, 1}
	};
	for (i = -2; i < 3; ++i)
		for (j = -2; j < 3; ++j)
			if ((i || j) && find (adj.begin (), adj.end (),
					make_pair (i, j)) == adj.end ())
				jump.push_back ({i, j});
	while (!bfs.empty ())
	{
		auto c = *bfs.begin ();
		bfs.erase (bfs.begin ());
		bool search = false;
		for (auto p : adj)
		{
			i = c.f + p.f;
			j = c.s + p.s;
			if (fits (i, j, n, m) && inp[i][j] == '.' &&
					cost[i][j] > cost[c.f][c.s])
				cost[i][j] = cost[c.f][c.s], bfs.insert ({i, j});
			if (fits (i, j, n, m) && inp[i][j] == '#') search = true;
		}
		if (search)
			for (auto p : jump)
			{
				i = c.f + p.f;
				j = c.s + p.s;
				if (fits (i, j, n, m) && inp[i][j] == '.' &&
						cost[i][j] > cost[c.f][c.s] + 1)
					cost[i][j] = cost[c.f][c.s] + 1, bfs.insert ({i, j});
			}
	}
	if (cost[dn][dm] >= INF/2) cout << "-1\n";
	else cout << cost[dn][dm] << '\n';

	return 0;
}



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

using namespace std;

typedef long long ll; 
const int maxs = 2000001;

// int main(){

//    ll t, i, j, a, b, c, f, s, k, l, resa, resb, resc;

//    cin>>t;

//    while(t--){
//         cin>>a>>b>>c;
//         ll res = 1000000;
//         for(i = 1;i <= b;i++){
//             for(j = 1;j <= min(a, i);j++){
//                  s = i;
//                  f = j;
//                //  cout<<f<<" "<<s<<"\n";
//                  if(s%f!=0){
//                      continue;
//                  }
//                  else{
//                    k = s;
//                    while(k <= c){
//                        k += s;
//                    }
//                    if(k != c)
//                      k -= s;
//                    res = min(res, a-f+b-s+c-k);  
//                    //cout<<f<<" "<<s<<" "<<k<<"\n";
//                    resa = f;
//                    resb = s;
//                    resc = k;


//                  }
//             }
//         }
//         cout<<res<<"\n";
//         cout<<resa<<" "<<resb<<" "<<resc<<"\n";
//    }
// }


int main(){
   ll n, i, j, k;

   cin>>n>>k;

     ll h[n];

     for(i =0 ;i < n;i++){
         cin>>h[i];
     }
   
    ll dp[n];

    memset(dp, 0, sizeof(dp));
    dp[0] = 0;

    for(i =1;i < n;i++){
        dp[i] = 10000000000;
    }

    for(i = 0;i < n;i++){
        for(j = 1;j <= k;j++)
        if(i+j<n){
            if(dp[i]+abs(h[i+j]-h[i]) < dp[i+j]){
                dp[i+j] = dp[i]+abs(h[i+j]-h[i]);
            }
        }  
        // if(i+2<n){
        //     if(dp[i]+abs(h[i+2]-h[i]) < dp[i+2]){
        //         dp[i+2] = dp[i]+abs(h[i+2]-h[i]);
        //     }
        // }
    }
    cout<<dp[n-1]<<"\n";
}

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

int main() {
  int a[] = { 0,1,3,1,2,1,2,1,1,2,1,2,1 };
  int x, y;
  cin >> x >> y;
  cout << (a[x] == a[y] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;


long trans_time(long time, long t, long t_prev, long max_num, int pos)
{
  	if(t_prev<= t) time+=1;
  	else
    {
     	time = pos + max_num / t ;
    	if(max_num % t >0) time+= 1;
    }
  	return time;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
  	long t[5];
  	int index = 0;
  	long n;
	cin >> n;
  	long lowest_path = -1;
  	while(cin >> t[index])
    {
      if(lowest_path == -1 || t[lowest_path] > t[index]) lowest_path = index;
      index++;
      if(index == 5) break;
    }
  	long time = n / t[lowest_path];
  	if(n % t[lowest_path] > 0) time+=1;
  
  	cout << time+4 << endl;
	return 0;
}

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

#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 all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

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

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int a, b;
    cin >> a >> b;
    for(int i=1;i<=3;++i) {
        if (a != i & b != i) cout << i << endl;
    }
    return 0;
}


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

int main() {
  int H, W; cin >> H >> W;
  vector<string> G(H);
  for (int i = 0; i < H; i++) cin >> G.at(i);
  const int INF = 1000000007;
  vector<vector<int>> dp(H, vector<int>(W, INF));
  dp.at(0).at(0) = 0;
  if (G.at(0).at(0) == '#') dp.at(0).at(0) = 1;
  queue<pair<int, int>> q;
  q.push(make_pair(0, 0));
  vector<int> dy = { 0, 1 };
  vector<int> dx = { 1, 0 };
  while (!q.empty()) {
    int cy = q.front().first;
    int cx = q.front().second;
    q.pop();
    for (int i = 0; i < 2; i++) {
      int ny = cy + dy.at(i);
      int nx = cx + dx.at(i);
      if (ny >= H || nx >= W) continue;
      if (dp.at(ny).at(nx) == INF) q.push(make_pair(ny, nx));
      if (G.at(cy).at(cx) == '#') {
        dp.at(ny).at(nx) = min(dp.at(ny).at(nx), dp.at(cy).at(cx));
      }
      else {
        if (G.at(ny).at(nx) == '#') {
          dp.at(ny).at(nx) = min(dp.at(ny).at(nx), dp.at(cy).at(cx) + 1);
        }
        else {
          dp.at(ny).at(nx) = min(dp.at(ny).at(nx), dp.at(cy).at(cx));
        }
      }
    }
  }
  cout << dp.at(H-1).at(W-1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int a1, a2,a3;
    cin >> a1 >> a2 >> a3;
    int a = a1+a2+a3;
    if(a >= 22){
        cout << "bust";
    }else{
        cout << "win";
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // exit()
#define N_LIST 1000001

typedef struct list_tbl
{
	int key;
	int prev;
	int next;
} list_t;

int lineno;
list_t list[N_LIST];
int ix;
int nil;
int room;

void
cleanup(int ecode)
{
	exit(ecode);
}

void
init()
{
	nil = 0;
	list[nil].key = -1;
	list[nil].next = nil;
	list[nil].prev = nil;
	ix = 1;
	room = 0;
}

void
insert(int key)
{
	int l;

	if (room == 0)
	{
		if (ix >= N_LIST)
		{
			fprintf(stderr, "line %d: List overflow. size%d\n", lineno, N_LIST);
			cleanup(1);
		}

		l = ix++;
	}
	else
	{
		l = room;
		room = list[l].next;
	}

	list[l].key = key;
	list[l].next = list[nil].next;
	list[l].prev = nil;
	list[list[nil].next].prev = l;
	list[nil].next = l;
}

void
_delete(int l)
{
	if (l == nil)
		return;

	list[list[l].next].prev = list[l].prev;
	list[list[l].prev].next = list[l].next;
	list[l].next = room;
	room = l;
}

void
delete(int key)
{
	int l;

	for (l = list[nil].next; l != nil; l = list[l].next)
	{
		if (list[l].key == key)
		{
			_delete(l);
			return;
		}
	}
}

void
delete_first()
{
	_delete(list[nil].next);
}

void
delete_last()
{
	_delete(list[nil].prev);
}

int
main(int argc, char** argv)
{
	char command[15];
	int n = 0;
	int key = 0;
	int l;
	int i;

	init();
	scanf("%d", &n);
	lineno = 0;
	for (i = 0; i < n; ++i)
	{
		lineno++;
		scanf("%s", command);
		switch (command[0])
		{
		case 'i':
			scanf("%d", &key);
			insert(key);
			break;

		case 'd':
			if (command[6] == 'F')
				delete_first();

			else if (command[6] == 'L')
				delete_last();

			else
			{
				scanf("%d", &key);
				delete(key);
			}

			break;
		}
	}

	for (l = list[nil].next; l != nil; l = list[l].next)
		printf("%d%c", list[l].key, list[l].next != nil ? ' ' : '\n');

	return 0;
}

Measured memory_bytes: 12312
#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 count = 0;
  
  while (true) {
    bool exist_odd = false;
    for (int i = 0; i < N; i++) {
      if (A[i] % 2 != 0) exist_odd = true;
    }
    if (exist_odd) break;
    
    for (int i = 0; i < N; i++) {
      A[i] /= 2;
    }
    count++;
    
  }
  
  
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

bool dp[7][100010];
int main(void) {
    ll x;
    cin >> x;

    dp[0][0] = true;
    REP(i, 6) REP(j, x+1) {
        dp[i+1][j] |= dp[i][j];
        if(j+100+i <= x) dp[i+1][j+100+i] |= dp[i+1][j];
    }

    cout << dp[6][x] << endl;

    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5 + 10;
LL K;
LL dp[20][10], f[20];
void prework()
{
    for(int j = 0; j <= 9; j++)
        dp[0][j] = 1;
    for(int i = 1; i <= 18; i++)
    {
        for(int j = 0; j <= 9; j++)
        {
            if(j == 0)
                dp[i][j] = dp[i-1][0] + dp[i-1][1];
            else if(j == 9)
                dp[i][j] = dp[i-1][8] + dp[i-1][9];
            else
                dp[i][j] = dp[i-1][j-1] + dp[i-1][j] + dp[i-1][j+1];
        }
    }
    for(int i = 1; i <= 19; i++)
    {
        f[i] = f[i-1];
        for(int j = 1; j <= 9; j++)
            f[i] += dp[i-1][j];
    }
}
int main()
{
    prework();
    scanf("%lld", &K);
    LL ans = 0;
    for(int i = 19; i >= 1; i--)
    {
        if(!ans)
        {
            if(f[i-1] < K)
                K -= f[i-1];
            else
                continue;
            for(int j = 1; j <= 9; j++)
            {
                if(dp[i-1][j] < K)
                    K -= dp[i-1][j];
                else
                {
                    ans = j;
                    break;
                }
            }
        }
        else
        {
            int pre = ans % 10;
            for(int j = -1; j <= 1; j++)
            {
                if(pre + j < 0 || pre + j > 9)
                    continue;
                if(dp[i-1][pre+j] < K)
                    K -= dp[i-1][pre+j];
                else
                {
                    ans = ans * 10 + pre + j;
                    break;
                }
            }
        }
    }
    printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<double, P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;
#define INF (ll)10000000000000000

int main() {
  ll N;
  cin>>N;
  ll w=2*N;
  vector<ll>ans(N+1);
  rep(i,N+1){ans[i]=0ll;}
  for(ll i=2;i<=150;i++){
    for(ll j=2;j<=150;j++){
      for(ll k=2;k<=150;k++){
        ll g=i*i+j*j+k*k;
        if(g>w){continue;}
        if((i+j-k)%2==0&&(i+j-k)>=1&&(i-j+k)%2==0&&(i-j+k)>=1&&(j-i+k)%2==0&&(j-i+k)>=1){
          ans[g/2]++;
        }
        
      }
    }
  }
  rep(i,N){cout<<ans[i+1]<<endl;}
  
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

string s;
int n;
long long ans = 0;

void func(vector<int>& v){
  if(v.size() == n - 1){
    long long t = s[0] - '0', ret = 0;
    for(int i = 0; i < n - 1; i++){
      if(v[i] == 0){
        t *= 10;
        t += s[i + 1] - '0';
      }
      else{
        ret += t;
        t = s[i + 1] - '0';
      }
    }
    ret += t;
    //cout << ret << endl;
    ans += ret;
    return;
  }
  v.push_back(0);
  func(v);
  v.pop_back();
  v.push_back(1);
  func(v);
  v.pop_back();
  return;
}

void solve(){
  cin >> s;
  n = s.size();
  vector<int> v;
  func(v);
  cout << ans << endl;
  return;
}

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


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let m: usize = read();
    let a: Vec<Vec<usize>> = (0..n).map(|_| (0..m).map(|_| read()).collect()).collect();
    let b: Vec<usize> = (0..m).map(|_| read()).collect();
    for i in 0..n {
        println!("{}", (0..m).fold(0, |acc, j| acc + a[i][j] * b[j]));
    }
}



Measured memory_bytes: 5048
#include<stdio.h>
#include<math.h>

int main(void)
{
	double a,s,n;
	int i;

	while (scanf("%lf", &a) != EOF) {
		s = a;
		n = a;
		for (i = 2; i <= 10; i++) {
			if (i % 2 == 0) {
				s *= 2.0;
				n += s;
			}
			else {
				s /= 3.0;
				n += s;
			}
		}
		printf("%.8lf\n",n);
	}
	return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int dp[105][4][2];
 
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int K;
  cin >> K;
  dp[0][0][0] = 1;
  rep(i,n)rep(j,4)rep(k,2) {
    int nd = s[i]-'0';
    rep(d,10) {
      int ni = i+1, nj = j, nk = k;
      if (d != 0) nj++;
      if (nj > K) continue;
      if (k == 0) {
        if (d > nd) continue;
        if (d < nd) nk = 1;
      }
      dp[ni][nj][nk] += dp[i][j][k];
    }
  }
  int ans = dp[n][K][0] + dp[n][K][1];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main  {
    public static void main(String args[]) {
      FastScanner fs=new FastScanner();    
      PrintWriter out=new PrintWriter(System.out);
        
        long a=fs.nextLong(),b=fs.nextLong(),c=fs.nextLong(),d=fs.nextLong();
    
        long p1=a*c,p2=a*d,p3=b*c,p4=b*d;
        
        out.println(Math.max(p1,Math.max(p2,Math.max(p3,p4))));   
        
        
        out.flush();
        out.close();
    }
	static void ruffleSort(int[] a) {
 		Random random=new Random();
		int n=a.length;
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
}
        class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		String next() {
			while (!st.hasMoreTokens())
				try {
				st=new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		String nextLine() {
		    String str="";
		    try {
		        str=br.readLine();
		    }
		    catch (IOException e) {
		        e.printStackTrace(); 
		    }
		    return str;
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		double nextDouble() {
		    return Double.parseDouble(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
	}

Measured memory_bytes: 32900
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int K;cin>>K;
  string S;
  cin>>S;
  if(S.length()<=K){
    cout<<S<<endl;
  }else{
    cout<<S.substr(0,K)<<"..."<<endl;
  }

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define IOS  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp    make_pair
#define pb    push_back
#define F     first
#define pi 	  3.14159265358979323846
#define S     second
#define ll    long long
#define ld    long double
#define sz(s) (ll)s.size() 
#define vl    vector < ll >
#define pll   pair < ll, ll >
#define ml    map < ll, ll >
#define mod   1000000007
#define MAXN  50005 
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define inv(i,a,b)  for(ll i=a;i>=b;i--)
#define all(a)  (a).begin(),(a).end()
using namespace std;
int main(){
	IOS;
	ll t,n,l;
	ll i,j,m,mn,d,x,a,b,y,ans1,temp,sum,c;
	string s;
	cin>>n;
	cout<<n+(n*n)+(n*n*n);
}

Measured memory_bytes: 3608
fun main(args: Array<String>) {
    val (X, Y) = readInputLine().split(" ").map { it.toInt() }
    
    var ans = 0
    
    ans += when (X) {
        1 -> 300000
        2 -> 200000
        3 -> 100000
        else -> 0
    }
    ans += when (Y) {
        1 -> 300000
        2 -> 200000
        3 -> 100000
        else -> 0
    }
    
    if (X == 1 && Y == 1) {
        ans += 400000
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37872
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            var A = inputLongArray[0];
            var B = inputLongArray[1];

            // 文字列の入力
            string s = Console.ReadLine();

            if(s.Substring(0,A).All(char.IsDigit)
                && s.Substring(A,1) == "-"
                && s.Substring(A+1, B).All(char.IsDigit)) {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

vector<int> graph[100005];
vector<bool> used(100005);
vector<int> dep(100005);
int ans = 0;
int k;

int dfs(int p) {
  //if (used[p]) return 0;
  used[p] = true;
  int ret = 0;
  for(auto e: graph[p]) {
    if (used[e]) continue;
    chmax(ret, dfs(e));
  }
  if (p == 1) return 0;
  ret++;
  if (ret >= k && dep[p] != 1) {
    ans++;
    ret = 0;
  }
  //debug(p); debugln(ret);
  return ret;
}

void dfs2(int p, int depth) {
  dep[p] = depth;
  for(auto e: graph[p]) {
    dfs2(e, depth+1);
  }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n >> k;
  vector<int> a(n+1);

  int cnt = 0;

  for(int i=1; i<=n; i++) {
    int a; cin >> a;
    if (a != 1) cnt++;
    if (i==1) {
      if (a != 1) {
        ans++;
      }
      continue;
    }
    graph[a].push_back(i);
  }
  /*if (k==1) {
    cout << cnt << endl;
    return 0;
  }*/

  dfs2(1, 0);
  dfs(1);
  cout << ans << endl;
}


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

string s;
bool flag;

int main(){
    cin>>s;
    flag = true;
    string cmp = "";
    int cnt=0;

    for(int i=s.size()-1; i>=0; i--){
        cmp += s[i];
        if(cmp == "maerd" || cmp == "esare" \
            || cmp == "remaerd" || cmp == "resare"){
                cmp = "";
        }

        if(cmp.size() >= 7) flag = false;
    }
    
    cout<<(flag ? "YES" : "NO")<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k,yu,chu;
	while(scanf("%d %d",&n,&k)!=EOF){
		yu=n%k;
		if(yu==0){
			printf("0\n");
		}
		else{
		    printf("1\n");
		}
	}
	return 0;
}

Measured memory_bytes: 256
N,K,Q = map(int, input().split())
A = {}
for i in range(Q):
    _ = int(input())
    if _ in A:
        A[_] += 1
    else:
        A[_] = 1
for i in range(N):
    try:
        print('Yes' if 0 < K - Q + A[i+1] else 'No')
    except KeyError as e:
        print('Yes' if 0 < K - Q else 'No')

Measured memory_bytes: 9064
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct Node
{
	int p;
	string s; 
	int num;
}f[105];
int n;
bool cmp(Node p,Node q)
{
	if(p.s!=q.s) return p.s<q.s;
	else return p.p>q.p;
}
int main ()
{ 
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		cin>>f[i].s;
		scanf("%d",&f[i].p);
		f[i].num=i;
	}
	sort(f+1,f+n+1,cmp); 
	for(int i=1;i<=n;i++)
	{
		cout<<f[i].num<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

double calc(int n, vector<vector<int>>& edges, vector<double>& dp)
{
	dp[n] = 0.0;

	FOR_DW(i, n - 1, 1) {
		int s = edges[i].size();
		if (s == 0) return numeric_limits<double>::max();

		for (int t : edges[i]) {
			dp[i] += (dp[t] + 1.0) / s;
		}
	}

	return dp[1];
}

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

	int n, m; cin >> n >> m;

	vector<vector<int>> edges(n + 1);
	FOR_LT(i, 0, m) {
		int s, t; cin >> s >> t;
		edges[s].push_back(t);
	}

	vector<double> dp(n + 1);
	double ans = calc(n, edges, dp);


	FOR_LE(i, 1, n - 1) {
		vector<double> cdp(n + 1);

		double val = 0.0;
		int idx = -1;
		vector<vector<int>> ces = edges;
		FOR_LT(j, 0, edges[i].size()) {
			if (val <= dp[edges[i][j]]) {
				val = dp[edges[i][j]];
				idx = j;
			}

		}

		ces[i].erase(ces[i].begin() + idx);

		double curans = calc(n, ces, cdp);
		ans = min(ans, curans);
	}

	cout << setprecision(20) << ans << endl;


	return 0;
}

Measured memory_bytes: 2112
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();  
        int X = r.i();
        int A = r.i();
        int B = r.i();
        println((X-A)%B);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int Int(String s){
            return Integer.parseInt(s);
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
    }
}

Measured memory_bytes: 22484
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int mo=1000000007;
const int N=1005;
int n,K,a[N];
int f[55][N],C[N][N];
int main(){
	scanf("%d%d",&n,&K);
	For(i,1,K) scanf("%d",&a[i]);
	For(i,0,n) C[i][0]=1;
	For(i,1,n) For(j,1,i)
		C[i][j]=(C[i-1][j]+C[i-1][j-1])%mo;
	f[0][0]=1;
	For(i,1,K) For(j,0,n) For(k,0,n-j)
		if (k<=a[i]) f[i][j+k]=(f[i][j+k]+1ll*f[i-1][j]*C[n-j][k]%mo*C[n-k][a[i]-k])%mo;
	//For(i,1,K) For(j,0,n) printf("%d %d %d\n",i,j,f[i][j]);
	printf("%d\n",f[K][n]);
}

Measured memory_bytes: 4352
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n , k = map(int, input().split())
    a = list(map(int, input().split()))
    l = 1
    r = max(a)
    while l < r:
        m = (l+r)//2
        cnt = 0
        for x in a:
            cnt += (x-1)//m
        if cnt > k: l = m+1
        else: r = m
    print(r)
    


if __name__ == '__main__':
    main()

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

int main() {
  int a, b; cin >> a >> b;
  if ((a < 0 && b > 0) || a == 0 || b == 0) {cout << "Zero" << endl;}
  else if (b < 0 && (b-a)%2 == 0) {cout << "Negative" << endl;}
  else {cout << "Positive" << endl;}
}
  

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

using namespace std;
//#define int long long
const int mod = 1e9+7;

int dp[10003][100][2];

int main(){
	string K;
	int D; 
	cin >> K >> D;
	int n = K.length();
	
	for(int i = 0; i < K[0] - '0'; i++){
		dp[0][i%D][0]++;
	}
	dp[0][(K[0]-'0')%D ][1]++;
	
	for(int i = 1; i < n; i++){
		for(int j = 0; j < D; j++){
			for(int k = 0; k < 2; k++){
				int up = 9;
				if(k) up = K[i] - '0';
				for(int d = 0; d <= up; d++){
					int ns = k & (d==up);
					dp[i][(j+d)%D][ns]+=dp[i-1][j][k];
					dp[i][(j+d)%D][ns]%=mod;
				}
			}
		}
	}
	int res = 1ll*(dp[n-1][0][0] + dp[n-1][0][1]-1+mod) % mod;
	cout << res << "\n";
	return 0;
}


Measured memory_bytes: 8064
#include<stdio.h>
int main() {
    int i, h, len, j, l, k;
    scanf("%d%d%d", &h,&i,&j);
    if(h+i==j||i+j==h||j+h==i){
        printf("Yes\n");
    }
else{
    printf("No\n");
}

    return 0;
}

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

const int MAXN = 2e5+2;
unsigned long long nums[MAXN];

const long long MAXL = 1e18;

//判断a*b是否超过1e18
bool overflow(unsigned long long a, unsigned long long b) {
    //判断是否越界
    if (ULLONG_MAX / a < b) {
        return true;
    }
    //判断是否超过1e18
    unsigned long long ans = a*b;
    if (ans>MAXL) {
        return true;
    }
    return false;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i=0; i<n; i++) {
        scanf("%llu", &nums[i]);
        if (0==nums[i]) {
            printf("0\n");
            return 0;
        }
    }

    long long ans=1;
    for (int i=0; i<n; i++) {
        if (true == overflow(ans, nums[i])) {
            printf("-1\n");
            return 0;
        }
        ans *= nums[i];
    }

    printf("%llu", ans);

    return 0;
}


Measured memory_bytes: 4608
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int N, K;

int sum(vector<int> &V, int i, int j, int count){
    vector<int> T;
    for(int k = 0; k < i; k++) T.push_back(V[k]);
    for(int k = j; k < N; k++) T.push_back(V[k]);
    sort(all(T));

    int index = 0, T_sum = 0;
    while(count > 0 && index < T.size() && T[index] < 0 ){
        index++;
        count--;
    }

    while(index < T.size()){
        T_sum += T[index];
        index++;
    }

    return T_sum;
}

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

    int ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = i; j <= N; j++){
            int s = N - (j - i);
            int c = K - s;
            if(c < 0) continue;
            ans = max(ans, sum(V, i, j, c));
        }
    }

    cout << ans << endl;

}

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

int main() {
    long long n;
    cin >> n;
    vector<long long> a(n);
    map<long long, long long> m;
    map<long long, long long> pre;



    for(int i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]] = m[a[i]] + 1;
    }

    long long ret = 0;
    for(auto itr = m.begin(); itr != m.end(); ++itr) {
        long long key = itr->first;
        //cout << itr->first;
        
        //if(key == a[i]) diff = 1; 
        //cout << (m[key] - diff) << endl;
        ret += ((m[key]  - 0 ) * (m[key] - 1)) / 2;
        //cout << diff << i << ret << key << endl;
        //cout << ret << endl;
    }

    //cout << ret << endl;

    for(int i = 0; i < n; i++) {
        long long temp = 0;
        temp = ret - ((m[a[i]] - 1));
        //if(m[a[i]] == 2) temp -= 1;
        cout << temp << endl;
    }

    return 0;
}

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


int main() {
    int n;
    cin >> n;
    int min = INT8_MAX;
    for (int i = 0; i < n; i++) {
        int count = 0;
        unsigned num;
        cin >> num;
        while((num & 1) == 0) {
            count++;
            num >>= 1;
        }
        if (count < min) min = count;
    }
    cout << min << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iomanip>
#include <cstring>
#include <climits>
#include <cstdio> 

#define nl '\n'

using namespace std;

int x, y, z;

int main(){

    cin >> x >> y >> z;

    cout << z << " " << x << " " << y;





}
 
//g++ -std=c++14 comp.cpp -o c && c.exe
//g++ -std=c++14 comp.cpp -o c; ./c.exe
//g++ -std=c++14 comp.cpp && ./a.out


//Surely this is going to AC

Measured memory_bytes: 256
const main = (inputs) => {
  var N = inputs[0].split(" ")[0]-0;
  var map = {};
  for(var i=1;i<=N;i++){
    var ip = inputs[i].split("").sort().join("");
    if(!map[ip])map[ip] = 0;
    map[ip]++;
  }
  var ans = 0;
  Object.keys(map).forEach(key=>{
    var cnt = map[key];
    if(cnt > 1){
      ans += cnt*(cnt-1)/2;
    }
  });
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


Measured memory_bytes: 42940
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
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() {
    string s;
    cin >> s;

    ll sum = 0;
    int n = s.size();

    for(int temp = 0; temp < (1 << n-1); ++temp) {
        ll t = s[0] - '0';

        for(int i = 0; i < n - 1; ++i) {
            if(temp & (1 << i)) {
                sum += t;
                t = s[i+1] - '0';
            } else {
                t *= 10;
                t += s[i+1] - '0';
            }
        }
        sum += t;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
x = a+b+c
ans = "No"
N = int(input())
for i in range(N) :
    b = int(input())
    x = ["x" if i == b else i for i in x]

for i in range(3) :
    if x[i] == x[i+3] == x[i+6] == "x" :
        ans = "Yes"
    if x[3*i] == x[3*i+1] == x[3*i+2] == "x" :
        ans = "Yes"
if x[0] == x[4] == x[8] == "x" :
    ans = "Yes"
if x[2] == x[4] == x[6] == "x" :
    ans = "Yes"
print(ans)

Measured memory_bytes: 9240
import scala.io.StdIn
object Main extends App {
  val List(n,k) = StdIn.readLine().split(" ").map(_.toInt).toList
  val S = StdIn.readLine()
  val initialScore = (for (i <- 0 until n-1) yield if (S(i) == S(i+1)) 1 else 0).sum
  println((n-1).min(initialScore + 2 * k))
}


Measured memory_bytes: 31608
#include<stdio.h>
#include<algorithm>
int main()
{
	int n,i,a[100],x,r;
	while(scanf("%d",&n)>0)
	{
		for(i=x=r=0;i<n;++i)scanf("%d",&a[i]);
		std::sort(a,a+n);
		for(i=0;i<n;++i)r+=x+=a[i];
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int SIZEN = 100010;
int N;
int L[SIZEN];
int R[SIZEN];
int a[SIZEN];
int b[SIZEN];
int mnb[SIZEN];
int id[SIZEN];

bool Cmp(const int &A,const int &B){
    return a[A] > a[B];
}

int main(){
    scanf("%d",&N);
    int mxl = 0,locl;
    int mnr = INF,locr;
    for(int i = 1;i <= N;i++){
        scanf("%d%d",&L[i],&R[i]);
        if(mxl < L[i])mxl = L[i],locl = i;
        if(mnr > R[i])mnr = R[i],locr = i;
    }
    int ans = max(mnr - mxl + 1,0),tmpans = 0;
    for(int i = 1;i <= N;i++)tmpans=max(tmpans,R[i] - L[i] + 1);
    ans = ans + tmpans;

    // printf("ans = %d,mxl = %d,mnr = %d\n",ans,mxl,mnr);

    for(int i = 1;i <= N;i++){
        a[i] = max(0,R[i] - mxl + 1);
        b[i] = max(0,mnr - L[i] + 1);
        id[i] = i;
    }
    sort(id + 1,id + 1 + N,Cmp);
    mnb[N] = b[id[N]];
    for(int i = N-1;i >= 1;i--)mnb[i] = min(mnb[i+1],b[id[i]]);
    int mxb = 0;

    // for(int i = 1;i <= N;i++)printf("L = %d,R = %d,a = %d,b = %d\n",L[id[i]],R[id[i]],a[id[i]],b[id[i]]);
    // printf("mnb : ");for(int i = 1;i <= N;i++)printf("%d ",mnb[i]);printf("\n");
    
    for(int i = 1;i <= N;i++){
        int x = id[i];
        ans = max(ans,a[x] + mnb[i+1]);
        mxb = max(mxb,b[x]);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 4080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2005;
char a[N][N];
ll prfx[N][N],hor[N][N],ver[N][N];
inline ll tot_cnt(ll x1,ll y1,ll x2,ll y2){
    return prfx[x2][y2] - prfx[x1-1][y2] - prfx[x2][y1-1] + prfx[x1-1][y1-1];
}
inline ll hor_cnt(ll x1,ll y1,ll x2,ll y2){
    return hor[x2][y2] - hor[x1-1][y2] - hor[x2][y1-1] + hor[x1-1][y1-1];
}
inline ll ver_cnt(ll x1,ll y1,ll x2,ll y2){
    return ver[x2][y2] - ver[x1-1][y2] - ver[x2][y1-1] + ver[x1-1][y1-1];
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,m,q;cin>>n>>m>>q;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            cin>>a[i][j];
            prfx[i][j]=prfx[i-1][j]+prfx[i][j-1]-prfx[i-1][j-1];
            hor[i][j]=hor[i-1][j]+hor[i][j-1]-hor[i-1][j-1];
            ver[i][j]=ver[i-1][j]+ver[i][j-1]-ver[i-1][j-1];
            prfx[i][j]+=(a[i][j]-'0');
            if(a[i][j-1]=='1'&&a[i][j]=='1')hor[i][j]++;
            if(a[i-1][j]=='1'&&a[i][j]=='1')ver[i][j]++;
        }
    }
    for(ll x1,y1,x2,y2;q>0;q--){
        cin>>x1>>y1>>x2>>y2;
        cout<<tot_cnt(x1,y1,x2,y2)-hor_cnt(x1,y1+1,x2,y2)-ver_cnt(x1+1,y1,x2,y2)<<"\n";
    }
}

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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long int X, Y;
    cin >> X >> Y;
    cout << abs(X-2) * abs(Y-2) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(12);
  double n,k;
  cin >> n >> k;
  int bai = 1;
  
  double ans = 0.00000000;
  rep(i,0,n){
    bai = 1;
    
    rep(j,0,30){
      if((i+1) * bai >= k) {
        ans += pow(0.5,j);
        break;
      }
      bai *= 2;
      
    }
    
  }
  cout << ans/n << endl;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(){
    int s;
    cin >> s;
    int now = s;
    bool used[1000000] = {};
    for(int i = 0; i < 1e6; i++){
        if(used[now]){
            cout << i + 1 << "\n";
            return 0;
        }
        used[now] = true;
        if(now % 2){
            now *= 3;
            now++;
        }else{
            now /= 2;
        }
    }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long H,W;
    cin >> H >>W;
    if(min(H,W)==1){
        cout << 1<< endl;
    }
    else if(H%2==1&&W%2==1){
       cout << (H*W+1)/2 << endl;
    }
    else{
        cout << H*W/2 << endl;
    }
}

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

int main(){
	int a, b, c;
	int d;
	int i;
	cin >> a >> b >> c;
	d = 0;
	for (i = a; i <= b; i++){
		if (c % i == 0){
			d += 1;
		}
	}
	cout << d << endl;
	return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    int sum = 0;
    if(a >= b){
        rep(i,a) sum = sum*10 + b;
    }
    else rep(i,b) sum = sum*10 + a;
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] h = new long[n];
        long[] buff = new long[n];
        boolean f = true;
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextLong();
            if (i>0) {
                if (h[i]<h[i-1]) {
                    long diff=h[i-1]-h[i];
                    if ( buff[i-1] !=0 || diff>1 ) f=false;
                    else buff[i]=1;
                }
                else if (h[i]==h[i-1]) buff[i]=buff[i-1];
            }
        }
        System.out.println(f ? "Yes" : "No");
    }
}

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

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

int main() {
    int n; cin >> n;
    map<int, int> ma;
    REP(i, n) {
        int t; cin >> t;
        ma.insert(make_pair(t, i + 1));
    }

    for (auto itr = ma.begin(); itr !=  ma.end(); ++itr) {
        cout << itr->second << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, M;
  cin >> N >> M;
  ll total = 0;
  vl A(N);
  rep(i, N){
    cin >> A[i];
    total += A[i];
  }

  stable_sort(A.begin(), A.end(), greater<ll>());
  
  rep(i, M){
    if(A[i] * 4 * M < total){
      cout << "No" << endl;
      return 0;
    }    
  }

  cout << "Yes" << endl;
  
  return 0;
}

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

int main(){
	int n, p, d1, d2;
	int max, max_p;
	while(cin >> n){
		if(n==0) break;
		cin >> p >> d1 >> d2;
		max = d1+d2;
		max_p = p;
		for(int i=1; i<n; i++){
			cin >> p >> d1 >> d2;
			if(max < d1+d2){
				max = d1+d2;
				max_p = p;
			}
		}
		cout << max_p << " " << max << endl;
	}
	return 0;
}
	
	
	
	
	

Measured memory_bytes: 868