akhauriyash/Code-Regression huggingface dataset:
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>              // for ordered set

#define C ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define NINF INT_MIN
const double pi=acos(-1); // value of pi


bool isVowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') {
        return 1;
    }
    return 0;
}

bool compare(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second<b.second;
}

// map<ll, list<ll>> m;
map<ll, ll> m;

bool isPrime(ll n) {
    for(ll i=3; i*i<=n; i+=2) {
        if(n%i==0) {
            return false;
        }
    }
    return true;
}

int main() {
    C
//     freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
    int t=1;
    // cin >> t;
    while(t--) {
        ll n, x, y, sum=0;
        cin >> n;
        ll arr[n];
        for(ll i=0; i<n; i++) {
            cin >> arr[i];
            m[arr[i]]++;
            sum+=arr[i];
        }
        ll q;
        cin >> q;
        for(ll i=0; i<q; i++) {
            cin >> x >> y;
            sum-=(m[x]*x);
            sum+=(m[x]*y);
            cout << sum << endl;
            m[y]+=m[x];
            m[x]=0;
        }
    }
}


Measured memory_bytes: 9856
h,w = map(int,input().split()) 
a = [input() for _ in range(h)]
flag = False
for i in range(1,h-1):
    for j in range(1,w-1):
        if a[i][j] == "#" and a[i][j+1] == "." and a[i+1][j] == "." and a[i-1][j] == "." and a[i][j-1] == ".":
            flag = True
        
if flag :
    print("No")
