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

int main(){
    int n,ans=0,flag=0;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    while(1){
        for(int j=0;j<n;j++){
            if(a[j]%2==1){
                flag=1;
            } else {
                a[j]/=2;
            }
        }
        if(flag==0){
            ans++;
        } else if(flag==1){
            break;
        }
    }
        cout<<ans;
}
            

Measured memory_bytes: 3532
n = gets.to_i
heights = gets.split.map(&:to_i)
ans = 'Yes'

highest = heights[0]

heights.each do |h|
 if h >= highest
   highest = h
 elsif h + 1 >= highest
   highest = h + 1
 else
   ans = 'No'
   break
 end
end

puts ans


Measured memory_bytes: 8580
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;

signed main(){

    int n, m; cin >> n >> m;
    vector<int> a(n);
    vector<int> cnt(m + 1, 0);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(i != 0){
            cnt[a[i]] += ((a[i] - a[i - 1] + m) % m - 1);
        }
    }

    /*for(int i = 0; i <= m; i++){
        cout << cnt[i] << " ";
    }
    cout << endl;*/

    vector<int> imos(m + 2, 0);
    //x は [1, m] を動く
    for(int i = 0; i < n - 1; i++){
        if(a[i + 1] > a[i]){
            imos[a[i] + 1]++;
            imos[a[i + 1]]--;
        }else{
            //二か所をいじる感じ
            imos[a[i] + 1]++;
            imos[m + 1]--;

            imos[1]++;
            imos[a[i + 1]]--;
        }
    }

    for(int i = 2; i <= m + 1; i++){
        imos[i] += imos[i - 1];
    }

    //dp[i] := i = x の時のボタンを押す必要のある回数
    vector<int> dp(m + 1, 0);
    int x = 1;
    for(int i = 0; i < n - 1; i++){
        dp[1] += min((a[i + 1] - a[i] + m) % m, 1 + (a[i + 1] - x + m) % m); 
    }

    int ans = dp[1];
    for(int x = 1; x < m; x++){
        int add = 0;
        add -= imos[x];
        add += cnt[x];
        dp[x + 1] = dp[x] + add;
        ans = min(ans, dp[x + 1]);
    }

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

Measured memory_bytes: 3328
import sys
sys.setrecursionlimit(10**5)
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
        self.weight = [0]*(n+1)
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            r = self.Find_Root(self.root[x])
            self.weight[x] += self.weight[self.root[x]]
            self.root[x] = r
            return r
    def GetWeight(self, x):
        self.Find_Root(x)
        return self.weight[x]
    def Unite(self, x, y, w):
        w += self.GetWeight(x)
        w -= self.GetWeight(y)
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return False
        if self.rnk[x] < self.rnk[y]:
            x, y = y, x
            w = -w
        if self.rnk[x] == self.rnk[y]:
            self.rnk[x] += 1
        self.root[y] = x
        self.weight[y] = w
        return True
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)
    def Count(self, x):
        return -self.root[self.Find_Root(x)]
    def Diff(self, x, y):
        return self.GetWeight(y) - self.GetWeight(x)

n, m = map(int, input().split())
if m == 0:
    print('Yes')
    exit()
lrd = [list(map(int, input().split())) for _ in range(m)]
uf = UnionFind(n)
for l, r, d in lrd:
    if uf.isSameGroup(l, r)==False:
        uf.Unite(l, r, d)
    else:
        if uf.Diff(l, r) != d:
            print('No')
            exit()
print('Yes')





Measured memory_bytes: 133264
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#define FOR(i,b,e) for(int i=b;i<e;i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;

#define INFTY 1000000
typedef pair<int, int> P;

const int N = 10000;
int n;
int D[N];
vector<P> W[N];
bool V[N];

