akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int a[2000006];double sum[2000006],sum1[2000006];
int main()
{
    double ant=32487484519;int n;
    scanf("%d",&n);
    sum[0]=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum[i]=sum[i-1]+a[i];
    }
    sum1[n]=a[n];
    for(int i=n-1;i>=1;i--)
    {
        sum1[i]=sum1[i+1]+a[i];
    }
    for(int i=1;i<n;i++)
    {
        if(abs(sum[i]-sum1[i+1])<ant)
        {
            ant=abs(sum[i]-sum1[i+1]);
        }
    }
    printf("%.0lf\n",ant);

}


Measured memory_bytes: 8064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    Int N; cin >> N;
    Int t = 0, x = 0, y = 0;
    rep(i, 0, N) {
        Int nt, nx, ny; cin >> nt >> nx >> ny;
        Int d = abs(x-nx) + abs(y-ny);
        Int dt = nt-t;

        if (d-dt > 0 or (dt-d)%2 != 0) {
            cout << "No" << endl;
            return 0;
        }

        t = nt, x = nx, y = ny;
    }

    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // メインプログラムここから
    string A, B, C; cin >> A >> B >> C;
    cout << "A" << B[0] << "C" << endl;
    // ここまで
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define cs const 
//#define int long long
#define low(i) (i&(-i))
#define mid ((l+r)>>1)
#define ls (now<<1)
#define rs (now<<1|1)
#define par pair<int,int>
#define mp make_pair
#define fr first 
#define se second
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define drep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])
cs int base = 233;
cs int ff = 2e6+1;
cs int mod = 998244353;
cs int inf = 1e9+1;
int n, k, a[ff]; 
int xs(int d) { return min(abs(d), abs(k - d)); }
void init()
{
	cin >> k >> n;
	rep(i, 1, n) scanf("%lld", &a[i]);
	rep(i, 1, n) a[i+n] = a[i] + k;
	int ans = k;
//	rep(i, 1, n+n) cout << a[i] << " ";
	rep(i, 1, n)
		ans = min(ans, abs(a[i+n-1] - a[i])); cout << ans;
}
signed main()
{
	int T = 1;
	while(T--) 
		init();
} 

Measured memory_bytes: 1792
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>

#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807
#define LLMIN       -9223372036854775808
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

int H,W,K;
vector<string> room;

int main(void){
    cin>>H>>W>>K;
    REP(i,H){string s;cin>>s;room.pb(s);}
    queue<tuple<int,int,int> > q;
    REP(i,H)
        REP(j,W)
            if(room[i][j]=='S')
                q.push(mt(i,j,K));
    vector<tuple<int,int> > vt;
    while(!q.empty()){
        auto t=q.front();
        q.pop();
        if(room[get<0>(t)][get<1>(t)]=='%' || room[get<0>(t)][get<1>(t)]=='#')
            continue;
        if(0<get<2>(t)) room[get<0>(t)][get<1>(t)]='%';
        if(0==get<2>(t)) room[get<0>(t)][get<1>(t)]='$';
        if(0<get<2>(t)){
            if(get<0>(t)+1<H) q.push(mt(get<0>(t)+1,get<1>(t),get<2>(t)-1));
            if(get<0>(t)-1>=0) q.push(mt(get<0>(t)-1,get<1>(t),get<2>(t)-1));
            if(get<1>(t)+1<W) q.push(mt(get<0>(t),get<1>(t)+1,get<2>(t)-1));
            if(get<1>(t)-1>=0) q.push(mt(get<0>(t),get<1>(t)-1,get<2>(t)-1));
        }
    }
    int ans=IMAX;
    // REP(i,H)
        // cout<<room[i]<<endl;
    REP(i,H)
        REP(j,W){
            if(room[i][j]=='%' || room[i][j]=='$'){
                int a = min(min(i,j),min(H-i-1,W-j-1));
                a = (a+K-1)/K;
                ans = min(ans,a+1);
            }
            if(room[i][j]=='%' && (i==0 || i==H-1 || j==0 || j==W-1))
                ans=min(ans,1);
        }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main()
{
    string S;
    cin >> S;
    int N = (int)S.length();
    int flag = 0;
    int cnt1 = 0;
    int cnt2 = 0;


    for (int i = 0; i < N; i++){
        if (S[i] != '0' + (flag%2)){
            cnt1++;
        }
        flag++;
    }

    flag = 0;

    for (int i = 0; i < N; i++){
        if (S[i] == '0' + (flag%2)){
            cnt2++;
        }
        flag++;
    }

    cout << min(cnt1,cnt2) << endl;

}


Measured memory_bytes: 512
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;



int main(){
    int N;
    cin >> N;
    
    int L[N];
    for (int i=0;i<N;i++) cin >> L[i];
    
    sort(L,L+N);
    
    int total = 0;
    for (int i=0;i<N-1;i++) total += L[i];
    
    if (total>L[N-1]) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define ll long long
#define vl vector<ll>
#define pl pair<ll,ll>
#define mp make_pair
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) for(ll i=0;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(),(v).end()
using namespace std;
ll n,ans=0,a,maxx=300000;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>a;
        if(maxx > a){
            ans++;
            maxx=a;
        }
    }
    cout<<ans<<endl;
}


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

