akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n;
ll ma[110][5][2];
ll p[110][10];
Vi tb[5][2];

ll calc(ll bit){
    Vi v;
    ll ans = 0;
    v.resize(n,0);
    rep(i,10){
        if(bit & (1<<i)){
            rep(j,tb[i%5][i/5].size()){
                v[tb[i%5][i/5][j]]++;
            }
        }
    }
    rep(i,n){
        ans += p[i][v[i]];
    }
    return ans;
}


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n;
    rep(i,n){
        rep(j,5){
            rep(k,2){
                cin>>ma[i][j][k];
                if(ma[i][j][k]){
                    tb[j][k].pb(i);
                }
            }
        }
    }
    rep(i,n){
        rep(j,11){
            cin>>p[i][j];
        }
    }
    ll ans = -INF;
    rep(i,1<<10){
        if(i==0)continue;
        chmax(ans,calc(i));
        //if(calc(i)==-1)cout<<i<<" "<<calc(i)<<endl;
    }
    
    print(ans);
    return 0;
}

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

int main() {
  
  int N;
  string S;
  cin >> N >> S;
  
  vector<char> A(26);
  A = {'A','B','C','D','E','F','G','H','I','J','K','L',
                        'M','N','O','P','Q','R','S','T','U','V','W','X',
                        'Y','Z'};
  
  int k = S.size();
  
  for(int i=0; i<k; i++) {
    for(int j=0; j<26; j++) {
      if(S.at(i) == A.at(j)) {
        cout << A.at((j+N)%26);   
      }
    }
  }
  
  cout << endl;
  
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    ll x;
    ll i = 1;
    ll sum = 0;
    
    cin >> x;
        
    while(true){
        sum += i;
        
        if(sum >= x){
            break;
        }
        
        i++;
    }
    
    cout << i << endl;
}

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

int n,ans;
multiset<int> s;

