akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef struct{//辺
    int a;//始点終点
    int b;
    int color;//色
}Edge;
typedef struct{//節点
    int num;
    int color;
}Node;
int main(void){
    Edge e[1000000];
    int N; cin >> N;
    vector <vector<int> > map(N+1);//節点に接続している辺
    for(int i=1;i<N;i++){
        cin >> e[i].a >> e[i].b;
        map[e[i].a].push_back(i);
        map[e[i].b].push_back(i);
    }
    e[1].color = 1;
    queue<Node> q;//節点番号と初期色
    q.push((Node){e[1].a,1}), q.push((Node){e[1].b,1});
    int K = 0;
    while(!q.empty()){
        int x = q.front().num; int c = q.front().color; q.pop();
        if(K<map[x].size()) K = map[x].size();
        int clr = 1;
        for(int i=0;i<map[x].size();i++){
            if(e[map[x][i]].color == 0){//未到達なら
                if(c==clr) clr++;//初期色と同値
                e[map[x][i]].color = clr++;
                if(e[map[x][i]].a == x)//今来た節点の反対
                    q.push((Node){e[map[x][i]].b,clr-1});
                else
                    q.push((Node){e[map[x][i]].a,clr-1});
            }
        }
    }
    cout << K << endl;
    for(int i=1;i<N;i++) cout << e[i].color << endl;
    
}


Measured memory_bytes: 9216
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int main() {
  int N,K;
  cin >> N >> K;
  vint a(N);
  repeat(i,N){
    cin >> a[i];
  }
  sort(a.begin(),a.end());

  int low=-1,high=N;
  while(high-low>1){
    cerr << low << " " << high<<endl;
    int mid = (high+low)/2;
    vector<vector<bool> > dp(N+2,vector<bool>(K+1,false));
    dp[0][0] = true;
    repeat(i,N){
      int ni=i+1;

      repeat(j,K+1){
        if(dp[i][j] || (i != mid && a[i]<=j && dp[i][j-a[i]]))
          dp[ni][j] = true;
      }
    }

    bool needed=false;
    for(int j=max(0,K-a[mid]);j<K;j++){
      needed |= dp[N][j];
    }
    if(needed){
      high = mid;
    }else{
      low = mid;
    }
  }
  cout << high << endl;

  return 0;
}


Measured memory_bytes: 3636
#include<cstdio>

#define t(a) ((a == 'S') ? (0) : (1))

using namespace std;

int N;
char S[100001];
char ans[100001];
char sw[3] = "SW";
bool f1 = true;

char dp(short int b, short int t, char r)
{

  if((b+t)%2 == 0){
    if(r == 'o'){
      return 'S';
    }else{
      return 'W';
    }
  }else{
    if(r == 'o'){
      return 'W';
    }else{
      return 'S';
    }
  }
  return '\0';

}

int main(){

  scanf("%d", &N);
  scanf("%s", S);

  for(int l = 0; l < 4 && f1; l++){
    ans[0] = sw[l/2];
    ans[1] = sw[l%2];
    for(int m = 1; m < N && f1; m++){
      if(m < N-1 ){
        ans[m+1] = dp(t(ans[m-1]), t(ans[m]), S[m]);
      }else if(ans[0] == dp(t(ans[N-2]), t(ans[N-1]), S[N-1])){
        if(ans[1] == dp(t(ans[N-1]), t(ans[0]), S[0])){
          f1 = false;
        }
      }
    }
  }

  if(f1)
  {
    printf("-1");
  }
  else
  {
    ans[N] = '\0';
    printf("%s", ans);

  }
  return 0;
}


Measured memory_bytes: 512
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
cnt = 0
s = set()
for i in range(1, N+1):
    cnt += i
    s.add(i)
    if cnt>=N:
        break
if N!=cnt:
    s.remove(cnt-N)

for i in s:
    print(i)

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;
const ll MOD = 1000000007;

// a^n % mod を計算する O(log n)
ll powmod(ll a, ll n, ll mod) {
  ll ret = 1;
  while (n > 0) {
    if (n % 2 == 1) { ret = ret * a % mod; }
    a = a * a % mod;
    n /= 2;
  }
  return ret;
}

