akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}
std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;}


void solve(long long D, long long N){
    LL ans = N  * pow(100, D);
    if(D==0 && N==100)cout<<101<<endl;
    else if(D==1 &&N==100)cout<<10100<<endl;
    else if(D==2 && N==100)cout<<1010000<<endl;
    else cout<<ans<<endl;

}

int main(){
    long long D;
    scanf("%lld",&D);
    long long N;
    scanf("%lld",&N);
    solve(D, N);
    return 0;
}


Measured memory_bytes: 512
H,W = list(map(int,input().split(" ")))
a = [list(input()) for i in range(H)]
h = []
w = []
for i in range(0,H):
    if "#" not in a[i]:
        h+=[(i,j,) for j in range(W)]

for i in range(W):
    for j in range(H):
        if a[j][i] != ".":
            break
        else:
            w.append(i)
    if w.count(i) == H:
        h+=[(k,i) for k in range(H)]
r = []
for i in range(H):
    c =[]
    for j in range(W):
        if (i,j,) in h:
            continue
        else:
            c.append(a[i][j])
    r.append(c)
for i in r:
    if i != []:
        print("".join(i))


Measured memory_bytes: 4596
def main():
    N, M = map(int, input().split())
    a = [0] * (1 + 10 ** 5)
    for _ in range(M):
        a[int(input())] = 1
    dp = [0] * (N + 1)
    dp[0] = 1
    if not a[1]:
        dp[1] = 1

    for i in range(2, N + 1):
        if not a[i]:
            dp[i] += dp[i-1] + dp[i-2]
            dp[i] %= 1000000007

    print(dp[N])

main()


Measured memory_bytes: 45016
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int ll
using namespace std;
const int N = 3005;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll lowbit(ll x){return (x&-x);}
inline ll kissme(ll x,ll y)
{
	ll res=1;
	if(x==0)return 1;
	if(x==1)return y;
	res=kissme(x/2,y);
	res=res*res%mod;
	if(x%2==1)res=res*y%mod;
	return res;
}
int n,m,q;int dp[N][N][5];
int x[N][N];
inline bool ok(int x2,int y2){return (x2<=n&&y2<=m);}
signed main()
{
	Very_fast;
	cin>>n>>m>>q;
	while(q--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		x[a][b]=c;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			for(int k=0;k<=3;k++)
			{
				if(ok(i,j-1))
				{
					dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k]);
					if(k)dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k-1]+x[i][j]);
				}
				if(ok(i-1,j))
				{
					int mx=-1;
					for(int l=0;l<=3;l++)mx=max(dp[i-1][j][l],mx);
					dp[i][j][k]=max(mx,dp[i][j][k]);
					if(k)dp[i][j][1]=max(dp[i][j][1],mx+x[i][j]);
				}
			}
		}
	}
	cout<<max(max(dp[n][m][0],dp[n][m][1]),max(dp[n][m][2],dp[n][m][3]))<<"\n";
	return 0;
}

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

int S(int x){
  int k=0;
  while(x >0){
    k++;
    x /= 10;
  }
  return k;
}

