akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9+7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
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; }
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

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

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}

//modの値の確認をすること
int main(){
    ll h,w;
    cin >> h >> w;
    vector<ll> c(26,0);
    rep0(i, h)rep0(j, w){
        char a;
        cin >> a;
        ++c[a - 'a'];
    }
    ll g1,g2,g4;
    if(h % 2 == 0 && w % 2 == 0){
        g1 = 0;
        g2 = 0;
        g4 = h * w / 4;
    }else if(h % 2 == 0){
        g1 = 0;
        g2 = h / 2;
        g4 = (h / 2) * (w / 2);
    }else if(w % 2 == 0){
        g1 = 0;
        g2 = w / 2;
        g4 = (h / 2) * (w / 2);
    }else{
        g1 = 1;
        g2 = h / 2 + w / 2;
        g4 = (h / 2) * (w / 2);
    }
    bool f = true;
    rep0(i, 26){
        if(g4 > 0){
            ll a = min(c[i] / 4,g4);
            g4 -= a;
            c[i] -= a * 4;
        }
        if(g2 > 0){
            ll a = min(c[i] / 2,g2);
            g2 -= a;
            c[i] -= a * 2;
        }
        if(g1 > 0){
            ll a = min(c[i],g1);
            g1 -= a;
            c[i] -= a;
        }
        if(c[i] > 0){
            f = false;
            break;
        }
    }
    pf(f? "Yes":"No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
// using namespace __gnu_pbds;
using namespace std;
 
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair <long long,long long> ii;
// typedef complex<long double> point;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll a,b;
	cin >> a >> b;
	if (max(a,b) > 9) cout << -1 << endl;
	else cout << a*b << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000

int partition(int,int);

int A[MAX],n;

main(){
  int i,q;

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

  q=partition(0,n-1);
  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==q)printf("[");
    printf("%d",A[i]);
    if(i==q)printf("]");
  }
  printf("\n");

  return 0;
}

int partition(int p,int r){
  int x,i,j,t;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 8e5+10 , OO = 0x3f3f3f3f;

#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define xloop(i,a,b) for(int i = int(a);i <= int(b);i++)
#define range(vec) for(auto &x : vec) cin >> x;
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);


int n;

int main()
{

    #ifndef ONLINE_JUDGE
        //freopen("in.in", "r", stdin);
        //freopen("out.in", "w", stdout);
    #endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


    string s;
    cin >> s;
    int q;
    cin >> q;
    bool mazbot = true;
    deque<char> ans;
    int x;
    char ch;

    for(int i = 0 ; i < s.size() ; ++i)
        ans.push_back(s[i]);
    while(q--){

        cin >> n;
        if(n == 1){
            mazbot = !mazbot;
        }else{
            cin >> x >> ch;
            if(mazbot==1){
                if(x==1){
                    ans.push_front(ch);
                }else{
                    ans.push_back(ch);
                }
            }else{

                if (x == 1)
                {
                    ans.push_back(ch);
                }
                else
                {
                    ans.push_front(ch);
                }
            }
        }
    }
    if(!mazbot)
        reverse(ALL(ans));

    for (auto rkm : ans)
        cout << rkm;
    cout << "\n";

    return 0;
}


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

using namespace std;

using ll = long long;