void dijkstra() {
  priority_queue< P, vector<P>, greater<P> > pq; // first: d, second: u

  REP(i, n) {
    D[i] = INFTY;
    V[i] = false;
  }

  pq.push(P(0, 0));

  while (!pq.empty()) {
    int dv, v, nv;
    P node = pq.top(); pq.pop();

    dv = node.first;
    v = node.second;
    if (V[v]) continue;

    V[v] = true;
    D[v] = dv;

    REP(i, W[v].size()) {
      nv = W[v][i].second;
      if (!V[nv]) {
        pq.push(P(D[v] + W[v][i].first, nv));
      }
    }
  }
}

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

  cin >> n;
  REP(i, n) D[i] = INFTY;

  REP(i, n) {
    int id, k, v, c;
    cin >> id >> k;
    REP(j, k) {
      cin >> v >> c;
      W[id].push_back(P(c, v));
    }
  }

  dijkstra();
  REP(i, n) {
    cout << i << " " << D[i] << endl;
  }
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	int x;
	cin >> x;
	int cnt = 0;
	REP(i, a + 1) {
		REP(j, b + 1) {
			REP(k, c + 1) {
				if (i * 500 + j * 100 + k * 50 == x)cnt++;
			}
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
#include <cstdio>
int gcd(int a,int b)
{
    return b? gcd(b,a%b):a;
}
int main()
{
    int a,b;
    while(scanf("%d%d",&a,&b) != EOF)
    {
        int g = gcd(a,b);
        int l = a/g*b;
        printf("%d %d\n",g,l);
    }
}

Measured memory_bytes: 1024
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
vector<int> adj[N];
int n, m, dp[N];
bool mark[N];

void dfs(int u) {
	mark[u] = true;
	for (auto v: adj[u]) {
		if (!mark[v])
			dfs(v);
		dp[u] = max(dp[u], dp[v] + 1);
	}
}

inline void readInput() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		adj[--u].push_back(--v);
	}
}

inline void solve() {
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (!mark[i])
			dfs(i);
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
}

int main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	readInput(), solve();
	return 0;
}


Measured memory_bytes: 8320
#include "bits/stdc++.h"
#define _CRT_SECURE_NO_WARNINGS
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define Pi pair<int,int>
#define IINF 1e9
#define LINF 1e18
#define vi vector<int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, 0,-1,0 };
int dy[] = { 0, 1,0,-1 };

void solve() {
	string s;
	cin >> s;
	int point = 0;
	if (s.length() % 2 == 0) {
		rep(i, s.length()/2) {
			if (s[i] == 'p') {
				point--;
			}
		}
		REP(i, s.length() / 2, s.length()) {
			if (s[i] == 'g') {
				point++;
			}
		}
	}
	else {
		int n = s.length() / 2 + 1;
		rep(i, n) {
			if (s[i] == 'p') {
				point--;
			}
		}
		REP(i, n, s.length()) {
			if (s[i] == 'g') {
				point++;
			}
		}
	}
	P(point);
}

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

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

int sum( int n, int s, int x ) {
	if( n == 0 ) {
		return s == 0;
	}

	int result = 0;

	for( int i = x; i <= 9; ++i ) {
		result += sum( n-1, s-i, i+1 );
	}

	return result;
}

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

	int n, s;
	while( cin >> n >> s ) {
		if( n == 0 && s == 0 ) { break; }

		cout << sum( n, s, 0 ) << '\n';
	}
}



Measured memory_bytes: 3012
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace contest_Csharp
{

    class Program
    {
        public static (long m, long s)[,] dp;

        static void Main(string[] args)
        {
            //checked
            {
                var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
                Console.SetOut(sw);

                var vals = Console.ReadLine().Split(' ').
                    Select(x => int.Parse(x)).ToList();


                var D = vals[0];
                var T = vals[1];
                var S = vals[2];

                var ans = (T * S >= D) ? "Yes" : "No";
                Console.WriteLine(ans);

                Console.Out.Flush();
            }




        }
    }

}




Measured memory_bytes: 28152
from collections import defaultdict


def main():

    def is_in(a, b):
        return (a, b) in nums_points

    flag = 0
    row1 = list(map(int, input().split()))
    row2 = list(map(int, input().split()))
    row3 = list(map(int, input().split()))

    n = int(input())
    nums = [int(input()) for i in range(n)]

    mat = [row1, row2, row3]
    combs = defaultdict(int)
    for i in range(3):
        for j in range(3):
            combs[mat[i][j]] = (i, j)

    nums_points = []
    for n in nums:
        nums_points.append(combs[n])

    if is_in(0, 0) and is_in(0, 1) and is_in(0, 2):
        flag += 1
    if is_in(1, 0) and is_in(1, 1) and is_in(1, 2):
        flag += 1
    if is_in(2, 0) and is_in(2, 1) and is_in(2, 2):
        flag += 1
    if is_in(0, 0) and is_in(1, 0) and is_in(2, 0):
        flag += 1
    if is_in(0, 1) and is_in(1, 1) and is_in(2, 1):
        flag += 1
    if is_in(0, 2) and is_in(1, 2) and is_in(2, 2):
        flag += 1
    if is_in(0, 0) and is_in(1, 1) and is_in(2, 2):
        flag += 1
    if is_in(0, 2) and is_in(1, 1) and is_in(2, 0):
        flag += 1

    if flag:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t powermod(int64_t x, int64_t y, int64_t p){
  if(y < 0 || x <= 0)
    return 0;
  else{
    int64_t n = 1;
    x %= p;
    for(int64_t i = 0; i < y; i++){
      n = n*x%p;
    }
    return n;
  }
}
int main() {
    int64_t mod = 998244353;
    int64_t n;
    cin >> n;
    vector<int>d(n);
    rep(i,n) cin >> d[i];
    if(d[0] != 0) cout << 0 << endl;
    else{
        sort(d.begin(),d.end());
        int dmax = d[d.size()-1];
        vector<int>cnt(dmax+1,0);
        rep(i,n) cnt[d[i]]++;
        int64_t ans = 1;
        if(cnt[0] != 1) cout << 0 << endl;
        else{
            rep(i,dmax) ans = ans*powermod(cnt[i],cnt[i+1],mod)%mod;
            cout << ans << endl;
        }
    }
}

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

