akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var A = G;
		var B = G;
		WriteLine((A[0] - B[0]) * (A[1] - B[1]));
	}
}


Measured memory_bytes: 13268
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O20")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#include <complex>
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << x << "\n")
using ll = long long; using ld = long double; using namespace std;

#ifndef __GNUC__
string text =
R"X(
8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310
)X";
stringstream iss{text};
#endif

class AverageLength
{
	ll N{0};
	vector<complex<ld>> p;
	void inp( ) {
		iss >> N; p.resize(N); ld x, y;
		rep(n, N) { iss >> x >> y;	p[n] = complex<double>(x, y); }
		//for_each(begin(p), end(p), [](auto x) { cout << x << "\n"; });
	}
	void changeKeiro( ) {
		ld total{0};
		vector<ll> v(N);
		rep(n, N) { v[n] = n; }
		do {
			for (ll i = 0; i < N - 1; ++i) {
				total += abs(p[v[i]] - p[v[i + 1]]);
			}
		} while (next_permutation(begin(v), end(v)));
		for (ll n = 1; n <= N; ++n) total /= n;
		p(total);
	}
public:
	void procedures( ) {
		inp( );
		changeKeiro( );
	}
};
//https://atcoder.jp/contests/abc145/tasks/abc145_c
int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	cout << fixed << setprecision(15);
	class AverageLength a; a.procedures( );
}

Measured memory_bytes: 3844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    int H, W; cin >> H >> W;
    do {
        char state[H][W];
        bool used[H][W] = {true};
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cin >> state[i][j];
                used[i][j] = true;
            }
        }

        int i = 0, j = 0;
        while (state[i][j] != '.' && used[i][j] == true) {
            used[i][j] = false;
            if (state[i][j] == '>') j++;
            else if (state[i][j] == '<') j--;
            else if (state[i][j] == '^') i--;
            else i++;

        }
        if (used[i][j] == false) cout << "LOOP" << endl;
        else cout << j << " " << i << endl;
        cin >> H >> W;
    } while (H != 0 && W != 0);
    return 0;

}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using T = tuple<int, int, int>;

template <typename T>
struct Dijkstra {
  struct Edge {
    int to;
    T cost;
  };
  vector<int> prev;
  vector<vector<Edge>> g;
  Dijkstra(int n) : prev(n, -1), g(n) {}