ll L[100010], R[100010];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int X, Y, Z;
	cin >> X >> Y >> Z;
	int n = X + Y + Z;
	vector<int> a(n), b(n), c(n), idx(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
		idx[i] = i;
	}
	sort(idx.begin(), idx.end(), [&](const int& i1, const int& i2){return a[i1] - b[i1] < a[i2] - b[i2];});
	priority_queue<int> pq;
	for (int i = 1; i <= n; i++) {
		L[i] = L[i - 1] + b[idx[i - 1]];
		pq.push(c[idx[i - 1]] - b[idx[i - 1]]);
		if (i > Y) {
			L[i] += pq.top();
			pq.pop();
		}  
	}
	priority_queue<int> pq2;
	for (int i = n - 1; i >= 0; i--) {
		R[i] = R[i + 1] + a[idx[i]];
		pq2.push(c[idx[i]] - a[idx[i]]);
		if (n - i > X) {
			R[i] += pq2.top();
			pq2.pop();
		}
	}
	ll ans = 0;
	for (int i = Y; i <= n - X; i++) {
		ans = max(ans, L[i] + R[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3904
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n;
  R n;
  double p[n];
  rep(i,n) R p[i];
  double dp[n+1][n+1];
  mem(dp);
  dp[0][0]=1;
  rep(i,n) {
    rep(j,n) {
      dp[i+1][j]+=dp[i][j]*(1.0-p[i]);
      dp[i+1][j+1]+=dp[i][j]*p[i];
    }
  }
  double ans=0;
  rep(i,n+1) {
    if(i>n/2) ans+=dp[n][i];
  }
  pd(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 70656
n=int(input())
m=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in range(m):
    b=list(map(int,input().split()))
    hit=0
    for j in range(n):
        if b[j]==a[i]:ans[j]+=1
        else:hit+=1
    ans[a[i]-1]+=hit
for i in ans:
    print(i)


Measured memory_bytes: 5624
using System;

class P {
  static void Main(string[] args) {
    string[] str = Console.ReadLine().Split(' ');
    char[] c = Console.ReadLine().ToCharArray();
    int N = int.Parse(str[0]);
    int K = int.Parse(str[1]);
    c[K-1] = Char.ToLower(c[K-1]);
    Console.WriteLine(c);
  }
}

Measured memory_bytes: 11092
// #include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)

const int INF = 1e9;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
   ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
   ostr << "}";
   return ostr;}

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

int factorial(int n){
  if (n==0) return 1;
  else return n * factorial(n-1);
}

int solve(vector<int> r, int N){
  int ans = 0;
  int exist[N];
  REP(i, N){exist[i] = 0;}
  REP(i, N-1){
    int val = r[i];
    int tmp = val - 1;
      REP(j, val-1){
        if (exist[j] == 1){tmp--;}
      }
      int fac = N - 1 - i;
      ans += factorial(fac) * tmp;
    exist[val-1] = 1;

  }
  return ans;
}

int main(void){
 ios::sync_with_stdio(false);

 int N;
 cin >> N;

 vector<int> P(N), Q(N);
 REP(i, N){cin >> P[i];}
 REP(i, N){cin >> Q[i];}

 int p_val = solve(P, N);
 int q_val = solve(Q, N);
 int ans = abs(p_val - q_val);

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



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

namespace ABC087C
{
    class Program
    {
        static int N;
        static int[,] data;
        static void Main(string[] args)
        {
            N = int.Parse(Console.ReadLine());

            data = new int[2, N];
            for (int i = 0; i < 2; i++)
            {
                var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int j = 0; j < N; j++) data[i, j] = line[j];
            }

            int max = 0;
            for(int i = 0; i < N; i++)
            {
                int count = 0;
                for(int s = 0; s <= i; s++)
                {
                    count += data[0, s];
                }
                for (int s = i; s <= N - 1; s++)
                {
                    count += data[1, s];
                }
                if (count > max) max = count;
            }

            Console.WriteLine(max);
            Console.ReadKey();
        }
        
    }
}


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

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

  return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i

def ss(n)
  arr = []

  while n != 0 do
    tmp = n % 26
    if tmp == 0
      arr << 'z'
      n -= 26
    else
      arr << ('a'.ord + tmp - 1).chr
    end
    n /= 26
  end

  arr.reverse().join()
end

def s(n)
  s = n.to_s(26)
  cs = s.chars.map do |c|
    if c < 'a'
      ('a'.ord + c.to_i - 1).chr
    else
      (c.ord + 9).chr
    end
  end
  cs.join('')
end

# puts s(n)
puts ss(n)
# 1.upto(100) do |n|
#   puts ss(n)
# end


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

int main(){

  int n=0;
  int y=0;

  cin>>n>>y;
 
  for(int a=0;a<=n;a++){
	for(int b=0;b<=n-a;b++){
      int c=n-b-a;

        if(y==(a*10000+b*5000+c*1000)){

          cout<<a<<" "<<b<<" "<<c<<endl;
          return 0;
              
      }
    }
  }

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


Measured memory_bytes: 256
import sys
from collections import deque
input = sys.stdin.readline

n,q = map(int,input().split())
score = [0]*(n+1)
tree = [[] for i in range(n+1)]
check = [0]*(n+1)
check[1] = 1

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

que = deque([1])
qappend = que.append
qpop = que.pop

for i in range(q):
  q,x = map(int,input().split())
  score[q] += x

while que:
  n = qpop()
  for i in tree[n]:
    if check[i]:continue
    check[i] = 1
    score[i] += score[n]
    qappend(i)

print(*score[1:])

Measured memory_bytes: 56056
#include<iostream>
#include<set>
#include<vector>
#include<map>
#include<cstdio>
#include<cmath>
#include<cassert>
#include<algorithm>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
int N,K; 

int main()
{
  cin >> N >> K;
  vector<vector<int> > G(10);
  int TypeMax[10][N+1];
  int dp[10][N+1];
  for(int i=0;i<N;i++)
    {
      P p;
      cin >> p.F >> p.S;
      p.S--;
      assert(0<=p.S && p.S <10);
      G[p.S].push_back(p.F);
    }
  for(int i=0;i<10;i++)
    {
      sort(G[i].begin(),G[i].end(),greater<int>());
      for(int j=0;j<N;j++)TypeMax[i][j] = dp[i][j] = 0;
    } 

  //TypeMax
  
  for(int i=0;i<10;i++)
    {
      if(G[i].empty())continue;
      TypeMax[i][1] = dp[i][1] = G[i][0];
      for(int j=2;j<=G[i].size();j++)
	TypeMax[i][j] = TypeMax[i][j-1]+G[i][j-1];
      for(int j=2;j<=G[i].size();j++)
	TypeMax[i][j] = dp[i][j] = TypeMax[i][j]+(j-1)*j;
    }
 
  int mex = 0;
  
  for(int i=0;i<10;i++)
    {
      if(!i)
	{
	  for(int j=1;j<=K;j++)
	    dp[i][j] = TypeMax[i][j],mex = max(mex,dp[i][j]);
	  
	  continue;
	}
      if(G[i].empty())
	{
	  for(int j=1;j<=K;j++)
	    dp[i][j] = dp[i-1][j];
	  continue;
	}
      for(int j=1;j<=K;j++)
	{	  
	  if(j == 1)
	    {
	      dp[i][j] = max(TypeMax[i][j],dp[i-1][j]);
	      mex = max(mex,dp[i][j]);
	      continue;
	    }
	  for(int k=1;k<min(j+1,(int)G[i].size()+1);k++)
	    {
	      if(!dp[i-1][abs(j-k)])continue;
	      dp[i][j] = max(dp[i][j],TypeMax[i][k]+dp[i-1][abs(j-k)]);
	      mex = max(mex,dp[i][j]);
	    }
	  if(dp[i-1][j]!=0)
	    {
	      dp[i][j] = max(dp[i-1][j],dp[i][j]);
	      mex = max(mex,dp[i][j]);
	    }
	  //if(i >= 2)
	    //assert(dp[i][j] >= dp[i-1][j]);
	}
    }
  /*
 for(int i=0;i<10;i++)
    {
      for(int j=0;j<N;j++)
	{
	  int k = dp[i][j] == 0?1:log10(dp[i][j])+1;
	  cout << string(5-k,' ');
	  cout << dp[i][j] << " ";
	}
      cout << endl;
    }
  cout << endl;
  */

  cout << mex << endl;

  return 0;
}

Measured memory_bytes: 1388
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define int                 long long
#define FF(i,a,b)           for(int i=a;i<b;i++)
#define BF(i,a,b)           for(int i=a;i>=b;i--)
#define vi                  vector<int>
#define MAP                 map<int,int>
#define pb                  push_back
#define MP                  make_pair
#define F                   first
#define S                   second
#define pi                  pair<int,int>
#define all(v)              v.begin(),v.end()
#define PIE                 3.1415926535897932384626433832795
#define FastIO              ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
//#define ordered_set         tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
/*

    order_of_key (k) : Number of items strictly smaller than k .
    find_by_order(k) : K-th element in a set (counting from zero).

*/
/**************************************************************************************/
                       /*Global Variables*/
const int mod = 1e9+7;
const int N = 2e5+10;
const int inf = 3e18;

/**************************************************************************************/
template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)input>>i;return input;}
template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)output<<i<<' ';return output;}
int add(int a, int b){return (a%mod + b%mod + mod)%mod;}
int sub(int a, int b){return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b){return ((a%mod)*(b%mod) + mod)%mod;}
signed main()
{
    FastIO;
    int T=1;
    //cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        vi a(n);
        cin>>a;
        MAP mp;
        int sum=0;
        for(auto it:a)mp[it]++,sum+=it;
        int q;
        cin>>q;
        while(q--)
        {
            int x,y;
            cin>>x>>y;
            sum=sum-mp[x]*x+mp[x]*y;
            
            mp[y]+=mp[x];
            mp[x]=0;
            cout<<sum<<"\n";
        }
    }

}
/*
|| Do what you can with all you have,wherever you are. ||

|| Knowing is not enough, we must apply. Wishing is not enough, we must do. ||

|| A goal is a dream with deadline. ||

|| Whether you think you can or you think you can't, you're right. ||

|| A year from now you may wish you had started today ||
*/



