akhauriyash/Code-Regression huggingface dataset:
/******************************************
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define fin for(int i = 0; i < n; i++)
#define fiab for(int i=a;i<b;i++)
#define fi1b for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
int m;
// long frog1(int i){
//  if(i>=n-1){
//      return 0;
//  }
//  else{
//      if(i<n-2){
//      return(min(abs(h[i+1]-h[i])+frog1(i+1),abs(h[i+2]-h[i])+frog1(i+2))); 
// }else if(i==n-2){
//  return(abs(h[n-1]-h[n-2])+frog1(n-1));


// }
// }}
LL max(LL a,LL b){
  return((a>b)?a:b);
}LL min(LL a,LL b){
  return((a<b)?a:b);
}
LL Abs(LL a){
  return(max(a,-a));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ios_base& scientific (ios_base& str);

  
     
int n,k;

     cin>>n; 
     LL dp[n+5][3];LL sum=0;
     LL a[n+5],b[n+5],c[n+5];
     fin{
        cin>>a[i]>>b[i]>>c[i];
     }
     for(int i=0;i<=n;i++){
        dp[i][0]=0;dp[i][1]=0;dp[i][2]=0;
     }
       
      dp[0][0]=a[0];dp[0][1]=b[0];dp[0][2]=c[0]; 
      for(int i=1;i<n;i++){
            dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
            dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
            dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
        } 
            sum=(dp[n-1][0]<dp[n-1][1])?(max(dp[n-1][1],dp[n-1][2])):max(dp[n-1][0],dp[n-1][2]);
      

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


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


int main(){
    int n, q;
    cin >> n;
    long S[n];
    for (int i=0; i<n; i++) {
        cin >> S[i];
    }   
    cin >> q;
    long T[q];
    for (int i=0; i<q; i++) {
        cin >> T[i];
    }   
    sort(T, T+q);
    long ans = 0;
    int Ti = 0;
    for (int i=0; i<n; i++) {
//      cerr << S[i] << " " <<Ti<< ":"<< T[Ti] << endl;
        if (S[i] == T[Ti]) {
            ans++;  
            Ti++;
        }
        else if (S[i] < T[Ti]) {
            continue;
        }
        else {
            i--;
            Ti++;
        }
        if (Ti >= q) break;
    }   
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4168
N, K = list(map(int,input().split()))
modlist = [0 for _ in range(K)]
for i in range(1, N + 1):  modlist[i % K] += 1
if K % 2:  print(modlist[0] ** 3)
else:  print(modlist[0] ** 3 + modlist[K // 2] ** 3)

Measured memory_bytes: 78460
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <functional>
# include <utility>
# include <queue>
# include <stack>
# define MOD 1000000007
# define INF 2000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	return x / gcd(x, y) * y;
}
int main() {
	int ans = 0, counter = 0, maxi = -1, mini = INF, pass = 0;
	//new
	int n1,m1;
	cin >> n1 >> m1;
	cout << lcm(n1, m1) << endl;
}

Measured memory_bytes: 256
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]

N, W = [int(x) for x in input().split()]

dp = [float('inf')] * 1000 * 100*10
vs = set()
vs.add(0)
dp[0] = 0

for i in range(N):
    w, v = [int(x) for x in input().split()]

    tmpDP = dp.copy()
    for vv in list(vs):
        if dp[vv + v] > dp[vv] + w:
            tmpDP[vv + v] = dp[vv] + w
            vs.add(vv + v)
    dp = tmpDP


ans = 0
for v in list(vs):
    if dp[v] <= W:
        ans = max(ans, v)
print(ans)


Measured memory_bytes: 27184
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,i,j,k,l,m,n,a[200005],b[200005];
    char s[200005],s1[200005];
    string ss;
    pair<int,int>p[200005];
    map<int,int>mp;
    long long int count=0,sum=0;
    cin>>n>>m>>k;
    if(m>=k)
    {
        sum=2*k;
        m=m-k;
        k=0;
        sum=sum+m;
    }
    else if(m<k)
    {
        sum=2*m;
        k=k-m;
        sum=sum+min(n,k);
        k=k-min(n,k);
    }
    if(k>=1)
    cout<<sum+1;
    else
    cout<<sum;
    return 0;
}

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

const int M=15;
const int INF=0x3f3f3f3f;
int c[M];
int a[M][M];

int main()
{
	int n,m,x;
	scanf("%d%d%d",&n,&m,&x);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&c[i]);
		for(int j=0;j<m;j++)
			scanf("%d",&a[i][j]);
	}
	int mask=1<<n;
	int ans=INF;
	for(int i=0;i<mask;i++)
	{
		int nans=0;
		for(int k=0;k<n;k++)
			if(i&(1<<k)) nans+=c[k];
		if(nans>=ans) continue;
		int f=1;
		for(int j=0;j<m;j++)
		{
			int sum=0;
			for(int k=0;k<n;k++)
				if(i&(1<<k)) sum+=a[k][j];
			if(sum<x)
			{
				f=0;
				break;
			}
		}
		if(f) ans=min(ans,nans);
	}
	printf("%d\n",ans==INF?-1:ans);
	return 0;
}

Measured memory_bytes: 3828
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int m = scan.nextInt();
    for (int i=0;i<m;i++){
      int k = scan.nextInt();
      n -= k;
      if (n<=0){
        System.out.println("Yes");
        return;
      }
    }
    System.out.println("No");
  }
}


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

int main() {
    int n, k; cin >> n >> k;
    vector<double> p(n);
    rep(i, n) {
        int tmp;
        double tmpb;
        cin >> tmp;
        if (i == 0)
            p.at(i) = (double)(tmp+1)/2;
        else
            p.at(i) = p.at(i-1) + (double)(tmp+1)/2;
    }
    int i;
    double ans = 0.0;
    for (i = (k-1); i < n; i++) {
        if (i == (k-1))
            ans = p.at(i);
        else
            ans = max(ans, p.at(i) - p.at(i-k));

    }
    //double ans = 0.0;
    //for (i = 0; i < k; i++) {
    //    ans += (double)(p.at(maxi+i)+1)/2;
    //}

    printf("%.12f\n", (double)ans);
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main (){
	int n;
	cin>>n;
	bool a = (n/1000==n%1000/100);
	bool b = (n%1000/100==n%1000%100/10);
	bool c = (n%1000%100/10==n%1000%100%10);
	if ( a && b ){
		cout <<"Yes"<<endl;
		}
	else if ( b && c){
		cout <<"Yes"<<endl;
	}
	else {
		cout <<"No"<<endl;
}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
typedef long long ll;

using namespace std;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    int ans = 1;
    for(int i = 0; i < n - 1; i++) {
        if(s[i] != s[i + 1]) {
            ans++;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 512
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=200000;
const int MAXLG=17;

int n,initcap;
int x[MAXN];
int prv[MAXN][MAXLG+2];
int nxt[MAXN][MAXLG+2];

int dpr[1<<(MAXLG+2)];
int dpl[1<<(MAXLG+2)];
int d[MAXN+1];

void run() {
	scanf("%d%d",&n,&initcap);
	REP(i,n) scanf("%d",&x[i]);

	int nstep=1; while((initcap>>(nstep-1))!=0) ++nstep;

	REP(k,nstep) {
		for(int at=0,to=at;at<n;at=to) {
			while(to<n&&(at==to||x[to]-x[to-1]<=(initcap>>k))) ++to;
			FOR(i,at,to) nxt[i][k]=to;
		}
		for(int at=n-1,to=at;at>=0;at=to) {
			while(to>=0&&(at==to||x[to+1]-x[to]<=(initcap>>k))) --to;
			FORE(i,to+1,at) prv[i][k]=to;
		}
	}
	memset(dpr,0,sizeof(dpr));
	REP(i,1<<nstep) REP(j,nstep) if((i&(1<<j))==0) dpr[i|(1<<j)]=max(dpr[i|(1<<j)],dpr[i]==n?n:nxt[dpr[i]][j]);
	REP(i,1<<nstep) dpl[i]=n-1;
	REP(i,1<<nstep) REP(j,nstep) if((i&(1<<j))==0) dpl[i|(1<<j)]=min(dpl[i|(1<<j)],dpl[i]==-1?-1:prv[dpl[i]][j]);

	//REP(i,1<<nstep) printf("r%x = %d\n",i,dpr[i]);
	//REP(i,1<<nstep) printf("l%x = %d\n",i,dpl[i]);

	REPE(i,n) d[i]=0;
	REP(i,1<<nstep) {
		if(i&1) continue;
		int l=dpr[i],r=dpl[(1<<nstep)-1-i-(1<<0)]+1;
		if(l==n) { d[0]++; d[n]--; }
		else if(nxt[l][0]>=r) { d[prv[l][0]+1]++; d[nxt[l][0]]--; }
	}
	REP(i,n) d[i+1]+=d[i];
	REP(i,n) printf("%s\n",d[i]>0?"Possible":"Impossible");
}

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


Measured memory_bytes: 37760
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll    long long
#define PR    pair<ll, ll>

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << '\n';
            return 0;
        }
    }
    cout << "NG" << '\n';
    return 0;
}


Measured memory_bytes: 3576
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define INF 1000000000
#define F first
#define S second
#define forn(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)

using namespace std;

ll a[200005];
ll sum[200005];

ll merge(ll arr[], ll l, ll r){
	ll tmp[200005];
	ll k = l;
	ll i = l;
	ll j = (l+r)/2;
	ll inv = 0;

	while(i < (l+r)/2 && j < r){
		if(arr[i] <= arr[j])	tmp[k++] = arr[i++];
		else{
			tmp[k++] = arr[j++];
			inv += (l+r)/2 - i;
		}
	}
	if(i == (l+r)/2){
		while(j < r) tmp[k++] = arr[j++];
	}
	else{
		while(i < (l+r)/2) tmp[k++] = arr[i++];
	}

	for(ll i = l; i < r; i++){
		arr[i] = tmp[i];
//		printf("%d ", arr[i]);
	}
//	printf("\n");

//	printf("%lld %lld %lld\n", l, r, inv);
	return inv;
}
ll ms(ll arr[], ll l, ll r){
	if(l == r-1){	
		return 0;
	}
	ll mid = (l+r)/2;
	ll inv = ms(arr, l, mid);
	inv += ms(arr, mid, r);
	inv += merge(arr, l, r);
	return inv;
}


int main(){
	ll n,k;
	scanf("%lld %lld", &n, &k);
	sum[0] = 0;
	rep(i,n){
		ll tmp;
		scanf("%lld", &tmp);
		tmp -= k;
		a[i] = tmp;
		sum[i+1] = sum[i] + tmp;
//		printf("%d\n", sum[i+1]);
	}
	printf("%lld\n", ((n*(n+1))/2) - ms(sum,0,n+1));
	return 0;
}




Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

// dp[i][j][k] := i-1個目まで見てj個選んで、合計をkにできるか
ll dp[52][52][2503];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    V<> a(n);
    cin >> a;
    repn(i, n) repn(j, n) repn(k, 2500) dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    rep(i, n) repn(j, n) repn(k, 2500){
        // a[i]を使わない
        dp[i+1][j][k] += dp[i][j][k];
        // a[i]を使う
        dp[i+1][j+1][k+a[i]] += dp[i][j][k];
    }
    ll ans = 0;
    srepn(i, 1, n) repn(j, 2500) {
        if(j / i == k && j % i == 0) ans += dp[n][i][j];
    }
    cout << ans << endl;
}

Measured memory_bytes: 55416
// 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

template <long long Modulus = 1000000007>
struct MInt
{
    long long x;
    static const long long mod = Modulus;
    
    MInt(long long a = 0) : x((a % mod + mod) % mod) {}

    // operator
    MInt& operator = (const MInt& a)
    {
        x = a.x;
        return *this;
    }
    MInt& operator = (const long long& a)
    {
        *this = MInt(a);
        return *this;
    }

    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;
        x = 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(long long t) const
    {
        if (t == 0)
            return 1;
        MInt a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // only for prime mod
    MInt Inv() const
    {
        return pow(mod - 2);
    }
    // only for prime mod
    MInt& operator/=(const MInt& a)
    {
        return (*this) *= a.Inv();
    }
    MInt operator/(const MInt& a) const
    {
        MInt res(*this);
        return res /= a;
    }
};

int main()
{
    ll K;
    cin >> K;
    if (K % 2LL == 0 || K % 5LL == 0)
    {
        cout << -1 << endl;
        return 0;
    }
    ll ans = 0;
    ll num = 7;
    while(num != 0)
    {
        num = (num + K) % K;
        ++ans;
        if (num > 0)
        {
            num *= 10;
            num += 7;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    string s,t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();

    int ans = 0;
    if(n > m) ans = 1;
    else if(n < m) ans = -1;
    else{
        rep(i,n){
            if(s[i] > t[i]){
                ans = 1;
                break;
            }
            else if(s[i] < t[i]){
                ans = -1;
                break;
            }
        }
    }

    if(ans == 1) cout << "GREATER" << endl;
    else if(ans == -1) cout << "LESS" << endl;
    else cout << "EQUAL" << endl;
}

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

int main() {
    using namespace std;
    constexpr unsigned long MOD = 998244353;
    unsigned long N;
    cin >> N;
    vector<vector<unsigned long>> children(N + 1);
    {
        vector<pair<long, long>> robots;
        robots.emplace_back(-2000000000, 4000000000);
        for(long i{0}, x, d; i++ < N; robots.emplace_back(x, x + d))cin >> x >> d;
        sort(robots.begin(), robots.end());
        stack<pair<unsigned long, long>> st;
        for(unsigned long i{0}; i <= N; ++i){
            while(!st.empty() && st.top().second <= robots[i].first)st.pop();
            if(!st.empty())children[st.top().first].emplace_back(i);
            while(!st.empty() && st.top().second < robots[i].second)st.pop();
            st.emplace(i, robots[i].second);
        }
    }
    vector<unsigned long> dp(N + 1, 1);
    for(unsigned long i{N + 1}; i--; ++dp[i])for(const auto& j : children[i])(dp[i] *= dp[j]) %= MOD;
    cout << (dp[0] - 1) % MOD << endl;
    return 0;
}

Measured memory_bytes: 15212
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if (a < b) {
            if (b < c) {
                System.out.printf("%d %d %d\n", a, b, c);
            } else if (a < c) {
                System.out.printf("%d %d %d\n", a, c, b);
            } else {
                System.out.printf("%d %d %d\n", c, a, b);
            }
        } else {
            if (b > c) {
                System.out.printf("%d %d %d\n", c, b, a);
            } else if (a < c) {
                System.out.printf("%d %d %d\n", b, a, c);
            } else {
                System.out.printf("%d %d %d\n", b, c, a);
            }
        }
    }
}


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

inline long long read()
{
	long long x=0,f=1,c=getchar();
	while(c<48) c=='-'&&(f=-1),c=getchar();
	while(c>47) x=x*10+c-'0',c=getchar();
	return x*f;
}

typedef long long ll;
const ll MAXN = 100005;
struct Node {ll a,b;} s[MAXN];
priority_queue<ll,vector<ll>,greater<ll> > q,ept;
ll lp[MAXN],rp[MAXN],ans;
ll n,x,y,z;

int main(int argc, char const *argv[])
{
	x=read(); y=read(); z=read(); n=x+y+z;
	for(ll i=1,k;i<=n;++i)
		ans+=(k=read()),s[i].a=read()-k,s[i].b=read()-k;
	sort(s+1,s+n+1,[](Node a,Node b)
	{return a.a-a.b>b.a-b.b;});
	for(ll i=1;i<=n;++i)
	{
		lp[i]=lp[i-1]+s[i].a; q.push(s[i].a);
		if(q.size()>y) lp[i]-=q.top(),q.pop();
	}
	for(ll i=(q=ept,n);i;--i)
	{
		rp[i]=rp[i+1]+s[i].b; q.push(s[i].b);
		if(q.size()>z) rp[i]-=q.top(),q.pop();
	}
	ll mx=-1000000000000000000ll;
	for(ll i=y;i<=n-z;++i)
		mx=max(mx,lp[i]+rp[i+1]);
	printf("%lld\n", ans+mx);
	return 0;
}

Measured memory_bytes: 6992
a = input()
N = int(a)

if N == 10**5:
    print(90909)
elif N >= 10**4:
    print(N-(9000+90))
elif N >= 10**3:
    print(909)
elif N >= 10**2:
    print(N-90)
elif N >= 10:
    print(9)
else:
    print(N)


Measured memory_bytes: 9004
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.valueOf(sc.nextLine());
		String sArray[] = new String[N];
		String sArraySub[] = new String[N];

		for (int i = 0; i < N; i++) {
			sArray[i] = sc.nextLine();
			sArraySub[i] = sArray[i].split(" ")[0] + " " + (Integer.valueOf(sArray[i].split(" ")[1]) - 1100);
		}

		List lst = new ArrayList<String>();
		lst = Arrays.asList(sArraySub);
		Collections.sort(lst);

		for (int i = 0; i < N; i++) {
			sArraySub[i] = sArraySub[i].split(" ")[0] + " " + (Integer.valueOf(sArraySub[i].split(" ")[1]) + 1100);
		}

		for (int i = 0; i < N; i++) {
			System.out.println(Arrays.asList(sArray).indexOf(lst.get(i)) + 1);
		}
	}
}


Measured memory_bytes: 23764
import java.util.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double x = sc.nextDouble();
        sc.close();
        double ans = 0;
        double S  = 0;
        if(b >= a){
            S = x/a;
            ans = Math.toDegrees(Math.atan(2*(a*b-S)/a/a));
            if(ans > Math.toDegrees(Math.atan(b/a))){
                ans = Math.toDegrees(Math.atan(b*b*a/2/x));
            }
        } else {
            S = x/a;
            ans = Math.toDegrees(Math.atan(2*(a*b-S)/a/a));
            if(ans > Math.toDegrees(Math.atan(b/a))){
                ans = Math.toDegrees(Math.atan(b*b*a/2/x));
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define MOD 1000000007
#define pb push_back
#define cy cout<<"Yes\n"
#define cn cout<<"No\n"
typedef long long int ll;
int main()
{
    ll sum=0;
    int n,a,b,c,d;
    string s,t;
    cin>>s>>t;
    int sz1=s.size();
    int sz2=t.size();
    int flag=0;
    for(int i=0;i<sz1;i++)
    {
        if(s[i]!=t[i])
        {
            flag=1;
            break;
        }
    }
    if(flag)
        cn;
    else
        cy;

}


Measured memory_bytes: 3628
S = input()
ans = 0
if S == 'SUN':
    ans = 7
elif S == 'MON':
    ans = 6
elif S == 'TUE':
    ans = 5
elif S == 'WED':
    ans = 4
elif S == 'THU':
    ans = 3
elif S == 'FRI':
    ans = 2
elif S == 'SAT':
    ans = 1
print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 100010;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
int main(){
    ll x, y, a, b, c; cin >> x >> y >> a >> b >> c;
    vector<ll> p(a);
    rep(i, a) cin >> p[i];
    vector<ll> q(b);
    rep(i, b) cin >> q[i];
    vector<ll> r(c);
    rep(i, c) cin >> r[i];
    sort(p.begin(), p.end(), greater<>());
    sort(q.begin(), q.end(), greater<>());
    vector<ll> apple;
    rep(i, x) apple.push_back(p[i]);
    rep(i, y) apple.push_back(q[i]);
    rep(i, c) apple.push_back(r[i]);
    sort(apple.begin(), apple.end(), greater<>());
    ll sum = 0;
    rep(i, x + y) sum += apple[i];
    cout << sum << endl;
}

Measured memory_bytes: 9804
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,n,s) for(int i=s;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()

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

  int n;
  cin >> n;
  vector<int> p(n);
  REP(i, n) {
    cin >> p[i];
  }

  int ans = 0;
  for(int i=1;i<n-1;i++) {
    if(p[i-1] > p[i] && p[i] > p[i+1] || p[i-1] < p[i] && p[i] < p[i+1]) {
      ans++;
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 1000000000 //1E+9
using namespace std;

int main(){
	int a,b,c; cin>>a>>b>>c;
	multiset<int> s;
	s.insert(a);s.insert(b);s.insert(c);

	if(s.count(5)==2 && s.count(7)==1) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	return 0;
}



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

using namespace std;
static const int MAX = 200000;

int main(void)
{
	int n, R[MAX];
	cin >> n;

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

	int maxv = -1000000000;
	int minv = R[0];

	for (int i = 1; i < n; i++)
	{
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	cout << maxv << endl;

	return 0;
}


Measured memory_bytes: 3868
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

int main(){

    ll flg[13] = {};
    flg[4] = 1;
    flg[6] = 1;
    flg[9] = 1;
    flg[11] = 1;
    flg[2] = 2;
    ll x, y;
    cin >> x >> y;
    Say(flg[x] == flg[y]);

    return 0;
}

Measured memory_bytes: 764
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const int INF = 1 << 30;
const uint64_t MOD = 1000000000 + 7;

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

	vector<int> a(n);
	int mina = 101, maxa = -101;
	for (int i = 0; i < n; i++)
	{
		cin >> a.at(i);

		maxa = max(maxa, a.at(i));
		mina = min(mina, a.at(i));
	}

	int minn = INF;
	for (int i = mina; i <= maxa; i++)
	{
		int x = 0;
		for (int j = 0; j < n; j++)
		{
			x += (a.at(j) - i) * (a.at(j) - i);
		}
		minn = min(minn, x);
	}

	cout << minn << endl;
}

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

int main() {
  // ここにプログラムを追記
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if (A+B > C+D){
    cout << "Left" << endl;
    }
  else if (A+B < C+D){
    cout << "Right" << endl;
    }
  else if (A+B == C+D){
    cout << "Balanced" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, k, q;
  cin>>n>>k>>q;
  vector<int> points(n);
  for(int i=0; i<n; i++){
    points.at(i) = k-q;
  }
  for(int i=0; i<q; i++){
    int a;//a(i+1)のこと
    cin>>a;
    points.at(a-1)++;
  }
  
  for(int i=0; i<n; i++){
    if(points.at(i)>0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
  
    
}

Measured memory_bytes: 1024
import numpy as np

N,M = map(int, input().split())
score = list(map(int, input().split()))
adj_list = [[] for _ in range(N)]

for _ in range(M):
    A,B = map(int, input().split())
    adj_list[A-1].append(B-1)
    adj_list[B-1].append(A-1)

score_ = 0
for i, adjs in enumerate(adj_list):
    is_max = True
    for adj in adjs:
        if score[i] <= score[adj]:
            is_max = False
    if is_max:
        score_+=1
print(score_)


Measured memory_bytes: 47836
x = int(input())

flag = 0
if x >= 2000:
    print(1)
    exit()
else:
    for i in range(20):
        for j in range(20):
            for k in range(20):
                for l in range(20):
                    for m in range(20):
                        for n in range(20):
                            if i*100+j*101+k*102+l*103+m*104+n*105 == x:
                                flag = 1
                                print(1)
                                exit()
if flag != 1:
    print(0)

Measured memory_bytes: 73592
#include <stdio.h>

int main(void) {
	int x[10000];
	int i;
	for(i=0; i<10000; i++) {
	scanf("%d",&x[i]); 
		if(x[i]==0) {
			break;
		}
	}
	for(i=0; i<10000; i++) {
		if(x[i]==0) {
			break;
	}
	printf("Case %d: %d\n",i+1,x[i]);
	}
	return 0;
}

Measured memory_bytes: 636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		if (N == 1) {
			System.out.println("Hello World");
		} else {
			System.out.println(sc.nextInt() + sc.nextInt());
		}
	}
}


Measured memory_bytes: 21844
#include <stdio.h>

#define N_MAX 30
#define QUEUE_MAX 1801 /* 2*N_MAX^2 + 1 */

