akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	string s;
	cin >> s;

	int t = 0;
	int f = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'a') {
			if (t < a + b) {
				t++;
				puts("Yes");
			} else {
				puts("No");
			}
		} else if (s[i] == 'b') {
			if (t < a + b && f < b) {
				t++;
				f++;
				puts("Yes");
			} else {
				puts("No");
			}
		} else {
			puts("No");
		}
	}
}

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

int main(void) {
  int n;
  cin >> n;
  int allsum = 0;
  int maxl = 0;
  for (int i = 0; i < n; i++){
    int l; cin >> l;
    maxl = max(l, maxl);
    allsum += l;
  }

  if ((allsum - maxl) > maxl) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
N, K = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(N)])

cnt = 0
for a in A:
  if(cnt < K-a[1]):
    cnt += a[1]
  else:
    print(a[0])
    break
"""
unk buriburi
"""

Measured memory_bytes: 28640
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

ll MOD = 1e9 + 7;

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

	int n;
	string s;
	cin >> n >> s;

	vector<ll> cnt(26);
	for (auto c : s) {
		cnt[c - 'a']++;
	}

	ll ans = 1;
	for (auto v : cnt) {
		ans = (ans * (v + 1LL)) % MOD;
	}
	ans = (ans - 1) % MOD;

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f(a, b) for (ll i = a; i <= b; i++)
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
#define N 200005
const ll INF = 1000000000000000001;
const ll MOD = 1000000007;

//vector< vector<ll> > g(N);
//vector< pair<ll, pair< ll, ll > > > g(N);
//ll vis[N] = {0}, par[N] = {0}, child[N] = {0},cnt = 0;


void solve(){
    ll a,b,c,d; cin >>a>>b>>c>>d;
    cout << max({a*c, a*d , b*c , b*d}) << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
   //ll t;cin >> t;for(ll index=1; index<=t; index++){
        //cout << "Case #" << index << ": " ;
        solve();
   // }
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main() {
	int n,r=0,w=0;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='R')
			r++;
	}
	for(int i=0;i<r;i++){
		if(s[i]=='W')
			w++;
	}
	cout<<w<<endl;
}

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

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

    int n;
    cin >> n;

    vector<int> h(n, 0);
    REP(i, n) cin >> h[i];

    int count = 0;
    int sum = accumulate(h.begin(), h.end(), 0);
    while (sum) {
        int l = 0;
        REP(i, n) {
            if (h[i] > 0) {
                l = i;
                break ;
            }
        }

        int r = l;
        for (int i = l + 1; i < n; i++) {
            if (h[i] != 0) r = i;
            else break ;
        }

        for (int i = l; i <= r; i++)
            h[i]--;

        count++;
        sum = accumulate(h.begin(), h.end(), 0);
    }

    cout << count << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
int main() {
	int N, M, A, B;
	scanf("%d %d", &N, &M);
	vector<int> adjlist[N];
	for (int i = 0; i < M; ++i) {
		scanf("%d %d", &A, &B);
		adjlist[A - 1].push_back(B - 1);
		adjlist[B - 1].push_back(A - 1);
	}
	int parent[N];
	bool visited[N];
	fill_n(visited, N, false);
	visited[0] = true;
	parent[0] = -1;
	queue<int> bfs;
	bfs.push(0);
	while (!bfs.empty()) {
		int x = bfs.front();
		bfs.pop();
		for (int i: adjlist[x]) {
			if (!visited[i]) {
				visited[i] = true;
				parent[i] = x;
				bfs.push(i);
			}
		}
	}
	printf("Yes\n");
	for (int i = 1; i < N; ++i) printf("%d\n", parent[i] + 1);
	return 0;
}

Measured memory_bytes: 10120
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <limits.h>
using namespace std;

