akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
#ABC119 C

n,A,B,C = map(int,input().split())
l = [int(input()) for _ in range(n)]
INF = float('inf')
#使わない竹、a用、b用、c用に使う竹をあらかじめ決める(4**n通り)
#a用、b用、c用に使う竹をすべて合成する
#+1,-1で調整する

def dfs(cur,a,b,c):#cur:=現在見ている竹,a:=竹aの長さ,b:=竹bの長さ,c:=竹cの長さ
    if cur == n:#最後まで見たら
        if min(a,b,c) > 0:#合成には,a,b,cそれぞれ1本以上必要(本数0→1も合成としている)
            #abs(X-x):=目標の長さまでの差(+1,-1で調整する回数)
            #-30:=長さ0→l[cur]の部分でも10を足しているためa,b,c分引く
            return abs(A - a) + abs(B - b) + abs(C - c) - 30
        else:
            return INF
    ret0 = dfs(cur+1,a,b,c)#使わない場合
    ret1 = dfs(cur+1,a+l[cur],b,c) + 10#a用として竹(l[cur])を使う(合成する)場合
    ret2 = dfs(cur+1,a,b+l[cur],c) + 10#b用として竹(l[cur])を使う(合成する)場合
    ret3 = dfs(cur+1,a,b,c+l[cur]) + 10#c用として竹(l[cur])を使う(合成する)場合
    return min(ret0,ret1,ret2,ret3)
print(dfs(0,0,0,0))


Measured memory_bytes: 45020
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,N;
  cin >> H >> N;
  vector<int>A(N);

  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  for(int i=0;i<N;i++){
    H -= A[i];
  }
  if(H>0){
      cout << "No";
  }else{
      cout << "Yes";
  }
}

Measured memory_bytes: 640
N = int(input())
H = list(map(int, input().split()))
ans = 0
cnt = 0

for i in range(1, len(H)):
    if H[i-1] >= H[i]:
        cnt += 1
    else:
        ans = max(ans, cnt)
        cnt = 0

ans = max(ans, cnt)
print(ans)

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

int main(){
    int n;
    cin>>n;
    vector<double> coins(n);
    for(auto &it : coins){
        cin>>it;
    }
    
    vector<vector<double>> dp(n + 1, vector<double>(n+1));
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++){
        dp[i][0] = dp[i-1][0] * (1 - coins[i - 1]);
        for(int j = 1; j <= i; j++){
            dp[i][j] = dp[i - 1][j] * (1 - coins[i - 1]) + dp[i - 1][j - 1] * coins[i - 1];
        }
    }
    // for(auto i : dp[n]){
    //     cout<<i<<endl;
    // }
    double ans = 0;
    for(auto i = dp[n].begin() + (n+1)/2; i != dp[n].end(); i++){
        ans += *i;
    }
    printf("%0.10lf", ans);
    return 0;
}

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