int main(){
	cin>>n;
	while(n--){
		int x;
		cin>>x;
		s.insert(x);
	}
	while(!s.empty()){
		int now=*s.rbegin();
		s.erase(prev(s.end()));
		for(int i=1;i<31;++i)
			if(s.count((1<<i)-now)){
				s.erase(s.find((1<<i)-now));
				++ans;
				break;
			}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> deg(n, 0);
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    deg.at(a)++;
    deg.at(b)++;
  }
  rep(i, n){
    if(deg.at(i) % 2 != 0){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int i,j,n;
	bool p[1001];
	fill(p,p+1001,false);
	p[1]=true;
	for (i=2;i<=32;i++){
		for (j=2;pow(i,j)<=1000;j++){
			p[(int)(pow(i,j)+0.1)]=true;
		}
	}
	cin>>n;
	while (p[n]==false){
		n--;
	}
	cout<<n;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1e9+7;
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;

int main(){
    int ans = 0, temp = 0;
    string S;
    cin >> S;
    REP(i, S.length()){
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T'){
            temp++;
            ans = max(ans, temp);
        }
        else{
            ans = max(ans, temp);
            temp = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

bool dp[105][10005];
int n, a[105];

int main(){
	cin >> n;
	int sum = 0;
	FORI(0, n) {
		cin >> a[i+1];
		sum += a[i+1];
	}
	dp[0][0] = true;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= sum; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j >= a[i])
				dp[i][j] |= dp[i - 1][j - a[i]];
		}
	}
	int ans = 0;
	for (int j = sum; j >= 0; j--) {
		if (dp[n][j] == true && (j % 10 != 0)) {
			ans = j;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
	ll X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;
	vector<pair<ll, int>> v;
	ll sum = 0 ;
	for (int i = 0; i < A; i++)
	{
		ll temp;
		cin >> temp;
		v.push_back({temp, 1});
	}
	for (int i = 0; i < B; i++)
	{
		ll temp;
		cin >> temp;
		v.push_back({temp, 2});
	}
	for (int i = 0; i < C; i++)
	{
		ll temp;
		cin >> temp;
		v.push_back({temp, 3});
	}
	sort(v.begin(), v.end());
	reverse(v.begin(),v.end());
	int nox = 0;
	int noy = 0;
	for (int i = 0; i < X + Y; i++)
	{
		if (v[i].second == 1)
			nox++;
		else if (v[i].second == 2)
			noy++;
	}
	int diffx = 0;
	int diffy = 0;
	if (nox >X)
	{
		for (auto it : v)
		{
			if (it.second == 1)
			{
				diffx++;
				sum += it.first;
			}
			if (diffx == X)
				break;
		}
		for (auto it : v)
		{
			if (it.second != 1)
			{
				diffy++;
				sum += it.first;
			}
			if(diffy == Y)
				break;
		}
	}
	else if (noy > Y)
	{
		for (auto it : v)
		{
			if (it.second == 2)
			{
				diffy++;
				sum += it.first;
			}
			if (diffy == Y)
				break;
		}
		for (auto it : v)
		{
			if (it.second != 2)
			{
				diffx++;
				sum += it.first;
			}
			if(diffx == X)
				break;
		}

	}
	else
	{
		for(int i = 0;i<X+Y;i++)
		{
			sum += v[i].first;
		}
	}
	cout << sum;
	
}


Measured memory_bytes: 10604
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll powmod(ll n, ll k, ll m) {
ll r=1;
 for(; k>0; k >>=1) {
   if(k&1) r=(r*n)%m;
   n=(n*n)%m;
 }
  return r;
}

ll fact(ll n) {
ll a=1;
rep(i,n) {
a=a*(n-i);
}
return a;
}

ll pow(ll a, ll b) {
ll x=1;
rep(i,b) {
x=x*a;
}
return x;
}

struct UF{
    vl par;
    UF(ll N):par(N){
        rep(i,N)par[i]=i;
    }
    ll root(ll x){
        if(par[x]==x)return x;
        return par[x]=root(par[x]);
    }
    bool same(ll x,ll y){
        return root(x)==root(y);
    }
    void unite(ll x,ll y){
        x=root(x),y=root(y);
        if(x==y)return;
        par[x]=y;
        return;
    }
};

int main() {
  ll D;
  ll T;
  ll S;
  cin >>D>>T>>S;
  double a=(double)D/(double)S;
  if(a<=T) {
cout<<"Yes"<<endl;
  }
else {
cout<<"No"<<endl;
}
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int h,w;cin>>h>>w;
for(int i=0;i<h;i++){
    vector<char>a(w);
    for(int i=0;i<w;i++)cin>>a[i];
    for(int i=0;i<w;i++)cout<<a[i];
    cout<<endl;
    for(int i=0;i<w;i++)cout<<a[i];
    cout<<endl;
}

}

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

void dfs(vector<vector<int>> &G, vector<int> &P, vector<int> &D, int u){
  for(int i=0;i<G[u].size();i++){
    int v = G[u][i];
    if(D[v]!=-1) continue;
    P[v] = u;
    D[v] = D[u]+1;
    dfs(G,P,D,v);
  }
  return;
}

int main(){
  int N;
  cin >> N;
  vector<vector<int>> G(N,vector<int>(0));
  for(int i=0;i<N-1;i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  vector<int> P(N,-1), D(N,-1);
  D[0] = 0;
  dfs(G,P,D,0);
  
  vector<int> V(3,0),W(3);
  W[1] = (N+2)/3;
  W[2] = (N+1)/3;
  W[0] = N/3;
  for(int i=0;i<N;i++){
    D[i] %= 2;
    D[i]++;
    V[D[i]]++;
  }
  
  if(V[1]<W[1] && V[1]<W[2]){
    for(int i=0;i<N;i++){
      if(D[i]==1) D[i] = 0;
    }
    V[0] = V[1];
    V[1] = 0;
    for(int i=0;i<N;i++){
      if(D[i]==2 && V[2]>W[2]){
        if(V[1]<W[1]){
          D[i] = 1;
          V[1]++;
        }
        else{
          D[i] = 0;
          V[0]++;
        }
        V[2]--;
      }
    }
  }
  else if(V[2]<W[2] && V[2]<W[2]){
    for(int i=0;i<N;i++){
      if(D[i]==2) D[i] = 0;
    }
    V[0] = V[2];
    V[2] = 0;
    for(int i=0;i<N;i++){
      if(D[i]==1 && V[1]>W[1]){
        if(V[2]<W[2]){
          D[i] = 2;
          V[2]++;
        }
        else{
          D[i] = 0;
          V[0]++;
        }
        V[1]--;
      }
    }
  }
  else{
    if(V[1]<W[1] || V[2]<W[2]){
      for(int i=0;i<N;i++){
        if(D[i]==1) D[i] = 2;
        else D[i] = 1;
      }
      swap(V[1],V[2]);
    }
    
    for(int i=0;i<N;i++){
      if(D[i]==1 && V[1]>W[1]){
        D[i] = 0;
        V[1]--;
      }
      if(D[i]==2 && V[2]>W[2]){
        D[i] = 0;
        V[2]--;
      }
    }
  }
  
  vector<int> C(3,0);
  C[0] = 1;
    for(int i=0;i<N;i++){
      cout << C[D[i]]*3+D[i] << " ";
      C[D[i]]++;
    }
  return 0;
}


Measured memory_bytes: 22656
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    vector<int> V(5);
    rep(i, 5) cin >> V.at(i);
    vector<int> P = {0,1,2,3,4};
    int final = 1<<30;
    do {
        int sum = 0;
        rep(i,4) sum += (V[P[i]] + 9) / 10 * 10;
        sum += V[P[4]]; 
        final = min(final, sum);
    } while(next_permutation(begin(P), end(P)));
    cout << final << endl;
}


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

int main() {
  int a,b;
  int d=0;
  int e=1;
  cin>>a>>b;
  int c;
  for(int i=0;i<a;i++){
    cin>>c;
    d+=c;
    if(d<=b){
      e++;
    }
  }
  cout<<e<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<ll,pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main(){
    ll n;
    string s;
    cin >> n >> s;
    vector<int> r, w;
    rep(i, n){
        if(s[i] == 'R')r.push_back(i);
        else w.push_back(i);
    }
    reverse(all(r));
    int ans = 0;
    rep(i, min(r.size(), w.size())){
        if(r[i] > w[i]){
            swap(s[r[i]], s[w[i]]);
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4680
#include <iostream>
#include<cmath>
#include<stdio.h>
using namespace std;

int main()
{
    int n,m=1,l=0,x[20],y[20];
    double f=0,g=0;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        // m=i*m;
        l=l+i;
    }
    l=l-n;
    double h;
    h=(n-1)*1.0/l;
    for(int i=1; i<=n; i++)
    {
        cin>>x[i]>>y[i];
    }
    for(int i=1;i<=n-1;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            f=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
            g=g+sqrt(f);
        }
    }
    printf("%.10f",g*h);

}


Measured memory_bytes: 256
'use strict'

const main = (input) => {
    input = input.split('\n')
    const N = parseInt(input[0].split(' ')[0])
    const K = parseInt(input[0].split(' ')[1])
    const arr = input[1].split(' ').map(v => parseInt(v))

    let dist = 100000000000
    // 通るべき点を調べ上げる
    for(let i = 0; i <= arr.length - K; i++){
        let left = arr[i]
        let right = arr[i + K - 1]
        // 左端からスタートするときの距離
        const a = Math.abs(left) + Math.abs(left - right)
        // 右端からスタートするときの距離
        const b = Math.abs(right) + Math.abs(right - left)
        const min = Math.min(a, b)
        if(dist > min){
            dist = min
        }
    }
    console.log(dist)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

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

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

    sort(a, a + n);
    int64_t s = 0;
    int32_t u = -1;
    for (int32_t i = 0; i < n - 1; i++) {
        s += a[i];
        if (s * 2 < a[i + 1]) {
            u = i;
        }
    }
    cout << n - (u + 1) << endl;
}

Measured memory_bytes: 640
n=int(input())
slist=[input() for i in range(n)]
m,a,r,c,h = 0,0,0,0,0
for s in slist:
  if s[0]=="M":
    m += 1
  if s[0]=="A":
    a+=1
  if s[0]=="R":
    r+=1
  if s[0]=="C":
    c+=1
  if s[0]=="H":
    h+=1
li=[m,a,r,c,h]
li=[i for i in li if i>0]
import itertools
if len(li)<3:
  print(0)
  exit()

b = list(itertools.combinations(li, 3))
ans=0
for i in b:
  ans += i[0]*i[1]*i[2]
print(ans)

Measured memory_bytes: 9856
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    string S;
    cin >>S;
    
    if(S<="2019/04/30"){
        cout<<"Heisei"<<endl;
    }else{
        cout<<"TBD"<<endl;
    }
    


    return 0;
    

}

Measured memory_bytes: 3600
#include <stdio.h>
int main(void){
    int w, h, x, y, r;
    scanf ("%d %d %d %d %d", &w, &h, &x, &y, &r);
    if(x-r>=0 && x+r<=w && y-r>=0 && y+r<=h)
        printf("Yes\n");
    else printf ("No\n");
    return 0;
    
}



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

int main() {
  int k;
  string s, ans;
  cin >> k >> s;

  if (s.size() <= k) {
    cout << s << endl;    
  } else {
  cout <<     s.substr(0, k)+"..." << endl;
  }
   
  return 0;
}

Measured memory_bytes: 3604
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let k = scan "%d" id

let rec list_candidates ls =
  if List.length ls >= 1_000_000 then ls
  else
    ListL.fold_left ls ~init:ls ~f:(fun ls v ->
        let d = v mod 10 in
        if d = 0 then (v*10 + d)::(v*10+d+1)::ls
        else if d = 9 then (v *10 + d)::(v*10+d-1)::ls
        else (v *10 + d-1)::(v*10+d)::(v*10+d+1)::ls)
    |> list_candidates

let () =
  list_candidates (1++9)
  |> List.sort_unique Int.compare
  |> (fun l -> List.nth l (pred k))
  |> Printf.printf "%d\n"


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

#define H_MAX 2000009

long H = 0;
long A[H_MAX];

long parent(long i) { return i / 2; }
long left(long i) { return i * 2; }
long right(long i) { return i * 2 + 1; }

void heapIncreseKey(long i, long key) {
    A[i] = key;
    while (i > 1 && A[parent(i)] < A[i]) {
        swap(A[parent(i)], A[i]);
        i = parent(i);
    }
}

void insert(long key) {
    H++;
    heapIncreseKey(H, key);
}

void maxHeapify(long i) {
    long idx_l = left(i);
    long idx_r = right(i);

    long idx_largest = i;
    if (idx_l <= H && A[idx_l] > A[i]) {
        idx_largest = idx_l;
    }
    if (idx_r <= H && A[idx_r] > A[idx_largest]) {
        idx_largest = idx_r;
    }

    if (idx_largest != i) {
        swap(A[idx_largest], A[i]);
        maxHeapify(idx_largest);
    }
}

long heapExtractMax() {
    long max;
    max = A[1];
    A[1] = A[H];
    H--;
    maxHeapify(1);

    return max;
}

int main() {
    char com[10];
    long key;

    while (true) {
        cin >> com;
        if (com[0] == 'i') {
            cin >> key;
            insert(key);
        }
        else if (com[0] == 'e' && com[1] == 'x') {
            cout << heapExtractMax() << endl;
        }
        else if (com[0] == 'e' && com[1] == 'n') {
            break;
        }
    }

    return 0;
}



Measured memory_bytes: 10864
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan= new Scanner(System.in);
		String s=scan.nextLine();
		int n=s.length();	
		StringBuilder s1=new StringBuilder(s.substring(0, (n-1)/2));
		StringBuilder s2=new StringBuilder(s.substring((n+1)/2,n));
		StringBuilder s3=new StringBuilder(s);
		s1.reverse();
		s2.reverse();
		s3.reverse();
		if(s.contains(s3) && s.substring(0, (n-1)/2).contains(s1) && s.substring((n+2)/2,n).contains(s2)) {
			System.out.println("Yes");
		}
		else System.out.println("No");
	}

}


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

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    char b;
    cin >> b;
    if(b == 'A'){
        cout << 'T' << endl;
    }

    if(b == 'T'){
        cout << 'A' << endl;
    }

    if(b == 'G'){
        cout << 'C' << endl;
    }

    if(b == 'C'){
        cout << 'G' << endl;
    }

    return 0;
}

Measured memory_bytes: 256
while True:
    try:
        s=input()
        
        joi=0
        ioi=0
        
        for i in range(len(s)-2):
            if(s[i:i+3]=="JOI"):
                joi+=1
            if(s[i:i+3]=="IOI"):
                ioi+=1
                
        print(joi)
        print(ioi)
    
    
    except EOFError:
        break


Measured memory_bytes: 5576
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for (; sc.hasNext();) {
			char[] swap = sc.nextLine().toCharArray();
			//  char[] swap = scan.next().toCharArray();    //char型の配列に格納する
			for (int i = 0; i < swap.length; i++) {
				if (Character.isUpperCase(swap[i])) { //大文字の場合
					swap[i] = Character.toLowerCase(swap[i]);
				} else if (Character.isLowerCase(swap[i])) { //小文字の場合
					swap[i] = Character.toUpperCase(swap[i]);
				} else {
					//swap[i];
				}
			}
			StringBuffer sb = new StringBuffer(new String(swap));
			System.out.print(sb.toString());
			System.out.println();
		}

	}

}



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