int sumdigit(int n){
  int sum = 0;
  
  while(n){
    sum += n % 10;
    n = n / 10;
  }
  
  return sum;
}

int main(void){
  int N;
  cin >> N;
  
  if(N % sumdigit(N) == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


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

int main(void){
  int w,d;
  while(cin>>w>>d,w||d){
    vector<int> hw(w),hd(d);
    int histw[21]={},histd[21]={};
    for(int i=0;i<w;++i){
      cin>>hw[i];
      ++histw[hw[i]];
    }
    for(int i=0;i<d;++i){
      cin>>hd[i];
      ++histd[hd[i]];
    }
    int ans=0;
    for(int i=0;i<=20;++i){
      ans+=i*max(histw[i],histd[i]);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  vector<int> X(n+1),Y(m+1);
  for(int i=0;i<n;i++)
    cin >> X[i];
  for(int i=0;i<m;i++)
    cin >> Y[i];
  X[n]=x;Y[m]=y;
  sort(X.begin(),X.end());
  sort(Y.begin(),Y.end());
  if(X[n]<Y[0])
    cout << "No" << ' ';
  cout << "War" << endl;
  //cout << X[n] << ' ' << Y[0] << endl;
}

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

class Solution
{
    static int CharToInt(char c)
    {
        if (c == '(')
        {
            return -1;
        }
        return -2;
    }

    static char IntToChar(int i)
    {
        if (i == -1)
        {
            return '(';
        }
        return ')';
    }

    static void Main()
    {
        Console.ReadLine();
        var s = Console.ReadLine();
        var t = (string)s.Clone();
        while(t.Contains("()"))
        {
            t = t.Replace("()", "");
        }

        var head = t.Count(c => c == ')');
        var tail = t.Count(c => c == '(');
        var result = new string('(', head) + s + new string(')', tail);

        Console.WriteLine(result);
    }
}

Measured memory_bytes: 11220
//28
#include<iostream>
#include<sstream>
#include<string>
#include<cctype>

using namespace std;

int main(){
  int ans=0;
  for(string s;cin>>s;){
    for(int i=0;i<s.size();i++){
      if(!isdigit(s[i])){
	s[i]=' ';
      }
    }
    stringstream ss(s);
    for(int n;ss>>n;){
      ans+=n;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge { ll from; ll to; ll cost; };
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

int main() {
	int x,a;
  	cin >> x >> a;
  	if(x < a)cout << 0 << endl;
  	else cout << 10 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int n,q;
	int l[100001],r[100001];
	char s[100001];
	int d[100001]={};

	cin>>n>>q;
	rep(i,n){
		cin>>s[i+1];
		d[i+1]=d[i];
		if(s[i+1]=='C'&&s[i]=='A')d[i+1]++;
	}
	rep(i,q){
		cin>>l[i]>>r[i];
		cout<<d[r[i]]-d[l[i]]<<endl;
	}

	return 0;

}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
typedef long long ll;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int main(){
    string s,t;
    int ch=0;
    cin >> s;
    cin >> t;
    for(int i=s.size()-t.size();i>=0;i--){
        string tmp = s.substr(i,t.size());
        int ok=1;
        for(int j=0;j<tmp.size();j++){
            if(!(t[j]==tmp[j]||tmp[j]=='?')){
                ok=0;
                break;
            }
        }
        if(ok){
            for(int j=0;j<t.size();j++){
                s[i+j]=t[j];
            }
            ch=1;
            break;
        }
    }
    if(ch){
        for(int i=0;i<s.size();i++){
        if(s[i]=='?')s[i]='a';
        }
        cout << s << endl;
    }else{
        cout << "UNRESTORABLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 100000
#define INFTY (1<<30)

class Edge {
public:
	int t, w;
	Edge(int t,int w):t(t),w(w){}
};

vector<Edge> G[MAX];
int n, d[MAX];

bool vis[MAX];
int cnt;

void bfs(int s) {
	for (int i = 0; i < n; i++)d[i] = INFTY;
	queue<int> Q;
	Q.push(s);
	d[s] = 0;
	int u;
	while (!Q.empty()) {
		u = Q.front();
		Q.pop();
		for (int i = 0; i < G[u].size(); i++) {
			Edge e = G[u][i];
			if (d[e.t] == INFTY) {
				d[e.t] = d[u] + e.w;
				Q.push(e.t);
			}
		}
	}
}

void solve() {
	bfs(0);
	int maxv = 0;
	int tgt = 0;
	for (int i = 0; i < n; i++) {
		if (maxv < d[i]) {
			maxv = d[i];
			tgt = i;
		}
	}

	bfs(tgt);
	maxv = 0;
	for (int i = 0; i < n; i++) {
		if (d[i] == INFTY)continue;
		maxv = max(maxv, d[i]);
	}

	cout << maxv << endl;
}

main() {
	int s, t, w;
	cin >> n;

	for (int i = 0; i < n - 1; i++) {
		cin >> s >> t >> w;

		G[s].push_back(Edge(t, w));
		G[t].push_back(Edge(s, w));
	}
	solve();
}


Measured memory_bytes: 9860
#include<stdio.h>
int main (){
    int r, c, R[102][102] = {},i, z;
    scanf("%d %d", &r, &c);
    for( i = 0; i < r; i++ ){
        for( z = 0; z < c; z++ ){
            scanf("%d",&R[i][z]);
            R[i][c] += R[i][z];
            R[r][z] += R[i][z];
            if( z == c - 1 ){
                R[r][c] += R[i][c];
            }
        }
    }
    for( i = 0; i <= r; i++ ){
        for( z = 0; z <= c; z++ ){
            if( z == 0 ){
                printf("%d",R[i][z]);
            }else{
                printf(" %d", R[i][z]);
                if( z == c ){
                    printf("\n");
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

#define ss substr

int main() {
  string s, t;
  cin >> s >> t;
  int n = len(s);
  map<string, set<string>> a, b;
  rep(i,0,n) {
    a[s.ss(i,1)].emplace(t.ss(i,1));
    if (len(a[s.ss(i,1)]) >= 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  rep(i,0,n) {
    b[t.ss(i,1)].emplace(s.ss(i,1));
    if (len(b[t.ss(i,1)]) >= 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3928
#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 = 2;

    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 <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

    int n;
    cin >> n;

    map<ll, int> mp;
    ll sum = 0, ans = 0;

    mp[0] = 1;

    for (int i=0; i<n; i++) {
        int x;
        cin >> x;
        sum += x;
        ans += mp[sum];
        mp[sum]++;
    }

    cout << ans << '\n';


    return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;

int main() {
	ll n; cin >> n;
	vector<ll> ns = { 0, 3, 5, 7 };
	int ans = 0;
	for (ll b = 0; b < (1LL << 18); b++) {
		[&]() {
			ll s = 0, w = b;
			bool flag[4] = {}, nonzero = false;
			for (ll i = 0; i < 9; i++) {
				ll k = w % 4;
				if (nonzero && k == 0) return;
				nonzero |= k != 0;
				flag[k] = true;
				s *= 10;
				s += ns[k];
				w >>= 2;
			}
			for (int i = 1; i < 4; i++) {
				if (!flag[i]) return;
			}
			if (s > n) return;
			ans++;
		}();
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    if(s[n-1]=='s'){
        s+='e';
        s+='s';
    }
    else
        s+='s';
    cout << s;
    return 0;
}

Measured memory_bytes: 3624
extern crate proconio;
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        h: usize,
        w: usize,
        k: usize,
    }

    let c = (0..h).map(|_| {
        input! {line: Chars}
        line
    }).collect::<Vec<_>>();

    let cmbh = 2_i32.pow(h as u32);
    let cmbw = 2_i32.pow(w as u32);
    let mut res = 0;
    for i in 0..cmbh {
        for j in 0..cmbw {
            let mut s = 0;
            for x in 0..h {
                if (i & 2_i32.pow(x as u32)) != 0 {
                    continue;
                }
                for y in 0..w {
                    if (j & 2_i32.pow(y as u32)) == 0 && c[x][y] == '#' {
                        s += 1;
                    }
                }
            }
            if s == k {
                res += 1;
            }
        }
    }

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


Measured memory_bytes: 2136
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());

        for(int j=0; j<n; j++){
            String input = reader.readLine();
            int i=0;
            while(input.charAt(i) == '[') i++;

            System.out.println(getMinCount(input.substring(i, input.length()-i), i));
        }
    }

    public static int getMinCount(String input, int hierarchy){
        if(hierarchy == 0){
            return (Integer.parseInt(input)+2)/2;
        }
        String divider = "";
        for(int i=0; i<hierarchy; i++){
            divider = "\\]" + divider + "\\[";
        }
        String[] inputs = input.split(divider);
        int[] mins = new int[inputs.length];
        for(int i=0; i<inputs.length; i++){
            mins[i] = getMinCount(inputs[i], hierarchy-1);
        }
        Arrays.sort(mins);
        int sum = 0;
        for(int i=0; i<(inputs.length+1)/2; i++){
            sum += mins[i];
        }
        return sum;
    }
}

Measured memory_bytes: 38592
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long idx=0;
    long X, Y, Z;
    cin >> X >> Y >> Z;

    cout << Z << " " << X << " " << Y << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Set         std::set
#define PQueue      std::priority_queue
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm   ( A x,  B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    signed call_of_Cthulhu( signed datum ) {

        int a[3];
        for ( int i = 0; i < 3; i++ ) read a[i];
        int min = INF;
        for ( int i = 0; i < 3; i++ ) {
            for ( int j = 0; j < 3; j++ ) {
                if ( i == j ) continue;
                for ( int k = 0; k < 3; k++ ) {
                    if ( k == i || k == j ) continue;
                    chmin(min, abs(a[j]-a[i]) + abs(a[j]-a[k]));
                }
            }
        }
        echo min fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


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

int main(){
    int a, b, c, d; cin >> a >> b >> c >> d;
    string ans;
    if(a+b > c+d) ans = "Left";
    else if(a+b == c+d) ans = "Balanced";
    else ans = "Right";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
int monu(int n){
    if(n==1)
    {
        return(1);
    }
    else{
        return(monu(n-1)+n);
    }
}
int main(){
    int a,b,c;
    scanf("%d %d",&a,&b);
    c=b-a;
    printf("%d\n",(monu(c)-b));
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  rep(i, n) cin >> A.at(i);
  sort(A.rbegin(), A.rend());

  ll ans = 0;
  rep(i, n) {
    if (i == 1) {
      ans += A.at(0);
    } else if (i != 0) {
      ans += A.at(i / 2);
    }
  }

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

Measured memory_bytes: 4040
N= int(input())
E = [input().split()[2:] for _ in [0]*N]
Q = [0]
L = [0] + [-1]*N

    


while Q:
    top = Q.pop(0)
    for i in E[top]:
        i = int(i) - 1
        if L[i] < 0 :L[i] = L[top] +1 ; Q+= [i]

for i in range(N):print(i + 1 ,int(L[i]))



Measured memory_bytes: 5628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

ll N;
vector<ll> A(300010);
vector<ll> bit_cnt(110, 0);
ll ans = 0;

int main() {
    cin >> N;
    rep(i, N) cin >> A[i];
    rep(i, N) {
        rep(j, 60) {
            bit_cnt[j] += (A[i] >> j) & 1;
        }
    }

    rep(i, 60) {
        ans += (((bit_cnt[i] * (N - bit_cnt[i])) % MOD) * (beki(2, i) % MOD)) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5488
#include<bits/stdc++.h>
using namespace std;
long long al[100003],ar[100003],bl[100003],br[100003],cr[100003],cl[100003],ql[100003],qr[100003],ans,power[100003],numq;
int main(){
	string s;
	cin>>s;
	power[0]=1;
	for(long long i=1;i<100003;i++)power[i]=(power[i-1]*3)%1000000007;
	if(s[0]=='A')al[0]=1;
	if(s[0]=='B')bl[0]=1;
	if(s[0]=='C')cl[0]=1;
	if(s[0]=='?')ql[0]=1,numq=1;
	for(long long i=1;i<s.size();i++){
		al[i]=al[i-1];
		bl[i]=bl[i-1];
		cl[i]=cl[i-1];
		ql[i]=ql[i-1];
		if(s[i]=='A')al[i]++;
		if(s[i]=='B')bl[i]++;
		if(s[i]=='C')cl[i]++;
		if(s[i]=='?')ql[i]++,numq++;
	}
	long long n=s.size(),l=s.size()-1;
	if(s[l]=='A')ar[l]=1;
	if(s[l]=='B')br[l]=1;
	if(s[l]=='C')cr[l]=1;
	if(s[l]=='?')qr[l]=1;
	for(long long i=l-1;i>=0;i--){
		ar[i]=ar[i+1];
		br[i]=br[i+1];
		cr[i]=cr[i+1];
		qr[i]=qr[i+1];
		if(s[i]=='A')ar[i]++;
		if(s[i]=='B')br[i]++;
		if(s[i]=='C')cr[i]++;
		if(s[i]=='?')qr[i]++;
	}
	long long ans=0;
	for(long long i=0;i<n;i++){
		if(numq>=0)if(s[i]=='B')ans=(ans+((al[i]*cr[i]%1000000007)*power[numq])%1000000007)%1000000007;
		if(numq>=1)if(s[i]=='B')ans=(ans+((al[i]*qr[i]%1000000007)*power[numq-1])%1000000007)%1000000007;
		if(numq>=1)if(s[i]=='B')ans=(ans+((ql[i]*cr[i]%1000000007)*power[numq-1])%1000000007)%1000000007;
		if(numq>=2)if(s[i]=='B')ans=(ans+((ql[i]*qr[i]%1000000007)*power[numq-2])%1000000007)%1000000007;
		if(numq>=1)if(s[i]=='?')ans=(ans+((al[i]*cr[i]%1000000007)*power[numq-1])%1000000007)%1000000007;
		if(numq>=2)if(s[i]=='?')ans=(ans+((al[i]*(qr[i]-1)%1000000007)*power[numq-2])%1000000007)%1000000007;
		if(numq>=2)if(s[i]=='?')ans=(ans+(((ql[i]-1)*cr[i]%1000000007)*power[numq-2])%1000000007)%1000000007;
		if(numq>=3)if(s[i]=='?')ans=(ans+(((ql[i]-1)*(qr[i]-1)%1000000007)*power[numq-3])%1000000007)%1000000007;
	}
	cout<<ans;
}

Measured memory_bytes: 7552
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    ll X;
    cin >> X;
    
    for (ll A = -1000; A <= 1000; A++) {
        for (ll B = -1000; B <= 1000; B++) {
            ll aa = A*A*A*A*A;
            ll bb = B*B*B*B*B;
            
            if(aa-bb == X){
                cout << A csp B << endl;
                return 0;
            }
            if(aa-bb == X){
                cout << A csp B << endl;
                return 0;
            }
        }
    }
    
    
    

    return 0;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

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

  string s;
  cin>>s;
  int result=0;
  for(int i=0;i<s.size();i++){
    int l=s.size()-1-i;
    if(i>=l){
      break;
    }
    if(s[i]!=s[l]){
      result++;
    }
  }

  cout<<result<<endl;


  return 0;
}


Measured memory_bytes: 888
#include <stdio.h>

int main(){
	int h,w,k;
	scanf("%d %d %d",&h,&w,&k);
	int i,j,s,t,count,ans=0;
	char c[h+1][w+2];
	for(i=0;i<h;i++){
		scanf("%s",&c[i]);
	}
	for(i=0;i<(1<<h);i++){
		for(j=0;j<(1<<w);j++){
			count=0;
			for(s=0;s<h;s++){
				int a=1<<s;
				if((a&i)==0){
					for(t=0;t<w;t++){
						int b=1<<t;
						if((b&j)==0 && c[s][t]=='#') count++;
					}
				}
			}
			if(count==k) ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1728
//In The Name Of God
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define L(x) (2*(x))
#define R(x) ((2*(x))+1)
#define pii pair<int, int>
#define pb push_back
using namespace std;
const int N = 3e3 + 5, Mod = 1e9 + 7, P = 727, Lg = 22, TOF = 1900, Inf = 3e18 + 10;

long double p[N], Dp[N][N], Ans = 0;
int main(){
      ios_base::sync_with_stdio(0); cin.tie(0);
      int n; cin >> n;
      for(int i = 1; i <= n; i++)
            cin >> p[i];
      Dp[0][0] = 1;
      long double yy = 1;
      for(int i = 1; i <= n; i++){
            for(int j = 0; j <= i; j++){
                  Dp[i][j] = Dp[i - 1][j] * (yy - p[i]);
                  if(j)
                        Dp[i][j] += Dp[i - 1][j - 1] * p[i];
                  if(i == n && j > i/2)
                        Ans += Dp[i][j];
            }
      }
      cout << fixed << setprecision(10) << Ans;
      return 0;
}



Measured memory_bytes: 139392
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
    int K, T;
    cin >> K >> T;
    int ans = 0;
    for (int i = 0; i < T; i++) {
        int a;
        cin >> a;
        ans = max(ans, K-(K-a)*2-1);
    }
    cout << ans << endl;
}

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

bounds = [0, 10, 100, 1000]
for i in range(bounds[N - 1], bounds[N]):
    str_i = str(i)
    for s, c in sc:
        if str_i[s - 1] != str(c):
            break
    else:
        print(str_i)
        break
else:
    print(-1)


Measured memory_bytes: 3060
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	int b[n];
	int c=0;
	if(n%2==1){
		for(int i=n-1;i>=0;i-=2){
			b[c]=a[i];
			c++;
		}
		for(int i=1;i<=n-1;i+=2){
			b[c]=a[i];
			c++;
		}
	}
	else
	{
		for(int i=n-1;i>=1;i-=2){
			b[c]=a[i];
			c++;
		}
		for(int i=0;i<=n-1;i+=2){
			b[c]=a[i];
			c++;
		}
	}
	for(int i=0;i<n;i++){
		cout<<b[i]<<' ';
	}
	return 0;
}


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

int main() {
    int N, K;
    cin >> N >> K;

    int accP[N+1], pi;
    fill(accP, accP + N+1, 0);
    rep(i, N) {
        cin >> pi;
        accP[i+1] = accP[i] + pi + 1;
    }

    double ans = 0;
    for (int i=0; i<=N-K; i++) {
        ans = max(ans, (double) (accP[i+K] - accP[i]));
    }

    cout << fixed << setprecision(7) << ans / 2 << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if((x >= r && x <= W-r) && (y >= r && y <= H-r))
		printf("Yes\n");
	else{
		printf("No\n");
	}
}



Measured memory_bytes: 2692
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int dp[5010];

signed main() {
    int N; cin >> N;
    vector<pii> A(N);
    for(int i=0; i<N; i++) {
        int h, p; cin >> h >> p;
        A[i] = make_pair(h, p);
    }

    sort(A.begin(), A.end(), [&](pii l, pii r) {
        int vl = l.first + l.second;
        int vr = r.first + r.second;
        return vl < vr;
    });

    fill(dp, dp+5010, INF);
    dp[0] = 0;
    int ans = 0;
    for(int i=0; i<N; i++) {
        for(int k=N-1; k>=0; k--) {
            if(dp[k] > A[i].first) continue;
            chmax(ans, k+1);
            chmin(dp[k+1], dp[k] + A[i].second);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;


int main() {
    int N,X;
    cin >> N >> X;
    
    int D = 0, c = 0;
    for(int i = 0; i <= N; i++) {
        if(D > X) break;
        c++;
        int L;
        cin >> L;
        D+=L;
    }
    
    cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long double LD; 
typedef long long ll; 
#define int ll 
#define ff(i,a,b) for (int i = a; i < b; i++) 
#define bf(i,a,b) for (int i = a; i >= b; i--) 
#define all(v) v.begin(),v.end() 
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define F first 
#define S second
#define pb push_back
#define mp make_pair
#define lb lower_bound   
#define ub upper_bound
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define one cout<<"-1"<<endl
#define pi 3.141592653589793238
#define intmx INT_MAX 
#define intmi INT_MIN
const int MOD=1e9+7;
int mod(int x){
    return ((x%MOD + MOD)%MOD);
}
int add(int a,int b){
    return mod(mod(a)+mod(b));
}
int mul(int a,int b){
    return mod(mod(a)*mod(b));
}
void solve(){
   int a,b,c,d;
   cin>>a>>b>>c>>d;
   cout<<max(max(a*c,a*d),max(b*c,b*d));
}
signed main() {
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define rep(i, a) for (int i=0; i<(a); i++) 
#define ub        upper_bound            // first element >  val(itr)
#define lb        lower_bound            // first element >= val(itr)

#define mp make_pair
#define pb push_back
#define pi 3.141592653589793
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define bitcount(a) __builtin_popcount(a) // count set bits
#define all(x) (x).begin(),(x).end()

const ll MOD = 1e9 + 7;
const int inf = 1e9+9;
const long long INF = 1e18+3;

//to debug 
#define dbg(x) cout << "Line " << __LINE__ << " | " #x ": " << (x) << endl

template<typename T> T gcd(T a,T b){ if(b>a) return gcd(b,a);return b==0?a:gcd(b,a%b); }
template<typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template<typename T> T fast_power(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

inline ll mod(ll x,ll n) {if (x < n) return x; if (x >= n) return x - n;}
string IntToString(ll a){ ostringstream temp; temp << a; return temp.str();}
ll findMMI_fermat(ll n,ll M) {ll ans= fast_power(n,M-2,M);return ans;}//i.e In (a/b)%M..it calculates MMI of b wrt M
ll add(ll a,ll b,ll M)  { return ( mod(a,M ) + mod(b,M ))%M;     }
ll sub(ll a, ll b,ll M) { return (mod(a,M ) + M - mod(b,M ))%M;   }
ll mult(ll a,ll b,ll M) { return  ( mod(a,M)*mod(b,M) ) %M ; }
bool isprime(ll a){ if(a==2) {return 1;}if(!(a&1) ) {return 0;}for(ll i=3;i*i<=a;i+=2){if(a%i==0) {return 0;} } return 1;} 

  
               /* -------------------------------Main Code------------------------------- */

void max_self(int &a,int b){
	a = max(a,b);
}

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

	vector<vector<int>>dp(a.length()+1,vector<int>( b.length()+1,0 ) );
	for(int i=0;i<(int)a.length();i++){
		for(int j=0;j<(int)b.length();j++){
			if(a[i]==b[j]){
				max_self(dp[i+1][j+1],dp[i][j]+1);
				//cout<<a[i]<<" "<<i<<" "<<j<<" "<<b[j]<<endl;
			}
			else{
				max_self(dp[i+1][j+1] , dp[i][j+1]);
				max_self(dp[i+1][j+1] , dp[i+1][j]);
			}
			
		}
	}
	//cout<<"LCS is "<<dp[a.length()][b.length()];
	int cri = a.length(),crj = b.length();
	string s = "";
	while(cri>0 && crj>0){
		if(a[cri-1]==b[crj-1]){
			s = s + a[cri-1];
			cri--;
			crj--;
		}
		else if(dp[cri-1][crj]<dp[cri][crj-1]) crj--;
    	else cri--;
		
	}
	if(s.length()==0) cout<<" "<<endl;
	else for(int i=s.length()-1;i>=0;i--) cout<<s[i];
	return 0;
}

	

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

signed main(void)
{
	vector<int> a(3);
	int t, ans;
	rep(i, 3) cin >> a[i];
	sort(a.rbegin(), a.rend());
	ans = 0;
	t = 2 * a[0] - a[1] - a[2];
	if (t % 2 == 0) 
		ans = t / 2;
	else
		ans = (t + 1) / 2 + 1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define MOD  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back

#define all(x) x.begin(),x.end()
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
signed main(){
    int n,h,w;cin>>n>>h>>w;
    cout<<(n-h+1)*(n-w+1)<<endl;
    return 0;
}

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

int main(){
  int n;
  cin>> n;
  vector<string> s(n);
  for (int i=0; i<n; i++) cin>> s.at(i);
  
  int64_t ans=0;
  unordered_map<string,int> m;
  for (auto i: s){
    sort(i.begin(), i.end());
    if (m.count(i)){
      ans+=m.at(i);
      m.at(i)+=1;
    }
    else m[i]=1;
  }
  cout<< ans <<endl;
}

Measured memory_bytes: 17700
S = input()
for i in range(len(S) - 1, 1, -1):
    if i % 2 != 0:
        continue
    for j in range(len(S[:i]) // 2):
        if S[j] != S[i // 2 + j]:
            break
    else:
        print(i)
        exit()


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

int main(){
  while(true){
    int h, w;
    cin >> h >> w;
    if(h == 0 && w == 0){
      break;
    }
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        if(j != w - 1){
          cout << "#";
        }
        else if(j == w - 1){
          cout << "#" << endl;
        }
      }
      if(i == h - 1){
        cout << endl;
      }
    }
  }    
}



Measured memory_bytes: 3112
#include <iostream>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if ( a == b)
        cout << "Draw" << endl;
    else if (a == 1)
        cout << "Alice" << endl;
    else if (b == 1)
        cout << "Bob" << endl;
    else if (a >  b)
        cout << "Alice" <<  endl;
    else if ( b > a )
        cout << "Bob" << endl;

}

Measured memory_bytes: 3092
import sys
from collections import deque
def input():
    return sys.stdin.readline().strip()

tozan = []
gezan = []

def check():
    s = input()
    m = 0
    res = 0
    for i in s:
        if i == "(":
            m += 1 
        else:
            m -= 1
            res = min(res,m)
    if m >= 0:
        tozan.append([res,m])
    else:
        gezan.append([res-m,res,m])

N = int(input())
for _ in range(N):
    check()

tozan.sort(reverse=True)
gezan.sort()
##print(tozan,gezan)
b = 0

for res,m in tozan:
    if b + res < 0:
        print("No")
        exit()
    b += m

for _,res,m in gezan:
    if b + res < 0:
        print("No")
        exit()
    b += m

if b == 0:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 104428