Measured memory_bytes: 10032
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int INF = 1e9;
int N, h[100005], dp[100005];
int main() {
  scanf("%d", &N);
  for(int i = 1; i <= N; ++i) {
    scanf("%d", &h[i]);
    dp[i] = INF;
  }
  dp[1] = 0;
  for(int i = 1; i <= N; ++i) {
    dp[i+1] = min(dp[i+1], dp[i]+abs(h[i]-h[i+1]));
    dp[i+2] = min(dp[i+2], dp[i]+abs(h[i]-h[i+2]));
  }
  printf("%d\n", dp[N]);
}

Measured memory_bytes: 896
// AOJ 2929 Chisaki and Picnic
// 2019.4.6 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

//// 高速入力
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	while (isspace(c)) c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}


//// 優先度付きキュー（降順用）
#define QSIZE 110000
#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

typedef int QUE;
QUE que[QSIZE + 5];
int qsize;

void max_heapify(int i)
{
	int max, l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l] > que[i]) max = l; else max = i;
	if (r < qsize && que[r] > que[max]) max = r;
	if (max != i) {
		QUE qt = que[i]; que[i] = que[max], que[max] = qt;
		max_heapify(max);
	}
}

void deq()
{
	que[0] = que[--qsize];
	max_heapify(0);
}

