akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repr(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;cin>>n;
    cout<<n*(n-1)/2<<ENDL;
}


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

int main(void)
{
	int n,i,a;
	double x=1.05,y=1,z=100000;
	scanf("%d",&n);
	for(i=0;i<n;i++){;
		z=z*x;
		a=1000*(ceil(z/1000));	
		z=a;
	}
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define gcd __gcd
#define pcount __builtin_popcount
#define pcountll __builtin_popcountll
#define nxtperm next_permutation
//primitive roots: 998244353 - 3; 7340033 - 5
//#pragma 03
//#pragma GCC target ("sse4.2")

const ll mod = 1000000007;		const double PI = acos(-1.);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef complex<double> cd;

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 kawaii = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + kawaii);
    }
};

const int maxn = 1e5 + 100; 
int n, m, dp[maxn];  
bool vis[maxn]; 
vector<vi> adj, p; 
vi a; 

void dfs(int u) 
{
	vis[u] = 1; 
	for(auto v:adj[u])
	{
		if(!vis[v]) dfs(v); 
	}
	a.pb(u); 
}

int ans; 

signed main()
{
//	freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
// 	fast_cin();
	cin >> n >> m; 
	adj.assign(n, vi()); 
	p.assign(n, vi());
	for(int i=0;i<m;i++)
 	{
 		int u, v; 
 		cin >> u >> v; u--; v--;  
 		adj[u].pb(v); 
 		p[v].pb(u); 
	}
	for(int i=0;i<n;i++) if(vis[i] == 0) dfs(i);  // toposort 
	reverse(a.begin(), a.end()); 
	for(int i=0;i<n;i++) 
	{
		int v = a[i]; 
		if(!p[v].size()) continue; 
		for(auto pa:p[v]) dp[v] = max(dp[pa] + 1, dp[v]); 
		ans = max(ans, dp[v]); 
	}
	cout << ans; 
 }

/*
	Test input:
*/


Measured memory_bytes: 14204
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define endl                         '\n'	
#define Ceil(x,y)             ((x+y-1)/y)
#define sz(s)               (int)s.size()
#define RT(x)           return cout<<x,0;
#define mem(x,y)    memset(x,y,sizeof(x))
#define all(v) ((v).begin()), ((v).end())
#define vi                    vector<int>
#define fr(x,y) for(int x=0; x<(y); ++x)
#define fr2(x,z,y) for(int x=z; x<(y); ++x)
#define Rabee_Adel          file();
const double PI = acos(-1), EPS = 1e-7;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
ll gcd(ll x, ll y) { return (!y) ? x : gcd(y, x%y); }
ll lcm(ll x, ll y) { return ((x / gcd(x, y))*y); }
ll mod = 998244353;
ll power(ll x, ll y){if (y == 0)return 1;if (y == 1)return x;ll r = power(x, y / 2) % mod;return r%mod*r%mod*power(x, y % 2) % mod;}
void file() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}
int main()
{
	
	Rabee_Adel
		int n;
	cin >> n; string s;
	set<string >st;
	while (n--)
	{
		cin >> s;
		st.insert(s);

	}
	cout << sz(st);
	
	
		
}

Measured memory_bytes: 19272
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define DBG(X) cout<<" "<<#X<<" : "<<X<<endl
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;

struct Input
{
	int n;char c;char str[10010];string s;ll l;double d;
	int nextInt(){scanf("%d", &n);return n;}
	ll nextLong(){scanf("%lld", &l);return l;}
	double nextDouble(){scanf("%lf", &d);return d;}
	char nextChar(){scanf("%c", &c);return c;}
	string next(){scanf("%s", str);return string(str);}
	string nextLine(){getline(cin, s);return s;}
};
Input in;

double dp[110][110];
int sq[110];