  void addEdge(int u, int v, T w) {
    g[u].push_back({v, w});
  }
  vector<T> build(int s) {
    vector<T> dist(g.size(), -1);
    using Node = pair<T, int>;
    priority_queue<Node, vector<Node>, greater<Node>> pq;
    pq.push({dist[s] = 0, s});

    while (!pq.empty()) {
      auto d = pq.top().first;
      auto u = pq.top().second;
      pq.pop();
      if (dist[u] < d) continue;
      for (auto&& v : g[u]) {
        if (dist[v.to] < 0 || dist[v.to] > dist[u] + v.cost) {
          dist[v.to] = dist[u] + v.cost;
          prev[v.to] = u;
          pq.push({dist[v.to], v.to});
        }
      }
    }
    return dist;
  }
  vector<int> getPath(int t) {
    vector<int> path;
    for (; t != -1; t = prev[t]) path.push_back(t);
    reverse(begin(path), end(path));
    return path;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  Dijkstra<ll> g(n);
  for (int i = 0; i < n - 2; i++) {
    g.addEdge(i + 1, i, 0);
  }
  for (int i = 0; i < m; i++) {
    int l, r, c;
    cin >> l >> r >> c, l--, r--;
    g.addEdge(l, r, c);
  }
  auto d = g.build(0);
  cout << ((d[n - 1] >= 0) ? d[n - 1] : -1) << endl;
}


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

int main(){
  int A,B,C;
  cin>>A>>B>>C;

  if((A==B&&A!=C) || (A==C&&A!=B) || (B==C&&A!=B)){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef long double lldb;
typedef pair<ll, ll>  ii;
typedef pair<lldb, lldb>  iidb;
typedef pair<ll, ii>  iii;
typedef vector<ll>     vi;
typedef vector<ll>      vll;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9+7;
const lldb PI = acos(-1);
#define initseg ll new_nodo=(pnodo*2),mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 320000
#define offset 200
#define ptr nodo*
const ll MOD=1e9+7;
ll v[tam];
int main()
{
	int n;
	cin>>n;
	ll answer=0,tot=0;
	forr(i,0,n)
	{
		cin>>v[i];
		v[i]%=MOD;
		tot+=v[i];
		tot%=MOD;
	}
	forr(i,0,n)
	{
		tot-=v[i];tot%=MOD;tot+=MOD;tot%=MOD;
		answer+=((tot%MOD)*(v[i]%MOD));
		answer%=MOD;
	}
	cout<<answer<<endl;
}

Measured memory_bytes: 5192
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static void Main(string[] args)
    {
        var n = Int64.Parse(Console.ReadLine());
        var ts = new List<Int64>();
        ts.Add(Int64.Parse(Console.ReadLine()));
        ts.Add(Int64.Parse(Console.ReadLine()));
        ts.Add(Int64.Parse(Console.ReadLine()));
        ts.Add(Int64.Parse(Console.ReadLine()));
        ts.Add(Int64.Parse(Console.ReadLine()));
        var tm = ts.Min();
        Console.WriteLine(4 + ((n % tm == 0) ? n / tm : n / tm + 1));
    }
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    vector<int> L(N);
    rep(i, N) cin >> L[i];
    sort(all(L));
    int cnt = 0;
    rep(i, N) for (int j = i+1; j < N; j++) for (int k = j+1; k < N; k++) {
        if (L[k] < L[i] + L[j]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>

int main(int argc, char *argv[])
{
  int A,B,C,X,Y;
  std::vector<int> ans;
  scanf("%d %d %d %d %d",&A,&B,&C,&X,&Y);
  ans.push_back(C * 2 * std::max(X, Y));
  ans.push_back(A * X + B * Y);
  if (X < Y) {
    ans.push_back(C * 2 * X + B * (Y - X));
  } else {
    ans.push_back(C * 2 * Y + A * (X - Y));
  }

  printf("%d\n", *std::min_element(ans.begin(), ans.end()));
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
#include <cctype>
#include <iterator>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  int n;
  cin >> n;
  vecint l(n, 0);
  REPe(e, l) { cin >> e; }
  sort(all(l));
  int ans = 0;
  REP(i, n) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        if (l[i] + l[j] > l[k] && l[i] > l[k] - l[j] && l[i] != l[j] &&
            l[j] != l[k]) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3652
#include <iostream>

using namespace std;

typedef long long ll;

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

ll f(ll x, int c, int d) {
    ll res = x;
     res -= x/c;
     res -= x/d;
     res += x/lcm(c, d);
     return res;
}

int main() {
    ll a, b;
    int c, d;
    cin >> a >> b >> c >> d;
    ll ans = f(b, c, d) - f(a-1, c, d);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/
const int MAX = 2001;
string grid[MAX];
int main()
{
    //freopen("input.txt", "r", stdin);
    SPEED
    int n;
    cin >> n;
    ld denom = 0;
    FOR(i, 0, n)
    {
        ld num;
        cin >> num;
        denom += 1.0 / num;
    }
  //  DEBUG(denom)
    cout << fixed << setprecision(15);
    cout << 1.0 / denom;
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		long[] pol = new long[N + 1];
		for (int i = 0; i <= N; i++) {
			pol[N-i] = sc.nextInt();
		}
		boolean[] primes = new boolean[N + 2];
		Arrays.fill(primes, true);
		for (int i = 2; i < primes.length; i++) {
			if (primes[i]) {
				for (int j =  i + i; j < primes.length; j+=i) {
					primes[j] = false;
				}
				if (divides(pol.clone(), i)) out.println(i);
			}
		}
		int p0 = (int)Math.abs(pol[0]);
		for (int i = 0; i <= N; i++) {
			p0 = gcd(p0, Math.abs((int)pol[i]));
		}
		for (int prime = 2; prime * prime <= p0 ; prime++) {
			if (p0 % prime == 0) {
				if (prime >= primes.length && divides(pol.clone(), prime)) out.println(prime);
			}
			while (p0 % prime == 0) p0 /= prime;
		}
		if (p0 > 1 && p0 >= primes.length && divides(pol.clone(), (int)p0)) out.println(p0);
		
		out.flush();
	}
	
	static int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a%b);
	}
	
	static boolean divides(long[] pol, int p) {
		int n = pol.length - 1;
		while (n >= p) {
			pol[n - p + 1] += pol[n];
			pol[n] = 0;
			n--;
		}
		for (int i = 0; i < p && i < pol.length; i++) {
			if (pol[i] % p != 0) return false;
		}
		return true;
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 62172
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test(n) cout << "test" << n << endl;
#define fixsp(n) fixed << setprecision(n)
#define defsp(n) defaultfloat << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define iikae auto&
#define vector3D(K, N, M, DP) vector<vector<vector<ll>>> DP(K, vector<vector<ll>>(N, vector<ll>(M)));
#define vector4D(K, N, M, O, DP) vector<vector<vector<vector<ll>>>> DP(K, vector<vector<vector<ll>>>(N, vector<vector<ll>>(M, vector<ll>(O))));
#define zenbu(a) a.begin(), a.end()
#define rzenbu(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}
/* ここからコード開始 */

int main(){
  kyopro;
  ll N, M;
  cin >> N >> M;
  vector<ll> A(M,0), B(M,0);
  rep(i, 0, M){
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    }
  UnionFind<ll> uf(N);
  vector<ll> ans(M);
  ans[M-1] = N*(N-1)/2;
  rem(i, M-1, 0){
    ans[i-1] = ans[i] - (uf.root(A[i]) == uf.root(B[i]) ? 0 : uf.size(uf.root(A[i])) * uf.size(uf.root(B[i])));
    uf.merge(A[i], B[i]);
  }
  for(auto&& i : ans) cout << i << rt;
}

Measured memory_bytes: 4480
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;

int main(){
    double n,d,x,ans=0;
    cin>>n>>d>>x;
    for(;n>0;n--){
	ans+=d+(n-0.5)*x;
	//d*=(n+x*2.5+1)/n;
	d=d*2*(n+1)+x*5; d/=2.0*n;
	x*=(2/n+1);
    }
    printf("%.9lf\n",ans);
    return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if(min(B,D)-max(A,C)<0) cout << 0 << endl;
  else cout << min(B,D)-max(A,C) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <random>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0)
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

struct Edge {
  lli to, cost;
  Edge(lli to=0, lli cost=0) : to(to), cost(cost) {}
};

lli n, q, k;
vector<Edge> e[100010];
lli dist[100010];

void dfs(lli vtx, lli prev, lli cost) {
  dist[vtx] = cost;
  for (Edge& f : e[vtx]) {
    if (f.to != prev) {
      dfs(f.to, vtx, cost + f.cost);
    }
  }
}

int main() {
  cin >> n;
  for (lli i=0; i<n-1; ++i) {
    lli a, b, c; cin >> a >> b >> c;
    e[a].emplace_back(b, c);
    e[b].emplace_back(a, c);
  }
  cin >> q >> k;

  dfs(k, -1, 0);

  cerr << "ready\n";

  for (lli i=0; i<q; ++i) {
    lli x, y; cin >> x >> y;
    cout << dist[x] + dist[y] << '\n';
  }
  return 0;
}


Measured memory_bytes: 14336
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

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

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    z->parent = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->left = z;
        }
        else {
            y->right = z;
        }
    }
}

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

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

int main() {
    int n, i, x;
    string com;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        cin >> com;
        if (com == "insert") {
            scanf("%d", &x);
            insert(x);
        } else if (com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 26616
S=gets.strip
cnt=0
cn=1
i=0
while true
    if cn==1 && S[i]!=S[i+1]
        cnt+=1
    elsif cn==1 && S[i]==S[i+1]
        cnt+=1
        i+=1
        cn=2
    elsif cn==2
        cn=1
        cnt+=1
    end
    i+=1
    break if i>=S.size
end
puts cnt


Measured memory_bytes: 2172
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int MOD = 1e9+7;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    // C++にするの忘れない
    string s;
    cin >> s;
    if (s == "ARC") cout << "ABC" << endl;
    else cout << "ARC" << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
int p=1000,s=0;
  p-=n;
  s+=p/500;
  p%=500;
  s+=p/100;
  p%=100;
  s+=p/50;
  p%=50;
  s+=p/10;
  p%=10;
  s+=p/5;
  p%=5;
  s+=p/1;
  p%=1;
  cout<<s<<endl;}

}

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

int main(){
    int N;
    cin >> N;
    int count=0;
    int ans=0;
    for(int i=1;i<=N;i++){
        int a;
        cin >> a;
        if(i==a){
            count++;            
        }
        else{
            if(count%2==0) ans+=count/2;
            else ans+=count/2+1;
            count=0;
        }
        if(i==N){
            if(count%2==0) ans+=count/2;
            else ans+=count/2+1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.second<b.second);
}
int main()
{
    ios;
    int n,d;
    cin>>n>>d;
    cout<<ceil(n/(2.0*d+1.0))<<endl;



}
























































Measured memory_bytes: 3804
function Main(input) {
    tmp = input.split(" ");
    a = parseInt(tmp[0], 10);
    b = parseInt(tmp[1], 10);
    c = parseInt(tmp[2], 10);
    k = parseInt(tmp[3], 10);
  
    var result = 0;
    var count = 0;
    var nokori = k;


  while(nokori > count){
    if (nokori >= a) {
      result += (a*1);
      count += a;
      nokori -= a;
    } else{
      result += (nokori*1);
      count += nokori;
      nokori -= nokori;
    }

    if (nokori >= b) {
      result += (0);
      count += b;
      nokori -= b;
    } else{
      result += (0);
      count += nokori;
      nokori -= nokori;
    }
    if (nokori >= c) {
      result += (c * -1);
      count += c;
      nokori -= c;
    } else{
      result += (nokori * -1);
      count += nokori;
      nokori -= nokori;
    }
  }
  

    console.log(result);
    
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29872
#include<iostream>

int main(void){
    long N, A, B, ans;
    std::cin >> N >> A >> B;
    ans = ( N/(A+B) )*A;
    if(N%(A+B) >= A){
        ans += A;
    }else{
        ans += N%(A+B);
    }

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

Measured memory_bytes: 256
n,a,b=map(int,input().split())
ans=10**30
if (a+b-1)%2==0:
  ans=min(ans,(a+b-1)//2)
if (2*n-b-a+1)%2==0:
  ans=min(ans,(2*n-b-a+1)//2)

if (b-a)%2==0:
  ans=min(ans,(b-a)//2)
elif a==1 or b==n:
  ans=min(ans,(b-a+1)//2)
else:
  ans=min(ans,min(b-1,n-a))
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>

using namespace std;

void solve()
{
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
	}
	vector<bool> visited(N);
	int pos = 1;
	bool isOK = false;
	int cnt = 0;
	while (true)
	{
		if (pos == 2)
		{
			isOK = true;
			break;
		}
		--pos;
		if (visited[pos])
		{
			break;
		}
		visited[pos] = true;
		pos = a[pos];
		++cnt;
	}
	if (isOK)
	{
		cout << cnt << endl;
	}
	else
	{
		cout << -1 << endl;
	}
}

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

Measured memory_bytes: 640
N ,M = map(int, input().split())
li = []
num = [0] * (N + 1)
for i in range(M):
    li.append(list(input().split()))
countAC = 0
countWA = 0
for i in range(M):
    if num[int(li[i][0])] != -1:
        if li[i][1] == "AC":
            countAC += 1
            countWA +=num[int(li[i][0])]
            num[int(li[i][0])] = -1
        else:
            num[int(li[i][0])] += 1

print(countAC, countWA)


Measured memory_bytes: 66648
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
template<class T> inline void chmin(T &a, T b){if(a>=b)a=b;}
template<class T> inline void chmax(T &a, T b){if(a<=b)a=b;}
typedef long long ll;
const int INF = 1e9;

int N, digit, ans = 0;

// 9桁めまで3,5,7が現れる数を全部みる。 bitで状態管理
void rec(int k = 0, int n = 0, int bit = 0){
    // この数字が条件を満たしてるか確認
    if((bit == ((1<<0) | (1<<1) | (1<<2))) && (n <= N)) ++ans;
    if(k < digit){
        rec(k + 1, n * 10 + 3, bit | (1<<0));
        rec(k + 1, n * 10 + 5, bit | (1<<1));
        rec(k + 1, n * 10 + 7, bit | (1<<2));
    }
}

int main(){
    cin >> N;
    digit = log10(N) + 1;
    rec();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define long long long
using namespace std;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
#define fin '\n'


signed main()
{
  cin.tie(nullptr), ios::sync_with_stdio(false);

  int Q;
  vector<int> a;
  a.reserve(150000);

  cin >> Q;
  while(Q--) {
    int com; int x;
    cin >> com;
    if (com == 0) {
      cin>> x;
      a.push_back(x);
    } else if (com == 1) {
      cin >> x;
      cout << a[x] << fin;
    } else {
      a.pop_back();
    }
  }

  return 0;
}




Measured memory_bytes: 3824
package main

import (
	"fmt"
	"strings"
)

var H, W int
var s [][]string

type point struct {
	x int
	y int
}

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

func bfs() int {
	var queue []point
	distance := make([][]int, W)
	inf := 1000000
	for i := range distance {
		distance[i] = make([]int, H)
		for j := range distance[i] {
			distance[i][j] = inf
		}
	}

	queue = append(queue, point{0, 0})
	distance[0][0] = 0

	for len(queue) > 0 {
		p := queue[0]
		queue = queue[1:]
		if p.x == W-1 && p.y == H-1 {
			break
		}
		for i := 0; i < 4; i++ {
			next := point{p.x + dx[i], p.y + dy[i]}
			if next.x >= 0 && next.x < W && next.y >= 0 && next.y < H && s[next.y][next.x] != "#" && distance[next.x][next.y] == inf {
				queue = append(queue, next)
				distance[next.x][next.y] = distance[p.x][p.y] + 1
			}
		}
	}
	if goal := distance[W-1][H-1]; goal != inf {
		return goal
	}
	return -1
}

func main() {
	fmt.Scan(&H, &W)

	s = make([][]string, H)
	for i := range s {
		var tmp string
		fmt.Scan(&tmp)
		s[i] = strings.Split(tmp, "")
	}

	min := bfs()
	if min == -1 {
		fmt.Println(min)
	} else {
		black := 0
		for _, v := range s {
			for _, w := range v {
				if w == "#" {
					black++
				}
			}
		}
		fmt.Println(H*W - black - min - 1)
	}
}


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

int main(){
  int n=0;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  
  int k=0;
  
  for(int i=0;i<n;i++){
    if(a.at(i)%2==0){
      if(a.at(i)%3!=0&&a.at(i)%5!=0)
        k++;
    }
  }
  
  if(k==0)
    cout << "APPROVED" << endl;
  else
    cout << "DENIED" << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
    ll n,a,b;cin>>n>>a>>b;
    ll now;cin>>now;
    ll ans = 0;
    rep(i,2,n){
        ll x;cin>>x;
        ans += min((x-now)*a, b);
        now = x;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
int main() {
    int n, a[100];
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
    }
    double s1 = 0., s2 = 0., s3 = 0., si = 0.;
    for (int i = 0, b, b2; i < n; ++i) {
        std::cin >> b;
        b = std::abs(a[i] - b);
        si = std::max(static_cast<double>(b), si);
        s1 += b;
        b2 = b * b;
        s2 += b2;
        s3 += b2 * b;
    }
    std::cout << std::fixed << std::setprecision(6)
        << s1 << std::endl
        << std::sqrt(s2) << std::endl
        << std::cbrt(s3) << std::endl
        << si << std::endl;
}



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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
 ll h,w;
  cin >> h >> w;
  
  
  if(h==1||w==1) cout << 1 << endl;
  else if(h%2==0) cout << h/2*w << endl;
  else if(w%2==0) cout << w/2*h << endl;
  else cout << (w-1)/2*h+(h+1)/2 << endl;
  
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int x;
  cin >> x;
  int ans = x / 11 * 2;
  x %= 11;
  if(x > 0){
    x -= 6;
    ans++;
  }
  if(x > 0){
    ans++;
  }
  cout << ans << endl;
}

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

int main()
{
	int n, total_coast = 0;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
		if (i == 0 || i == n - 1)
		{
			total_coast += abs(v[i]);
		}
		if (i != 0)
		{
			total_coast += abs(v[i] - v[i - 1]);
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (i == 0)
		{
			cout << total_coast - abs(v[i]) - abs(v[i + 1] - v[i]) + abs(v[i + 1]) << endl;
		}
		else if (i == n - 1)
		{
			cout << total_coast - abs(v[i]) - abs(v[i] - v[i - 1]) + abs(v[i - 1]) << endl;
		}
		else
		{
			cout << total_coast - abs(v[i] - v[i - 1]) - abs(v[i + 1] - v[i]) + abs(v[i + 1] - v[i - 1]) << endl;
		}
	}
}

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

int main(){
    ll n;
    string s;
    cin>>s;
    n = 10;
    ll maxS=0;
    ll now=0;
    for(int i=0;i<n;++i){
        if(s[i]=='A' or s[i]=='C' or s[i]=='G' or s[i]=='T'){
            now+=1;
        }else{
            maxS=max(maxS,now);
            now=0;
        }
    }
    cout<<max(maxS,now)<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;

int max(int a, int b) { return a < b ? b : a; }
int board[2010][2010];
int main() {
    int N, K; scanf("%d%d", &N, &K);

    int sum = 0, white = 0;
    for(int i=0; i<N; i++) {
        int x, y; char c; scanf(" %d%d %c", &x, &y, &c);
        x %= 2*K, y %= 2*K;
        if(c == 'B') board[x+1][y+1]++, sum++;
        if(c == 'W') board[x+1][y+1]--, sum--, white++;
    }
for(int i=1; i<=2*K; i++) {
        for(int j=1; j<=2*K; j++) {
            board[i][j] += board[i][j-1];
        }
    }

    for(int j=1; j<=2*K; j++) {
        for(int i=1; i<=2*K; i++) {
            board[i][j] += board[i-1][j];
        }
    }
int ma = -(1 << 25);
    for(int i=0; i<=K; i++) {
        for(int j=0; j<=K; j++) {
            int a = board[i][j];
            int b = board[i+K][j+K] - board[i+K][j] - board[i][j+K] + board[i][j];
            int c = board[2*K][j] - board[i+K][j];
            int d = board[i][2*K] - board[i][j+K];
            int e = board[2*K][2*K] - board[2*K][j+K] - board[i+K][2*K] + board[i+K][j+K];
            int tmp = a + b + c + d + e;
            ma = max(ma, max(tmp, sum - tmp));
        }
    }
    ma += white;
    printf("%d\n", ma);
    return 0;
}


Measured memory_bytes: 15872
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N=sc.nextInt();
String S=sc.next();
int[] W=new int[N+1];
int[] sumW=new int[N+1];
int[] E=new int[N+1];
int[] sumE=new int[N+1];
int Min=N-1;
for(int i=1;i<=N;i++){
    if(S.charAt(i-1)=='W'){W[i]=1;E[i]=0;}
    if(S.charAt(i-1)=='E'){W[i]=0;E[i]=1;}
    sumW[i]+=sumW[i-1]+W[i];
    sumE[i]+=sumE[i-1]+E[i];
}
for(int i=1;i<=N;i++){
        Min=Math.min(sumW[i-1]+sumE[N]-sumE[i],Min );
}
System.out.println(Min);
}
}

Measured memory_bytes: 32992
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    a, b, c, x, y = list(map(int, input().split()))
    ab_yen = a + b
    c_yen = 2 * c
    min_x_y_count = min(x, y)
    cost = 0

    if ab_yen >= c_yen:
        cost += c_yen * min_x_y_count
        cost += min(a, c_yen) * (x - min_x_y_count)
        cost += min(b, c_yen) * (y - min_x_y_count)
    else:
        cost = (a * x) + (b * y)

    print(cost)


Measured memory_bytes: 3064
#include <iostream>
#include<algorithm>
#include <vector>
#include<string>
#include<cmath>
#include<cstdio>

using namespace std;

long n, a, b, k;
int func(long,long);
int P(int, int);
int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8) {
		cout << "Yay!";
	}
	else {
		cout << ":(";
	}
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lson (rt << 1)
#define rson (rt << 1 | 1)
using namespace std;
const int MAXN = 4e5 + 7;
int n, m; 
struct node{int v, next;}e[MAXN];
int head[MAXN], d[MAXN], tot = 1, vis[MAXN];
void add(int u, int v) {e[++tot] = {v, head[u]}; head[u] = tot; d[v]++;}
int a[MAXN << 1], cnt = 0;
void dfs(int u)
{
    for (int &i = head[u]; i; i = e[i].next)
    {
        if (vis[i]) continue;
        vis[i] = vis[i ^ 1] = 1;
        dfs(e[i].v);
    }
    a[++cnt] = u;
}
int pos[MAXN], nxt[MAXN];
int T[MAXN << 2];
inline void pushup(int rt) {T[rt] = min(T[lson], T[rson]);}
void build(int rt, int l, int r)
{
    if (l == r) {T[rt] = nxt[l]; return;}
    int mid = (l + r) >> 1;
    build(lson, l, mid); build(rson, mid + 1, r);
    pushup(rt);
}
int query(int rt, int l, int r, int L, int R)
{
    if (L <= l && r <= R) return T[rt];
    int res = 2e9, mid = (l + r) >> 1;
    if (L <= mid) res = min(res, query(lson, l, mid, L, R));
    if (mid <  R) res = min(res, query(rson, mid + 1, r, L, R));
    return res;
}
void print(int *a, int n)
{
    for (int i = 1; i <= n; i++) printf("%d ", a[i]);
    puts("");
}
bool check()
{
    cnt--;
    for (int i = cnt + 1; i <= cnt * 2; i++) a[i] = a[i - cnt];
    for (int i = 1; i <= cnt * 2; i++) nxt[i] = 2e9;
    for (int i = 1; i <= cnt * 2; i++) nxt[pos[a[i]]] = i, pos[a[i]] = i;
    //print(nxt, cnt * 2);
    build(1, 1, cnt * 2);
    for (int i = 1; i <= cnt; i++) if (nxt[i] <= i + cnt - 1)
    {
        int pos = query(1, 1, cnt * 2, nxt[i], i + cnt - 1);
        if (pos <= i + cnt - 1) 
        {
            //printf("st = %d pos = %d\n", i, pos);
            return true;
        }
    }
    return false;
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1, u, v; i <= m; i++) scanf("%d%d", &u, &v), add(u, v), add(v, u);
    for (int i = 1; i <= n; i++) if (d[i] & 1)
    {
        puts("No");
        return 0;
    }
    dfs(1); 
    //print(a, cnt);
    check() ? puts("Yes") : puts("No");
    return 0;
}
/*
5 7
1 5
5 4
4 1
1 3
3 4
2 4
1 2
*/

Measured memory_bytes: 18048
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> isPair;
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
#define Pll pair<ll,ll>
#define vpll vector<pll>
#define sll set<ll>
#define mll map<ll,ll>

const ll inf=1e18;
const ll maxs = 100005;
const ll mod = 1e9+7;

#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define LB lower_bound
#define UB upper_bound
#define line cout<<endl;
#define fr(i,a,b) for(int i=a;i<=b;++i)
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mst(x,a) memset(x,a,sizeof(x))

ll a[maxs];
ll n;
ll dp[3002][3002];

ll solve(ll l,ll r)
{
    if(dp[l][r]!=-1) 
        return dp[l][r];
    
    if(l==r)
    {
        return dp[l][r] = a[l];
    }
    ll left = a[l] - solve(l+1,r);
    ll right = a[r] - solve(l,r-1);
    
    return dp[l][r] = max(left,right);
}

int main(){
    cin>>n;
    for(ll i=0;i<n;i++)
        cin>>a[i];
    memset(dp,-1,sizeof dp);
	solve(0,n-1);
	cout<<dp[0][n-1];
	return 0;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;


int main(){
  ll N, x; cin >> N >> x;
  ll a[N]; rep(i,N) cin >> a[i];

  ll ans = 0;
  if (a[0]>x) ans += a[0]-x, a[0] = x;
  reps(i,N-1){
    if (a[i-1]+a[i]>x) {
      ans += a[i]+a[i-1]-x;
      a[i] = x-a[i-1];
    }
  }
  cout << ans << endl;
  


  // cout << fixed << setprecision(10);
  
  return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long


#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

const int N=1e5+5;
const int mod=1e9+7;
int32_t main() {
    IOS
int n,ans=0;
    cin>>n;
    for (int i = 0; i < n; ++i) {
        int a;
        cin>>a;
        ans+=a-1;
    }
    cout<<ans;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

public class AtCoderC
{
    static void Main()
    {
        long a;
        long b;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            a = long.Parse(words[0]);
            b = long.Parse(words[1]);
        }

        int answer = -1;
        for (int i = 0; i <= 1000; i++)
        {
            int priceA = (i * 8 / 100);
            int priceB = (i * 10 / 100);
            if (priceA == a && priceB == b)
            {
                answer = i;
                break;
            }
        }

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,x,y,xkyori,saitann,ykyori;
  cin>>n>>x>>y;
  vector<int> vec(n);
  for(int i=0; i<n; i++){
    vec.at(i)=0;
  }
  for(int i=1; i<n; i++){
    for(int j=i+1; j<n+1; j++){
      xkyori=abs(i-x)+abs(j-y)+1;
      ykyori=abs(i-y)+abs(j-x)+1;
      saitann=min(xkyori,ykyori);
      saitann=min(saitann,j-i);
      vec.at(saitann)=vec.at(saitann)+1;
    }
  }
  for(int i=1; i<n; i++){
    cout<<vec.at(i)<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[20];
int main()
{
	int n, m;
	cin >> n >> m;
	long long i;
	int j;
	for(i=0; i<m; i++) cin >> a[i];
	for(i=0; i<(1 << n); i++)
	{
		int flag = 1;
		for(j=0; j<m; j++)
		{
			if(!(i & (1 << a[j])))
			{
				flag = 0;
				break;
			}
		}
		if(flag)
		{
			cout << i << ":";
			for(j=0; j<n; j++)
			{
				if(i & (1 << j)) cout << " " << j;
			}
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define repa(X,A,Y) for (int (X) = A;(X) <= (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000;
int N;
int a[MAX_N];

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

  cin >> N;
  rep(i, N) cin >> a[i];

  sort(a, a+N);
  reverse(a, a+N);

  for (int i = 0; i < N; ++i) {
    if (a[i]%2 == 1) {
      cout << "first" << endl;
      return 0;
    }
  }

  cout << "second" << endl;
  return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#define N 3010
typedef long long ll;
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
using namespace std;
const int P = 1e9 + 7;
const int inv2 = 5e8 + 4;
inline ll quickpow(ll x, int k) {
	ll res = 1;
	while (k) {
		if (k & 1)	res = res *x  % P;
		x = x * x % P;
		k >>= 1;
	}
	return res;
}
int n, q;
int a[N];
int f[N][N], g[N][N];
int main() {
	read(n), read(q);
	for (int i = 1; i <= n; ++i)	read(a[i]);
	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			f[i][j] = a[i] > a[j];
			f[j][i] = a[j] > a[i];
		}
	}
	for (int i = 1; i <= q; ++i) {
		int l, r; read(l), read(r);
		if (l > r)	swap(l, r);
		int tmp = 1ll * inv2 * (f[l][r] + f[r][l]) % P;
		f[l][r] = f[r][l] = tmp;
		for (int j = 1; j <= n; ++j) if (j != l && j != r) {
			f[j][l] = f[j][r] = 1ll * inv2 * (f[j][l] + f[j][r]) % P;
			f[l][j] = f[r][j] = 1ll * inv2 * (f[l][j] + f[r][j]) % P;
		}
//		for (int j = l + 1; j < r; ++j) {
//			f[l][j] = f[j][r] = 1ll * inv2 * (f[l][j] + f[j][r]) % P;
//		}
//		for (int j = r + 1; j <= n; ++j) {
//			f[l][j] = f[r][j] = 1ll * inv2 * (f[l][j] + f[r][j]) % P;
//		}
	}
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			ans = (ans + f[i][j]) % P;
		}
	}
	ans = ans * quickpow(2, q) % P;
	printf("%lld\n", (ans % P + P) % P);
	return 0;
}


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

int main() {
    int n;
    double d;
    cin >> n >> d;
    int sum= 0;
    for (int i= 0;i< n;i++) {
        long long x, y;
        cin >> x >> y;
        double dis= sqrt(x* x+ y* y);
        if (dis <= d) sum++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3668
#include <stdio.h>
#include <string.h>
int main(void){
  int A,B;
  scanf("%d",&A);
  scanf("%d",&B);
  if(A+B==3){
    printf("3\n");
  }
  else if(A+B==4){
    printf("2\n");
  }
  else{
    printf("1\n");
  }
  return 0;
}

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

int main(){
    int k;
    string s;

    cin >> k >> s;

    int l = s.length();

    if(l <= k){
        cout << s << "\n";
    }
    else{
        l = l - k;
        s.erase(k, l);

        cout << s << "...\n";
    }
    return 0;
}

Measured memory_bytes: 3628