akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, M, X[100000];
ll res;
priority_queue<int, vector<int>, greater<int>>que;

int main(){
	cin >> N >> M;
	if (N >= M)
		cout << 0 << endl;
	else {
		for (int i = 0; i != M; ++i)
			cin >> X[i];
		sort(X, X + M);
		for (int i = 0; i != M - 1; ++i) {
			que.push(X[i + 1] - X[i]);
		}
		for (int i = 0; i != M - N; ++i) {
			res += que.top();
			que.pop();
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;


ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
bool root(string s){
    int n=s.length();
    if(n==2){
        if(s[0]==s[1]){
            return true;
        }
        else return false;
    }
    if(n==3){
        if(s[0]==s[2]){
            return true;
        }
        else return false;
    }
 
    return false;
}
 
 
//深さ優先
vector<int> seen;
vector<ll> h;
 
//普通の深さ優先探索seenを返す感じ
void dfs(const Graph &G,int v){

    seen[v] = 0; //v探索済み
 
    P good=make_pair(v,h[v]);
    for(auto next_v :G[v]){
        if(seen[next_v]!=-1) continue;//もう探索していた
        if(h[next_v]>good.second){
            good=make_pair(next_v,h[next_v]);
        }
        dfs(G,next_v);
    }
 
    if(!(h[v]==good.second && v==good.first)){
        seen[good.first]=1;
    }
}


int n;

void dfs(string s, char mx){
    if(s.length()==n){
        cout<<s<<endl;
    }else{
        for(char c='a';c<=mx;c++){
            dfs(s+c,((c==mx) ? (char)(mx+1) : mx));
        }
    }
}

signed main(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    
    int ans=0;
    
    if(k>=a){
        ans+=a;
        k=k-a;
    }else{
        ans+=k;
        cout<<ans<<endl;
        return 0;
    }
    
    k=k-b;
    
    if(k>=c){
        ans-=c;
        cout<<ans<<endl;
    }else{
        if(k>=0){
            ans-=k;
            cout<<ans<<endl;
        }else{
            cout<<ans<<endl;
        }
    }

}  

Measured memory_bytes: 3628
//Be Name Khoda
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma optimize O3
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>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
#define RETD(x) { cout << fixed << setprecision(15) << x; exit(0); }
const ll M=2e5+5,LG=32,SM=600+5,inf=1e18+5;
ll mod=1e9+7;
 
ll n;
ll a[M];
 
int main()
{
	ios::sync_with_stdio(0);
	cin >> n;
	For(i,0,n) cin >> a[i];
	sort(a,a+n);
	if (a[n-1]-a[0]>1) RET("No");
	if (a[n-1]==a[0]) 
	{
	    if (a[0]==n-1) RET("Yes");
	    if (a[0]<=n/2) RET("Yes");
	    RET("No");
	}
	ll ned=a[n-1],pr=LB(a,n,a[n-1]);
	ned-=pr;
	pr=n-pr;
	if (pr==1 || ned<=0) RET("No");
	RET((ned>pr/2?"No":"Yes"));
}

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

int main(){
    int N;
    long long T_list[1010], A_list[1010];
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> T_list[i] >> A_list[i];
    }
    long long x = T_list[0], y = A_list[0];
    for(int i=1; i<N; i++){
        long long t = T_list[i], a = A_list[i];
        long long k = (x+t-1)/t > (y+a-1)/a ? (x+t-1)/t : (y+a-1)/a;
        x = k*t;
        y = k*a;
    }
    cout << x+y;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc098/tasks/arc098_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (auto &x : a)
        cin >> x;
    int ans = 0, i = 0, r = 0;
    REP(l, N) {
        while (r < N && (i & a[r]) == 0) {
            i += a[r++];
        }
        ans += r - l;
        i -= a[l];
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 4784
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, K) = read!(i64, i64);

    let r = N % K;
    let m = min(r, K - r);

    println!("{}", m)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const double INF = 1e5;
const double eps = 1e-8;

struct Star{
    double px,py,pz,vx,vy,vz,r,vr;
};

Star scan_star(){
    double px,py,pz,vx,vy,vz,r,vr;
    scanf(" %lf %lf %lf %lf %lf %lf %lf %lf", &px, &py, &pz, &vx, &vy, &vz, &r, &vr);
    return Star{px,py,pz,vx,vy,vz,r,vr};
}

inline double pw(double x){
    return x*x;
}

int main(){
    int n;
    while(scanf(" %d", &n),n){
        vector<Star> s(n);
        rep(i,n) s[i] = scan_star();

        vector<double> disappear(n);
        rep(i,n) disappear[i] = s[i].r/s[i].vr;

        auto f = [&](int i, int j, double t){
            return sqrt( pw((s[i].px+t*s[i].vx)-(s[j].px+t*s[j].vx)) + pw((s[i].py+t*s[i].vy)-(s[j].py+t*s[j].vy)) + pw((s[i].pz+t*s[i].vz)-(s[j].pz+t*s[j].vz)) ) - (s[i].r - t*s[i].vr) - (s[j].r - t*s[j].vr);
        };

        auto calc = [&](int i, int j){
            double l = 0, r = min(disappear[i], disappear[j]);
            rep(loop,40){
                double ml = (2*l+r)/3, mr = (l+2*r)/3;
                if(f(i,j,ml) < f(i,j,mr)) r = mr;
                else l = ml;
            }

            double argt = (l+r)/2;
            if(f(i,j,argt)>0) return INF;

            l = 0;
            r = argt;
            rep(loop,40){
                double m = (l+r)/2;
                if(f(i,j,m)>0) l = m;
                else r = m;
            }
            return r;
        };

        using pi = pair<int,int>;
        using P = pair<double, pi>;
        priority_queue<P, vector<P>, greater<P>> pq;

        rep(i,n)rep(j,i){
            double t = calc(i,j);
            if(t < INF - eps) pq.push({t,{i,j}});
        }

        vector<double> ans(disappear);
        vector<bool> rem(n,true);

        while(!pq.empty()){
            P now = pq.top();
            pq.pop();

            int u = now.se.fi, v = now.se.se;
            if(rem[u] && rem[v]){
                ans[u] = ans[v] = now.fi;
                rem[u] = rem[v] = false;
            }
        }

        rep(i,n) printf("%.10f\n", ans[i]);
    }
    return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
int n, q;
vector<int> v[200002];
int up[200002];
int ans[200002];
void dfs(int cur, int par)
{
    ans[cur] = ans[par] + up[cur];
    for(int nxt : v[cur])
    {
        if(nxt == par) continue;
        dfs(nxt, cur);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> q;
    for(int i=1;i<n;i++)
    {
        int a,b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i=0;i<q;i++)
    {
        int a,b;
        cin >> a >> b;
        up[a] += b;
    }
    dfs(1, 0);
    for(int i=1;i<=n;i++)
        cout << ans[i] << ' ';
}

Measured memory_bytes: 24064
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define endl "\n"
    #define space " "
    #define ll long long int
    #define vl vector<ll>
    #define vvl vector < vll >
    #define pii pair<int,int>
    #define pll pair<ll,ll>
    #define vpl vector < pll >
    #define mod 1000000007
    #define pi 3.1415926535897932384626433
    #define inf 1000000000000000001;
    #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y) 
    #define mem(a,val) memset(a,val,sizeof(a))
    #define pb push_back
    #define f first
    #define s second
    
    void solve()
    {
        int x; cin>>x;
        cout<<1-x;
    }

    signed main()
    {

    fast;
    #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
     #endif

    ll T=1;
    // cin>>T;
    while(T--)
    {
        solve();
    }
    return 0;
    }


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

#define llint long long int

#define mod 2019

int main(void){

  int n;
  std::cin >> n;
  std::vector<llint> a(n);
  for(int i=0; i<n; i++){
    std::cin >> a[i];
  }

  std::vector<llint> start_cum(n);
  start_cum[0] = a[0];
  for(int i=1; i<n; i++){
    start_cum[i] = a[i] - start_cum[i-1];
  }
  std::vector<llint> end_cum(n);
  end_cum[n-1] = a[n-1];
  for(int i=n-2; i>=0; i--){
    end_cum[i] = a[i] - end_cum[i+1];
  }

  std::vector<llint> b(n);
  /**
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      if(j%2 == 0){
        b[i]+=a[(i+j)%n];
      }else{
        b[i]-=a[(i+j)%n];
      }
    }
  }
  **/
  for(int i=0; i<n; i++){
    if(i!=0) b[i] += start_cum[i-1];
    b[i] += end_cum[i];
  }

  std::cout << b[0];
  for(int i=1; i<n; i++){
    std::cout << " " << b[i];
  }
  std::cout << std::endl;

  return 0;
}

Measured memory_bytes: 4480
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//cout<<setprecision(20)
const llint mod=1000000007;
const llint big=1.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int LBI(vector<lldo>&ar,lldo in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
int UBI(vector<lldo>&ar,lldo in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int n,i;cin>>n;
	if(n==2){cout<<"1 2"<<endl;return 0;}
	if(n==3){cout<<"1 2 3"<<endl;return 0;}
	vector<vector<int>>go(n);
	for(i=0;i<n-1;i++){
		int a,b;cin>>a>>b;a--;b--;
		go[a].pub(b);
		go[b].pub(a);
	}
	vector<int>nozi(n);
	int haza=-1,hazb=-1;
	for(i=0;i<n;i++){
		if(go[i].size()<=1){continue;}
		int g=0;
		for(auto it:go[i]){
			if(go[it].size()>1){g++;}
		}
		nozi[i]=g;
		if(g>2){cout<<"-1\n";return 0;}
		if(g==0){haza=i;hazb=i;}
		if(g==1){
			if(haza==-1){haza=i;}
			else{hazb=i;}
		}
	}
	vector<int>ansab;
	ansab.pub(1);
	int gen=haza,mae=-1;
	while(-1){
		int kazu=go[gen].size();
		kazu-=2;
		int ne=ansab.size()+1;
		while(kazu--){
			int nf=ansab.size()+2;
			ansab.pub(nf);
		}
		ansab.pub(ne);
		if(gen==hazb){break;}
		for(auto it:go[gen]){
			if(it!=mae&&go[it].size()>1){mae=gen;gen=it;break;}
		}
	}
	ansab.pub(n);
	
	
	vector<int>ansba;
	ansba.pub(1);
	gen=hazb,mae=-1;
	while(-1){
		int kazu=go[gen].size();
		kazu-=2;
		int ne=ansba.size()+1;
		while(kazu--){
			int nf=ansba.size()+2;
			ansba.pub(nf);
		}
		ansba.pub(ne);
		if(gen==haza){break;}
		for(auto it:go[gen]){
			if(it!=mae&&go[it].size()>1){mae=gen;gen=it;break;}
		}
	}
	ansba.pub(n);
	if(ansab>ansba){ansab=move(ansba);}
	for(auto it:ansab){cout<<it<<" ";}cout<<endl;
	return 0;
}

Measured memory_bytes: 7928
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main() => new Program().Solve();

	void Solve()
	{
		var nk = ReadLongArray();
		var n = nk[0];
		var k = nk[1];
		var p = ReadLongArray();
		var sum = 0L;

		Array.Sort(p);

		for (var i = 0; i < k; i++) {
			sum += p[i];
		}

		Console.WriteLine(sum);
	}

	#region Console.Read 関係
	long[] ReadLongArray() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
	long ReadLong() => long.Parse(Console.ReadLine());
	#endregion
}


Measured memory_bytes: 27896
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a = [i-1 for i in a]

ans = 0
tmp = -99
for i in a:
  if i == tmp+1:
    ans += c[tmp]
  ans += b[i]
  tmp = i
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
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;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}

int main(){
    ll n,a,b; cin >> n >> a >> b;
    cout << min(a,b) << " " << max(0LL,a+b-n) << endl;
}

Measured memory_bytes: 256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int b; 
    while(cin >> b) {
        if(b == 0) break;
        int x = 0, y = 0;
        for(int i = 1; i * i <= 2 * b; ++ i) {
            if((2 * b) % i == 0) {
                int j = (2 * b) / i;
                if((i + j) % 2 == 0) continue;
                x = (j - i + 1) / 2, y = (i + j - 1) / 2;
            }
        }
        cout << x << " " << y - x + 1 << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}


Measured memory_bytes: 3132
using System;
class Program
{
    public static void Main()
    {
        int[] mountain = new int[10];
        for(int i = 0; i <= 9; i++)
        {
            mountain[i] = int.Parse(Console.ReadLine());
        }
        Array.Sort(mountain);
        Array.Reverse(mountain);
        for(int i = 0; i < 3;i++)
        {
            Console.WriteLine(mountain[i]);
        }
    }
}


Measured memory_bytes: 17940
#include <bits/stdc++.h>
using namespace std;
//using ll = long long;
int n;
vector<int> A(50);

bool solve (int i, int m) {
  if (m == 0) return true;
  if (i >= n) return false;
  bool res = solve(i+1,m) || solve(i+1,m-A.at(i));
  return res;
}
int main(void) {
  int q, M, i;

  cin >> n;
  for (i = 0; i < n; i++) 
    cin >> A.at(i);
  cin >> q;
  for (i = 0; i < q; i++)
  {
    cin >> M;
    if (solve(0, M))
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }
  
}


Measured memory_bytes: 3104
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    int a,ans=0;
    cin >>a;
    while(a>=0){
        ans+=a;
        a--;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long T = sc.nextLong();
		long[] t = new long[n];
		for(int i = 0; i < n; i++) {
			t[i] = sc.nextLong();
		}
		long[] dp = new long[n];
		dp[0] = 0;
		for(int i = 1; i < n; i++) {
			dp[i] = Math.min(dp[i - 1] + T, dp[i - 1] + t[i] - t[i - 1]);
		}
		System.out.println(dp[n - 1] + T);
	}
}

Measured memory_bytes: 65164
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n,m;
	cin>>n>>m;
	vi in(n);
	rep(i,n)cin>>in[i];
	rep(i,m){
		int t=i+1;
		rep(j,n-1)if(in[j]%t>in[j+1]%t)swap(in[j],in[j+1]);
	}
	rep(i,n)cout<<in[i]<<endl;
}

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

using namespace std;

const int M = 1e5 + 2;

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

    int n, k;
    cin >> n >> k;
    long long arr[M], pre[M] = {}, suf[M] = {}, pref[M] = {}, suff[M] = {}, sum = 0, ans = 0;
    for (int i = 1; i <= n; i++)
        cin >> arr[i], sum += arr[i];

    for (int i = 1; i <= n; i++)
        pre[i] = arr[i] + pre[i - 1], pref[i] = max(0ll, arr[i]) + pref[i - 1];
    for (int i = n; i >= 0; i--)
        suf[i] = arr[i] + suf[i + 1], suff[i] = max(0ll, arr[i]) + suff[i + 1];

    for (int i = k; i <= n; i++) {
        long long left, mid, right;
        left = pref[i - k];
        right = suff[i + 1];
        mid = sum - (pre[i - k] + suf[i + 1]);
        ans = max(ans, left + right + max(mid, 0ll));
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 4224
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    s=sum(A)
    for i in range(n-1):
        A[i+1]+=A[i]
    res=INF
    for x in A[:-1]:
        res=min(res,abs(s-2*x))
    print(res)
resolve()

Measured memory_bytes: 71584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
  ll X; cin>>X;
  ll A,B;
  int ans=0;
  for(ll i=0;;i++){
    for(ll j=i;;j++){
      A = i; ll a =A*A*A*A*A;
      B = j; ll b =B*B*B*B*B;
      ll K = b-a;
      if(K>X) break;
      if(K==X){
        ans++;
        break;
      }
      if(a+b==X){
        ans++;
        A = (-1)*A;
        break;
      }
    }
    if(ans>0) break;
  }
  cout << B << " " << A <<endl;
  return 0;
}

Measured memory_bytes: 3588
#include<stdio.h>
int main(void){
	char s[100] = {'\0'};
	int n = 0;
	int flg = 1;
	scanf("%s", s);
	while(s[n] != '\0'){
		n++;
	}
	for(int i=0; i<(n-1)/2; i++){
		if(s[i] != s[n-i-1]){
			flg = 0;
			break;
		}
		if(i < (n-1)/2-i-1){
			if(s[i] != s[(n-1)/2-i-1]){
				flg = 0;
				break;
			}
			if(s[(n+3)/2+i-1] != s[n-i-1]){
				flg = 0;
				break;
			}
		}
	}
	if(flg == 1){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define ISEQ(c) (c).begin(), (c).end()
int main() {
	
		int n, m;
		const ll INF = 1000000100LL;
		cin >> n >> m;
		vector<ll> s(n), t(n);
		for (int i = 0; i < n; i++) {
			scanf("%lld%lld", &s[i], &t[i]);
		}
		vector<ll> p(m+2);
		p[0] = -1;
		for (int i = 1; i <= m; i++) {
			scanf("%lld", &p[i]);
		}
		p[m+1] = INF;
		sort(ISEQ(p));
		vector<ll> podd, peven;
		ll sumo = 0, sume = 0;
		podd.push_back(0); peven.push_back(0);
		for (int i = 1; i <= m+1; i++) {
			if (i % 2) {
				sumo += p[i] - p[i-1];
				podd.push_back(sumo);
				peven.push_back(sume);
			} else {
				sume += p[i] - p[i-1];
				peven.push_back(sume);
				podd.push_back(sumo);
			}
		}
		ll res = 0LL;
		for (int i = 0; i < n; i++) {
			int a = lower_bound(ISEQ(p), s[i]) - p.begin();
			int b = lower_bound(ISEQ(p), t[i]) - p.begin();
			if (a == b) {
				res += abs(s[i] - t[i]);
			} else {
				ll temp;
				if (a % 2) {
					if (b % 2) {
						temp = podd[b] - podd[a] - (p[b] - t[i]) + (p[a] - s[i]);
					} else {
						temp = podd[b] - podd[a] + p[a] - s[i];
					}
				} else {
					if (b % 2) {
						temp  = peven[b] - peven[a] + p[a] - s[i];
					} else {
						temp = peven[b] - peven[a]  - (p[b] - t[i]) + (p[a] - s[i]);
					}
				}
				if (temp < 0) temp = -temp;
				res += temp;
			}
		}
		cout << res << endl;
	
}

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

using namespace std;

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define INF LLONG_MAX
#define EPS 1e-9
#define all(v) (v).begin(),(v).end()
#define sq(x) ((x)*(x))
#define foreach(it, v) for(auto it=(v).begin(); it != (v).end(); ++it)
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)


#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
 
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
 
typedef long double dbl;
bool codejam = 0;

const int MOD = 1000*1000*1000 + 7;
const int NMAX = 1000*1000 + 11;

int arr[NMAX];
int n,m,p,q,k,a,b,c,ans;
string s,str;
char ch;
vector<int> v;

void solve()
{
    int s,w;
    cin>>s>>w;
    if(w >= s){
        cout<<"unsafe";
    }
    else
        cout<<"safe";
}

int32_t main(){ fio;
    int t = 1;
    int cs = 1;
    // cin>>t;
    while(t--){
        if(codejam){
            cout<<"Case #"<<cs<<": ";
        }
        cs++;
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 3652
def prime(n)
  if n == 2
    return true
  elsif n % 2 == 0
    return false
  else
    k = 3
    while k*k <= n do
      if (n % k) == 0
        return false
      end
      k += 2
    end
    return true
  end
end

n = gets.to_i
cnt = 0
n.times do
  i = gets.to_i
  if prime(i)
    cnt += 1
  end
end
puts cnt


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

inline int read(){
	char ch=getchar();
	int x=0,f=1;
	while(ch<'0' || ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();	
	}
	while(ch>='0' && ch<='9') x=x*10+(ch^48),ch=getchar();
	return x*f;
}

int n,tree[26][500005];

int lowbit(int x){
	return  x&-x;
}

int sum(int x,int tr){
	int ans=0;
	while(x>0){
		ans+=tree[tr][x];
		x-=lowbit(x);
	}	
	return ans;
}

void add(int x,int k,int tr){
	while(x<=n){
		tree[tr][x]+=k;
		x+=lowbit(x);
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<n;i++)
		add(i+1,1,s[i]-'a');
		
	int t;
	cin>>t;
	int x,y,z;
	char c;
	
	while(t--){
		cin>>x;
		if(x==1){
			cin>>y>>c;
			add(y,-1,s[y-1]-'a');
			add(y,1,c-'a');
			s[y-1]=c;
		}
		else if(x==2){
			cin>>y>>z;
			int ans=0;
			for(int i=0;i<26;i++){
				if(sum(z,i)>sum(y-1,i)) ans++;
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 51740
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))

using namespace std;
unsigned long long int newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main()
{
	int N,M;
	double p = 0.0;
	double cp = 1.0;
	cin >> N >> M;
	int cur = 0;
	for(int i=1; i <= N; i++)
	{
		cur = i;
		cp = 1.0;
		while(true)
		{
			if(cur >= M)
			{
				p += cp;
				break;
			}
			cp /= 2;
			cur <<= 1;
		}
	}
	cout << fixed << setprecision(15) << p/N << endl;

	return 0;
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, m;
    cin >> n >> m;
    dsu uf(n);
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        uf.merge(a, b);
    }
    auto g = uf.groups();
    cout << sz(g) - 1 << endl;
}


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

using namespace std;

#define ll long long

int main (){

    int i,n;
    string s,ss;

    cin>>n;

    cin>>s>>ss;

    for(i=0; i<n; i++) cout<<s[i]<<ss[i];
    
    cout<<endl;

    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include<cstring>
#include <stack>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include <string>
const int MAXN = 2000 * 100 + 6;
typedef long long LL;
int t, n, m;
using namespace std;
struct node {
	int parent = -1;
	int depth = 0;
	vector<int>child;
}tree[MAXN];
void dfs(node &root) {
	for (auto it : root.child) {
		tree[it].depth = root.depth + 1;
		dfs(tree[it]);
	}
}
int main()
{
#ifdef _DEBUG
	freopen("E:\\input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
#endif
	int i, j;
	LL ans;
	scanf("%d", &n);
	int root = 0;
	for (int i = 0; i < n; i++) {
		int id, numofchild;
		scanf("%d %d", &id, &numofchild);

		for (int j = 0; j < numofchild; j++) {
			int child;
			scanf("%d", &child);
			tree[id].child.push_back(child);
			tree[child].depth = tree[id].depth + 1;
			tree[child].parent = id;
		}
		if (tree[id].depth == 0)root = id;
	}
	dfs(tree[root]);
	for (int i = 0; i < n; i++) {
		printf("node %d: parent = %d, depth = %d, ", i, tree[i].parent, tree[i].depth);
		if (tree[i].depth == 0)printf("root");
		else if (tree[i].child.size() == 0)printf("leaf");
		else printf("internal node");
		printf(", [");
		int j = 0;
		for (auto it : tree[i].child) {
			if (j++)printf(", ");
			printf("%d",it);
		}
		printf("]\n");
	}
	return 0;
}


Measured memory_bytes: 10292
#include<stdio.h>
#include<stdlib.h>
#include<map>
using namespace std;

int main(){
  int i,n;
  long li,m;
  char buf[10];
  map<char,char> conv;
  map<char,char>::iterator it;
  do{
    fgets(buf,10,stdin);
    n=atoi(buf);
    if(n==0) break;
    for(i=0;i<n;i++){
      fgets(buf,10,stdin);
      conv.insert(map<char,char>::value_type(buf[0],buf[2]));
    }
    fgets(buf,10,stdin);
    m=atol(buf);
    for(li=0;li<m;li++){
      fgets(buf,10,stdin);
      if((it=conv.find(buf[0]))==conv.end()){
	printf("%c",buf[0]);
      }else{
	printf("%c",it->second);
      }
    }
    printf("\n");
    conv.clear();
  }while(1);
  return 0;
}

Measured memory_bytes: 0
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				double W=sc.nextDouble();
				double H=sc.nextDouble();
				int N=sc.nextInt();
				if(W+H+N==0) break;
				double[] x=new double[2*N];
				double[] y=new double[2*N];
				ArrayList<Double> list=new ArrayList<>();
				list.add(0.0);
				list.add(H);
				for(int i=0; i<2*N; i++) {
					x[i]=sc.nextDouble();
					y[i]=sc.nextDouble();
				}
				//ケーキの角といちごを結ぶ直線のy切片
				for(int i=0; i<2*N; i++) {
					double y1=(H-y[i])/(W-x[i])*(0-W)+H;
					double y2=(0-y[i])/(W-x[i])*(0-W);
					if(y1>=0 && y1<=H) {
						list.add(y1);
					}
					if(y2>=0 && y2<=H) {
						list.add(y2);
					}
				}
				//いちご二つを結ぶ直線のy切片
				for(int i=0; i<2*N-1; i++) {
					for(int j=i+1; j<2*N; j++) {
						double y3=(y[i]-y[j])/(x[i]-x[j])*(0-x[i])+y[i];
						if(y3>=0 && y3<=H) {
							list.add(y3);
						}
					}
				}
				Collections.sort(list);
				double[] list2=new double[2*N+2];
				double prev=0, cur=0, ans=0;
				int c=0;
				prev=list.get(c);
				
				while(c<list.size()-1) {
					c++;
					cur=list.get(c);
					if(cur-prev>0.000000001) {
					double mid=(prev+cur)/2.0;
					//midの時のいちごと結ぶ直線でy範囲探索
					for(int i=0; i<2*N; i++) {
						double y4=(y[i]-mid)/(x[i]+0.000000001)*W+mid;
						if(y4<0) y4=0;
						if(y4>H) y4=H;
						list2[i]=y4;
					}
					list2[2*N]=0;
					list2[2*N+1]=H;
					Arrays.sort(list2);
					int mid2=(2*N+2)/2;
					ans+=(cur-prev)*(list2[mid2]-list2[mid2-1]);
					}
					prev=cur;
				}
				ans /= H*H;
				System.out.println(ans);
				
				
			}

		}
	}
}


Measured memory_bytes: 69972
#include<iostream>
using namespace std;
static const int MAX = 100;
char M[MAX][MAX + 1];
int h, w;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
void dfs(int y, int x, char c)
{
	M[y][x] = 'a';
	for (int i = 0; i < 4; i++) {//??£??\4???????????¢?????????????????????a??§?¶?????????????
		int ny = y + dy[i];
		int nx = x + dx[i];
		if (0 <= nx < w && nx < w && 0 <= ny && ny < h && M[ny][nx] == c) {
			dfs(ny, nx, c);
		}
	}
}


int main()
{
	while (cin >> h >> w, !(w==0 && h==0)) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> M[i][j];
			}
		}
		int counter = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (M[i][j] == '#' || M[i][j] == '*' || M[i][j] == '@') {
					char c = M[i][j];
					dfs(i, j, c);
					counter++;
				}
			}
		}
		cout << counter << endl;
	}

	
    return 0;
}