int main(){
	while(1){
		int n = in.nextInt(), t = in.nextInt(), l = in.nextInt(), b = in.nextInt();
		if(n == 0 && t == 0 && l == 0 && b == 0) break;
		for(int i = 0; i < 110; i++){
			sq[i] = 0;
			for(int  j = 0; j < 110; j++) dp[i][j] = 0.0;
		}
		rep(i, l) sq[in.nextInt()] = 1;
		rep(i, b) sq[in.nextInt()] = 2;

		dp[0][0] = 1.0;
		for(int i = 1; i <= t; i++){
			for(int j = 0; j < n; j++){
				for(int k = 1; k <= 6; k++){
					int nxt = j + k;
					if(nxt > n) nxt = n-(nxt-n);
					if(sq[nxt] == 2) dp[i][0] += dp[i-1][j] / 6.0;
					else if(sq[nxt] == 1) 
						dp[i+1][nxt] += dp[i-1][j] / 6.0;
					else
						dp[i][nxt] += dp[i-1][j] / 6.0;
				}
			}
		}
		double ans = 0.0;
		for(int i = 0; i <= t; i++) ans += dp[i][n];
		printf("%.15lf\n", ans);
	}
}

Measured memory_bytes: 1320
n=int(input())
x=list(map(int, input().split()))
maxn=0
for i in range(n):
    if x[i]>maxn:
        maxn=x[i]
    else:
        maxn=maxn
minp=0
for j in range(n):
    minp=minp+(x[j]-1)**2
for i in range(maxn+1):
    power=0
    for j in range(n):
        power=power+(x[j]-i)**2
    if power<minp:
        minp=power
    else:
        minp=minp
print(minp)

Measured memory_bytes: 3064
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}


ll a[100009];


int main() {
	set<ll> A;
	vector<ll> B;
	ll N;
	cin >> N;
	rep(i, N) {
		ll a;
		cin >> a;
		if (A.count(a)) {
			B.push_back(a);
			A.erase(a);
		}
		else {
			A.insert(a);
		}

	}
	if (B.size() < 2) {
		cout << 0 << endl;
		return 0;
	}

	sort(B.begin(), B.end());
	reverse(B.begin(), B.end());
	cout << B.at(0) * B.at(1) << endl;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int &
#define SZ(a) ((int)((a).size()))
#define watch(x) cout << (#x) << " = " << (x) << endl;

const double PI = 2 * acos(0.0);

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


inline void transpose(vector<string> &a) {

    int n = a.size();
    if (n == 0) return;
    int m = a[0].size();
    vector<string> b(m, string(n, ' '));
    fori (i, n) fori (j, m) b[j][i] = a[i][j];
    a = b;
}


template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "{";
    fori (i, SZ(a))
        out << a[i] << vector<string>{", ", "}"}[i + 1 == SZ(a)];
    return out;
}

void smain();

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


#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#define cerr cout
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\n\n\n";
    cout << "TOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
}


const int N = 1e5 + 9;

vi g[N];

int dp[N];
int dfs(int v) {
    if (dp[v] != -1) return dp[v];
    dp[v] = 0;
    for (int to : g[v]) inmax(dp[v], dfs(to) + 1);
    return dp[v];
}
void smain() {

    fill(dp, dp + N, -1);
    int n, m;
    cin >> n >> m;
    fori (i, m) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) inmax(ans, dfs(i));
    cout << ans;
}

Measured memory_bytes: 7552
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#define int long long
#define endre getchar();getchar();return 0
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return kai(n - 1)*n;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int n, m, a[505][505], cnt;
signed main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
			cnt += a[i][j] * (i*(n - i + 1))*(j*(m - j + 1));
		}
	}
	cout << cnt << endl;
	endre;
}


Measured memory_bytes: 5088
import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for i in range(m)]

g=nx.Graph()
g.add_edges_from(s)
di=nx.predecessor(g,source=1)

print("Yes")
for x in range(2,n+1):
      print(di[x][0])


Measured memory_bytes: 221932
import sys

a = int(sys.stdin.readline().strip())
b = int(sys.stdin.readline().strip())
c = int(sys.stdin.readline().strip())
x = int(sys.stdin.readline().strip())

max_500 = int(x/500)
max_500 = min(max_500, a)

count = 0
for i in range(max_500 + 1):
    res = x - 500 * i
    max_100 = int(res/100)
    max_100 = min(max_100, b)
    for j in range(max_100 + 1):
        num_50 = int((res - 100 * j)/50)
        if num_50 <= c:
            count += 1
print(count)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
 