else:
    print("Yes")

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main() {
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k;
	cin >> n >>k;
	VI h(n);
	rep(i, n) cin >>h[i];
	ll ans = 0;
	rep(i, n) if(h[i] >= k) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 640
import random
import time
import copy
import math
start=time.time()
d=int(input())
c=list(map(int,input().split()))
s=[]
cli=[]
for i in range(d+1):
  ch=[]
  for j in c:
    ch.append(i*j)
  cli.append(ch)
for i in range(d):
  s.append(list(map(int,input().split())))
last=[0]*26
score=0
solution=[]
for day in range(1,d+1):
  co=[]
  dla=[]
  down=0
  for (i,j) in zip(last,c):
    down+=(day-i)*j
  for (i,j) in zip(last,c):
    dla.append(down-(j*(day-i)))
  for con in range(26):
    co.append(s[day-1][con]-dla[con])
  choice=co.index(max(co))
  score+=co[choice]
  last[choice]=day
  #print(choice+1)
  #print(score)
  solution.append(choice)
#print(score)
stemp=5000
etemp=1
def tem():
  return stemp-((stemp-etemp)*(time.time()-start)/1.9)
while time.time()-start<1.9:
  
  sc=0
  sol=copy.deepcopy(solution)
  for x in [random.randrange(d) for i in range(5)]:
    sol[x]=random.randrange(26)
  last=[0]*26
  for (day,i) in zip(range(1,d+1),sol):
    sc+=s[day-1][i]
    last[i]=day
    for (i,j) in zip(last,range(26)):
      sc-=cli[day-i][j]
  try:
    prob = math.exp((sc-score)/tem())
  except:
    prob=0
  #print("{} {}".format(sc,prob))
  if prob>random.random():
    solution=copy.deepcopy(sol)
    score=sc
    #print(score)
for i in solution:
  print(i+1)
#print(sco)


Measured memory_bytes: 10548
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
char in[110];
int main(){
	scanf("%s",in);
	int n=strlen(in);
	for(int i=0;i<n;i++){
		if(in[i]!=in[n-1-i]){
			printf("No\n");return 0;
		}
	}
	for(int i=0;i<n/2;i++){
		if(in[i]!=in[n/2-1-i]){
			printf("No\n");return 0;
		}
	}
	for(int i=0;i<n/2;i++){
		if(in[n-1-i]!=in[n/2+1+i]){
			printf("No\n");return 0;
		}
	}
	printf("Yes\n");
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;


Node treeMinimum(Node x){
  return 0;

}

Node treeMaximum(Node x){
  return 0;

}

Node treeSearch(Node u, int k){
  return 0;

}

Node treeSuccessor(Node x){
  return 0;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  return ;


}

void inorder(Node u){
  if(u->key == NIL) return;

  if(u->left != NIL){
    inorder(u->left);
  }
  
  printf(" %d",u->key);

  if(u->right != NIL){
    inorder(u->right);
  }
}

void preorder(Node u){
  if(u->key == NIL) return;

  printf(" %d",u->key);

  if(u->left != NIL){
    preorder(u->left);
  }

  if(u->right != NIL){
    preorder(u->right);
  }
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
      }
  }
  z->parent = y;
  
  if(y == NIL){
    root = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25128
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int n; cin >> n;
    long long l[n+1];
    l[0] = 2;
    l[1] = 1;
    for(int i = 2; i <= n; i++){
        l[i] = l[i-1] + l[i-2];
    }
    cout << l[n] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#define ll long long
using namespace std;

ll n;
char x[23333];
ll cb;
ll ans;

int main()
{
	cin>>n>>x+1;
	for(int i=1;i<=n;i++)
		if(x[i]=='B') cb++;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
		{
			if(x[i]=='B' || x[j]=='B' || x[i]==x[j]) continue;
			ans+=cb;
			if((j-i+1)%2)
				if(x[(i+j)/2]=='B')
					ans--;
			if(i-(j-i)>0 && x[i-(j-i)]=='B')
				ans--;
			if(x[j+(j-i)]=='B')
				ans--;
		}
	cout<<ans;
	return 0;
}

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

int main() {
    
    long long int n,a,b,c,d,cnt = 0;
    string s;
    int i,j;
    
    cin>>n>>a>>b>>c>>d;
    
    cin>>s;
    
    a--;b--;c--;d--;

    if(c < d){
        swap(a,b);
        swap(c,d);
    }
    
    bool B[n];
    
    memset(B, false, sizeof(B));
    
    B[a] = B[b] = true;
    i = a;s[i] = '#';
    j = b;s[j] = '#';
    
    while(cnt < 800000){
        

        while(1){
            if(i != c){
                
                if(B[i] && s[i+1] == '.'){
                    B[i+1] = true;
                    s[i] = '.';
                    i++;
                }
                else if(B[i] && s[i+2] == '.'){
                    B[i+2] = true;
                    s[i] = '.';
                    i += 2;
                }
                
            }
            if(s[i] == '#') break;
            else s[i] = '#';
        }
           
        if(j != d){
            
            if(B[j] && s[j+1] == '.'){
                B[j+1] = true;
                s[j] = '.';
                j++;
            }
            else if(B[j] && s[j+2] == '.'){
                B[j+2] = true;
                s[j] = '.';
                j += 2;
            }
            
        }
        s[j] = '#';
        
        cnt++;
    }
    
    if(i == c && j == d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}


Measured memory_bytes: 772
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N,T,ans=100000;
  scanf("%d%d",&N,&T);
  for(int n=0;n<N;n++){
    int c,t;
    scanf("%d%d",&c,&t);
    if(t<=T)ans=min(ans,c);
  }
  if(ans==100000)printf("TLE\n");
  else printf("%d\n",ans);
  return 0;
}

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

public class Main {
    private static final BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) {
        exec(args);
    }

    public static void exec(String[] args) {
        String str = readLineStandardInput();
        int N = Integer.parseInt(str);
        if(N == N / 2 * 2){
            System.out.println(N);
        }
        else {
            System.out.println(N  * 2);
        }
    }

    private static String readLineStandardInput() {
        String str;
        try {
            str = input.readLine();
        } catch(IOException e){
            str = null;
            System.out.println(e);
        }
        return str;
    }
}


Measured memory_bytes: 22996
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;
using LL = long long;

int main(void)
{
	LL n, a, b;
	cin >> n >> a >> b;
	if (n == 1)
	{
		if (a != b)
		{
			cout << 0 << endl;
			return 0;
		}
	}
	if (a > b)
	{
		cout << 0 << endl;
		return 0;
	}
	LL ans = (n - 2) * b - (n - 2) * a + 1;
	cout << ans << endl;
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  int i = 0;
  while(i < n){
    string s;
    cin >> s;
    if(s == "Y"){
      cout << "Four" << endl;
      break;
    }
    i++;
  }
  if(i == n) cout << "Three" << endl;
}
  
    
    


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

int main() {
	int x[3000], y[3000];
	int i = 0;
	do {
		cin >> x[i] >> y[i];
		i++;
	} while (!((x[i-1] == 0) && (y[i-1] == 0)));

	for (int n = 0; n < i-1; n++) {
		if (x[n] > y[n]) {
			swap(x[n], y[n]);
		}
		cout << x[n] << ' ' << y[n] << endl;
	}

}


Measured memory_bytes: 3088
//confilm 0LL and 1LL
//confilm cornercases such as 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecVec = vector<Vec>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll r, d, x;
	cin >> r >> d >> x;
	rep(i, 10){
		x = r*x-d;
		co(x);
	}

	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
sum = 0

for i in range(len(a)):
  num = a[i]-1
  sum += b[num]
  if i >= 1 and a[i]-a[i-1] == 1:
    tmp = a[i]-2
    sum += c[tmp]
else:
  print(sum)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;
typedef vector<char> vech;


int main() {
	ll N;cin>>N;
    vel data(N);rep0(i,N){cin>>data[i];}
    ll m=1,ans=0;
    rep0(i,N){
        if(data[i]==m){m++;}
        else{ans++;}
    }
    if(ans==data.size()){cout<<-1<<endl;return 0;}
    cout<<ans<<endl;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
ll a,b;
cin >> a >> b;
if ((a + b) % 2 != 0) cout << "IMPOSSIBLE" << endl;
else
    cout << (a + b) / 2 << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
//#include<algorithm>
//#include<cmath>
//#include<string>
using namespace std;
int main() {
	int i = 4, t=0, a;
	while (i--) cin >> a, t += a;
	cout << t / 60 << endl << t % 60 << endl;
	return 0;
}

Measured memory_bytes: 3084
import java.util.Scanner;

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

		int n = sc.nextInt();

		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
			
		int plan1 = n * a;
		int plan2 = b;
		int plan;
		
		if(plan1<plan2){
			plan = plan1;
		}else{
			plan = plan2;
		}		
		System.out.println(plan);
				

	}
}