int main() {
  int k, s, ans=0;
  cin >> k >> s;
  for(int i = 0; i <= k; ++i) {
    for(int j = 0; j <= k; j++) {
      int z = s - j - i;
      if (z >= 0 && z <= k) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define MOD 1000000007
#define fi first
#define se second
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define repe(i,n) for(int i = 0 ; i <= n ; i++)
#define repb(i,a,b) for(int i = a ; i < b ; i++)
#define repeb(i,a,b) for(int i = a ; i <= b ; i++)
#define rfor(i,n,a) for(int i = n ; i >= a ; i--)
#define pb push_back
#define popb pop_back()
#define endl "\n"
#define pii pair<int,int> 
#define pll pair < long long, long long >
typedef priority_queue<ll, vector<ll>, greater<ll>> minheap;
typedef priority_queue<ll> maxheap;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a,b) cout << a << " " << b << endl
#define p3(a,b,c) cout << a << " " << b << " " << c << endl
#define p4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl
#define sortv(v) sort(v.begin(),v.end())
#define rsortv(v) sort(v.begin(),v.end(), greater<>());
#define sortby(v,prop) sort( v.begin( ), v.end( ), [ ]( const auto& lhs, const auto& rhs ){ return lhs.prop < rhs.prop; });
#define rsortby(v,prop) sort( v.begin( ), v.end( ), [ ]( const auto& lhs, const auto& rhs ){ return lhs.prop > rhs.prop; });

ll modPower(ll num,ll r){
	if(r==0) return 1;
	if(r==1) return num%MOD;
	ll ans=modPower(num,r/2)%MOD;
	if(r%2==0) {
		return (ans*ans)%MOD;
	} return (((ans*ans)%MOD)*num)%MOD;
}

ll nCr(ll n, ll r) { 
    ll res = 1; 
    if (r > n - r) {
        r = n - r; 
    }
    rep(i,r) { 
        res *= (n - i); 
        res /= (i + 1); 
    } 
    return res; 
}

bool isPrime(long long n)
{
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
 
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
 
    return true;
}


/*-------------------------------------------------*/

void solve() {

	ll n;
	cin >> n;

	string s = "";

	while(n > 0) {
		s = (char)(97 + (n - 1) % 26) + s;
        n = (n - 1) / 26;
	}

	p1(s);

}


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

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};

const int N=1e5+5;
void no(){cout<<"No\n";exit(0);}
struct edge{
    int to,pos,rem=0;
    edge(int _to,int _pos):to(_to),pos(_pos){}
};
vector<edge> g[N];//<- size
int we[N];//<- size
void del(int v,int i){g[v][i].rem=g[g[v][i].to][g[v][i].pos].rem=1;}
vector<int> eulerpath;
void go(int v){
    for(;we[v]<g[v].size();++we[v]){
        if(g[v][we[v]].rem)continue;
        del(v,we[v]);
        go(g[v][we[v]].to);
    }
    eulerpath.pb(v);
}
void euler(int n){
    int s=1,c=0;//<- default start
    for(int i=1;i<=n;++i)if(g[i].size()&1)s=i,c++;
    if(c>1)no();
    go(s);
}
void ae(int a,int b){
    assert(a!=b);//otdelno
    int za=sz(g[a]);
    int zb=sz(g[b]);
    g[a].pb(b,zb);
    g[b].pb(a,za);
}
int u[N];
vector<int> p;
bool dfs(int v,int tar){
    if(v==tar)return 1;
    u[v]=1;
    forn(i,sz(g[v])){
        if(!g[v][i].rem&&!u[g[v][i].to]){
            int res=dfs(g[v][i].to,tar);
            if(res){
                del(v,i);
                dbg(v,g[v][i].to);
                return 1;
            }
        }
    }
    return 0;
}
int32_t main(){
    int n,m;
    cin>>n>>m;
    forn(i,m){
        int a,b;
        cin>>a>>b;
        ae(a,b);
    }
    euler(n);
    int c6=0,c4=0;
    for(int i=1;i<=n;++i){
        if(sz(g[i])>=6)c6++;
        if(sz(g[i])==4)c4++;
    }
    if(c6||c4>=3){
        cout<<"Yes\n";
        return 0;
    }
    if(c4<2){
        cout<<"No\n";
        return 0;        
    }
    vector<int> v4;
    for(int i=1;i<=n;++i){
        if(sz(g[i])==4)v4.pb(i);
        for(edge&e:g[i])e.rem=0;
    }
    int a=v4[0];
    int b=v4[1];
    for(int i=1;i<=n;++i)u[i]=0;
    dfs(a,b);
    for(int i=1;i<=n;++i)u[i]=0;
    dfs(a,b);
    for(int i=1;i<=n;++i)u[i]=0;
    if(dfs(a,b))cout<<"No\n";
    else cout<<"Yes\n";
    return 0;
}


Measured memory_bytes: 18444
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
#define MOD (1e9+7)
#define INF (1e9)
#define LLINF (4e18)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
void input() {}
template<typename... R> void input(int& f, R&... r) { scanf("%d", &f); input(r...); }
template<typename... R> void input(double& f, R&... r) { scanf("%lf", &f); input(r...); }
template<typename... R> void input(ll& f, R&... r) { scanf("%lld", &f); input(r...); }
template<typename... R> void input(char& f, R&... r) { scanf("%c", &f); input(r...); }
template<typename... R> void input(string& f, R&... r) { cin >> f; input(r...); }
template<typename T, typename... R> void input(vector<T>& f, R&... r) { REP(i, f.size())input(f[i]); input(r...); }
#pragma endregion

//UnionFind
class UnionFind {
private:
    vector<int> par;
    vector<pair<int, int>> siz;
public:
    UnionFind(int n, int m) {
        par.resize(n + m, -1);
        siz.resize(n + m);
        fill(siz.begin(), siz.begin() + n, pair<int, int>(1, 0));
        fill(siz.begin() + n, siz.end(), pair<int, int>(0, 1));
    }

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (size(rx) < size(ry)) swap(rx, ry);
        par[rx] += par[ry];
        siz[rx].first += siz[ry].first;
        siz[rx].second += siz[ry].second;
        par[ry] = rx;
        return true;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return -par[root(x)];
    }

    int xsize(int x) {
        return siz[root(x)].first;
    }

    int ysize(int x) {
        return siz[root(x)].second;
    }
};

int main() {
    int N; input(N);
    UnionFind uni(1e5, 1e5);
    vector<bool> visited(2 * 1e5, false);
    REP(i, N) {
        int x, y; input(x, y);
        x--; y--;
        uni.unite(x, y + 1e5);
    }
    ll cnt = 0;
    REP(i, 2 * 1e5) {
        if (visited[uni.root(i)]) continue;
        visited[uni.root(i)] = true;
        cnt += (ll)uni.xsize(uni.root(i)) * uni.ysize(uni.root(i));
    }
    cout << cnt - N << endl;
    getchar(); getchar();
}

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



