akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1000000001;
#define MOD 1000000007;
#define INF64 1000000000000000001;

#define F first
#define S second

#define Pii pair<SINT32,SINT32>
#define Pll pair<SINT64,SINT64>


using namespace std;

int main() {

	string N,M;
	cin >> N >> M;
	SINT64 ans = 0;

	N = N+M;

	rep(i,0,N.length()) {
		ans += (N[N.length()-1-i] - '0') * pow(10,i);
	}

	rep(i,0,ans) {
		if ((i*i) == ans) {
			
			cout << "Yes" << endl;
			return 0;

		}

	}


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

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));	//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();	//key以上を探す
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/

/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int  main()
{

int n;
cin>>n;
int l;
cin>>l;
vector<string> myvec;
for(int i=0;i<n;i++)
{
string s;
cin>>s;
myvec.push_back(s);
}
sort(myvec.begin(),myvec.end());
for(string s: myvec) cout<<s;
cout<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


		int n = Integer.parseInt(br.readLine());

		int min = Integer.MAX_VALUE;
		for(int i = 1; i < n - 1; i++){
			int a = sumOfDigits(i);
			int b = sumOfDigits(n - i);

			if(a + b < min){
				min = a + b;
			}
		}
		if(n == 2){
			min = 2;
		}

		System.out.println(min);
	}

	static int sumOfDigits(int x){
		int result = 0;
		while(x > 0){
			result += x%10;
			x /= 10;

		}

		return result;
	}

}


Measured memory_bytes: 21332
def main():

    S = input()
    n = len(S)
    i = 0
    ans = [0 for _ in range(n)]
    while i < n:
        countL, countR = 0, 0
        while i < n and S[i] == 'R':
            countR += 1
            i += 1
        while i < n and S[i] == 'L':
            countL += 1
            i += 1
        if(abs(countL-countR) % 2 == 0):
            cL, cR = (countL + countR) // 2, (countL + countR) // 2
        else:
            c = (countL + countR + 1) // 2
            if(countR > countL):
                if(countR % 2 == 1): cR, cL = c, c-1
                else: cR, cL = c-1, c
            else:
                if(countL % 2 == 1) : cR, cL = c-1, c
                else: cR, cL = c, c-1
        ans[i-countL] = cL
        ans[i-countL-1] = cR

    return " ".join(map(str, ans))

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 10492
#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 INF = 1001001001;


int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    sort(h.begin(), h.end());
    if (k >= n) {
        cout << 0 << endl;
        return 0;
    }
    else {
        ll ans = 0;
        rep(i,n-k) ans += h[i];
        cout << ans << endl;
    }


    return 0;
}

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

#define vi vector<int>
#define vii vector<int, int>
#define ll long long
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...) 42
#endif
const int MOD=1e9+7;

//////////////////////// code starts ///////////////////////

int main(){
    IOS;
    #ifdef LOCAL
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif

    string s;
    cin >> s;
    if (s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes" << endl;
    else cout << "No" << endl;




    #ifdef LOCAL
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif

    return 0;
}




Measured memory_bytes: 3640
{-# LANGUAGE BangPatterns #-}
import Control.Applicative((<$>))
import Control.Monad
import Data.Map ((!))
import qualified Data.Map as M
import qualified Data.List as L
import Data.Maybe (catMaybes)
-- import qualified Data.Char as C
-- import qualified Data.IntSet as I
import Debug.Trace
--------------------------------------------
readInt    = read :: String -> Int
getInt     = readInt <$> getLine
getIntList = map readInt . words <$> getLine
int2bin 0 =  []
int2bin n =  n `mod` 2 : int2bin (n `div` 2)
----------------------------------------------

solve xs =
  let ln = length xs - 1
      x  = head xs
      tmp = sum $ map (\c -> read [c]) xs
  in tmp `max` (read [x] - 1 + 9 * ln)

main :: IO ()
main = do
  n <- getLine
  print $ solve n


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

int main()
{
	int n; cin >> n;
	
	int a;
	int cnt_4 = 0;
	int cnt_2 = 0;
	int cnt_odd = 0;

	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 4 == 0) cnt_4++;
		else if (a % 2 == 0) cnt_2++;
		else cnt_odd++;
	}

	string ans = "No";

	int tmp = n - (2 * cnt_4 + 1);

	if (n <= 0) {
		ans = "Yes";
	}
	else {
		if (tmp % 2 == 0) {
			if (tmp <= cnt_2) ans = "Yes";
		}
		else {
			if (tmp < cnt_2) ans = "Yes";
		}
	}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long int sum=1LL,kake=2LL;
  long int H,Log=0;
  cin >> H;
  Log = log2(H);
  for(int i = 0;i<Log;i++){
  	sum += kake;
    kake *=2LL;
  }
  cout << sum << endl;
}

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

using ll = long long;

#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

ll N;

ll g(ll j) {
  ll Y = N / j;
  return j * (Y + 1) * Y / 2;
}

void solve() {
  ll sum = 0;
  FOR(j, 1, N + 1) { sum += g(j); }
  cout << sum << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  scanf("%lld", &N);
  solve();
  return 0;
}


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