int main() {
  int M, N;
  cin >> N;
  map<string, int> score;
  string str;
  for (int i = 0; i < N; i++) {
    cin >> str;
    if (score.count(str)) {
      score.at(str)++;
    } else {
      score[str] = 1;
    }
  }
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> str;
    if (score.count(str)) {
      score.at(str)--;
    }
  }
  
  int max = 0;
  for (auto p: score) {
    if (max < p.second) {
      max = p.second;
    }
  }
  
  cout << max << endl;
}


Measured memory_bytes: 3588
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,k=0;
    cin>>a;
    int b[a];
    for(int i=0;i<a;i++)cin>>b[i];
    if(a%2==0){
        for(int i=0;i<a/2;i++){
            if(b[i*2]%2!=0){
                k+=1;
            }
        }
    }
    else{
        for(int i=0;i<a/2+1;i++){
            if(b[i*2]%2!=0){
                k+=1;
            }
        }
    }
    cout<<k;
}


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

int main() {
  string S;
  cin >> S;
  
  for (int i = 0; i < 4; i++) {
    cout << S.at(i);
  }
  cout << ' ';
  for (int i = 0; i < 8; i++) {
    cout << S.at(i+4);
  }
  cout << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL)
#define REP(i,a,b) for(int i=a,_b=b;i<=_b;i++)
#define rep(i,n) REP(i,0,n-1)
#define FORD(i,b,a) for(int i=b,_a=a;i>=_a;i--)
#define ford(i,n) FORD(i,n-1,0)
#define sqr(x) ((x)*(x))
#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pi>
#define vll vector<ll>
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define add push_back
#define len(arr) arr.size()
#define print(x) cout<<(x)<<'\n'
using namespace std;