int main()
{
    ll n,t;
    cin>>n>>t;
    ll l1[n+1],x=t,s=0;
    for(int i=1;i<=n;i++){
        cin>>l1[i];
    }
    for(int i=2;i<=n;i++){
        if(l1[i]<=x)x=l1[i]+t;
        else s+=l1[i]-x,x=l1[i]+t;
    }
    cout<<x-s<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<string> W(N);
  for(int i = 0; i < N; i++){
    cin >> W.at(i);
  }
  bool x = true;
  for(int i = 0; i < N-1; i++){
    if(W.at(i).back() != W.at(i+1).front()){
      x = false;
      break;
    }
  }
  for(int i = 0; i < N-1; i++){
    for(int j = i+1; j < N; j++){
      if(W.at(i) == W.at(j)){
        x = false;
        break;
      }
    }
  }
  if(x){
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    cout << ((abs(a - b) - 1) % 2 ? "Alice" : "Borys") << endl;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

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


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

	int a=0,b=0;
	REP(i,4) {
		int A;cin>>A;a+=A;
	}
	REP(i,4) {
		int B;cin>>B;b+=B;
	}
	cout<<max(a,b)<<endl;

	return 0;
}



Measured memory_bytes: 3204
#include <iostream>
#include "bits/stdc++.h"

using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i, a, b) for(ll i=a;i<b;i++)
#define REP(i, a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i, a) for(ll i=a;i>0;i--)
#define rrep(i, a, b) for(ll i=a-1;i>=b;i--)
#define printall(n, array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
typedef vector<vector<ll>> VVE;
const ll mod = 1e9 + 7; //10^9+7

int main() {
    ll x, y, z, K;
    cin >> x >> y >> z >> K;
    VE a(x), b(y), c(z);
    REP(i, x) cin >> a[i];
    REP(i, y) cin >> b[i];
    REP(i, z) cin >> c[i];
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    sort(c.rbegin(), c.rend());
    set<vector<ll>> s;
    priority_queue<pair<ll, vector<ll>>> que;
    que.push({a[0] + b[0] + c[0], {0, 0, 0}});
    s.insert({0, 0, 0});
    REP(q, K) {
        if(que.empty()){print("empty");break;}
        auto pair = que.top();
        que.pop();
        ll value = pair.first;
        ll i = pair.second[0];
        ll j = pair.second[1];
        ll k = pair.second[2];
        print(value);
        if(i < x - 1){
            if(s.find({i + 1, j, k}) == s.end()){
                que.push({a[i + 1] + b[j] + c[k], {i + 1, j, k}});
                s.insert({i + 1, j, k});
            }
        }
        if(j < y - 1){
            if(s.find({i, j + 1, k}) == s.end()) {
                que.push({a[i] + b[j + 1] + c[k], {i, j + 1, k}});
                s.insert({i, j + 1, k});
            }
        }
        if(k < z - 1){
            if(s.find({i, j, k + 1}) == s.end()){
                que.push({a[i] + b[j] + c[k + 1], {i, j, k + 1}});
                s.insert({i, j, k + 1});
            }
        }
    }
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <utility>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

#define _overload2(_1,_2,name,...) name
#define _overload3(_1,_2,_3,name,...) name
#define _all1(a) (a).begin(),(a).end()
#define _all2(a,n) (a),(a)+n
#define all(...) _overload2(__VA_ARGS__,_all2,_all1,)(__VA_ARGS__)
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){for(int i=0;i<vec.size();++i)os<<vec[i]<<(i+1==vec.size()?"":" ");return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}

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

  priority_queue<pii> q;
  vi v;
  rep(i, N) {
    int a; in(a);
    q.push(pii(a, i));
  }
  while (!q.empty()) {
    v.push_back(q.top().second+1);
    q.pop();
  }
  reverse(all(v));
  cout << v << "\n";

  return 0;
}


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


using namespace std;

#define int long long
#define all(a) a.begin(),a.end()
#define sz(x) ((int)x.size())
#define ff first 
#define ss second 
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<string> vs;
typedef map<int,int> mii;
typedef map<char,int> mci;
typedef vector<vector<int>> vvi;
typedef vector<pair<int,int>> vpii;
template<class T>
istream &operator>>(istream &in, vector<T> &arr){
	for(auto &x: arr) in >> x;
	return in;
}


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<double> p(n);
    cin >> p;
    vector<double> dp(n + 1);

    dp[0] = 1;

    // dp[i] -> prbility of getting i heads

    for(int i = 1; i <= n; ++i){
        for(int j = i; j >= 0; --j){
            dp[j] = (j == 0 ? 0 : dp[j-1]*(p[i - 1])) + dp[j]*(1 - p[i-1]);
        }
    }
    
    double ans = 0;

    // cout << dp[3] << ' ' << dp[2] << ' ';
    for(int i = 1; i <= n; ++i){
        if(i > n - i){
            ans += dp[i];
        }
    }
    cout << fixed << setprecision(10) << ans;
}  

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