void enq(int t)
{
	int max, i = qsize++;
	que[i] = t;
	while (i > 0 && que[max = PARENT(i)] < que[i]) {
		QUE qt = que[i]; que[i] = que[max], que[max] = qt;
		i = max;
	}
}


//// 本問題関連
#define INF 1000000005
#define MAX 100005
int N, M;
int a[MAX], b[MAX];
int c[MAX], d[MAX];

int upper_bound(int l, int x)
{
	int m, r = N;
	while (l < r) {
		m = (l + r) >> 1;
		if (a[m] <= x) l = m + 1; else r = m;
	}
	return l - 1;
}

int main()
{
	int i, j, k, n, lim;
	long long ans;

	N = in(), M = in();
	for (i = 0; i < N; i++) a[i] = in(), b[i] = in();
	c[0] = in(), d[0] = lim = in(), i = 0;
	while (lim > 1 && --M) {
		k = in(), lim = in();
		if (lim >= d[i]) continue;
		if (k > c[i]) c[++i] = k;
		d[i] = lim;
	}
	if (lim == 1) N = upper_bound(0, c[i--] - 1) + 1;
	M = i + 1, c[M] = INF, d[M] = 1;

	ans = 0; a[N] = INF + 5;  // 番兵
	for (i = 0; a[i] < c[0]; i++) ans += b[i];  // 嫌われるほど、価値のないお菓子を積算

	qsize = 0, lim = d[0];
	for (j = 1; i < N && j <= M; j++) {
		if (j == M) k = N - 1;
		else k = upper_bound(i, c[j] - 1);  // c[j]より価値の高くないお菓子
		while (i <= k) enq(b[i++]);
		n = lim - d[j], lim = d[j];
		while (n-- && qsize) ans += que[0], deq();
	}
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 2960
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;
 
int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}
 
int gcds(vector<int> A, int skip, int ans){
  int result = A[0];
  if(skip==0)result=A[1];
  for(int i=1;i<A.size();i++){
    if(i==skip)continue;
    result = gcd(A[i],result);
    if(result<=ans)break;
  }
  return result;
}
 
int gcds2(vector<int> A){
  int result = A[0];
  for(int i=1;i<A.size();i++){
    result = gcd(A[i],result);
  }
  return result;
}
 