//Queue

int Q[QUEUE_MAX], sp, rp;

void Qstore(int N){ Q[sp++%QUEUE_MAX]=N; }
void Qstore2(int N, int M){ Q[sp++%QUEUE_MAX]=N, Q[sp++%QUEUE_MAX]=M; }
int Qretrive(){ return Q[rp++%QUEUE_MAX]; }
int Qempty(){ return sp==rp; }

//Main

int H,W;

int main(void){
	int hpart[N_MAX][N_MAX], vpart[N_MAX][N_MAX], step[N_MAX][N_MAX], x, y, depth;	
		
	while(scanf("%d %d",&W,&H), W!=0){
	
		/* load */
		for(y=0; y<H-1; y++){
			for(x=0; x<W-1; x++) scanf("%d",&hpart[x][y]);
			for(x=0; x<W; x++) scanf("%d",&vpart[x][y]); }
		for(x=0; x<W-1; x++) scanf("%d",&hpart[x][y]);
		
		/* initialize */
		sp=0, rp=0;
		for(x=0; x<W; x++) for(y=0; y<H; y++) step[x][y]=-1;
		
		/* search */
		depth=0, step[0][0]=0, Qstore2(0,0), Qstore(-1);
		
		while(1){
			depth++;
			while((x=Qretrive())!=-1){
				y=Qretrive();
				if(W>x+1 && !hpart[x][y] && step[x+1][y]==-1) step[x+1][y]=depth, Qstore2(x+1,y);
				if(H>y+1 && !vpart[x][y] && step[x][y+1]==-1) step[x][y+1]=depth, Qstore2(x,y+1);
				if(x>0 && !hpart[x-1][y] && step[x-1][y]==-1) step[x-1][y]=depth, Qstore2(x-1,y);
				if(y>0 && !vpart[x][y-1] && step[x][y-1]==-1) step[x][y-1]=depth, Qstore2(x,y-1);
			}
			if(Qempty() || step[W-1][H-1]!=-1) break;
			else Qstore(-1);
		}
		
		/* out */
		if(step[W-1][H-1]==-1) printf("0\n");
		else printf("%d\n",step[W-1][H-1]+1);
	}
	
	return 0;
}