int sum(int n){
  int a = 0;
  while(n > 0){
    a += n%10;
    n /= 10;
  }
  return a;
}
int main() {
  int N;
  cin >> N;
  if(N % sum(N)) cout << "No" << endl;
  else cout <<"Yes" << endl;
}


Measured memory_bytes: 256
D, G = map(int, input().split())
P = list()
for i in range(1, D + 1):
    p, c = map(int, input().split())
    P.append((100 * i, p, c))

ans = float('inf')
for i in range(2 ** D):
    points = 0
    problems = 0
    for d in range(D):
        if (i >> d) & 1:
            i100, p, c = P[d]
            points += i100 * p + c
            problems += p
    if points >= G:
        ans = min(ans, problems)
        continue
    for d in reversed(range(D)):
        if (i >> d) & 1:
            continue
        i100, p, c = P[d]
        for j in range(p):
            if points >= G:
                break
            points += i100
            problems += 1
    ans = min(ans, problems)

print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
 
using namespace std;
 
double EPS = 1e-10;
 
double add(double a,double b){
  if(abs(a+b)<EPS*(abs(a)+abs(b)))return 0;
  return a+b;
}
 
struct point{
  double x,y;
  point() {}
  point(double x,double y):x(x),y(y){
  }
  point operator + (point p){
    return point(add(x,p.x),add(y,p.y));
  }
  point operator - (point p){
    return point(add(x,-p.x),add(y,-p.y));
  }
  point operator * (double d){
    return point(x*d,y*d);
  }
  point operator / (double d){
    return point(x/d,y/d);
  }
};
 
double dist(point a,point b){
	return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}
 
int main(void){
	int n,x,y,v;
	vector<point>P;
	vector<double>V;
	
	while(cin >> n,n){
		P.clear();
		V.clear();
		
		for(int i=0;i<n;i++){
			cin >> x >> y >> v;
			P.push_back(point(x,y));
			V.push_back(v);
		}
		
		
		double r=0.99;
		point now(0,0);
		
		for(double d=10;d>1e-8;d*=r){
			int mx=0;
			double mxd=0;
			
			for(int j=0;j<P.size();j++){
				if(dist(now,P[j])/V[j]>mxd)mx=j,mxd=dist(now,P[j])/V[j];
			}
			
			now=now+((P[mx]-now)/dist(P[mx],now)*d);
		}
		
		double ans=0;
		for(int i=0;i<P.size();i++){
			ans=max(ans,dist(now,P[i])/V[i]);
		}
		printf("%.8f\n",ans);
	}
	
	return 0;
}

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

int main(){
    int h,w;
    cin>>h>>w;

    int numWhite=0;
    vector<vector<int>> map(h,vector<int>(w,-1));
    rep(i,0,h){
        rep(j,0,w){
            char tmp;
            cin>>tmp;
            if(tmp=='.'){
                map.at(i).at(j)=0;
                numWhite++;
            }
        }
    }

    queue<pair<int,int>> q;
    q.push(make_pair(0,0));

    vector<pair<int,int>> delta={make_pair(-1,0),make_pair(1,0),make_pair(0,-1),make_pair(0,1)};

    while(!q.empty()){
        pair<int,int> nowPos=q.front();
        q.pop();

        if(nowPos==make_pair(h-1,w-1)) break;

        for(auto d:delta){
            int next_x=nowPos.first+d.first,next_y=nowPos.second+d.second;
            if(next_x>=0 && next_x<h && next_y>=0 && next_y<w){
                if(map.at(next_x).at(next_y)==0){
                    map.at(next_x).at(next_y)=map.at(nowPos.first).at(nowPos.second)+1;
                    q.push(make_pair(next_x,next_y));
                }
            }
        }
    }

    if(map.at(h-1).at(w-1)==0) cout<<-1<<endl;
    else cout<<numWhite-map.at(h-1).at(w-1)-1<<endl;
}

Measured memory_bytes: 256
def s()
  gets().chomp
end
def i()
  gets.to_i
end
def li()
  gets.split.map(&:to_i)
end
def ili()
  n = gets.to_i
  as = gets.split.map(&:to_i)
  [n, as]
end
class Array
  def sum
    total = 0
    self.each do |item|
      total += item
    end
    total
  end