int main() {
    ll n, x;
    cin >> n;
    vector<ll> nums;
    for (ll i=0; i<n; i++) {
        cin >> x;
        nums.push_back(x);
    }
    sort(nums.begin(),nums.end());
    ll one = nums[n-1]/2;
    ll two = one+1;
    if (nums[n-1]%2==0) two = one;
    ll minim = 1000000001;
    ll res;
    for (ll i=0; i<n; i++) {
        ll diff = min(abs(nums[i]-one),abs(nums[i]-two));
        if (diff<minim) {
            minim = diff;
            res = nums[i];
        }
    }
    cout << nums[n-1] << ' ' << res;
    return 0;
}

Measured memory_bytes: 4300
n = list(map(int, input().split()))
n.sort()
a = abs(n[-1] - n[1])
b = abs(n[-1] - n[0])

count = 0
while a != 0 and b != 0:
    a -= 1
    b -= 1
    count += 1

while b > 1:
    b -= 2
    count += 1

if b == 1:
    count += 2

print(count)



Measured memory_bytes: 3060
import math
n = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
def f(l):
    return math.factorial(l)
a = 0
b = 0
R = [1,2,3,4,5,6,7,8,9]
S = [1,2,3,4,5,6,7,8,9]
for i in range(n):
    c = R.index(P[i])
    a += f(n-i-1)*(c-1)
    R.remove(P[i])
for i in range(n):
    d = S.index(Q[i])
    b += f(n-i-1)*(d-1)
    S.remove(Q[i])
print(abs(a-b))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<string> s(n);
	vector<int> t(n);
	for(int i = 0; i < n; ++i){
		cin >> s[i] >> t[i];
	}
	string x;
	cin >> x;
	int answer = 0, flag = 0;
	for(int i = 0; i < n; ++i){
		if(flag){ answer += t[i]; }
		if(s[i] == x){ flag = 1; }
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
	typedef long long int lli;
	const int MaxN=55;
	#define fst first
	#define snd second
	
int main(){
	lli a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a>0||c>0){
		c-=b;
		if(c<=0){
			cout<<"Yes";
			return 0;
		}
		a-=d;
		if(a<=0){
			cout<<"No\n";
			return 0;
		}
	}
}

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

int main() {
  int A, B, T;
  cin >> A >> B >> T;
  int c = 0; // ビスケットの生産回数
  while (true) {
    if (A * (c + 1) > T + 0.5)
      break;
    c++;
  }
  cout << B * c << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(ll i=0;i<(n);++i)
#define Fr(i,n) for(ll i=1;i<=(n);++i)
#define ifr(i,n) for(ll  i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
 
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a,ans,j,k,q,c,x,y;
    cin>>a;
    c=0;
    ans=1000000ll;
    ll iro[a+1];
    iro[0]=0;
    string s;
    cin>>s;
    Fr(i,a){
        if(s[i-1]=='W'){
            iro[i]=iro[i-1]+1;
            ++c;
        }
        else{
            iro[i]=iro[i-1]; 
        }
    }
    fr(i,a+1){
        ans=min(ans,max(iro[i],a-i-c+iro[i]));
    }
    cout<<ans;
}

Measured memory_bytes: 5316
#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 n, m, q;
vector<int> a, b, c, d;
int ans;

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

    A.push_back(A.back());
    while(A.back() <= m) {
        dfs(A);
        A.back()++;
    }
}

int main() {
    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: 3640
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;

void y(bool c) {
	if (c)print("Yes");
	else print("No");
}


void solve() {
	int N, M, V, P; cin >> N >> M >> V >> P;
	vector<int>v(N);
	REP(i, N)cin >> v[i];
	VSORT(v);
	int ok = N-1, ng = -1;
	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;
		int val = v[mid] + M;
		int rem = M * V - M;
		rem -= M * mid;
		rem -= M * (P - 1);

		FOR(i, mid + 1, N-P+1) {
			if (v[i] <= val) {
				rem -= (val - v[i]);
			}
		}
		if (rem <= 0&&val>=v[N-P])ok = mid;
		else ng = mid;
	}
	REP(i, N) {
		if (v[i] == v[ok]) {
			ok = i;
			break;
		}
	}
	print(N - ok);
}



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
set<int> S;
const int mod=998244353;
int dp[200005],l,r,n,k;
int sp[200005];
pair<int,int> v[200005];


int main()
{
    scanf("%d%d",&n,&k);

    for(int i=1;i<=k;i++) {
        scanf("%d%d", &v[i].first, &v[i].second);

    }

    sort(v+1,v+k+1);

    dp[1]=1;
    sp[1]=1;

    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            int x,y;
            x=i-v[j].first;
            y=i-v[j].second;
            if(x<=0) continue;
            y=max(1,y);
            int add=(sp[x]-sp[y-1]+mod)%mod;
            dp[i]=(dp[i]+add)%mod;
        }
        sp[i]=(sp[i-1]+dp[i])%mod;
    }

    printf("%d\n",dp[n]);

        return 0;

    }

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

vector<int> A(10);
vector<int> B = {9,2,5,5,4,5,6,3,7,6};
vector<int> C(10);
vector<int> dp(10010, -1);