using ll = long long;
using pll = pair <ll, ll>;
const int MAX = 1e6+5;

ll n;
ll arr[MAX];

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

	cin >> n;
	arr[1] = 7%n;
	if (n == 7 || n == 1) return cout << 1 << endl, 0;
	for (int i = 2; i <= n; i++){
		arr[i] = arr[i-1]*10+7;
		arr[i] %= n;
		if (arr[i] == 0) return cout << i << endl, 0;
	}
	cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 11416
def calc(i, j, B1, len_b):
    extra = 0
    d = j - i

    # i < j < k
    k1 = d + j
    if k1 < len_b:
        extra += B1[k1]

    # k < i < j
    k2 = i - d
    if 0 <= k2 and k2 < len_b:
        extra += B1[k2]

    # i < k < j
    s = i + j
    if s % 2 == 0:
        k3 = s // 2
        if k3 < len_b:
            extra += B1[k3]
    return extra

def main():
    N = int(input())
    S = input()
    RGB = {'R': [], 'G': [], 'B': []}
    for i in range(N):
        RGB[S[i]].append(i)
    num_r = len(RGB['R'])
    num_g = len(RGB['G'])
    num_b = len(RGB['B'])
    if num_r == 0 or num_g == 0 or num_b == 0:
        print(0)
        return

    len_b = (RGB['B'][-1] + 1)
    B1 = [0]*len_b
    for b in RGB['B']:
        B1[b] = 1
    # print(R, G, B)
    ans = num_r * num_g * num_b
    for i in RGB['R']:
        for j in RGB['G']:
            ans -= calc(min(i, j), max(i, j), B1, len_b)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9272
n, k = map(int, input().split())
H = sorted(int(input()) for _ in range(n))
tmp = H[k - 1] - H[0]
best = tmp
for i in range(1, n - k + 1):
  tmp = H[k + i - 1] - H[i]
  if tmp < best:
    best = tmp
print(best)

Measured memory_bytes: 7492
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
#define pi 3.1415926535
typedef long long ll;

int main(){
    vector<vector<int>>A(3,vector<int>(3));
    
    rep(i,3){
        rep(j,3){
            cin>>A[i][j];
        }
    }
    int N;
    cin>>N;
    vector<int>b(N);
    rep(i,N){
        cin>>b[i];
    }

    rep(i,N){
        rep(j,3){
            rep(k,3){
                if(b[i]==A[j][k]){
                    A[j][k]=0;
                }
            }
        }
    }

/*
    rep(i,3){
        rep(j,3){
            cout<<A[i][j]<<" ";
            if(j==2){
                cout<<endl;
            }
        }
    }
    */
   int flag=0;

   rep(i,3){
       if(A[i][0]==0&&A[i][0]==A[i][1]&&A[i][0]==A[i][2]){
           flag=1;
       }
   }

   rep(i,3){
       if(A[0][i]==0&&A[0][i]==A[1][i]&&A[0][i]==A[2][i]){
           flag=1;
       }
   }

   if(A[0][0]==0&&A[0][0]==A[1][1]&&A[0][0]==A[2][2]){
       flag=1;
   }else if(A[0][3]==0&&A[0][3]==A[1][1]&&A[0][3]==A[2][0]){
       flag=1;
   }

   if(flag){
       cout<<"Yes"<<endl;
   }else{
       cout<<"No"<<endl;
   }


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll long long
#define ld double
#define pb push_back
#define mod 1000003
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
ll binpow(ll a,ll b,ll m=mod)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        res=(a*res)%m;
        a=(a*a)%m;
        b/=2;
    }
    return res;
}
main()
{
    IO
    string s,t;
    cin>>s>>t;
    ll ans=t.length();
    for(int x=0;x<=s.length()-t.length();x++)
    {   ll f=0;
        for(int y=x;y<t.length()+x;y++)
        {
            if(s[y]!=t[y-x])++f;
        }
        ans=min(ans,f);
    }
    cout<<ans;
}


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


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


int insertionSort(int A[], int N, int g){
    int cnt = 0;
    for(int i = g; i < N; ++i){
        int v = A[i];
        int j = i - g;
        while(j >= 0 && A[j] > v){
            A[j + g] = A[j];
            j -= g;
            ++cnt;
        }
        A[j + g] = v;
    }
    return cnt;
}

int shellSort(int A[], int N, vector<int> &G){
    int h = 1;
    while(h <= N){
        G.pb(h);
        h = 3 * h + 1;
    }
    
    int cnt = 0;
    for(int i = G.size() - 1; i >= 0; --i)
        cnt += insertionSort(A, N, G[i]);
    
    return cnt;
}

int main(void){
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; ++i) cin >> A[i];
     
    vector<int> G;
    int cnt = shellSort(A, N, G);
    
    cout << G.size() << endl;
    for(int i = G.size() - 1; i > 0; --i){
        cout << G[i] << " ";
    }
    cout << G[0] << endl;
    cout << cnt << endl;
    rep(i, N) cout << A[i] << endl;
    
    return 0;
}