end

def solve(n,m)
  sq = Math.sqrt(m).floor
  res = []
  (1..sq).each{|i|
    if m%i == 0
      pair = m/i
      if i >= n || pair >= n
        if i  >= n && pair >= n
          res.push([i,pair].max)
        else
          res.push([i,pair].min)
        end
      end  
    end
  }
  return res.max
end

n, m = li()
p solve(n,m)


Measured memory_bytes: 1788
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpi(x1) fprintf(stderr, "#%s.%d (%s) = (%d)\n", __func__, __LINE__, #x1, x1);
#define dumpii(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%d, %d)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpiii(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%d, %d, %d)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct Solver {
  long n, l;
  std::vector<std::string> xs;
  Solver() {
    S002 r;
    r >= n >= l >n>= xs;
  }
  void solve() {
    std::sort(xs.begin(), xs.end());
    for(auto& x : xs) {
      printf("%s", x.c_str());
    }
    putchar('\n');
  }
};
 
int main() {
  for(;;) std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char*argv[])
{
   int a,b ;
   scanf("%d %d",&a,&b);
  // if(a+b==3) printf("3\n");
//   else if(a+b==4) printf("2\n");
    printf("%d\n",(3*a+b)/2);
	return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    int ans = 0;
    vector<int> v(n);
    vector<int> c(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
    }
    for (int i = 0; i < n; i++)
    {
        if(v[i]-c[i]>0)
        {
            ans += v[i] - c[i];
        }
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
	using namespace std;
	typedef long long int ll;
	typedef pair<int,int> pii;
	#define MAX 1000000
	#define mp make_pair
	#define pb push_back
	#define F first
	#define S second
	#define _min(x,y) x = min(x,y)
	ll h[MAX],dp[MAX];
	int main(){
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		
		ll n;cin >> n;
		cin >> h[0] >> h[1];
		dp[1] = abs(h[0]-h[1]);
		//dp[0] = (unsigned int)-1;
		for(int i = 2;i < n;i++){
			cin >> h[i];
			dp[i] = min( dp[i-1] + abs( h[i] - h[i-1] ) , dp[i-2] + abs( h[i] - h[i-2] ) );
		}
		/*for(int i = 0;i < n;i++){
			cout << dp[i] << ' ';
		}*/
		cout << dp[n-1];
		return 0;
	}


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

#define int long long
#define vi vector <int>
#define endl "\n"
#define vvi vector <vector<int> >
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>=b;i--)
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define init(i,k) memset(i,k,sizeof i)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
const int N=1e5+5 , MOD=1e9+7;\

vvi adj(N);
int in_degree[N]={0};
bool visited[N]={0};
int dp[N]={0};

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

void dfs(int v)
{
	visited[v] = 1;
	for(int x:adj[v])
	{
		dp[x] = max(dp[x],1+dp[v]);
		in_degree[x]--;
		if(in_degree[x]==0 && !visited[x])
			dfs(x);
	}
}

void solve()
{
    int n,m;
    cin >> n >> m;
    while(m--)
    {
    	int x,y;
    	cin >> x >> y;
    	adj[x].pb(y);
    	in_degree[y]++;
    }

    for(int i=1;i<n+1;i++)
    {
    	if(in_degree[i]==0 && !visited[i])
    		dfs(i);
    }
    int ans=0;
    rep(i,1,n+1)
    {
    	ans = max(ans,dp[i]);
    }
    cout << ans << endl;
}

signed main()
{
    speed;
    
 //    int t; cin >> t;
 //    rep(tt,1,t+1)
 //    {
	// cout <<"Case #"<<tt<<": ";
	solve();
 //    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "yes" << endl;}
void no(){ cout << "no" << endl;}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  while(1){
    ll h, w;
    cin >> h >> w;
    if(h == 0 && w == 0) return 0;
    REP(i,h){
      REP(j,w){
        cout << "#";
      }
      cout <<endl;
    }
    cout <<endl;
  }


  return 0;
}






Measured memory_bytes: 3148
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = (1<<30);
 
int main() {
  string s;
  cin >> s;

  if(s[s.size()-1] != 's') {
    cout << s+'s' << endl;

  }
  else {
    cout << s+"es" << endl;
    
  }

}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N;
    Scd(N);

    int a;

    double ans = 0;

    Rep(i,N){
        Scd(a);
        ans += 1.0 / a;
    }

    printf ("%lf\n", 1/ans);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#define MAX 1000001

struct qq {
    char name[100];
    int time;
};

int head, tail, n;
qq Q[MAX];

void enqueue(qq a) {
    Q[tail] = a;
    tail = (tail+1) % MAX;
}

qq dequeue() {
    head = (head+1) % MAX;
    return Q[head-1];
}

int main() {
    int elapse = 0, c;
    n = 0;
    int q;
    qq u;
    
    scanf("%d %d", &n, &q);
    for (int i = 1; i <= n; i++) {
        std::cin >> Q[i].name;
        std::cin >> Q[i].time;
    }
    head = 1;
    tail = n+1;
    
    while (head != tail) {
        u = dequeue();
        c = std::min(u.time, q);
        u.time -= c;
        elapse += c;
        if(u.time>0) enqueue(u);
        else {
            printf("%s %d\n", u.name, elapse);
        }
    }
    
    return 0;
}

Measured memory_bytes: 22400
#include <iostream>
using namespace std;
 
int main(void)
{
    int N,K,X,Y;
    cin >> N >> K >> X >> Y;

    if(N < K){
        cout << N * X << endl;
    }
    else{
    cout << N * X - (N-K) * (X-Y) << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;

char s[MAXN];
int main() {
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	ll ans = 0; int now = 0, pos = 1;
	while (pos <= n) {
		if (s[pos] == 'A') now++, pos++;
		else if (s[pos] == 'B' && s[pos + 1] == 'C') ans += now, pos += 2;
		else now = 0, pos++;
	}
	printf("%lld",ans);
	return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#define INF 1000000009
#define LINF 1000000000000000009
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
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; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll mod = 1000000007;

ll fac[1000010];

ll modinv(ll a) {
	ll b = mod, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= mod;
	if (u < 0) u += mod;
	return u;
}

void modfac() {
	fac[0] = 1;
	for (ll i = 1; i < 1000010; i++) {
		fac[i] = (fac[i - 1] * i) % mod;
	}
}

ll modperm(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	else return (fac[n] * modinv(fac[n - k])) % mod;
}

ll modcomb(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	else return ((fac[n] * modinv(fac[k])) % mod*modinv(fac[n - k])) % mod;
}

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	ll ans = 0;
	sort(all(a));
	modfac();
	for (ll i = 0; i < n; i++) {
		ll base = modcomb(n - i - 1, k - 1);
		ans += (mod - base) * (a[i] + mod) % mod;
		ans %= mod;
	}
	//cout << ans << endl;
	for (int i = n - 1; i >= 0; i--) {
		ll base = modcomb(i, k - 1);
		if (base > 0) ans += base * (a[i] + mod) % mod;
		ans %= mod;
	}
	cout << ans << endl;
}

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

#define INF 0x3fffffff

typedef long long int LLI;
typedef pair<int, int> Data;
typedef pair<int, Data> Pair;

int N;
LLI ans;
int as[300][300];
int ds[300][300];
priority_queue<Pair> que;

int main() {
  scanf("%d", &N);
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      scanf("%d", &as[i][j]);
      ds[i][j] = as[i][j];
      if (i < j) {
        ans += ds[i][j];
        que.push(Pair(ds[i][j], Data(i, j)));
      }
    }
  }

  for (int k=0; k<N; k++) {
    for (int i=0; i<N; i++) {
      for (int j=0; j<N; j++) {
        as[i][j] = min(as[i][j], as[i][k] + as[k][j]);
      }
    }
  }

  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      if (as[i][j] != ds[i][j]) {
        puts("-1");
        return 0;
      }
    }
  }

  while (!que.empty()) {
    Pair p = que.top(); que.pop();
    int md = p.first;
    int u, v;
    tie(u, v) = p.second;
    ds[u][v] = ds[v][u] = INF;
    for (int k=0; k<N; k++) {
      ds[u][v] = ds[v][u] = min(ds[u][v], ds[u][k] + ds[k][v]);
    }
    if (ds[u][v] == md) ans -= md;
  }
  printf("%lld\n", ans);
}


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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000
#define MAX_N 1000000
#define MAX_E 10000000
struct edge {int u, v, cost; };