int calc_lr(vector<ll> &st, ull x) {
    int left = 0, right = st.size() - 1;
    while (right - left > 1) {
        int mid = (left + right) / 2;
        if (st[mid] > x) right = mid;
        else left = mid;
    } 
    return left;
}

const ll MAX_ST = 2E+10 + 10;

int main() {
    int A, B, Q;
    cin >> A >> B >> Q;
  
    vector<ll> S, T, vQ;
    ll si, ti, qi;
    S.push_back(-MAX_ST);
    T.push_back(-MAX_ST);
    rep(i, A) cin >> si, S.push_back(si);
    rep(i, B) cin >> ti, T.push_back(ti);
    rep(i, Q) cin >> qi, vQ.push_back(qi);
    S.push_back(MAX_ST);
    T.push_back(MAX_ST);

    sort(S.begin(), S.end());
    sort(T.begin(), T.end());

    for (auto xi : vQ) {
        int sl, tl;
        sl = calc_lr(S, xi);
        tl = calc_lr(T, xi);

        ull ans_i;
        ull ll = max(xi - S[sl], xi - T[tl]);
        ull rr = max(S[sl+1] - xi, T[tl+1] - xi);
        ull lsrt = (xi - S[sl]) + (T[tl+1] - S[sl]);
        ull ltrs = (xi - T[tl]) + (S[sl+1] - T[tl]);
        ull rslt = (S[sl+1] - xi) + (S[sl+1] - T[tl]);
        ull rtls = (T[tl+1] - xi) + (T[tl+1] - S[sl]);
        ans_i = min({ll, rr, lsrt, ltrs, rslt, rtls});
        cout << ans_i << endl;
    }

    return 0;
}

 

Measured memory_bytes: 3832
#include <stdio.h>
#include <string.h>