Measured memory_bytes: 23252
#include<stdio.h>
#include<algorithm>
#include <iostream>


using namespace std;

int main ()
{
    int a , b,c;
    while (scanf ("%d%d%d",&a,&b,&c)!=EOF)
    {
        if (a+b>=c && a <=c ) printf ("YES\n");
        else printf ("NO\n");
    }

    return 0 ;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char* argv[]){
  int H, W;
  scanf("%d %d", &H, &W);
  int a[H][W];
  int i,j;
  char c;
  for(i=0; i<H; ++i){
    scanf("\n");
    for(j=0; j<W; ++j){
      scanf("%c",&c);
      if(c == '#'){
        a[i][j] = 1;
      }else{
        a[i][j] = 0;
      }
    }
  }
  for(i=0;i<H;++i){
    for(j=0;j<W;++j){
      if(j == 0 || (j != W-1 && i % 2 == 0) || a[i][j] == 1){
        printf("#");
      }else{
        printf(".");
      }
    }
    printf("\n");
  }
  printf("\n");
  for(i=0;i<H;++i){
    for(j=0;j<W;++j){
      if(j == W-1 || (j != 0 && i % 2 == 1) || a[i][j] == 1){
        printf("#");
      }else{
        printf(".");
      }
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1664
# ABC 123 C

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

neck = min(a, b, c, d, e)

time = n // neck
time += 1 if n % neck != 0 else 0

print(time + 4)


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
using namespace std;
int c[3][3];
int main()
{
    for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
    scanf("%d",&c[i][j]);
    int judge=1;
    if(!(c[1][0]-c[0][0]==c[1][1]-c[0][1]&&c[1][1]-c[0][1]==c[1][2]-c[0][2]))
    judge=0;
    if(!(c[2][0]-c[0][0]==c[2][1]-c[0][1]&&c[2][1]-c[0][1]==c[2][2]-c[0][2]))
    judge=0;
    if(!(c[2][0]-c[1][0]==c[2][1]-c[1][1]&&c[2][1]-c[1][1]==c[2][2]-c[1][2]))
    judge=0;
    if(!(c[0][1]-c[0][0]==c[1][1]-c[1][0]&&c[1][1]-c[1][0]==c[2][1]-c[2][0]))
    judge=0;
    if(!(c[0][2]-c[0][0]==c[1][2]-c[1][0]&&c[1][2]-c[1][0]==c[2][2]-c[2][0]))
    judge=0;
    if(!(c[0][2]-c[0][1]==c[1][2]-c[1][1]&&c[1][2]-c[1][1]==c[2][2]-c[2][1]))
    judge=0;
    if(judge) printf("Yes");
    else printf("No");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a, b, ans = 0;
    cin >> n >> a >> b;
    rep(i, 1, n + 1){
        int tmp = i, sum = 0;
        while(tmp){
            sum += tmp % 10;
            tmp /= 10;
        }
        if(a <= sum && sum <= b) ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#pragma GCC optimize ("unroll-loops")
#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 fi first
#define se second
#define pb push_back
#define sz(x)  ((int)x.size ())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define sqrt(x) sqrt (abs(x))
#define y0 y3451
#define y1 y4562
#define j0 j25624
#define j1 j45624
#define makeunique(x) sort(all(x)), (x).resize (unique(all(x)) - (x).begin())

typedef pair <int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef long double ld;
typedef unsigned int uint;
typedef vector <string> vs;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;

template <class T> using _tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }
template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }
template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }

#define filename ""

const D pi = acos(-1.);
const int N = 2e5 + 20;
const int inf = 1e9 + 7;

int n, m, k;
int c[N], v[N];
ll dp[110][N];
int w;

int main() {
	cin >> n >> w;
	for (int i = 0; i < n; i++)
		scanf("%d%d", v + i, c + i);
	for (int i = 0; i < n; i++)
		for (int j = 0; j <= w; j++)
			dp[i][j] = -1;
	dp[0][0] = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j <= w; j++)
			if (dp[i][j] != -1) {
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
				if (j + v[i] <= w)				
					dp[i + 1][j + v[i]] = max(dp[i + 1][j + v[i]], dp[i][j] + c[i]);
			}
	ll ans = 0;
	for (int i = 0; i <= w; i++)
		ans = max(dp[n][i], ans);
	cout << ans;
	return 0;
}


Measured memory_bytes: 159232
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
ll A[5000001],bin[5000001];
vector<ll>v;
map<int,int>myMap;
set<int>mySet;
vector<pair<ll,ll> >vp;
/* Precode Start Here *\



     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
 ll n,sum=0,d=0;
 cin>>n;
 for(int i=0;i<n;i++)
 {
     cin>>A[i];
     sum+=A[i];
 }
 for(int i=0;i<n;i++)
 {
     d+=A[i];
     if(d==sum-d)
     {
         cout<<0<<endl;
         return 0;
     }
     if(d>sum-d)
     {
         ll p=d-sum+d;
         d-=A[i];
         ll q=sum-d-d;
         cout<<min(p,q)<<endl;
         return 0;
     }
 }
return 0;
}



Measured memory_bytes: 2304
import qualified Data.Vector.Unboxed as V
import Control.Monad
import Data.Maybe
import Data.List
import qualified Data.ByteString.Char8 as BS
readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine

tw :: (a -> Bool) -> [a] -> [a]
tw p (x:xs) = if p x then x:tw p xs else [x]

main = do
  [n,k] <- getIntList
  p <- V.fromList . map (+(-1)) <$> getIntList
  c <- V.fromList <$> getIntList
  let acc i = tail $ scanl' (+) 0 $ map ((c V.!).(p V.!)) $ tw (/=i) (iterate (p V.!) (p V.! i))
      ans i = 
        if val > 0
          then
            if rem /= 0
              then num * val + maximum (take (fromIntegral rem) list)
              else (num-1) * val + maximum list
          else maximum list
        where list = acc i
              val = last list
              len = fromIntegral $ length list
              num = k `div` len
              rem = k `mod` len
  print $ maximum $ map ans [0..n-1]


Measured memory_bytes: 7104
h,w = map(int,input().split())
list1 = []
for i in range(h):
  list1.append(list(input()))

def del_rows(r):
  del list1[r]

def del_cols(c):
  for l in range(h):
    del list1[l][c]
i = 0
#colの削除
while True:
  flag = 1
  if i >= len(list1[0]):
    break
  for j in list1:
    if j[i] == "#":
      flag = 0
      break
  if flag:
    del_cols(i)
  else:
    i += 1
#rowの削除
i = 0
while True:
  if i >= len(list1):
    break
  if all(j == "." for j in list1[i]):
    del_rows(i)
  else:
    i += 1
for i in range(len(list1)):
  print("".join(list1[i]))

Measured memory_bytes: 40560
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var X, Y int

func main() {
	sc.Split(bufio.ScanWords)
	X, Y = nextInt(), nextInt()
	ans := 0
	tmp := X
	for tmp <= Y {
		ans++
		tmp *= 2
	}

	fmt.Println(ans)

}


Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
  int h,w,i,j;
  do{
     scanf("%d %d",&h,&w);
     if((h==0)&&(w==0)){
       break;
     }
     for(i=0;i<h;i++){
         if((i==0)||(i==(h-1))){
            for(j=0;j<w;j++){
                printf("#");
            }
            printf("\n");
         }else if(0<i&&i<(h-1)){
            for(j=0;j<w;j++){
              if((j==0)||(j==(w-1))){
                printf("#");
              }else if(0<j&&j<(w-1)){
                printf(".");
              }
            }
            printf("\n");
         }
      }
      printf("\n");
   }while(1);
   return 0;
}
         


Measured memory_bytes: 2140
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    string s;
    cin>>s;
    if(s.size()>=4 && s.substr(0,4)=="YAKI")cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
/*input
16 10
1 7 12 27 52 75 731 13856 395504 534840 1276551 2356789 9384806 19108104 82684732 535447408
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}
ll n,x;
ll a[maxn];
vector<ll> v;

ll cal(int i){
	ll cnt=0;
	for(ll d=0;d<n;d++){
		cnt+=a[d]*v[d/i];
	}
	return cnt+i*x;
}

int main()
{
	cin>>n>>x;
	v.pb(5);
	{
		ll meow=5;
		while(SZ(v)<n){	
			v.pb(meow);
			meow+=2;
		}
	}
	REP(i,n) cin>>a[i];

	sort(a,a+n,greater<ll>());

	ll l=1,r=n;
	ll ans;
	if(cal(l)<=cal(l+1)) ans=cal(l);
	else{
		while(l!=r-1){
			ll mid=(l+r)/2;
			if(cal(mid)<=cal(mid+1)) r=mid;
			else l=mid;
		}
		ans=cal(r);
	}
	cout<<ans+n*x<<'\n';
	return 0;
}


Measured memory_bytes: 3440
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A = deque(list(input()))
B = deque(list(input()))
C = deque(list(input()))

who = "a"
while 1:
    if who == "a":
        if not A:
            print("A")
            exit()
        who = A.popleft()
    elif who == "b":
        if not B:
            print("B")
            exit()
        who = B.popleft()
    elif who == "c":
        if not C:
            print("C")
            exit()

        who = C.popleft()


    






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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<int> A(N);
    REP(i,N) cin >> A[i];
    sort(ALL(A));
    cout << A[N-1] - A[0] << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
using namespace std;
#define MAX 31

int main(){
  int n,dp[MAX];

  dp[1] = 1; dp[2] = 2; dp[3] = 4;
  for(int i = 4 ; i < MAX ; i++)
    dp[i] = dp[i-1]+dp[i-2]+dp[i-3];

  while(cin >> n,n){
    cout << dp[n]/365/10+1 << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#define LL long long
using namespace std;
LL A,B,C,D;
LL gcd(LL a,LL b) {return a==0?b:gcd(b%a,a);}
int main()
{
	LL T;scanf("%lld",&T);
	while(T--)
	{
		scanf("%lld %lld %lld %lld",&A,&B,&C,&D);
		if(A<B) {printf("No\n");continue;}
		if(D<B) {printf("No\n");continue;}
		if(C>=B-1) {printf("Yes\n");continue;}
		A%=B;D=(D-B)%B;
		if(A>C) {printf("No\n");continue;}
		LL d=gcd(B,D),len=C-A;
		A=A+len/d*d;
		if(A+d<B) {printf("No\n");continue;}
		else {printf("Yes\n");continue;}
	}
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 #-}

import qualified  Data.HashMap.Strict as Map

main = do
  n   <- readLn
  dictionary n Map.empty

dictionary n maps = do

-- Stop condition
  if n == 0 then return ()
  else do
    s' <- getLine
    let [fOI,str] = words s'

--Separate cases with find and insert
    if fOI == "find"
       then do
         putStrLn (findDic str maps)
         dictionary (n-1) maps
       else
         dictionary (n-1) (insertDic str maps)

--Because list is slow, use Data.Map
insertDic str maps = Map.insert str "yes" maps

--Corresponds when reference is not possible by using the lookup function
findDic   str maps
  | Map.lookup str maps == Nothing = "no"
  | otherwise                      = "yes"

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

#define INF ((1<<31)-1)  //int32_t
#define MOD 1000000007
#define MOD2  

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main(){
    bool flag=true;
    ll ans=0,sum=0;
    ll N;
    cin >>N;

    ll n,h,w;

    for (ll i = 1; i <= 3500; i++)
    {
        for (ll j = 1; j <= 3500; j++)
        {
            ll p=i+j;
            ll q=i*j;

            if((4*q-N*p > 0) &&  N*q % (4*q-N*p) == 0){
                
                n = N*q/(4*q-N*p);
                h=i;
                w=j;
                
                cout <<h<<" " <<n<<" "<<w<<'\n';
                return 0;
            }
        }
        
    }
    




    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>
#define ul unsigned long long int
#define ll long long int
#define MAX 1000000+1
using namespace std;
#define F first
#define S second
#define pi 2*acos(0.0)
#define PB push_back
#define CL clear()



int main()
{

    ul sum = 0;
    ul a, b, c, x,  y, i, j,  k;
    vector<ul> aa, bb, cc;
    cin >> x >> y >> a>> b>> c;
    aa.CL;
    bb.CL;
    cc.CL;
    aa.resize(a);
    bb.resize(b);
    cc.resize(c);
    for(ul i = 0; i < a; i++)
        cin >> aa[i];
    for(ul i = 0; i < b; i++)
        cin >> bb[i];
    for(ul i = 0; i < c; i++)
        cin >> cc[i];
    sort(aa.begin(), aa.end());
    sort(bb.begin(), bb.end());
    sort(cc.begin(), cc.end());
    i  = a- 1;
    j = b- 1;
    k = c-1;
    ul t= 0;
    ul r;
    ul e, w;
    w = x;
    e = y;
    while(x+y >t )
    {
        r = 0;
        if(w && r < aa[i])
            r = aa[i];
        if(e && r < bb[j])
            r = bb[j];
        if(k >= 0 && r < cc[k])
            r = cc[k];

        if( k >= 0 && r == cc[k] )
        {
            k--;
            t++;
        }
        else if( w && r==aa[i])
        {
            i--;
            t++, w--;
        }
        else if (e)
        {
            j--, t++, e--;
        }
//        cout << x+y << endl;
        sum  += r;
    }
    cout << sum;



}




Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a - c) <= d)
  {
    cout << "Yes" << endl;
    return 0;
  }
  else if (abs(a - b) <= d && abs(b - c) <= d)
  {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
const ll inf = 1e9;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vec<ll> a(n); rep(i,n)cin >> a[i];
    sort(a.begin(),a.end());
    vec<bool> ok(1000005,true);
    rep(i,n){
        if(ok[a[i]] == false)continue;
        if(i != n-1){if(a[i] == a[i+1])ok[a[i]] = false;}
        for(ll j = 2*a[i] ; j < 1000005;j += a[i]){
            ok[j] = false; 
        }
    }
    ll ans = 0;
    rep(i,n){
        if(ok[a[i]])ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5120
import collections

#文字列を一文字ずつ取得したいとき
def inputStrOnebyOne():
    s = list(input())
    return s

#整数を一つずつリストに入れる
def inputOnebyOne_Int():
    a = list(int(x) for x in input().split())
    return a

def main():
    a,b = input().split()
    if int(a)*int(b)%2==0:
        print("Even")
    else:
        print("Odd")

if __name__=='__main__':
    main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;
const int maxn=1e5+7;
int n;
string s;
int main()
{
	cin>>n;
	cin>>s;
	bool ok=0;
	string op;
	for(int st=0;st<2;st++)
	{
		for(int ed=0;ed<2;ed++)
		{
			op=(st?"S":"W");
			for(int i=0;i<s.length()-1;i++)
			{
				char pre=(i?op[i-1]:(ed?'S':'W'));
				char cur=op[i];
				if(s[i]=='o')
				{
					if(cur=='S')
						op+=pre;
					else op+=(pre=='W'?'S':'W');
				}
				else{
					if(cur=='W')
						op+=pre;
					else op+=(pre=='W'?'S':'W');
				}
				//dbg(st,ed,i);
	//			dbg(op);
			}
			char edd=(ed?'S':'W');
			if(edd==op[s.length()-1])
			{
				if(s[s.length()-1]=='o')
				{
					char pre=op[s.length()-2];
					if((pre==op[0]&&edd=='S')||(pre!=op[0]&&edd=='W'))
					{
						ok=1;
						break;
					}
				}
				else{
					char pre=op[s.length()-2];
					if((pre==op[0]&&edd=='W')||(pre!=op[0]&&edd=='S'))
					{
						ok=1;break;
					}
				}
			}
		}
		if(ok) break;
	}
	if(!ok) cout<<"-1\n";
	else cout<<op<<'\n';
}


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

const int64_t MOD = 1000000007;

signed main() {
  int n;
  cin >> n;
  int a[n] = {};
  int maxA1 = 0;
  int maxA2 = 0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    int m = max(maxA1,a[i]);
    if( m == a[i] ){ // update maxA1
      maxA2 = maxA1;
      maxA1 = m;
    }
    else{
      maxA2 = max(maxA2,a[i]);
    }
  }
  for(int i=0;i<n;i++){
    if(a[i]==maxA1) cout << maxA2 << endl;
    else cout << maxA1 << endl;
  }
  
  return 0;
}



Measured memory_bytes: 4468
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>



#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

/*
//tenka1 2017
int main(void) {
	ll N;
	cin >> N;
	bool isEnd = false;
	rep(h, 1, 3501) {
		rep(n, 1, 3501) {
			ll child = h * n * N;
			ll parent = 4 * h * n - N*(h + n);
			if (parent > 0 && child % parent == 0) {
				ll w = child / parent;
				if (4 * h * n * w == N * (h * n + n * w + h * w)) {
					cout << h << " " << n << " " << w  << endl;
					isEnd = true;
					break;
				}
			}

		}
		if (isEnd)break;
	}
}
*/
/*
//ABC98 D

int main(void) {
	ll n;
	cin >> n;
    vector<ll> a = vector<ll>(n);	
	rep(i, 0, n)cin >> a[i];
	ll l = 0, r = 0;
	ll xorSum = 0;
	ll sum = 0;
	ll ans = 0;
	while (r < n) {
		ll xorSumNew = xorSum ^ a[r];
		ll sumNew = sum + a[r];
		if (xorSumNew == sumNew) {
			ans += r - l + 1;
			r++;
			xorSum = xorSumNew;
			sum = sumNew;
		}
		else {
			xorSum ^= a[l];
			sum -= a[l];
			l++;
		}
	}
	cout << ans << endl;
}
*/

/*
//ABC 96 D

int main(void) {
	ll n;
	cin >> n;
	vector<ll> p = vector<ll>(55556,0);
	rep(i, 2, 55556) {
		if (p[i] < 0)continue;
		else {
			for (ll j = i * 2; j < 55556; j += i) {
				p[j] = -1;
			}
		}
	}
	ll count = 1;
	for (ll j = 5; j + 2 < 55556; j += 10) {
		if (p[j + 2] == 0) {
			if (count < n) {
				cout << j + 2 << " " << endl;
				count++;
			}
			else {
				cout << j + 2 << endl;
				break;
			}
		}
	}
}
*/

//ABC 95 D
int main(void) {
	ll n, c;
	cin >> n >> c;
	vector<ll> x = vector<ll>(n), s = vector<ll>(n);
	rep(i, 0, n)cin >> x[i] >> s[i];
	vector<ll> r = vector<ll>(n), l = vector<ll>(n);
	vector<ll> rTwice = vector<ll>(n), lTwice = vector<ll>(n);
	r[0] = s[0] - x[0], l[0] = s[n - 1] - (c - x[n - 1]);
	rTwice[0] = r[0] - x[0], lTwice[0] = l[0] - (c - x[n - 1]);
	rep(i, 1, n) {
		r[i] = s[i] + r[i - 1] + x[i - 1] - x[i];
		rTwice[i] = r[i] - x[i];
		l[i] = s[n - 1 - i] + l[i - 1] + x[n - 1 - i] - x[n - i];
		lTwice[i] = l[i] - (c - x[n - 1 - i]);
	}
	vector<ll> rMax = vector<ll>(n), lMax = vector<ll>(n);
	rMax[0] = r[0], lMax[0] = l[0];
	rep(i, 1, n) {
		rMax[i] = max(rMax[i - 1], r[i]);
		lMax[i] = max(lMax[i - 1], l[i]);
	}
	ll ans = 0;
	rep(i, 0, n - 1) {
		ans = max(ans, max(r[i], l[i]));	
		ans = max(ans, rTwice[i] + lMax[n - 2 - i]);
		ans = max(ans, lTwice[i] + rMax[n - 2 - i]);
	}
	ans = max(ans, max(r[n - 1], l[n - 1])); 
	cout << ans << endl;
}


Measured memory_bytes: 6528
#include<stdio.h>
int main(){
	int cnt=0,i,j,k,n,x,y;
	char map[101][101];
	scanf("%d%d%d",&n,&k,&x);
	for(i=0;i<n;i++)scanf("%s",map[i]);
	for(i=0;i<n;i++){
		for(j=0;j<k-x+1;j++){
			if(map[i][j]=='#')continue;
			else{
				for(y=j;y<x+j;y++){
					if(map[i][y]=='#')break;
					else if(y==x+j-1)++cnt;
				}
			}
		}
	}
	for(j=0;j<k;j++){
		for(i=0;i<n-x+1;i++){
			if(map[i][j]=='#')continue;
			else{
				for(y=i;y<x+i;y++){
					if(map[y][j]=='#')break;
					else if(y==x+i-1)++cnt;
				}
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}


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

signed main(){
  lint N, K; cin >> N >> K;
  vector<lint> a(N);
  for(int i = 0; i < K; i++){
    int d; cin >> d;
    for(int j = 0; j < d; j++){
      int x; cin >> x; a[x - 1]++;
    }
  }
  lint ans = 0;
  for(lint i = 0 ;i < N; i++) if(a[i] == 0) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3636
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data',function(chunk){

var line = chunk.split(' ');
var W = Number(line[0]);
var H = Number(line[1]);
var x = Number(line[2]);
var y = Number(line[3]);
var r = Number(line[4]);

if(W >= x+r && H >= y+r && 0 <= x-r && 0 <= y-r){
console.log("Yes")
}else{
console.log("No")
}
});

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

using namespace std;

#define MAX_N 501
#define MAX_M 501
typedef long long ll;
const ll MOD = 10000LL;

int M;
ll dp[MAX_N][MAX_M][10][2][3];

ll dfs(int idx, int m, int d, bool lt, int up, string &s)
{
    if (idx == (int)s.size()) {
        return (m == 0);
    }
    ll &res = dp[idx][m][d][lt][up];
    if (res != -1) return res;
    
    res = 0;    
    int num = s[idx] - '0';
    for (int i = 0; i < 10; i++) {
        int nup = -1;
        if (lt || i <= num) {
            if (up == 0 && d < i) {
                nup = 1;
            } else if (up == 1 && d > i) {
                nup = 0;
            } else if (up == 2) {
                if (d == 0) {
                    nup = 2;
                } else if (d > i) {
                    nup = 0;
                } else if (d < i) {
                    nup = 1;
                }
            }
            if (nup != -1) {
                res += dfs(idx + 1, (10*m + i) % M, i, lt || (i < num), nup, s);
            }            
            res %= MOD;
        }            
    }
    return res;
}

void sub(string &A)
{
    for (int i = (int)A.size()-1; i >= 0; i--) {
        int num = (A[i] - '0'); num--;
        if (num == -1) {
            A[i] = '9';
        } else {
            A[i] = num + '0';
            return;
        }
    }
}

int main()
{
    string A, B;
    cin >> A >> B >> M;

    sub(A);    
    memset(dp, -1, sizeof(dp));
    ll va = dfs(0, 0, 0, 0, 2, A);
    
    memset(dp, -1, sizeof(dp));    
    ll vb = dfs(0, 0, 0, 0, 2, B);

    cout << (vb - va + MOD) % MOD << endl;
    return 0;
}

Measured memory_bytes: 120916
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<20)
#define LLINF (1LL<<60)
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
    int n, m;
    ll sum = 0;
    cin >> n >> m;
    rep(i,m){
        int t;
        cin >> t;
        sum += t;
    }
    if(n<sum){
        cout << "-1";
    }
    else{
        cout << n - sum;
    }
    return 0;
}

Measured memory_bytes: 3624