akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
 
using namespace std;

#define int long long
 
struct segtree {
    vector<int> dat;
    int n;
 
    segtree(int n_) {
        n = 1;
 
        while (n < n_) n *= 2;
 
        dat.resize(2*n, 0);
    }
 
    void update(int i, int x) {
        i += n - 1;
        int diff = x - dat[i];
        dat[i] = x;
 
        while (i > 0) {
            i = (i - 1) / 2;
            dat[i] += diff;
        }
    }
 
    int query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r == -1) r = n;
 
        if (r <= a || l >= b) return 0;
 
        if (a <= l && r <= b) {
            return dat[k];
        }
 
        int lv = query(a, b, k * 2 + 1, l, (l + r) / 2);
        int rv = query(a, b, k * 2 + 2, (l + r) / 2, r);
 
        return lv + rv;
    }
};

signed main()
{
    int N; cin >> N;
    vector<int> a(N), b(N);
 
    segtree P(N), Q(N);
    vector<tuple<int, int, int>> tmp;
 
    for (int i = 0; i < N; ++i) {
        cin >> a[i] >> b[i];
        tmp.push_back(make_tuple(a[i], i, b[i]));
    }
 
    sort(begin(a), end(a));
    sort(begin(tmp), end(tmp));
 
    vector<pair<int, int>> data;
 
    for (int i = 0; i < N; ++i) {
        int aaa, bbb, val;
        tie(aaa, bbb, val) = tmp[i];
        data.push_back(make_pair(val, i));
    }
 
    sort(begin(data), end(data));
     
    for (int i = 0; i < N; ++i) {
        P.update(i, a[i]);
        Q.update(i, 1);
    }
 
    int ma = 0;
 
    for (int i = 0; i < N; ++i) {
        pair<int, int> d = data[i];
 
        int l = 0, r = N;

        int PP, QQ;
 
        for (int j = 0; j < 20; ++j) {
            int mid = (l + r) / 2;

            PP = P.query(0, mid + 1);
            QQ = Q.query(0, mid + 1);
 
            if (PP <= d.first * QQ) {
                l = mid;
            } else {
                r = mid;
            }
        }
 
        if (PP <= d.first * QQ) {
            ma = max(ma, QQ);
        }
 
        P.update(d.second, 0);
        Q.update(d.second, 0);
    }
 
    cout << ma << endl;
}

Measured memory_bytes: 43752
/*
   Created by Rahul Goel.
*/
/*******************************************************************************/
#include <iostream>
#include <vector>
#include <numeric>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
/*******************************************************************************/
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const int INF = 1e9;
const ll LINF = 1e18;
/*******************************************************************************/
/*
.-.. . -. -.- .- / .. ... / .-.. --- ...- . -.-.--
 */
/* For PBDS */
/*Two new methods X.order_of_key() and X.find_by_order()*/
/*
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

/*******************************************************************************/
ll mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

ll mod_prod() { return 1LL; }
template<typename T, typename... Args>
T mod_prod(T a, Args... args) { return (a*mod_prod(args...))%mod; }
/*******************************************************************************/
using pii = pair < ll, ll >;
using vi = vector < ll >;
using vb = vector < bool >;
using vvi = vector < vector < ll > >;
using vvb = vector < vector < bool > >;
using vpii = vector < pii >;
using vvpii = vector < vector < pii > >;
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(c)          (c).begin(), (c).end()
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())
#define uniq(c)         (c).resize(distance((c).begin(), unique(all(c))))
#define min_pq(t)       priority_queue < t, vector < t >, greater < t > >
#define max_pq(t)       priority_queue < t >
#define pb              push_back
#define ff              first
#define ss              second
/*******************************************************************************/

/*
    Code begins after this.
*/


ll solve(){
    ll l, r, d;
    cin >> l >> r >> d;
    cout << r / d - (l - 1) / d << endl;
    return 0;
}


signed main(){
    fastio;

    ll t = 1;
    while(t--)
        solve();

    return 0;
}

/*******************************************************************************/
// Remeber - In a custom comparator cmp(a, b) a==b must always return to false.



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

int main(){
   char s[11],t[11],u[11];
   int a,b;
 
   scanf("%s %s",s,t);
   scanf("%d %d",&a,&b);
   scanf("%s",u);
   if (strcmp(s,u)==0) printf("%d %d\n",a-1,b);
   else                printf("%d %d\n",a,b-1);
   return 0;
}


Measured memory_bytes: 128
while True:
  H, W = map(int, input().split())
  for i in range(H):
    for j in range(W):
      if (i + j) % 2 == 0:
        print("#", end ="")
      else:
        print(".", end ="")
    print()
  if H == 0 and W == 0:
    break

  print()


Measured memory_bytes: 7008
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

//ただの辺
struct edge {
    using lint = long long int;
    int to;
    lint cost;
    //引数一つの時は距離1
    edge(int t, lint c = 1) : to(t), cost(c) {
    }
};