int main(void){
	int a,b;
	scanf("%d %d",&a,&b);
	char s[12];
	scanf("%s",s);
	int i;
	for(i=0;i<a+b+1;i++){
		if(i==a){
			if(s[a]=='-')continue;
			else{
				printf("No");
				return 0;
			}
		}
		if(s[i]>='0'&& s[i]<='9'){
		}else{
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <iostream>
#include <math.h>
using namespace std;
int main ()
{
	bool b=false,a=false;
    int x;
    scanf("%i",&x);
    int i=x,z;
	while (b==false)
	{
		for(int j=2;j<=sqrt(i);j++)
		{
			if(i%j==0)
			{
				a=true;
				break;
			}
		}
		if(a==false)
		{
			printf("%i",i);
			break;
		}
		a=false;
		i++;
	}
	return 0;
}


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

int n,m,ru[100005],t,num[100005],f[100005],ans=0;
vector <int> dis[100005],x[100005];
queue <int> que;

int main(void){
	int t=n;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		ru[b]++;
		dis[a].push_back(b);
		x[b].push_back(a);
	}
	for(int i=1;i<=n;i++)
	if(ru[i]==0)que.push(i);
	while(!que.empty()){
		int u=que.front();
		num[++num[0]]=u;
		que.pop();
		int len=dis[u].size();
		for(int i=0;i<len;i++){
			ru[dis[u][i]]--;
			if(ru[dis[u][i]]==0)que.push(dis[u][i]);
		}
	}
	for(int i=1;i<=n;i++){
		int len=x[num[i]].size();
		for(int j=0;j<len;j++)
		f[num[i]]=max(f[num[i]],f[x[num[i]][j]]+1);
		ans=max(ans,f[num[i]]);
	}
	printf("%d\n",ans);
}

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

signed main()
{
    int a,b,c,d; cin>>a>>b>>c>>d;
    cout<<max(0LL,min(b,d)-max(a,c))<<endl;
}


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

int main() {
  int N; cin >> N;
  int A[N]; for (int i = 0; i < N; i++) cin >> A[i];
  sort(A, A + N);
  int prevIfWritten = 0, num = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] == prevIfWritten) {
      num--;
      prevIfWritten = 0;
    } else {
      num++;
      prevIfWritten = A[i];
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 640
using System.Linq;
using System.Collections.Generic;
using System;
using System.Collections;

class A {

    static void Main() {
        int[] a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        Array.Sort(a);
        if (a[0] == 5 && a[1] == 5 && a[2] == 7) {
            Console.WriteLine("YES");
        }
        else {
            Console.WriteLine("NO");
        }
    }

}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N,K;
	cin>>N>>K;
	vector<int>A(N);
	for(int i=0;i<N;i++)cin>>A.at(i);
	for(int i=K;i<N;i++)cout<<((A.at(i)>A.at(i-K))?"Yes":"No")<<"\n";
}

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

int main(void) {
    long long N, A[200005], B[200005], C[200005], x, i, j, I, J;
    scanf("%lld", &N);
    for (i=0; i<N; i++) scanf("%lld", &A[i]);
    for (i=0; i<N; i++) B[i]=A[i]+i;
    for (i=0; i<N; i++) C[i]=i-A[i];
    
    sort(B, B+N);
    sort(C, C+N);
    
    /*
    for (i=0; i<N; i++) printf("%lld ", A[i]);
    printf("\n");
    for (i=0; i<N; i++) printf("%lld ", B[i]);
    printf("\n");
    for (i=0; i<N; i++) printf("%lld ", C[i]);
    printf("\n");
    */
    
    x=0;
    i=0; j=0;
    while (i!=N && j!=N) {
        if (B[i]==C[j]) {
            if (i==N-1 && j==N-1) {
                x++;
                break;
            }
            if (i==N-1) {
                x++; j++;
            }
            else if (j==N-1) {
                x++; i++;
            }
            else if (B[i+1]==C[j+1]) {
                I=i; J=j;
                while (1) {
                    if (I!=N-1 && B[I+1]==B[i]) I++;
                    else break;
                }
                while (1) {
                    if (J!=N-1 && C[J+1]==C[j]) J++;
                    else break;
                }
                // printf("%lld %lld\n", I-i+1, J-j+1);
                x+=(I-i+1)*(J-j+1);
                i=I+1; j=J+1;
            }
            else if (B[i+1]>C[j+1]) {
                x++; j++;
            }
            else {
                x++; i++;
            }
        }
        else if (B[i]>C[j]) j++;
        else i++;
    }
    printf("%lld", x);
    return 0;
}


Measured memory_bytes: 8452
a=gets.chop
d=0
a.size.times{|i|b,c=a[0,i],a[i,a.size]
x=(b.to_i+c.to_i)/2
y=(c.to_i-b.to_i)/2
d+=1 if x-y==b.to_i&&(x+y).to_s==c&&x>=0&&y>=0}
p d

Measured memory_bytes: 6108
#include <iostream>

using namespace std;

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

const int N = (int)1e5;
int p[N];

int find(int a){
  if(p[a] == a) return a;
  return p[a] = find(p[a]);
}
 
void uni(int a, int b){
  p[find(b)] = find(a);
}

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  int a[m], b[m], c[k], d[k];
  rep(i,m) cin >> a[i] >> b[i], a[i]--, b[i]--;
  rep(i,k) cin >> c[i] >> d[i], c[i]--, d[i]--;
  
  rep(i,n) p[i] = i;
  rep(i,m) uni(a[i], b[i]);
  
  int cc[n], fc[n], bc[n];
  rep(i,n) cc[i] = 0, fc[i] = 0, bc[i] = 0;
  rep(i,n) cc[find(i)]++;
  rep(i,m) fc[a[i]]++, fc[b[i]]++;
  rep(i,k) if(find(c[i]) == find(d[i])) bc[c[i]]++, bc[d[i]]++;
  
  rep(i,n) cout << cc[find(i)] - fc[i] - bc[i] - 1 << (i != n-1 ? " " : "");
  return 0;
}

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

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

  int N;
   cin >> N;
   vector<int> a(N);
   vector<bool> visited(N, false);
   for (int i = 0; i < N; ++i) {
     cin >> a.at(i);
     a.at(i)--;
   }

   bool button = true;
   int cnt = 0;
   int light = 0;
   visited.at(0) = true;
   while (button) {
     light = a.at(light);
     cnt++;
     if (light == 1) {
       button = false;
     }
     if (visited.at(light) == false) {
       visited.at(light) = true;
     }
     else {
       cout << -1 << endl;
       return 0;
     }
   }

   cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;

ll gcd(ll a, ll b) {
	while (b) { ll t = a%b; a = b; b = t; }
	return a;
}

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