int main()
{
  int N,ans1=0,ans2=0, ans=0;
  cin>>N;
  vector<int> A(N), B,C;
  for(int i=0;i<N;i++){
    cin>>A[i];
    if(i<N/2){
      B.push_back(A[i]);
    }else{
      C.push_back(A[i]);
    }
  }

  if(N>=10000){
    int gcd1=gcds2(B);
    int gcd2=gcds2(C);
    cout<<max(gcd1,gcd2)<<endl;
  }else{
    for(int i=0;i<N;i++){
      ans=max(ans,gcds(A,i,ans));
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1404
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

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

    map<int, int> cnt;
    REP(i, 3) {
        int a, b;
        cin >> a >> b;
        cnt[a]++;
        cnt[b]++;
    }

    bool ok = true;
    for (auto kv: cnt) {
        if (kv.second == 3) {
            ok = false;
        }
    }
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
while True:
    cnt = 0
    for i in range(n):
        m = b[(i - 1) % n] + b[(i + 1) % n]
        if 0 < m < b[i] and a[i] < b[i]:
            cnt += (b[i] - a[i]) // m
            b[i] -= (b[i] - a[i]) // m * m
    ans += cnt
    if cnt == 0:
        break
print(ans if a == b else -1)

Measured memory_bytes: 113220
// --------------
// Tejas Pandey  |
// 13 - 09 - 20  |
// Atcoder BC 178|
// --------------

#include <bits/stdc++.h>
using namespace std;
     
#define mod 1000000007
#define vi vector<int>
typedef long long int ll;
     
int main (void){
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << max(a*c,max(b*d,max(b*c,a*d))) << "\n";
  return 0;
}


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

const int N_MAX = 1000000;
int c[N_MAX+1];

int next(int n0) {
    int n1 = 0;
    for (int i = 10; i < n0; i *= 10) {
        int a = n0 / i;
        int b = n0 % i;
        n1 = max(n1, a * b);
    }
    return n1;
}

int main() {
    for (int i = 0; i < N_MAX; i++) {
        c[i] = next(i);
    }
    int q;
    while (cin >> q) {
        for (int i = 0; i < q; i++) {
            int n;
            cin >> n;
            set<int> s;
            s.insert(n);
            int ans = 0;
            while (n >= 10) {
                int n1 = c[n];
                if (s.find(n1) != s.end()) {
                    ans = -1;
                    break;
                }
                ans++;
                n = n1;
            }
            cout << ans << endl;
        }
    }
}

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

#pragma warning(disable:4996)
using namespace std;


long long int mod=1e9+7;

int main() {
	int N,M;cin>>N>>M;
	vector<long long int>v(5*N);
	int k=2*N;
	int x=2*N;
	v[k]=1;
	long long int sum=1;
	for (int i = 0; i < N; ++i) {
		k--;
		v[k]=sum;
		sum+=sum;
		if (i >= M - 1) {

			sum -= v[x];
			v[x] = 0;
			x--;

		}
		sum+=mod*10;
		sum%=mod;
	}
	long long int pown=1;
	for (int k = 0; k < N; ++k) {
		pown*=2;
		pown%=mod;
	}
	long long int ans=pown+mod*1000000-(accumulate(v.begin(),v.end(),0ll));
	ans%=mod;
	cout<<ans<<endl;
	
		return 0;
}


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

using namespace std;

class Stack{
  int seq[100];
  int top = 0;

  public:
  void push(int item){
    seq[top] = item;
    top++;
  }

  int pop(){
    if(top>0){
      top--;
      return seq[top];
    }
    return 0;
  }
};

int main(){
  Stack st;

  string str;
  while(cin>>str){
    if(str[0] >= '0' && str[0] <= '9'){
      st.push(stoi(str));
    }else{
      int a=st.pop();
      int b=st.pop();
      switch(str[0]){
        case '+':
          st.push(b+a);
          break;
        case '-':
          st.push(b-a);
          break;
        case '*':
          st.push(b*a);
          break;
      }
    }
  }
  cout<<st.pop()<<endl;
  
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
long long dp[100005];
long long a[100005],n;

long long frog(int i)
{
    if(i>=n-1) return 0;
    if(dp[i]!=-1)return dp[i];
    long long ans1=100000000000,ans2=99999999999999999;
    if(i<n-1)ans1=abs(a[i]-a[i+1])+frog(i+1);
    if(i<n-2)ans2=abs(a[i]-a[i+2])+frog(i+2);

    return dp[i]=min(ans1,ans2);
}

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

    memset(dp,-1,sizeof(dp));
    cout<<frog(0)<< endl;
    return 0;
}




Measured memory_bytes: 4992
import itertools
H, W, N = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(N)]

memo = {}
for a, b in AB:
    #0-indexed
    a -= 1
    b -= 1
    for na, nb in itertools.product(range(a - 2, a + 1), range(b - 2, b + 1)):
        if na in range(H - 2) and nb in range(W - 2):
            memo[na + H * nb] = memo.get(na + H * nb, 0) + 1
result = [0] * 10
for k, v in memo.items():
    result[v] += 1
result[0] = (H - 2) * (W - 2) - sum(result)
[print(_) for _ in result]


Measured memory_bytes: 122736
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll n, res = 0;
string str;
string longestRepeatedSubstring() 
{ 
    int n = str.length(); 
    int LCSRe[n+1][n+1]; 
  
    // Setting all to 0 
    memset(LCSRe, 0, sizeof(LCSRe)); 
  
    string res; // To store result 
    int res_length  = 0; // To store length of result 
  
    // building table in bottom-up manner 
    int i, index = 0; 
    for (i=1; i<=n; i++) 
    { 
        for (int j=i+1; j<=n; j++) 
        { 
            // (j-i) > LCSRe[i-1][j-1] to remove 
            // overlapping 
            if (str[i-1] == str[j-1] && 
                LCSRe[i-1][j-1] < (j - i)) 
            { 
                LCSRe[i][j] = LCSRe[i-1][j-1] + 1; 
  
                // updating maximum length of the 
                // substring and updating the finishing 
                // index of the suffix 
                if (LCSRe[i][j] > res_length) 
                { 
                    res_length = LCSRe[i][j]; 
                    index = max(i, index); 
                } 
            } 
            else
                LCSRe[i][j] = 0; 
        } 
    } 
  
    // If we have non-empty result, then insert all 
    // characters from first character to last 
    // character of string 
    if (res_length > 0) 
        for (i = index - res_length + 1; i <= index; i++) 
            res.push_back(str[i-1]); 
  
    return res; 
} 
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> str;
    cout << sz(longestRepeatedSubstring());
    return 0;
}

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

using namespace std;

int main()
{   
    int a,b;
    cin>>a>>b;
    int h;
    h=a+b;
    if(a-b>h) h=a-b;
    if(a*b>h) h=a*b;
    cout<<h<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std ; 
 
const int N = 1e6 +  7 ; 
 
int  n ; 
 
int main(){
    ios_base::sync_with_stdio(0) ; 
    cin.tie(0) ; 
    //freopen("in.in" , "r" , stdin) ; 
    int x ; 
    cin>>x ; 
    while(x){
        if(x%10==7)return cout<<"Yes" , 0; 
        x/=10 ; 
    }
    cout<<"No" ;
    return 0 ; 
}

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

int main(){
    char ch;
    int al[26] = {};
    while(cin >> ch){
        if('A' <= ch && ch < 'a') al[ch - 'A']++;
        else if('a' <= ch && ch <= 'z') al[ch - 'a']++;
    }
    for(int i=0;i<26; i++){
        cout << char(i+'a') << " : " << al[i] << endl;
    }
    return 0;
}


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

int main() {

  int n;
  cin >> n;
  
  vector<double> a(n);
  vector<double> b(n);
  
  double sum=0;
  for(int i=0;i<n;i++){
    cin>>a.at(i);
    b.at(i)=1/a.at(i);
    sum+=b.at(i);
  }
  
  cout << fixed << setprecision(10);
  cout << 1/sum << endl;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll d[100010];
    rep(i,0,N) cin >> d[i];
    sort(d, d+N);
    ll ans = d[N/2] - d[N/2-1];
    print(ans);
    

}

Measured memory_bytes: 1024
// abc105_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll N;
    cin >> N;

    vector<ll> u(40);
    vector<ll> d(40);
    ll mx=0;
    ll mn=0;
    REP(i, 40){
        if (i % 2 == 0){
            u[i] = mx + (1ll << i);
            d[i] = mn + (1ll << i);
        } else {
            u[i] = mx - (1ll << i);
            d[i] = mn - (1ll << i);
        }
        mx = max(mx, u[i]);
        mn = min(mn, d[i]);
    }

//    print(u);
//    print(d);

    string ans;
    REP_REV(i, 40){
        if (d[i] <= N && N <= u[i]){
            ans += '1';
            if (i % 2 == 0){
                N -= 1ll << i;
            } else {
                N += 1ll << i;
            }
        } else {
            if (ans.size() > 0) ans += '0';
        }
    }
    if (ans.size() == 0) ans = '0';
    print(ans);


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    V<int> h(n);
    for (int i = 0; i < n; i++) cin >> h[i];
    V<int> dp(n, INF);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            if (i + j >= n) break;
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    cout << dp.back() << '\n';
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    vector<int> h(n+1),dp(n+1);
    h[0]=1e9;
    for(int i=1;i<=n;i++) cin>>h[i];
    for(int i=2;i<=n;i++) dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    cout<<dp[n]<<endl;
}

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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long llint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const long long MOD = (long long)1e9 + 7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double pi = 3.14159265358979323846;

// 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();
}

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