/// take centroid -> unite separate components
///                                     |
///                                     V
///                         sum of edge * g of subtree

int g[100010];
long long ans;
vector <pair <int, int>> adia[100010];

int find_centr(int nod, int tata, int g_tata);
void find_ans(int nod, int tata);
void calc_g(int nod, int tata);

int main()
{
    int n, a, b, c;
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    cin >> n;

    while (--n) {
        cin >> a >> b >> c;
        adia[a].push_back({ b, c });
        adia[b].push_back({ a, c });
    }

    calc_g(1, 0);
    c = find_centr(1, 0, g[1]);
    calc_g(c, 0);

    find_ans(c, 0);

    int dmin(1e9);
    for (auto i : adia[c]) {
        dmin = min(dmin, i.second);
        if (2 * g[i.first] == g[c]) {
            dmin = i.second;
            break;
        }
    }

    cout << 1ll * ans - dmin;

    return 0;
}

void find_ans(int nod, int tata)
{
    for (auto i : adia[nod]) {
        if (i.first != tata) {
            ans += 2ll * g[i.first] * i.second;
            find_ans(i.first, nod);
        }
    }
}

int find_centr(int nod, int tata, int g_tata)
{
    for (auto i : adia[nod])
        if (i.first != tata && 2 * g[i.first] > g_tata)
            return find_centr(i.first, nod, g_tata);
    return nod;
}

void calc_g(int nod, int tata)
{
    g[nod] = 1;
    for (auto i : adia[nod])
        if (i.first != tata)
            calc_g(i.first, nod), g[nod] += g[i.first];
}


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

int a, b, c, d;

int main() {
    cin >> a >> b >> c >> d;

    if (abs(a - c) <= d || abs(a - b) <= d && abs(b - c) <= d) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    
    return 0;
}


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


int main(){
  int N;
  cin>>N;
  long long a,tmp;
  vector<long long> av;
  long long first,second;
  priority_queue<long long,std::vector<long long>,std::greater<long long>> q_1;
  priority_queue<long long,std::vector<long long>,std::less<long long>> q_2;  
  //k=0-Nで分ける
  long long first_sum[N+1]={};
  long long second_sum[N+1]={};  
  first=0;
  for(int i=0;i<N;++i){
    cin>>a; 
    first+=a;
    q_1.push(a);
  }

  
  first_sum[0]=first;

  
  for(int i=0;i<N;++i){
    cin>>a;
    av.push_back(a);
    q_1.push(a);
    tmp=q_1.top();
    q_1.pop();
    first+=a;
    first-=tmp;
    first_sum[i+1]=first;
  }

  second=0;
  for(int i=0;i<N;++i){
    cin>>a;  
    second+=a;
    q_2.push(a);
  }


  second_sum[N]=second;

  
  for(int i=0;i<N;++i){
    a=av[N-1-i];
    q_2.push(a);
    tmp=q_2.top();
    q_2.pop();
    second+=a;
    second-=tmp;
    second_sum[N-1-i]=second;
  }

  long long ans=-1000000000000000;

  for(int i=0;i<=N;++i){
    ans=max(ans,(first_sum[i]-second_sum[i]));
  }

  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 4852
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<pair<int,int>,null_type, less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e4+10, mod=1e9+7;
ll dp[N][100][2]; string s; int d;

ll calc(int i,int sum,int less){
	if( i==(int)s.length() ){
		return (sum==0);
	}
	ll &ans= dp[i][sum][less];
	if(ans!=-1) return ans;
	int mx=(less?9:(s[i]-'0'));
	ans=0;
	for(int j=0;j<=mx;j++){
		ans+=calc(i+1, (sum+j)%d, less|(j!=mx) );
		if(ans>=mod) ans-=mod;
	}
	ans%=mod;
	return ans;
}

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	cin>>s>>d;
	memset(dp,-1,sizeof dp);
	cout<<(calc(0,0,0)-1+mod)%mod;
}

// check for any potential overflow before submitting