int main() {
  ll N; cin>>N;
  vi T(N); REP(i,N) cin>>T[i];
  ll ans=1; for(ll i:T) ans=lcm(ans,i);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
alp=[]
alp+="abcdefghijklmnopqrstuvwxyz"
li=[]
n = int(input())
li+=input()
saidai = 0
for i in range(n):
    count = 0
    lia = li.copy()
    lib = []
    for j in range(i):
        lib += lia.pop()
    for t in range(26):
        if alp[t] in lia and alp[t] in lib:
            count += 1
    if saidai < count:
        saidai = count
print(saidai)

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int cnt = 0;
	for (int i = 0, a; i < 3; ++i) {
		cin >> a;
		if (a == 5)
			cnt++;
	}
	cout << (cnt >= 2 ? "YES" : "NO");




}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N;
  cin >> N;
  for (int i = N; i <= 999; ++i)
  {
    string s = to_string(i);
    if (s[0] == s[1] && s[1] == s[2])
    {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx") 
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i<(b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define dF2(i,a,b) for(int i=(a);i>(b);--i)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define INF 0x3f3f3f3f
#define INFll 0x3f3f3f3f3f3f3f3f
#define y0 _lxybz_
#define y1 _ljmnzyzhhhoscartxdy_
typedef long double ld;
typedef long long ll;
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize
#define lo(x) ((x)&(-(x)))
#define trav(a, x) for (auto &a : x)
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
const ld Pi = 4*atan((ld)1);
template<class T> void chmin(T &a,const T&b) { a = min(a, b); }
template<class T> void chmax(T &a,const T&b) { a = max(a, b); }
namespace IO{
template<class T> inline void read(T&ret)
{
	ret=0; int f=1; char c=getchar();
	while(c<48||c>57){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	ret*=f;
}
template<class T> inline void prin(const T&ret)
{
	if(!ret){putchar(48);return;} static T o; o=ret;
	if(o<0){putchar('-');o=-o;}
	static int op[25],tt; tt=0;
	while(o){
		op[++tt]=o%10;
		o/=10;
	}
	for(int i=tt;i;--i)putchar(op[i]+48);
}
template<class T> inline void pri_(const T&ret)
{
	prin(ret);putchar(' ');
}
template<class T> inline void priE(const T&ret)
{
	prin(ret);putchar('\n');
}
}
using namespace IO;

#define N 500005
#define MO
struct node {
	int d,u;
	bool operator < (const node & a)const {
		if(d!=a.d)return d<a.d;
		return u<a.u;
	}
}; 
set<node>S;
int n,m,c[N][2],u,v,tot,C[N],d[N],O[N],w,a[N],st[N],_[N],fl;
inline void _Sol_()
{
	read(n);read(m);
	F(i,1,n)read(d[i]),S.insert((node){d[i],i});
	tot=1;F(i,1,m){
		read(u);read(v);
		c[++tot][0]=v;c[tot][1]=a[u];a[u]=tot;
		c[++tot][0]=u;c[tot][1]=a[v];a[v]=tot;
	}
	
	while(S.size()){
		u=S.begin()->u; w=S.begin()->d;S.erase(S.begin());
		if(C[u])continue;
		fl=0;
		for(int o=a[u];o;o=c[o][1]){
			v=c[o][0];
			if(C[v]){
				if(C[u]){
					continue;
				}
				C[u]=3-C[v];
				O[o>>1]=w;
				continue;
			}
			if(d[u]==d[v]){
				st[++fl]=v,_[fl]=o>>1;
			}
		}
		if(!C[u]&&!fl){
			puts("-1");return;
		}
		if(!C[u])C[u]=1;
		F(i,1,fl){
			O[_[i]]=w;
			C[st[i]]=3-C[u];
		}
	}
	F(i,1,n){
		if(C[i]==1)printf("W");else printf("B");
	}
	puts("");
	F(i,1,m){
		if(O[i])priE(O[i]);else priE(1000000000);
	}
}

int main()
{
	int T=1; //read(T);
	while(T--)_Sol_();
}

Measured memory_bytes: 19968
IDENTIFICATION DIVISION.
PROGRAM-ID. 161C.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP        PIC X(41).
01 NX         PIC X(19).
01 KX         PIC X(19).
01 N          PIC 9(18) COMP.
01 K          PIC 9(18) COMP.
01 S          PIC 9(18) COMP.
01 A          PIC 9(18) COMP.
01 ANS        PIC Z(17)9.
*>
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO NX KX.
*>
    EVALUATE TRUE
      WHEN NX = '1000000000000000000' AND
           KX = '1000000000000000000'
        MOVE 1 TO N
        MOVE 1 TO N
      WHEN NX = '1000000000000000000'
        MOVE KX TO K
        COMPUTE N = 999999999999999999 - K + 1
      WHEN KX = '1000000000000000000'
        MOVE NX TO N
        COMPUTE K = 500000000000000000
      WHEN OTHER
        MOVE NX TO N
        MOVE KX TO K
    END-EVALUATE.
 
    DIVIDE N BY K GIVING S REMAINDER A
    EVALUATE TRUE
      WHEN A = 0
        MOVE 0 TO ANS
      WHEN A <= K / 2
        MOVE A TO ANS
      WHEN OTHER
        COMPUTE ANS = K - A
    END-EVALUATE.
*>
  DISPLAY FUNCTION TRIM(ANS).
  STOP RUN.


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

void fnLinkedListSet(list<int> &a_rltiNumber)
{
  list<int>::iterator itlti;
  list<int>::iterator itltEND = a_rltiNumber.end();
  char acCommand[80];
  int iMaxCommand, iNumber;

  cin.tie(0);
  ios::sync_with_stdio(false);
 
  cin >> iMaxCommand;
  for (int i = 0; i < iMaxCommand; i++)
  {
    cin >> acCommand;
    if (acCommand[0] == 'i')
    {
      cin >> iNumber;
      a_rltiNumber.push_front(iNumber);
    }
    else if (acCommand[6] == 'F')
      a_rltiNumber.pop_front();
    else if (acCommand[6] == 'L')
      a_rltiNumber.pop_back();
    else if (acCommand[0] == 'd')
    {
      cin >> iNumber;
      for (itlti = a_rltiNumber.begin(); itlti != itltEND; ++itlti)
        if (*itlti == iNumber)
        {
          a_rltiNumber.erase(itlti);
          break;
        }
    }
  }
}

void fnLinkedListGet(const list<int> &a_cnrltiNumber)
{
  list<int>::const_iterator itlti;
  list<int>::const_iterator itltEND = a_cnrltiNumber.end();

  for (itlti = a_cnrltiNumber.begin(); itlti != itltEND; ++itlti)
  {
    if (itlti != a_cnrltiNumber.begin()) cout << " ";
    cout << *itlti;
  }
  cout << endl;
}

int main()
{
  list<int> ltiNumber;
  fnLinkedListSet(ltiNumber);
  fnLinkedListGet(ltiNumber);

  return 0;
}

Measured memory_bytes: 32464
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int n; cin >> n;
  vector<int> h(n);
  REP(i, n) cin >> h[i];
  int ans = 1, mx = h[0];
  FOR(i, 1, n) {
    if (mx <= h[i]) { 
      ans++;
      mx = h[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
#include<stdlib.h>
int main(void){
    double v,t,y;
    int floor;

    while(scanf("%lf",&v)!=EOF){;
        t=v/9.8;
        y=4.9*t*t;
        floor=ceil((y+5)/5);
    
        printf("%d\n",floor);
  
    }
}


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

typedef long long ll;

ll k,a,b;

int main(){
	cin >> k >> a >> b;
	/**Aが実行できるまでたたく*/
	ll n1 = a-1;
	ll n2 = (k-n1)/2;
	ll n3 = (k-n1)%2;
	
	if(b-a>=2){
		cout << a+n2*(b-a)+n3;
	}else{
		cout << 1+k;
	}
	
	return 0;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

int f(int x, int y) {
    if (x <= y) {
        int r = y - x;
        if (x < 0 && y > 0) r -= min(-x, y) * 2 - 1;
        return r;

    } else {
        if (abs(x) < abs(y)) {
            return f(x, -y) + 1;
        } else {
            return 1 + f(-x, y);
        }
    }
}

int main() {
    int x, y;
    cin >> x >> y;

    cout << f(x, y) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int[] array = new int[3];
        
        array[0] = Math.abs(a - b);
        array[1] = Math.abs(b - c);
        array[2] = Math.abs(c - a);
        Arrays.sort(array);
        System.out.println(array[0] + array[1]);
    }    
}


Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>

using namespace std;


int main() {
    string s;
    int w;
    cin >> s;
    cin >> w;
    
    string ret = "";
    for (int i = 0; i < s.size(); i += w)
    {
        ret += s[i];
    }
    
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 256
x, y, a, b, c = map(int, input().split())
red = [int(x) for x in input().split()]
green = [int(x) for x in input().split()]
red.sort(reverse=True)
green.sort(reverse=True)
candidates = [int(x) for x in input().split()] + red[:x] + green[:y]
candidates.sort(reverse=True)
print(sum(candidates[:x+y]))

Measured memory_bytes: 22592
import java.util.Scanner;

public class Main {

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

		String s = sc.next();
		int a = Integer.parseInt(s.substring(0,2));
		int b = Integer.parseInt(s.substring(2,4));
		boolean yymm = 1<=b && b<=12;
		boolean mmyy = 1<=a && a<=12;
		
		if (yymm) {
			if (mmyy) {
				System.out.println("AMBIGUOUS");
			} else {
				System.out.println("YYMM");
			}
		} else {
			if (mmyy) {
				System.out.println("MMYY");
			} else {
				System.out.println("NA");
			}
		}
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

struct item {
	int value;
	int weight;
	item(int v = 0, int w = 0) {
		value = v; weight = w;
	}
};

const int MAX_W = 10010;
const int MAX_N = 101;

int main() {
	int N, W;
	cin >> N >> W;
	vector<item> items(N, 0);
	for(int i = 0; i < N; ++i) {
		int v, w;	
		cin >> v >> w;	
		items[i] = item(v, w);
	}

	int dp[MAX_W];
	fill_n((int *)dp, MAX_W, 0);	

	for(int w = 0; w <= W; ++w) {
		for(int i = 0; i < N; ++i) {
			if(w < items[i].weight) {
				dp[w] = dp[w];
			} else {
				dp[w] = max(dp[w], dp[w - items[i].weight] + items[i].value);		
			}	
		}
	}
	
	cout << dp[W] << endl;
	return 0;
}

Measured memory_bytes: 1236
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef unsigned int uint;
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

const int MX = 1<<19;
const int MM = 998244353;

char D[MX];
int main()
{
	int n;
	scanf("%s", D+1);
	n = strlen(D+1);
	if(D[n] == '1' || D[1] == '0') return !printf("-1\n");
	for(int i = 1; i <= n-1; i++){
		if(D[i] != D[n-i]) return !printf("-1\n");
	}

	int cur = 1, root = 1;
	for(int i = 1; i < n; i++){
		if(D[i] == '1'){
			printf("%d %d\n", ++cur, root);
			root = cur;
		}
		else{
			printf("%d %d\n", ++cur, root);
		}
	}
}


Measured memory_bytes: 1536
# 解説AC
# 素直に立式してから因数分解
# そこから愚直に計算せず線形時間でできるように考える
MOD = 10**9 + 7


def main():
    N, M = (int(i) for i in input().split())
    X = [int(i) for i in input().split()]
    Y = [int(i) for i in input().split()]
    xl = 0
    yl = 0
    for i, x in enumerate(X):
        xl += i*x - (N-i-1)*x
    for i, y in enumerate(Y):
        yl += i*y - (M-i-1)*y
    ans = xl*yl
    ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 83044
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[1111];
signed main(){
  int n,w,cnt=0;
  while(cin>>n>>w,n||w){
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    int INF=1LL<<55LL;
    fill_n(dp,n+1,INF);
    dp[0]=0;
    int ans=INF;
    for(int i=0;i<n;i++){
      int tmp=0;
      for(int j=i;j<n;j++){
	tmp+=a[j];
	dp[j+1]=min(dp[j+1],dp[i]+abs(tmp-w));
	if(j+1==n) ans=min(ans,dp[i]+max(0LL,tmp-w));
      }
    }
    cout<<"Case "<<++cnt<<": "<<ans<<endl;
  }
  return 0;
}

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

// using namespace std;
// using ll = long long;

// const int mod = 1000000007;
// struct mint {
//   ll x;
//   mint(ll x = 0) : x(x % mod) {}
//   mint operator-() const { return mint(-x); }
//   mint& operator+=(const mint a) {
//     if ((x += a.x) >= mod) {
//       x -= mod;
//     }
//     return *this;
//   }
//   mint& operator-=(const mint a) {
//     if ((x += mod - a.x) >= mod) {
//       x -= mod;
//     }
//     return *this;
//   }
//   mint& operator*=(const mint a) {
//     (x *= a.x) %= mod;
//     return *this;
//   }
//   mint operator+(const mint a) const {
//     mint res(*this);
//     return res += a;
//   }
//   mint operator-(const mint a) const {
//     mint res(*this);
//     return res -= a;
//   }
//   mint operator*(const mint a) const {
//     mint res(*this);
//     return res *= a;
//   }
//   mint pow(ll t) const {
//     if (!t) {
//       return 1;
//     }
//     mint a = pow(t >> 1);
//     a *= a;
//     if (t & 1) {
//       a *= *this;
//     }
//     return a;
//   }

//   mint inv() const { return pow(mod - 2); }
//   mint& operator/=(const mint a) { return (*this) *= a.inv(); }
//   mint operator/(const mint a) const {
//     mint res(*this);
//     return res /= a;
//   }
// };

// mint f(int n) {
//   if (n == 0) {
//     return 1;
//   }
//   mint x = f(n / 2);
//   x *= x;
//   if (n % 2 == 1) {
//     x *= 2;
//   }
//   return x;
// }
// mint choose(int n, int a) {
//   mint x = 1, y = 1;
//   rep(i, a) {
//     x *= n - i;
//     y *= i + 1;
//   }
//   return x / y;
// }
// int main() {
//   int n, a, b;
//   cin >> n >> a >> b;
//   mint ans = f(n);
//   ans -= 1;
//   ans -= choose(n, a);
//   ans -= choose(n, b);
//   cout << ans.x << endl;
//   return 0;
// }

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll MOD = 1000000007;

ll mod_pow(ll n, ll x) {
  if (x == 0) return 1;
  if (x == 1) return n;
  ll v = mod_pow(n, x/2);
  v *= v;
  v %= MOD;
  if (x%2 == 1) v *= n;
  return v % MOD;
}

ll mod_inv(ll a) {
  return mod_pow(a, MOD - 2) % MOD;
}

ll nck(ll n, ll k) { 
  ll x = 1, y = 1;
  for (ll i = 0; i < k; i++) {
    x *= n-i;
    x %= MOD;
    y *= mod_inv(i+1);
    y %= MOD;
  }
  return (x * y) % MOD;
}

int mod(ll n) {
  n %= MOD;
  if (n < 0) n += MOD;

  return n;
}

int main()
{
  ll n, a, b;
  cin >> n >> a >> b;
  ll v = mod_pow(2, n) - nck(n, a) - nck(n, b) - (ll)1;
  cout << mod(v) << endl;
  
  return 0;
}


Measured memory_bytes: 3640
import java.util.*;

public class Main {

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

		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n==0 && m==0) break;
			
			int[][] map = new int[n][n];
			int[][][] piece = new int[4][m][m];
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					map[i][j] = sc.nextInt();
				}
			}
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					piece[0][i][j] = sc.nextInt();
					piece[1][j][m-1-i] = piece[0][i][j];
					piece[2][m-1-i][m-1-j] = piece[0][i][j];
					piece[3][m-1-j][i] = piece[0][i][j];
				}
			}
			
			int count;
			int x = -1;
			int y = -1;
			int z = -1;
			for(int p=0;p<=n-m;p++){
				for(int q=0;q<=n-m;q++){
					for(int k=0;k<4;k++){
						count = 0;
						for(int i=0;i<m;i++){
							for(int j=0;j<m;j++){
								if(piece[k][i][j]==-1){
									count++;
								}else{
									if(piece[k][i][j]==map[p+i][q+j]) count++;
									else{
										i = m;
										j = m;
									}
								}
							}
						}
						if(count==m*m){
							y = p;
							x = q;
							z = k;
							k = 4;
							p = n;
							q = n;
						}
					}
				}
			}
			
			if(x==-1){
				System.out.println("NA");
			}else{
				for(int i=0;i<m;i++){
					for(int j=0;j<m;j++){
						if(piece[z][i][j]!=-1){
							System.out.println((x+j+1) + " " + (y+i+1));
							i = m;
							j = m;
						}
					}
				}
			}
				
		}
	}
}

Measured memory_bytes: 71204
#include <cstdio>
#include <vector>
using namespace std;

typedef long long int lli;
typedef pair<lli, int> pli;
long long int n, s;
const int SIZE = 400005;
bool isPrime[SIZE];
vector<pli> v;
lli INF = 12345987654321;
lli ans = INF, tmp=1;

void check(int p){
	if(p == v.size()){
		lli b = tmp+1, t=n, sum=0;
		while(t){
			sum += t % b;
			t /= b;
		}
		if(sum == s && b < ans)
			ans = b;
		return;
	}
	lli save = tmp;
	for(int i=0; i<=v[p].second; ++i){
		check(p+1);
		tmp *= v[p].first;
	}
	tmp = save;
}

int main(){
	scanf("%lld%lld", &n, &s);	
	long long int t = n - s;
	if(t == 0){
		printf("%lld\n", n+1);
		return 0;
	}
	for(int i=2; i<SIZE; ++i)
		isPrime[i] = true;
	for(lli i=2; i<SIZE; ++i){
		if(isPrime[i]){
			for(lli j=i*i; j<SIZE; j+=i)
				isPrime[j] = false;
			int cnt=0;
			while(t % i == 0){
				++cnt;
				t /= i;
			}
			if(cnt)
				v.push_back({i, cnt});
		}
	}
	if(t > 1)
		v.push_back({t, 1});
	check(0);
	if(ans == INF)
		ans = -1;
	printf("%lld\n", ans);
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>

using namespace std;

int a,b;
int s;
int Count;
int main(){
  while(scanf("%d %d",&a,&b) != EOF){
    s = a+b;
  Count = 0;
  for(; s != 0; s/=10){
    Count++;
  }
  printf("%d\n",Count);
  }
  return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
int n, a, b, c;
int l[10];
vector<int> A, B, C;
int res = INF;
//int cc = 0;
void dfs(int depth)
{
    if(depth==n){
        if(A.size() > 0 && B.size() >0 && C.size()){
            int suma = 0, sumb = 0, sumc = 0;
            REP(i,A.size()){
                suma += A[i];
            }
            REP(i,B.size()){
                sumb += B[i];
            }
            REP(i,C.size()){
                sumc += C[i];
            }
            int cnt = 10 * (A.size() + B.size() + C.size() - 3) + abs(a - suma) + abs(b - sumb) + abs(c - sumc);
            chmin(res, cnt);
        }
       // cc++;
        return;
    }
    for (int i = 0; i < 4;i++){
        if(i == 0){
            A.push_back(l[depth]);
            dfs(depth + 1);
            A.pop_back();
        }
        if (i == 1)
        {
            B.push_back(l[depth]);
            dfs(depth + 1);
            B.pop_back();
        }
        if (i == 2)
        {
            C.push_back(l[depth]);
            dfs(depth + 1);
            C.pop_back();
        }
        if(i == 3){
            dfs(depth + 1);
        }
    }
}

signed main()
{
    cin >> n >> a >> b >> c;
    REP(i,n){
    cin >> l[i];
    }
    dfs(0);
   // cerr << cc << endl;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import numpy as np
 
N,T = map(int,readline().split())
m = map(int,read().split())
AB = sorted(zip(m,m))
 
can_add = [0] * N
for n in range(N-1,0,-1):
    x = can_add[n]
    y = AB[n][1]
    can_add[n-1] = x if x > y else y
dp = np.zeros(T,np.int64)
 
answer = 0
for i,(a,b) in enumerate(AB):
    np.maximum(dp[a:], dp[:-a] + b, out = dp[a:])
    x = dp.max() + can_add[i]
    if answer < x:
        answer = x
print(answer)

Measured memory_bytes: 21924
use proconio::{
   fastout, input,
   marker::{Bytes, Chars, Isize1, Usize1},
};

fn main() {
   input! {
      n:usize,a:usize,b:usize
   }
   if a + b > n + 1 || a * b < n {
      println!("-1");
      return;
   }
   let mut remove = a * b - n;
   for i in (1..=b).rev() {
      print!("{} ", i);
   }
   let mut start = b;
   let mut prev = b;
   let mut count = b;
   while count < n {
      start = if start + b <= start + remove {
         start + 1
      } else {
         start + b - remove
      };
      remove -= b + prev - start;
      for i in (prev + 1..=start).rev() {
         print!("{} ", i);
         count += 1;
      }
      prev = start;
   }
   println!("");
}


Measured memory_bytes: 2372
// A - Frog 1
#include <bits/stdc++.h>
using namespace std;

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

	vector<int> h(n+1, INT_MAX);
	for(int i=0; i<n; i++) cin>>h[i];

	vector<int> dp(h.size());
	for(int i=dp.size()-3; i>=0; --i){
		dp[i] = min(dp[i+1] + abs(h[i]-h[i+1]), dp[i+2] + abs(h[i]-h[i+2]));
	}
	cout<< dp[0] <<endl;
}

Measured memory_bytes: 1024