bool func(int x,vector<int> d){
  bool y = true;
  int k=x,n=d.size();
  int m = S(x);
  vector<int> z(m);
  for(int i=0;i<m;i++){
    z.at(i) = k%10;
    k = k/10;
  }
  for(int i=0;i<m;i++){
    for(int j=0;j<n;j++){
      if(z.at(i) == d.at(j)){
        y = false;
        break;
      }
    }
    if(!y){
      break;
    }
  }
  
  return y;
}

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> d(k);
  for(int i=0;i<k;i++){
    cin >> d.at(i);
  }
  int ans = n;
  while(!func(ans,d)){
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	sort(s.begin(),s.end());
	if(s[0]==s[1] && s[2]==s[3] && s[1]!=s[2]){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int N_MAX = 200000;
int main()
{
  int n,t,i;
  int a[N_MAX];
  long long res=0;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> a[i];
    a[i]-=i+1;
  }
  sort(a,a+n);
  for(i=0;i<n;i++)
    res+=abs(a[i]-a[n/2]);
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M =1000000007;
//MOD??
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}
ll mpow(ll x, ll n){ //x^n(mod M) ????pow(x,n)?????????????mod??
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
int main (){
  ll i,a,b,c,k;
  cin>>a>>b>>c>>k;
  if(a>=k){
    cout<<k<<endl;
  }
  else if(a+b>=k){
    cout<<a<<endl;
  }
  else {
    cout<<2*a-k+b<<endl;
  }
  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[100],b[100],ans;
  for(int i=0; i<7; i++){
	cin >> a[i];
	cin >> b[i];
  }
  for(int i=0; i<7; i++){
	ans = a[i] - b[i];
	cout << ans << endl;
  }
  return 0;
}
  


Measured memory_bytes: 3104
from sys import setrecursionlimit
setrecursionlimit(1000000) 
N = int(input())
H = list(map(int, input().split()))


def memoize(f):
    cache = {}
    def helper(x):
        if x not in cache:
            cache[x] = f(x)
        return cache[x]
    return helper


@memoize
def jump(i):
    if i == 0:
        return 0
    a = abs(H[i] - H[i - 1]) + jump(i - 1)
    if i == 1:
        return a
    b = abs(H[i] - H[i - 2]) + jump(i - 2)
    return min(a, b)

print(jump(N - 1))


Measured memory_bytes: 207440
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	printf("%d\n",a^b^c);
	return 0;
}


Measured memory_bytes: 256
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=nl()

s = 0

for i in range(n):
  s ^= a[i]
for i in range(n):
  a[i] ^= s
  print(a[i])


Measured memory_bytes: 31520
#include "bits/stdc++.h"

using namespace std;
int main() {
	long long N, M, K;
	cin >> N >> M >> K;
	vector<long long>A(N+1);
	vector<long long>B(M+1);
	for (int n = 0;n<N;++n) {
		int m = 0;
		cin >>m;
		A[n + 1] = A[n] + m; 
	}
	for (int n = 0; n < M; ++n) {
		int m = 0;
		cin >> m;
		B[n + 1] = B[n] + m; 
	}
	int ans = 0;
	int subM = M;
	for (int n = 0;n<=N;++n) {
		for (int m = subM;m>=0;--m) {
			if (A[n] + B[m] <= K) {
				ans = max(ans,n+m);
				subM = m;
				break;
			}
		}
	}
	cout <<ans <<endl;
	return 0;
}


Measured memory_bytes: 6420
import numpy as np
from numba import njit, i8

n, k = map(int, input().split())
arr = np.array(list(map(int, input().split())))


@njit(i8[:](i8, i8, i8[:]), cache=True)
def solve(n, k, arr):
    for i in range(min(k, 50)):
        tmp_arr = np.zeros(n + 2, np.int64)
        for i, power in enumerate(arr):
            tmp_arr[max(0, i - power + 1)] += 1
            tmp_arr[min(n + 1, i + power + 2)] -= 1
        arr = np.cumsum(tmp_arr)[1:-1]
    return arr


print(*solve(n, k, arr))

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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
const long long INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/


int main() {
  int n;
  cin >> n;
  cout << 111 * (1 + (n - 1) / 111) << endl;
}


Measured memory_bytes: 256
N = int(input())
A=[]
for _ in range(N):
    x,l = map(int,input().split())
    A.append([x-l,x+l])
A = sorted(A, key=lambda x:x[1])
now = -10**10
cnt = 0
for x in A:
    if now <= x[0]:
        now = x[1]
        cnt+=1
print(cnt)



Measured memory_bytes: 26320
#include<bits/stdc++.h>
using namespace std;
const int MAX = 2e5 ;
const int INF = 1e9 + 1e5 + 2;
const int mod= 1e9+7;
using namespace std;
int main()
{
    string s;
    int q;

    cin>>s;
    deque<char>d;
    for (int i=0; i<s.size(); ++i)
    {
        d.push_back(s[i]);
    }

    cin>>q;

    int t,c;
    char h;
    bool b=0;

    while(q--)
    {
        cin>>t;
        if (t==1)
            b=!b;
        else
        {
             cin>>c>>h;
             if (c==1)
             {
                if (b)
                    d.push_back(h);
                else
                    d.push_front(h);
             }
             else
             {
                 if (b)
                    d.push_front(h);
                 else
                    d.push_back(h);
             }

        }
    }
    if (!b)
    {
        for (auto it=d.begin(); it!=d.end(); ++it)
            cout<<*it;

    }
    else
    {
        for (auto it=d.rbegin(); it !=d.rend(); ++it)
            cout<<*it;

    }




}


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

#define int long long

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

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int n, m, k, res = 0;
	cin >> n >> m >> k;

	vector<int> a(n + 1), b(m + 1);
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		a[i] += a[i - 1];
	}
	for (int j = 1; j <= m; ++j) {
		cin >> b[j];
		b[j] += b[j - 1];
	}

	int idx = m;
	for (int i = 0; i <= n; ++i) {
		if (a[i] > k)
			break;

		while (a[i] + b[idx] > k)
			--idx;

		res = max(res, i + idx);
	}

	cout << res;

	return 0;
}