const int N = 4e5 + 1;

int main() {
	SPEED;
	//freopen("in.txt", "r", stdin);
	int a, b; cin >> a >> b;
	if(a + b == 15) print('+');
	else if(a * b == 15) print('*');
	else print('x');
	return 0;
}


Measured memory_bytes: 256
import sys;input=sys.stdin.readline

N, P = map(int, input().split())
S=input().strip()
if P in {2, 5}:
    r=0
    for i in range(N):
        if not int(S[i])%P:
            r+=i+1
    print(r)
else:
    S = S[::-1]
    r=0
    from collections import defaultdict
    d=defaultdict(int)
    d[0] += 1
    R=0
    X=1
    for i in range(N):
        r += int(S[i])*X
        R += d[r%P]
        X = (X*10)%P
        d[r%P]+=1
    print(R)


Measured memory_bytes: 43052
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/
int N, M;
int a[50];
int b[50];
int c[50];
int d[50];
/**********************************/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    REP(i, N) cin >> a[i] >> b[i];
    REP(i, M) cin >> c[i] >> d[i];

    REP(i, N) {
        int min = MOD;
        int minP = -1;
        REP(j, M) {
            int dist = max(a[i]-c[j],c[j]-a[i]) + max(b[i]-d[j],d[j]-b[i]);
            if(dist < min) {
                min = dist;
                minP = j;
            }
        }
        cout << minP+1 << endl;
    }
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n=int(input())
x=list(map(int,input().split()))
s=sum(x)
a=s//n
temp=0
for i in range(n):
    temp+=(x[i]-a)**2
