akhauriyash/Code-Regression huggingface dataset:
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

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

int h(int x, int y){
	return x * x + 2 * x * y + x + 1;
}

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

	int a[3][3];
	forn(i, 3){
		forn(j, 3)cin >> a[i][j];
	}
	set<int> s;
	bool ok = true;
	forn(i, 3)s.insert(a[i][0] - a[i][1]);
	ok &= (s.size() == 1);
	//deb(ok);
	s.clear();
	forn(i, 3)s.insert(a[i][1] - a[i][2]);
	ok &= (s.size() == 1);
	deb(ok);
	s.clear();
	forn(j, 3)s.insert(a[0][j] - a[1][j]);
	ok &= (s.size() == 1);
	s.clear();
	forn(j, 3)s.insert(a[1][j] - a[2][j]);
	ok &= (s.size() == 1);
	s.clear();
	if(ok)puts("Yes");
	else puts("No");
	return 0;
}



Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        String weather = scan.next();
        switch (weather) {
            case "Sunny":
                os.println("Cloudy");
                break;

            case "Cloudy" :
                os.println("Rainy");
                break;

            case "Rainy" :
                os.println("Sunny");
                break;
        }

    }
}

Measured memory_bytes: 23124
import java.util.*;

public class Main {             
    
  public static void main(String[] args) {
   
    Scanner sc = new Scanner(System.in);                                              
    
     int N = sc.nextInt();
    
     int K = sc.nextInt();
     
     int ans = 0;
     
     for(int i = 0;i < N;i++){
         int x = sc.nextInt();
         
         int l = Math.min(x,K-x);
         
         ans += l*2;
     }
     
     System.out.println(ans);
    
  }  
}

Measured memory_bytes: 22612
A = list(input())
x = int(A[0])
y = int(A[1])
z = int(A[2])

ans = ''
a = 0
if x > y:
    a = str(x)
    ans = a + a + a
elif x == y:
    if y >= z:
        a = str(x)
        ans = a + a + a
    else:
        a = str(x + 1)
        ans = a + a + a
else:
    a = str(x + 1)
    ans = a + a + a