bool comp(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}

edge es[MAX_E];
int V, E;

int par[MAX_N]; // 親
int depth[MAX_N]; // 木の深さ

// n要素で初期化
void init(int n) {
	rep(i, 0, n) {
		par[i] = i;
		depth[i] = 0;
	}
}

// 木の根を求める
int find(int x) {
	if(par[x] == x) return x;
	else return par[x] = find(par[x]);
}

// xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(depth[x] < depth[y]) {
		par[x] = y;
	} else {
		par[y] = x;
		if(depth[x] == depth[y]) depth[x]++;
	}
}

// xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}

int kruskal() {
	sort(es, es + E, comp);
	init(V);
	int res = 0;
	rep(i, 0, E) {
		edge e = es[i];
		if(!same(e.u, e.v)) {
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}

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

	cin >> V;
	vector<pair<ll, ll> > va, vb;
	rep(i, 0, V) {
		int x, y;
		cin >> x >> y;
		va.push_back(make_pair(x, i));
		vb.push_back(make_pair(y, i));
	}
	vsort(va);
	vsort(vb);

	E = 0;
	rep(i, 0, V - 1) {
		int dx = abs(va[i].first - va[i + 1].first);
		es[E].u = va[i].second;
		es[E].v = va[i + 1].second;
		es[E].cost = dx;
		E++;
		es[E].u = va[i + 1].second;
		es[E].v = va[i].second;
		es[E].cost = dx;
		E++;

		int dy = abs(vb[i].first - vb[i + 1].first);
		es[E].u = vb[i].second;
		es[E].v = vb[i + 1].second;
		es[E].cost = dy;
		E++;
		es[E].u = vb[i + 1].second;
		es[E].v = vb[i].second;
		es[E].cost = dy;
		E++;
	}

	cout << kruskal() << endl;


}


Measured memory_bytes: 16228
t_HP,t_AT,a_HP,a_AT=map(int,input().split())
while 1:
    a_HP-=t_AT

    if a_HP<=0:
        print("Yes")
        exit()

    t_HP-=a_AT
    
    if t_HP<=0:
        print("No")
        exit()
    

Measured memory_bytes: 61492
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			var inputArray = retreiveStringArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			var str = inputArray[0];

			//答えの出力
			var ans = str=="ARC"?"ABC":"ARC";
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 25880
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)44e12;//ごめん
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int main(void){
	int n,i;cin>>n;
	vector<int>a(n);
	for(i=0;i<n;i++){cin>>a[i];}
	SO(a);REV(a);a.pub(0);
	pair<int,int>win=mp(mod,1);//0->fir
	int mae=-1;
	for(i=0;i<n;i++){if(a[i]!=a[i+1]){mineq(win,mp(max(a[i+1],mae+1),(a[i]+i)%2));mae=i;}}
	cout<<(win.sec==0?"First":"Second")<<endl;
	RE;
}


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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i = (a); i >= (b); i--)
#define FORR(i,a,b) for (int i = (a); i > (b); i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

 	int n;
 	char s[100005];
 	bool A[100005];
 	cin >> n >> s;
 	s[n]=s[0];
 	s[n+1]=s[1];

 	FOR(i,0,4){
 		A[0]=i&1;
 		A[1]=(i>>1)&1;
 		for(int i=2;i<n+2;i++){
			if(A[i-1]^(s[i-1]=='o'))
				A[i]=A[i-2]^1;
			else 
				A[i]=A[i-2];
		}
 		if(A[n]==A[0] && A[n+1]==A[1]){
 			FOR(i,0,n){
 				if(A[i])
 					cout << 'S';
 				else
 					cout << "W";
 			}
 			return 0;
 		}
 	}

 	cout << -1 << endl;
    
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dl double long
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rrep(i, m, n) for(ll i = (ll)(m); i > (ll)(n); --i)
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;