Measured memory_bytes: 7016
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

struct Node{
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;
int flag=1;

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;
    z = (Node*)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    while(x!=NIL){
        y = x;
        if(x->key > z->key) x = x->left;
        else x = x->right;
    }
    z->parent = y;
    if(y==NIL) root = z;
    else{
        if(y->key > z->key) y->left = z;
        else y->right = z;
    }
}

Node* find(int k){
    Node *x = root;
    while(x!=NIL && x->key!=k){
        if(x->key > k) x = x->left;
        else x = x->right;
    }
    return x;
}

void preorder(Node *u){
    if(u==NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

void inorder(Node *u){
    if(u==NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void dlt(Node *z){
    if(z==NIL) return;
    if(z->left==NIL && z->right==NIL){
        if(z == z->parent->left) z->parent->left = NIL;
        else z->parent->right = NIL;
        z->parent = NIL;
    }
    else if(z->left==NIL || z->right==NIL){
        Node *y = z->parent;
        Node *x;
        if(z->left!=NIL) x = z->left;
        else x = z->right;
        if(y->left==z){
            x->parent = y;
            y->left = x;   
        }
        else{
            x->parent = y;
            y->right = x;
            z->parent = NIL;
        }
    }
    else{
        Node *y = z->parent;
        Node *xl = z->left;
        Node *xr = z->right;
        while(xr->left!=NIL){
            xr = xr->left;
        }
        z->key = xr->key;
        dlt(xr);
    }
}

void dltn(int k){
    Node *z = find(k);
    dlt(z);
}

void fnd(Node *x){
    if(x==NIL) cout<<"no"<<endl;
    else cout<<"yes"<<endl;
}

int main(){
    int n;
    scanf("%d", &n);
    for(int i=0;i<n;i++){
        string str;
        int k;
        cin>>str;
        if(str=="insert"){
            scanf("%d", &k);
            insert(k);
        }
        else if(str=="find"){
            scanf("%d", &k);
            fnd(find(k));
        }
        else if(str=="print"){
            inorder(root);
            cout<<endl;
            preorder(root);
            cout<<endl;
        }
        else{
            scanf("%d", &k);
            dltn(k);
        }
    }
}


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

int main(){
	int a[3],t,h;
	char d;
	t=h=0;
	while(cin>>a[0]!='\0'){
		cin>>d>>a[1]>>d>>a[2];
		if(a[0]*a[0]+a[1]*a[1]==a[2]*a[2])t++;
		else if(a[0]==a[1])h++;
	}
	cout<<t<<endl<<h<<endl;
}

Measured memory_bytes: 1160
// https://atcoder.jp/contests/abc152/tasks/abc152_d

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;

  // 末尾は 0 でない
  VVL cts(10, VL(10));

  rep1(f, 9) rep1(b, 9) {
    if (f == b && f <= N) {
      cts[f][b]++;
    }

    ll digit = 2;
    for (ll digit = 2; f * pow(10, digit - 1) + b <= N; digit++) {
      ll low = f * pow(10, digit - 1) + b;
      ll high = (f + 1) * pow(10, digit - 1) - 10 + b;

      if (high <= N) {
        cts[f][b] += pow(10, digit - 2);
        continue;
      }

      // N の先頭と末尾を除いた数 + 0 only
      ll mid_ct = N / 10 - f * pow(10, digit - 2) + 1;

      if (N % 10 == b) {
        cts[f][b] += mid_ct;
      } else if (N % 10 < b) {
        cts[f][b] += mid_ct - 1;
      } else {
        cts[f][b] += mid_ct;
      }
    }
  }

  ll res = 0;

  rep1(f, 9) rep1(b, 9) { res += cts[f][b] * cts[b][f]; }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 *
 * @author cs18097
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a<6){
            System.out.print(0);
            return;
        }else if(a > 12){
            System.out.print(b);
            return;
        } else {
            System.out.print(b/2);
        }
        
    }
    
}


Measured memory_bytes: 20308
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);;
        ArrayList<Integer> mList = new ArrayList<>();

        while(sc.hasNext()){
            mList.add(sc.nextInt());
        }
        mList.sort(Comparator.reverseOrder());
        for (int i = 0; i < 3; i++) {
            System.out.println(mList.get(i));
        }
    }
}

Measured memory_bytes: 26096
X, K ,D = input().split()
X = abs(int(X))
K = int(K)
D = int(D)
Q, mod = divmod(X, D)
if K < Q:
    ans = X - K*D
else:
    Rest = (K - Q)%2
    if Rest == 0:
         ans = mod
    else:
         ans = D - mod
print(ans)