Measured memory_bytes: 0
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS

(declaim (inline dict<))
(defun dict< (str1 str2)
  (let* ((len1 (length str1))
         (len2 (length str2)))
    (loop for i below (min len1 len2)
          for c1 = (aref str1 i)
          for c2 = (aref str2 i)
          do (cond ((char< c1 c2) (return t))
                   ((char> c1 c2) (return nil)))
          finally (return (if (< len1 len2) t nil)))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun feasible-p (s key start)
  (declare (simple-base-string s key))
  (when (loop for i from start
              for k across key
              always (or (char= (schar s i) #\?)
                         (char= (schar s i) k)))
    (let ((res (copy-seq s)))
      (loop for i from start
            for k across key
            do (setf (schar res i) k))
      (dotimes (i (length s))
        (when (char= #\? (schar res i))
          (setf (schar res i) #\a)))
      res)))

(defun main ()
  (let* ((s (coerce (read-line) 'simple-base-string))
         (key (coerce (read-line) 'simple-base-string))
         (min nil))
    (loop for i from 0 to (- (length s) (length key))
          for res = (feasible-p s key i)
          when (and res
                    (or (null min)
                        (dict< (the simple-base-string res)
                               (the simple-base-string min))))
          do (setf min res))
    (write-line (or min "UNRESTORABLE"))))

#-swank(main)


Measured memory_bytes: 25696
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use itertools_num::ItertoolsNum;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use superslice::*;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: i64 = sc.read();
    let c = sc.read_chars();

    let mut ans = 0;
    let mut i = 0_i64;
    let mut j = n - 1;
    while i < j {
        while i <= n - 1 && c[i as usize] == 'R' {
            i += 1;
        }
        while j >= 0 && c[j as usize] == 'W' {
            j -= 1;
        }
        if i < j && i <= n - 1 && j >= 0 {
            ans += 1;
            i += 1;
            j -= 1;
        }
    }
    println!("{}", ans);
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 2392
#include <bits/stdc++.h>
#define ll long long
#define ulli unsigned long long int
#define ld long double  
using namespace std; 

void solve() {
    int k, n;
    cin >> k >> n;

    int f = 0;
    int temp1;
    int temp2;
    vector<int> d;
    for (int i = 0; i < n; i++) {
        cin >> temp1;
        if (i == 0) {
            f = temp1;
        }

        if (i > 0) {
            int dist = temp1 - temp2;
            d.push_back(dist);
        }
        if (i == n - 1) {
            d.push_back(k - temp1 + f);
        }
        temp2 = temp1;
    }

    sort(d.begin(), d.end());

    int sum = 0;
    for (int i = 0; i < n - 1; i++) {
        sum += d[i];
    }

    cout << sum << "\n";
    
}

int main() 
{ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
  
    int t = 1; 
    //cin >> t; 
    while (t--) { 
        solve(); 
    } 
  
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
    return 0; 
} 


Measured memory_bytes: 1400
n, m = map(int, input().split())
left = 0
right = n
ls = list(range(1,n+1))

for i in range(m):
    l,r = map(int, input().split())
    if l - 1 > left:
        left = l - 1
    if r < right:
        right = r
print(len(ls[left:right]))

Measured memory_bytes: 7668
#include <iostream>

using namespace std;

int main()
{
    int x,y,z;
    cin >> x >> y >> z;
    bool poor = false;
    if(x==y && y!=z)
        poor = true;

    else if(y==z && y!=x)
        poor = true;

    else if(x==z && y!=x)
        poor = true;

    if(poor)
        cout << "Yes";
    else
        cout << "No";


}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int A[200010],B[200010],num[200010];
int N,M,W,C,D,E,G;
int ans,ans2,sum,sum2,cnt,cnt2;
string S,T;
vector<int> V;
set<int> U;
map<int,int> H;
bool F,Q[200010];

signed main(){
	cin>>D;
	if(D==25){
		cout<<"Christmas"<<endl;
	}
	else if(D==24){
		cout<<"Christmas Eve"<<endl;
	}
	else if(D==23){
		cout<<"Christmas Eve Eve"<<endl;
	}
	else{
		cout<<"Christmas Eve Eve Eve"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	int n;
	cin>>n;
	cout<<(3*( n*n ))<<endl;
	
}

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

const int maxn = 100005;

// Global variables declared here
int n, q;
vector<int> childs[maxn];
int jt[18][100005];
int depth[100005];
// End of global variables

void dfs(int n, int p = -1) {
    depth[n] = p == -1 ? 0 : depth[p] + 1;
    for (int h : childs[n])
        dfs(h, n);
}

void init() {
    dfs(0);

    jt[0][0] = -1;

    for (int i = 0; i < 17; i++) {
        for (int j = 0; j < n; j++) {
            if (jt[i][j] != -1) {
                jt[i + 1][j] = jt[i][jt[i][j]];
            }
        }
    }
}

// Walk up n from v
int up(int v, int n) {
    for (int i = 17; i >= 0; i--) {
        if (n & (1 << i)) {
            v = jt[i][v];
        }
    }

    return v;
}

int lca(int a, int b) {
    if (depth[a] > depth[b])
        swap(a, b);

    b = up(b, depth[b] - depth[a]);

    if (a == b)
        return a;

    for (int i = 17; i >= 0; i--) {
        if (jt[i][a] != jt[i][b]) {
            a = jt[i][a], b = jt[i][b];
        }
    }

    return jt[0][a];
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        int k; cin >> k;
        for (int j = 0; j < k; j++) {
            int c; cin >> c;
            childs[i].push_back(c);
            jt[0][c] = i;
        }
    }

    init();

    cin >> q;
    for (int i = 0; i < q; i++) {
        int u, v; cin >> u >> v;
        cout << lca(u, v) << endl;
    }
}


Measured memory_bytes: 19080
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define Local
#ifdef Local
    #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
    void err() { std::cout << std::endl; }
    template<typename T, typename...Args>
    void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
    template <template<typename...> class T, typename t, typename... A> 
    void err(const T <t> &arg, const A&... args) {
    for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
    #define dbg(...)
#endif
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int N = 1e5 + 10;

int n, m;
vector<int>g[N];
int vis[N];


void dfs(int u) {
    vis[u] = 1;

    for (int i = 0; i < g[u].size(); ++i) {
            int v = g[u][i];
            if (vis[v]) continue;
            dfs(v);
    }
}

int main()
{
    fastIO;
    cin >> n >> m;
    while (m--) {
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int cnt = 0;
    for(int i = 1; i <= n; ++i) 
        if(!vis[i])
        {
            dfs(i);
            cnt++;
        }

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

Measured memory_bytes: 9968
#ABC094-B
n,m,x = map(int,input().split())
a = set(list(map(int,input().split())))
masu = [i for i in range(n+1)]
a_left = masu[:x]
a_right = masu[x+1:]

#print(a_left)
#print(a_right)

c_l = 0
c_r = 0
for i in range(len(a_left)):
    if a_left[i] in a:
        c_l += 1
        
for j in range(len(a_right)):
    if a_right[j] in a:
        c_r += 1
        
print(min(c_l,c_r))

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

using namespace std;
using LL = long long;

int main(){
	string s, t;
	cin >> s >> t;
	s+=s;
	LL ans=0, prev=-1;
	vector<vector<LL>> chara(26);
	rep(i,s.size()){
		int c=s[i]-'a';
		chara[c].emplace_back(i);
	}
	rep(i,t.size()){
		int c=t[i]-'a';
		auto itr=upper_bound(chara[c].begin(),chara[c].end(),prev);
		if(itr==chara[c].end()){
			cout << -1 << endl;
			return 0;
		}
		LL num=*itr;
		ans+=num-prev;
		if(num>=s.size()/2) prev=num-s.size()/2;
		else prev=num;
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
  long n;
  cin >> n;
  
  vector<long> arr(n);
  for(int i = 0; i < n; ++i) cin >> arr[i];
  
  for (int i = 0;i < n; ++i) 
    if (arr[i] == 0) {cout << 0; return 0;}
  
  long prod = 1;
  for (int i = 0; i < n; ++i) {
    if (arr[i] <= 1e+18L / prod) prod *= arr[i];
    else {cout << -1; return 0;}
  }
  cout << prod;
  return 0;
}
      

Measured memory_bytes: 4048
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  char a;
  bool b=false;
  cin>>s;
  cin>>t;
  t=t+t;
  for(int i=0;i<t.size()-s.size()+1;i++){
    string c=t.substr(i,s.size());
    if(c==s){
      b=true;
      break;
    }
  }
  if(b) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

double dis=0;

int main(){
 int n,a,b;
   cin >> n >> a >> b;

  int res=0;
  
  for(int i=1;i<=n;i++){
  
    int sum=0;
    int digit=i;
  while(digit>0){
   sum+=(digit%10);
   digit/=10;
  }
    if(sum>=a && sum<=b) res+=i;
    
  }
  
  cout << res << endl;
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
ll dp[100010][4] = {};
main(){
    string S;
    cin >> S;
    int N = S.size();
    for(int i = N;i >= 0;i--){
        for(int j = 3;j >= 0;j--){
            if(i == N)dp[i][j] = (j == 3 ? 1 : 0);
            else      if(j == 3)dp[i][j] = dp[i+1][j] * (S[i] == '?' ? 3 : 1);
                      else      dp[i][j] = dp[i+1][j] * (S[i] == '?' ? 3 : 1)
                                        +  dp[i+1][j+1] * (S[i] == '?' || S[i] == 'A' + j ? 1 : 0);
            dp[i][j] %= MOD;
        }
    }
    cout << dp[0][0] << endl;
}   

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<long double> x(N+1), y(N+1);
  for(int i=1; i<=N; ++i) cin >> x[i] >> y[i];
  vector<long double> v(N);
  iota(v.begin(), v.end(), 1);
  vector<long double> ans;
  do{
    long double distance = 0;
    rep(i, v.size()-1) {
      distance += sqrt(pow(x[v[i+1]]-x[v[i]],2) + pow(y[v[i+1]]-y[v[i]], 2));
    }
    ans.push_back(distance);
  } while(next_permutation(v.begin(), v.end()));
  long double ret = accumulate(ans.begin(), ans.end(), 0.0)/ans.size();
  printf("%.10Lf\n", ret);
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long int;
using namespace std;
int main() {
    fastIO;
    int n;
    cin >> n;
    vector<lint> A(n);
    rep(i, n) cin >> A.at(i);

    lint diff = -1;
    for (size_t i = 0; i < A.size() - 1; i++) {
        for (size_t j = i + 1; j < A.size(); j++) {
            diff = max(diff, abs(A.at(i) - A.at(j)));
        }
    }
    cout << diff << endl;
}


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

const int N = 2e5 + 10, inf = 0x3f3f3f3f;
typedef long long ll;
ll n, D, A, sum[N << 2], tag[N << 2], s[N], ans;
struct node { ll x, h; }e[N];

bool cmp(node a, node b) { return a.x < b.x; }

void psd(int x, int l, int r) {
    if (tag[x]) {
        int mid = (l + r) >> 1;
        tag[x << 1] += tag[x], tag[x << 1 | 1] += tag[x];
        sum[x << 1] += 1ll * tag[x] * (mid - l + 1);
        sum[x << 1 | 1] += 1ll * tag[x] * (r - mid);
        tag[x] = 0;
    }
}

void modify(int x, int l, int r, int lx, int rx, ll val) {
    if (lx <= l && r <= rx) {
        sum[x] += 1ll * val * (r - l + 1); tag[x] += val;
        return;
    }
    psd(x, l, r);
    int mid = (l + r) >> 1;
    if (lx <= mid) modify(x << 1, l, mid, lx, rx, val);
    if (rx > mid) modify(x << 1 | 1, mid + 1, r, lx, rx, val);
    sum[x] = sum[x << 1] + sum[x << 1 | 1];
}

ll query(int x, int l, int r, int pos) {
    if (l == r) return sum[x];
    psd(x, l, r);
    int mid = (l + r) >> 1;
    if (pos <= mid) return query(x << 1, l, mid, pos);
    else return query(x << 1 | 1, mid + 1, r, pos);
}

int main() {
    cin >> n >> D >> A;
    rep(i, 1, n) scanf("%lld%lld", &e[i].x, &e[i].h);
    sort(e + 1, e + n + 1, cmp);
    rep(i, 1, n) {
        modify(1, 1, n, i, i, e[i].h);
        s[i] = e[i].x;
    }
    s[n + 1] = inf;
    ll k;
    int id;
    rep(i, 1, n) {
        k = query(1, 1, n, i);
        if (k <= 0) continue;
        id = upper_bound(s + 1, s + n + 1, e[i].x + 2 * D) - s;
        id--;
        ans += k / A + (k % A > 0);
        modify(1, 1, n, i, id, -A * (k / A + (k % A > 0)));
        // printf("%d %lld %d %d %lld\n", e[i].x + D, k / A + (k % A > 0), i, id, -A * (k / A + (k % A > 0)));
    }
    printf("%lld\n", ans);
    return 0;
}


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

int s(ll x){
	int res = 0;
	while(x) res += x % 10, x /= 10;
	return res;
}

int main(){
	ll k, step = 1, curr = 1;
	cin >> k;
	for(int i = 1; i <= k; ++ i){
		while((curr + 10 * step) * s(curr + step) <= (curr + step) * s(curr + 10 * step)){
			step *= 10;
		}
		cout << curr << '\n';
		curr += step;
	}
}


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

const int N = 1e5 + 5;
int in[N];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        cin >> in[i];
    }

    int res = 0;
    for (int i = 1; i <= n; ++i) {
        if (in[i] == i) res++, i++;
    }

    cout << res << endl;
}

Measured memory_bytes: 640