/* べき乗(mのn乗)を計算する関数. O(logn) */
template <typename T>
T modpow(T m, T n, const T& p) {
  if (n == 0) return 1;
  T ret = modpow(m * m % p, n / 2, p);
  if (n % 2) ret *= m;
  return ret % p;
}
/* フェルマーの小定理を使って二項係数を計算. O(r) */
template <typename T>
T binomial(T n, T r, const T& p) {
  if (r > n - r) return binomial(n, n - r, p);
  T ansMul = 1;
  T ansDiv = 1;
  for (T i = 0; i < r; i++) {
    ansMul *= (n - i);
    ansDiv *= (i + 1);
    ansMul %= p;
    ansDiv %= p;
  }
  // ansDivの逆元
  T ans = (ansMul * modpow(ansDiv, p - 2, p)) % p;
  return ans;
}

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

  llint n, a, b;
  cin >> n >> a >> b;

  llint tot = modpow(2LL, n, MOD) - 1;
  if (tot < 0) tot += MOD;
  tot -= binomial(n, a, MOD);
  if (tot < 0) tot += MOD;
  tot -= binomial(n, b, MOD);
  if (tot < 0) tot += MOD;
  cout << tot << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> Pa;
typedef pair<int, pair<int, int> > PP;
//const int MAX=;