int main(void){
    bool can = false;
    string s, t;
    cin >> s >> t;
    if(t.find(s) == 0 && t.size() == s.size()+1) can = true;
    cout << (can? "Yes":"No") << endl;
    
    return 0;
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int k;
	scanf("%d", &k);
	vector<vector<pair<int, int>>> a(k, vector<pair<int, int>>(0));
	for(int i = 0; i < k; ++i)
	{
		a[i].push_back(make_pair(0, i * 10 % k));
		a[i].push_back(make_pair(1, (i + 1) % k));
	}
	vector<int> b(k, -1);
	deque<pair<int, int>> d;
	d.push_front(make_pair(1, 1));
	for(int t, u; !d.empty(); )
	{
		t = d.front().first;
		u = d.front().second;
		d.pop_front();
		if(b[u] != -1)
		{
			continue;
		}
		b[u] = t;
		for(int i = 0; i < a[u].size(); ++i)
		{
			if(a[u][i].first)
			{
				d.push_back(make_pair(t + 1, a[u][i].second));
			}
			else
			{
				d.push_front(make_pair(t, a[u][i].second));
			}
		}
	}
	printf("%d\n", b[0]);
}

Measured memory_bytes: 6912
fn main(){
  loop {
    let n: u32 = read();

    if n == 0 { break; }
  
    let mut fld: Vec<Vec<usize>> = vec![vec![0; 5]; 5000];
    let mut pa: Vec<usize> = vec![0; 5];
    
    for _ in 0 .. n {
      let tv: Vec<usize> = read_vec();
      let d = tv[0];
      let p = tv[1];
      let q = tv[2] - 1;

      put_block(&mut fld, &mut pa, d, p, q);
    }

    let cnt: usize = count_block(&fld, &pa);

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

fn read<T>() -> T
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.trim().parse().unwrap()
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}

// fn print_field(fld: &Vec<Vec<usize>>, pa: &Vec<usize>){
//   let mp: &usize = pa.iter().max().unwrap();

//   println!("----------");
//   for i in (0..*mp).rev() {
//     println!("{:04}:{}{}{}{}{}", i, fld[i][0], fld[i][1], fld[i][2], fld[i][3], fld[i][4])
//   }
//   println!("----------");
// }

fn put_block(fld: &mut Vec<Vec<usize>>, pa: &mut Vec<usize>, d: usize, p: usize, q: usize) {
  if d == 1 {
    let mx: usize = (q..q+p).map(|i| pa[i]).max().unwrap();

    for i in q .. q + p {
      fld[mx][i] = 1;
      pa[i] = mx + 1;
    }

    if fld[mx].iter().all(|i| *i == 1) {
      let tp: usize = (0..5).map(|i| pa[i]).max().unwrap();

      for i in mx .. tp {
        for j in 0 .. 5 {
          fld[i][j] = fld[i+1][j];
        }
      }
      
      for j in 0 .. 5 {
        for i in (0 .. pa[j]).rev() {
          if fld[i][j] == 1 { break; }
          else { pa[j] = i; }
        }
      }
    }
  } else {
    for i in pa[q] .. pa[q] + p {
      fld[i][q] = 1;
    }
    pa[q] = pa[q] + p;

    for i in (pa[q]-p .. pa[q]).rev() {
      if fld[i].iter().all(|i| *i == 1) {
        let tp: usize = (0..5).map(|i| pa[i]).max().unwrap();

        for j in i .. tp {
          for k in 0 .. 5 {
            fld[j][k] = fld[j+1][k];
          }
        }
      }
    }
    
    for j in 0 .. 5 {
      for i in (0 .. pa[j]).rev() {
        if fld[i][j] == 1 { break; }
        else { pa[j] = i; }
      }
    }
  }
}

fn count_block(fld: &Vec<Vec<usize>>, pa: &Vec<usize>) -> usize {
  let mut cnt: usize = 0;

  for j in 0 .. 5 {
    for i in 0 .. pa[j] {
      if fld[i][j] == 1 { cnt += 1; }
    }
  }
  cnt
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; ll K; cin>>N>>K;
    vi p(N);
    rep(i,N) cin>>p[i];
    rep(i,N) p[i]--;
    vll C(N);
    rep(i,N) cin>>C[i];
    ll ans=-1e9;
    rep(i,N){
        vi cycle;
        ll sum=0;
        vll maxi; maxi.pb(0LL);
        ll cand=-1e9;
        int cnt=0;
        cycle.pb(C[i]); cnt++;
        sum += C[i];
        chmax(cand,sum);
        maxi.pb(max(maxi.back(),sum));
        int cur = p[i];
        while(cur!=i){
            cycle.pb(C[cur]); cnt++;
            sum += C[cur];
            if (K>=cnt) chmax(cand,sum);
            maxi.pb(max(maxi.back(),sum));
            cur = p[cur];
        }
        int C = cycle.size();
        // rep(j,C+1) cout<<maxi[j]<<" "; cout<<endl;
        if (sum>=0 && C<=K){
            ll t = K/C;
            ll ex = K-t*C;
            chmax(cand, (t-1)*sum + maxi[C]);
            chmax(cand, t*sum + maxi[ex]);
        }
        chmax(ans,cand);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3812
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()

using namespace std;

int main () {
  int n; cin>>n;
  ll ans=0;
  for(int i=1;i<n;i++){
    rep2(j,1,sqrt(i)+1){
      if(i%j==0){
        ans++;
        if(i!=j*j)ans++;
        //cout <<i<<j<<endl;
      }
    }
  }
  cout <<ans<<endl;
        
}



Measured memory_bytes: 3676
const main = (inputs) => {
  var yen = Number(inputs[0]);
  var ureshi = 0;
  ureshi = Math.floor(yen / 500) * 1000;
  yen = yen - Math.floor(yen / 500) * 500;

  ureshi = ureshi + Math.floor(yen / 5) * 5;

  console.log(ureshi);
}
main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));

Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main(){
  int a, b;
    cin >> a >> b;
    if(a<=5) cout << 0;
    else if(a<=12) cout << b/2;
    else cout << b;
    cout << endl;
}


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

int main()
{
	int n, A, B;
	cin >> n >> A >> B;
	string s;
	cin >> s;
	s = ' ' + s;
	int nowa = 0, nowb = 0;
	for (int i = 1; i < s.size(); ++i)
	{
		if (s[i] == 'a')
		{
			if(nowa + nowb < A + B)
			{
				cout << "Yes" << endl;
				nowa++;
			}
			else
			{
				cout << "No" << endl;
			}
		}
		else if(s[i] == 'b')
		{
			if(nowa + nowb < A + B && nowb < B)
			{
				cout << "Yes" << endl;
				nowb++;
			}
			else
			{
				cout << "No" << endl;
			}
		}
		else
		{
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

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

    int ans = a + a*a + a*a*a;

    cout <<  ans << endl;

    return 0;
}


Measured memory_bytes: 3608
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

vec eratosthenes(ll N){
  ll i;
  vec ch(N+1,1),p;
  ch[0]=ch[1]=0;
  rep(i,N+1){
    if(ch[i]){
      p.push_back(i);
      for(ll j=2;i*j<=N;j++){
        ch[i*j]=0;
      }
    }
  }
  return ch;
}
int main(){
  ll x,N,M,ans;
  cin>>N>>M>>x;
  ans=M/x;
  if(N!=0){
    ans-=(N-1)/x;
  }else{
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let v: Vec<i64> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
    let (x, y) = (v[0], v[1]);

    let ans: i64 = vec![(x + y).abs() + 1, y - x, x - y + 2]
        .iter()
        .filter(|&&x| x >= 0)
        .map(|&x| x)
        .min()
        .unwrap();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 2e5 + 5;
int n, a[maxn];
ll cnt[maxn], w[maxn], ans;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	cin >> n;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		cnt[a[i]]++;
	}
    for(int i = 1; i <= n; ++i) {
    	if(!w[a[i]]) {
    		w[a[i]] = cnt[a[i]] * (cnt[a[i]] - 1) / 2;
    		ans += w[a[i]];
		}
	}
	for(int i = 1; i <= n; ++i) {
		ll tmp = 0;
		if(cnt[a[i]] > 2) tmp = (cnt[a[i]] - 1) * (cnt[a[i]] - 2) / 2;
		cout << ans - w[a[i]] + tmp << endl;
	}
	return 0;
}

Measured memory_bytes: 5504