void solve()
{
  int n;
  cin >> n;

  cout << ((powmod(10, n, MOD) - powmod(9, n, MOD) * 2 + MOD * 2) % MOD + powmod(8, n, MOD)) % MOD;
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

public class Main {
        public static void main(String[] args) {
                Scanner scan = new Scanner(System.in);

                int N = scan.nextInt();
                long K = scan.nextLong();

                int[] town_to = new int[N];

                for (int i = 0; i < N; i++) {
                        town_to[i] = scan.nextInt();
                }

                int[] flag = new int[N];

                int now_town = 1;

                long k = K;

                for (int j = 0; j < K; j++) {
                        flag[now_town-1] = 1;
                        now_town = town_to[now_town-1];
                        k--;
                        if (flag[now_town-1] == 1) {
                                break;
                        }
                }

                long count = 0;

                if (k != 0) {
                        while (true) {
                                flag[now_town-1] = 0;
                                now_town = town_to[now_town-1];
                                count++;
                                k--;
                                if (k == 0) {
                                        break;
                                }
                                if (flag[now_town-1] == 0) {
                                break;
                                }
                        }
                }

                if (k == 0) {
                        System.out.println(now_town);
                } else {
                        long nokori = k%count;
                        if (nokori == 0) {
                                System.out.println(now_town);
                        } else {
                                for (long index = 1; index <= nokori; index++) {
                                        now_town = town_to[now_town-1];
                                }
                                System.out.println(now_town);
                        }
                }
        }
}

Measured memory_bytes: 60092
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define yes {cout << "Yes"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

const int N = 3e5 + 7, MOD = 1e9 + 7;

int calc[60], a[N], deg[60] = { 1 };

void solve() {
    loop1(i, 59)
        deg[i] = deg[i - 1] * 2 % MOD;
    int n; cin >> n;
    loop(i, n) {
        cin >> a[i];
        loop(bit, 60)
            calc[bit] += bool(a[i] & (1ll << bit));
    }
    int ans = 0;
    loop(i, n)
        loop(bit, 60) {
            calc[bit] -= bool(a[i] & (1ll << bit));
            ans = (ans + (a[i] & (1ll << bit) ? n - i - 1 - calc[bit] : calc[bit]) * deg[bit]) % MOD;
        }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 5920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

int main() {
    int X, Y, Z;  cin >> X >> Y >> Z;

    int X_ = X - Z;
    print((int)(X_/(Y+Z)));
}




Measured memory_bytes: 256
// Last Change: 07/20/2019 21:03:02.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll N, D;
  cin >> N >> D;
  D = D * 2 + 1;
  ll ans = N / D;
  if (N % D != 0) {
    ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2*1e5 + 1)
#define F first
#define S second
#define endl "\n"
#define MOD (lli)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
#define DEBUG if(0) cout << "aqui" << endl;
#define PI 2 * acos(0.0)
typedef pair<int,int> ii;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

int n, k;
vector<int> vec(MAXN);

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

  cin >> n >> k;
  for(int i=1;i<=n;i++){
    int a;
    cin >> vec[i];
    
    vec[i] += (vec[i-1] - 1);
    vec[i] %= k;
  }

  // for(int i=1;i<=n;i++) cout << vec[i] << " ";
  // cout << endl;

  map<int, int> cnt;
  lli ans = 0;
  for(int i=1;i<=n;i++){
    if(i - k >= 0) cnt[vec[i-k]]--;
    cnt[vec[i-1]]++;
    ans += cnt[vec[i]];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 10496
S = input()

S1 = int(S[:2])
S2 = int(S[2:])

if 0 < S1 <= 12 and 0 < S2 <= 12:
    print('AMBIGUOUS')
elif 0 < S1 <= 12:
    print('MMYY')
elif 0 < S2 <= 12:
    print('YYMM')
else:
    print('NA')


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

int main(){
  int k, s, x, y, atta = 0;
  cin >> k >> s;

  for( int i=0; i<k+1; i++ ){
    for( int j=0; j<k+1; j++ ){
      if( 0 <= s-i-j && s-i-j <= k ){
        atta++;
      }
    }
  }
  cout << atta << endl;
  return 0;
}


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

int const M = 1e9 + 7;
vector<int> memo(5500000, -1);
string K; int D;

int count(size_t i, int total, bool upto) {
	if (i == K.size()) return total == 0;

	// 14 bits for index, 7 bits for total, 1 bit for upto
	int key = (i << 9) + (total << 1) + upto;
	if (memo[key] >= 0) return memo[key];

	int sum = 0, leading = K[i] - '0';
	for (int digit = 0; digit <= (upto ? leading : 9); ++digit) {
		if (digit == leading)
			sum += count(i+1, (total+digit) % D, upto);
		else
			sum += count(i+1, (total+digit) % D, false);
		sum %= M;
	}

	return memo[key] = sum;
}

int main() {
	ios_base::sync_with_stdio(false);

	getline(cin, K);
	cin >> D;

	int answer = count(0, 0, true) - 1;
	if (answer < 0) answer += M;
	cout << answer << endl;
}


Measured memory_bytes: 25676
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;

ll N;
ll L[110];


int main(void){

    cin >> N;
    for (int i = 1; i <= N;i++) cin >> L[i];

    ll ans = 0;

    if (N > 2) {
        for (int i = 1; i <= N;i++) {
            int P = i;
            for (int j = P + 1; j <= N;j++){
                int Q = j;
                for (int k = Q + 1; k <= N;k++){
                    if (L[i] != L[j] && L[j] != L[k] && L[i] != L[k]){
                        ll IJ = L[i] + L[j];
                        ll JK = L[j] + L[k];
                        ll IK = L[i] + L[k];
//                        cout << L[i] << "," << L[j] << "," << L[k] <<endl;
                        if (L[i] >= L[j] && L[i] >= L[k]){
                            if (JK > L[i]) {
                                ans++;
//                                cout << "ok" << endl;
                            }
                        } else if (L[j] >= L[i] && L[j] >= L[k]){
                            if (IK > L[j]) {
                                ans++;
//                                cout << "ok" << endl;
                            }
                        } else {
                            if (IJ > L[k]) {
                                ans++;
//                                cout << "ok" << endl;
                            }
                        }
                    }
                }
            }
        }







    }

    cout << ans << endl;

    return 0;
}


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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

int main()
{
    // Fast_IO();
    ll a, b; cin >> a >> b;
    a *= b;
    cout << a;
    return 0;
}

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

using int64 = long long;

struct UnionFind {
	vector< int > data;

	UnionFind(int sz) {
		data.assign(sz, -1);
	}

	bool unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return (false);
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return (true);
	}

	int find(int k) {
		if (data[k] < 0) return (k);
		return (data[k] = find(data[k]));
	}

	int size(int k) {
		return (-data[find(k)]);
	}
};

#define int long long

signed main() {
	int N, M, A[100000], B[100000];
	cin >> N >> M;
	UnionFind uf(N);

	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
		--A[i], --B[i];
	}
	int ret = 0;

	vector< int > ans(M);
	for (int i = M - 1; i >= 0; i--) {
		ans[i] = 1LL * N * (N - 1) / 2 - ret;
		if (uf.find(A[i]) != uf.find(B[i])) {
			ret += 1LL * uf.size(A[i]) * uf.size(B[i]);
			uf.unite(A[i], B[i]);
		}
	}
	for (auto &p : ans) cout << p << endl;
}


Measured memory_bytes: 4096
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
ll n;
vector<pair<ll,ll>> a;
ll memo[2020][2020];
ll rec(ll l, ll r){
    if(l > r) return 0;
    if(memo[l][r] != -1) return memo[l][r];
    ll idx = l + n - 1 - r;
    ll res = 0;
    res = max(res, rec(l + 1, r) + abs(a[idx].second - l) * a[idx].first);
    res = max(res, rec(l, r - 1) + abs(a[idx].second - r) * a[idx].first);

    return memo[l][r] = res;
}
int main(void){
    cin >> n;
    a.resize(n);
    rep(i, n) {
        ll tmp;
        cin >> tmp;
        a[i] = {tmp, i};
    }

    sort(all(a), greater<pair<ll,ll>>());

    rep(i, 2020){
        rep(j, 2020){
            memo[i][j] = -1;
        }
    }

    cout << rec(0, n - 1) << endl;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  int res = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (i and a[i - 1] < a[i]) {
      ++res;
    }
  }
  cout << res << '\n';
}



Measured memory_bytes: 3356
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <ctime>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
#ifdef __linux
#define LLD "%lld"
#else
#define LLD "%I64d"
#endif

#define NMAX 100000

struct p{
	int x,y,t;
};

int n;
p ps[NMAX+1000];

inline int dis(int x1,int y1,int x2,int y2){
	return abs(x2-x1)+abs(y2-y1);
}

inline bool check(){
	int i;

	p last=(p){0,0,0};
	for(i=0;i<n;i++){
		int dd=dis(last.x,last.y,ps[i].x,ps[i].y);
		int dt=ps[i].t-last.t;
		if(dt<dd)return false;
		int lt=dt-dd;
		if(lt%2)return false;
		last=ps[i];
	}
	return true;
}


int main(){
	int i;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d%d",&ps[i].t,&ps[i].x,&ps[i].y);
	}

	if(check())printf("Yes\n");
	else printf("No\n");
	return 0;
}