Measured memory_bytes: 3480
//2019.7.7 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define eps 1e-12
#define RG register
#define db double
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define gc getchar
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
    res s=0,ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline int read() {
//    res s=0,ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
namespace MAIN{
    int n,A,B;
    inline void MAIN(){
        n=read(),A=read(),B=read();
        printf("%d\n",min(n*A,B));
    }
}
int main() {
//    srand((unsigned)time(NULL));
    // freopen("zao.in","r",stdin);
    // freopen("std.out","w",stdout);
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int indexx=0,child=0;
int num[55],low[55],ans=0;
struct node
{
	int nxt,to;
}e[5005];
int head[5005],cnt=0;
void add(int u,int v)
{
	e[++cnt].to=v;
	e[cnt].nxt=head[u];
	head[u]=cnt;
}
inline int read()
{
	int x=0,w=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-') w=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<1)+(x<<3)+c^'0';
		c=getchar();
	}
	return w*x;
}
void dfs(int cur,int fa)
{
	child=0;
	indexx++;
	low[cur]=num[cur]=indexx;
	for(int i=head[cur];i;i=e[i].nxt)
	{
		int j=e[i].to;
		if(!num[j])
		{
			dfs(j,cur);
			low[cur]=min(low[cur],low[j]);
			if(low[j]>num[cur]) ans++;
		}
		else if(j!=fa) low[cur]=min(low[cur],num[j]);
	}
	return;
}
int n,m,l,r;
int main()
{	
	while(cin>>n>>m)
	{
		ans=0;
		indexx=0;
		cnt=0;
		child=0;
		memset(low,0,sizeof(low));
		memset(num,0,sizeof(num));
		memset(e,0,sizeof(e));
		memset(head,0,sizeof(head));
		for(int i=1;i<=m;i++)
		{
			cin>>l>>r;
			add(l,r),add(r,l);	
		}
		dfs(1,-1);
		cout<<ans<<endl;
	}
	return 0;
}

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

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

	while(1){
		if(s=="ABC")break;
		
		string nxt="";
		int count=0;
		int c[3]={};
		for(int i=0;i<s.size();){
			if(i+2<s.size()&&s.substr(i,3)=="ABC"){
				count++;
				i+=3;
			}
			else{
				c[s[i]-'A']++;
				i++;
			}
		}
		int zero=0,pos=-1;
		rep(i,3)if(c[i]==0)zero++,pos=i;
		if(zero!=1){
			cout<<"No"<<endl;
			return 0;
		}
		if(count==0){
			cout<<"No"<<endl;
			return 0;
		}

		for(int i=0;i<s.size();){
			if(i+2<s.size()&&s.substr(i,3)=="ABC"){
				nxt+=('A'+pos);
				i+=3;
			}
			else{
				nxt+=s[i];
				i++;
			}
		}
		s = nxt;
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	double n;
	while (1) {
		cin >> n;
		if (n == 0) break;
		vi ss(n);
		REP(i, n) cin >> ss[i];
		int sum = accumulate(ALL(ss), 0);
		double avg = sum / n;
		double tmp_sum = 0;
		REP(i, n) {
			tmp_sum += pow(ss[i] - avg, 2);
		}
		double variance = tmp_sum / n;
		cout << sqrt(variance) << endl;
	}
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}



Measured memory_bytes: 3256
x,n = map(int,input().split())
if n == 0:
    print(x)
else:
    L = list(map(int,input().split()))
    ans = []
    cur = 0
    while len(ans) == 0:
        temp_1 = x-cur
        temp_2 = x+cur
        if temp_1 not in L:
            ans.append(temp_1)
        if temp_2 not in L:
            ans.append(temp_2)
        cur += 1
    print(ans[0])


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

vector<int>v,dp;
int mincost(int n){
	//cout<<n<<"\n";
	
	if(dp[n]!=-1){
		//cout<<"in\n";
		return dp[n];
	}
	//cout<<"out\n";
	dp[n] = min((mincost(n-1) +abs(v[n]-v[n-1])),(mincost(n-2)+abs(v[n]-v[n-2])));
	//cout << n<<", "<<dp[n]<<"\n";
	//int x;cin>>x;
	return dp[n];
}

void solve(){
	int n;cin>>n;
	dp.resize(n,-1);
	v.resize(n);
	
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	dp[0]=0;
	dp[1]= abs(v[1]-v[0]);
	cout<<mincost(n-1)<<"\n";

}
int main(){
	int t=1;//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3328
//b.c B-String Rotation
#include<stdio.h>
#include<string.h>
#include<stdbool.h>

int main(void){
    char buf1[201],buf2[201],buf3[201];
    bool flag = false;
    scanf("%s",buf1);
    scanf("%s",buf2);
    int len = strlen(buf1);
    strcpy(buf3,buf1);
    strcat(buf3,buf1);

    for(int i=0;i<len;++i){
        if(strncmp(buf2,buf3+len-1-i,len)==0){
            flag = true;
        }
    }
    if(flag){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
int main(){
	int H,W,x,y;
	while(true){
		std::cin >> H >> W;
		if(H == 0&&W == 0)break;
		for(int a = 0;a < H;a++){
			for(int b = 0;b < W;b++){
				x = a + b;
				y = x % 2;
				if(y == 0){
					std::cout <<"#";
				}else{
					std::cout <<".";
				}
			}
			std::cout <<std::endl;
		}
		std::cout <<std::endl;
	}
}

Measured memory_bytes: 3096
# include <bits/stdc++.h>
# define rr
const int N=100010,INF=0x3f3f3f3f;
int a,b,c,k;
inline int read(void){
	int res,f=1;
	char c;
	while((c=getchar())<'0'||c>'9')
		if(c=='-')f=-1;
	res=c-48;
	while((c=getchar())>='0'&&c<='9')
		res=res*10+c-48;
	return res*f;
}
int main(void){
	a=read(),b=read(),c=read(),k=read();
	int ans=0;
	ans+=std::min(a,k);
	k-=std::min(a,k);
	if(k){
		k-=std::min(b,k);
	}
	if(k){
		ans-=std::min(c,k);
		k-=std::min(c,k);
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 3764
use std::str::FromStr;
use std::collections::HashMap;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let s : String = get_one();
    let t : String = get_one();

    let mut ss : Vec<char> = s.chars().collect();
    let mut ts : Vec<char> = t.chars().collect();
    ss.sort();
    ts.sort();
    ts.reverse();

    if ss < ts {
        println!("{}", "Yes");
    }
    else {
        println!("{}", "No");
    }
}




Measured memory_bytes: 4352
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::cmp::{max, min, Ordering};

macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

// N M => let (N, M) = get!(usize, usize)
// A1 B1
// ...
// AQ BQ => let A = get!(usize, usize; Q)

const MOD: u64 = 1000000007;

fn main() {
    let N = get!(usize);
    let A = get!(String);
    let B = get!(String);
    let C = get!(String);

    let mut ans = 0;
    for (a, (b, c)) in A.chars().zip(B.chars().zip(C.chars())) {
        if a == b && b == c {
            continue;
        }
        if a == b || b == c || c == a {
            ans += 1;
            continue;
        }
        ans += 2;
    }

    println!("{}", ans);
}


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


int main() {
  long long N, M; cin >> N >> M;

  if(N == 1 && M == 1){
    cout << 1 << endl;
  }
  else if(N == 1 || M == 1){
    cout << max(N, M) - 2 << endl;
  }
  else if(N == 2 || M == 2){
    cout << 0 << endl;
  }
  else cout << (N-2)*(M-2) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main() {
	int n,m;
	cin>>m>>n;
	vector<vector<char>> arr(m,vector<char>(n));
	for(int i=0;i<m;i++)
	{
	    for(int j=0;j<n;j++)
	    {
	        cin>>arr[i][j];
	    }
	}
	vector<vector<int>> dp(m,vector<int>(n,0));
	dp[0][0]=1;
	for(int i=1;i<m;i++)
	{
	    if(arr[i][0]!='#')
	        dp[i][0] = dp[i-1][0];
	   else
	        dp[i][0]=0;
	}
	for(int j=1;j<n;j++)
	{
	    if(arr[0][j]!='#')
	        dp[0][j] = dp[0][j-1];
	   else
	        dp[0][j]=0;
	}
	for(int i=1;i<m;i++)
	{
	    for(int j=1;j<n;j++)
	    {
	        if(arr[i][j]!='#')
	            dp[i][j] = (max(dp[i][j], dp[i-1][j]+dp[i][j-1]))%MOD;
	        else
	            dp[i][j]=0;
	    }
	}
	cout<<dp[m-1][n-1]%MOD<<endl;
	return 0;
}


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

const int MAX_N = 110000;

vector<int> prime_list() {
    char f[MAX_N+1];
    fill(f, f + MAX_N + 1, -1);
    f[0] = f[1] = false;
    for(int i = 2; i <= MAX_N; i++)
        if(f[i])
            for(int j = 2 * i; j <= MAX_N; j += i)
                f[j] = false;
    vector<int> res;
    for(int i = 2; i <= MAX_N; i++) if(f[i]) res.push_back(i);
    return res;
}

int main() {
    vector<int> prime = prime_list();
    for(int N, P; cin >> N >> P, N + P != -2; ) {
        vector<int> li;
        int s = upper_bound(prime.begin(), prime.end(), N) - prime.begin();
        for(int i = s; i <= s + P; i++)
            for(int j = i; j <= s + P; j++)
                li.push_back(prime[i]+prime[j]);
        sort(li.begin(), li.end());
        cout << li[P - 1] << endl;
    }
}

Measured memory_bytes: 1436