int main(){
  int n; string s; cin >> n >> s;
  int cnt = 0;
  for(int i = 0; i < n - 2; i++){
    if(s.compare(i, 3, "ABC") == 0) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	int n;
	string str;
	cin >> str >> n;
	for(int i=0 ; i<n ; i++ ){
		string sign , st;
		int x,y;
		cin >> sign >> x >> y;
		if( sign=="print" ){
			for( int j=x ; j<=y ; j++ )
				cout << str[j];
			cout << endl;
		}		
		else if( sign =="reverse"){
			string tmp="";
			for( int j=y ; j>=x ; j-- )
				tmp+=str[j];
			for( int j=x ; j<=y ; j++ ){
				str[j] = tmp[j-x];
			//	cout << tmp[j-x] <<" ";
			}
			//cout << endl;
		}
		else if( sign=="replace"){
			cin >> sign;
			for( int j=x ; j<=y ; j++ )
				str[j] = sign[j-x];
		}
		//else
		//	cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<lint, lint>;
const int mod = 1e9 + 7;
const int MAXN = 2000005;

int n, a[20];

set<pi> s[20][20];

int main(){
	cin >> n;
	for(int i=1; i<=n; i++){
		 cin >> a[i];
	}
	for(int i=1; i<n; i++){
		s[i][i + 1].emplace(0, 0);
	}
	for(int i=2; i<n; i++){
		for(int j=1; j+i<=n; j++){
			for(int k=j+1; k<j+i; k++){
				auto l = s[j][k];
				auto r = s[k][j+i];
				for(auto &p : l){
					for(auto &q : r){
						lint tmp = p.second + q.first + a[k];
						s[j][j+i].emplace(p.first + tmp, q.second + tmp);
					}
				}
			}
			vector<pi> v;
			for(auto &k : s[j][i+j]){
				v.emplace_back(k.first, k.second);
			}
			s[j][i +j].clear();
			sort(v.begin(), v.end());
			lint curMin = 1e18;
			for(auto &k : v){
				if(curMin > k.second){
					s[j][i + j].insert(k);
					curMin = k.second;
				}
			}
		}
	}
	lint ret = 1e18;
	for(auto &i : s[1][n]){
		ret = min(ret, i.first + i.second);
	}
	cout << ret + a[1] + a[n] << endl;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

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

  ll N;
  ll mod = 1000000007;
  cin >> N;

  vvl a(N, vl(N, 0));
  vvl lookUp(N+1, vl());

  FOR(c, 0, (1<<N)){
    ll s = 1;
    ll counter = 0;
    while(s <= c){
      if(c & s) counter++;
        s = s << 1;

    }
    //TR(c); TR(counter);
    lookUp[counter].pb(c);
  }

  FOR(i, 0, N)FOR(j, 0, N) cin >> a[i][j];

  vl dp((1<<N), 0);

  dp[0] = 1;

  FOR(w, 0, N){
      for(ll c : lookUp[w]){
        FOR(b, 0, N){
          if(a[w][b] == 0) continue;
          if(c & 1<<b) continue;
          dp[c+(1<<b)] = (dp[c+(1<<b)]+dp[c])%mod;
      }
    }

    /*
    FOR(i, 0, (1<<N)){
      cout << i << ' ' <<dp[i] << endl;
    }
    cout << endl;
    */
  }


  cout << dp[(1<<N)-1] << endl;

}


Measured memory_bytes: 39588
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

constexpr int MOD = 1000000007;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

constexpr int INF = MOD;

int N, K;
vector<vector<int>> graph;
int p[101010];

PLL rmemo[101010];

PLL dfs(int x, int prev = -1) {
    LL minR = -INF, maxR = INF;
    for (const int& v: graph[x]) {
        if (v == prev) { continue; }
        PLL r = dfs(v, x);
        if (r.first > r.second) {
            return make_pair(INF, -INF);
        }
        if (p[x] == -1) {
            minR = max(minR, r.first);
            maxR = min(maxR, r.second);
        } else {
            if (p[x] < r.first - 1 || r.second + 1 < p[x]) {
                return make_pair(INF, -INF);
            }
        }
    }

    if (p[x] != -1) {
        return rmemo[x] = make_pair(p[x], p[x]);
    }
    return rmemo[x] = make_pair(minR-1, maxR+1);
}

LL ret[101010];

void dfs_set(int x, LL minR, LL maxR, int prev = -1) {
    ret[x] = max(minR, rmemo[x].first);
    for (const int& v : graph[x]) {
        if (v == prev) { continue; }
        dfs_set(v, ret[x]-1, ret[x]+1, x);
        if (ret[x] == ret[v]) {
            cout << "No" << endl;
            exit(0);
        }
    }
}

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

    cin >> N;
    graph.resize(N);
    fill(p, p+N, -1);
    for (int j = 0; j < N-1; ++j) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    cin >> K;
    for (int j = 0; j < K; ++j) {
        int v, w;
        cin >> v >> w;
        p[--v] = w;
    }

    PLL result = dfs(0);

    if (result.first > result.second) {
        cout << "No" << endl;
        return 0;
    }

    dfs_set(0, -INF, INF);
    
    cout << "Yes" << endl;
    for (int j = 0; j < N; ++j) {
        cout << ret[j] << endl;
    }

    return 0;
}


Measured memory_bytes: 17024
#include<iostream>
// #include<string>
#include<vector>
// #include <algorithm>
// #include <functional>

using namespace std;
int main()
{
  // Input
  int n;
  cin >> n;

//   vector<int> vecIn(n);

  int minimum;
  cin >> minimum;
  int count = 1; 

  for (int i = 1; i < n; i++) {
      int tmp;
      cin >> tmp;

      if (tmp <= minimum) {
          count++;
          minimum = tmp;
      }
  }

  cout << count << endl;
  return 0;
}


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

int main(){
    int n;
    while(cin >> n, n){
        int ans = 1<<30;
        for(int i=0; i*i*i <= n; i++){
            int j = sqrt(n - i*i*i);
            if(n < i*i*i + j*j) continue;
            ans = min(ans, i+j+(n-i*i*i-j*j));
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int h,w,n,x,y;
string s,t;
bool C(int k,int l,char a,char b)
{
	for(int i=0;i<n;i++)
	{
		if(s[i]==a)
			k--;
		if(!k)
			return true;
		if(t[i]==b&&k<l)
			k++;
	}
	return false;
}
int main()
{
	cin>>h>>w>>n>>x>>y>>s>>t;
	if(C(x,h,'U','D')||C(h-x+1,h,'D','U')||C(y,w,'L','R')||C(w-y+1,w,'R','L'))
		cout<<"NO";
	else
		cout<<"YES";
	return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
const int N=2003;
int n,m,ans,f1[N][N],f2[N][N],f3[N][N],f4[N][N];
char mp[N][N];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%s",mp[i]+1);
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    if(mp[i][j]=='.')f1[i][j]=f1[i-1][j]+1,f2[i][j]=f2[i][j-1]+1;
    for(int i=n;i;i--)
    for(int j=m;j;j--)
    if(mp[i][j]=='.')f3[i][j]=f3[i+1][j]+1,f4[i][j]=f4[i][j+1]+1;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    if(mp[i][j]=='.')ans=max(ans,f1[i][j]+f2[i][j]+f3[i][j]+f4[i][j]-3);
    printf("%d\n",ans);
}

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

typedef pair<int, int> P;


int main() {
    int n, m;
    cin >> n >> m;
    map<P, int> freq;
    rep(i, m){
        int s, c;
        cin >> s >> c;
        freq[P(s,c)]++;
    }

    vector<int> result(n,0);
    if(n != 1) result[0] = 1;

    int current_s = 0;
    for(auto i = freq.begin(); i != freq.end(); i++){
        int s = i->first.first;
        int c = i->first.second;
        if(current_s == s){
            cout << -1 << endl;
            return 0;
        }
        if(s == 1 && n != 1 && c == 0){
            cout << -1 << endl;
            return 0;
        }
        current_s = s;
        result[s-1] = c;
    }

    rep(i, n){
        cout << result[i];
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int sum=0,x,i;
	for(i=0;i<k;++i){
		cin>>x;
		sum+=x;
	}
	if(sum>n)
		cout<<"-1";
		else
		cout<<n-sum;
	return 0;
}


Measured memory_bytes: 3644
N=int(input())
A=[int(s) for s in input().split(" ")]
B=[int(s) for s in input().split(" ")]

Ans1=0
Ans1=sum(A)

for i in range(N):
    if B[i]-A[i]<0:
        A[i]=A[i]-B[i]
    else:
        A[i+1]=max(A[i+1]-(B[i]-A[i]),0)    
        A[i]=0

Ans2=0
Ans2=sum(A)        
        
print(Ans1-Ans2)

Measured memory_bytes: 18624
N = int(input())
Vn = list(map(int, input().split()))
Cn = list(map(int, input().split()))

X = 0
Y = 0
for i, d in enumerate([v - c for v, c in zip(Vn, Cn)]):
    
    if(d >= 0):
        X += Vn[i]
        Y += Cn[i]
print(X - Y)

Measured memory_bytes: 38384
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;

void solve() {
	int N; cin >> N;
	bool ok = true;
	int T = 0;
	int x = 0, y = 0;
	REP(i, N) {
		int t, nx, ny;
		cin >> t >> nx >> ny;
		int d = abs(nx - x) + abs(ny - y);
		if (d > t-T)ok = false;
		if ((t - T) % 2 != d % 2)ok = false;
		T = t;
		x = nx, y = ny;
	}
	if (ok)print("Yes");
	else print("No");
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args) { 
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int a=0,b=0,c=0;
		for(int i=0;i<n;i++){
			a=sc.nextInt();
			b=sc.nextInt();
			c=sc.nextInt();
			if(a>b&&a>c){
				if(Math.pow(a, 2)==Math.pow(c, 2)+Math.pow(b, 2))
					System.out.println("YES");
				else System.out.println("NO");
			}else if(b>c&&b>a){
				if(Math.pow(b, 2)==Math.pow(c, 2)+Math.pow(a, 2))
					System.out.println("YES");
				else System.out.println("NO");
			}else if(c>b&&c>a){
				if(Math.pow(c, 2)==Math.pow(a, 2)+Math.pow(b, 2))
					System.out.println("YES");
				else System.out.println("NO");
			}else System.out.println("NO");
		}
	}
}

Measured memory_bytes: 23392
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

#define MAX 200005
 
typedef long long ll;
typedef pair<int, int> P;

int n;
int a[MAX];
vector<int> adj[MAX];
vector<int> dp;    // 増加列長さ
int ans[MAX];

void dfs(int v, int p)
{
    for (int e : adj[v]) {
        if (e == p) continue;
        auto itr = lower_bound(dp.begin(), dp.end(), a[e]);
        int index = itr - dp.begin();
        int bkup;
        if (itr == dp.end()) {
            bkup = -1;
            dp.push_back(a[e]);
        } else {
            bkup = *itr;
            dp[index] = a[e];
        }
        dfs(e, v);
        if (bkup == -1) {
            dp.pop_back();
        } else {
            dp[index] = bkup;
        }
    }
    ans[v] = dp.size();
}

int main(int, char**)
{
    cin >> n;
    rep(i,n) cin >> a[i];

    int u, v;
    rep(i,n-1) {
        cin >> u >> v;
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dp.push_back(a[0]);
    dfs(0,-1);

    rep(i,n) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 30328
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
typedef long long ll;
using namespace std;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline int max(int a, int b) {return a>b ? a : b;}
inline int min(int a, int b) {return a<b ? a : b;}
const int N = 102000;
char s[N];
int n,buc[4];

int main() {
	scanf("%s",s+1); n=strlen(s+1);
	rep(i,1,n) buc[s[i]-'a'+1]++;
	int x=1000000; rep(i,1,3) x=min(x,buc[i]);
	rep(i,1,3) buc[i]-=x;
	printf("%s", (buc[1]<=1&&buc[2]<=1&&buc[3]<=1) ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define usecppio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int color[9];
int main()
{
    int n;
    int ct = 0;
    scanf("%d",&n);
    while(n--)
    {
        int x;
        scanf("%d",&x);
        color[min(x/400,8)]++;
    }
    for (int i = 0; i<8; i++)
        ct += (color[i]>=1);
    printf("%d %d",max(1,ct),ct+(color[8]));
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define int long long
# define fi first
# define se second

using namespace std ;

const int N = 1e5 + 1 ;
int v[N], dp[N];

int32_t main() {
    //freopen("haybales.in", "r", stdin ) ;
    //freopen("haybales.out", "w", stdout ) ;
    int t, k ;
    cin >> t >> k ;
    for( int i = 1 ; i <= t ; i ++ ) {
        cin >> v[i] ;
    }
    dp[2] += abs(v[2] - v[1] ) ;
    for( int i = 3 ; i <= t ; i ++ ) {
        for( int j = 1 ; j <= k ; j ++ ) {
            if( i == j ) break ;
            if( j == 1 ) dp[i]  = abs(v[i] - v[i-j]) + dp[i-j] ;
            else dp[i]  = min( dp[i], abs(v[i] - v[i-j]) + dp[i-j] );
        }
    }
    cout << dp[t] << endl;

}



Measured memory_bytes: 5132
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxN=5e5, M=1e9+7;
int n, m;
ll iv[mxN+1], f1[mxN+1], f2[mxN+1];
ll nck(int n, int k) {
	return f1[n]*f2[k]%M*f2[n-k]%M;
}
int main() {
	iv[1]=1;
	for(int i=2; i<=mxN; ++i)
		iv[i]=M-M/i*iv[M%i]%M;
	f1[0]=f2[0]=1;
	for(int i=1; i<=mxN; ++i) {
		f1[i]=f1[i-1]*i%M;
		f2[i]=f2[i-1]*iv[i]%M;
	}
	cin >> n >> m;
	ll ans=0;
	for(int i=0; i<=n; ++i) {
		ll c=i&1?M-1:1;
		c=c*nck(n, i)%M*nck(m, i)%M*f1[i]%M*nck(m-i, n-i)%M*nck(m-i, n-i)%M*f1[n-i]%M*f1[n-i]%M;
		ans=(ans+c)%M;
	}
	cout << ans;
}

Measured memory_bytes: 15284
/* ITP1_8_D: Ring */
/* 20181124 AOJ */

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#define N 101

int main(void) {
	char s[N], p[N];
	int i, j, len_s, len_p, flag;

	scanf("%s %s", s, p);

	len_s = strlen(s);
	len_p = strlen(p);

	for(i = 0; i < len_s; i++) {
		flag = 1;
		for(j = 0; j < len_p; j++) {
			if(s[(i + j) % len_s] != p[j]) {
				flag = 0;
				break;
			}
		}
		if(flag) break;
	}
	
	if(flag) {
		puts("Yes");
	}else {
		puts("No");
	}
	
	return 0;
}


Measured memory_bytes: 2112
#include <stdio.h>

int max(int a,int b){
	if(a>=b){return a;}
	else{return b;}
}

int A[100005];

int main() {

	int N;

	scanf("%d",&N);

	int i;

	for(i=1;i<=N;i++){
	scanf(" %d",&A[i]);
	}

	int sum=0;

	for(i=1;i<=N+1;i++){
	sum+=max(A[i]-A[i-1],A[i-1]-A[i]);
	}

	for(i=1;i<=N;i++){
	int a,b,c;
	a=max(A[i]-A[i-1],A[i-1]-A[i]);
	b=max(A[i+1]-A[i],A[i]-A[i+1]);
	c=max(A[i+1]-A[i-1],A[i-1]-A[i+1]);
	printf("%d\n",sum-a-b+c);
	}

	return 0;
}

Measured memory_bytes: 1536
<?php
    $n = trim(fgets(STDIN));
    $arr = explode(" ", trim(fgets(STDIN)));
    $flg = 0;
    $cnt = 0;
    for($i = 0; $i < $n; $i++){
        if($arr[$i] % 2 == 0){
            $cnt++;
            if($arr[$i] % 3 == 0 || $arr[$i] % 5 == 0){
                $flg++;
            }
        }
    }
    if($cnt == $flg){
        echo "APPROVED";
    }else{
        echo "DENIED";
    }
?>

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

long long int Q, H, S, D, T, P[4], N;

int main(){
    scanf("%lld%lld%lld%lld%lld", &Q, &H, &S, &D, &N);
    P[0] = Q;
    P[1] = min(P[0] * 2, H);
    P[2] = min(P[1] * 2, S);
    P[3] = min(P[2] * 2, D);
    N <<= 2;
    cout << (N >> 3) * P[3] + (N & 4) / 4 * P[2] + (N & 2) / 2 * P[1] + (N & 1) * *P << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,i,a[100];
double s;
int main(){
  for(cin>>n>>m;i<n;i++)cin>>a[i];
  sort(a+1,a+n,greater<int>());
  for(i=0;i<n;i++)s+=a[i];
  s=ceil(s/(double)4/(double)m);
  cout<<(a[m-1]>=s?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int a0=a,b0=b,c0=c;
    for(int i=0;i<k;i++){
        if(a>0)
            a--;
        else if(b>0)
            b--;
        else if(c>0)
            c--;
    }
    int ans=(a0-a)*1+(b0-b)*0+(c0-c)*-1;
    cout << ans;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N=2e5+100;

ll vis[N];
int32_t main(){
    ll u,v;
    cin >> u >> v;
    vis[u]=1;
    vis[v]=1;
    for (int i=1;i<=3;i++){
        if (!vis[i]){
            cout << i << endl;
        }
    }
}


Measured memory_bytes: 384
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    db=[0]*(10**5+10)

    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))

    sm=0
    for a in arr:
        db[a]+=1
        sm+=a

    q=int(readline())

    for i in range(q):
        b,c=map(int, readline().rstrip().split())
        sm-=b*db[b]
        sm+=c*db[b]
        db[c]+=db[b]
        db[b]=0
        print(sm)
    
    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------


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

int main(){
  string s,t;cin >> s >> t;
  string ans="";
  for(int i=0;i<s.size();++i){
    ans+=s.at(i);
    if(i<t.size()) ans+=t.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include <iterator>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<cstdint>
#include<chrono>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

using namespace std;



signed main() {

	string S;
	cin >> S;
	if (S == "Sunny") {
		cout << "Cloudy" << endl;
	}
	if (S == "Cloudy") {
		cout << "Rainy" << endl;
	}
	if (S == "Rainy") {
		cout << "Sunny" << endl;
	}



	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const double PI = acos(-1);
const double EPS = 1e-8;

using pi = pair<int,int>;
using P = pair<double,pi>;

int main(){
    int n;
    scanf(" %d", &n);

    vector<P> v;
    rep(i,n){
        int x,y;
        scanf(" %d %d", &x, &y);
        double t = atan2(y,x);
        if(t<0) t = 2*PI+t;

        v.pb({t,{x,y}});
        v.pb({t+2*PI,{x,y}});
    }
    sort(all(v));

    int V = v.size();
    ll ans = 0;
    rep(loop,2){
        rep(i,V){
            // dbg(i);
            ll x = 0, y = 0;
            for(int j=i; j<V; ++j){
                if(v[j].fi - v[i].fi > PI-EPS) break;
                // dbg(v[j].se);
                x += v[j].se.fi;
                y += v[j].se.se;
                ans = max(ans, x*x+y*y);
            }
            // dbg((pi(x,y)));
        }

        rep(i,V) v[i].fi = -v[i].fi;
        reverse(all(v));
     }

    printf("%.15Lf", sqrtl(ans));
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;

int n;
double m;
double a[N];
double sum=0;
int main() {
    ios::sync_with_stdio(false);
    cin>>n>>m;
     for(int i=0;i<n;++i){
         cin>>a[i];
         sum+=a[i];
     }
     sort(a,a+n);

     double check=sum/(4*m);
     int cnt=0;
     for(int i=n-1;i>=0;--i){
         if(a[i]>=check) cnt++;
         if(cnt==m){
             printf("Yes\n");
             return 0;
         }
     }
     printf("No\n");


    return 0;
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
use std::convert::TryInto;
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//abc128-C

fn main() {
    //     input! {
    //         n: u8,
    //         m: u8,
    //         sk: [[u8]; n],
    //         ps: [u8; m]
    //     }

    //     println!(
    //         r#"
    // n: {},
    // m: {},
    // sk: {:?},
    // ps: {:?}
    //         "#,
    //         n, m, sk, ps
    //     );

    let n: usize = read();
    let m: usize = read();
    let mut s: Vec<Vec<usize>> = vec![vec![]; m];
    let mut p: Vec<usize> = vec![];

    for i in 0..m {
        let k = read();
        for _ in 0..k {
            s[i].push(read());
        }
    }

    for _ in 0..m {
        p.push(read());
    }
    let mut ans = 0;

    let mut sstate = vec![false; n];

    for switch_state in 0..(2u64.pow(n.try_into().unwrap())) {
        for i in 0..n {
            sstate[i] = (switch_state >> i) % 2 == 0
        }

        let mut is_ok = true;
        for i in 0..m {
            let mut sum = 0;
            for s in &s[i] {
                sum += if sstate[s - 1] { 1 } else { 0 }
            }

            if sum % 2 != p[i] {
                is_ok = false;
            }
        }

        if is_ok {
            ans += 1;
        }
    }

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


Measured memory_bytes: 2132
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
//#define local
#ifdef local
    #include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
    #include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define pi std::pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
#define npm next_permutation
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll& x, ll& y);
ll nCr(ll n, ll r);
void stat();
template <typename T> T fact(T num);
constexpr ll mod = 1000000000 + 7;

int main()
{
    stat();
ll a,b,c;
cin>>a>>b>>c;
if(a%2==0 || b%2==0 || c%2==0){
	cout<<0<<endl;return 0;
}
cout<<min(min(a*b,b*c),c*a)<<endl;
    return 0;
}
ll extgcd(ll a, ll b, ll& x, ll& y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) {
        is_prime[i] = true;
    }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++) {
        if (is_prime[i]) {
            for (unsigned ll j = 2 * i; j <= N; j += i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat(){
#ifdef local
    rep(i, 2){std::cout << "local enable" << std::endl;
}
#endif
#ifdef hacks
rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}

ll nCr(ll n, ll r)
{
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

template <typename T> T fact(T num)
{
    if (num == 1) { return 1; }
    return num * fact(num - 1);
}


Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>

using namespace std;

const int MOD = 1000000007;
typedef long long ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  cout<<((N+110)/111)*111<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
typedef pair<int,pair<int, int>> P1;

using Graph = vector<vector<int>>;


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

  int N;
  cin >> N;
  int A[N];
  rep(i,N){
    cin >> A[i];
  }
  int ans = INF;
  rep(i,101){
    int ans1 = 0;
    rep(j,N){
      ans1 += abs(A[j] - i) * abs(A[j] - i);
    }
    if(ans > ans1){
      ans = ans1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
 
signed main(){
    int N,M;cin>>N>>M;
    int ans=1;
    if(M==1)ans=1;
    else{
        for(int i=1;i<=sqrt(M);i++){
            if(M%i==0){
                int a=i;int b=M/i;
                if(b>=N)ans=max(ans,a);
                if(a>=N)ans=max(ans,b);
            }
        }
    }
    cout<<ans<<endl;
}


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

#include <string>

#include <vector>
#include <list>
#include <map>

#include <algorithm>
#include <utility>

using namespace std;

int main(const int argc, const char **argv){
  int N, M;
  scanf("%d %d", &N, &M);

  vector<int> A(M, 0);
  for(int i = 0; i < N; i++){
    int K;
    scanf("%d", &K);
    for(int i = 0; i < K; i++){
      int tmp;
      scanf("%d", &tmp);

      A[tmp - 1]++;
    }
  }

  int ans = 0;
  for(int i = 0; i < M; i++){
    if(A[i] == N){
      ans++;
    }
  }

  printf("%d", ans);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+1;
const int mod = 1e9+7;

int main() {
		int x;
		cin >> x;
		int y = (x%100)%10;
		if (y == 2 || y == 4 || y == 5 || y == 7 || y == 9){
                cout << "hon";
		}
		else if (y == 3){
            cout << "bon";
		}
		else
            cout << "pon";
	return 0;
}


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

int main(void) {
	// your code goes here
	char a[100],b[100],c[100];
	scanf("%s %s %s",a,b,c);
	int A=strlen(a)-1;
	int B=strlen(b)-1;
	int C=strlen(c)-1;
	if(a[A]==b[0] && b[B]==c[0])printf("YES\n");
	else  printf("NO\n");
	//else if(a[A]!=b[0] && b[B]==c[0]) printf("");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;

void ERROR(int num) { printf("ERROR%d!\n",num); }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};

struct P
{
	int x;
	int y;
	bool operator < (const P& A) const{
			return x < A.x;
	}
};
int N;
vector<P> vec1, vec2;
vector<int> check;


int main(){
	cin >> N;
	vec1.resize(N);
	vec2.resize(N);
	rep(i,N) cin >> vec1[i].x >> vec1[i].y;
	rep(i,N) cin >> vec2[i].x >> vec2[i].y;

	sort(vec1.begin(), vec1.end());
	sort(vec2.begin(), vec2.end());

	int k = 0;
	int cnt = 0;
	check.resize(N,0);
	rep(i,N){
		P num = vec2[i];
		int l = lower_bound(vec1.begin(), vec1.end(), num) - vec1.begin();
		int max = -1;
		int index = -1;
		bool ok = 0;
		//cout << "L:" << l << endl;
		rep(j,l){
			if(!check[j]){
				if(vec1[j].y>max && vec1[j].y<num.y){
					max = vec1[j].y;
					index = j;
					ok = 1;
				}
			}
		}
		if(ok){
			//cout << "vec2: " << num.y << " vec1: " << vec1[index].y << endl;
			check[index] = 1;
			cnt++;
		}
	}
	cout << cnt << endl;

}


Measured memory_bytes: 256
n = int(input())
a = input().split(' ')
b = []
inds = [0] * n

for i in range(int(n/2)):
    inds[i] = n-2*i
    inds[n-1-i] = n-2*i-1
if n % 2 == 1:
    inds[int(n/2)] = n-2*int(n/2)

for i, ind in enumerate(inds):
    print(a[ind-1], end="")
    if i != n-1:
        print(' ', end="")
print('')

Measured memory_bytes: 29456
#include <bits/stdc++.h>
using namespace std;
int n,k,a[105];
bool dp[100005];
string s[2]={"Second","First"};
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)	cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=0;i<a[1];i++)	dp[i]=0;
	for(int i=a[1];i<=k;i++)
		for(int j=1;j<=n;j++)
			if(i-a[j]>=0)
				dp[i]|=dp[i-a[j]]^1;
	cout<<s[dp[k]]<<endl;
}

Measured memory_bytes: 384
#include <stdlib.h>
#include <string.h>
#define maxx 100000
int main()
{
    int check[maxx],i,j;
    memset(check,0,sizeof(check));
    for(i=2;i<=maxx;i++){
        for(j=i+i;j<maxx;j=j+i){
            check[j]=1;
        }
    }
    int dp[maxx],ddp[maxx];
    memset(dp,0,sizeof(dp));
    for(i=2;i<=maxx;i++){
            if(i%2!=0){
       if(check[i]==0&&check[(i+1)/2]==0){
        dp[i]=1;
       }
            }
    }
    for(i=1;i<=maxx;i++){
        ddp[i]=ddp[i-1]+dp[i];
    }
    int l,r,q;
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d %d",&l,&r);
        printf("%d\n",ddp[r]-ddp[l-1]);
    }
    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  ll n, a; in(n);
  ll now = 2, ans;
  in(ans); ans--;
  rep(i,n-1) {
    in(a);
    if (a == now) now++;
    ans += (a - 1) / now;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
const int MaxN = 2000 + 10 ;
int N , A[MaxN] ;
bool Map[MaxN][MaxN] , Vis[MaxN] ;
int Cnt , Head[MaxN] , To[MaxN] , Next[MaxN] , In[MaxN] ;
inline void Add( int U , int V ) {
	To[++Cnt] = V ;
	Next[Cnt] = Head[U] ;
	Head[U] = Cnt ;
	++In[V] ;
}
void Dfs( int Nod ) {
	Vis[Nod] = true ;
	for(register int i = 0 ; ++i <= N ; )
		if( Map[Nod][i] and ( not Vis[i] ) ) {
			Add( Nod , i ) ;
			Dfs( i ) ;
		}
}
priority_queue<int> Q ;
int main() {
	scanf( "%d" , &N ) ;
	for(register int i = 0 ; ++i <= N ; )
		scanf( "%d" , &A[i] ) ;
	sort( A + 1 , A + 1 + N ) ;
	for(register int i = 0 ; ++i <= N ; )
		for(register int j = 0 ; ++j <= N ; )
			Map[i][j] = __gcd( A[i] , A[j] ) != 1 ;
	for(register int i = 0 ; ++i <= N ; )
		if( not Vis[i] ) Dfs( i ) ;
	for(register int i = 0 ; ++i <= N ; )
		if( In[i] == 0 )
			Q.push( i ) ;
	while( Q.size() ) {
		register int Nod = Q.top() ;
		Q.pop() ;
		printf( "%d " , A[Nod] ) ;
		for(register int i = Head[Nod] ; i ; i = Next[i] )
			if( --In[To[i]] == 0 )
				Q.push( To[i] ) ;
	}
	return 0 ;
}

Measured memory_bytes: 4352
package main

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

func main() {
	scanInit()

	s := nextStr()

	for {
		s = s[:len(s)-1]

		if len(s)%2 == 1 {
			continue
		}

		if s[:len(s)/2] == s[len(s)/2:] {
			fmt.Println(len(s))
			break
		}
	}

}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(void) {
	int n;
	long long int a[100000] = { 0 },x;
	scanf("%d", &n);
	scanf("%lld", &a[0]);
	for (int i = 1; i < n; i++) {
		scanf("%lld", &x);
		a[i] = a[i - 1] + x;
	}

	long long ans = 0, dif = 0;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0 && a[i] + dif <= 0) {
			ans += 1 - (a[i] + dif);
			dif += 1 - (a[i] + dif);
		}
		if (i % 2 == 1 && a[i] + dif >= 0) {
			ans += a[i] + dif + 1;
			dif += -(a[i] + dif + 1);
		}
	}
	long long ans2 = 0, dif2 = 0;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 1 && a[i] + dif2 <= 0) {
			ans2 += 1 - (a[i] + dif2);
			dif2 += 1 - (a[i] + dif2);
		}
		if (i % 2 == 0 && a[i] + dif2 >= 0) {
			ans2 += a[i] + dif2 + 1;
			dif2 += -(a[i] + dif2 + 1);
		}
	}
	printf("%lld\n", ans > ans2 ? ans2 : ans);
}


Measured memory_bytes: 896
#include <stdio.h>
#define N 250
typedef struct node
{
  int key,left,right,parent;
  int flagl,flagr;
}T;
int main()
{
  int n,i,j;
  T tree[N];
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    {
      scanf("%d",&tree[i].key);
      tree[i].flagl=0;
      tree[i].flagr=0;
      if(i!=1)
	{
	  tree[i].parent=tree[i/2].key;
	  if(i%2==0)
	    {
	      tree[i/2].left=tree[i].key;
	      tree[i/2].flagl=1;
	    }
	  else
	    {
	      tree[i/2].right=tree[i].key;
	      tree[i/2].flagr=1;
	    }
	}
    }
  for(i=1;i<=n;i++)
    {
      printf("node %d: key = %d, ",i,tree[i].key);
      if(i!=1)
	printf("parent key = %d, ",tree[i].parent);
      if(tree[i].flagl==1)
	printf("left key = %d, ",tree[i].left);
      if(tree[i].flagr==1)
	printf("right key = %d, ",tree[i].right);
      printf("\n");
    }
  return 0;
}



Measured memory_bytes: 2104
#include <stdio.h>
#include <math.h>
int main(void) {
    int num,score[1000],i;
    double average,sigma,sum;
    while (1) {
        scanf("%d",&num);
        if (num==0) break;
        sum=0;
        for (i=0; i<num; i++) {
            scanf("%d",&score[i]);
            sum+=score[i];
        }
        average=1.0*sum/num;
        sum=0;
        for (i=0; i<num; i++) sum+=(score[i]-average)*(score[i]-average);
        sigma=sum/num;
        printf("%.8lf\n",sqrt(sigma));
    }
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define forn(i,a,b) for (int i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
#define er erase
#define in insert
#define pi pair <int, int>
# define sz(x) (int)((x).size())
#define int long long

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

const ll inf = 0x3f3f3f3f3f3f3f;
const ll mod = 1999999973;
const int N = 2e5 + 11;

int dp[N],h[N],n,k,x;
vector<int>v;

int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0); cerr.tie(0); cout.tie(0);

//ifstream cin("flip.in");
//ofstream cout("flip.out");

    cin >> n >> k;

    forn(i,1,n)cin >> h[i];

    for(int i = 1; i <= n; i++){

        dp[i] = (i != 1 ? 2e18 : 0);

        for(int j = max(1ll,i-k); j < i; j++){

                dp[i] = min(dp[i] , abs(h[i] - h[j]) + dp[j]);

        }

    }

    rc(dp[n]);

return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(void){
    char str[4];
    scanf("%s",str);
    if(str[0]==str[1] && str[1]==str[2] || str[1]==str[2]&&str[2]==str[3]){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
  let (a, b) = read_touple::<isize>();
  let mut ans = -1;

  if a/10 == 0 && b/10 == 0 {
    ans = a * b; 
  } 

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


Measured memory_bytes: 4352
N=int(input())
xx=[]
yy=[]
for i in range(N):
  x,y=map(int,input().split())
  xx.append(x+y)
  yy.append(x-y)
xx.sort()
yy.sort()
print(max(xx[-1]-xx[0],yy[-1]-yy[0]))


Measured memory_bytes: 104760
n = int(input())
H = list(map(int, input().split()))[::-1]
for i in range(n-1):
    if H[i] >= H[i + 1]:
        pass
    elif H[i] == H[i + 1] - 1:
        H[i + 1] -= 1
    else:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 14396
module Main (main) where

import qualified Data.ByteString.Char8 as C8
import Data.Bool
import Data.Maybe

main :: IO ()
main = do
  [a,b] <- readInts
  print . showAnswer $ solve (a,b)

type Input  = (Int, Int)
type Output = Int

solve :: Input -> Output
solve (a,b) = if b `mod` a == 0 then a+b else b-a

showAnswer :: Output -> Answer
showAnswer = Number

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | String String
  | Compare Ordering
  | Compare2 Ordering

instance Show Answer where
  show (YesNo b)    = bool "No" "Yes" b
  show (YESNO b)    = bool "NO" "YES" b
  show (AB b)       = bool "B"  "A" b
  show (Number i)   = show i
  show (String s)   = s
  show (Compare o)  = ordering "<" "=" ">" o
  show (Compare2 o) = ordering "Right" "Balanced" "Left" o

ordering :: a -> a -> a -> Ordering -> a
ordering lt eq gt o = case o of
  LT -> lt
  EQ -> eq
  GT -> gt

Measured memory_bytes: 380
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define ub upper_bound
#define pp push_back
#define ep emplace_back
#define all(v) (v).begin(),(v).end()
#define szz(v) ((int)(v).size())
#define psm partial_sum
#define acm accumulate
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
const lf PI = 3.14159265358979323846264338L;
const ll mod = 998244353;
ll pw(ll a, ll n){
    ll ret = 1, pv = a % mod;
    for(;n;n>>=1){
        if(n & 1) ret = ret * pv % mod;
        pv = pv * pv % mod;
    }
    return ret;
}
void addr(int& a, int b){
    a = (a + b) % mod;
}
int n, a[303];
const int o = 90000;
int dp[2][180005];
int dp2[2][180005];

int main(){
    fio;
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    dp[0][o] = 1;
    dp2[0][o] = 1;
    for(int i = 1, w = 1; i <= n; i++, w = !w){
        memset(dp[w],0,sizeof(dp[w]));
        memset(dp2[w],0,sizeof(dp2[w]));
        for(int j = -o; j <= o; j++){
            if(j + a[i] <= o){ 
                addr(dp[w][o + j + a[i]], dp[!w][o + j]);
                addr(dp2[w][o + j + a[i]], dp2[!w][o + j]);
            }
            if(j - a[i] >= -o){
                addr(dp[w][o + j - a[i]], dp[!w][o + j] * 2 % mod);
                addr(dp2[w][o + j - a[i]], dp2[!w][o + j]);
            }
        }
        /*
        for(int j = -o; j <= o; j++){
            if(dp[w][o + j] != 0){
                cout << "dp[" << i << "][" << j << "] = " << dp[w][o + j] << '\n';
            }
            if(dp2[w][o + j] != 0){
                cout << "dp2[" << i << "][" << j << "] = " << dp2[w][o + j] << '\n';
            }
        }
        */
    }
    ll ans = pw(3, n);
    //cout << ans << '\n';
    for(int i = 0; i <= o; i++){
        ans = (ans + mod - 3ll * dp[n&1][o + i] % mod) % mod;
    }
    ans = (ans + dp2[n&1][o] * 3ll) % mod;
    cout << ans << '\n';
}

Measured memory_bytes: 3072