Measured memory_bytes: 1280
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define inf 1e9
#define INF 1000000000000000000

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    X--, Y--;
    vector<vector<int>> G;
    G.assign(N, vector<int>());
    G[X].push_back(Y);
    G[Y].push_back(X);
    for (int i = 0; i < N - 1; i++) {
        G[i].push_back(i + 1);
        G[i + 1].push_back(i);
    }

    map<int, int> ma;
    rep(i, N) {
        vector<int> d(N, -1);
        d[i] = 0;
        queue<int> q;
        q.push(i);
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (auto nv : G[v]) {
                if (d[nv] != -1)
                    continue;
                d[nv] = d[v] + 1;
                ma[d[nv]]++;
                q.push(nv);
            }
        }
    }

    for (int i = 1; i < N; i++) {
        cout << ma[i] / 2 << endl;
    }
}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
using namespace std;
int main(void)
{
    int a,b,c,d,a1,a2;
    cin >> a >> b >> c >> d;
    if(a >= b){a1 = b;}else{a1=a;}
    if(c >= d){a2 = d;}else{a2=c;}
    cout << a1+a2;
    return 0;
}

Measured memory_bytes: 256
import collections
def main():

    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort(reverse = True)
    q.sort(reverse = True)
    r.sort(reverse = True)

    p = p[:X]
    q = q[:Y]
    pqr = p + q + r
    pqr.sort(reverse = True)
    return sum(pqr[:X+Y])