Measured memory_bytes: 6372
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  int d_1;
  d_1=a[2]-a[1];
  int b;
  b=a[0]+d_1;
  int d_2;
  if((a[2]-b)%2==0){
  d_2=(a[2]-b)/2;
  }
  else{
  d_2=(a[2]-b)/2+2;
  }
  int ans;
  ans=d_1+d_2;
  cout<<ans;
  return 0;
}

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

int selectionSort(int A[], int N) {
    int count = 0;
    for (int  i = 0; i < N; i++) {
        int minj = i;
        for (int j = i; j < N; j++) {
            if (A[j] < A[minj]) {
                minj = j;
            }
        }
        if (minj != i) {
            swap(A[i], A[minj]);
            count++;
        }
    }
    return count;
}

int main() {
    int N;
    int A[110];
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];

    int count = selectionSort(A, N);

    for (int i = 0; i < N; i++) {
        if (i == N-1) cout << A[i] << endl;
        else cout << A[i] << " ";
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    if (a > 2*b){
        cout << a-2*b << endl;
    }
    else {
        cout << "0" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
using namespace std;
#define vel vector<long long>
#define vvel vector<vel>
#define int long long
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
long long p = 998244353;
vel kai(4001, 1);
vel ink(4001, 1);
int le = (1 << 20) + 1;
vel BIT(le, 0);
vel uni(vel &list) {
	if (list.size() == 0) { return list; }
	sort(list.begin(), list.end());
	vel ql(1, list[0]);
	rep(i, list.size() - 1) {
		if (list[i] != list[i + 1]) { ql.push_back(list[i + 1]); }
	}
	list = ql;
	return ql;
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a, p - 2);
}
void make_kai() {
	rep(i, 4000) { kai[i + 1] = (kai[i] * (i + 1)) % p; }
	rep(i, 4001) { ink[i] = inv(kai[i]); }
}
int com(int n, int r) {
	int ans = kai[n] * ink[r];
	ans %= p; ans *= ink[n - r]; ans %= p;
	return ans;
}
signed main() {
	int a, b; cin >> a >> b;
	if (a >= 13) { cout << b << endl; }
	else if (a >= 6) { cout << b / 2 << endl; }
	else { cout << 0 << endl; }
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    string ans;
    for(int i = 0;i < s.size();i++){
        if(s.at(i) == 'B'){
            if(ans.size() != 0)ans.erase(ans.size() - 1);
            else continue;
        }
        else ans += s.at(i);
        //cout << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
using namespace std;
const int N=200010;
struct A{
	int l,r,v;
}s[N];
int a[N];
int n;
bool check(int ans){
	int i,j,k,len=0;
	for(i=1;i<=n;i++){
		if(i==1){
			s[++len]=(A){1,a[i],1};
		}
		else{
			if(a[i]>a[i-1]) s[++len]=(A){a[i-1]+1,a[i],1};
			else{
				while(s[len].l>a[i]) len--;
				s[len].r=a[i];
				for(j=len;j>=1&&s[j].v==ans;j--);
				if(j==0) return false;
				if(s[j].r==s[j].l) s[j].v++;
				else{
					s[j+1]=(A){s[j].r,s[j].r,s[j].v+1};
					s[j++].r--;
				}
				if(s[j].r<a[i]) s[len=j+1]=(A){s[j].r+1,a[i],1};
				else len=j;
			}
		}
	}
	return true;
}
int main(){
	int lb,rb,mid,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",&a[i]);
	lb=0;rb=n;
	while(rb-lb>1){
		mid=lb+rb>>1;
		if(check(mid)) rb=mid;
		else lb=mid;
	}
	printf("%d",rb);
	return 0;
}


Measured memory_bytes: 3328
// Best practice

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <functional> // for less 

#define int         long long
#define pb          emplace_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

#define fbo find_by_order
#define ook order_of_key

signed main() {
   tezz
   
   int n,m,k;
   cin >> n >> m >> k;
   if(n==m && m==k){
       cout << "No" << endl;
   }
   else if(n==m || m==k || n==k){
       cout << "Yes" << endl;
   }
   else{
       cout << "No" << endl;
   }
  
   return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#pragma warning(disable:4996)
using namespace std;
#define N 3
#define N2 9

struct Puzzle {
	int f[N2];
	int space;
	string path;
	bool operator <(const Puzzle &p) const {
		for (int i = 0; i < N2; ++i) {
			if (f[i] != p.f[i]) return f[i] < p.f[i];
		}
		return false;
	}
};

bool isComplete(Puzzle p) {
	for (int i = 0; i < N2; ++i) {
		if (p.f[i] != i + 1) return false;
	}
	return true;
}

const int dx[4]{ -1, 0, 1, 0 };
const int dy[4]{ 0, -1, 0, 1 };
const char dir[4]{ 'u', 'l', 'd', 'r' };

string bfs(Puzzle p) {
	p.path = "";
	map<Puzzle, bool> M;
	M[p] = true;
	Puzzle u, v;
	queue<Puzzle> Q;
	Q.push(p);
	for (int i = 0; i < N2; ++i) {
		while (!Q.empty()) {
			u = Q.front();
			Q.pop();
			if (isComplete(u))
				return u.path;
			int sx = u.space / N;
			int sy = u.space % N;
			for (int r = 0; r < 4; ++r) {
				int tx = sx + dx[r];
				int ty = sy + dy[r];
				if (tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
				v = u;
				swap(v.f[u.space], v.f[tx * N + ty]);
				v.space = tx * N + ty;
				if (!M[v]) {
					M[v] = true;
					v.path += dir[r];
					Q.push(v);
				}
			}
		}
	}
	return "unresolved";
}

int main() {
	Puzzle p;
	for (int i = 0; i < N2; ++i) {
		scanf("%d", &p.f[i]);
		if (p.f[i] == 0) {
			p.f[i] = N2;
			p.space = i;
		}
	}
	string ans = bfs(p);
	cout << ans.size() << "\n";
	return 0;
}

Measured memory_bytes: 30636
import collections as co
n = int(raw_input())
aa = map(int, raw_input().split())

r = 0
d = co.Counter(aa).most_common()
for (a, count) in d:
    r += count - 1

if r % 2 == 0:
    print(len(d))
else:
    print(len(d) - 1)

Measured memory_bytes: 23912
N, L = gets.split.map(&:to_i)
taste_list = []

(1..N).each do |i|
  taste_list << L + i - 1
end

taste_by_all = taste_list.inject(:+)

ans = nil
before_gap = nil
N.times do |n|
  taste_sub_list = (n == 0 ? [] : taste_list[0..(n-1)]) + taste_list[(n+1)..-1]
  sub_sum = taste_sub_list.inject(:+)
  gap = (taste_by_all - sub_sum).abs
  
  if before_gap.nil?
    before_gap = gap
    ans = sub_sum
    next
  end
  
  if gap < before_gap
    ans = sub_sum
  end
  before_gap = gap
end

puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
//mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count());
//int rnd(int x) { return mrand()%x;}
typedef long long ll;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	int cnt=0;
	while(n){
		n/=k;
		cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String m[] = s.split("");
    int ans = 0;
    for (int i = 0; i < s.length(); i++){
      if (m[i].equals("+")){
        ans++;
      }else{
        ans--;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35604
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> temp(N);
    for(int i = 0; i < N; i++)
        cin >> temp[i];
    
    int count = 0;
    int coor = 0;
    for(int i = 0; i < N; i++) {
        coor += temp[i];
        if(coor <= X)
            count++;
    }

    cout << 1 + count << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(raw_input())
a=map(int,raw_input().split())
a.sort()
if n%2==0:
    i=0
    j=-1
    while i<n-1:
        j+=1
        if a[i]==a[i+1]==2*j+1:
            i+=2
            continue
        else:
            print(0)
            exit()
    print(pow(2,n/2,10**9+7))
else:
    i=1
    j=0
    while i<n-1:
        j+=1
        if a[i]==a[i+1]==2*j:
            i+=2
            continue
        else:
            print(0)
            exit()
    print(pow(2,(n-1)/2,10**9+7))


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

int main() {
     int N,  A,  b ;
     cin >>  N   >>  A ;
     
      b = N / 500 ;
      N = N - b * 500 ; 
      if ( N <= A){
            cout << "Yes" << endl;
       }
       else {
             cout << "No" << endl;
      }
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    cout<<s[0]<<int(s.size()-2)<<s[s.size()-1]<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
#define YES cout<<"YES"<<'\n'
#define NO cout<<"NO"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define yes cout<<"yes"<<'\n'
#define no cout<<"no"<<'\n'
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) cout << n << '\n';
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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 T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    VI a(n); REP(i,n) cin >> a[i];
    VI b(n); REP(i,n) cin >> b[i];
    VI c(n-1); REP(i,n-1) cin >> c[i];

    int ans = b[0];
    FOR(i,1,n){
        if(a[i-1]+1==a[i]) ans+=c[a[i-1]-1];
        ans+=b[i];
    }
    out(ans);

    return 0;
}

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

int main() {
	int a1, a2, a3, a4, b1, b2, b3, b4;
	while (cin >> a1 >> a2 >> a3 >> a4 >> b1 >> b2 >> b3 >> b4) {
		int hit = 0, blow = 0;
			if (a1 == b1)hit++;if (a2 == b2)hit++;
			if (a3 == b3)hit++;if (a4 == b4)hit++;
			if (a1 == b2 || a1 == b3 || a1 == b4)blow++;
			if (a2 == b1 || a2 == b3 || a2 == b4)blow++;
			if (a3 == b1 || a3 == b2 || a3 == b4)blow++;
			if (a4 == b1 || a4 == b2 || a4 == b3)blow++;
			cout << hit << " " << blow << endl;
	}
	return 0;
}

Measured memory_bytes: 3020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <unordered_map>

#define MIN(a,b) (a)>(b)?(b):(a)

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> H(N);

	for (int i = 0, h; i < N; i++) {
		cin >> h;
		H[i] = h;
	}

	for (int i = N - 1; i >= 1; i--) {
		if (H[i - 1]-1> H[i]) {
			cout << "No";
			return 0;
		}
		else if(H[i - 1]>H[i]){
			H[i - 1]--;
		}
	}
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 5e5+5, rt = 1000;

int a[sz], cnt[sz], ans[sz], now;

struct dtt {
   int l, r, id;
} quers[sz];

bool cmp(dtt a, dtt b) {
   if(a.l / rt == b.l / rt) return a.r < b.r;
   return a.l < b.l;
}

inline void add(int x) {
   if(!cnt[a[x]]) now++;
   cnt[a[x]]++;
}

inline void del(int x) {
   cnt[a[x]]--;
   if(!cnt[a[x]]) now--;
}

int main() {
   int n, q;
   scanf("%d %d", &n, &q);
   for(int i=0; i<n; i++) scanf("%d", &a[i]);
   for(int i=0; i<q; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      quers[i] = {x-1, y-1, i};
   }
   sort(quers, quers+q, cmp);

   for(int i=0, l=0, r=-1; i<q; i++) {
      while(l < quers[i].l) del(l++);
      while(quers[i].l < l) add(--l);
      while(r < quers[i].r) add(++r);
      while(quers[i].r < r) del(r--);
      ans[quers[i].id] = now;
   }
   for(int i=0; i<q; i++) printf("%d\n", ans[i]);
}


Measured memory_bytes: 15436
s = input()
n = len(s)
def check(x):
    p = len(x)
    a = x[:p//2]
    b = x[p//2:]
    return a == b
for i in range(n-2,-1,-1):
    if check(s[:i+1]):
        print(len(s[:i+1]))
        break
    

Measured memory_bytes: 38704
'use strict'

function main(input) {

    input = input.split(/\n/).map(v => v.split(''))

    let ans = ''
    for (let i = 0; i < 3; i++) {
        ans += input[i][i]

    }
    console.log(ans)

}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)


typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            cout<<x<<"/"<<y<<endl;
            return;
        }
    }
    cout<<"nun"<<endl;
}
//////////////////////////




int main(){fastio
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll dp[n][3];
    rep(i,0,n-1)rep(j,0,2)dp[i][j]=-inf;
    rep(j,0,2){
        if(j<=n-1)dp[j][j]=a[j];
    }
    rep(i,0,n-1){
        rep(j,0,2){
            rep(k,0,2){
                if(i+2+k<=n-1&&j+k<=2)chmax(dp[i+2+k][j+k],dp[i][j]+a[i+2+k]);
            }
        }
    }
    /*
    rep(i,0,n-1){
        rep(j,0,2)cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/
    ll ans=-inf;
    if(n%2==0){
        chmax(ans,dp[n-1][1]);
        chmax(ans,dp[n-2][0]);
    }else{
        chmax(ans,dp[n-1][2]);
        chmax(ans,dp[n-2][1]);
        chmax(ans,dp[n-3][0]);
    }
    cout<<ans<<endl;
    
    
    return 0;
}



Measured memory_bytes: 9944
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())

using namespace std;
typedef long long  ll;
const int N = 1e5 + 4;

ll memo[N][2];
int n;
vector<int> a;

ll solve(int indx , bool t){
    if(indx == n)
        return 0;

    ll &ret = memo[indx][t];
    if(~ret)
        return ret;

    ll toadd = (t ? -a[indx] : a[indx]);
    ret = -LLONG_MAX;
    if(indx < n - 1)ret = max(ret , -1 * toadd + solve(indx + 1 , true));
    ret = max(ret , toadd + solve(indx + 1 , false));
    return ret;
}

int main(){
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    cin >> n;
    a.resize(n);
    for(int &x : a)
        cin >> x;
    memset(memo , -1 , sizeof memo);
    cout << solve(0 , 0) << "\n";
 }


Measured memory_bytes: 6912
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	long H = rei();
	long W = rei();
	long X = rei();
	long Y = rei();
	double ans = H*W;
	ans /= 2;
	cout << ans << " ";
	if(X*2 == H && Y*2 == W){
		cout << 1 << endl;
	}
	else{
		cout << 0 << endl;
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

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

int main(){
    int X;
    cin>>X;
    if(X>=400&&X<=1999){
        if(X>=400&&X<=599){
            cout<<8;
        }
        else if(X>=600&&X<=799){
            cout<<7;
        }
        else if(X>=800&&X<=999){
            cout<<6;
        }
        else if(X>=1000&&X<=1199){
            cout<<5;
        }
        else if(X>=1200&&X<=1399){
            cout<<4;
        }
        else if(X>=1400&&X<=1599){
            cout<<3;
        }
        else if(X>=1600&&X<=1799){
            cout<<2;
        }
        else if(X>=1800&&X<=1999){
            cout<<1;
        }
        
    }
}

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

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

  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  int alice = 0;
  int bob = 0;

  if (N % 2 == 0) {
    for (int i = 0; i < N / 2; i++) {
      alice += a[2 * i];
      bob += a[2 * i + 1];
    }
  cout << alice - bob << endl;
  }

  else {
    for (int i = 0; i < N / 2; i++) {
      alice += a[2 * i];
      bob += a[2 * i + 1];
    }
  cout << alice + a[N - 1] - bob << endl;
  }
}

Measured memory_bytes: 3584
def resolve():
  x = input()
  a = int(x[0])
  b = int(x[1])
  c = int(x[2])
  d = int(x[3])
  for i in range(2):
    ans1 = str(a)
    sum1 = a
    if i == 0:
      sum1 -= b
      ans1 += "-" + str(b)
    else:
      sum1 += b
      ans1 += "+" + str(b)
    for j in range(2):
      ans2 = ans1
      sum2 = sum1
      if j == 0:
        sum2 -= c
        ans2 += '-' + str(c)
      else:
        sum2 += c
        ans2 += '+' + str(c)
      for k in range(2):
        sum3 = sum2
        ans3 = ans2
        if k == 0:
          sum3 -= d
          ans3 += '-' + str(d)
        else:
          sum3 += d
          ans3 += '+' + str(d)
        if sum3 == 7:
          print(ans3 + "=7")
          return
  return

if __name__ == "__main__":
  resolve()


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

int main()
{
  long long a;
  long long b;
  long long c;
  scanf("%lld %lld.%lld", &a, &b, &c);
  long long res = a * (b * 100 + c) / 100;
  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 3844
#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 FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  int cnt = 0;
  int stat = 0;
  while(true){
    if(stat==1){
      cout << cnt << '\n';
      break;
    }
    stat = a[stat]-1;
    cnt++;
    if(cnt>n){
      cout << -1 << '\n';
      break;
    }
  }
  return 0;
}


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

using ll = long long;

const int maxn = 1e5 + 5;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int tc = 1;
    //cin >> tc;
    while(tc--) {
        ll n;
        cin >> n;
        string res = "";
        while(n) {
            n--;
            int d = n % 26;
            if(d < 0) d += 26;
            char c = 'a' + d;
            res = res + c;
            n /= 26;
        }
        reverse(res.begin(), res.end());
        cout << res << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define INF 0x7fffffff
#define LL_INF 0x7fffffffffffffff
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

int main(void)
{
	int L; cin >> L;
	double ans = 1;
	for(int i=0;i<3;i++) ans *= (double)L / 3;
	printf("%.10lf\n", ans);

	return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input!(n: usize, a: [u32; n]);
    let mut ans = 0u64;
    let mut r = 0;
    let mut now = 0;
    for l in 0..n {
        while r < n && now & a[r] == 0 {
            now ^= a[r];
            r += 1;
        }
        ans += (r - l) as u64;
        now ^= a[l];
    }
    println!("{}", ans);
}


Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool isPrime(int n)
{
    if (n < 2)
    {
        return false;
    }
    else
    {
        for (int i = 2; i * i <= n; i++)
        {
            if (n % i == 0)
            {
                return false;
            }
        }
        return true;
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int Q;
    cin >> Q;
    vector<int> left(Q), right(Q);
    for (int i = 0; i < Q; i++)
    {
        cin >> left[i] >> right[i];
    }

    vector<bool> prime_number(100010, false);
    for (int i = 1; i <= 100000; i++)
    {
        if (isPrime(i))
        {
            prime_number[i] = true;
        }
    }

    vector<int> rui(100001, 0); //2017に似た数の個数を累積和
    for (int i = 0; i < 100000; i++)
    {
        if ((i + 1) % 2 && isPrime(i + 1) && isPrime((i + 2) / 2))
        {
            rui[i + 1] = rui[i] + 1;
        }
        else
        {
            rui[i + 1] = rui[i];
        }
    }

    for (int i = 0; i < Q; i++)
    {
        cout << rui[right[i]] - rui[left[i] - 1] << endl;
    }
}

Measured memory_bytes: 1792
import java.util.List;
import java.util.Scanner;
import java.util.Arrays;
public class Main {
	public static void main(String[] args) {
        Scanner sn = new Scanner(System.in);
        int n = Integer.parseInt(sn.next());

        if (400 <= n && n <= 599){
          System.out.println(8);
        }else if (600 <= n && n <= 799){
            System.out.println(7);
        }else if (800 <= n && n <= 999){
            System.out.println(6);
        }else if (1000 <= n && n <= 1199){
            System.out.println(5);
        }else if (1200 <= n && n <= 1399){
            System.out.println(4);
        }else if (1400 <= n && n <= 1599){
            System.out.println(3);
        }else if (1600 <= n && n <= 1799){
            System.out.println(2);
        }else if (1800 <= n && n <= 1999){
            System.out.println(1);
        }
    }
}

Measured memory_bytes: 35600
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) x.begin(),x.end()
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, n, m) for(int i = n; i >= m; i--)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;

int main(){

  int N,M;
  cin >> N>>M;
  ll ct=0;

  vector<pair<int,int>> he;

  rep(i,N){
    int a,b;
    cin>>a>>b;
    he.emplace_back(a,b);
  }

  SORT(he);

  multiset<int,greater<int>> x;

  int id=0;

  reps(i,1,M+1){
    if(id<N){
    while(he[id].first<=i){
      x.insert(he[id].second);
      id++;
      if(id>=N){
          break;
        }
      }
    }

    if(x.end() != x.begin()){
      auto itr=x.begin();
      ct+= *itr;
      x.erase(itr);
    }
  }

  cout << ct <<endl;
  return 0;
}


Measured memory_bytes: 5620
s = gets.chomp
t = gets.chomp
cs = []
if s.length != t.length
  puts 'No'
else
  if s == t
    puts 'Yes'
    exit
  end
  for i in 0...s.length do
    add = true
    cs.each do |c|
      if (c[0] == t[i] && c[1] == s[i]) || (c[0] == s[i] && c[1] == t[i])
        add = false
      elsif s[i] == c[1] || t[i] == c[0]
        puts 'No'
        exit
      end
    end
    cs << [t[i], s[i]] if add
  end
  puts 'Yes'
end

Measured memory_bytes: 4348
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(), (v).end()

int main(){
    string S;
    cin >> S;
    if(S[2]==S[3] && S[4]==S[5]){
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here
    int N;
    int i;
    long x=0;
    
    cin >> N;
    
    for(i=1;i<=N;i++){
        if(i%3==0||i%5==0){

        }else{
            x += i;
        }
    }
    
    cout << x << endl;
    
}


Measured memory_bytes: 3632
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] a = new int[n];
	for(int i=0; i<n; i++) {
		a[i] = sc.nextInt();
	}
	Arrays.sort(a);
	System.out.println(a[n-1] - a[0]);
}
}


Measured memory_bytes: 23892
import itertools
N, M, Q = map(int, input().split())
abcd = []
ans = 0
for i in range(Q):
  abcd.append(input())
for X in itertools.combinations_with_replacement(range(1, M + 1), N):
  tmp = 0
  for z in abcd:
    a, b, c, d = map(int, z.split())
    if X[b - 1] - X[a - 1] == c:
      tmp += d
  ans = max(ans, tmp)
print(ans)

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

int main() {
  int n;
  cin >> n;
  
  int l, r, people = 0;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    people += r - l + 1;
  }
  
  cout << people << endl;
}


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

using namespace std;

int main(){
    int n,max = 0;
    string s;

    cin >> n >> s;

    //cout << s << endl;

    for(int i=1; i<n; i++){
        string sub1 = s.substr(0, i);
        string sub2 = s.substr(i, n-i);

        //cout << sub1 << endl;
        //cout << sub2 << endl;

        string sub3="";
        int ns = 0;
        for(int j=0;j<i;j++){
            //cout << sub1[j] << endl ;
            if(string::npos==sub3.find(sub1[j])){
                //cout << "pass" << endl;
                sub3+=sub1[j];
                ns++;
            }
        }
        //cout << sub3 << endl<< endl;
        int maxsub = 0;
        for(int j=0;j<ns;j++){
            if(sub2.find(sub3[j])!=std::string::npos){
                maxsub++;
            }
        }
        if(max < maxsub){
            max = maxsub;
        }
    }

    cout << max << endl;

    return 0;
}

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

int n,p[250001];
int a[250001],z[250001];
vector<int>g[250002];
void cc(int o){
	queue<int>q;
	q.push(o);
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(int i=0;i<g[u].size();i++)
			if(a[g[u][i]]>a[u]+z[u]){
				a[g[u][i]]=a[u]+z[u];
				q.push(g[u][i]);
			}
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++)
		for(int j=1;j<=n;j++){
			int u=(i-1)*n+j,v=i*n+j;
			g[u].push_back(v);
			g[v].push_back(u);
		}
	for(int i=1;i<=n;i++)
		for(int j=1;j<n;j++){
			int u=(i-1)*n+j,v=(i-1)*n+j+1;
			g[u].push_back(v);
			g[v].push_back(u);
		}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			a[(i-1)*n+j]=min(min(i-1,n-i),min(j-1,n-j));
			z[(i-1)*n+j]=1;
		}
	n*=n;
	int ans=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&p[i]);
		z[p[i]]=0;
		ans+=a[p[i]];
		cc(p[i]);
	}
	printf("%d\n",ans);
}


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

const ll mod = 1e9+7;
const int maxn = 5e5+7;
int sum[maxn];
stack<int>sta;

std::vector<int> v;

int a[maxn];

int pre[maxn],pos[maxn];
ll dp[maxn];
 

int main (){
    int n;cin>>n;
    for(int i=0;i<n*2;i++) pre[i]=0;
    for(int i=1;i<=n;i++) cin>>a[i];
    stack<int>sta;
    for(int i=1;i<=n;i++){
        if(sta.empty()) sta.push(a[i]);
        else if(sta.top()!=a[i]) sta.push(a[i]);
    }
    int sz=sta.size();
    for(int i=sz;i>=1;i--) a[i]=sta.top(),sta.pop();
    for(int i=1;i<=sz;i++) pre[i]=pos[a[i]],pos[a[i]]=i;
    dp[0]=1;
    
    for(int i=1;i<=sz;i++){
        dp[i]=dp[i-1];
        if(pre[i]!=0) dp[i]=(dp[i]+dp[pre[i]])%mod;
    }
    cout<<dp[sz]<<endl;
    return 0;
}




Measured memory_bytes: 10652
<?php

    $A = intval(trim(fgets(STDIN)));
    $B = intval(trim(fgets(STDIN)));
    
    $ans =[1,2,3];
    
    $ans = array_diff($ans,array($A));
    $ans = array_diff($ans,array($B));
    
    echo $ans[array_rand($ans,1)];

?>

Measured memory_bytes: 16088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

struct I {
    ll l;
    ll r;
    bool operator<(const I& a) { return l < a.l; }
};

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<I> lr(n);
  REP(i, n) {
    cin >> lr[i].l >> lr[i].r;
  }
  SORT(lr);
  ll l1, l2, r1, r2;
  l1 = lr[0].l;
  r1 = lr[0].r;
  l2 = lr[1].l;
  r2 = lr[1].r;
  FOR(i, 2, n - 1) {
    ll l, r;
    l = lr[i].l;
    r = lr[i].r;
    ll p1, p2, p3;
    p1 = max(min(r1, r) - max(l1, l) + 1, (ll) 0) + max(r2 - l2 + 1, (ll) 0);
    p2 = max(min(r2, r) - max(l2, l) + 1, (ll) 0) + max(r1 - l1 + 1, (ll) 0);
    p3 = max(min(r1, r2) - max(l1, l2) + 1, (ll) 0) + max(r - l + 1, (ll) 0);
    if (p1 >= p2 && p1 >= p3) {
      r1 = min(r1, r);
      l1 = max(l1, l);
    } else if (p2 >= p1 && p2 >= p3) {
      r2 = min(r2, r);
      l2 = max(l2, l);
    } else if (p3 >= p1 && p3 >= p2) {
      r2 = min(r2, r1);
      l2 = max(l2, l1);
      r1 = r;
      l1 = l;
    }
  }
  ll ans = max(r1 - l1 + 1, (ll) 0) + max(r2 - l2 + 1, (ll) 0);
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 1792