Measured memory_bytes: 9160
function heron(a,b,c){
   var s=(a+b+c)/2;
   var S=Math.sqrt(s*(s-a)*(s-b)*(s-c));
   return S;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
for(var i=0;i<Arr.length;i++){
   var arr=Arr[i].split(",").map(Number);
   (function(x1,y1,x2,y2,x3,y3,x4,y4){
      var d12=Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));
      var d23=Math.sqrt(Math.pow(x2-x3,2)+Math.pow(y2-y3,2));
      var d34=Math.sqrt(Math.pow(x3-x4,2)+Math.pow(y3-y4,2));
      var d41=Math.sqrt(Math.pow(x4-x1,2)+Math.pow(y4-y1,2));
      var d13=Math.sqrt(Math.pow(x1-x3,2)+Math.pow(y1-y3,2));
      var d24=Math.sqrt(Math.pow(x2-x4,2)+Math.pow(y2-y4,2));
      var A=heron(d12,d24,d41)+heron(d23,d34,d24);
      var B=heron(d12,d23,d13)+heron(d13,d34,d41);
      var ans=(Math.abs(A-B)<1.0e-5)?"YES":"NO";
      console.log(ans);
   }).apply(null,arr);
}

Measured memory_bytes: 7644
s=input()
f1=f2=0
if(len(s)%2==0):
    f1=1
if(s[0]==s[len(s)-1]):
    f2=1
    
if((f1==1 and f2==0) or (f1==0 and f2==1)):
    print('Second')
else:
    print('First')

Measured memory_bytes: 3316
#include <stdio.h>
#include <math.h>

int main(void){
	double ww;
	while(scanf("%lf",&ww)!=EOF){
		if(ww>91.0)printf("heavy\n");
		else if(ww>81.0)printf("light heavy\n");
		else if(ww>75.0)printf("middle\n");
		else if(ww>69.0)printf("light middle\n");
		else if(ww>64.0)printf("welter\n");
		else if(ww>60.0)printf("light welter\n");
		else if(ww>57.0)printf("light\n");
		else if(ww>54.0)printf("feather\n");
		else if(ww>51.0)printf("bantam\n");
		else if(ww>48.0)printf("fly\n");
		else printf("light fly\n");
	}
	return 0;
}

Measured memory_bytes: 608
/*
* @author:  codancer
* @createTime:  2020-04-04, 19:50:22
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
int main(){
	int x,y,z;
	cin>>x>>y>>z;
	swap(x,y);
	swap(x,z);
	cout<<x<<' '<<y<<' '<<z<<endl;
	return 0;
}

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

int main()
{
	int N, M, D;
	cin >> N >> M >> D;
	vector<string> S(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	int res = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j + D <= M; j++) {
			bool ok = true;
			for (int k = j; k < j + D; k++) {
				if (S[i][k] == '#') {
					ok = false;
					break;
				}
			}
			res += ok;
		}
	}
	for (int i = 0; i + D <= N; i++) {
		for (int j = 0; j < M; j++) {
			bool ok = true;
			for (int k = i; k < i + D; k++) {
				if (S[k][j] == '#') {
					ok = false;
					break;
				}
			}
			res += ok;
		}
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
 
/*** Template Begins ***/
 
typedef long long   ll;
typedef pair<ll,ll> pll;
typedef long double ld; 
#define rep(i,a,b) for(i=a;i<b;i++)
#define pb           push_back
#define F            first
#define S            second
#define ios          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define hell   1000000007LL
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p){ ll res = 1;x = x % p;while (y > 0) {if (y & 1) res = (res*x) % p;y = y>>1;
  x = (x*x) % p;} return res;} 

const long double PI = acos(-1);
// Debug //
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
ll euclid(ll x,ll y,ll a,ll b){
  return (a-x)*(a-x)+(b-y)*(b-y);
}
void solve()
{
  ld x,y;
  cin>>x>>y;
  ld a = (4*x-y)/2;
  ld b = (y-2*x)/2;
  if(a!=(int)a || b!=(int)b || a<0 || b<0)
    cout<<"No";
  else
    cout<<"Yes";
}
int main()
{ 
  ios;
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ll t=1,i=1;
  // cin>>t;
  while(i<=t)
  {
    solve();
    i++;
  }
  return 0;
}


Measured memory_bytes: 3740
import java.util.*;

public class Main {
    public static void main(String[] args) {
        aldl_1_2_a();
    }

    static void aldl_1_2_a() {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        ArrayList<Integer> data = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            data.add(sc.nextInt());
        }
        sc.close();
        int count = 0;
        for (int i = 0; i < data.size(); i++) {
            for (int j = data.size() - 1; j > i; j--) {
                int dataJ = data.get(j);
                int dataJ1 = data.get(j - 1);
                if (dataJ < dataJ1) {
                    data.set(j, dataJ1);
                    data.set(j - 1, dataJ);
                    count++;
                }
            }
        }
        for (int i = 0; i < data.size(); i++) {
            if (i > 0)
                System.out.print(" ");
            System.out.print(data.get(i));
        }
        System.out.println();
        System.out.println(count);
    }
}


Measured memory_bytes: 26392
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#define rep(i, a, b) for(int i = a; i < b; i++)