if __name__ == '__main__':
    # main()
    print(main())


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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.1415926535
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

int main()
{
	string s,t;
	cin>>s>>t;
	int ans=0;
	ffor(i,0,sz(s)) if(s[i]==t[i]) ans++;
	cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int, int>
#define ld long double
const int mod = 1e9 + 7;
 
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
 
 
 
 
 int bin(multiset<int>&s)
 {

	 
	 int l=0,r=s.size()-1,mid,ans=1;
	 while(l<=r)
	 {
		 mid=(l+r)/2;
		 auto k =s.begin();
	   	advance(k,mid);
		 if(*k>=s.size()-mid)
		 { 
			 ans=s.size()-mid; r=mid-1;
		 }
		 else l=mid+1;
	 }
	 return ans;
 }
 
 
 
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
 

 

int n,k;
cin>>n>>k;
vector<int>v(n+1);

for(int i=1;i<=n;i++)cin>>v[i];

vector<int>dp(100006,1e18);
dp[1]=0;

for(int i=2;i<=n;i++)
{
	for(int j=1;j<=k;j++)
	{
		if(i-j>=1)
		{
			
			dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j])); 
		}
	}
	
}

cout<<dp[n];
 
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,arr[]= {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin>>k;
    cout<<arr[k-1]<<endl;
    return 0;
}


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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i ,a, b) for (int i = a ; i <= b ; i++)
#define sz(a) int(a.size())
#define cuti(a) cout << a << endl;
#define cutii(a,b) cout << a << " " << b << endl;
#define cutiii(a,b,c) cout << a << " " << b << " " << c << endl;
#define vec(a) vector<int > a;

template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }

typedef long long LL;
typedef pair<int ,int > pii;
typedef pair<string ,int > psi;
typedef pair<string ,string > pss;
typedef pair<LL, LL> pLL;

const long long oo = 1e9 + 7;

string s;

int main(){
 //   freopen("test.txt","r",stdin);
    cin >> s;
    for (int i = 0 ; i < s.size() - 1; i++) {
        if ( s[i] == 'A' && s[i+1] == 'C') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        int h = scan.nextInt();
        int w = scan.nextInt();
        String[] s = new String[h];
        for(int i=0;i<s.length;i++)
        {
            s[i] = scan.next();
        }
        
        for(int i=0;i<=h+1;i++)
        {
            if(i==0 || i==h+1)
            {
                for(int j=0;j<w+2;j++)
                {
                    System.out.print("#");
                }
                System.out.println();
                continue;
            }
            System.out.print("#");
            System.out.print(s[i-1]);
            System.out.print("#");
            System.out.println();
        }
    }
}


Measured memory_bytes: 21332
N = int(input())
SP = []
for i in range(N):
    SP.append(input().split() + [i + 1])

SP.sort()
city = SP[0][0]
tmp = [[int(SP[0][1]), SP[0][2]]]
for i in range(0, N - 1):
    if SP[i + 1][0] == city:
        tmp.append([int(SP[i + 1][1]), SP[i + 1][2]])
    else:
        tmp.sort()
        tmp.reverse()
        for j in range(len(tmp)):
            print(tmp[j][1])
        tmp = [[int(SP[i + 1][1]), SP[i + 1][2]]]
        city = SP[i + 1][0]
tmp.sort()
tmp.reverse()
for j in range(len(tmp)):
    print(tmp[j][1])










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