// Bellman-Ford
// depend:edge
vector<lint> bellman_ford(vector<vector<edge>>& g, int s) {
    using lint = long long int;
    int n = g.size();
    vector<lint> res(n, LLONG_MAX);
    res[s] = 0;
    for (int i = 0; i < 2 * n; i++) {
        for (int j = 0; j < n; j++) {
            if (res[j] == LLONG_MAX) continue;
            for (int k = 0; k < (int)g[j].size(); k++) {
                int c = g[j][k].cost, dest = g[j][k].to;
                if (i < n - 1) {
                    res[dest] = min(res[dest], res[j] + c);
                } else {
                    if (res[j] == LLONG_MIN || res[dest] > res[j] + c)
                        res[dest] = LLONG_MIN;
                }
            }
        }
    }
    return res;
}

int main() {
    int n, m, p;
    cin >> n >> m >> p;
    vector<vector<edge>> g(n);
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        g[a].push_back(edge(b, p - c));
    }
    vector<lint> dist = bellman_ford(g, 0);
    if (dist[n - 1] == LLONG_MIN) {
        cout << -1 << endl;
    } else {
        cout << max(-dist[n - 1], 0LL) << endl;
    }
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

signed main(){
    cin.tie(0); 
    ios::sync_with_stdio(false);
    int n;
    int a[200005],b[200005];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        b[i] = a[i];
    }
    
    sort(b,b+n,greater<int>());
    
    for(int i=0;i<n;i++){
        if( b[0] == a[i] ){
            cout << b[1] << "\n";
        }else{
            cout << b[0] << "\n";
        }
    }
    
    return 0;
}


Measured memory_bytes: 3200
N = int(input())
en_list = "abcdefghijklmnopqrstuvwxyz"
answer = ""
while N > 0:
    r = N % 26
    if r == 0:
        r = 26
    answer = en_list[r-1] + answer
    N = (N - r) // 26
print(answer)

Measured memory_bytes: 9092
import java.util.*;
import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        int ans = 0;
        for(int i=1; i<=n; i++){
            ans += (n-1)/i;
        }
        out.println(ans);

    }
}


Measured memory_bytes: 35748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1e9 + 7;

int N, M;
vector<vector<int>> edge(0, vector<int>(0));
vector<bool> visited;
vector<int> sign;

queue<int> q;

void bfs() {
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        visited[now] = true;
        for (int i = 0; i < (int)edge[now].size(); i++) {
            int next = edge[now][i];
            if (visited[next]) continue;
            if (sign[next] != -1) continue;
            sign[next] = now;
            q.push(next);
        }
    }
}

int main() {
    cin >> N >> M;
    edge.resize(N);
    sign.assign(N, -1);
    visited.assign(N, false);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    q.push(0);
    bfs();
    cout << "Yes" << endl;
    for (int i = 1; i < N; i++) {
        cout << ++sign[i] << endl;
    }
    return 0;
}

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

using namespace std;

int n, m;
vector<vector<int>> g(9);
bool vi[9];

int dfs(int p = 1, int d = 1){
	if(d == n) return 1;
	vi[p] = true;
	int cnt = 0;
	for(int i = 0; i < g[p].size(); i++){
		if(!vi[g[p][i]]){
			cnt += dfs(g[p][i], d + 1);
		}
	}
	vi[p] = false;
	return cnt;
}

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	cout << dfs() << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <unordered_map>

typedef long long ll;

int main (void) {
  ll N;
  std::cin >> N;

  ll headb = 0, lasta = 0, bothab = 0, countab = 0;
  for(ll i=0; i<N; i++){
    std::string s; std::cin >> s;

    if ( s.front() == 'B' && s.back() == 'A' ) bothab++;
    else if ( s.front() == 'B' ) headb++;
    else if ( s.back()  == 'A' ) lasta++;
    for(ll j=0; j<s.size(); j++){
      if ( s.substr(j,2) == "AB" ) countab++;
    }
  }

  ll ans = countab + std::min(lasta, headb) + bothab;
  if ( lasta == 0 && headb == 0 && bothab != 0 ) ans--;
  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(x) cerr << #x << " = " << x << endl

int main(int qtd, char* nome[])
{
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	string a, b;
	cin >> a >> b;
	cout << (b.substr(0, b.length()-1) == a? "Yes\n": "No\n") << endl;
	
	return 0;
}

Measured memory_bytes: 3600
m='+=+j[0]*Math.',n='(s*Math.PI/180)',x=y=s=0;require("fs").readFileSync("/dev/stdin","utf8").split('\n').some(function(i){j=i.split(','),eval('x'+m+'sin'+n+',y'+m+'cos'+n),s+=+j[1]});console.log(~~x),console.log(~~y)

Measured memory_bytes: 7648
n,m=[int(x) for x in input().split()]
first_gate=0
last_gate=10**10
for _ in [0]*m:
    small,large=[int(x) for x in input().split()]
    first_gate=max(first_gate,small)
    last_gate=min(last_gate,large)
print(max(0,last_gate- first_gate+1))

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

int mod(int x)
{
    if(x>=0){return x;}
    return (-1)*x;
}

int min_cost(int f,int dp[],int h[])
{
    if(f==1){return 0;}
    if(f==2){return mod(h[2]-h[1]);}
    if(dp[f]!=-1){return dp[f];}
    dp[f]=min(min_cost(f-1,dp,h)+mod(h[f]-h[f-1]),min_cost(f-2,dp,h)+mod(h[f]-h[f-2]));
    return dp[f];
}

int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   int h[n+1],dp[n+1]={-1};
   for(int x=1;x<=n;x++)
   {
       cin>>h[x];
       dp[x]=-1;
   }
   cout<<min_cost(n,dp,h)<<endl;
}