using namespace std;
typedef long long ll;
string s;
int n;
int main(){
	cin >> n;
	rep(i, 0, n){
		vector<int> v(3);
		cin >> v[0] >> v[1] >> v[2];
		sort(v.begin(), v.end());
		
		if(v[2]*v[2] == v[1]*v[1] + v[0]*v[0]) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
while(true){
  int N, M;
  cin >> N >> M;
  if(N==0 && M == 0) break;
  vi C(M), x(N+1);
  for(int i = 0; i < M; i++){
    cin >> C.at(i);
  }
  for(int i = 1; i <= N; i++){
    cin >> x.at(i);
  }

  vvi dp(N+1, vi(256, INT_INF));
  dp.at(0).at(128) = 0;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 256; j++){
      if(dp.at(i).at(j) == INF) continue;
      for(int k = 0; k < M; k++){
        int nextj = j+C.at(k);
        if(nextj < 0) nextj = 0;
        if(nextj > 255) nextj = 255;
        chmin(dp.at(i+1).at(nextj), dp.at(i).at(j) + (nextj-x.at(i+1))*(nextj-x.at(i+1)));
      }
    }
  }
  int result = INT_INF;
  for(int i = 0; i < 256; i++){
    chmin(result, dp.at(N).at(i));
  }
  cout << result << endl;
}
}


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++ i)
#define ALL(r) r.begin(), r.end()
#define DUP(x, y) (((x) + (y) - 1) / (y))

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    int n, k;
    cin >> n >> k;
    vint h(n);
    rep(i, n) cin >> h[i];
    sort(ALL(h));

    int m = INF;
    rep(i, n - k + 1) {
        m = min(m, h[i + k - 1] - h[i]);
    }
    cout << m << endl;
}

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



Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define lli long long int
using namespace std;
#define S second
#define F first
#define pb push_back 
#define M1 1000000007
#define M2 998244353
#define plli pair<lli,lli>
#define setit set<lli>::iterator seti
#define mapit map<lli,lli> ::iterator mapi
#define MP make_pair
#define MT make_tuple
#define PI 3.14159265358979323846
// map      iterator->first  iterator.first
// map      mp[key]=value
// set      *s.begin()
// vector   v[j]=value
// pair     p.first p.second
// vector of pairs v[j].first v[j].second
// tuple    get<index>(tuple_name)
// vector of tuples get<index>(v[j])  sort(v.begin(),v.end())
//priority queue .top() .pop() .push()
// __gcd(x,y)
#define mini(x,y) (y + ((x - y) & ((x - y) >>(sizeof(int) * CHAR_BIT - 1))))
#define maxi(x,y) (x - ((x - y) & ((x - y) >> (sizeof(int) * CHAR_BIT - 1))))
#define fr(j,a,b) for(j=a;j<b;j++)