int N, M, V, P;
vi A;
void input(){
	cin>>N>>M>>V>>P;
	rep(_, N){
		int a;
		cin>>a;
		A.pb(a);
	}
	sort(all(A), greater<int>());
}

bool check(int x){
	int c = A[x];
	vi tmp;
	rep(i, N)if(i != x)tmp.pb(A[i]);
	int over = 0;
	int under = 0;

	rep(i, N-1){
		if(tmp[i] > c + M) over += 1;
		if(tmp[i] <= c) under += 1;
	}
	int nowover = N - 1 - under;
	//自分がP番目以内ならOK
	if(nowover < P) return true;
	//超えれないものがたくさんあったらだめ
	if(over >= P) return false;
	//ゴミ捨て完了ケース
	if(P+under >= V)return true;
	//ゴミ捨てきれないケース
	else{
		ll sum = 0;
		rep(i, N-1){
			if(i >= P-1 && tmp[i] > c) sum = sum + (ll)tmp[i];
		}
		ll target = ((ll)c + M) * ((ll)N - P - under);
		ll remain = (ll)M * (V - P - under);
      	//cout<<under<<" "<<target<<" "<<sum<<" "<<remain<<" "<<"! ";
		if(target >= sum + remain) return true;
		else return false;
	}
}

void solve(){
	int l = -1;
	int r = N;
	while(r-l>1){
		int mid = (l + r)/2;
		bool tmp = check(mid);
      	//cout<<mid<<" "<<tmp<<endl;
		if(tmp) l = mid;
		else r = mid;
	}
	cout<<l+1<<endl;
}

void output(){
  
}

int main(){
  input();
  solve();
  output();
}

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

#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;
using namespace __gnu_pbds;

template<typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)

long long power(long long x , long long n){
   long long ret = 1;
   while(n){
      if(n & 1)
         ret *= x;
      x *= x;
      n >>= 1;
   }
   return ret;
}

void solve(){
   int n;
   cin >> n;
   vector<int> d(n + 1);
   long long sum = 0;
   for(int &x : d)
      cin >> x , sum += x;
   long long rs = 0 , cr = 1;
   for(int i = 0 ; i <= n ; ++i){
      sum -= d[i];
      // check u have cr node , there are d[i] leafs
      if(d[i] > cr){
         cout << "-1\n";
         return;
      }
      cr = min(cr , d[i] + sum);
      rs += cr;
      long long rm = cr - d[i];
//      cout << d[i] << ' ' << rm << '\n';
//      watch(rs);
      // compare sum vs 2^rm take the min
//      rm = min(rm , sum);
//      long double lg = log2(1.0L * sum);
      if(sum / 2 < rm)
         cr = sum;
      else cr = 2 * rm;
   }
   cout << rs << "\n";
}