ans=temp
a+=1
temp=0
for i in range(n):
    temp+=(x[i]-a)**2
ans=min(ans,temp)
print(ans)



Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int n,a[2][105],dp[2][105];
int main() {
	cin>>n;
	for(int i=1;i<=2;i++) for(int j=1;j<=n;j++) {
		cin>>a[i][j];
	}
	for(int i=1;i<=2;i++) for(int j=1;j<=n;j++) {
		if (i>1) {
			dp[i][j]=max(dp[i][j],dp[i-1][j]);
		}
		if (j>1) {
			dp[i][j]=max(dp[i][j],dp[i][j-1]);
		}
		dp[i][j]+=a[i][j];
	}
	cout<<dp[2][n]<<endl;
	return 0;
}

Measured memory_bytes: 256
// In the Name of Allah. Ya Ali!
#include<bits/stdc++.h>
typedef long long ll;
const ll MAX_N = 1e5+5;
const ll MOD = 1e9+7;
using namespace std;

int dp[MAX_N];
int h[MAX_N];
int n,k;

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


Measured memory_bytes: 1024
import Data.List
main = getLine >>= putStrLn . cvt . solve
    where
        cvt b
            | b = "YES"
            | otherwise = "NO"

solve :: String -> Bool
solve ('d' : 'r' : 'e' : 'a' : 'm' : rs)
    | "era" `isPrefixOf` rs = solve rs
    | "er" `isPrefixOf` rs = solve $ drop 2 rs
    | otherwise = solve rs
solve ('e' : 'r' : 'a' : 's' : 'e' : rs) = solve rs'
    where
        rs'
            | "r" `isPrefixOf` rs = tail rs
            | otherwise = rs
solve (_ : _) = False
solve _ = True


Measured memory_bytes: 4988
#include <iostream>