public class Main {
    int n, m;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        m = sc.nextInt();
        solve();
    }

    void solve() {
        if (n + m == 15) {
            System.out.println("+");
        } else if (n * m == 15) {
            System.out.println("*");
        } else {
            System.out.println("x");
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 22996
#include <stdio.h>
#include <string.h>

int main()
{
	int n;
	scanf("%d", &n);
	char s[105], t[105];
	scanf("%s %s", s, t);
	int len1 = strlen(s), len2 = strlen(t);
	int j=0, k=0;
	for(int i=0; i<len1+len2; i++)
	{
		if(i&1)
			printf("%c", t[k++]);
		else
			printf("%c", s[j++]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
int main(){
	int inf=1e9,n,k;cin>>n>>k;
	atcoder::mcf_graph<int,long long> g(n*2+2);
	int s=n*2,t=s+1,a;
	g.add_edge(s,t,n*k,inf);
	rep(i,n){
		g.add_edge(s,i,k,0);
		g.add_edge(i+n,t,k,0);
		rep(j,n)cin>>a,g.add_edge(i,j+n,1,inf-a);
	}
	cout<<1LL*k*n*inf-g.flow(s,t,n*k).second<<endl;
	vector grid(n,string(n,'.'));
	for(auto e:g.edges())if(e.from!=s&&e.to!=t&&e.flow>0)grid[e.from][e.to-n]='X';
	for(auto s:grid)cout<<s<<endl;
}

Measured memory_bytes: 3932
// Author: Amey Bhavsar
// IDE: Geany/Ubuntu
// Platform: ABC168

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

typedef long long ll;
typedef unsigned long long ull;

#define rep(i,a,b) for(auto i=a;i<b;i++)
#define repD(i,a,b) for(auto i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
// traversal function to avoid long template definition
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define MOD 1000000007
//make sure to change MAXN according to constraints
#define MAXN 200005
int n,m,u,v;
int main() {
	cin >> n >> m;
	
	vector<int> adj[n+1];
	vector<int> vst(n+1, -1);
	
	rep(i,0,m) {
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	
	queue<int> q;
	q.push(1);
	
	while(!q.empty()) {
		int f = q.front();
		q.pop();
			
		for (auto& nb : adj[f]) {
			if (vst[nb] == -1) {
				q.push(nb);
				vst[nb] = f;
			}
		}	
	}	
	
	rep(i,2,n+1) {
		if (vst[i] == -1) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	rep(i,2,n+1) {
		cout << vst[i] << endl;
	}	
	return 0;
}


Measured memory_bytes: 10340
#include <bits/stdc++.h>
#define ll long long
#define PII pair < int, int >
#define x first
#define y second
#define pb push_back
  
using namespace std;
int n;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    while (n){
		if (n % 10 == 9) return cout << "Yes", 0;
		n /= 10;
	}
	cout << "No";
}


Measured memory_bytes: 256
import itertools


def read():
    N = int(input())
    town = []
    for i in range(N):
        x, y = list(map(int, input().split()))
        town.append([x, y])

    return N, town


def solve(N, town):
    ans = 0
    import math
    townLens = 0.0
    for xys in itertools.permutations(town):
        townLen = 0.0
        for i in range(len(xys) - 1):
            townLen += math.sqrt((xys[i][0] - xys[i + 1][0]) ** 2 + (xys[i][1] - xys[i + 1][1]) ** 2)
        townLens += townLen

    ans = townLens / math.factorial(N)
    return ans


if __name__ == '__main__':
    N, town = read()
    # print("%d" % solve(N, renga))
    print(solve(N, town))


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

double dp[3001][3001];

double solve(double arr[], int n, int heads){

    if(heads == 0)
        return 1;

    if(n == 0)
        return 0;

    if(dp[n][heads] > -0.9)
        return dp[n][heads];

    return dp[n][heads] = arr[n]*solve(arr,n-1,heads-1) + (1-arr[n])*solve(arr,n-1,heads);

}

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

    memset(dp,-1,sizeof dp);

    double arr[n+1];

    for(int i=1;i<=n;i++)
        cin>>arr[i];

    cout<<fixed<<setprecision(10)<<solve(arr,n,(n+1)/2);

    return 0;
}


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

int edge[100][4];

int gcd(int m, int n){
    int temp;
    if(m > n){
        temp = m;
        m = n;
        n = temp;
    }
    while(m){
        temp = m;
        m = n % m;
        n = temp;
    }
    return n;
}

int lcm(int m, int n){
    return m / gcd(m, n) * n;
}

int binary(int i){
    int bin1, bin2, l;
    bin1 = 1;
    bin2 = 1;
    if(edge[i][2]){
        bin1 = binary(edge[i][2]-1);
    }
    if(edge[i][3]){
        bin2 = binary(edge[i][3]-1);
    }
    l = lcm(bin1*edge[i][0], bin2*edge[i][1]);
    return l/edge[i][0] + l/edge[i][1];
}

int main(){
    int n;
    int i;
    int g;
    bool data[101];
    int top;
    cin >> n;
    while(n){
        for(i=1;i<=n;i++){
            data[i] = false;
        }
        for(i=0;i<n;i++){
            cin >> edge[i][0] >> edge[i][1] >> edge[i][2] >> edge[i][3];
            data[edge[i][2]] = true;
            data[edge[i][3]] = true;
        }
        for(i=1;i<=n;i++){
            if(!data[i]){
                top = i-1;
                break;
            }
        }
        cout << binary(top) << endl;
        cin >> n;
    }
}

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


int main() {
	vector<vector<int>> appear(3, vector<int>(3));
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> appear[i][j];
		}
	}
	int N; cin >> N;
	int b;
	for (int i = 0; i < N; i++)
	{
		cin >> b;
		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < 3; k++)
			{
				if (appear[j][k] == b)appear[j][k] = 1e4;
			}
		}
	}
bool T = false;
for (int i = 0; i < 3; i++)if (appear[i][0] == 1e4 and appear[i][1] == 1e4 and appear[i][2] == 1e4)T = true;
for (int i = 0; i < 3; i++)if (appear[0][i] == 1e4 and appear[1][i] == 1e4 and appear[2][i] == 1e4) T = true;;
if (appear[0][0]==1e4 and appear[1][1]==1e4 and appear[2][2]==1e4) T = true;
if (appear[0][2]==1e4 and appear[1][1]==1e4 and appear[2][0]==1e4) T=true;
if (T)cout << "Yes";
else cout << "No";
}

Measured memory_bytes: 256
def main():
    a, b, c = map(int, input().split())
    k = int(input())
    while b <= a:
        b *= 2
        k -= 1
        if k < 0:
            print('No')
            exit()
    while c <= b:
        c *= 2
        k -= 1
        if k < 0:
            print('No')
            exit()
    if a < b < c:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for

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


Measured memory_bytes: 256
/*
    Author : DemonStar
*/

#pragma GCC optimize("Ofast")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define loop(i, n) for(ll i = 0; i < n; i++)
#define pl pair<ll, ll>
#define vl vector<ll>
#define endl '\n'
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t) {
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t) {
    for (auto &i : t) os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &t : v) is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
    for (pair<T1, T2> &t : v) is >> t.first >> t.second;
    return is;
}