int main() {
#ifndef ONLINE_JUDGE
#endif
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int t = 1;
//   cin >> t;
   while(t--){
      solve();
   }
}

Measured memory_bytes: 3772
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
//const int mod = 1e9 + 7;
const int mod = 998244353;

vector<ll> fac(MAX), finv(MAX), inv(MAX);

void comInit(ll p){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(ll i=2; i<=p; i++){
		fac[i] = fac[i-1]*i % p;
		inv[i] = p - inv[p%i] * (p/i) % p;
		finv[i] = finv[i-1] * inv[i] % p;
	}
}


ll com(ll n, ll k){
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

/*vvl invmat(vvl &c, int p){
	vvl ret(p,vl(p));
	int buf;
	rep(i,p) rep(j,p) ret[i][j] = (i==j) ? 1 : 0;
	rep(i,p){
		buf = inv[c[i][i]];
		rep(j,p){
			c[i][j] *= buf; c[i][j] %= p;
			ret[i][j] *= buf; ret[i][j] %= p;
		}
		rep(j,p){
			if(i!=j){
				buf = c[j][i];
				rep(k,p){
					c[j][k] -= c[i][k] * buf % p;
					if(c[j][k] < 0) c[j][k] += p;
					ret[j][k] -= ret[i][k] * buf % p;
					if(ret[j][k] < 0) ret[j][k] += p; 
				}
			}
		}
	}
	return ret;
}*/

int main(){
	int p; cin >> p;
	vl a(p); rep(i,p) cin >> a[i];
	comInit(p);
	vvl c(p,vl(p));
	rep(i,p) c[i][0] = 1;
	rep(i,p){
		rep(j,p-1) c[i][j+1] = (c[i][j] * i) % p;
	}
	vvl d(p,vl(p,0));
	d[0][0] = 1;
	REP(i,1,p) d[i][1] = p-1;
	rep(j,p) d[p-1][j] = p-1;
	REP(i,2,p){
		REP(j,1,p-1){
			d[p-1-j][i] = p - c[i][j];
		}
	}
	rep(i,p){
		int ans = 0;
		rep(j,p){
			ans += d[i][j] * a[j] % p;
		}
		ans %= p;
		cout << ans << " ";
	}
	cout << "\n";
}

Measured memory_bytes: 156116
a = input()


if  a  == "TUE":
  print(5)
elif a  == "WED":
  print(4)
elif a  == "THU":
  print(3)
elif a  == "FRI":
  print(2)
elif a  == "SAT":
  print(1)
elif a  == "SUN":
  print(7)
else:
  print(6)

Measured memory_bytes: 2940
#include <iostream>
using namespace std;
typedef long long ll;
int main(void){
    ll a,b,c;
    cin>>a>>b;
    b++;
    c=((b-a+a%2)/2)%2;
    for(int i=1;i<43;i++){
        //cout<<c<<endl;
        ll v=((ll)1<<(ll)i),w=((ll)1<<(ll)(i+1));
        ll p=a%w,q=b%w;
        if(p<v&&q<v)continue;
        ll z=0;
        if(p>=v)z+=w-p;
        if(q>=v)z+=q;
        z%=2;
        c+=(ll)z<<i;
    }
    cout<<c<<endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == 1)return;for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> void SORT_(vector<int>& v,bool GREATER = 0){if(GREATER == 0)sort(v.begin(),v.end());else{sort(v.begin(),v.end(),std::greater<T>());}}

int DIGIT_SUM(int A)
{
  int res = 0;
  while(A>0)
  {
    res += A%10;
    A /= 10;
    // DEBUG(A);
  }
  return res;
}
void solve(void)
{  
  int N,A,B;
  cin>>N>>A>>B;
  int ANS = 0;
  for (int i = 1; i <= N; i++)
  {
    int X = DIGIT_SUM(i);
    if(X >= A && X <= B)
    ANS += i;
  }
  cout<<ANS<<endl;
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
char c[2010][2010];
ll sum[2010][2010];
ll sum2[2010][2010];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	vector<ll>p(n);
	ll res = INF;
	ll ans = 0;
	rep(i, n) {
		cin >> p[i];
		if (p[i] <= res) {
			ans++;
			res = p[i];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4816