int main()
{
  int a, b;

  std::cin >> a >> b;

  if (a == 2 && b == 2) {
    std::cout << 1 << std::endl;
  } else {
    std::cout << (a-1) * (b-1) << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int n,m;

int a[1000],b[1000];




int main() {

    int k;
    cin >> k;
    if( k == 1){
     cout << 1 << endl;
     return 0;
    }

    if( k%7 ==0){
        k = k/7;
    }
    
    if( __gcd(10,k) != 1){
        cout << -1 << endl;
        return 0;
    }
    
    int c = 1%k;
    int ans =1;
    while(c !=0){
        c = (10*c +1)%k;
        ans++;
    }
  cout << ans << endl;
}



 

    
 

Measured memory_bytes: 3584
data = input().split()#lines[0]つまり１行目をスペースで区切る.dataは配列
N = int(data[0])#人数
A = int(data[1])#一人分の電車料金
B = int(data[2])#N人分のタクシー料金
Bp = B / N#一人分のタクシー料金
total = []#要素数0のリストを用意

for i in range(N+1):
    total.append(A*i + Bp*(N-i))#リストに計算結果を入れていく
min = total[0]
for i in range(len(total)):
    if min > total[i]:
        min = total[i]
pri_min = int(min)
print(pri_min)

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

int n,k;
string s;

int main(){
	cin >> n >> k;
	cin >> s;
	int ans = 0;
	int part = 1;
	for(int i=1;i<s.size();i++){
		if(s[i] != s[i-1]){
			part++;
		} else {
			ans++;
		}
	}
	for(int i=1;i<=k;i++){
		if(part <= 1) break;
		if(part == 2){
			ans++;
			part--;
		} else {
			ans+=2;
			part-=2;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
a, b, c =input().split()
k = int(input())

a = int(a)
b = int(b)
c = int(c)
l = []

if k == 1:
    if a < 2*b < c or a < b < 2*c:
        l.append('Yes')
    else:
        l.append('No')
elif a < b*(2**k) < c or a < b < c*(2**k):
    l.append('Yes')
else:
    for i in range(1, k):
        if a < b*(2**(k-i)) < c*(2**i):
            l.append('Yes')
            break
        else:
            l.append('No')

d = len(l)
print(l[d-1])

Measured memory_bytes: 9208
protocol InitFromString {
    init?(_ str: String)
}

extension Int: InitFromString {}
extension Int8: InitFromString {}
extension Int16: InitFromString {}
extension Int32: InitFromString {}
extension Int64: InitFromString {}
extension String: InitFromString {}

func input<T: InitFromString>() -> [T] {
    readLine()!.split(separator: " ").map(String.init).compactMap(T.init)
}

let nm: [Int] = input()
let n = nm[0]
let m = nm[1]
let am: [Int] = input()

let sum = am.reduce(0, +)
let p = n - sum
print(p < 0 ? -1 : p)


Measured memory_bytes: 8252
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rep2(i,s,t) for(int i = s; i <= t; ++i)
#define rev(i,n) for(int i = n-1; i >= 0; --i)
#define rev1(i,n) for(int i = n; i > 0; --i)
#define rev2(i,s,t) for(int i = s; i >= t; --i)
#define F first
#define S second
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;
int main()
{
  int h,n; cin >> h >> n;
  vi a(n), b(n);
  rep(i,n) {
    cin >> a[i] >> b[i];
  }

  int inf = 1e+9;
  vii dp(n+1, vi(h+1, inf));
  dp[0][h] = 0;
  rep1(i,n) {
    rev(j,h+1) {
      dp[i][j] = min(dp[i-1][j], dp[i][min(j+a[i-1], h)] + b[i-1]);
    }
  }

  // rep(i,n+1) {
  //   rep(j,h+1) {
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << "\n";
  // }
  
  cout << dp[n][0] << "\n";
  return 0;
}


Measured memory_bytes: 42304
#include <stdio.h>
#include <string.h>
int main(void) {
	int n, i, top, buf, num, cou[2], turn, cards[2][100], bufcou, deglis[200];

	while(scanf("%d", &n)){
		if(n == 0)break;
		top = 0;
		cou[0] = n;
		cou[1] = n;
		turn = 1;
		bufcou = 0;
		memset(deglis, 0, sizeof(deglis));
	for (i = 0; n > i; i++){
		scanf("%d", &cards[0][i]);
		deglis[cards[0][i] - 1] = 1;
	}
	for (i = 0; n*2 > i; i++){
		if (deglis[i] == 0){
			cards[1][bufcou] = i + 1;
			bufcou++;
		}
	}

	while (1){
		turn = 1 - turn;
		buf = 201;
		for (i = 0; n > i; i++) if (buf > cards[turn][i] && top < cards[turn][i]) {
			buf = cards[turn][i];
			num = i;
		}

		if (buf == 201) {top = 0; continue;}
		top = buf;
		cards[turn][num] = 0;
		cou[turn]--;
		if (cou[turn] == 0) break;
		
	}
	printf("%d\n%d\n", cou[1], cou[0]);
}
	return 0;
}

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

int main(){
  	int n,k,memo = 1;
  
  	cin >> n >> k;
  
  	rep(i,0,n){
      memo = min(memo*2,memo+k);
    }
  
  	cout << memo << endl;
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

class UnionFind {
    int n;
    vector<int> uni;
public:
    explicit UnionFind(int n) : uni(static_cast<u32>(n), -1) , n(n){};

    int root(int a){
        if (uni[a] < 0) return a;
        else return (uni[a] = root(uni[a]));
    }

    bool unite(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] += uni[b];
        uni[b] = a;
        return true;
    }

    int size(int i){ return -uni[root(i)]; }
    bool same(int a, int b) { return root(a) == root(b); }
};

int main() {
    int n;
    cin >> n;
    auto G = make_v(n, n, INF<int>);
    vector<vector<int>> G1(n);
    vector<int> deg;
    UnionFind uf(2*n);
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < n; ++j) {
            if(s[j] == '1') {
                G1[i].emplace_back(j);
                G[i][j] = 1;
                uf.unite(i, n+j);
                uf.unite(i+n, j);
            }
        }
        G[i][i] = 0;
    }
    int ok = 1;
    for (int i = 0; i < n; ++i) {
        if(uf.same(i, i+n)) ok = 0;
    }
    if(!ok){
        puts("-1");
        return 0;
    }
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                G[i][j] = min(G[i][j], G[i][k]+G[k][j]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if(G[i][j] != INF<int>) ans = max(ans, G[i][j]);
        }
    }
    cout << ans+1 << "\n";
    return 0;
}

Measured memory_bytes: 640
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
d={0:1}
s=0
for i in a:
  s=(s+i)%m
  if s in d:
    d[s]+=1
  else:
    d[s]=1
    
def f(x):
  return int(x*(x-1)/2)

s=0
for i in d:
  s+=f(d[i])
print(s)

Measured memory_bytes: 14224
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int X = s.nextInt();
			final int A = s.nextInt();

			if (X < A) {
				System.out.println(0);
			} else {
				System.out.println(10);
			}
		}
	}
}


Measured memory_bytes: 22100
n=int(input())

sisu=[]
yakusu=[]
gen=n
soinsu=2
for i in range(n):
    if(soinsu**2>gen):
        if(gen!=1):
            yakusu.append(gen)
        break
    if(gen%soinsu==0):
        yakusu.append(soinsu)
        gen//=soinsu
    else:
        soinsu+=1

#print(yakusu)

kosu=len(yakusu)

if(kosu==1):
    sisu.append(1)
elif(kosu>1):
    sisu=[1]
    for i in range(1,kosu):
        if(yakusu[i]==yakusu[i-1]):
            sisu[-1]+=1
        else:
            sisu.append(1)


ans=0