Measured memory_bytes: 8268
#include <stdio.h>
int main(void)
{
    char a[20];
    int i;
    scanf("%s", a);
    for(i=0; i<5; i++) printf("%c", a[i]);
    printf(" ");
    for(i=6; i<13; i++) printf("%c", a[i]);
    printf(" ");
    for(i=14; i<19; i++) printf("%c", a[i]);
    return 0;
}

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	VI tbl(100010, 1);
	VB used(100010);
	int n, m;
	cin >> n >> m;
	VI xs, ys;
	int pos = 1;
	used[pos] = true;
	rep (i, m) {
		int x, y;
		cin >> x >> y;
		if (used[x]) {
			used[y] = true;
			pos = y;
		}
		if (used[x] && tbl[x] - 1 == 0) {
			used[x] = false;
		}
		tbl[x]--;
		tbl[y]++;
	}
	int ans = 0;
	REP (i, 1, n + 1) {
		if (used[i]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> void vdebug(vector<T> v){ cout << "vdebug" << endl; for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ cout << "adebug" << endl; reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
template<typename T1, typename T2> void mdebug(map<T1, T2> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebug(multimap<T1, T2> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mdebugr(map<T1, T2, greater<T1>> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebugr(multimap<T1, T2, greater<T1>> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << 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 dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


// 二次元累積和
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n, m, Q;
    ll l, r;
    int a[510][510];
    Fill(a, 0);
    cin >> n >> m >> Q;
    rep(i, m){
        cin >> l >> r;
        a[l][r]++;
    }

    reps(i, 1, n){
        reps(j, 1, n){
            a[i][j] += a[i-1][j];
        }
    }
    reps(i, 1, n){
        reps(j, 1, n){
            a[i][j] += a[i][j-1];
        }
    }

    ll p, q;
    rep(i, Q){
        cin >> p >> q;
        cout << a[q][q] + a[p-1][p-1] - a[q][p-1] - a[p-1][q] << endl;
    }

    // reps(i, 1, n){
    //     reps(j, 1, n){
    //         cout << a[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    return 0;
}


Measured memory_bytes: 1920
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

using vll = vector<ll>;

void solve();

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

  solve();

  return 0;
}

#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)

#define inl(...)  \
  ll __VA_ARGS__; \
  in(__VA_ARGS__)

#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__);

#define inc(...)      \
  char __VA_ARGS__; \
  in(__VA_ARGS__);

void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
  cin >> t;
  in(u...);
}

void out() {
  cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}

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

void solve();
#ifndef ONLINE_JUDGE
#include "./lib.hpp"
#endif

void solve() {
  ini(A, B, C);
  ini(K);

  while (A >= B) {
    if (K == 0) {
      out("No");
      return;
    }
    B *= 2;
    K--;
  }
  while (B >= C) {
    if (K == 0) {
      out("No");
      return;
    }
    C *= 2;
    K--;
  }
  out("Yes");
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <string.h>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#define INF 100000000

const int MOD = 1e9+7;
typedef long long ll;
using namespace std;
const ll M = 998244353;

int main(void) {
	int k, a, b;
	cin >> k >> a >> b;
	for(int i=a;i<=b;i++) {
	    if(i%k==0) { cout << "OK" << endl; return 0; }
	}
	cout << "NG" << endl;
}


Measured memory_bytes: 3636
N, K = map(int, input().split())
*A, = map(int, input().split())
visited = [False] * N
towns = []
now = 0
length = 0
while not visited[now] and K > 0:
    visited[now] = True
    towns.append(now + 1)
    length += 1
    K -= 1
    now = A[now] - 1
if K == 0: print(now + 1)
else:
    idx = towns.index(now + 1)
    length -= idx
    print(towns[idx:][K % length])

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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};


class Eratosthenes {
public:
    vector<bool> prime;

    Eratosthenes(int size) {
        prime.resize(size + 1, 1);
        prime[0] = 0;
        prime[1] = 0;
        FOR(i, 2, size) {
            if (prime[i]) {
                for (int j = 2 * i; j <= size; j += i) {
                    prime[j] = 0;
                }
            }
        }
    }

};


class Combination {
    vector<ll> fac; //n!(mod M)
    vector<ll> ifac; //k!^{M-2} (mod M)
public:
    Combination(ll size) {
        fac.resize(size);
        ifac.resize(size);
        fac[0] = 1;
        ifac[0] = 1;
        for (ll i = 0; i < size; i++) {
            fac[i + 1] = fac[i] * (i + 1) % MOD;
            ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
        }
    }

    ll mpow(ll x, ll n) {
        ll ans = 1;
        while (n != 0) {
            if (n & 1) ans = ans * x % MOD;
            x = x * x % MOD;
            n = n >> 1;
        }
        return ans;
    }

    ll comb(ll a, ll b) {
        if (a == 0 && b == 0)return 1;
        if (a < b || a < 0)return 0;
        ll tmp = ifac[a - b] * ifac[b] % MOD;
        return tmp * fac[a] % MOD;
    }
};


ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll N, x;
bool v[101010];

int main() {
    cin >> N >> x;
    vector<ll> A(N), C(N);
    ll mm = 0, m = 1;
    ll ans = 0;
    REP(i, N) {
        cin >> A[i];
        C[i] = A[i];
        ans += C[i];
    }
    REP(i, N) {
        ll c = m * x;
        REP(k, N) {
            int p = (k + m >= N ? (k + m) % (N) : k + m);
            C[p] = min(C[p], A[k]);
            c += C[p];
        }
        m++;
        ans = min(c, ans);
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
void main() {
  problem();
}

void problem() {
  const N = scan!int;
  const A = scan!(long)(N);

  long[] counts = new long[N+1];
  foreach(a; A) counts[a]++;

  const pairsCounts = counts.map!(x => x <= 0 ? 0 : (x-1)*x/2).array;
  const totalPairsCounts = pairsCounts.sum;

  const pairsCountsLess = counts.map!(x => (x - 1) <= 0 ? 0 : (x-2)*(x-1)/2).array;
  const pairsDecreaseCounts = (N+1).iota.map!(i => pairsCounts[i] - pairsCountsLess[i]).array;

  counts.deb;
  pairsCounts.deb;
  totalPairsCounts.deb;
  pairsCountsLess.deb;
  pairsDecreaseCounts.deb;

  int solve() {
    foreach(a; A) {
      (totalPairsCounts - pairsDecreaseCounts[a]).writeln;
    }
    return 0;
  }

  solve();
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

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


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

int partition(vector<int> &array, int p, int r)
{
    int v = array[r];
    // vより小さい部分の境界
    int i = p - 1;
    int j = p;
    for (int j = p; j < r; j++)
    {
        if (array[j] <= v)
        {
            i++;
            int t = array[i];
            array[i] = array[j];
            array[j] = t;
        }
    }
    i++;
    int t = array[i];
    array[i] = v;
    array[r] = t;
    return i;
}

int main()
{
    int num;
    cin >> num;
    vector<int> array;
    for (int i = 0; i < num; i++)
    {
        int v;
        cin >> v;
        array.push_back(v);
    }

    int p = partition(array, 0, num - 1);

    for (int i = 0; i < num; i++)
    {
        if (i != 0)
            cout << " ";

        if (i == p)
            cout << "[";
        cout << array[i];
        if (i == p)
            cout << "]";
    }
    cout << endl;
}



Measured memory_bytes: 3316
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rep1n(i, n) for(int i=1;i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
int main() {

	int x;
	cin >> x;
	cout << (x < 1200 ? "ABC" : "ARC");

	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(input()) for i in range(N)]
sorted_A = sorted(A)
d = {}
for i in range(N):
    d[sorted_A[i]] = i
# print(d)
cnt = 0
for i in range(N):
    if i % 2 == 0 and d[A[i]] % 2 != 0:
        cnt += 1
    elif i % 2 != 0 and d[A[i]] % 2 == 0:
        cnt += 1
ans = cnt // 2
print(ans)


Measured memory_bytes: 20044
#include<iostream>
#include<string>
using namespace std;
int main(){
	int s=0,f=0;
	string S,k="keyence";
	cin>>S;
	for(int i=0;i<S.length();i++){
		if(S[i]==k[i])s++;
		else break;
	}
	for(int i=0;i<S.length();i++){
		if(S[S.length()-1-i]==k[6-i])f++;
		else break;
	}
	if(s+f>=7)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

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

const ll INF=100100100100100100;

ll n,m;


vector<ll> g[1005];
vector<ll> og[1005];

vector<ll> bfs(ll t){
  vector<ll> d;
  vector<ll> D(n+1);

  vector<ll> dist(n,INF);
  vector<ll> par(n,-1);

  dist[t]=0;

  queue <ll>q;
  q.push(t);
  while(!q.empty()){
    ll now=q.front();
    q.pop();
    for(ll to:g[now]){
  //    cout<<to<<"to"<<endl;
      if (dist[to]!=INF)continue;
      dist[to]=dist[now]+1;
    //  cout<<dist[to]<<"distto"<<endl;
      par[to]=now;
      q.push(to);
    }
  }
  P distmin=make_pair(ll(INF),ll(INF));
  rep(i,n){
    if (i==t)continue;
    for(ll to:g[i]){
      if (to==t){
        distmin=min(distmin,make_pair(dist[i],i));
      //  cout<<distmin.first<<"ok"<<i<<endl;
      }
    }
  }
  if (distmin.first==INF) return D;
  ll now=distmin.second;
//  cout<<now<<endl;
  d.push_back(now);
  while(now!=t){
//    cout<<now<<endl;
    now=par[now];
    d.push_back(now);
  }
  //d.push_back(t);
  return d;
}

int main() {
  cin>>n>>m;
  rep(i,m){
    ll a1,b1;
    cin>>a1>>b1;
    a1--;b1--;
    g[a1].push_back(b1);
    og[b1].push_back(a1);
  }
  vector<ll> ans(n+1);

  rep(i,n){
//    cout<<endl;
  //  cout<<i<<'i'<<endl;
    vector<ll> temp=bfs(i);
    if (temp.size()<ans.size())ans=temp;
  }
  //cout<<"ans"<<endl;
  if (ans.size()==n+1){
    cout<<-1;
  return 0;
}
cout<<ans.size()<<endl;
  rep(i,ans.size()){
    cout<<(ans[ans.size()-i-1]+1)<<endl;
  }


}


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

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

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

    int n; cin >> n;
    vector<int> h(n);
    for(int i=0; i<n; ++i) cin >> h[i];
    const int inf = 1<<30;
    vector< vector<int> > dp(n+5, vector<int>(2, inf));
    dp[1][0] = dp[1][1] = 0;
    dp[2][0] = abs(h[1]-h[0]);
    
    for(int i=3; i<=n; ++i){
        dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + abs(h[i-1]-h[i-2]);
        dp[i][1] = min(dp[i-2][0], dp[i-2][1]) + abs(h[i-1]-h[i-3]);
    }

    cout << min(dp[n][0], dp[n][1]) << endl;    

	return 0;
}


Measured memory_bytes: 6144
a, b , c = -1,-1,-1
n, y = map(int,input().split())
for i in range(n+1):
    for j in range(n+1):
        if i+ j > n:
            break
        elif ((y - (i*10000 + j*5000))%1000 == 0) and ((i+j+(y - (i*10000 + j*5000))/1000) == n):
            if (y - (i*10000 + j*5000))/1000 >= 0:
                a,b,c = i, j, int((y - i*10000 - j*5000)/1000)
                break
print(a, b, c)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define sz(a) (long long)((a).size())
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#define mp make_pair
#include <iostream>

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}

int main()
{
    fastinput;
    LL n, i, j, k, t, temp,tc;
    long double a,b,h,m;
    
    cin>>a>>b>>h>>m;
    h+=(m/60.000000000000);
    long double angle_a=h*30;
    long double angle_b=m*6;
    //debug(angle_a);
   // debug(angle_b);
    long double diff=fabs(angle_a-angle_b);
    diff=min(diff,360-diff);
    //debug(diff);
    long double c=0.0;
    long double angle=3.141592653589793238;
    angle/=180.0000000000000000000;
    angle*=diff;
    long double p=a*a+b*b-2*a*b*cos(angle);
    c=sqrt(p);
    //debug(p);
    printf("%0.15Lf\n",c);

    return 0;
}


Measured memory_bytes: 4176
//INCLUDES##############
#include<bits/stdc++.h>
//USING##############
using namespace std;
//TYPEDEFS###############
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
//MACROS#################
#define pb push_back
#define mp make_pair
#define rep(i,begin,end) for(auto i = begin-((begin>end));i!=end - ((begin>end));i+=1-2*((begin>end)))
#define fq(i,begin,end) for(ll i=begin;i<=end;i++)
#define fm(i,begin,end,t) for(ll i=begin;i<end;i+=t)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ff first  
#define ss second
//FUNCTIONS################
ll powermod(ll a, ll b , ll m) {ll r=1; while(b) { if(b%2==1)r = (r*a)%m; b/=2;a = (a*a)%m;}return r;}
ll power(ll a,ll b){ll r=1;while(b){if(b%2==0)r = r*a;b/=a;a=a*a;}return r;}
ll add(ll a,ll b){ll x= (a%mod + b%mod)%mod;return x;}
ll sub(ll a,ll b){ll x = (a-b+mod)%mod;return x;}
ll divi(ll a,ll b){ll x = a;ll y = powermod(b,mod-2,mod);ll res = (x*y)%mod;return res;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
#define INF 1e9
int main()
{
    int n;
    cin >> n;
    int a[n];
    rep(i,0,n)cin >> a[i];
    vector<int> dp(n,INF);
    dp[0] = 0;
    rep(i,0,n)
    {
        for(int j:{i+1,i+2})
        {
            if(j<n)
            {
                dp[j] = min(dp[j],dp[i]+abs(a[i]-a[j]));
            }
        }
    }

    cout << dp[n-1];
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();
		sc.close();

		int cnt = 0;
		for (int i = 1; i < n; i++) {
			if (s.charAt(i - 1) != s.charAt(i)) {
				cnt++;
			}
		}
		cnt = Math.max(cnt - 2 * k, 0);
		System.out.println(n - cnt - 1);
	}
}


Measured memory_bytes: 25684
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define debug1(a) cout<<#a<<" "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" "<<(a)<<" "<<#b<<" "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" "<<(a)<<" "<<#b<<" "<<(b)<<" "#c<<" "<<(c)<<endl;
typedef long double ld;
void solve()
{
	ll n;
	cin >> n;
	vector<ll> arr(n);
	vector<ll> res;
	rep(i, n)
	{
		cin >> arr[i];
	}
	ll j = 1;
	for (int i = 0; i < n; i++)
	{
		if (arr[i] == j)
		{
			res.push_back((i + 1));
			j++;
		}
	}
	if (res.size() == 0)
	{
		for (int i = 0; i < n; i++)
		{
			if (arr[i] != (i + 1))
			{
				cout << -1 << endl;
				return;
			}
		}
		cout << 0 << endl;
	}
	else
	{
		ll sum = res[0] - 1;
		for (int i = 1; i < res.size(); i++)
		{
			sum += (res[i] - res[i - 1] - 1);
		}
		if (res[res.size() - 1] != n)
		{
			sum += n - res[res.size() - 1];
		}
		if (sum > n - 1)
		{
			cout << -1 << endl;
			return;
		}
		cout << sum << endl;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	t = 1;
	while (t--)
	{
		solve();
	}
}

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

int main()
{
	int x,a,b;
	cin>>x>>a>>b;
	
	if(b-a<=0) cout<<"delicious"<<endl;
	else if(b-a<=x) cout<<"safe"<<endl;
	else cout<<"dangerous"<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

struct path {
	int a ;
	int b ;
} p[33] ;

int w ;
int n ;
int ans[35] ;

int main ( )
{
	while ( scanf ( "%d" , &w ) == 1 ) {
		scanf ( "%d" , &n ) ;
		for ( int i = 0 ; i < n ; i++ ) {
			scanf ( "%d,%d" , &p[i].a , &p[i].b ) ;
			p[i].a-- ;
			p[i].b-- ;
		}
		for ( int i = 0 ; i < w ; i++ ) {
			int tmp = i ;
			for ( int j = 0 ; j < n ; j++ ) {
				if ( tmp == p[j].a ) {
					tmp = p[j].b ;
				}
				else if ( tmp == p[j].b ) {
					tmp = p[j].a ;
				}
			}
			ans[tmp] = i ;
		}
		for ( int i = 0 ; i < w ; i++ ) {
			printf ( "%d\n" , ans[i] + 1 ) ;
		}
	}
	return 0 ;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define debug1(a) cout<<" "<<#a<<" : "<<a<<"\n"
#define debug2(a,b) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define debug3(a,b,c) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define debug4(a,b,c,d) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"
#define INF (int)10000000000000000
#define PI (double)3.14159265358979
// #define M 421412341324321
#define MOD 1000000007

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int n, m, l;
	cin>>n>>m>>l;
	int a[n+1][n+1];
	rep(i,n+1)
	{
		rep(j,n+1)
		{
			a[i][j] = INT_MAX;
		}
		a[i][i] = 0;
	}
	rep(i,m)
	{
		int x, y, w;
		cin>>x>>y>>w;
		if (w<=l)
		{
			a[x][y] = w;
			a[y][x] = w;
		}
	}
	REP(k,1,n)
	{
		REP(i,1,n)
		{
			REP(j,1,n)
			{
				if (a[i][k]!=INT_MAX && a[k][j]!=INT_MAX && a[i][j]>a[i][k]+a[k][j])
				{
					a[i][j] = a[i][k]+a[k][j];
				}
			}
		}
	}
	int adj[n+1][n+1];
	REP(i,0,n)
	{
		REP(j,0,n)
		{
			if (a[i][j]<=l)
			{
				adj[i][j] = 1;
			}
			else
			{
				adj[i][j] = INT_MAX;
			}
		}
	}
	REP(k,1,n)
	{
		REP(i,1,n)
		{
			REP(j,1,n)
			{
				if (adj[i][k]!=INT_MAX && adj[k][j]!=INT_MAX && adj[i][j]>adj[i][k]+adj[k][j])
				{
					adj[i][j] = adj[i][k]+adj[k][j];
				}
			}
		}
	}
	// REP(i,1,n)
	// {
	// 	REP(j,1,n)
	// 	{
	// 		// if (a[i][j]==INT_MAX) cout<<"INT_MAX ";
	// 		// else cout<<a[i][j]<<" ";
	// 		cout<<pred[i][j]<<" ";
	// 	}
	// 	cout<<"\n";
	// }
	int q;
	cin>>q;
	rep(i,q)
	{
		int x,y;
		cin>>x>>y;
		int ans = adj[x][y];
		if (ans==INT_MAX) ans=0;
		cout<<ans-1<<"\n";
	}




}


Measured memory_bytes: 1920
import bisect

N = int(input())
L = map(int, input().split())

SL = sorted(L)
ans = 0
for i in range(N):
  if i+1 == N-1:
    break
  a = SL[i]
  for j in range(i+1, N):
    b = SL[j]
    c_max = bisect.bisect_left(SL, a+b)
    ans += c_max - (j+1)

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int n,m;
vi a;
ll cnt = 0;
/*
void dfs(int x){
    if(x>n){return;}
    auto result = find(all(a),x);
    if(result != a.end()){return;}
    if(x==n){cnt++; cnt%=mod;cout << cnt << endl;}

    dfs(x+1);
    dfs(x+2);
    
}
*/
/*
int dp(int x){
    if(x==0) return 1;
    if(x==1) return 1;
    auto result = find(all(a),x);
    if(result != a.end()){return 0;}
    return (dp(x-1) + dp(x-2))%mod;

}
*/

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

    cin >> n >> m;
    vl b(n+1,0);
    rep(i,m){
        int x ;
        cin >> x;
        b[x]=-1;
    }
    
    rep(i,n+1){
        if(b[i]==-1){b[i]=0;}
        else if(i==0){b[0]=1;}
        else if(i==1){b[1]=1;}
        else{b[i] = (b[i-1]+ b[i-2])%mod;}
        //cout << b[i]<<endl;
    }
    cout << b[n] << endl;
    return 0;
}

Measured memory_bytes: 1024
import sys
from operator import add
(r, c) = [int(i) for i in sys.stdin.readline().split()]
s = [0] * (c + 1)
for i in range(r):
    l = [int(i) for i in sys.stdin.readline().split()]
    l.append(sum(l))
    print(" ".join([str(i) for i in l]))
    s = map(add, s, l)

print(" ".join([str(i) for i in s]))

Measured memory_bytes: 6740
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,T;
  cin >> N >> T;
  vp vw(N);
  rep(i,N) {
    int a,b;
    cin >> a >> b;
    vw[i] = P(a,b);
  }
  sort(rng(vw));
  vi dp(T+3010,0);
  rep(i,N) {
    vi dp2(T+3010,0);
    int we = vw[i].first;
    int va = vw[i].second;
    rep(j,T+3010) {
      if(j < T) {
        if(j - we >= 0) {
          dp2[j] = max(dp[j],dp[j-we]+va);
        } else {
          dp2[j] = dp[j];
        }
      } else {
        if(j - we >= T) {
          dp2[j] = dp[j];
        } else if(j - we >= 0) {
          dp2[j] = max(dp[j],dp[j-we]+va);
        } else {
          dp2[j] = dp[j];
        }
      }
    }
    dp = dp2;
  }
  int ans = 0;
  rep(i,T+3010) {
    ans = max(ans,dp[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(){
  long long n,m,s=0;
  scanf("%lld",&n);
  s+=(n*(n+1))/2;//printf("%lld\n",s);
  m=n/3;
  s-=(m*(m+1))/2*3;//printf("%lld\n",s);
  m=n/5;
  s-=(m*(m+1))/2*5;//printf("%lld\n",s);
  m=n/15;
  s+=(m*(m+1))/2*15;
  printf("%lld\n",s);
  return 0;
}


Measured memory_bytes: 1728
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func readInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
	}
	return a
}

func main() {
	var N int
	fmt.Scan(&N)
	h := readInts(N)
	dp := make([]int, N)
	dp[1] = abs(h[0] - h[1])
	for i := 2; i < N; i++ {
		dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
	}
	fmt.Println(dp[N-1])
}


Measured memory_bytes: 3876
#include <bits/stdc++.h>
#include<algorithm>
#define rep(i,n) for (int i=1;i<(n);++i)
using namespace std;

int main(){
    int x;
    int sum=0;
    cin>>x;

    rep(i,x+1){
        rep(j,x+1){
            rep(k,x+1){
                
sum+=__gcd(i,__gcd(j,k));
                    
                }
            }
        }
    

    cout<<sum<<endl;


}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define ort (b+s)/2
#define y2 asrwjaelkf
#define y1 asseopirwjaelkf
#define set multiset
 
using namespace std;
 
typedef long long Lint;
typedef pair<int,int> ii;
typedef pair<int,char> ic;
typedef pair<ii,int> iii;
typedef pair<ii,ii> i4;
 
const int maxn = 1000020;
const int maxm = 10000020;
const int MOd = 998244353;

int a, b;
string s, s2;
vector<int> w[maxn];
int used[maxn];
int segment[maxn], lazy[maxn], n;

void push( int k ) {
	if( lazy[k] ) {
		if( k < n ) {
			lazy[k+k] = lazy[k];
			lazy[k+k+1] = lazy[k];
		}
		segment[k] = lazy[k];
		lazy[k] = 0;
	}
}

void up( int k, int b, int s, int x, int y, int m ) {
		push(k);
	if( x > s || b > y ) return;
	if( x <= b && s <= y ) {
		lazy[k] = m;
		push(k);
		return;
	}
	up( k+k, b, ort, x, y, m );
	up( k+k+1, ort+1, s, x, y, m );
	segment[k] = min(segment[k+k],segment[k+k+1]);
}

void solve() {
	scanf("%d %d",&a,&b);
	n=1;
	while( n < a ) n <<= 1;
	int ans = 0, x = 1;
	set<ii> st;
	set<int> num;
	for(int i=1;i<=b;i++) st.insert(ii(i,i)), num.insert(0);


	for(int i=1,j,k;i<=a;i++) {
		scanf("%d %d",&j,&k);

		set<ii> :: iterator it = st.lower_bound( ii(j, 0) ), it2;
		int v = -1;
		while( it != st.end() && it->fi <= k ) {
			it2 = it;
			it++;
			umax( v, it2->se );
			// cout << it2->se << it2->fi << endl;
			num.erase( num.find(it2->fi-it2->se) );
			st.erase(it2);
		}
		if( k+1 <= b && v != -1 ) {
			num.insert( k+1-v );
			st.insert( ii( k+1, v ) );
		}

		ans++;
		up( 1, 1, n, j, k, k+1 );
		push(1);
		int x = b+1;
		if( num.size() ) x = *num.begin();
		if( x > b ) cout << -1 << endl;
		else cout << ans + x << endl;
	}

}
 
int main() {
	int n = 1;
	// scanf("%d",&n);
	while( n-- ) solve();
 
	return 0;
}

Measured memory_bytes: 49060
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n,m;
    
    vector<ll> node[100001];
    vector<ll> r_node[100001];
    ll old_to_new[100001];
    ll tmp_cc[100001];
    
    std::cin >> n>>m;
    for (int i = 0; i < n+m-1; i++) {
        ll tmp_a,tmp_b;
        std::cin >> tmp_a>>tmp_b;
        
        node[tmp_a].push_back(tmp_b);
        r_node[tmp_b].push_back(tmp_a);
        tmp_cc[tmp_b]++;
    }
    
    stack<ll> kouho; 
    ll root = 0;
    for (int i = 1; i <= n; i++) {
        if(tmp_cc[i]==0){
            kouho.push(i);
            root = i;
        }
    }
    
    ll index = 1;
    
    while(kouho.size()>0){
        ll aaa = kouho.top();
        kouho.pop();
        
        old_to_new[aaa] = index;
        index++;
        
        for (auto e : node[aaa]) {
            tmp_cc[e]--;
            if(tmp_cc[e]==0){
                kouho.push(e);
            }
        }
    }
    
    for (int i = 1; i <= n; i++) {
        ll max_v = 0;
        ll max_i;
        if(i == root){
            std::cout << 0 << std::endl;
            continue;
        }
        for (auto e : r_node[i]) {
            if(max_v<old_to_new[e]){
                max_v = old_to_new[e];
                max_i = e;
            }
        }
        std::cout << max_i << std::endl;
    }
    
   
}

Measured memory_bytes: 13312
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    string s; cin >> s;
    cout << count(s.begin(),s.end(),'1') << endl;
    return 0;
}


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

int main(void)
{
    char a[11],b[11],c[11];
    scanf("%s %s %s",a,b,c);
    printf("%c%c%c",toupper(a[0]),toupper(b[0]),toupper(c[0]));
    return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 105;
int N;
int A[MAX_N];

class Dinic{
public:
  Dinic(int v) : MAX_V(v) {
    init();
    G.resize(v);
    level.resize(v);
    iter.resize(v);
  }

  void init() {
    G.clear(); level.clear(); iter.clear();
  }

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

  void bfs(LL s) {
      fill(begin(level), end(level), -1);
      queue<LL> que;
      level[s] = 0;
      que.push(s);
      while(!que.empty()){
          LL v = que.front(); que.pop();
          for(LL i = 0; i < G[v].size(); i++) {
              edge &e = G[v][i];
              if(e.cap > 0 && level[e.to] < 0) {
                  level[e.to] = level[v]+1;
                  que.push(e.to);
              }
          }
      }
  }

  LL dfs(LL v, LL t, LL f) {
      if(v==t) return f;
      for(LL &i = iter[v]; i < G[v].size(); i++) {
          edge &e = G[v][i];
          if(e.cap > 0 && level[v] < level[e.to]) {
              LL d = dfs(e.to, t, min(f, e.cap));
              if(d > 0) {
                  e.cap -= d;
                  G[e.to][e.rev].cap += d;
                  return d;
              }
          }
      }
      return 0;
  }

  LL maxFlow(LL s, LL t)
  {
      LL flow = 0;
      while(true) {
          bfs(s);
          if(level[t] < 0) {
              return flow;
          }
          fill(begin(iter), end(iter), 0);
          LL f;
          while((f = dfs(s, t, INF)) > 0) {
              flow += f;
          }
      }
  }

private:
  int MAX_V;

  struct edge {
      LL to, cap, rev;
      edge(LL to, LL cap, LL rev) : to(to), cap(cap), rev(rev) {}
  };

  vector<vector<edge>> G;
  vector<LL> level;
  vector<LL> iter;
};

signed main()
{
  cin >> N;
  REP(i,N) {
    cin >> A[i];
  }

  int ans = 0;
  Dinic dinic(N+5);
  REP(i,N) {
    if(A[i] >= 0) {
      ans += A[i];
      dinic.addEdge(i,N+1,A[i]);
    } else {
      dinic.addEdge(N,i,-A[i]);
    }
  }

  FOR(i,1,N+1) {
    for(int j = 2; i*j <= N; j++) { 
      dinic.addEdge(i-1,i*j-1,INF_LL);
    }
  }

  cout << ans - dinic.maxFlow(N,N+1) << endl;

  return 0;
}

Measured memory_bytes: 384