const ll mod = 1e9 + 7;

int main()
{

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    fast;
    ll n;
    cin >> n;
    vl v(n);
    cin >> v;
    ll ans = 0 ;
    for (int i = 1; i <= n; i++) {
        if ((i & 1) and (v[i - 1] & 1)) ans++;
    }
    cout << ans << endl;




#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s";
#endif

    return 0;
}

Measured memory_bytes: 3656
sub f{my$p=$h[my$c=$c[$_]-=my$r=$s=$v[++$_]=1];$v[$_--]or$a[$c]-=-$s*(-$s+($s=($r+=&f)-$h[$c]+$p))for@$_;$a[$c]+=$s*(@a-($h[$c]=$p+$r))+1;$r}@a=(0)x<>;@c=glob<>;map{push@$_,$u-$_+$;for($u,$;)=split}<>;f;print"@a"

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

int main(void){
	int n, m;
	cin >> n >> m;
	vector<vector<int> > gp = vector<vector<int> >(n, vector<int>(n, 0));
	vector<vector<int> > rev_gp = vector<vector<int> >(n, vector<int>(n, 0));

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

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(gp[i][j] == 0) rev_gp[i][j] = 1;
        }
    }

	vector<int> color = vector<int>(n, 0);
    stack<int> st;
    st.push(0);

    int cur_color = 1;
    color[0] = cur_color;
	for(int i = 0; i < n; i++){
        if(st.empty()) {
            cur_color += 2;
            for(int j = 0; j < n; j++) {
                if(color[j] == 0) {
                    color[j] = cur_color;
                    st.push(j);
                    break;
                }
            }
        }

        int top = st.top();
        st.pop();

        int next_color = color[top] + 1;
        if(next_color % 2 == 1) next_color -= 2;

        for(int j = 0; j < n; j++){
            if(top == j) continue;
            if(rev_gp[top][j] && color[j] == 0){
                color[j] = next_color;
                st.push(j);
            } else if(rev_gp[top][j] && color[j] != 0 && color[j] == color[top]) {
                cout << -1 << endl;
                return 0;
            }
        }
	}

    vector<int> colorsum = vector<int>(cur_color + 4, 0);
	for(int i = 0; i < n; i++){
        colorsum[color[i]]++;
	}

    /*
    vector<int> dy = vector<int>(2, 0);
    for(int i = 1; i <= cur_color / 2 + 1; i++){
        int odd = colorsum[i * 2 - 1];
        int even = colorsum[i * 2];

        int min = 2100000000;
        int to_even = dy[0] + even;
        int to_odd = dy[1] + odd;
        for(int j = 0; j < 2; j++){
            int next = (j + 1) % 2;
            int oddv = dy[j] + odd;
            int evenv = dy[next] + even;
            if(min > (oddv * (oddv - 1) + evenv * (evenv - 1))){
                min = (oddv * (oddv - 1) + evenv * (evenv - 1));
                to_odd = oddv;
                to_even = evenv;
            }
        }
        dy[0] = to_even;
        dy[1] = to_odd;
    }

	int taka = dy[0];
	int hashi = dy[1];
	cout << ((taka * (taka-1)) + (hashi*(hashi-1)))/2 << endl;
    */

    vector<vector<int> > dy = vector<vector<int> >(n + 1, vector<int>(n + 1, 0));
    dy[0][0] = 1;
    int now = 1;
    for(int i = 1; i <= cur_color / 2 + 1; i++, now++){
        int odd = colorsum[i * 2 - 1];
        int even = colorsum[i * 2];

        for(int j = 0; j <= n; j++){
            if(dy[now - 1][j]) {
                dy[now][j + even] = 1;
                dy[now][j + odd] = 1;
            }
        }
    }

    int min = 2100000000;
    for(int i = 0; i <= n; i++){
        if(dy[now - 1][i]){
            int first = i * (i - 1) / 2;
            int second = (n - i) * (n - i - 1) / 2;
            if(min > first + second) min = first + second;
        }
    }

    cout << min << endl;

	return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    int x[n], y[n], h[n];
    rep(i, n) cin >> x[i] >> y[i] >> h[i];

    int base;
    rep(i, n)
    {
        if (h[i] != 0)
        {
            base = i;
            break;
        }
    }

    rep(i, 101)
    {
        rep(j, 101)
        {
            int ans = h[base] + abs(x[base] - i) + abs(y[base] - j);
            bool flag = 0;
            rep(k, n)
            {
                if (h[k] != max(ans - abs(x[k] - i) - abs(y[k] - j), 0))
                    flag = 1;
            }
            if (flag == 0)
                cout << i << " " << j << " " << ans << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100;
int main()
{
    ll n;
    cin >> n;
    ll cnt  = 0;
    for(ll i=1; i<=n; i++)
    {
        ll x;
        cin >> x;
        if(x!=i)
            cnt++;
    }

    if(cnt>2)
    {
        cout << "NO" << endl;
    }
    else
    {
        cout << "YES" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
using namespace std;

int main(){
    int K,S,count=0;
    cin >> K >> S;
    for(int a=0;a<=K;a++){
        for(int b=0;b<=S-a;b++){
            if(b<=K&&S-a-b<=K)  count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
using namespace std;
int main(void){
    int n,sum,a,b,c,size,w;
 
    while(true){
        cin >> n;
        if(n == 0)break;
 
        sum = 0;
 
        for(int i = 0; i < n; i++){
            cin >> a >> b >> c >> w;
 
            size = a+b+c;
 
            if(size <= 60 && w <= 2){
                sum += 600;
            }else if(size <= 80 && w <= 5){
                sum += 800;
            }else if(size <= 100 && w <= 10){
                sum += 1000;
            }else if(size <= 120 && w <= 15){
                sum += 1200;
            }else if(size <= 140 && w <= 20){
                sum += 1400;
            }else if(size <= 160 && w <= 25){
                sum += 1600;
            }
        }
 
        cout << sum << endl;
    }
 
    return 0;
}


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

#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pi;
typedef vector<int> vi;
void print_pair(pi a){
  cerr<<"("<<a.first<<", "<<a.second<<") ";
}
template<int T1, int T2>
void print_2d(int a[T1][T2], int x, int y){
  For(i, x){
    For(j, y){
      cerr<<a[i][j]<<" ";
    }
    cerr<<endl;
  }
}
template<class T>
void print_array(T a[],size_t n){
  cerr<<"array:";
  REP(n-1)cerr<<a[i]<<",";
  cerr<<a[n-1]<<endl;
}

int N;
int A[300001];

int main(){
  cin>>N;
  REP(N){
    cin>>A[i];
    A[i]--;
    if((A[i]%2)!=(i%2)){
      cout<<"No"<<endl;
      return 0;
    }
  }
  int i=0;
  while(i<N){
    int b=i,e=A[i];
    int j=i;
    while(true){
      e=max(e,A[j]);
      if(A[j]<b||j>e)goto NO;
      if(j==e)break;
      j++;
    }
    if((e-b)%2==1)
      goto NO;
    if(b==e){
      i=e+1;
      continue;
    }
    int prevb=-1,prevs=-1;
    for (int jj = b+1; jj < e; jj+=2) {
      if(A[jj]!=jj)
        goto NO;
    }
    for (int jj = b; jj <= e; jj+=2) {
      if(A[jj]>jj){
        if(prevb!=-1){
          if(prevb>A[jj])
            goto NO;
        }
        prevb=A[jj];
      }else if(A[jj]<jj){
        if(prevs!=-1){
          if(prevs>A[jj])
            goto NO;
        }
        prevs=A[jj];
      }else{
        goto NO;
      }
    }
    i=e+1;
  }
  cout<<"Yes"<<endl;
  return 0;
NO:
  cout<<"No"<<endl;
  return 0;
}



Measured memory_bytes: 1408
#include <stdio.h>
 
using namespace std;
 
int main(){
    int n;
    scanf("%d",&n);
    int A[n];
 
    for(int i = 0; i < n; i++) scanf("%d",&A[i]);
 
    for(int i = n-1; i > 0; i--) printf("%d ",A[i]);
    printf("%d\n",A[0]);
}


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

int main(){
    int N;
    long int count =0;
    cin >> N;
    char M1[2*N][2*N];
    for(int i=0;i<N;i++){
        string str;
        cin >> str;
        str.copy(M1[i],N);
    }
    for(int i=0;i<N;i++){
        for(int j=0; j<N;j++){
            M1[i+N][j]=M1[i][j];
            M1[i][j+N]=M1[i][j];
            M1[i+N][j+N]=M1[i][j];
//            cout << M1[i][j] << endl;
        }
    }
    for(int A=0;A<1;A++){
        for(int B=0; B<N;B++){
            for(int i=0;i<N;i++){
                for(int j=0; j<N;j++){
                    if (M1[i+A][j+B] !=M1[j+A][i+B]) {
//                        cout << "a:"<<A<<" b:"<<B<<" i:"<<i<<" j:"<<j<<endl;
                        goto BAD;
                    }
                }
            }
            count +=1;
BAD:;
        }
    }
    cout<<count*N<<endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define all(x) x.begin(), x.end()
 
using namespace std;

set <string> s;
int n;
string a;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cin >> n;
	while (n--) {
		cin >> a;
		s.insert(a);
	}
	printf ("%d\n", ss(s));
	return 0;
}


Measured memory_bytes: 19264
#include <iostream>
#include<algorithm>
#include <vector>
#include <string>
#include <stdio.h>
#include <cstdio>
#include <ctype.h>
#include <cstdlib>
using namespace std;

int main() {
	string a,b,c;
	cin>>a>>b>>c;
	int d,e,f;
	d=a.length();
	e=b.length();
	f=c.length();
	if(a[d-1]==b[0]&&b[e-1]==c[0])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
void print(char str[1000]);
void reverse(char str[1000]);
void replace(char str[1000]);

int main(){
    char str[1000];
    int i, q, q0;
    char com[7];
    
    scanf("%s", str);
    scanf("%d", &q);
    q0 = q;
    for (i = 0; i < q; i++) {
        scanf("%s", com);
        if (strcmp(com, "print") == 0) {print(str);}
        else if (strcmp(com, "reverse") == 0) {reverse(str);}
        else if (strcmp(com, "replace") == 0) {replace(str);}
    }
}

void print (char str[1000]) {
    int a, b;
    scanf("%d %d", &a, &b);
    for (int i = a; i < b; i++){
        printf("%c", str[i]);
    }
    printf("%c\n", str[b]);
}

void reverse(char str[1000]) {
    int a, b;
    int i, j;
    char c;
    scanf("%d %d", &a, &b);
    for (i = a, j = b; i <= (a + b) / 2; i++, j--) {
        c = str[i];
        str[i] = str[j];
        str[j] = c;
    }
}

void replace(char str[1000]) {
    int a, b;
    char p[1000];
    int i, j;
    scanf("%d %d %s", &a, &b, p);
    for (i = a, j = 0; i <= b; i++, j++) {
        str[i] = p[j];
    }
}



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

int main(){
  int H, N;
  int a[100010];
  cin >>H >>N;
  for (int i = 0; i<N ; ++i)cin >> a[i];
  //cout<<"Hの値:"<<H<<"  Nの値:"<<N<<endl;
  int sum =0;
  for (int i=0; i<N;++i ){
  //  cout <<"sumに"<<a[i]<<"を代入"<<endl;
    sum += a[i];
  }

  if (sum>=H){
    cout <<"Yes"<<endl;
  }
  else {
    cout <<"No"<<endl;
  }
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>

using namespace std;

int main(){
  while(true){
    int a[100000] = {0};
    int n, k;
    cin >> n >> k;
    if(!n)
      break;
    for(int i = 0; i < n; i++){
      cin >> a[i];
    }
    int ans = 0;
    for(int j = 0; j < k; j++){
      ans += a[j];
    }
    int ab = ans;  
    //cout << "f:" << aa << endl;
    for(int i = k; i < n; i++){
      int aa = ab - a[i - k] + a[i];
      ab = aa;
      ans = aa > ans ? aa : ans;
      //cout << aaa << ":" << aa << " - " << a[i - k] << " + " << a[i] << endl;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1556
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		
		int[] panel = new int[3];
		// 読み込み
		for(int i=0;i<3;i++){
			panel[i] = scan.nextInt();
		}
		// ソート(昇順)
		Arrays.sort(panel);
		
		// 最大値 * 10 + 2番目の大きさ  "+" 最小値
		int max = panel[2]*10 + panel[1] + panel[0];
		
		System.out.println(max);
		

	}

}

Measured memory_bytes: 21460