for s in sisu:
    now=0
    for i in range(1,s+100):
        now+=i
        if(now>s):
            #print(s,i)
            ans+=i-1
            break

print(ans)

Measured memory_bytes: 9240
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	int a,b;
	cin>>a>>b;
	if(a+b==15) puts("+");
	else if(a*b==15) puts("*");
	else puts("x");
}


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

#define inf 0x3f3f3f3f3f3f3f
#define ll long long

const int maxn = 1e5 + 500;
ll dp[2][maxn]; //dp[0][i]表示正向走到i点获得的最大能量，dp[1][i]为反向...
ll g[2][maxn];  //g[0][i]表示正向走到i点回到x=0位置所拥有的能量，g[1][i]反之...
ll x[maxn], v[maxn];
ll n, c, sum;

int main()
{
	scanf("%lld %lld", &n, &c);
	for (int i = 1; i <= n; i++)
    {
        scanf("%lld %lld", &x[i], &v[i]);
    }

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

    //正向遍历
	for (int i = 1; i <= n; i++)
    {
		sum += v[i];
		dp[0][i] = max(dp[0][i - 1], sum - x[i]);
		g[0][i] = sum - 2 * x[i];
	}

	sum = 0;
	//反向遍历
	for (int i = n; i >= 1; i--)
    {
		sum += v[i];
		dp[1][i] = max(dp[1][i + 1], sum - (c - x[i]));
		g[1][i] = sum - 2 * (c - x[i]);
	}

	ll ans = max(dp[0][n], dp[1][1]);

	for (int i = 1; i <= n; i++)
    {
		ans = max(ans, g[0][i] + dp[1][i + 1]);
		ans = max(ans, g[1][i] + dp[0][i - 1]);
	}

	printf("%lld\n", ans > 0 ? ans : 0);//若ans<0可以选择不走

	return 0;
}


Measured memory_bytes: 4864
#include<iostream>
#include<list>
#include<set>
#include<cmath>

int main()
{
    //accept input
    std::list<int> inputs;
    int input_max = 5, n;
    while( true ){
        std::cin >> n;
        if( n == 0 ) break;
        if( n > input_max ) input_max = n;
        inputs.push_back(n);
    }

    //find prime numbers( <= input_max )
    std::list<int> primes;
    primes.push_back(3);
    std::list<int>::iterator itr;
    int sqrt_i;
    for( int i = 5; i <= input_max; i += 2 ) {
        sqrt_i = (int)std::sqrt(i);
        for( itr = primes.begin(); itr != primes.end(); itr++ ){
            if( i % *itr == 0 ) break;
            else if( *itr > sqrt_i ){
                primes.push_back(i);
                break;
            }
        }
    }

    //prime numbers -> twin prime set
    std::set<int> twin_prime_st;
    int prev = 2;
    for( itr = primes.begin(); itr != primes.end(); itr++ ){
        if( *itr == prev + 2 ) twin_prime_st.insert(*itr);
        prev = *itr;
    }

    //find each max twin price
    std::set<int>::iterator st_itr;
    for( itr = inputs.begin(); itr != inputs.end(); itr++ ){
        st_itr = twin_prime_st.upper_bound(*itr);
        st_itr--;
        std::cout << *st_itr - 2 << " " << *st_itr << std::endl;
    }

    return 0;

}


Measured memory_bytes: 3368
use std::io::stdin;

fn read_line() -> Vec<i32> {
    let mut a_str = String::new();
    stdin().read_line(&mut a_str).expect("read error");
    a_str.split_whitespace()
        .map(|x| x.parse::<i32>().expect("parse error"))
        .collect::<Vec<i32>>()
}

fn main() {
    let v = read_line();
    let h = v[0] as usize;
    let n = v[1] as usize;

    let mut m = Vec::<(i32, i32)>::new();
    for _i in 0..n {
        let v = read_line();
        m.push((v[0], v[1]));
    }

    let a_max = match m.iter().max_by(|x, y| x.0.cmp(&y.0)) {
        Some(x) => x.0,
        _ => 0,
    };
    let a_max = a_max as usize;

    let mut dp = vec![std::i32::MAX; h+a_max];

    let d_max = h + a_max as usize;

    dp[0] = 0;
    for i in 0..h {
        for x in m.iter() {
            let ni = i + x.0 as usize;
            let mp = if dp[i] == std::i32::MAX { dp[i] } else { dp[i] + x.1 };
            if mp < dp[ni] {
                dp[ni] = mp;
            }
        }
    }

    let na = 0;
    let m_min = match dp[h..d_max].iter().min() {
        Some(x) => x,
        _ => &na,
    };
    println!("{}", m_min);
}

Measured memory_bytes: 4352
#include<iostream>
#include<queue>
#include<map>
#include<cstring>
using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> PP;

int bfs();
int n;
int bill[2][222];
bool flag[2][222];

int main(){
  while(1){
    memset(bill,0,sizeof(bill));
    cin >> n;
    if(n == 0) break;
    for(int i=0;i<n;i++){
      cin >> bill[0][i];
      flag[0][i] = false;
    }
    for(int i=0;i<n;i++){
      cin >> bill[1][i];
      flag[1][i] = false;
    }
    //memset(flag,0,sizeof(flag));
    int ans = bfs();
    if(ans == -1) cout << "NA" << endl;
    else cout << ans << endl;
  }
}

