akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(v) for (auto itr = v.begin(), itr != v.end(); ++itr)
#define LB(v, x) lower_bound(v.begin(), v.end(), x) - v.begin()
#define UB(v, x) upper_bound(v.begin(), v.end(), x) - v.begin()
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    string S;
    cin >> S;
    bool yes = true;
    vector<int> num(3);
    for (auto &c : S) { num[c - 'a']++; }
    REP(i, 3) REP(j, 3) yes = yes && abs(num[i] - num[j]) <= 1;

    cout << (yes ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;

int powMOD(int n,int r){
    if(r==0)return 1;
    if(r%2==0)return powMOD(n,r/2)*powMOD(n,r/2)%MOD;
    if(r%2==1)return powMOD(n,r-1)*n%MOD;
}

int modFAC(int x){
    if(x==1) return 1;
    return x*modFAC(x-1)%MOD;
}

int COM(int n,int r){
    int ret=1;
    REP(i,r){
        ret *= (n-i);
        ret %=MOD;
    }
    return ret*powMOD(modFAC(r),1e9+5)%MOD;
}

signed main(){
    int n;cin>>n;
    int ans=0;
    int c=0;
    int h[n];
    REP(i,n)cin>>h[i];
    REP(i,n-1){
        if(h[i]>=h[i+1])c++;
        else{
            chmax(ans,c);
            c=0;
        }
    }
    chmax(ans,c);
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>

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

using namespace std;

int main(){
	int f[128];
	f['T']=0;
	f['L']=1;
	f['U']=2;
	f['R']=3;
	f['D']=4;

	char s[1024]; scanf("%s",s);
	int n=strlen(s);
	rep(i,n/2){
		int a=s[2*i]-'0';
		char b=s[2*i+1];
		if(a==1){
			putchar("aiueo"[f[b]]);
		}
		else if(a==0){
			if     (b=='T') printf("wa");
			else if(b=='D') printf("wo");
			else            printf("nn");
		}
		else{
			putchar("@@kstnhmyr"[a]);
			putchar("aiueo"[f[b]]);
		}
	}
	puts("");

	return 0;
}

Measured memory_bytes: 964
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define re return
#define pb push_back
#define po pop_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define si size
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pi 3.14159265359
#define er erase
#define in insert
#define em empty
#define ft front
#define fo(i,n) for(i = 0; i < n; i++)
#define ro(i,n) for(i = n - 1; i >= 0; i--)
#define fr(i,j,n) for(i = j; i < n; i++)
#define rf(i,j,n) for(i=n-1;i>=j;i--)
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::pair<int,int> ii;
typedef std::vector<ii> vii;
typedef std::vector<std::string> vs;
typedef double dl;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> vll;
#define filename ""
using namespace std;
    int gwas=0;
    vector<int> v[(int)1e5+10];
    int was[(int)1e5+10];
    int p[(int)1e5+10];
    int c[(int)1e5+10];
void dfs(int x)
{
    was[x]=gwas;
    c[p[x]]=gwas;
    int i;
    fo(i,v[x].size())
    {
        if (!was[v[x][i]])
        {
            dfs(v[x][i]);
        }
    }
}
int main()
{
    /*
	freopen(filename".in","r",stdin);
	freopen(filename".out","w",stdout);
	*/
	/*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    */
    /*
    ios::sync_with_stdio(0);
    */
    int n,m;
    cin>>n>>m;
    int i;
    fo(i,n)
    {
        scanf("%d",&p[i]);
        p[i]--;
    }
    int a,b;
    fo(i,m)
    {
        scanf("%d%d",&a,&b);
        v[a-1].pb(b-1);
        v[b-1].pb(a-1);
    }
    fo(i,n)
    {
        if (!was[i])
        {
            gwas++;
            dfs(i);
        }
    }
    int o=0;
    fo(i,n)
    {
        if (was[i]==was[p[i]])
        {
            o++;
        }
    }
    cout<<o;
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[60000],s=0;
    cin>>n;
    for(int i = 0;i < n;i++)
    {
        cin>>a[i];
        s += a[i]-1;
    }
    cout<<s<<endl;
}


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

int main() {
    int r;
    cin >> r;
    cout << 3 * r * r << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

using namespace std;
using ll = long long;

const ll INF = 1001001001001001001;

int main() {
    int n; cin >> n;
    vector<ll> a(n), b(n);
    rep(i, n) {
        cin >> a[i];
        b[i] = a[i] - i;
    }

    sort(all(b));
    ll x = b[n / 2];

    ll ans = 0;
    rep(i, n) ans += max(x - b[i], - x + b[i]);
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int N,A,B,C,m,n;
char a,b,c,x,y,z;
int main()
{
	cin>>a>>b>>c;
	cin>>x>>y>>z;
	if(a==x) A++;
	if(b==y) A++;
	if(c==z) A++;
	cout<<A;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using ll = long long;
const ll MOD=1e9+7;
const long long INF = 1LL<<60;

int main() {
    vector<int> input(3);
    rep(i,3) cin >> input.at(i);

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

    if(input.at(0)==5 && input.at(1)==5 && input.at(2)==7) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3468
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

ll b[110000];

int main(){
  int N;
  ll H,a=0,temp;
  cin>>N>>H;

  for(int i=0;i<N;i++){
    cin>>temp>>b[i];
    a=max(a,temp);
  }

  sort(b,b+N,greater<ll>());

  for(ll i=0;i<110000;i++){
    if(H<=0){
      cout<<i<<endl;
      return 0;
    }
    if(a<b[i]) H-=b[i];
    else{
      i=i+(H+a-1)/a;
      cout<<i<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 1024
S = int(input())

Q = 10 ** 9 + 7
if S < 3:
    print(0)
    exit()

d_list = [-1] * 2001
d_list[3] = 1
d_list[4] = 1
d_list[5] = 1

def ans(n):
    if d_list[n] > 0:
        return d_list[n]
    
    d_list[n] = 1
    # d_list[n] += (n + 1) // 2 + 1
    for i in range(3, n - 2):
        d_list[n] += ans(i)
        d_list[n] %= Q
    
    return d_list[n]

print(ans(S))


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

using namespace std;

int gcd(int a,int b) {
    if(a % b== 0) {
        return b;
    } else {
        return gcd(b,a%b);
    }
}

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

    int K;
    cin>>K;

    unsigned long long int sum=0;
    for(int i=1;i<=K;i++)
        for(int j=1;j<=K;j++)
            for(int k=1;k<=K;k++)
                sum+=gcd(i,gcd(j,k));

    printf("%llu\n",sum);
    return 0;
}


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

int main()
{
	ll n;
	cin>>n;
	ll ans;
	ans = n/500;
	ans = ans * 500;
	ans = ans *2;
	
	n = n%500;
	ans += (n/5)*5;
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

pair<int,char> f(int a,int b,int l)
{
	pair<int,char> x;
	if (l == 0)
	{
		x.first = a-b;
		x.second = '-';
		return x;
	}else
	{
		x.first = a+b;
		x.second = '+';
		return x;
	}
}

int main()
{
	string p;
	cin >> p;
	int a = (int)p[0] - '0';
	int b = (int)p[1] - '0';
	int c = (int)p[2] - '0';
	int d = (int)p[3] - '0';



	for(int i = 0; i < 2; i++)
	{
		for(int j = 0; j < 2; j++)
		{
			for(int k = 0; k < 2; k++)
			{
				int z = f(f(f(a,b,i).first,c,j).first,d,k).first;
				if (z==7)
				{
					cout << a << f(a,b,i).second << b << f(f(a,b,i).first,c,j).second << c <<  f(f(f(a,b,i).first,c,j).first,d,k).second<< d <<"=7" << endl;
					return 0;
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef vector<int> vi;
    typedef vector<long long> vll;
    typedef vector<pair<int , int>> vpii;
    typedef pair<int , int> pii;
    typedef pair<long long  , long long> pll;
    typedef pair<double , double> pdd;
    #define eb emplace_back;
    #define mp make_pair;
     
    int main(){
        string s;
        cin>>s;
        bool ok = false;
        for(int i = 0 ; i<s.length()-1 ; i++){
            if(s[i]!=s[i+1]){
                ok = true;
                break;
            }
        }
        if(ok){
            cout<<"Yes\n";
        } 
        else{
            cout<<"No\n";
        }
        return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;

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

  int res;
  int ans = 0;
  ans += (X / 500) * 1000;
  res = X % 500;
  ans += (res / 5) * 5;
  cout << ans << endl;
}


Measured memory_bytes: 256
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(__,v.size()){rep(_,v[__].size())cout<<" "<<v[__][_];cout<<endl;}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

//nCr mod m
#define MOD 1000000007
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
signed main(){
	int n,k;
	cin>>n>>k;
	int out=0;
	vi y;
	for(int i=1;i*i<=n;i++)if(n%i==0){
		y.pb(i);
		if(i-n/i)y.pb(n/i);
	}
	sort(all(y));
	vi dp(y.size());
	rep(i,y.size()){
		int sum=powmod(k,(y[i]+1)/2);
		rep(j,i)if(y[i]%y[j]==0)
			(sum+=MOD-dp[j])%=MOD;
		dp[i]=sum;
	}
	
	rep(i,dp.size()){
		int t=y[i];
		if(t%2==0)t/=2;
		(out+=dp[i]*t%MOD)%=MOD;
	}
	cout<<out<<endl;
}















Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
#include <iomanip>
#include <set>

using namespace std;

const int N6 = 1e6 + 6;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <int, ll> PIl;
typedef pair <ll, int> PlI;
typedef pair <ll, ll> Pll;


#define F first
#define S second
#define pb push_back
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define sz() size()
#define skip continue

using namespace std;

string s;

map<char,ll>m;

int main(){

     cin >> s;
     for(int i = 0; i < s.size(); ++i){

          ++m[s[i]];

     }

     for(int i = 97; i <= 122; ++i){

          if( m[i] % 2 == 1 ){ cout << "No"; return 0; }

     }

     cout << "Yes";
     
  return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>
using namespace std;

#define ll long long

void solve()
{
    ll N, M, X;
    cin >> N >> M >> X;
    vector<ll> C(N);
    vector<vector<ll>> A(N, vector<ll>(M));
    for (ll i = 0; i < N; i++)
    {
        cin >> C.at(i);
        for (ll j = 0; j < M; j++)
        {
            cin >> A.at(i).at(j);
        }
    }

    for (ll i = 0; i < N; i++)
    {
        cin >> C.at(i);
        for (ll j = 0; j < M; j++)
        {
            cin >> A.at(i).at(j);
        }
    }

    ll n = N;
    ll minPrice = 3000000;
    bool isOKOK = false;
    for (ll bit = 0; bit < (1 << n); bit++)
    {
        vector<ll> ANS(M, 0);
        ll price = 0;
        for (ll i = 0; i < n; ++i)
        {
            if (bit & (1 << i))
            {
                price += C.at(i);
                for (ll j = 0; j < M; j++)
                {
                    ANS.at(j) += A.at(i).at(j);
                }
            }
        }

        // 理解度OKか
        bool isOk = true;
        for (ll j = 0; j < M; j++)
        {
            if (ANS.at(j) < X)
            {
                isOk = false;
            }
        }

        if (isOk)
        {
            minPrice = min(minPrice, price);
            isOKOK = true;
        }
    }

    if (isOKOK)
    {
        cout << minPrice << endl;
    }
    else
    {
        cout << "-1" << endl;
    }

    // for (auto a : A)
    // {
    //     for (auto b : a)
    //     {
    //         cout << b;
    //     }
    //     cout << endl;
    // }

    return;
}

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


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

int main() {
    int N;
    int sum[55] = {};
    string name[55];
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> name[i] >> sum[i];
    }
    for (int i = N - 2; i >= 0; i--) sum[i] += sum[i + 1];
    string X;
    cin >> X;

    for (int i = 0; i < N; i++) {
        if (name[i] == X) {
            cout << sum[i + 1] << endl;
            return (0);
        }
    }


    return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

#include <bits/stdc++.h>
using namespace std;

signed main(){
    int N; cin>>N;
    int P = N%10;
    if(P==3) Out("bon");
    else if(P==0||P==1||P==6||P==8) Out("pon");
    else Out("hon");
}

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

// C - Sum of gcd of Tuples (Easy)
int gcd(int a, int b) {
    if (b == 0)
        return a;

    return gcd(b, a % b);
}

int main() {
    int K;
    cin >> K;
    int sum = 0;
    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            for (int k = 1; k <= K; k++) {
                sum += gcd(gcd(i, j), k);
            }
        }
    }
    cout << sum;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct edge{  ll to,cap,rev;};

vector<edge> G[110];

void add_edge(ll from,ll to,ll cap){
  G[from].push_back( (edge){to,cap, (ll)G[to].size() } );
  G[to].push_back( (edge){from,0, (ll)G[from].size()-1} );
}

bool visited[110];
ll dfs(ll pos,ll ti,ll f){
  if(pos==ti)return f;
  if(visited[pos])return 0;
  visited[pos]=true;
  for(int i=0;i<(int)G[pos].size();i++){
    edge &e=G[pos][i];
    if(e.cap==0)continue;
    ll a=dfs(e.to,ti,min(f,e.cap));
    if(a==0)continue;
    e.cap-=a;
    G[e.to][e.rev].cap+=a;
    return a;
  }
  return 0;
}

ll max_flow(ll si,ll ti){
  ll res=0;
  while(1){
    memset(visited,false,sizeof(visited));
    ll f=dfs(si,ti,(1LL<<60));
    if(f==0)break;
    res+=f;
  }
  return res;
}

void init(){
  for(int i=0;i<110;i++)G[i].clear();
}

map<string,int> mp;
ll N,W;
int main(){
  mp["Sunday"]=0;
  mp["Monday"]=1;
  mp["Tuesday"]=2;
  mp["Wednesday"]=3;
  mp["Thursday"]=4;
  mp["Friday"]=5;
  mp["Saturday"]=6;

  while(1){
    cin>>N>>W;
    if(N==0&&W==0)break;
    init();
    ll si=7+N,ti=8+N,sum=0;
    for(int i=0;i<7;i++)add_edge(si,i,W);
    for(int i=0;i<N;i++){
      string str;
      ll t,c;
      cin>>t>>c;
      sum+=t;
      add_edge(7+i,ti,t);
      for(int j=0;j<c;j++){
        cin>>str;
        add_edge(mp[str],7+i,W);
      }
    }

    cout<< (max_flow(si,ti)==sum?"Yes":"No") <<endl;
  }
  return 0;
}

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ws(x) cerr << #x << " is " << x << endl
#define pb push_back
#define ats(x) cout << x << "\n"
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef pair <int, int> pii;
typedef vector<pii> vii;
typedef tuple<int, int, int> tiii;

const int INF = INT_MAX;


int main()
{
    FAST_IO;
    ll a, b;
    cin >> a >> b;
    ats(a * b);
    return 0;
}



Measured memory_bytes: 3612
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int x,t; cin>>x>>t;
  if(x>t)
  cout<<x-t<<endl;
  else
  cout<<0<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef vector<long long> vll;
int main()
{
    int n;
    cin>>n;
    vll v(n+3),vv(n+3);
    for(int i=1;i<=n;i++) cin>>v[i];
    vv[1]=0; vv[2]=abs(v[1]-v[2]);
    for(int i=3;i<=n;i++){
        vv[i]=min(vv[i-1]+abs(v[i]-v[i-1]),vv[i-2]+abs(v[i]-v[i-2]));
    }
    cout<<vv[n];
}


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

int compare_int(const void *a, const void *b);

typedef enum{
	en_taro = 0,
	en_hanako = 1
} en_turn;

typedef struct {
	int num;
	int str[100];
} card;

int main(void){
	int n;
	int field_number;
	int taro_first, hanako_first;
	int i, j, k;
	en_turn turn;
	card taro, hanako;
	
	scanf("%d", &n);
	while(n !=0){
		for(i = 0; i < n; i++){
			scanf("%d", &taro.str[i]);
		}
		
		qsort(taro.str, n, sizeof(int), compare_int);
		
		for(i = 1, j = 0, k = 0; i <= 2 * n; i++){
			if(taro.str[k] != i){
				hanako.str[j] = i;
				j++;
			}else{
				k++;
			}
		}
		
		taro.num = n - 1;
		hanako.num = n;
		field_number = taro.str[0];
		taro.str[0] = -1;
		turn = en_taro;
		taro_first = 1;
		hanako_first = 0;
		while(taro.num != 0 && hanako.num != 0){
			if(field_number == 0){
				if(turn == en_taro){
					field_number = taro.str[taro_first];
					taro.str[taro_first] = -1;
					taro.num--;
					
					do{
						taro_first++;
					}while(taro.str[taro_first] == -1);
					
				}else if(turn == en_hanako){
					field_number = hanako.str[hanako_first];
					hanako.str[hanako_first] = -1;
					hanako.num--;
					
					do{
						hanako_first++;
					}while(hanako.str[hanako_first] == -1);
					
				}
			}else{
				if(turn == en_taro){
					if(hanako.str[hanako_first] > field_number){
						field_number = hanako.str[hanako_first];
						hanako.str[hanako_first] = -1;
						hanako.num--;
						turn = en_hanako;
						
						do{
							hanako_first++;
						}while(hanako.str[hanako_first] == -1);
					}else{
						i = hanako_first + 1;
						while(hanako.str[i] < field_number){
							i++;
							if(i == n){
								field_number = 0;
								break;
							}
						}
						
						if(i != n){
							field_number = hanako.str[i];
							hanako.str[i] = -1;
							hanako.num--;
							turn = en_hanako;
						}
					}
				}else if(turn == en_hanako){
					if(taro.str[taro_first] > field_number){
						field_number = taro.str[taro_first];
						taro.str[taro_first] = -1;
						taro.num--;
						turn = en_taro;
						
						do{
							taro_first++;
						}while(taro.str[taro_first] == -1);
					}else{
						i = taro_first + 1;
						while(taro.str[i] < field_number){
							i++;
							if(i == n){
								field_number = 0;
								break;
							}
						}
						
						if(i != n){
							field_number = taro.str[i];
							taro.str[i] = -1;
							taro.num--;
							turn = en_taro;
						}
					}
				}
			}
		}
		
		printf("%d\n",hanako.num);
		printf("%d\n",taro.num);
		
		scanf("%d",&n);
	}

	return 0;
}

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
    using namespace std;
    int main(){
      long long n;
      cin >> n;
      long long  ans = (n/11)*2;
      if(n%11  > 0){
      	if(n%11 > 6)ans +=2;
      	else ans++;
      }
      cout<<ans<<"\n";
      return 0;
    }

Measured memory_bytes: 256
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(13)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int N, M, A[100000], B, C;
  vector<pair<int, int>> vec;
  cin >> N >> M;
  int ans = 0;
  REP(i, N){
    cin >> A[i];
    ans += A[i];
  }
  sort(A, A+N);
  REP(i, M) {
    cin >> B >> C;
    vec.push_back(mkp(C, B));
  }
  sort(ALL(vec)); reverse(ALL(vec));
  int index = 0;
  REP(i, M){
    REP(j, vec[i].second){
      if(A[index] >= vec[i].first) break;
      if(index < N) ans += vec[i].first-A[index];
      index++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3188
#include <stdio.h>
#define MAX(maxN,m) ((maxN) > (m) ? (maxN) : (m))

int main(){
    int n;

    scanf("%d", &n);

    int maxN = 0, total = 0;
    for (int i = 0; i<n; i++) {
        int m;

        scanf("%d", &m);

        maxN = MAX(maxN, m);
        total += m;
    }

    printf("%s", maxN < total - maxN ? "Yes" : "No");

    return 0;
}

Measured memory_bytes: 128
n,k=map(int,input().split())
r,s,p=map(int,input().split())
d={'r':p,'s':r,'p':s}
t=input()
ans=0
for i in range(k):
  x=t[i]
  ans+=d[x]
  for j in range(i+k,n,k):
    if t[j]!=x:
      x=t[j]
      ans+=d[x]
    else:
      x='z'
print(ans)

Measured memory_bytes: 9232
#include<iostream>
using namespace std;
int main() {
    int a;
    int b;
    while (1) {
        cin >> a >> b;
        if (a == 0) {
            if (b == 0) break;
        }
        if (a<=b) {
            cout << a << " " << b << endl;
        } else {
            cout << b << " " << a << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        String word =s.next();
        System.out.println(word.replace(","," "));

    }
}



class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25548
import java.math.*

fun main(args: Array<String>) {
    val (n, k) = readInputLine().split(" ").map { it.toInt() }
    val s = readInputLine().toCharArray()
    
    val changePoints = mutableListOf<Int>()
    
    changePoints.add(0)
    
    for (i in 1 until n) {
        if (s[i] != s[i - 1]) {
            changePoints.add(i)
        }
    }
    
    changePoints.add(n)

    var max = 0
    
    for (i in 0 until changePoints.size - 1) {
        if (s[changePoints[i]] == '0') {
            val maxIndex = if (i + k * 2 < changePoints.size) changePoints[i + k * 2] else n
            max = Math.max(max, maxIndex - changePoints[i])
        } else {
            val maxIndex = if (i + k * 2 + 1 < changePoints.size) changePoints[i + k * 2 + 1] else n
            max = Math.max(max, maxIndex - changePoints[i])
        }
    }
    
    println(max)
}
 
fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 39864
#N = int(input())
#A = [int(x) for x in input().split()]
#a, b, c = map(int, input().split())
#name1 = str(input())
#alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}
a, b, c = map(int, input().split())
if a <= c <= b:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll N, M;
  cin >> N >> M;
  ll ans=1;
  if(abs(N-M)<=1){
    //N!*M!*2
    for(ll i=1;i<=N;i++){
      ans *= i;
      ans %= mod;
    }
    for(ll i=1;i<=M;i++){
      ans *= i;
      ans %= mod;
    }
    if(N==M) {ans *= 2; ans %= mod;}
  }
  else ans = 0;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// typedef
typedef std::vector<int> VI;
typedef std::vector<VI> VII;
typedef std::vector<std::string> VS;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

signed main() {
  solve();
  return 0;
}

void solve() {
  std::string s;
  std::cin >> s;
  std::string h = "Heisei\n";
  std::string t = "TBD\n";
  if (std::stol(s.substr(0, 4)) < 2019) {
    std::cout << h;
  } else if (std::stol(s.substr(0, 4)) > 2019) {
    std::cout << t;
  } else {
    if (std::stol(s.substr(5, 2)) < 4) {
      std::cout << h;
    } else if (std::stol(s.substr(5, 2)) > 4) {
      std::cout << t;
    } else {  
      if (std::stol(s.substr(8, 2)) <= 30) {
        std::cout << h;
      } else {
        std::cout << t;
      }
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    pair<int,int>p[n+1];
    vector<pair<int,int> >pp;
    for(int i=1;i<=n;i++)
    {
        cin>>p[i].first>>p[i].second;        
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            pp.push_back({p[j].first-p[i].first,p[j].second-p[i].second});
        }
    }
    int mn=1e10;
    sort(p+1,p+n+1);
    for(auto i:pp)
    {
        int mm[n+1]={0};
        int ans=0;
        int cnt=n;
        while (cnt)
        {
            pair<int,int>prev={-1e10,-1e10};
            for(int j=1;j<=n;j++)
            {
                if(mm[j]==0)
                {
                        ans++;
                        cnt--;
                        prev=p[j];
                        mm[j]=1;
                        break;
                }
            }
            for(int j=1;j<=n;j++)
            {
                if(mm[j]==0)
                {
                    if(p[j].first-prev.first==i.first && p[j].second-prev.second==i.second)
                    {
                        cnt--;
                        mm[j]=1;
                        prev=p[j];
                    }
                }
            }     
        }
        mn=min(mn,ans);
        
    }
    cout<<mn;

} 



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

bool IsEvenStr(const string& str) {
  int n = str.size() / 2;
  for (int i = 0, j = n; i < n; ++i, ++j) {
    if (str[i] != str[j])
      return false;
  }
  return true;
}

int main() {
  string str;
  cin >> str;

  for (int n = str.size() - 2; n > 0; n -= 2) {
    str.resize(n);
    if (IsEvenStr(str)) {
      cout << n << "\n";
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>	
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)
#define int long long

// random_device rd; mt19937 g(rd());    
                                        	
using namespace std;
using namespace __gnu_pbds;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}

template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 133;
 
int n, d, b, ans;
pair <int, int> a[N];
int t[N * 4], add[N * 4];

void push(int tl, int tr, int v)
{
	if(!add[v]) return;
	if(tl != tr)
	{
		add[v + v] += add[v];
		add[v + v + 1] += add[v];
	}
	t[v] += 1ll * add[v] * (tr - tl + 1);
	add[v] = 0;
}

int Get(int pos, int tl = 1, int tr = n, int v = 1)
{
	push(tl, tr, v);
	if(tl == tr) return t[v];
	int tm = (tl + tr) / 2;
	if(pos <= tm) return Get(pos, tl, tm, v + v);
	else return Get(pos, tm + 1, tr, v + v + 1);
	t[v] = t[v + v] + t[v + v + 1];
}

void Update(int l, int r, int val, int tl = 1, int tr = n, int v = 1)
{
	push(tl, tr, v);
	if(tl > r || tr < l) return;
	if(l <= tl && tr <= r)
	{
		add[v] += val;
		push(tl, tr, v);
		return;
	}
	int tm = (tl + tr) / 2;
	Update(l, r, val, tl, tm, v + v);
	Update(l, r, val, tm + 1, tr, v + v + 1);
	t[v] = t[v + v] + t[v + v + 1];
}

vector <int> v;

main ()
{                      	
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();   
	cin >> n >> d >> b;
	for(int i = 1; i <= n; i++) cin >> a[i].F >> a[i].S;
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i++) v.pb(a[i].F);
	for(int i = 1; i <= n; i++)
	{
		int l = a[i].F;
		int r = l + 2 * d;
		int last = upper_bound(all(v), r) - v.begin();
		last = min(last, n);
		a[i].S += Get(i);
		if(a[i].S <= 0) continue;
  		Update(i, last, -((a[i].S + b - 1) / b * b));
		ans += a[i].S / b + (a[i].S % b > 0);
	}
	cout << ans;
}                                

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

#define ll long long

int main () {
  ll n, c;
  cin >> n >> c;
  ll x[2][n + 1], v[2][n + 1];
  ll sum1[2][n + 1], sum2[2][n + 1];
  x[0][0] = 0;
  x[1][0] = 0;
  sum1[0][0] = 0;
  sum1[1][0] = 0;
  sum2[0][0] = 0;
  sum2[1][0] = 0;
  v[0][0] = 0;
  v[1][0] = 0;
  ll max = -1;
  for (ll i = 1; i <= n; i++) {
    cin >> x[0][i] >> v[0][i];
    sum1[0][i] = sum1[0][i - 1] + v[0][i];  
    if (max < (sum1[0][i] - x[0][i])) {
      max = sum1[0][i] - x[0][i];  
    }
  }  
  for (ll i = 1; i <= n; i++) {
    x[1][i] = c - x[0][n - i + 1];
    v[1][i] = v[0][n - i + 1];
    sum2[0][i] = sum2[0][i - 1] + v[1][i];  
    if (max < sum2[0][i] - x[1][i]) {
      max = sum2[0][i] - x[1][i];  
    }
  }
  for (ll i = 1; i <= n; i++) {
    sum1[1][i] = sum2[0][i];
    sum2[1][i] = sum1[0][i];  
  }
  for (ll q = 0; q < 2; q++) {
    pair<ll, ll> dp1[n + 1], dp2[n + 1];
    dp1[0] = make_pair(0, 0);
    dp2[0] = make_pair(0, 0);
    for (ll i = 1; i <= n; i++) {
      ll now;
      if ((sum1[q][i] - 2 * x[q][i]) > dp1[i - 1].first) {
        now = i;
        dp1[i] = make_pair(sum1[q][i] - 2 * x[q][now], now);  
      }  
      else {
        dp1[i] = dp1[i - 1];  
      }
      ll j = n - i + 1;
      if ((sum2[q][i] - (c - x[q][j]))> dp2[i - 1].first) {
        now = j;
        dp2[i] = make_pair(sum2[q][i] - (c - x[q][now]), now);  
      }
      else {
        dp2[i] = dp2[i - 1];  
      }
    }
    for (ll i = 0; i <= n; i++) {
      ll sum = dp1[i].first;
      sum = sum + dp2[n - dp1[i].second].first;
      if (max < sum) {
        max = sum;  
      }
    }
  }
  cout << max << endl;
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
using namespace std;
typedef  long long  ll;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    ll k;
    cin>>n>>k;
    vector<int> next(n+1);
    
    for(int i =1; i<=n;i++){
        int e;
        cin>>e;
        next[i]=e;
    }
    map<int,int> round;
    int curr = 1;
    int r = 1;
    for(;k;k--){
        //k times left
        round.insert(make_pair(curr,r));
        curr = next[curr];
        auto f = round.find(curr);
        if(f!=round.end()){
            ll mod;
            mod = k%(ll)(r-f->second+1);
            if(mod==0)
                mod=r-f->second+1;
            mod--;
            for(;mod;mod--){
                curr=next[curr];
            }
            cout<<curr<<endl;
            return 0;
        }
        r++;
    }
    
    cout<<curr<<endl;
    
    return 0;
}

Measured memory_bytes: 11520
def main():
    from string import ascii_lowercase
    dic = {i: s for i, s in enumerate(ascii_lowercase)}
    N = int(input())
    ans = []

    def dfs(s, mx):
        if len(s) == N:
            print(s)
            return
        else:
            for i in range(mx+2):
                v = s + dic[i]
                mx = max(mx, i)
                dfs(v, mx)
    dfs("a", 0)


if __name__ == '__main__':
    main()


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

#define N 8

int next(int *aa, int n) {
	int i, j, tmp;

	for (i = n - 2; i >= 0; i--)
		if (aa[i] < aa[i + 1])
			break;
	if (i < 0)
		return 0;
	for (j = n - 1; j > i; j--)
		if (aa[i] < aa[j])
			break;
	tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
	for (i++, j = n - 1; i < j; i++, j--)
		tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
	return 1;
}

int same(int *aa, int *bb, int n) {
	int i;

	for (i = 0; i < n; i++)
		if (aa[i] != bb[i])
			return 0;
	return 1;
}

int main() {
	static int pp[N], qq[N], xx[N];
	int n, i, a, b;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &pp[i]);
	for (i = 0; i < n; i++)
		scanf("%d", &qq[i]);
	for (i = 0; i < n; i++)
		xx[i] = i + 1;
	a = b = -1;
	i = 0;
	do {
		if (same(xx, pp, n))
			a = i;
		if (same(xx, qq, n))
			b = i;
		i++;
	} while (next(xx, n));
	printf("%d\n", abs(a - b));
	return 0;
}


Measured memory_bytes: 128
# Problem: https://atcoder.jp/contests/arc096/tasks/arc096_a
# Python 1st Try

import sys
# from collections import defaultdict
# import heapq,copy
import pprint as pp
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


# CONST
MAXSIZE = ( 1 << 31 ) -1
MINSIZE = -( 1 << 31) + 1

def solver(a_price, b_price, c_price, target_x, target_y):
    result = MAXSIZE
    for mix_i in range(0, 2 * 10**5+1, +1):
        a_i = target_x - mix_i//2
        b_i = target_y - mix_i//2
        totalPrice = max(a_i, 0) * a_price + max(b_i,0) * b_price + mix_i * c_price
        if totalPrice < result:
            # print("A={},B={},C={} -> total = {}".format(a_i, b_i, mix_i, totalPrice))
            result = totalPrice
    return result


if __name__ == "__main__":
    A, B, C, X, Y = MI()
    print("{}".format(solver(A, B, C, X, Y)))


Measured memory_bytes: 9700
#include<bits/stdc++.h>
using namespace std;
struct hzy{
	int val,next;
}e[400001];
int n,m,x,y,linkk[200001],f[100001],p[100001],v[100001],t,tail=1;
void ling(int x,int y) {
	e[++t].val=y;
	e[t].next=linkk[x];
	linkk[x]=t;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		ling(x,y);
		ling(y,x);
	}
	f[1]=0;
	p[1]=1;
	v[1]=1;
	for(int i=1;i<=tail;i++){
		for(int j=linkk[p[i]];j;j=e[j].next){
			int y=e[j].val;
			if(v[y]==0){
				v[y]=1;
				f[y]=p[i];
				p[++tail]=y;
			}
		}
	}
	for(int i=2;i<=n;i++){
		if(v[i]==0){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	for(int i=2;i<=n;i++){
		cout<<f[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 8292
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+9;
string st ;
int arr[N],frq[N];
int t,a,b,c,m;
int main(){
    scanf("%d%d%d",&a,&b,&c);
    printf("%d %d %d",c,a,b);
        }





/**
5
2 3
10 10
2 4
7 4
9 3



*/




/**
  int power1(int b, int p){               //O(p)
    if(!p)  return 1;
    return b*power1(b, p-1);
  }
  int power2(int b, int p){               //O(Log(p))
    if(!p)  return 1;
    int ret = power2(b, p/2);
    return (p&1 ? ret*ret*b : ret*ret);
  }
   int mul(int a, int b, int m){
      return (a%m * b%m) % m;
  }

*/


/**
void seive()
{
    bitset<N>iscomp;
    iscomp[0]=iscomp[1]=1;
    for(long long i=2; i<=N; ++i)
    {
        if(!iscomp[i])
        {
            a.push_back(i);
            for(long long j=i*i; j<=N; j+=i)
                iscomp[j]=1;
        }
    }
}
3
abc
abc
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define llong long long
int n;
int mp[55][55];
llong dp[55][55][55];
llong dfs(int l,int r,int m)
{
    if(l==r)return 1;
    if(l==m||r==m||l>r)return 0;
    if(dp[l][r][m]!=-1)return dp[l][r][m];
    llong res=0;
    for(int j=l;j<m;++j)
        for(int k=m+1;k<=r;++k)
        {
            if(!mp[j][k])continue;
            for(int p=j+1;p<=m;++p)
                for(int q=m;q<k;++q)
                {
                    if(!((q-p+1)&1))continue;
                    res+=dfs(l,p-1,j)*dfs(p,q,m)*dfs(q+1,r,k);
                }
        }
    dp[l][r][m]=res;
    return res;
}
int main()
{
    scanf("%d",&n);n*=2;
    for(int i=1;i<=n;++i)
        for(int j=1;j<=n;++j)
            scanf("%1d",&mp[i][j]);
    memset(dp,-1,sizeof(dp));
    llong ans=0;
    for(int i=2;i<=n;++i)
        if(mp[1][i]) ans+=dfs(2,n,i);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1536