akhauriyash/Code-Regression huggingface dataset:
/*
最大値を求める問題
動的計画法が使えるか？
Aのi番目の要素についてBi-1とBiの要素の最小値をとればよい。
Bは0~Nまでの要素を無限大で初期化すれば、ループ条件を工夫しなくてもよいのではないか
*/

# include <iostream>
# include <algorithm>
using namespace std;
int N;
long long b[110];
const long long INF = 1LL << 60;

int main() {
  cin >> N;
  b[0] = INF, b[N] = INF;
  for (int i = 1; i < N; i++) cin >> b[i];
  
  int ans = 0;
  for (int i = 1; i <= N; i++) ans += min(b[i - 1], b[i]);
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 200020
#define INF 10000000000000ll
using namespace std;
LL read(){
	LL nm=0,fh=1; char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
LL n,m,A,B,G[M]; LL p[M<<2][2],tg[M<<2],ans=INF;
void pushup(LL x){p[x][0]=min(p[x<<1][0],p[x<<1|1][0]),p[x][1]=min(p[x<<1][1],p[x<<1|1][1]);}
void pushdown(LL x){
	if(!tg[x]) return;
	p[x<<1][0]+=tg[x],p[x<<1|1][0]+=tg[x];
	p[x<<1][1]+=tg[x],p[x<<1|1][1]+=tg[x];
	tg[x<<1]+=tg[x],tg[x<<1|1]+=tg[x],tg[x]=0; 
}
void build(LL x,LL l,LL r){
	if(l==r){
		if(l==A) p[x][0]=-l,p[x][1]=l;
		else p[x][0]=p[x][1]=INF; return;
	}
	LL mid=((l+r)>>1); build(x<<1,l,mid);
	build(x<<1|1,mid+1,r),pushup(x);
}
LL qry(LL x,LL l,LL r,LL L,LL R,LL kd){
	if(r<L||R<l) return INF; if(L<=l&&r<=R) return p[x][kd]; pushdown(x);
	LL mid=((l+r)>>1); return min(qry(x<<1,l,mid,L,R,kd),qry(x<<1|1,mid+1,r,L,R,kd));
}
void mdf(LL x,LL l,LL r,LL pos,LL dt){
	if(l==r){p[x][0]=min(p[x][0],dt-l),p[x][1]=min(p[x][1],dt+l);return;}
	LL mid=((l+r)>>1); pushdown(x);
	if(pos<=mid) mdf(x<<1,l,mid,pos,dt);
	else mdf(x<<1|1,mid+1,r,pos,dt); pushup(x);
}
void dfs(LL x,LL l,LL r){
	if(l==r){ans=min(ans,p[x][0]+l);return;}LL mid=((l+r)>>1);
	pushdown(x),dfs(x<<1,l,mid),dfs(x<<1|1,mid+1,r);
}/*
void opt(LL x,LL l,LL r){
	if(l==r){if(p[x][0]<100000ll)printf("Pos = %d   t1 = %lld   t2 = %lld\n",l,p[x][0]+l,p[x][1]-l);return;}
	LL mid=((l+r)>>1);	pushdown(x),opt(x<<1,l,mid),opt(x<<1|1,mid+1,r);
}*/
int main(){
	n=read(),m=read(),A=read(),B=read(),G[0]=B,build(1,1,n);
	for(LL i=1;i<=m;i++){
		G[i]=read();LL t1=G[i]+qry(1,1,n,1,G[i],0),t2=qry(1,1,n,G[i],n,1)-G[i],dt=abs(G[i]-G[i-1]);
		tg[1]+=dt,p[1][0]+=dt,p[1][1]+=dt,mdf(1,1,n,G[i-1],min(t1,t2));//opt(1,1,n),puts("haha");
	} dfs(1,1,n),printf("%lld\n",ans) ;return 0;
}

Measured memory_bytes: 18176
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define     mkp(a,b)    make_pair(a,b)
#define     PI          3.14159265359
#define     ll              long long
#define     ul              unsigned long long
#define     ld              long double
#define     mset(arr,val)   memset(arr,val,sizeof arr)
#define     MAXN            (long long)2e5+5
#define     eb              emplace_back
#define     mod             (long long)(1e9+7)
#define     FILE_READ       freopen("input.txt","r",stdin)
#define     FILE_WRITE      freopen("output.txt","w",stdout)
using namespace std;
using namespace __gnu_pbds;;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void dfs(int root,int par,vector<int> nbs[],ll val[]) {
    for(auto i:nbs[root]) {
        if(i==par) {
            continue;
        }
        val[i]+=val[root];
        dfs(i,root,nbs,val);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
//    FILE_READ;
//    FILE_WRITE;

    string s,t;
    cin>>s>>t;
    vector<int> a[26];
    for(int i=0;i<s.size();++i) {
        a[s[i]-'a'].eb(i);
    }
    bool p=false;
    for(int i=0;i<t.size();++i) {
        if(a[t[i]-'a'].empty()) {
            p=true;
            break;
        }
    }
    if(p) {
        cout<<"-1";
        return 0;
    }
    int j=0;
    ll c=0;
    ll last=-1;
    while(j!=t.size()) {
//        cout<<c<<endl;
        ++c;
        int prev=-1;
        while(j!=t.size()) {
            int pos = upper_bound(a[t[j] - 'a'].begin(), a[t[j]-'a'].end(), prev) - a[t[j] - 'a'].begin();
//            cout<<pos<<endl;
//            cout<<a[t[j]-'a'].size()<<endl;
            if(pos==a[t[j]-'a'].size()) break;
            prev=a[t[j]-'a'][pos];
            ++j;
        }
        last=prev;
//        break;
    }
    c-=1ll;
    c=c*(ll)s.size();
    c++;
    c+=last;
    cout<<c;


    return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
//#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define sll                     set<ll>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define umcl                    um<char,ll>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define test                    ll Testcases;cin>>Testcases;while(Testcases--)
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
    #endif
}

int main()
{
	fastIO
//	inp_out();
	ll a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<" "<<b<<" "<<c;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) > 0 ? (a) : (-1 * (a)))
#define rep(i, n) for ((i) = 0; (i) < (int)(n); (i)++)
#define rep2(i, s, e) for ((i) = (s); (i) < (int)(e); (i)++)

void arg_marge(int *, int *, int);

int main(void)
{

    int n, d, a, i, j, k, l, *x, *h, p, *pp, t, ppp;
    long long int at = 0;

    scanf("%d %d %d", &n, &d, &a);
    x = (int *)malloc(n * sizeof(int));
    h = (int *)malloc(n * sizeof(int));
    pp = (int *)malloc(n * sizeof(int));
    rep(i, n)
    {
        scanf("%d %d", x + i, h + i);
        h[i] = (h[i] + a - 1) / a;
    }
    arg_marge(x, h, n);

    p = 0;
    ppp = 0;
    rep(i, n)
    {
        l = x[i] - d - d;
        while (x[p] < l)
            ppp -= pp[p++];
        pp[i] = max(h[i] - ppp, 0);
        at += pp[i];
        ppp += pp[i];
    }
    printf("%lld", at);
}

void arg_marge(int *a, int *b, int n)
{

    if (n == 1)
        return;

    int *tmp, *arg_tmp;
    tmp = (int *)malloc((n) * sizeof(int));
    arg_tmp = (int *)malloc((n) * sizeof(int));
    arg_marge(a, b, n / 2);
    arg_marge(a + n / 2, b + n / 2, n - n / 2);

    for (int i = 0; i < n / 2; i++)
    {
        tmp[i] = a[i];
        arg_tmp[i] = b[i];
    }
    for (int i = n / 2; i < n; i++)
    {
        tmp[i] = a[n / 2 + n - i - 1];
        arg_tmp[i] = b[n / 2 + n - i - 1];
    }

    int lp = 0, rp = n - 1, p = 0;
    int l3, r3;
    while (p < n)
    {
        l3 = tmp[lp];
        r3 = tmp[rp];
        if (l3 < r3)
        {
            a[p] = l3;
            b[p] = arg_tmp[lp];
            lp++;
            p++;
        }
        else
        {
            a[p] = r3;
            b[p] = arg_tmp[rp];
            rp--;
            p++;
        }
    }

    return;
}


Measured memory_bytes: 37504
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;


int main()
{
    ll n, y;
    cin >> n >> y;

    ll a = -1;
    ll b = -1;
    ll c = -1;

    ll p = (y - 1000*n)/1000;
    if(p < 0){
        cout << -1 << " " << -1 << " " << -1;
        return 0;
    }else{
        int f = 0;
        rep(i, 2001){
            rep(j, 2001){
                if(9*i+4*j == p && (i+j)<=n){
                    f = 1;
                    a = i;
                    b = j;
                    c = n-i-j;
                    break;
                }
            }
        }
    }

    cout << a << " " << b << " " << c;


}

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

int main()
{
  int N, l, r, sum;
  // string S;
  sum = 0;
  cin >> N;

  for (int i = 0; i < N; i++)
  {
    cin >> l >> r;
    sum += r + 1 - l;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int D,G; cin>>D>>G;
  vector<int> p(D);
  vector<int> c(D);
  for(int i=0;i<D;i++){
    cin>>p.at(i)>>c.at(i);
  }

  vector<int> t(D);
  int ans = 10000;
  for(int bit=0;bit<(1<<D);bit++){
    int tmp = 0, cnt = 0;
    for(int i=0;i<D;i++){
      t.at(i) = p.at(i);
      if((1<<i)&bit){
        tmp += c.at(i) + p.at(i)*100*(i+1);
        cnt += p.at(i);
        t.at(i) = 0;
      }
    }
    int i = D-1;
    while(tmp < G){
      if(t.at(i)!=0){
        tmp += (i+1)*100;
        t.at(i)--;
        cnt++;
      }else if(i==0){
        break;
      }else{
        i--;
      }
    }
    ans = min(cnt, ans);
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	char A[101], B[101];
	scanf("%s%s", A, B);
	int i, j, k, flag=0;
	for (i = 0; A[i] != '\0'; i++) {
		;
	}
	for (j = 0; B[j] != '\0'; j++) {
		;
	}
	if (i > j) {
		printf("GREATER\n");
		flag = 1;
	} else if (i < j) {
		printf("LESS\n");
		flag = 1;
	} else {
		for (k = 0; k < i; k++) {
			if (A[k] < B[k]) {
				printf("LESS\n");
				flag=1;
				break;
			} else if (A[k] > B[k]) {
				printf("GREATER\n");
				flag = 1;
				break;
			} 
		}
	} 
	if (flag == 0) {
		printf("EQUAL\n");
	}
	return 0;
}


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

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

//head
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int n;
  	cin >> n;
  	set<int> nu;
  	for(int i = 0; i < n; i++){
  		int k;
  		cin >> k;
  		nu.insert(k);
  	}
  	cout << ((nu.size()&1) ? (nu.size()) : (nu.size()-1)) << endl;
	return 0;
}


Measured memory_bytes: 4992
/*
[abc113] D - Number of Amidakuji
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_H = 100;
const int MAX_W = 8;
const ll MOD = 1e9 + 7;

int H, W, K;
int dp[MAX_H + 1][MAX_W + 2];

ll solve() {
    dp[0][1] = 1;
    for (int i = 0; i < H; i++) {
        for (int pat = 0; pat < (1 << W); pat += 2) {
            if (pat & (pat << 1)) {
                continue;
            }
            for (int j = 1; j <= W; j++) {
                if (pat & (1 << (j - 1))) {
                    (dp[i + 1][j - 1] += dp[i][j]) %= MOD;
                } else if (pat & (1 << j)) {
                    (dp[i + 1][j + 1] += dp[i][j]) %= MOD;
                } else {
                    (dp[i + 1][j] += dp[i][j]) %= MOD;
                }
            }
        }
    }
    return dp[H][K];
}

int main() {
    cin >> H >> W >> K;
    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair <int, int> cn;
const int NS = 1e5 + 100;

int main() {
	ll sum = 0, argn, m, a[NS];
	scanf("%lld%lld", &argn, &m);
	for (int i = 0; i < argn; ++i) {
		scanf("%lld", a + i);
	}
	sort(a, a + argn);
	cn z[m];
	for (int i = 0; i < m; ++i) {
		scanf("%lld%lld", &z[i].first, &z[i].second);
	}
	sort(z, z + m, [](const cn &p1, const cn &p2) {
			return p1.second < p2.second;
			});
	int i = 0;
	--m;
	for (; i < argn; ++i) {
		if (a[i] >= z[m].second) { break; }
		sum += z[m].second;
		if (z[m].first == 1) {
			if (m-- == 0) {
				++i;
				break;
			}
			continue;
		}
		z[m].first -= 1;
	}
	for (;i < argn; ++i) {
		sum += a[i];
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
    char ch[5];
    while(cin>>ch)
    {
        int l=strlen(ch);
        if(l==2)
            cout<<ch<<endl;
        else
        {
            for(int i=2;i>=0;i--)
               cout<<ch[i];
            cout<<endl;
        }
    }
}


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

using namespace std;

int main(){
	
	int n, p;
	
	while(true){
		cin >> n >> p;
		if(n == 0){
			break;
		}
		int cup = p;
		
		int num[100];
		
		int ans = -1;
		
		for(int i = 0; i < n; i++){
			num[i] = 0;
		}
		
		while(true){
			for(int i = 0; i < n; i++){
				if(cup != 0){
					cup--;
					num[i]++;
					if(num[i] == p){
						ans = i;
						break;
					}
				}else{
					cup = num[i];
					num[i] = 0;
				}
				//cout << cup << " ";
			}
			if(ans != -1){
				break;
			}
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3096
from sys import stdin, stdout
from collections import Counter

input = lambda: stdin.readline().rstrip()
# write = stdout.write

def main():
    N = int(input())
    W = stdin.read().splitlines()

    word = Counter(W)
    last = W[0][-1]
    for i in range(1, N):
        s = W[i]
        if word[s] > 1 or s[0] != last:
            print('No')
            return
        last = s[-1]
    print('Yes')

main()


Measured memory_bytes: 3444
#include <stdio.h>

#define MAX 100000

struct TRAMP{
	char mark;
	int number;
};

TRAMP cards[MAX];

struct Node{
	Node(){
		number = 0;
		mark_array_index = 0;
		l_p = r_p = p_p = -1;
	}
	int number, mark_array_index,l_p,r_p,p_p;
	char mark_array[5];
};

class Tree{
public:
	Tree(){
		num_of_nodes = 0;
		nodes = new Node[MAX];
	};
	~Tree(){
		delete[] nodes;
	}
	void push(TRAMP data){
		int t = 0;
		while(true){
			if(num_of_nodes == 0){
				nodes[num_of_nodes].number = data.number;
				nodes[num_of_nodes].mark_array[nodes[num_of_nodes].mark_array_index++] = data.mark;
				num_of_nodes++;
				break;
			}else{
				if(nodes[t].number == data.number){
					nodes[t].mark_array[nodes[t].mark_array_index++] = data.mark;
					break;
				}else if(nodes[t].number > data.number){
					if(nodes[t].l_p == -1){
						nodes[t].l_p = num_of_nodes;
						nodes[num_of_nodes].p_p = t;
						nodes[num_of_nodes].number = data.number;
						nodes[num_of_nodes].mark_array[nodes[num_of_nodes].mark_array_index++] = data.mark;
						num_of_nodes++;
						break;
					}else{
						t = nodes[t].l_p;
					}
				}else{
					if(nodes[t].r_p == -1){
						nodes[t].r_p = num_of_nodes;
						nodes[num_of_nodes].p_p = t;
						nodes[num_of_nodes].number = data.number;
						nodes[num_of_nodes].mark_array[nodes[num_of_nodes].mark_array_index++] = data.mark;
						num_of_nodes++;
						break;
					}else{
						t = nodes[t].r_p;
					}
				}
			}
		}
	}

	bool compare(int cards_index){
		int k = 0,number = cards[cards_index].number,t=0;

		while(true){
			if(nodes[t].number == number)
				break;
			else{
				t = (nodes[t].number > number) ? nodes[t].l_p:nodes[t].r_p;
			}
		}

		while(number == cards[cards_index].number){
			if(cards[cards_index].mark != nodes[t].mark_array[k])
				return false;
			else{
				cards_index++;
				k++;
			}
		}
		return true;
	}

private:
	int num_of_nodes;
	Node* nodes;
};


int n;

int Partition(int left,int right){
	int i = left-1,pivot = cards[right].number;
	TRAMP tmp;
	for(int start = left; start < right; start++){
		if(cards[start].number <= pivot){
				i++;
				tmp = cards[i];
				cards[i] = cards[start];
				cards[start] = tmp;
		}
	}

	tmp = cards[right];
	cards[right] = cards[i+1];
	cards[i+1] = tmp;

	return i+1;
}

void quickSort(int left,int right){
	if(left < right){
		int q = Partition(left,right);
		if(q-left>1)
			quickSort(left,q-1);
		if(right-q>1)
			quickSort(q+1,right);
	}
}


int main(){

	Tree tree;
	bool stableFLG = true;
	scanf("%d",&n);

	for(int i = 0; i < n; i++){
		scanf("%s %d",&cards[i].mark,&cards[i].number);
		tree.push(cards[i]);
	}

	quickSort(0,n-1);

	int history = 0;
	for(int i = 1; i < n; i++){
		if(cards[history].number != cards[i].number || i == n-1){
			if(!tree.compare(history)){
				stableFLG = false;
				break;
			}else{
				history = i;
			}
		}
	}

	if(stableFLG){
		printf("Stable\n");
	}else{
		printf("Not stable\n");
	}

	for(int i = 0; i < n; i++)	printf("%c %d\n",cards[i].mark,cards[i].number);
}

Measured memory_bytes: 4440
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define FOR(i,n) for(int i = 0; i < n; i++)
#define FORa(i,a,b) for(int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a,n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define UP(s) transform(s.begin(),s.end(),s.begin(),::toupper)

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

int main() {
	int n;
	ll sum = 0;
	cin >> n;
  
	vector<ll> v(n);
	FOR(i,n) cin >> v[i];
	
	FORa(i,1,n) {
		if(v[i] < v[i-1]) {
			int stool = v[i-1] - v[i];
			v[i] += stool;
			sum += stool;
		}
	}
	
	cout << sum << endl;
  
	return 0;
}


Measured memory_bytes: 4836
import math
while True:
    E = int(input())
    if E == 0: break
    ans = 10**10
    z = 0
    while z**3 <= E:
        y = int(math.sqrt(E - z**3))
        x = E - z**3 - y**2
        ans = min(x+y+z, ans)
        z += 1
    print(ans)

Measured memory_bytes: 5668
o[999999],n,r;main(i){for(;++i<999;)if(!o[i])for(r=i+i;r<999999;r+=i)o[r]=1;for(;scanf("%d",&n),n;printf("%d\n",r))for(i=1,r=0;++i<=n/2;)o[i]+o[n-i]||r++;exit(0);}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = 1e9;
  for (int k = 0; k <= max(x, y) * 2; k += 2) {
    int i = x - k / 2;
    int j = y - k / 2;
    if (i < 0) i = 0;
    if (j < 0) j = 0;
    ans = min(ans, a * i + b * j + c * k);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
fn main() {
    let n = read_i64();
    println!("{}", solve(n));
}

fn solve(n : i64) -> i64 {
    n * (n + 1) / 2
}

fn read_i64() -> i64 {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf);
    buf.trim().parse().unwrap()
}


Measured memory_bytes: 4352
n = input()
ans = 0
for i in range(1,len(n)+1):
    if i % 2 == 1 and i != len(n):
        ans = ans + 10**i -10**(i-1)
    elif i %2 == 1:
        ans = ans + int(n) - 10**(i-1) + 1
    
print(ans)


Measured memory_bytes: 2940
//
//  D.cpp
//  CodeForcesProblems
//
//  Created by Jacob Murry on 1/6/20.
//  Copyright © 2020 Jacob Murry. All rights reserved.
//  ACCEPTED

//#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

//top down solution
struct Solution {
    vector<long long> &wt, &vals;
    Solution(vector<long long> &w, vector<long long> &v, long long W, long long N) : wt(w), vals(v) {
        vector<long long> memo_row(W+1, -1);
        vector<vector<long long> > memo(N+1, memo_row);
        long long answer = dp(memo, W, N);
        cout << answer << "\n";
    }
    
    //take nth item or not
    long long dp(vector<vector<long long> > &memo, long long W, long long N) {
        //base case negative weight or 0 items left
        if(W<=0)
            return 0;
        if(N<=-1)
            return 0;
        //see if subproblem has been solved
        if(memo[N][W]!=-1)
            return memo[N][W];
        //if nth item cant be included
        if(wt[N]>W)
            return dp(memo, W, N-1);
        //include Nth item or not
        long long included = dp(memo, W-wt[N], N-1)+vals[N];
        long long notincluded = dp(memo, W, N-1);
        long long result = max(included, notincluded);
        memo[N][W] = result;
        return result;
    }
    
};

int main(int argc, char * argv[]) {
    long N, W;
    cin >> N >> W;
    vector<long long> weights(N);
    vector<long long> values(N);
    for(long long i=0; i<N; ++i) {
        cin >> weights[i] >> values[i];
    }
    //Solution sol(weights, values, W, N-1);
    //bottom up iteration solution 0-1 knapsack
    vector<long long> row(W+1, 0);
    vector<vector<long long> > dp(N+1, row);
    for(long long n=1; n<=N; n++) {
        for(long long w=1; w<=W; ++w) {
            if(weights[n-1]<=w)
                dp[n][w] = max(values[n-1]+dp[n-1][w-weights[n-1]], dp[n-1][w]);
            else
                dp[n][w] = dp[n-1][w];
        }
    }
    cout << dp[N][W] << "\n";
    
    return 0;
}


Measured memory_bytes: 80256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(a < b && b < c){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26224
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
   
   vector<long long> key;
    map<long long, int> M1,M2;
    long long N,M;
    cin >> N;
    for ( int i = 0; i < N; i++ ) {        
        long long a;
        cin >> a;
        M1[a]++;
    }
    cin >> M;
    for ( int i = 0; i < M; i++ ) {        
        long long a;
        cin >> a;        
        key.push_back(a);        
        M2[a]++;        
    }
   
   for ( int i = 0; i < key.size(); i++ ) {
       // if ( !M1.count(key[i]) ) { cout << "NO" << endl; return 0; }
       if ( M1[key[i]] < M2[key[i]] ) { cout << "NO" << endl; return 0; }
   }
   
   cout << "YES" << endl;
   
    return 0;
}

Measured memory_bytes: 26864
#include<stdio.h>

int main(){
    int flag = 0;
    int count = 0;

    int len = 0;
    scanf("%d",&len);

    int num[len];

    for(int i=0; i<len; i++){
        scanf("%d",&num[i]);
    }

    while(flag == 0){
        for(int i=0; i<len; i++){
            if(num[i]==1 || num[i]%2 == 1)flag = 1;
            num[i] = num[i]/2;
        }

        if(flag == 1)break;
        count ++;
    }

    printf("%d\n",count);

    return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int h,w,n,r,c,_r,_c;
    cin >> h >> w >> n >> r >> c;
    --r;
    --c;
    _r = r;
    _c = c;
    string s, t;
    cin >> s >> t;
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, -1, 0, 1};
    char _s[4] = {'R', 'U', 'L', 'D'};
    char _t[4] = {'L', 'D', 'R', 'U'};
    int ret = true;
    for(int dir=0;dir<4;++dir)
    {
        r = _r;
        c = _c;
        int cur_pos = dir % 2 ? r : c;
        int max_allowed = dir % 2 ? h : w;
        // s: try to remove, t: try to stay
        for(int i=0;i<n;++i)
        {
            if(s[i] == _s[dir])
            {
                cur_pos += dir % 2 ? dy[dir] : dx[dir];
            }

            if(cur_pos < 0 || max_allowed <= cur_pos)
            {
                ret = false;
                break;
            }

            if(t[i] == _t[dir])
            {
                int delta = dir % 2 ? dy[dir] : dx[dir];
                if(0 <= (cur_pos - delta) && (cur_pos - delta) < max_allowed)
                {
                    cur_pos -= delta;
                }
            }
        }
        if (!ret)
        {
            break;
        }
    }

    cout << (ret ? "YES" : "NO") << endl;
}

Measured memory_bytes: 920
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    constexpr int INF = 1e9 + 6;
    int m = INF;
    ll sum = 0;
    int state = 0;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        sum += a;
        m = min(a, m);
        if (a == 0) {
            state = 2;
        }
    }
    if (state == 2) {
        if (sum & 1) {
            puts("First");
        }
        else {
            puts("Second");
        }
    }
    else if (sum & 1) {
        puts("First");
    }
    else {
        if ((n & 1) == 0) {
            if (m & 1) {
                puts("First");
            }
            else {
                puts("Second");
            }
        }
        else {
            puts("Second");
        }
    }
    /*
        for (int a = 0; a < 4; a++) {
            for (int b = 0; b < 4; b++) {
                for (int c = 0; c < 4; c++) {
                    for (int d = 0; d < 4; d++) {
                        cout << a << " " << b << " " << c << " " << d << " " << grundy(a, b, c, d) << endl;
                    }
                }
            }
        }*/
    return 0;
}


Measured memory_bytes: 3104
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;
using Int = long long;

constexpr double EPS = 1e-10;
constexpr long long MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

long long my_mod_pow(long long x, long long n) {
	long long ret = 1;
	for (; n > 0; n >>= 1, x = x * x % MOD) {
		if (n & 1) {
			ret = ret * x % MOD;
		}
	}
	return ret;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    int N, M; cin >> N >> M;
    int ans = N*(N-1)/2 + M*(M-1)/2;
    cout << ans << endl;
}

Measured memory_bytes: 888
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define gcd __gcd
#define lcm(n, m) n * m / gcd(n, m)
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define ea(i, n) for(auto&& i: n)
#define so(n) sort(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// rtsq ルート, int 2*10^9, __gcd

int main() {
  int N, M, C, a = 0;
  ci(N,M,C);
  ve<int> B(M);
  rep(i, M){
    ci(B.at(i));
  }
  ve<ve<int>> A(N, vector<int>(M));
  rep(i, N){
    rep(j, M){
      ci(A.at(i).at(j));
    }
  }
  rep(i, N){
    int b = C;
    rep(j, M){
      b += A.at(i).at(j) * B.at(j); 
    }
    if(b > 0){
      a++;
    }
  }
  co(a);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
const int INF = 1001001001;
//int 2×10の9乗
//vector<vector<int>> a(n, vector<int>(m));
  //rep(i,n) rep(j,m) cin >> a[i][j]; 
//cout << fixed << setprecision(10);
//int gcd(int x, int y){
  //if(y==0) return x;
  //return gcd(y, x%y);
//}
//sort小さい順(昇順)
//g++ code.cpp   ./a.out 
int main(){
  int n;
  cin >> n;
  map<string,int> m;
  rep(i,n){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    m[s]++;
  }
  ll ans=0;
  for(pair<string,int> p : m){
    int v = p.second;
    ans += (ll)v*(v-1)/2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 11136
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int h, w, c;
vector<vector<int>> grid;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

vector<vector<int>> change(const vector<vector<int>>& g, int color) {
    vector<vector<int>> v = g;
    vector<pair<int, int>> vertices;
    bool visited[8][8] = {false}; 
    queue<pair<int, int>> que;
    que.push(make_pair(0, 0));
    int target = v[0][0];
    while (!que.empty()) {
        auto vec = que.front();
        que.pop();
        for (int i = 0; i < 4; ++i) {
            int nx = vec.first + dx[i];
            int ny = vec.second + dy[i];
            if (0 <= nx && nx < w && 0 <= ny && ny < h 
                && !visited[ny][nx] && v[ny][nx] == target) {
                visited[ny][nx] = true;
                vertices.push_back(make_pair(nx, ny));
                que.push(make_pair(nx, ny));
            }
        }
    }
    v[0][0] = color;
    for (auto ver : vertices) {
        v[ver.second][ver.first] = color;
    }
    return v;
}

int count(const vector<vector<int>>& g) {
    int count = 1;
    bool visited[8][8] = {false}; 
    visited[0][0] = true;
    queue<pair<int, int>> que;
    que.push(make_pair(0, 0));
    int target = g[0][0];
    while (!que.empty()) {
        auto vec = que.front();
        que.pop();
        for (int i = 0; i < 4; ++i) {
            int nx = vec.first + dx[i];
            int ny = vec.second + dy[i];
            if (0 <= nx && nx < w && 0 <= ny && ny < h 
                && !visited[ny][nx] && g[ny][nx] == target) {
                visited[ny][nx] = true;
                que.push(make_pair(nx, ny));
                count++;
            }
        }
    }
    return count;
}

int solve() {
    int ans = 0;
    queue<pair<vector<vector<int>> , int>> que;
    que.push(make_pair(grid, 0));
    while(!que.empty()) {
        auto front = que.front();
        que.pop();
        auto g = front.first;
        int depth = front.second;
        if (depth < 4) {
            for (int i = 1; i < 7; ++i) {
                auto tmp_grid = change(g, i);
                que.push(make_pair(tmp_grid, depth+1));
            }
        }
        else {
            auto tmp_grid = change(g, c);
            ans = max(ans, count(tmp_grid));
        }
    }
    cout<<ans<<endl;
}

int main (int argc, char *argv[]) {
    while (cin>>h>>w>>c, h||w||c) {
        for (int y = 0; y < h; ++y) {
            vector<int> tmp;
            for (int x = 0; x < w; ++x) {
                int t;
                cin>>t;
                tmp.push_back(t);
            }
            grid.push_back(tmp);
        }
        solve();
        grid.clear();
    }
    return 0;
}


Measured memory_bytes: 3940
#include <bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
void dfs(Graph &,int,int);
vector<bool> seen;
vector<int> counter;

int main(){
    int n,q,i;cin>>n>>q;
    
    Graph G(n);
    for(i=0;i<n-1;i++){//Graphの作成
        int a,b;cin>>a>>b;
        a--;b--;
        G[a].push_back({b});
        G[b].push_back({a});
    }

    seen.assign(n,false);//初期化
    counter.assign(n,0);//

    for(i=0;i<q;i++){//部分木全体に足す
        int root,plus;
        cin>>root>>plus;
        root--;
        counter[root]+=plus;
    }

    dfs(G,0,0);//rootからDFS

    for(i=0;i<n;i++){
        cout<<counter[i];
        cout<<' ';
    }
    return 0;
}

void dfs(Graph &G,int root,int plus){//DFS
    seen[root]=true;
    counter[root]+=plus;
    for(auto next:G[root]){
        if(!seen[next]){
            dfs(G,next,counter[root]);//親の値を子に足す
        }
    }
}

Measured memory_bytes: 23552
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll N;
	cin >> N;
	ll a[N + 10];
	for (ll i = 0; i < N; i++) {
		cin >> a[i];
	}
	ll cnt0_mod4 = 0;
	ll cnt0_mod2 = 0;
  	ll cnt2_mod4 = 0;
	for (ll i = 0; i < N; i++) {
		if (a[i] % 4 == 0)
			cnt0_mod4++;
		if (a[i] % 2 == 0)
			cnt0_mod2++;
      	if(a[i]%4 == 2)
           cnt2_mod4++;
	}
	if (cnt0_mod4 >= N / 2 || cnt0_mod2 == N)
      	cout<<"Yes"<<endl;
  	else if(cnt0_mod4+(cnt2_mod4)/2>=N/2)
      cout<<"Yes"<<endl;
	else
		cout << "No" << endl;
	}








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

int reverse(string &s){
	int n = s.size(), n2 = n/2;
	for (int i=0; i<n2; i++)
		swap(s[i], s[n-1-i]);
	return 0;
}

int main(void){
	int n;
	cin>>n;
	for (int i=0; i<n; i++){
		string s1, s2, s3="";
		cin>>s1>>s2;

		reverse(s1);
		reverse(s2);

		while (s1.size()<s2.size()) s1 += '0';
		while (s2.size()<s1.size()) s2 += '0';

		int c=0, stmp;
		for (int i=0; i<s1.size(); i++){
			stmp = s1[i]-'0' + s2[i]-'0' + c;
			c = stmp / 10;
			s3 += stmp%10 +'0';
		}
		if (c!=0) s3 += c + '0';

		reverse(s3);
		if (s3.size()>80)
			cout<<"overflow"<<endl;
		else
			cout<<s3<<endl;

	}
	return 0;
}

Measured memory_bytes: 1220
{
  const main = (input: string): void | string | number => {
    const r = reader(input)
    const [A, B, T] = r.ns()

    return B * Math.floor(T / A)
  }

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    const nls = () => lines.map(Number)

    return { lines, s, n, ss, ns, nls }
  }

  const getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  const res = main(getInput())

  if (typeof res === 'number' || typeof res == 'string') console.log(res)
}


Measured memory_bytes: 7500
d=int(input())
a=[0 for i in range(26)]
c=list(map(int,input().split()))
l=[]
for i in range(d):
    l.append(list(map(int,input().split())))
    #print(c.index(max(c))+1)
p=[0]
ans=[]
for i in range(1,d+1):
    #t=int(input())-1
    k=[0 for i in range(26)]
    for t in range(26):
        a[t]=i
        for j in range(26):
            k[t]-=c[j]*(i-a[j])
    for j in range(26):
        k[j]+=l[i-1][j]
    #print(max(k))
    ans.append(k.index(max(k))+1)
#print(*p[1:],sep='\n')
print(*ans,sep='\n')

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;



signed main(){

    int X; cin >> X;
    chOut(X >= 30, "Yes", "No");

    return 0;
}


Measured memory_bytes: 3648
#coding:utf-8
#1_6_C 2015.4.5
house = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]

n = int(input())
for i in range(n):
    b,f,r,v = map(int,input().split())
    house[b - 1][f - 1][r - 1] += v

for b in range(4):
    for f in range(3):
        print(' ' + ' '.join(list(map(str,house[b][f]))))
    if b != 3:
        print('#' * 20)

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

int main() {
  int a , b ;
  cin >> a >> b ;
if ( (a * b) % 2 == 0 ){
    cout << "Even" <<endl;
}
if( (a * b) % 2 == 1) {
    cout << "Odd" << endl;
}
}

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

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

  string S; cin >> S;
  vector<ll> m(2020, 0);

  ll N = S.size();
  ll ten = 1;
  ll r = 0;
  m[r]++;
  for (ll i = N - 1; i >= 0; i--) {
    ll d = S[i] - '0';
    r += d * ten;
    r %= 2019;
    m[r]++;
    ten = (ten * 10) % 2019;
  }

  ll ans = 0;
  for (ll i = 0; i < 2019; i++) {
    ll t = m[i];
    ans += (t * (t - 1)) / 2;
  }

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

Measured memory_bytes: 3744
#include<bits/stdc++.h>
#define rgi register int
#define ll long long
class fastin{
	private: int _ch,_f;
	public: inline fastin& operator>>(char&c) {c=getchar(); return *this;}
		template<typename _Tp> inline fastin& operator>>(_Tp&_x){
		_x=0; while(!isdigit(_ch)) _f|=(_ch==45),_ch=getchar();
		while(isdigit(_ch)) _x=(_x<<1)+(_x<<3)+(_ch^48),_ch=getchar();
		_f&&(_x=-_x,_f=0); return *this;}
	fastin() {_ch=_f=0;}
}fin;
class fastout{
#define endl '\n'
	private: int _num[32],_head;
	public: inline fastout& operator<<(char c) {putchar(c); return *this;}
		template<typename _Tp> inline fastout& operator<<(_Tp _x){
		_Tp _k; if(_x==0) {putchar('0'); return *this;} if(_x<0) putchar('-'),_x=-_x;
		while(_x>0) _k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k;
		while(_head>0) putchar(_num[_head]),--_head; return *this;}
	fastout() {_head=0;}
}fout;
// ----------------------------
#define int ll
// using namespace std;
const int maxn=200004;
const int mod=998244353,inf=1000000007;

ll maxv=1e18;
int a[maxn];
signed main()
{
	int n; fin>>n;
	for(rgi i=1;i<=n;++i)
	{
		fin>>a[i];
		if(a[i]==0) {fout<<0; return 0;}
	}
	int res=1;
	for(rgi i=1;i<=n;++i)
	{
		if(res>maxv/a[i]) {puts("-1"); return 0;}
		res*=a[i];
		if(res>maxv) {puts("-1"); return 0;}
	}
	fout<<res;
	return 0;
}
// ----------------------------
// by imzzy


Measured memory_bytes: 4408
import scala.io.StdIn

object Main extends App {

  val l = StdIn.readLine().split(" ")
  val K = l(0).toInt
  val X = l(1).toInt

  if (impl(K, X)) println("Yes") else println("No")

  def impl(K: Int, X: Int): Boolean = {
    K * 500 >= X
  }
}

Measured memory_bytes: 25544
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC target ("avx,tune=native")
//Use above if bruteforcing with lots of small operations. Or just use it anytime, there's no downside.
//AVX is better slightly
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double ld;

ll inv(ll a, ll b){
    return (a > 1 ? b - inv(b%a, a)*b/a : 1);
}

#define rc(s) return cout << s, 0
#define fi first
#define se second
#define L (nod << 1)
#define R (L | 1)
#define smax(X, Y) ((X) > (Y) ? (X) : (Y))
#define smin(X, Y) ((X) < (Y) ? (X) : (Y))

const int MOD = 998244353;
const int N = 3010;

const ld e = 2.71828182845904523536028747;
const ld PI = 3.14159265359;
const ll inf = (1LL<<62);
const int iinf = (1<<30);
//CLOCKS_PER_SEC

int n, s, dp[N][N];
ll ans;

int main(){
    //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    ios_base::sync_with_stdio(0); cin.tie(0);
    //ifstream cin ("test.in");
    cin >> n >> s;
    for (int i=1, x; i<=n; i++){
        cin >> x;
        for (int j=1; j<=s; j++) dp[i][j] = dp[i-1][j];
        if (x == s) ans = (ans + i * (n - i + 1)) % MOD;
        for (int j=s; j>=x; j--){
            if (j == s) ans = (ans + 1LL * (n - i + 1) * dp[i-1][j-x]) % MOD;
            else if (j == x) dp[i][j] = (dp[i][j] + i) % MOD;
            else dp[i][j] = (dp[i][j] + dp[i-1][j-x]) % MOD;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 35584
import java.util.*;
public class Main{
	public static void main(String[] args)
	{
		 Scanner sc=new Scanner(System.in);
		 int i=sc.nextInt();
		 int j=sc.nextInt();
		 int min=9999;
		 int arr[]=new int[j];
		 List<Integer> li1=new ArrayList<Integer>();
		 int flag=0;
		 if(j==0)
		 {
			 System.out.println(i);
			 return;
		 }
		 for(int k=0;k<j;k++)
		 {
			 arr[k]=sc.nextInt();
			 li1.add(arr[k]);
		 }
		 if(!li1.contains(i))
		 {
			 System.out.println(i);
			 return;
		 }
		
		 for(int k=0;k<=j;k++)
		 {
			if((li1.contains(i+k))&&(li1.contains(i-k)))
			 { 
				 continue;
			 }
           
			 if(!li1.contains(i-k))
			 {
				 flag=1;
				
				 System.out.println(i-k);
                 break;
				 
			 }
			 if(!li1.contains(i+k))
			 {
				 flag=1;
				 System.out.println(i+k);
                 break;
				 
			 }
			 
			 
			 
			 
			 
		 }
		 
		 
	}

}


Measured memory_bytes: 35852
using System;

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int L = int.Parse(input[1]);

        input = Console.ReadLine().Split(' ');
        int[] a = new int[N];
        for(int i = 0; i < N; i++)
        {
            a[i] = int.Parse(input[i]);
        }

        int d = -1;

        for(int i = 0; i < N-1; i++)
        {
            if (a[i] + a[i + 1] >= L)
            {
                d = i+1;
                break;
            }
        }

        if (d == -1) Console.WriteLine("Impossible");
        else
        {
            Console.WriteLine("Possible");
            for (int i = 1; i < d; i++) Console.WriteLine(i);
            for (int i = N - 1; i > d; i--) Console.WriteLine(i);
            Console.WriteLine(d);
        }

    }
}

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

int main(){
  long long int i,j,k,l,n,m,N,ans=0;
  scanf("%lld",&N);
  
  long long int A[N+1];
  long long int C[N+1];
  long long int B[N];
  
  for(i=0;i<N;i++){
    A[i+1]=C[i+1]=0;
  }
  
  for(i=0;i<N;i++){
    scanf("%lld ",&l);
    B[i]=l;
    C[l]++;
    if(C[l]>=2){
      A[l]+=(C[l]-1);
      ans+=(C[l]-1);
    }
  }
  
  for(i=0;i<N;i++){
    printf("%lld\n",ans+1-C[B[i]]);
  }
  return 0;
}
  

Measured memory_bytes: 7168
#include <bits/stdc++.h>
#define ll long long

using namespace std;

// input
int n,k;
vector<int> vec;

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

    cin >> n >> k;

    ll onazi = 0;

    ll syurui = 0;

    ll ans = 0;

    // for(int i = )

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

        if ((i % k) * 2 == k){
            syurui += 1;
        }
        else if((i+i) % k == 0){
            onazi++;
        }

    }


    ans += pow(onazi,3);
    ans += pow(syurui,3);

    cout << ans << "\n";


}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import sys
n, m = map(int, input().split())
# demands = [tuple(map(int, input().split())) for i in range(m)]
demands = [
    tuple(map(int,
              line.strip().split())) for line in sys.stdin.readlines()
]
demands.sort(key=lambda x: x[1])

compressed = []
while demands:
    a, b = demands.pop()

    for i, (ai, bi) in enumerate(compressed):
        if b <= ai or bi <= a:
            continue

        else:
            compressed[i] = [max(a, ai), min(b, bi)]
            break

    else:
        compressed.append([a, b])

print(len(compressed))


Measured memory_bytes: 23732
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W, h, w = map(int, read().split())

    print((H - h) * (W - w))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9020