int bfs(){
  queue<PP> que;
  que.push(PP(0,P(0,0)));
  que.push(PP(0,P(1,0)));
  while(!que.empty()){
    PP a = que.front();
    que.pop();
    int cou = a.first;
    int b = a.second.first;
    int k = a.second.second;
    if(bill[b][k] == 1){
      while(bill[b][k+1] == 1) k++;
    }
    else if(bill[b][k] == 2){
      while(bill[b][k] == 2) k--;
    }
    if(k == n-1) return cou;
    int v = 0;
    if(b == 0) v = 1;
    if(flag[v][k] == false){
      flag[v][k] = true;
      for(int i=0;i<3;i++){
	if(k+i < n){ 
	  que.push(PP(cou+1,P(v,k+i)));
	}
      }
    }
  }
  return -1;
}

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

const ll MOD = 998244353;

ll cal(int a, int r){
  int p = 1;
  rep(i,r){
    p*=a;
    p%=MOD;
  }
  return p;
}

main(){
  int n;
  cin>>n;
  map<int,int> mp;
  int bottom=0;
  bool corner=0;
  rep(i,n){
    int d;
    cin>>d;
    if(i==0 && d!=0) corner=1;
    if(i!=0 && d==0) corner=1;
    mp[d]++;
    bottom=max(bottom,d);
  }
  if(corner) cout<<0<<endl;
  else{
    ll ans=1;
    for(int i = 1; i <= bottom; i++){
      if(mp[i]==0){
        cout<<0<<endl;
        return 0;
      }
      ans *= cal(mp[i-1],mp[i]);
      ans%=MOD;
    }
    cout<<ans<<endl;
  }
}



Measured memory_bytes: 9812
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll ma = max(a, max(b, c));
    if((3 * ma) % 2 == (a + b + c) % 2) {
        cout << (ma * 3 - (a + b + c)) / 2;
    } else {
        cout << ((ma + 1) * 3 - (a + b + c)) / 2;
    }
}


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

using namespace std;

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

int main() {
    int n, cnt = 0;
    while (cin >> n) {
        cnt = 0;
        REP(a, 10) REP(b, 10) REP(c, 10) {
                    int d = n - a - b - c;
                    if (d >= 0 && d <= 9) cnt++;
                }
        cout << cnt << endl;
    }
    return 0;
}

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


int main(){
    string O, E;
    cin >> O >> E;
    vector<char> ans(O.size() + E.size());

    for(int i = 0; i < O.size() + E.size(); i++){
        if(i % 2 == 0){
            ans[i] = O[i / 2];
        }else{
            ans[i] = E[(i - 1)/2];
        }
    }

    for(int i = 0; i < ans.size(); i++) cout << ans[i];
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	cat N, P;
	cin >> N >> P;
	if(N == 1) {
		cout << P << "\n";
		return 0;
	}
	cat ans = 1;
	for(cat i = 2; i*i <= P; i++) if(P%i == 0) {
		int e = 0;
		while(P%i == 0) e++, P /= i;
		for(int j = 0; j < e/N; j++) ans *= i;
	}
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 256
N = int(input())
t = 0
x = 0
y = 0

for i in range(N):
    tt, xx, yy = map(int,input().split())
    if tt-t>=abs(xx-x)+abs(yy-y) and ((tt-t)-(abs(xx-x)+abs(yy-y)))%2==0:
        t = tt
        x = xx
        y = yy
    else:
        print('No')
        exit()
print('Yes')


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



int main()
{
    string s,t;
    cin >> s >> t;

    int sub = 0;
    bool same = s.size() == t.size();
    for (int i = 0; i < s.size() - t.size() + same; i++) {
        int temp_sub = 0;
        for (int j = 0; j < t.size() && i + j < s.size(); j++) {
            if (s[i + j] == t[j]) {
                temp_sub++;
            }
        }
        sub = max(temp_sub, sub);

    }
    cout << t.size() - sub << "\n";

}



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

int main() {
 int a,b,cnt=0;
 string s;
  cin >> a >>b;
  for(int i=a;i<=b;i++){
  s = to_string(i);
    if(s[0]==s[4] && s[1]==s[3]){
    cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
n, m = gets.split.map { |i| i.to_i }
d = m.times.map{|time| gets.split.map { |i| i.to_i } << time}
d << [10000000,10000000,10000000]
d.sort!

arr_all = []
j = 0
n.times do |i|
	arr = []
	while d[j][0] == i+1
		arr << d[j]
		j += 1
	end
	arr_all << arr 
end

ans = []
n.times do |i|
	arr_all[i].size.times do |j|
		ans << [(i+1).to_s.rjust(6, "0") + (j+1).to_s.rjust(6, "0"), arr_all[i][j][2]]
	end
end

ans.sort_by!{|val, index| index}

m.times do |i|
	puts ans[i][0]
end


Measured memory_bytes: 33584