int power(int x, unsigned int y, int p)  
{    int res = 1;    
     x = x % p;
     if (x == 0) return 0;
     while (y > 0)  
     {  if (y & 1)  
        res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
     }  
    return res;  
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lli t,i,j,x;
    t=1;
    char n;
    for(i=0;i<t;i++){
        cin>>n;
        x=(int)n;
        if(x>96&&x<123){
            cout<<"a";
        }
        else{
            cout<<"A";
        }

    }
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define ll long long
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
#define BIT_FLAG_1 (1<<1) // 0000 0000 0000 0010
#define BIT_FLAG_2 (1<<2) // 0000 0000 0000 0100
#define BIT_FLAG_3 (1<<3) // 0000 0000 0000 1000
#define BIT_FLAG_4 (1<<4) // 0000 0000 0001 0000
#define BIT_FLAG_5 (1<<5) // 0000 0000 0010 0000
#define BIT_FLAG_6 (1<<6) // 0000 0000 0100 0000
#define BIT_FLAG_7 (1<<7) // 0000 0000 1000 0000

int main(){
    int n;
    cin >> n;
    ll ans=0;
    rep(i,n){
        if(!(i%3==0 or i%5==0)){
            ans+=i;
        }
    }
    cout << ans << endl;    
}

Measured memory_bytes: 3536
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <set>
#include <list>
#include <map>
#include <queue>
#include <iterator>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <utility>
#include <functional>
#include <stack>
#include <deque>
#include <sstream>
using namespace std;

#define ll long long
#define ld long double
#define pdd pair<double,double>
#define pll pair<ll, ll>
#define pii pair<int,int>

#define mod 1000000007
#define infinity (ll)1e18+1
#define PI 3.14159265358979

#define MP make_pair
#define SZ size()
#define PB push_back

#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define vpii vector<pii>

#define FOR(i,a,b) for(ll i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(ll i = (b) - 1; i >= (a); --i)
#define REPEAT(i) FOR(counter1234,0,i)
#define ALL(a) a.begin(), a.end()

int main()
{
	int n; cin >> n;
	int t;
	cin >> t;

	vi a(n); FOR(i, 0, n)scanf("%d", &a[i]);


	ll x = 0;
	FOR(i, 0, n - 1)
	{
		x += min(t, a[i + 1] - a[i]);
	}

	x += t;






	cout << x;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
long long p = 1000000007;
long long rui(long long rui_a, long long rui_b) {
	if (rui_b == 0)return 1;
	if (rui_b == 1)return rui_a % p;
	long long rui_c;
	rui_c = rui(rui_a, rui_b / 2);
	rui_c = rui_c * rui_c % p;
	if (rui_b % 2) {
		return rui_c * rui_a % p;
	}
	return rui_c;
}
long long n, k, x, y, z;
long long m[100001];
long long ans[100001];
int main() {
	scanf("%lld%lld", &n, &k);
	m[1] = 1;
	for (long long i = 2; i <= k; i++) {
		z = 0;
		for (long long j = 2; j * j <= i; j++) {
			if (i % j == 0) {
				if ((i / j) % j == 0)m[i] = 0;
				else m[i] = -m[i / j];
				z = 1;
				break;
			}
		}
		if (z == 0)m[i] = -1;
	}
	z = 0;
	for (long long i = 1; i <= k; i++) {
		x = k / i;
		x = rui(x, n);
		y = 1;
		while (y * y < i) {
			if (i % y == 0) {
				ans[y] += x * m[i / y];
				ans[y] += p;
				ans[y] %= p;
				ans[i / y] += x * m[y];
				ans[i / y] += p;
				ans[i / y] %= p;

			}
			y++;
		}
		if (y * y == i) {
			ans[y] += x * m[y];
			ans[y] += p;
			ans[y] %= p;
		}
	}
	for (int i = 1; i <= k; i++) {
		z += ans[i] * i;
		z %= p;
	}
	printf("%lld\n", z);
}

Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  int N=S.size(),A,Z;
  for(int i=0;i<N;i++){
    if(S.at(i)=='A'){
      A=i;
      break;
    }
  }
  for(int i=N-1;0<=i;i--){
    if(S.at(i)=='Z'){
      Z=i;
      break;
    }
  }
  cout<<Z-A+1<<endl;
}

Measured memory_bytes: 640
s = input()
listS = list(s)
listA = []
listB = []
for i in range(len(listS)-2):
	for j in range(3):
		n = int(listS[j+i])
		listA.append(n)
	Sm =listA[0]*100+listA[1]*10+listA[2]
	sa= abs(int(753) - Sm)
	listB.append(sa)
	listA.clear()
print(min(listB))

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(v) (v).begin(),(v).end()

const int MOD = 1000000007;
const int N = 1000005;
const double PI =4*atan(1);
ll n,k,x;
ll dp[N];
ll h[N];


int main(){
    ios::sync_with_stdio(0);
    //freopen("baklava.in","r",stdin);
    cin.tie(0);
    cout.tie(0);
    //start
    cin >> n >> k;
    for(int i=0;i<n;i++){
    	cin >> h[i];
    }
    dp[0]=0;
    for(int i=1;i<n;i++){
    	dp[i]=1e18;
    	for(int j=i-1;j>=max(i-k,0ll);j--){
    		dp[i]=min(dp[i],abs(h[i]-h[j])+dp[j]);
    	}
    }
    cout << dp[n-1];

    return 0;
}


Measured memory_bytes: 5248
from collections import Counter

N, *A = map(int, open(0).read().split())

C = Counter(A)
ma = max(C)
mi = min(C)

if (ma == 2 * mi and C[ma] >= 2 and C[mi] == 1) or \
    (ma == 2 * mi - 1 and C[ma] >= 2 and C[mi] == 2):
    if any(C[i] < 2 for i in range(mi + 1, ma)):
        print("Impossible")
    else:
        print("Possible")
else:
    print("Impossible")

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

long long gcd(long long a, long long b) { return b?gcd(b,a%b):a;}

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

    ll n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;

    ll g = gcd(n, m);
    
    ll n_ = n/g;
    ll m_ = m/g;

    for (int i = 0, j = 0; i < n && j < m; i += n_, j += m_) {
        if (s[i] != t[j]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << n/g*m << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

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

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) 
#define dumpL(x) 
#define LINE 
#define LINEL 
#define dumpV(v) 
#define dumpVL(v) 
#define STOP assert(false)
#endif
#define mp make_pair
 
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
    out << '(' << a.fi << ", " << a.se << ')';
    return out;
}
}

int main(){
    string s;
    cin >> s;
    int a = stoi(s.substr(0, 2).c_str());
    int b = stoi(s.substr(2).c_str());
    bool x = (a>=1 && a <= 12);
    bool y = (b>=1 && b <= 12);
    string ans;
    if(x&&y) ans = "AMBIGUOUS";
    else if(x) ans = "MMYY";
    else if(y) ans = "YYMM";
    else ans = "NA";
    cout << ans << endl;
    dump(a);
    dumpL(b);
    return 0;
}

Measured memory_bytes: 256