print(ans)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
  char a, b;
  cin >> a >> b;
  if (a == 'H') {
    if (b == 'H') {
      cout << 'H' << endl;
    } else {
      cout << 'D' << endl;
    }
  } else {
    if (b == 'H') {
      cout << 'D' << endl;
    } else {
      cout << 'H' << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3040
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define sz(a) (int)(a.size())
#define pb push_back
#define all(c) c.begin(),c.end()
#define tr(it,a,c) for(auto it=c.begin()+a;it!=c.end();it++)
#define fr(i,a,n)	for(int i=a;i<n;i++)
#define present(c,x) (c.find(x)!=c.end()) //for set/map etc.
#define cpresent(c,x) (find(all(c),x)!=c.end())
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
int N=100001;
int mod=1e9+7;


int min(int a,int b){if(a<b) return a; else return b;}
int max(int a,int b){if(a>b) return a; else return b;}
int power(int a,int b){int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int p, int q){if(p%q==0) return q; else{return gcd(q,p%q);}} 
bool comp(int a, int b) 
{ 
    return (a > b); 
}

bool comp1(pi a, pi b)
{
	if(a.first==b.first)return a.second<b.second;
	else return a.first>b.first;
}

template<typename T> 
istream& operator>>(istream& in, vector<T>& v)
{
	for (T& x : v) in >> x; return in;
}

template<typename T> 
ostream& operator<<(ostream& out, vector<T>& v)
{
	for (T& x : v) out << x<<" "; return out;
}

// template<typename T>
int sum1(vector<int>& v)
{
	int sum=0;
	// for(auto x: v)sum+=x;
	fr(i,0,v.size())sum+=v[i];
	return sum;
}





 void solve()
{
	int n;
	cin>>n;
	vi v(n);
	cin>>v;
	int a= v[0];
	int c=0;
	fr(i,0,n)
	{
		if(a>v[i])
		{
			c+=a-v[i];
		}
		else
		{
			a=v[i];
		}
	}
	cout<<c;
}

signed main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	// int t;
	// cin>>t;
	// while(t--)
	// {
	// 	solve();
	// 	cout<<endl;
	// }
	solve();
	return 0;	
}

Measured memory_bytes: 4840
import copy
import time
t1 = time.time()

def calc(T):
    res = 0
    L = [0]*26
    for i in range(D):
        res += S[i][T[i]-1]
        L[T[i]-1] = i+1
        for j in range(26):
            res -= C[j]*(i+1-L[j])
    return res

D = int(input())
C = [int(c) for c in input().split()]
S = [[int(s) for s in input().split()] for _ in range(D)]

T = [0]*D
for i in range(D):
    temp = -1
    for j in range(26):
        if temp < S[i][j]:
            temp = S[i][j]
            idx = j+1
    T[i] = idx

T2 = [0]*D
L = [0]*26
for i in range(D):
    p = -10**15
    for j in range(26):
        d = S[i][j]
        for k in range(26):
            if k == j:
                continue
            d -= C[k]*(i+1-L[k])
        if p < d:
            p = d
            idx = j+1
    T2[i] = idx

p1 = calc(T)
p2 = calc(T2)
if p2 > p1:
    T = copy.deepcopy(T2)
    p = p2
else:
    p = p1

i = 0
next = 1
while time.time()-t1 < 1.9:
    temp = T[i]
    for j in range(1, 27):
        T[i] = j
        newp = calc(T)
        if p < newp:
            p = newp
            temp = j
    T[i] = temp
            
    i += next
    if i == -1:
        i = 1
        next = 1
    elif i == D:
        i = D-2
        next = -1

for t in T:
    print(t)

Measured memory_bytes: 70984
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int A=0;
  int B=0;
  int count=0;
  vector<int>a(110);
  cin >> N;
  for(int i=0;i<N;i++) cin >> a.at(i);
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());

  for(int i=0;i<N;i++){
    if(a.at(i)==a.at(i+1)) count++;
 }
 cout << N - count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int main() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    int ans = min(b, d) - max(a, c);
    if (ans < 0) {
        cout << 0 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import collections
import itertools
t=[]
while True:
    try:
        k=int(input())
        t.append(k)
    except EOFError:
        break
counter = collections.Counter(t)
mode_v=counter.most_common()[0][-1]
it=itertools.takewhile(lambda kv:kv[-1]==mode_v,counter.most_common())
m=(k for k,v in it)
[print(i) for i in m]    


Measured memory_bytes: 6016
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

struct TNode
{
	int Index;
	TNode* Parent;
	TNode* Left;
	TNode* Right;
	
	TNode();
};

TNode::TNode()
{
	Index  = -1;
	Parent = NULL;
	Left   = NULL;
	Right  = NULL;
}

typedef std::vector<TNode> TBinaryTree;

void InputNode(TBinaryTree& Tree)
{
	int Index;
	std::cin >> Index;
	Tree[Index].Index = Index;
	
	int Left;
	std::cin >> Left;
	if(Left >= 0){
		Tree[Index].Left  = &(Tree[Left]);
		Tree[Left].Parent = &(Tree[Index]);
	}
	
	int Right;
	std::cin >> Right;
	if(Right >= 0){
		Tree[Index].Right  = &(Tree[Right]);
		Tree[Right].Parent = &(Tree[Index]);
	}
}

int GetParentIndex(const TNode& Node)
{
	return Node.Parent != NULL ? Node.Parent->Index : -1;
}

int GetSibling(const TNode& Node)
{
	if(Node.Parent == NULL) return -1;
	if(Node.Parent->Left == NULL || Node.Parent->Right == NULL) return -1;
	int Sibling = Node.Parent->Left->Index;
	if(Sibling != Node.Index) return Sibling;
	return Node.Parent->Right->Index;
}

int GetDegree(const TNode& Node)
{
	int Degree = 0;
	if(Node.Left)  Degree++;
	if(Node.Right) Degree++;
	return Degree;
}

int GetDepth(const TNode& Node)
{
	int Depth = 0;
	TNode* Counter = Node.Parent;
	while(Counter){
		Counter = Counter->Parent;
		Depth++;
	}
	return Depth;
}

int GetHeight(const TNode* Node, int Height = 0)
{
	int LeftHeight = Height;
	if(Node->Left) LeftHeight = GetHeight(Node->Left, Height + 1);
	int RightHeight = Height;
	if(Node->Right) RightHeight = GetHeight(Node->Right, Height + 1);
	return std::max(LeftHeight, RightHeight);
}

std::string GetType(const TNode& Node)
{
	if(Node.Parent == NULL) return "root";
	if(!(Node.Left || Node.Right)) return "leaf";
	return "internal node";
}

void OutputNode(const TNode& Node)
{
	std::cout << "node " << Node.Index << ": ";
	std::cout << "parent = "   << GetParentIndex(Node) << ", ";
	std::cout << "sibling = "  << GetSibling(Node) << ", ";
	std::cout << "degree = "   << GetDegree(Node)  << ", ";
	std::cout << "depth = "    << GetDepth(Node)   << ", ";
	std::cout << "height = "   << GetHeight(&Node)  << ", ";
	std::cout << GetType(Node) << std::endl;
}

int main()
{
	int Count;
	std::cin >> Count;
	TBinaryTree BinaryTree(Count);
	for(int i = 0; i < Count; i++){
		InputNode(BinaryTree);
	}
	for(int i = 0; i < Count; i++){
		OutputNode(BinaryTree[i]);
	}
	return 0;
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(i, n) for (int i = n; i >= 0; --i) 
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000000 + 7;
const static int INT_INF = 999999999;
const static llong INF = 1LL << 60;
const static double eps = 1e-6;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

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

    llong a, b, c;
    cin >> a >> b;
    c = b;
    int loop_cnt = 0;
    while (1) {
        ++loop_cnt;
        c /= 2;
        if (c == 0) break;
    }
    
    vector<llong> counter(loop_cnt, 0);
    for (int i = 0; i < loop_cnt; ++i) {
        llong tmp1 = (b / (llong)pow(2, i + 1)) * (llong)pow(2, i);
        llong tmp2 = b % (llong)pow(2, i + 1);
        ++tmp2;
        tmp1 += max((llong)0, tmp2 - (llong)pow(2, i));
        counter[i] += tmp1;
        // cout << i << " " << counter[i] << endl;
    }
    // cout << "----" << endl;
    if (a != 0) --a;
    for (int i = 0; i < loop_cnt; ++i) {
        llong tmp1 = (a / (llong)pow(2, i + 1)) * (llong)pow(2, i);
        llong tmp2 = a % (llong)pow(2, i + 1);
        ++tmp2;
        tmp1 += max((llong)0, tmp2 - (llong)pow(2, i));
        if (a) counter[i] -= tmp1;
        // cout << i << " " << tmp1 << endl;
    }

    llong ans = 0;
    rep(i, loop_cnt) {
        // cout << counter[i] << endl;
        if (counter[i] % 2 == 1) ans += (llong)pow(2, i);
    }

    cout << ans << endl;

    return 0;
}

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

int main(void){
  int a, b, k;
  cin >> a >> b >> k;

  int count = 0, res = 1;
  for(int i = min(a,b); i != 0; i --){
    if(a%i == 0 && b%i == 0){
      count ++;
      res = i;
    }
    if(count == k)
      break;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
t = input()

n = t.count('N')
s = t.count('S')
w = t.count('W')
e = t.count('E')

if ((n == 0 and s == 0) or (n > 0 and s > 0)) and\
    ((w == 0 and e == 0) or (w > 0 and e > 0)):
    print("Yes")
else:
    print("No")


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

typedef long long ll;
typedef pair<int, int> P;

int MOD=1e9+7;
ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int gcd(int x, int y){
    if(y == 0) return x;
    else return gcd(y, x % y);
}

int main(){
    ll n, m; cin>>n>>m;
    string s, t; cin>>s>>t;
    
    ll ans=n*m/gcd(n, m);
    
    ll num=(ans/n)*(ans/m); 
    ll cntn=ans/n, cntm=ans/m;
    vector<char> stringn, stringm;
    for(ll i=0; i<n; i++){
        if((cntn*i)%num==0) stringn.push_back(s[i]);
    }
    for(ll i=0; i<m; i++){
        if((cntm*i)%num==0) stringm.push_back(t[i]);
    }

    bool f=true;
    for(int i=0; i<stringn.size(); i++){
        //cout << stringn[i] << " " << stringm[i] << endl;
        if(stringn[i]!=stringm[i]) f=false;
    }
    
    if(f) cout << ans << endl;
    else cout << -1 << endl;
    
}

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

using namespace std;

using ll = long long;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    map<int, ll> mp;
    for (int i = 0; i < N; ++i) {
        int a, b;
        cin >> a >> b;
        mp[a] += b;
    }
    for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
        K -= itr->second;
        if (K <= 0) {
            cout << itr->first << endl;
            break;
        }
    }
}

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

using namespace std;
typedef long long ll;
ll  n,m;
ll dp[3000+1][3000+1];

string add1(string s){
  int carry=1;
  for(int i=s.size()-1; i>=0; i--){
    if (carry==0) return s;
    else if(s[i]=='0' && carry==1) {s[i]='1'; carry=0;}
    else if(s[i]=='1' && carry==1) {s[i]='0'; carry=1;}   
  }
}
int main() {
  ll n;
  cin>>n;
  double x;
  vector<double> dp(n+1,0);
  dp[0]=1;
  for(int i=0; i<n; i++) {
    cin>>x;
    for(int j=i+1; j>=0; j--){
      if(j>0) dp[j]=dp[j-1]*x+dp[j]*(1-x);
      else dp[j]=dp[j]*(1-x);
    }
  }
  double ans=0;
  for(int i=n; i>n/2; i--){
    ans+=dp[i];
  }
  cout<<setprecision(10)<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,n,m,r,v[105];
    cin>>n;
    for(a=0;a<n;a++)
    {
        cin>>v[a];
    }
    m=0;
    r=0;
    for(a=0;a<n;a++)
    {
        if(v[a]%2==0)
        {
            r++;
            if(v[a]%3==0||v[a]%5==0)
            {
                m++;
            }
        }
    }
    if(m==r)
    {
        cout<<"APPROVED"<<endl;
    }
    else
    {
        cout<<"DENIED"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi atan(1.0)*4
#define pb(x) push_back(x)
#define in(x) insert(x)
#define fl(x,y) for(ll i=x;i<y;i++)
int main()
{
    ll t,n,k,p,q,r,sum,ct=0,flag=0;
    string s,s1,s2,s3;
    set<ll>st;
    map<ll,ll>mp;
    vector<ll>v;
        cin>>n>>s;
        k=0;
        for(ll i=0;i<s.size();i++)
        {
            if(s[i]!='.')
            {
                k=(k*10)+(s[i]-'0');
            }
        }
        n*=k;
        cout<<n/100<<endl;
}






Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N,K;
	cin>>N>>K;
	vector<int> A(N);
	for(int i=0;i<N;++i){
		cin>>A[i];
	}
	vector< vector<LL> > fld(N+1,vector<LL>(256,0));
	fld[0][0] = 1;//初期値
	for(int i=0;i<N;++i){
		for(int num=i;num>=0;--num){
			for(int val=255;val>=0;--val){
				if(fld[num][val]){
					fld[num+1][val^A[i]] += fld[num][val];
					if(fld[num+1][val^A[i]] >= MOD ){
						fld[num+1][val^A[i]] -= MOD;
					}
				}
			}
		}
	}
	LL ans = fld[0][K];
	LL mul = 1;
	for(LL i=1;i<=N;++i){
		ans = ans + (fld[(int)i][K] * mul)%MOD;
		ans %= MOD;
		mul = ( mul*(i+1) ) % MOD;
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


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

#define MAX_N 1000

int t[MAX_N];
int cycle[MAX_N];
int dp[MAX_N][MAX_N];
int T,N,a,b;

int main(){
	while(true){
		for(int i=0;i<MAX_N;i++){
			t[i]=24;
			cycle[i]=0;
			for(int j=0;j<MAX_N;j++){
				dp[i][j]=999999999;
			}
		}
		cin>>T;
		if(T==0){break;}
		for(int i=1;i<=T;i++){cin>>cycle[i];}
		cin>>N;
		for(int i=0;i<N;i++){
			cin>>a>>b;
			t[a]=min(t[a],b);
		}
		dp[0][0]=0;
		for(int i=0;i<MAX_N-1;i++){
			for(int j=0;j<T;j++){
				if(dp[i][j]<999999999){
					if(t[i+1]>=cycle[j+1]){
						dp[i+1][(j+1)%T]=min(dp[i+1][(j+1)%T],dp[i][j]);
					}
					dp[i+1][1]=min(dp[i+1][1],dp[i][j]+1);
				}
			}
		}
		int minx=999999999;
		for(int i=0;i<T;i++){
			minx=min(dp[MAX_N-1][i],minx);
		}
		cout<<minx<<endl;
	}
}

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

int main() {
	int n, w;
	cin >> n >> w;
	vector< vector<long long int> > a(n, vector<long long int>(2));
	
	for(int i=0; i<n; i++)
		cin >> a[i][0] >> a[i][1];
	
	vector< vector<long long int> > dp(n+1, vector<long long int>(w+1, 0));
	
	for (long long int i=1; i<=n; i++) {
		for (long long int j=1; j<=w; j++) {
			if (a[i-1][0]<=j)
				dp[i][j] = max(a[i-1][1] + dp[i-1][j-a[i-1][0]], dp[i-1][j]);
			else
				dp[i][j] = dp[i-1][j];
		}
	}
	cout << dp[n][w] << endl;
}


Measured memory_bytes: 80256
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)


int main()
{
	string s;
	cin >> s;
	string t = "";
	for (auto i = 0; i < s.length(); ++i) {
		if (s[i] == '1') {
			t += '1';
		}
		else if (s[i] == '0') {
			t += '0';
		}
		else if(s[i] =='B'){
			if (!t.empty()) {
				t.pop_back();
			}
		}
	}
	cout << t << endl;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func Reverse(buf []byte) []byte {
	l := len(buf)
	res := make([]byte, l)
	for i := 0; i < l; i++ {
		res[i] = buf[l-i-1]
	}
	return res
}

func main() {
	var s string
	var n int
	fmt.Scan(&s, &n)

	var reverse bool
	head := []byte{}
	tail := []byte{}
	body := []byte(s)
	for i := 0; i < n; i++ {
		t := scanInt()
		if t == 1 {
			head, tail = tail, head
			reverse = !reverse
		} else {
			f, c := scanInt(), scanString()

			if f == 1 {
				head = append(head, c[0])
			} else {
				tail = append(tail, c[0])
			}
		}
	}

	head = Reverse(head)
	if reverse {
		body = Reverse(body)
	}

	ans := []byte{}
	ans = append(ans, head...)
	ans = append(ans, body...)
	ans = append(ans, tail...)
	fmt.Println(string(ans))
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

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

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

  CIN(N);
  int ans = 800 * N - 200 * (N / 15);

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n;
  cin>>n;
  int b[n];
  REP(i, n) cin>>b[i];
  vector<int> now;
  REP(i, n) now.push_back(b[i] - 1);
  vector<int> ans;
  bool possible = true;
  REP(i, n){
    int k = -1;
    int m = now.size();
    for(int j = m - 1; j >= 0; j--){
      if(now[j] == j){
        k = j;
        break;
      }
    }
    if(k < 0){
      possible = false;
      break;
    }
    vector<int> temp;
    for(int j = 0; j < m; j++){
      if(j == k) continue;
      temp.push_back(now[j]);
    }
    now = temp;
    ans.push_back(k + 1);
  }
  if(!possible){
    cout << -1 << endl;
    return 0;
  }
  reverse(ALL(ans));
  REP(i, n) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;
public class Main{
	public static void main(String args[]){
    	Scanner sc=new Scanner(System.in);
     	int n=sc.nextInt();
      	int k=sc.nextInt();
      	int arr[]=new int[n];
      	int diff[]=new int[n];
      	for(int i=0;i<n;i++) {
        	arr[i]=sc.nextInt();
          	if(i == 0) diff[i]=0;
          	else if(i == 1) diff[i]=Math.abs(arr[1]-arr[0]);
          	else{
            	int min=Integer.MAX_VALUE;
              	int j=i-1;
              	int count=k;
              	while( count>0 && j>=0){
                  int temp=diff[j]+Math.abs(arr[i]-arr[j]);
                	if(temp<min)
                      min=temp;
                      j--;
                      count--;
                }
              diff[i]=min;
            }
        }
      
      	System.out.println(diff[n-1]);
      	
      	
    }
}

Measured memory_bytes: 50752
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,c;
    int counter = 0;
    int sum;
    cin >> n >> m >>c;
    int B[20];
    int a;
    for (int j=0;j<m;j++){
        cin >> B[j];
    }
    
    for (int i=0;i<n;i++){
        sum = 0;
        for (int j=0;j<m;j++){
            cin >> a;
            sum += a*B[j];
        }
        if (sum + c > 0)counter++;
    }
    cout << counter << endl;
}

Measured memory_bytes: 256
function Main(input) {
	const min = input.split("\n")[0].split(" ")[0]
	const max = input.split("\n")[0].split(" ")[1]
	const d = input.split("\n")[0].split(" ")[2]
//     const min = input.split(" ")[0]
// 	const max = input.split(" ")[1]
// 	const d = input.split(" ")[2]
    let count = 0;
    for (let i = Number(min); i <= Number(max); i++) {
        if(i % d === 0) {
	        count += 1;
	    }
    }
	console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define FOR(i,a,b) for(int i=(a),i<(b),i++)
#define REP(i,n) FOR(i,0,n)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
typedef long long LL;
typedef double db;
typedef pair<int,int> PII;
const double PI=acos(-1.0);
const int INF=1e9;
const double EPS=1e-10;


int main(){
int x,a;
cin>>x>>a;
if(x<a){cout<<0<<endl;}
else if(x>=a){cout<<10<<endl;}
return 0;
}

Measured memory_bytes: 256
/**
 * @author torith
 * @date 2019-02-09
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int path[4][4];
bool solve(int now, bool used[]){

    bool frag = true;
    for (int i = 0; i < 4; ++i) {
        if(!used[i]) frag = false;
    }
    if(frag) return true;

    for (int i = 0; i < 4; ++i) {
        if(!used[i] && path[now][i] == 1) {
            used[i] = true;
            if(solve(i, used)) return true;
            used[i] = false;
        }
    }
    return false;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);


    for (int i = 0; i < 3; ++i) {
        int a; cin >> a;
        int b; cin >> b;
        path[a-1][b-1] = 1;
        path[b-1][a-1] = 1;
    }

    for (int i = 0; i < 4; ++i) {
        bool used[4] = {};
        used[i] = true;
        if(solve(i, used)){
            cout << "YES" << "\n";
            return 0;
        }
    }

    cout << "NO" << "\n";

    return 0;
}



Measured memory_bytes: 256
def main():

  U = 2*10**5
  MOD = 10**9+7

  fact = [1]*(U+1)
  fact_inv = [1]*(U+1)
  two = [1]*(U+1)
  two_inv = [1]*(U+1)

  for i in range(1,U+1):
      fact[i] = (fact[i-1]*i)%MOD
      two[i] = (two[i-1]*2)%MOD
  fact_inv[U] = pow(fact[U], MOD-2, MOD)
  two_inv[U] = pow(two[U], MOD-2, MOD)

  for i in range(U,0,-1):
      fact_inv[i-1] = (fact_inv[i]*i)%MOD
      two_inv[i-1] = (two_inv[i]*2)%MOD

  def comb(n, k):
      if k < 0 or k > n:
          return 0
      z = fact[n]
      z *= fact_inv[k]
      z %= MOD
      z *= fact_inv[n-k]
      z %= MOD
      return z

  B, W = map(int, input().split())
  p = 0
  q = 0
  for i in range(1, B+W+1):
    ans = 1 - p + q
    ans %= MOD
    ans *= two_inv[1]
    ans %= MOD
    print(ans)
    p += comb(i-1, B-1) * two_inv[i] % MOD
    p %= MOD
    q += comb(i-1, W-1) * two_inv[i] % MOD
    q %= MOD
    
if __name__ == "__main__":
  main()

Measured memory_bytes: 56536
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define speed                     \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define ll long long
#define pb push_back
#define mem1(a) memset(a, -1, sizeof(a))
#define mem0(a) memset(a, 0, sizeof(a))
#define endl "\n"
#define mod 1000000007
#define mod1 998244353
#define ff first
#define ss second
#define MAX 500005
#define N 10004
#define INF 1000000009
#define all(v) v.begin(), v.end()
#define sbit(a) __builtin_popcount(a)
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef pair<ll, ll> pll;
typedef pair<pll, ll> ppl;
typedef map<ll, ll> mpll;
typedef map<vector<ll>, ll> mpvl;
ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;

    if (x == 0)
        return 0;
    while (y > 0)
    {

        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }

    return res;
}
void solve()
{
   string s;
   cin>>s;
   ll n=s.length();
   n--;
   if(s[n]=='s')
   {
       s+='e';
       s+='s';
       cout<<s<<endl;
   }
   else
   {
        s+='s';
       cout<<s<<endl;
   }
   
}
int main()
{
    speed;
    ll kk;
    kk = 1;
    //cin >> kk;
    while (kk--)
    {

        solve();
    }
    return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
bool d[13];
int main(){
	fastIO;
	for(int i=0;i<13;i++)d[i]=0;
	int k,n; 
	cin>>n>>k;
	for(int i=0;i<k;i++){
		int x;
		cin>>x;
		d[x]=1;	
	}
	for(int i=n;i<=(int)1e6+7;i++){
		bool f=0;
		int x=i;
		while(x>0){
			int y=x%10;
			if(d[y]){
				f=1;
				break;
			}
			x/=10;
		}
		if(!f){
			cout<<i<<"\n";
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;

  vll counter(N, 0);
  char before_char = '\0';
  char now_char = S[0];

  FOR(i, 1, N){
    before_char = now_char;
    now_char = S[i];
    if(before_char == 'A' && now_char == 'C') counter[i] = counter[i-1]+1;
    else counter[i] = counter[i-1];
  }

  REP(i, Q){
    ll r, l;
    cin >> r >> l;
    r--; l--;
    ll ans;
    if(r==0) ans = counter[l];
    else ans = counter[l] - counter[r-1];

    if(r>0){
      if(S[r-1] == 'A' && S[r] == 'C') ans--;
    }
    cout << ans << "\n";
  }

  return 0;
}

Measured memory_bytes: 1872
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		int K = in.nextInt();
		String S = in.next();
		
		if(K >= S.length()) {
			System.out.println(S);
		}else {
			System.out.println(S.substring(0,K) + "...");
		}
	}
}


Measured memory_bytes: 38544
#include <iostream>

using namespace std;

int a[55];
long long dp[55][2505][55];

long long utility(int index, int sum, int count, int * a, int k)	{
	if (index < 0)
    	return 0;
    else if (index == 0)	{
    	if (count == 0)
        	return 0;
        int remainder = sum % count;
       	if (remainder)
        	return 0;
        else	{
        	int avg = sum / count;
            if (avg == k)
            	return 1;
            else
            	return 0;
        }
    }
    
    if (dp[index][sum][count] != -1)	{
    	return dp[index][sum][count];
    }
    
    long long include = utility(index - 1, sum + a[index - 1], count + 1, a, k);
    long long exclude = utility(index - 1, sum, count, a, k);
    long long total = include + exclude;
  	dp[index][sum][count] = total;
    return total;
}

long long ways(int n, int k)	{
	return utility(n, 0, 0, a, k);
}

int main()	{
  	int n, k;
    for (int i = 0; i < 55; i++)
    	for (int j = 0; j < 2505; j++)
        	for (int k = 0; k < 55; k++)
            	dp[i][j][k] = -1;
  	cin >> n >> k;
  	for (int i = 0; i < n; i++)	
      	cin >> a[i];
 	cout << ways(n, k);
  	return 0;
}

Measured memory_bytes: 59392
N = int(input())
A = list(map(int,input().split()))
a = 0
tmp = 0
for i in range(N):
  a = A.pop(0)
  if(a % 2 == 0):
    if(a % 3 != 0 and a % 5 != 0):
      print("DENIED")
      tmp = 1
      break
      
if(tmp != 1):
  print("APPROVED")

Measured memory_bytes: 3060
use std::cmp::min;
use std::io::{BufRead, StdinLock};

fn read(stdin_lock: &mut StdinLock, buf: &mut Vec<u8>, delimiter: u8) -> i32 {
    buf.clear();
    let l = stdin_lock
        .read_until(delimiter, buf)
        .expect("read_until");
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().expect("parse")
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let p = read(&mut stdin_lock, &mut buf, b' ');
    let q = read(&mut stdin_lock, &mut buf, b' ');
    let r = read(&mut stdin_lock, &mut buf, b'\n');
    println!("{}", solve(p, q, r));
}

fn solve(p: i32, q: i32, r: i32) -> i32 {
    min(min(p + q, q + r), p + r)
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <cmath>
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ll も int も longlongにしてしまう
    #define int long long

	int a, b; cin >> a >> b;
    
    if (b >= a) {
        cout << a << endl;
    } else {
        cout << a - 1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var h, w int
	fmt.Scanf("%d %d\n", &h, &w)

	grid := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Scanf("%s\n", &grid[i])
	}

	hl, wl := map[int]bool{}, map[int]bool{}

	for i := 0; i < h; i++ {
		flg := true
		for j := 0; j < w; j++ {
			if string(grid[i][j]) != "." {
				flg = false
				break
			}
		}
		if flg {
			hl[i] = true
		}
	}

	for i := 0; i < w; i++ {
		flg := true
		for j := 0; j < h; j++ {
			if string(grid[j][i]) != "." {
				flg = false
				break
			}
		}
		if flg {
			wl[i] = true
		}
	}

	for i := 0; i < h; i++ {
		if !hl[i] {
			for j := 0; j < w; j++ {
				if !wl[j] {
					fmt.Print(string(grid[i][j]))
				}
			}
			fmt.Print("\n")
		}
	}

}


Measured memory_bytes: 2088
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int j = 0;
        int m[][] = new int[200][200];
        int X[] = new int[200];
 
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            X[i] = a;
            X[i + 1] = b;
        }
 
        for (int k = 2; k <= n; k++) {
            for (int i = 1; i <= n - k + 1; i++) {
                j = i + k - 1;
                m[i][j] = 10000000;
                for (int l = i; l <= j - 1; l++) {
                    if (m[i][j] > m[i][l] + m[l + 1][j] + X[i - 1] * X[l] * X[j]) {
                        m[i][j] = m[i][l] + m[l + 1][j] + X[i - 1] * X[l] * X[j];
                        //System.out.println(m[i][j]);
                    }
                }
            }
        }
        System.out.println(m[1][n]);
    }
}



Measured memory_bytes: 26564
D = int(input())
c = [int(x) for x in input().split()]
s = [input().split() for l in range(D)]

manzoku = 0
kyounomanzoku = 0
kyounotype = 0
d = 1
last = [0]*26




for p in range(D):
    #タイプはt[p]-1,0~25 満足度増加 s[p][t[p]] p+1日目 
    #typeを出力するときは＋１するのを忘れずに
    for t in range(26):
        if kyounomanzoku < int(s[p][t]):
            kyounomanzoku = int(s[p][t])
            kyounotype = t
    print(kyounotype+1)

Measured memory_bytes: 9620
#include <stdio.h>

int main (void){
	int a = 0, b = 0, c = 0, x = 0;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	int way = 0, sum = 0;
	
	int i, j, k;
	for(i = 0;i<=a;i++){
		for(j = 0;j<=b;j++){
			for(k = 0;k<=c;k++){
				sum = 500*i + 100*j + 50*k;
				if(sum == x)way += 1;
			}
		}
	}
	printf("%d",way);
	
	return 0;
}


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

void ways(int i, int j){
    int d = 0, w;
    for(int a = 1; a <= i - 2; a++){
        for(int b = a + 1; b <= i - 1; b++){
            for(int c = b + 1; c <= i; c++){
              if(a + b + c ==j) d += 1;
            }
        }
    }
    cout << d << endl;
}

int main(){
    int n, x;
    while(1){
        cin >> n >> x;
        if(n == 0 && x == 0) break;
        ways(n, x);
    }
    
    return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();

        String[] strArray;
        int x, y;

        while(true) {
        	strArray = br.readLine().split(" ");

            x = Integer.parseInt(strArray[0]);
            y = Integer.parseInt(strArray[1]);

            if(x==0 && y==0) {
            	break;
            }
            sb.append(Math.min(x, y)).append(" ").append(Math.max(x, y)).append("\n");
        }
        System.out.print(sb);
	}
}

Measured memory_bytes: 26588
#include<stdio.h>

int average(int a[])
{
  int i,sum=0;
  for(i=0;i<5;i++){
    if(a[i]<40){
      a[i]=40;
    }
    sum=sum+a[i];
  }
  return(sum/5);
}

int main(void)
{
  int a[5];
  int s;
  int i;
  for(i=0;i<5;i++){
    scanf("%d",&a[i]);
  }

  s=average(a);
  printf("%d\n",s);
  return(0);
}

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

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            int seisuu = int.Parse(Console.ReadLine());
            string moziretu = Console.ReadLine();
            string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            string kaitou ="";
            for (int i = 0; i < moziretu.Length; i++){
                for(int n =0; n < s.Length; n++)
                {
                    if (moziretu[i] == s[n])
                    {
                        kaitou += s[(n + seisuu) % 26];
                    }
                }
            }
            Console.WriteLine(kaitou);
        }
    }
}


Measured memory_bytes: 34772
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, C = list(map(int, sys.stdin.buffer.readline().split()))
XY = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]

XY.sort()
XY = np.array(XY, dtype=int)
X = XY[:, 0]
Y = XY[:, 1]

# 右に行ってから左に行けるだけ行く
lefts = np.zeros(N + 1, dtype=int)
rights = np.zeros(N + 1, dtype=int)
lefts[1:] = np.maximum.accumulate(Y.cumsum() - X)
rights[1:] = Y[::-1].cumsum() - (C - X[::-1]) * 2
ans1 = max(lefts + rights[::-1])

# 左に行ってから右に行けるだけ行く
lefts = np.zeros(N + 1, dtype=int)
rights = np.zeros(N + 1, dtype=int)
lefts[1:] = Y.cumsum() - X * 2
rights[1:] = np.maximum.accumulate(Y[::-1].cumsum() - (C - X[::-1]))
ans2 = max(lefts + rights[::-1])

ans = max(ans1, ans2, 0)
print(ans)


Measured memory_bytes: 37872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  string S;
  cin >> S;
  set<string> s;
  int n = S.length();
  if (n == 1) {
    cout << "1\n";
    return 0;
  }
  if (n == 2) {
    if (S[0] == S[1]) {
      cout << "1\n";
    } else {
      cout << "2\n";
    }
    return 0;
  }

  int dp[n + 1][2]{};
  dp[0][0] = 1;
  dp[0][1] = 0;
  if (S[0] == S[1]) {
    dp[1][0] = 1;
    dp[1][1] = 1;
  } else {
    dp[1][0] = 2;
    dp[1][1] = 1;
  }

  for (int i = 2; i < n; i++) {
    if(S[i] != S[i - 1]) {
      dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + 1; 
      dp[i][1] = dp[i - 2][0] + 1;
    } else {
      dp[i][0] = dp[i - 1][1] + 1;
      dp[i][1] = dp[i - 2][0] + 1;
    }
  }
  cout << max(dp[n -1][0], dp[n - 1][1]) << "\n";
  return 0;
}

Measured memory_bytes: 2180
/* be name khoda */

// #define stream_enable
// #define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = ((a) + (b)) % M
#define Mul(a, b) a = (1LL * (a) * (b)) % M

stringstream sss;

// -----------------------------------------------------------------------

const ll maxn = 310;

ll N, K, M;
ll cnt[maxn][maxn];
ll dp[maxn][maxn];

void MAIN() {

    cin >> N >> K >> M;
    cnt[0][0] = 1;
    fori (i, N) {
        cnt[i + 1][0] = 1;
        fori (j, i + 1) {
            cnt[i + 1][j + 1] = (cnt[i][j + 1] + 1LL * cnt[i][j] * (i - j + 1)) % M;
        }
    }
    dp[0][0] = 1;
    fori (i, K) {
        fori (j, N + 1) {
            fori (k, j + 1) {
                Add(dp[i + 1][j], 1LL * dp[i][j - k] * cnt[j][k]);
            }
        }
    }
    cout << dp[K][N] << '\n';

}

// -----------------------------------------------------------------------

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    sss << R"(
4 3 999999999
    )";
    MAIN();
    return 0;
}


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

int main() {
  int N,M;
  cin >> N >> M;
  ll H[N];
  rep(i,N) {
    cin >> H[i];
  }

  int b[N];

  rep(i,N) {
    b[i] = 1;
  }

  rep(i,M){
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    
    if (H[tmp1-1]>=H[tmp2-1]) {
      b[tmp2-1] = -1;
    }
    if (H[tmp2-1]>=H[tmp1-1]) {
      b[tmp1-1] = -1;
    }
  }
  int ans = 0;
  rep(i,N) {
    if (b[i]==1) {
      ans++;
    }
  }
  cout << ans << endl;
}



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

int cnt(vector<int> A,int n){
    auto Iter1 = lower_bound(ALL(A),n);
    auto Iter2 = Iter1-1;
    return *Iter1-*Iter2-1;
}

int main(){
    int h,w; cin >> h >> w;
    vector<string> s(h),t(w);
    vector<vector<int>> S(h,{-1}),T(w,{-1});
    rep(i,h) {
        cin >> s[i];
        rep(j,w){
            if(s[i][j] == '#') S[i].push_back(j);
        }
        S[i].push_back(w);
    }
    rep(i,w){
        rep(j,h) if(s[j][i] == '#') T[i].push_back(j);
        T[i].push_back(h);
    }
    int ans = 0;
    rep(i,h){
        rep(j,w){
            if(s[i][j] == '.'){
                ans = max(ans,cnt(S[i],j)+cnt(T[j],i)-1);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 40448
#include <bits/stdc++.h>
using namespace std;
int main() {
    int A,N,c;
    cin >> N >> A;
   if(N>500){
       c=N/500;
       N=N-c*500;
   }

   if(A>=N){
       cout << "Yes" << endl;
   }
   else{
       cout << "No" << endl;
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define repl(k,n) for(k=0;k<n;++k)

int main() {
	long long int X, K, D;
	long long int A;
	cin >> X >> K >> D;
	if (abs(X) / D > K) {
			cout << abs(X) - K * D;
	}
	else {
		if ((abs(X) % D) > (D - abs(X) % D)) {
			if (((K - abs(X) / D) + 1) % 2 == 0) {
				cout << D - abs(X) % D;
			}
			else {
				cout << abs(X) % D;
			}
		}
		else {
			if ((K - abs(X) / D) % 2 == 0) {
				cout << abs(X) % D;
			}
			else {
				cout << D - abs(X) % D;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3580
import sys

input = sys.stdin.readline


def main():
    N = int(input())

    A = [[0 for i in range(10)] for j in range(10)]

    for i in range(1, N + 1):
        s = str(i)
        A[int(s[0])][int(s[-1])] += 1

    ans = 0
    for i in range(1, 10):
        for j in range(1, 10):
            ans += A[j][i] * A[i][j]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import math

N, D = map(int, input().split())

x = [[]]*N
for l in range(N):
    x[l] = list(map(int, input().split()))

count = 0
for i in range(N):
    for j in range(i+1, N):
        dis = 0
        for d in range(D):
            dis += (x[i][d] - x[j][d])**2
        if math.sqrt(dis).is_integer():
            count += 1

print(count)



Measured memory_bytes: 3060