Measured memory_bytes: 16896
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, n) for(int i=n; i>=0; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e10
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<lli>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> bool chmax(T &a, T &b){ if(a<b) { a=b; return 1; }}
template<typename T> bool chmin(T &a, T &b){ if(b<a) { a=b; return 1; }}
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


int n, m;
vector<int> g[100];
int visit[100];
int cnt = 0;
int res = 0;

void dfs(int e){
    visit[e] = 1;
    cnt++;

    bool flg = false;
    for(auto gg : g[e]){
        if(visit[gg] == 1) continue;
        dfs(gg);
        flg = true;
    }

    if(!flg){
        if(cnt == n){
            res++;
        }
    }

    visit[e] = 0;
    cnt--;
    return;
}

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

    int a, b;
    cin >> n >> m;
    rep(i, m){
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    dfs(1);

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = [int(input())  for i in range(N)]
count = 0
for i in range(N) :
    if a[i] >= 2:
        count = count + a[i]//2
        a[i] = a[i] % 2
    if i+1<N :
        if a[i]==1 and a[i+1]>0:
            count = count + 1
            a[i+1] = a[i+1]-1
print('%s' % str(count))


Measured memory_bytes: 7072
#include<bits/stdc++.h>
using namespace std;
int A,ans=0;
int main(){
    scanf("%d",&A);
    ans=sqrt(A*2);
    if(A-(1+ans)*ans/2>0){
    	ans++;
    }
    A=(1+ans)*ans/2-A;
    for(int i=1;i<=ans-A;i++){
    	printf(")");
    }
    printf("(");  
    for(int i=1;i<=A;i++){
    	printf(")");
    }
    for(int i=1;i<ans;i++){
    	printf("(");
    }
    printf("\n");
    return 0;
}

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

#define   ll    long long int

const int N = 100005;
ll n, k, r, s, p;
string t;
int ara[N];
ll dp[N][3];

ll point(int a, int b)
{
    if (a == 0 && b == 1)
        return r;
    if (a == 1 && b == 2)
        return s;
    if (a == 2 && b == 0)
        return p;
    return 0;
}

ll solve(int at, int p)
{
    if (at > n)
        return 0;
    if (dp[at][p] != -1)
        return dp[at][p];
    ll res = 0;
    for (int i = 0; i < 3; i++)
    {
        if (i == p) continue;
        res = max(res, point(i, ara[at]) + solve(at + k, i));
    }
    dp[at][p] = res;
    return res;
}


int main( )
{
    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;
    ll i, j, l;
    for (i = 0; i < n; i++)
    {
        if (t[i] == 'r')
            ara[i + 1] = 0;
        else if (t[i] == 's')
            ara[i + 1] = 1;
        else
            ara[i + 1] = 2;
    }
    ll s = 0;
    memset(dp, -1, sizeof dp);
    for (i = 1; i <= k; i++)
        s += max(solve(i, 2), max(solve(i, 0), solve(i, 1)));
    cout << s << '\n';
    return 0;
}


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

using namespace std;

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

    int ans,i = 0;
    ans = 0;

    while(i < s.length()){
        if(s[i] == 'S'){
            i++;
        }
        int counts = 0;
        while(i < s.length() && s[i] == 'R'){
            counts++;
            i++;
        }
        ans = max(ans,counts);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
 int main() {
     int a,b,c,d;
     cin>>a>>b>>c>>d;
     if(a+b>c+d) cout<<"Left"<<endl;
     else if(a+b==c+d) cout<<"Balanced"<<endl;
     else cout<<"Right"<<endl;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll x;
    cin >> x;
    for(ll i = -1000;i <= 1000;i++){
        for(ll j = -1000;j <= 1000;j++){
            if(i*i*i*i*i - j*j*j*j*j == x){
                printf("%lld %lld\n",i,j);
                return 0;
            }
        }    
    }
    return 0;
}

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

int main() {
    int N, K; cin >> N >> K;
    int r = min(N, K);
    vector<int> V(N);
    for (int i = 0; i < N; i++) {
        cin >> V[i];
        V[i] *= -1;
    }

    int out = 0;
    for (int i = 0; i <= r; i++) {
        vector<int> W;
        for (int j = 0; j < i; j++) {
            W.push_back(V[j]);
        }
        for (int j = 0; j <= r - i; j++) {
            vector<int> X = W;
            for (int k = 0; k < j; k++) X.push_back(V[N - 1 - k]);
            sort(X.begin(), X.end());

            for (int k = 0; k < K - i - j; k++) {
                if (X.empty() || X[X.size() - 1] <= 0) break;
                X.pop_back();
            }

            out = max(out, -accumulate(X.begin(), X.end(), 0));
        }
    }

    cout << out << endl;

    return 0;
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n; cin >> n;
    if(n >= 1000){
        cout << "ABD" << endl;
    }else{
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 3576
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
ans1 = 0
ans2 = 0
for i in range(1, N + 1):
  if i in A:
    if i < X:
      ans1 += 1
    else:
      ans2 += 1
print(min(ans1, ans2))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    string s;
    cin>>s;
    int i;
    for (i=0;i<s.size();i++)
    {
        if (i==5 || i==13)
            cout<<" ";
        else
            cout<<s[i];
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int n, m;
  cin >> n >> m;
  cout << (n-1) * (m-1) << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python

N = int(input())

for i in range(1000):
    n = N + i
    nums = []
    while n != 0:
        nums.append(n % 10)
        n //= 10

    f = True
    if all([n == nums[0] for n in nums]):
        print(N + i)
        break


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

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

    vector<int> nums(n);
    rep(i, n) cin >> nums[i];
    sort(all(nums));
    reverse(all(nums));

    int scores[2] = {0};
    rep(i, n) scores[i % 2] += nums[i];

    cout << scores[0] - scores[1] << endl;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Control.Monad.State

main :: IO ()
main = do
  lines <$> getContents >>= solve

solve :: [String] -> IO ()
solve xs = runStateT (mapM_ calc xs) ("?",0) >> return ()

calc :: String -> StateT (String,Int) IO ()
calc x
  | x == "+" = modify (\(s,y) -> ("+",y))
  | x == "-" = modify (\(s,y) -> ("-",y))
  | x == "*" = modify (\(s,y) -> ("*",y))
  | x == "/" = modify (\(s,y) -> ("/",y))
  | x == "=" = do
      (_,y) <- get
      liftIO $ print y
      put ("?",0)
  | otherwise = do
      (s,y) <- get
      case s of
       "+" -> put ("?", y + toInt x)
       "-" -> put ("?", y - toInt x)
       "*" -> put ("?", y * toInt x)
       "/" -> put ("?", y `div` (toInt x))
       _ -> put ("?", toInt x)

toInt :: String -> Int
toInt = read

Measured memory_bytes: 4208
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <stack>


using namespace std;
typedef long long LL;
const int MaxN = 1e6 + 5;
const int Mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const double esp = 1e-6;

int a[MaxN];
int sum,n,k;

int main(){
    cin >> n >> k;
    for(int i = 1; i <= k; i++){
        scanf("%d",&a[i]);
        sum += a[i];
    }
    if(sum <= n)cout << (n-sum) << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3696
MOD = 1_000_000_007

nn = gets.chomp.to_i

a = []
a = gets.chomp.split.map(&:to_i)

def abs(a,b)
  return a>b ? a-b : b-a
end

sum = a.inject(:+)
b_sum = 0
sa = sum
a.each do |v|
  b_sum += v
  sum -= v
  if sa > abs(b_sum, sum)
    sa = abs(b_sum, sum)
  else
    break
  end
end

p sa

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int nmax=100005;
vector<vector<pair<int,int>>> g(nmax);
vector<ll> d(nmax,INF);
bool f=true;
void dfs(int s){
    d[s]=0;
    stack<int> st;
    st.push(s);
    while(!st.empty()){
        int p=st.top();
        st.pop();
        for(auto x:g[p]){
            if(d[x.first]==INF){
                d[x.first]=d[p]+x.second;
                st.push(x.first);
            }
            else if(d[x.first]==d[p]+x.second){
                continue;
            }
            else{
                f=false;
                return;
            }
        }
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin >> n >> m;
    for(int i=0;i<m;i++){
        int l,r,d;cin >> l >> r >> d;
        l--,r--;
        g[l].push_back({r,d});
        g[r].push_back({l,-d});
    }
    for(int i=0;i<n;i++){
        if(d[i]!=INF){
            continue;
        }
        dfs(i);
        if(!f){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

int main()
{
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    if(b<a)
    {
		
		long long e = a-b;
		cout<<(c*b)+(d*e)<<endl;
	}
	else
	{
		cout<<c*a<<endl;
	}
    
    return 0;
}


Measured memory_bytes: 3536
// AOJ 0154
#include<iostream>
#include<cstring>

int m;
int a[7], b[7];
int dp[8][1001];

int main()
{
	while( std::cin >> m, m )
	{
		memset( dp, 0, sizeof( dp ) );

		for( int i = 0; i != m; ++i )
			std::cin >> a[i] >> b[i];

		dp[0][0] = 1;
		for( int i = 0; i != m; ++i )
			for( int j = 0; j <= 1000; ++j )
				for( int k = 0; k <= b[i]; ++k )
					if( j + k * a[i] <= 1000 )
						dp[i+1][j+k*a[i]] += dp[i][j];

		int g;
		std::cin >> g;
		while( g-- )
		{
			int n;
			std::cin >> n;
			std::cout << dp[m][n] << std::endl;
		}
	}

	return 0;
}

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

int main(){
  string s ;
  cin >> s ;
  string t = "keyence" ;
  rep(i,s.size()){
    rep(j,s.size()){
      string u = s ;
      if( u.erase(i,j) == t ){
        cout << "YES" << endl;
        return 0 ;
      }
    }
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> pii;
struct SegmentTree{
	int size;
	vector<int> dat,lazy;
	SegmentTree(int n){
		size = 1;
		while(size<n) size *= 2;
		dat.assign(2*size-1,0);
		lazy.assign(2*size-1,0);
	}
	void lazy_evaluate(int k,int l,int r){
		if(k<size-1){
			lazy[2*k+1] += lazy[k];
			lazy[2*k+2] += lazy[k];
		}
		dat[k] += lazy[k] * (r - l);
		lazy[k] = 0;
	}
	void update(int a,int b,int x,int k,int l,int r){
		lazy_evaluate(k,l,r);
		if(b<=l||r<=a) return;
		if(a<=l&&r<=b){
			lazy[k] += x;
			return;
		}
		update(a,b,x,2*k+1,l,(l+r)/2);
		update(a,b,x,2*k+2,(l+r)/2,r);
		dat[k] = dat[2*k+1] + dat[2*k+2];
		return;
	}
	int query(int a,int b,int k,int l,int r){
		lazy_evaluate(k,l,r);
		if(b<=l||r<=a) return 0;
		if(a<=l&&r<=b) return dat[k];
		int vl = query(a,b,2*k+1,l,(l+r)/2);
		int vr = query(a,b,2*k+2,(l+r)/2,r);
		return vl + vr;
	}
	void update(int a,int b){
		update(a,b+1,1,0,0,size);
	}
	int query(int i){
		return query(i,i+1,0,0,size);
	}
};

int main(){
	int n,m;
	vector<pii> P;
	scanf("%d%d",&n,&m);
	SegmentTree segtre(m+1);
	for(int i=0;i<n;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		P.push_back(pii(r-l,l));
	}
	sort(P.begin(),P.end());
	int p = 0;
	for(int d=1;d<=m;d++){
		int ans = 0;
		int pos = 0;
		while(p<n&&P[p].first+1<d){
			segtre.update(P[p].second,P[p].first+P[p].second);
			p++;
		}
		while(pos<=m){
			ans += segtre.query(pos);
			pos += d;
		}
		ans += n - p;
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 8304
#include <iostream>
#include <utility>
#include <algorithm>
int main(){
  int n,p,t,a=0,x,y,s[101]={},inf=1001001;
  std::cin>>n;
  std::pair<int,int> r[n],b[n];
  for(int i=0;i!=n;++i){std::cin>>x>>y;r[i]={x,y};}
  for(int i=0;i!=n;++i){std::cin>>x>>y;b[i]={x,y};}
  std::sort(r,r+n,std::greater<std::pair<int,int>>());
  std::sort(b,b+n);
  for(int i=0;i!=n;++i){
    t=inf;
    p=inf;
    for(int j=0;j!=n;++j){
      if(s[j]==0&&b[j].first>r[i].first){
        if(b[j].second<t&&b[j].second>r[i].second){
          t=b[j].second;
          p=j;
        }
      }
    }
    if(p<inf){
      ++s[p];
      ++a;
    }
  }
  std::cout<<a<<"\n";
}
  
  

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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; }



void func(long long n, std::vector<long long> a){

    lli sum = 0;
    lli cnt = 0;
    lli ans = INF;
    REP(i,0,n){
        sum+=a[i];
        LOG3(cnt,sum,a[i]);
        if(i%2==0){
            if(sum<=0){
                cnt += abs(sum) + 1;
                sum = 1;
            }
        }
        else{
            if(sum>=0){
                cnt += abs(sum) + 1;
                sum = -1;
            }
        }
    }
    chmin(ans,cnt);

    sum = 0;
    cnt = 0;
    REP(i,0,n){
        sum+=a[i];
        LOG3(cnt,sum,a[i]);
        if(i%2==0){
            if(sum>=0){
                cnt += abs(sum) + 1;
                sum = -1;
            }
        }
        else{
            if(sum<=0){
                cnt += abs(sum) + 1;
                sum = 1;
            }
        }
    }

    chmin(ans,cnt);
    cout<<ans<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long n;
    scanf("%lld",&n);
    std::vector<long long> a(n);
    for(int i = 0 ; i < n ; i++){
        scanf("%lld",&a[i]);
    }
    func(n, std::move(a));
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=max(x,a)
#define chmin(x,a) x=min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<int> >;//ll or Edge
using Edge=pair<int,ll>;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse...greater<ll>()
// g++ -o a a.cpp -Wall -lm -std=c++17

int main(){
    string S;cin>>S;
    int k;cin>>k;
    set<string> list;
    rep(i,5){
        for(int j=0;j<(int)S.length()-i;j++){
            list.insert(S.substr(j,i+1));
        }
    }
    int i=0;
    for(auto v:list){
        if(i==k-1)cout<<v<<endl;
        i++;
    }
}

Measured memory_bytes: 4792
#include <stdio.h>

int main(void){

int a,b,c;
int tmp;

scanf("%d %d %d", &a,&b,&c);

if(a > b){
tmp = a;
a = b;
b = tmp;
}

if(b > c){
tmp = b;
b = c;
c = tmp;

if(a > b){
tmp = b;
b = a;
a = tmp;
}
}

printf("%d %d %d\n", a,b,c);

return 0;
}

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

int main()
{
  int w, h, n, ct = 0, nx, ny, x, y;

  cin >> w >> h >> n;
  cin >> nx >> ny;
  for (int i = 1; i < n; i++){
    cin >> x >> y;
    int z = min(abs(nx - x), abs(ny - y));
    if (nx - x > 0) z *= -1;
    if (nx < x && ny < y || x < nx && y < ny){
      ct += abs(z);
      nx += z;
      ny += z;
    }
    ct += abs(nx - x) + abs(ny - y);
    nx = x;
    ny = y;
  }

  cout << ct << '\n';
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N - 1);

  for (int i = 0; i < N - 1; i++) {
    cin >> B.at(i);
  }

  A.at(0) = B.at(0);
  for (int i = 1; i < N - 1; i++) {
    A.at(i) = min(B.at(i - 1), B.at(i));
  }
  A.at(N - 1) = max(B.at(N - 2), A.at(N - 2));

  int result = 0;
  rep(i, N) {
    result += A.at(i);
  }
  cout << result << endl;
}

Measured memory_bytes: 256
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################

def solve():
    n = inp()
    print(n + n ** 2 + n ** 3)
            
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1],1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97],1
    return(q)

def factors(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i); q.append(n // i)
    return(list(sorted(list(set(q)))))

def prime_factors(n):
    q = []
    while n % 2 == 0: q.append(2); n = n // 2
    for i in range(3,int(n ** 0.5) + 1,2):
        while n % i == 0: q.append(i); n = n // i
    if n > 2: q.append(n)
    return(list(sorted(q)))

#-----------------------------------------------------------------------#
        
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
main()

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

long long K;
long long A, B;

int main(){
	cin >> K >> A >> B;
	for(long long i = A; i <= B; i++) {
		if(i%K == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
}

Measured memory_bytes: 3560
#!/usr/bin/env python3

def main():
    antenas = [int(input()) for i in range(5)]
    k = int(input())

    for antena in antenas:
        for antena2 in antenas:
            if (antena - antena2)>k:
                print(':(')
                return

    print('Yay!')


if __name__ == "__main__":
    main()


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

long long gcd(long long a, long long b) {
    while (a % b > 0) {
        long long c = a;
        a = b;
        b = c % b;
    }
    return b;
}

int solve(long long gcd) {
    int ans = 1;
    long long n = gcd;
    for (long long i = 2; i*i <= n; ++i) {
        if (gcd % i == 0) {
            ++ans;
            while (gcd % i == 0) gcd /= i;
        }
    }
    if (gcd > 1) ++ans;
    return ans;
}
int main() {
    long long a, b;
    cin >> a >> b;
    long long g = gcd(a, b);
    int ans = solve(g);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int A[2000000];
int i,p=1,r,j,x,n,t=0;
int pqrtition();

int main (void){
  
  scanf("%d",&r);
  for(i=1;i<=r;i++){
    scanf("%d",&A[i]);
  }
  partition();

  for(i=1;i<=t;i++){
    printf("%d ",A[i]);
  }
  printf("[%d] ",A[i]);
  for(i=t+2;i<=r;i++){
    printf("%d",A[i]);
    if(i!=r)printf(" ");
  }
  printf("\n");

  return 0;
}

int partition(){
  x=A[r];
  i=p-1;
  if(i>r)return -1;
  for(j=p;j<=r-1;j++){
    if(A[j]<=x){
      i=i+1;
      n=A[i];
      A[i]=A[j];
      A[j]=n;
      t++;
    }
  }
  n=A[i+1];
  A[i+1]=A[r];
  A[r]=n;
  p++;
  return i++;
}

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

//AtCoder ABC 77

using namespace std;

#define int long long
#define all(m) m.begin(),m.end()
#define all_mas(m) for(auto &i: m) cout << i  << " ";\
cout << endl;
#define fast ios::sync_with_stdio(0), cin.tie(), cout.tie()

signed main() {
    int n;
    cin >> n;
    int a = sqrt(n);
    int ans = a*a;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a) & -(a))
#define clean(a, b) memset(a, b, sizeof(a))
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 2e6 + 9;

int _;

//========================================================================
int c[maxn],a[maxn],last[maxn],pre[maxn],n,ans[maxn];
struct node
{
    int l,r,num;
}x[maxn];
int cmp(node a,node b)
{
    if(a.r==b.r) return a.l<b.l;
    return a.r<b.r;
}
void update(int x,ll y,int n)///One point update
{
    for(int i=x; i<=n; i+=lowbit(i))
        c[i] += y;
}
ll get_sum(int x)///Interval query
{
    ll ans = 0;
    for(int i=x; i; i-=lowbit(i))
        ans += c[i];
    return ans;
}
//========================================================================
int main()
{
    int q;
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(last[a[i]])
        {
            pre[i]=last[a[i]];
            last[a[i]]=i;
        }
        else 
        {
            pre[i]=maxn+1;
            last[a[i]]=i;
        }
    }
    for(int i=1;i<=q;i++)
    {
        scanf("%d%d",&x[i].l,&x[i].r);
        x[i].num=i;
    }
    sort(x+1,x+1+q,cmp);
    int j=1;
    for(int i=1;i<=q;i++)
    {
        for(;j<=x[i].r;j++)
        {
            update(pre[j],-1,n);
            update(j,1,n);
        }
        ans[x[i].num]=get_sum(x[i].r)-get_sum(x[i].l-1);
    }
    for(int i=1;i<=q;i++) printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 19396
import java.util.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    static int dx[]={-1,0,1,0};
    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}


        
//        long L=sc.nextLong();
        int n=sc.nextInt();	
        int k=sc.nextInt();	
        int h[]=new int[n];
        int dp[]=new int[n];
        
        for (int i = 0; i < n; i++) {
        	h[i] = sc.nextInt();
        	dp[i]=Integer.MAX_VALUE;
		}
        
        dp[0]=0;
        
        
        for (int i = 1; i < dp.length; i++) {
        	for (int t = 1; -1 < i-t && t<=k; t++) {
    			dp[i]=min(dp[i-t]+abs(h[i]-h[i-t]), dp[i]);
				
			}
		}


        out.println(dp[n-1]);
        out.flush();
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

class P {
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
}

//class P implements Comparable<P>{
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//    public int compareTo(P p){
//        return d-p.d; //des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


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

using namespace std;

typedef long long ll;
typedef string sr;
typedef pair<int, int> pii;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    sr s;
    cin >> s;
    int q;
    cin >> q;
    int total_reverse = 0;
    for (int i = 1; i <= q; ++i) {
        int t;
        cin >> t;
        if (t == 1) {
            total_reverse += t;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if (total_reverse % 2) f = (f == 1) ? 2 : 1;
            if (f == 1) s.insert(s.begin(), c);
            else s += c;
        }
    }
    if (total_reverse % 2){
        reverse(s.begin(), s.end());
    }
    cout << s << "\n";
    return 0;
}

Measured memory_bytes: 912
#include <bits/stdc++.h> 
using namespace std;
long long a,b,ans,cnt;
int main(){
	cin>>a>>b;
	ans=max(a,b);
	if(a-b==0){
		cnt+=a;
		cnt+=b;}
		else{
			cnt+=ans;
			cnt+=ans-1;}
			cout<<cnt;
}

Measured memory_bytes: 384
class abc_166:
    
    def __init__(self):
        pass
    
    def A(self):
        S=input()
        ans= "ARC" if S=="ABC" else "ABC"
        print(ans)
    
    def B(self):
        NK=list(map(int,input().split()))
        d=[]
        A=[]
        
        for i in range(NK[1]):
            d=int(input())
            a = list(map(int,input().split()))
            A.extend(a)
        
        print(NK[0]-len(list(set(A))))  
            
    def C(self):
        NM=list(map(int,input().split()))
        H=list(map(int,input().split()))
        A=[list(map(int,input().split())) for i in range(NM[1])]
        memo=[0]*(NM[0])
        count=0
        
        for i in range(len(memo)):memo[i]=H[i]
        
        #メモ化処理
        for i in A:
            if H[i[0]-1]>H[i[1]-1]:
                memo[i[1]-1]=H[i[0]-1]
            elif H[i[0]-1]==H[i[1]-1]:
                memo[i[0]-1]=0
                memo[i[1]-1]=0
            else:
                memo[i[0]-1]=H[i[1]-1]
                
        
        for i in range(NM[0]):
            if H[i]==memo[i]:count+=1
            else:pass
        
        print(count)
    
    
    def D(self):
        pass
    
    def E(self):
        pass
    
    def F(self):
        pass
    
    
if __name__=='__main__':
    obj=abc_166()
    obj.C()

Measured memory_bytes: 93740
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            int iM = int.Parse(sS[1]);
            List<string> lstN = new List<string>();
            List<string> lstM = new List<string>();
            for (int i = 0; i < iN; i++) { lstN.Add(Console.ReadLine().Trim()); }
            for (int i = 0; i < iM; i++) { lstM.Add(Console.ReadLine().Trim()); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "No";
            for (int i = 0; i <= lstN.Count - lstM.Count; i++)
            {
                int iNx = 0;                                        // 検索開始位置
                while (true)
                {
                    if (iNx > iN - iM) { break; }                   // Nのこの行の末尾まで検索したら Nの次行目
                    int iFx = lstN[i].IndexOf(lstM[0], iNx);        // Nのこの行中にMの1行目存在？
                    Boolean bOK = false;
                    if (iFx >= 0)                                    // Nのこの行中にMの1行目存在の場合
                    {
                        bOK = true;
                        for (int j = 1; j < lstM.Count; j++)        // 残りのMが存在するか確認
                        {
                            if (lstN[i + j].Substring(iFx, iM) != lstM[j]) { bOK = false; break; }  // 次行目以降は比較文字列位置特定可能 合致しない為、またMの1行目からやりなおし
                        }
                        iNx = iFx + 1;
                    }
                    else
                    {
                        break;                                      // Nのこの行にMの1行目は存在しない為、Nの次行目
                    }
                    if (bOK) { sOut = "Yes"; break; }
                }
                if (sOut == "Yes") {  break; }
            }

            //出力
            Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


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

int main() {
int n;
cin>>n;
int AC=0,WA=0,TLE=0,RE=0;
while(n--){
	string s;
	cin>>s;
	if(s=="AC")AC++;
	else if(s=="WA")WA++;
	else if(s=="TLE")TLE++;
	else
	RE++;
}cout<<"AC x "<<AC<<endl;
cout<<"WA x "<<WA<<endl;
cout<<"TLE x "<<TLE<<endl;
cout<<"RE x "<<RE<<endl;

	return 0;
}

Measured memory_bytes: 3612
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n,m,x = gets.chomp.split.map(&:to_i)
a = []
n.times do
  a.push gets.chomp.split.map(&:to_i)
end

d = n
ans = INF
(2**d).times do |i|
  bits = i.to_s(2).split(//)
  (d - bits.length).times{bits.unshift('0')}
  skill = Array.new(m, 0)
  cost = 0
  a.zip(bits).each do |line, bit|
    next if bit == '0'
    cost += line.first
    m.times do |i|
      skill[i] += line[i+1]
    end
  end

  if skill.all?{|s| s >= x}
    ans = [ans, cost].min
  end
end

if ans == INF
  puts -1
else
  puts ans
end


Measured memory_bytes: 14744
from collections import Counter
N, C = list(map(int, input().split()))
D = [list(map(int, input().split())) for _ in range(C)]
c = [list(map(int, input().split())) for _ in range(N)]
'''
D0 = {}
D1 = {}
D2 = {}
for color in range(1, C + 1):
    D0[color] = 0
    D1[color] = 0
    D2[color] = 0
    
for color in range(1, C + 1):
    for i in range(N):
        for j in range(N):
            if (i + j) % 3 == 0:
                D0[color] = D0[color] + D[ c[i][j] - 1 ][ color - 1 ] 
            if (i + j) % 3 == 1:
                D1[color] = D1[color] + D[ c[i][j] - 1 ][ color - 1 ] 
            if (i + j) % 3 == 2:
                D2[color] = D2[color] + D[ c[i][j] - 1 ][ color - 1 ] 

ans = 1000000000000000
for i in range(1, C + 1):
    for j in range(1, C + 1):
        for k in range(1, C + 1):
            if i != j and j != k and k != i:
                tmp = D0[i] + D1[j] + D2[k]
                if tmp < ans:
                    ans = tmp
print(ans)
'''
diclist = [Counter() for _ in range(3)]
for i in range(N):
    for j in range(N):
        diclist[(i+j)%3][c[i][j]] += 1

ans = 100000000000000
for i in range(C):
    for j in range(C):
        for k in range(C):
            tmp = 0
            if i != j and j != k and k != i:
                for l, v in diclist[0].items():
                    tmp += D[l - 1][i] * v
                for l, v in diclist[1].items():
                    tmp += D[l - 1][j] * v
                for l, v in diclist[2].items():
                    tmp += D[l - 1][k] * v
                if tmp < ans:
                    ans = tmp
print(ans)


Measured memory_bytes: 5868