akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h> 
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#define mod 1000000007
#define mod2 998244353
#define int long long
#define endl "\n"
#define p_b push_back
#define m_p make_pair
#define fastIO ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
using namespace __gnu_pbds;
template <class T> 
using _ost = tree<
		T, 
		null_type, 
		less<T>, 
		rb_tree_tag, 
        tree_order_statistics_node_update>;

// char alphabet[26] = {'a','b','c','d','e','f','g','h','i',
//        'j','k','l','m','n','o','p','q','r','s','t','u','v',
//        'w','x','y','z'};


int32_t main(){
 	fastIO;
 	int n,k;cin>>n>>k;
 	map<int,int> cnt;
 	for(int i=0;i<k;i++){
 		int d;
 		cin>>d;
 		int a;
 		for(int i=0;i<d;i++){
 			cin>>a;
 			cnt[a]++;
 		}
 	}
 	int ans=0;
 	for(int i=1;i<=n;i++){
 		ans+=cnt[i]==0;
 	}
 	cout<<ans<<endl;
} 			



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

int main()
{
	string str;
	double s[128];

	while(getline(cin,str))
	{
		int t = 0;
		stringstream ss;
		ss << str;
		while(ss >> str)
		{
			     if(str=="+") { s[t-2] = s[t-2]+s[t-1]; t--; }
			else if(str=="-") { s[t-2] = s[t-2]-s[t-1]; t--; }
			else if(str=="*") { s[t-2] = s[t-2]*s[t-1]; t--; }
			else if(str=="/") { s[t-2] = s[t-2]/s[t-1]; t--; }
			else { s[t] = atoi(str.c_str()); t++; }
		}

		printf("%.6lf\n",s[0]);
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
using namespace std;

string s;
bool a[50];
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>s;
  for(int i=0;i<(int)s.length();i++){
    a[s[i]-'a']=1;
  }
  for(int i=0;i<26;i++){
    if(!a[i]){cout<<(char)('a'+i)<<endl; break;}
    if(i==25)cout<<"None"<<endl;
  }

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

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

int main(){
	int a,b;
	while(cin>>a>>b){
		int n=a+b;
		int ans=0;
		while(n>0){
			n/=10;
			ans++;
		}
		if(ans==0)ans++;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 2976
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M; cin >> N >> M;
	vector<int> coins(M+1); rep(i, 1, M+1) { cin >> coins[i]; }
	vector<vector<int>>dp(M + 1, vector<int>(N + 1, INF));
	rep(i, 1, M + 1)rep(j, 0, N + 1) {
		if (j == 0)dp[i][j] = 0;
		else {
			dp[i][j] = dp[i - 1][j];
			if (j - coins[i] >= 0)chmin(dp[i][j], dp[i][j - coins[i]]+1);
		}
	}
	cout << dp[M][N] << endl;
	return 0;
}

Measured memory_bytes: 7128
def b_collatz_problem():
    def collatz(n):
        return n // 2 if n % 2 == 0 else 3 * n + 1

    S = int(input())
    collatz_set = {S}
    num = S
    ans = 1
    while True:
        num = collatz(num)
        ans += 1
        if num in collatz_set:
            return ans
        collatz_set.add(num)

print(b_collatz_problem())

Measured memory_bytes: 3060
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0, _n = (int)(n); i < _n; ++i)
#define int long long
const int N = 0, mod = 0;
int a[3];
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    for (int i = 0; i < 3; ++i)
        cin >> a[i];
    long long res = 1e18 + 1;
    for (int i = 0; i < 3; ++i)
        res = min(res, (a[i] & 1) * a[(i + 1) % 3] * a[(i + 2) % 3]);
    cout << res << endl;


}




Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b1 = []
b2 = []
m = n % 2
for i in range(n):
  if i % 2 == m:
    b1.append(a[i])
  else:
    b2.append(a[i])
b2 = b2[::-1]
b = b2 + b1
b = [str(bb) for bb in b]
b = ' '.join(b)
print(b)

Measured memory_bytes: 31428
#include <iostream>
#include <string>
using namespace std;
 
long long GCD(long long n, long long m) {
    return m ? GCD(m, n % m) : n;
}
 
int main() {
    long long n, m; cin >> n >> m;
    string s, t; cin >> s >> t;
    
    long long g = GCD(n, m);
    long long res = n / g * m;
    n /= g, m /= g;
    bool ok = true;
    for (long long i = 0; i < g; ++i) {
        if (s[i*n] != t[i*m]) ok = false;
    }
    if (ok) cout << res << endl;
    else cout << -1 << endl;
}

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

signed main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n, p;
	string s;
	cin >> n >> p >> s;
	int ans = 0;
	map<int, int> m;
	if(p <= 100) {
		for(int i = 0; i < n; ++i) {
			// Just s[i]
			int use = (s[i] - '0') % p;
			if(use == 0) {
				++ans;
			}
			// New map
			map<int, int> nm;
			for(auto it: m) {
				int r1 = (10 * it.first + use) % p;
				if(r1 == 0) {
					ans += it.second;
				}
				nm[r1] += it.second;
			}

			++nm[use];
			m = nm;
		}
		cout << ans;
	}
	else {
		vector<int> pre(n);
		int ten = 1;
		for(int i = n-1; i >= 0; --i) {
			pre[i] = (ten * (s[i] - '0')) % p;
			ten = (ten * 10) % p;
		}
		for(int i = 1; i < n; ++i) pre[i] = (pre[i] + pre[i-1]) % p;
		m[0] = 1;
		for(int i = 0; i < n; ++i) {
			ans += m[pre[i]];
			++m[pre[i]];
		}
		cout << ans;
	}
	return 0;
}


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

using namespace std;

long long ans;
int n;
unordered_map<string, int> m;

int main(){
	cin >> n;
	for(int i = 0; i < n; ++i){
		string s; cin >> s;
		sort(s.begin(), s.end());
		if(m.find(s) != m.end()){
			m[s]++;
		}else{
			m.emplace(s, 1);
		}
	}
	for(auto itr = m.begin(); itr != m.end(); ++itr){
		ans += 1LL * itr->second * (itr->second - 1) / 2;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 10660
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define pai 3.141592653589793238462643383279

/* SegTree<X>(n,fx,ex): モノイド(集合X, 二項演算fx, 単位元ex)についてサイズnで構築
    set(int i, X x), build(): i番目の要素をxにセット。まとめてセグ木を構築する。O(n)
    update(i,x): i 番目の要素を x に更新。O(log(n))
    query(a,b):  [a,b) 全てにfxを作用させた値を取得。O(log(n))
*/
template <typename X>
struct SegTree {
    using FX = function<X(X, X)>;
    int n;
    FX fx;
    const X ex;
    vector<X> dat;
    SegTree(int n_, FX fx_, X ex_) : n(), fx(fx_), ex(ex_), dat(n_ * 4, ex_) {
        int x = 1;
        while (n_ > x) {
            x *= 2;
        }
        n = x;
    }
 
    void set(int i, X x) { dat[i + n - 1] = x; }
    void build() {
        for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]);
    }
 
    void update(int i, X x) {
        i += n - 1;
        dat[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;  // parent
            dat[i] = fx(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }
 
    // the minimum element of [a,b)
    X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
    X query_sub(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) {
            return ex;
        } else if (a <= l && r <= b) {
            return dat[k];
        } else {
            X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return fx(vl, vr);
        }
    }
    /* debug */
    inline X operator[](int a) { return query(a, a + 1); }
    void print() {
        for (int i = 0; i < n; ++i) {
            cout << (*this)[i];
            if (i != n) cout << ",";
        }
        cout << endl;
    }
};


int main(){
  int N, K; cin >> N >> K; int P[N];
  rep(i, N){
    cin >> P[i];
  }
  int cnt[N] = {};
  rep(i, N-1){
    if(P[i+1]>P[i]) cnt[i+1]++;
  }
  rep(i, N-1){
    cnt[i+1]+=cnt[i];
  }
  int ans = 1; bool sorted[N-K+1] = {};
  rep(i, N-K+1){
    sorted[i] = (cnt[i+K-1]-cnt[i]==K-1);
  }
  //rep(i, N){
    //cout << cnt[i] << " ";
  //}
  //cout << endl;
  using X = int;
  auto fx = [](X x1, X x2) -> X{return max(x1,x2);};
  auto gx = [](X x1, X x2) -> X{return min(x1,x2);};
  auto eax = 0; auto ebx = inf;
  SegTree<X> segma(N, fx, eax);
  SegTree<X> segmi(N, gx, ebx);
  rep(i, N){
    segma.set(i, P[i]);
    segmi.set(i, P[i]);
  }
  segma.build(); segmi.build(); int so = 0;
  if(sorted[0]){
    so = 1; ans = 0;
  }
  for(int i=0; i<N-K; i++){
    int M = segma.query(i, i+K+1);
    int m = segmi.query(i, i+K+1);
    //cout << m << " " << M << endl;
    if(m==P[i] && M==P[i+K]) continue;
    if(sorted[i+1]){
      so = 1; continue;
    }
    ans++;
  }
  cout << ans+so << endl;
}
  

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

int main(){
	int A,B,calc[3];
	cin>>A>>B;
	calc[0]=A+B;
	calc[1]=A-B;
	calc[2]=A*B;
	sort(calc,calc+3);
	cout<<calc[2]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
using namespace std;
int main(void){
    int N;
    cin>>N;
    char str[N+5];
    cin>>str;
    int wall=0;
    for(int i=0;i<N;i++){
        if(str[i]=='W'){wall++;}
    }
    int eall=N-wall;
    int ans=10000000; int wcount=0; int ecount=0; int wleft=0; int eright=0;
    for(int i=0;i<N;i++){
      if(str[i]=='W'){wleft=wcount; eright=eall-ecount; wcount++;}
      else {wleft=wcount; ecount++; eright=eall-ecount;}
      if(ans>(wleft+eright)){ans=wleft+eright;}
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 512
//#include<bits/stdc++.h>
//using namespace std;
//int main()
//{
//	int n;
//	while(cin>>n)
//	cout<<3*n*n<<endl;
//}

//#include<bits/stdc++.h>
//using namespace std;
//int main()
//{
//	int n,d;
//	while(cin>>n>>d)
//	{
//		int sum=0,num=0;
//		for(int i=2*d+1;i<n;i+=(2*d+1))
//		{
//			num++;
//		}
//		cout<<num+1<<endl;
//	}
//}
#include<bits/stdc++.h>
using namespace std;
int s[1000010];
int main()
{
	int n;
	while(cin>>n)
	{
		priority_queue<int> pq;
		memset(s,0,sizeof(s));
		for(int i=1;i<=n;i++)
		{
			cin>>s[i];
			pq.push(s[i]);
		}
		for(int i=1;i<=n;i++)
		{
			if(pq.top()!=s[i])
			cout<<pq.top()<<endl;
			else
			{
				int a=pq.top();
				pq.pop();
				cout<<pq.top()<<endl;
				pq.push(a);
			} 
		}
	}
 } 

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

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ar array
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll mod = 1e9 + 7;
const ll inf = 2e9 + 5;
double PI = 3.14159265358979323846;

void solve() {

	int n;
	cin >> n;
	if(n)cout << 0 << endl;
	else cout << 1 << endl;

}

int32_t main()
{
    IOS
    // int T; cin >> T; while (T--)
    solve();
    return 0;
}


Measured memory_bytes: 3600
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math;


void main() {
    int n;
    scan(n);
    auto p = readln.split.to!(int[]);

    auto a = new int[](n);
    auto b = new int[](n);
    foreach (i ; 0 .. n) {
        a[i] = (i + 1) * (n + 1);
        b[n - 1 - i] = (i + 1) * (n + 1);
    }

    auto aim = new int[](n + 1);
    auto bim = new int[](n + 1);

    p[] -= 1;
    foreach (pi ; p[0 .. $-1]) {
        aim[pi + 1]++; aim[n]--;
        bim[0]++; bim[pi]--;
    }
    foreach (i ; 0 .. n) {
        aim[i + 1] += aim[i];
        bim[i + 1] += bim[i];
    }

    foreach (i ; 0 .. n) {
        a[i] += aim[i];
        b[i] += bim[i];
    }

    debug {
        writeln(aim);
        writeln(bim);
        writeln(a);
        writeln(b);
    }

    foreach (i ; 0 .. n - 2) {
        a[p[i]] -= (n - 2 - i);
    }

    writefln("%(%s %)", a);
    writefln("%(%s %)", b);
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 3196
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
using namespace std;
const int maxn=1e5+10;
struct num
{
    int l,r;
} a[3*maxn];
struct node
{
    int l,r,sum,mark;
} tre[maxn<<2];
void build(int l,int r,int rt)
{
    tre[rt].l=l;
    tre[rt].r=r;
    tre[rt].mark=0;
    if(l==r)
    {
        tre[rt].sum=0;
        return ;
    }
    int mid=(l+r)>>1;
    build(l,mid,rt<<1);
    build(mid+1,r,rt<<1|1);
    tre[rt].sum=tre[rt<<1].sum+tre[rt<<1|1].sum;
    return ;
}
void pushdown(int rt)
{
    if(tre[rt].mark)
    {
        tre[rt<<1].sum+=(tre[rt<<1].r-tre[rt<<1].l+1)*tre[rt].mark;
        tre[rt<<1|1].sum+=(tre[rt<<1|1].r-tre[rt<<1|1].l+1)*tre[rt].mark;
        tre[rt<<1].mark+=tre[rt].mark;
        tre[rt<<1|1].mark+=tre[rt].mark;
        tre[rt].mark=0;
    }
}
void update(int l,int r,int val,int rt)
{
    if(tre[rt].l>=l&&tre[rt].r<=r)
    {
        tre[rt].sum+=(tre[rt].r-tre[rt].l+1)*val;
        tre[rt].mark+=val;
    }
    else
    {
        pushdown(rt);
        int mid=(tre[rt].l+tre[rt].r)>>1;
        if(l>mid) update(l,r,val,rt<<1|1);
        else if(r<=mid) update(l,r,val,rt<<1);
        else
        {
            update(l,r,val,rt<<1);
            update(l,r,val,rt<<1|1);
        }
        tre[rt].sum=tre[rt<<1].sum+tre[rt<<1|1].sum;
    }
}
int query(int pos,int rt)
{
    if(tre[rt].l==pos&&tre[rt].r==pos) return tre[rt].sum;
    else
    {
        pushdown(rt);
        int mid=(tre[rt].l+tre[rt].r)>>1;
        if(pos>mid)return query(pos,rt<<1|1);
        else if(pos<=mid) return query(pos,rt<<1);
    }
}
int n,m;
vector<int>q[maxn];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0; i<=m; i++)q[i].clear();
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d",&a[i].l,&a[i].r);
        q[a[i].r-a[i].l+1].push_back(i);
    }
    build(1,m,1);
    for(int i=1; i<=m; i++)
    {
        int ans=0;
        n-=q[i].size();
        for(int j=0; j<q[i].size(); j++) update(a[q[i][j]].l,a[q[i][j]].r,1,1);
        for(int j=i; j<=m; j+=i) ans+=query(j,1);
        printf("%d\n",ans+n);
    }

}

Measured memory_bytes: 14976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,W;
    cin>>n>>W;
    int w[n],v[n];
    for(int i=0;i<n;i++){
        cin>>w[i]>>v[i];
    }
    vector<int> vec[4];
    for(int i=0;i<n;i++){
        vec[w[i]-w[0]].push_back(v[i]);
    }
    for(int i=0;i<4;i++){
        vec[i].push_back(INF);
        sort(vec[i].begin(),vec[i].end(),greater<int>());
        vec[i][0]=0;
        for(int j=1;j<vec[i].size();j++){
            vec[i][j]=vec[i][j]+vec[i][j-1];
        }
    }
    int ans=0;
    for(int i=0;i<vec[0].size();i++){
        for(int j=0;j<vec[1].size();j++){
            for(int k=0;k<vec[2].size();k++){
                for(int l=0;l<vec[3].size();l++){
                    if(((ll)(i+j+k+l)*w[0]+j+2*k+3*l)<=W){
                        ans=max(ans,vec[0][i]+vec[1][j]+vec[2][k]+vec[3][l]);
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}


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

int main() {
  vector<int> BJ(3);
  
  for ( int i=0; i < 3; i++) {
		cin >> BJ.at(i);
        }
        
	int sum = 0;
    for ( int l=0; l<3; l++) {
    	sum += BJ.at(l);
        }
        
    if ( sum <= 21) {
        cout << "win" << endl;
    }
    else {
        cout << "bust" << endl;
    }
}

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

#define I inline
#define fi first
#define se second
#define R register
#define LL long long
#define mp make_pair
#define reg register int
#define pii pair<int,int>
#define fo(i, a, b) for(reg i = a; i <= b; i++)
#define fd(i, a, b) for(reg i = a; i >= b; i--)
#define cr const reg&
using namespace std;
const int inf = 2147483647;
const int N = 2e5 + 1;

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I LL read() {
	LL x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(LL x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(LL x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(LL x) {put(x), putchar(' ');}
I void pr2(LL x) {put(x), puts("");}

char ss[N];

int main() {
	scanf("%s", ss + 1);
	reg n = strlen(ss + 1);
	LL ans = 0, f0 = 0, f1 = 0;
	fo(i, 1, n) {
		if(ss[i] == '1') {
			if(i & 1) f1++;
			else f0++;
			ans += i + 1 >> 1;
		} else {
			f0 = f1 = max(f0, f1);
			ans += f1;
		}
	}
	pr2(ans);
	return 0;
}



Measured memory_bytes: 3964
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def MI(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
A = MI(N,1)

if A[0] != 0:
    print(-1)
    exit()

ans = 0
for i in range(1,N):
    if A[i]-A[i-1] >= 2:
        print(-1)
        exit()
    else:
        if A[i]-A[i-1] == 1:
            ans += 1
        else:
            ans += A[i]

print(ans)

Measured memory_bytes: 51292
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int main(){
  long long N;
  long long ans=0;
 
  scanf("%lld",&N);
  if(N & 1) {
      printf("0\n");
	  return 0;
  }
  
  for(long long i=10; i<= N; i*=5){
    ans += N / i;
  }
  printf("%lld\n", ans);
  return 0;

}

Measured memory_bytes: 128
#include <stdio.h>
int main(void)
{
    int n,m,l,A[100][100],B[100][100],i,j,k,c;
    long C[100][100]={};
    
    scanf("%d %d %d",&n,&m,&l);
    
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++) scanf("%d",&A[i-1][j-1]);
    }
    
    for(j=1;j<=m;j++)
    {
        for(k=1;k<=l;k++) scanf("%d",&B[j-1][k-1]);
    }
    
    for(i=1;i<=n;i++)
    {
        for(k=1;k<=l;k++)
        {
            for(j=1;j<=m;j++)
            {
                c=0;
                c=A[i-1][j-1]*B[j-1][k-1];
                C[i-1][k-1]=C[i-1][k-1]+c;
            }
            if(k==1) printf("%ld",C[i-1][k-1]);
            else printf(" %ld",C[i-1][k-1]);
        }
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 2104
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        int length = s.length();

        StringBuilder sb = new StringBuilder(s);

        int turn = 0; // 偶数 = 高橋, 奇数 = 青木

        int i = 1;
        while (i < length - 1) {
//            System.out.println(i + " : " + sb.toString());

            if (sb.length() <= 2) {
                // give up
                System.out.println((turn % 2 == 0) ? "Second" : "First");
                return;
            }

            if (sb.charAt(i - 1) == sb.charAt(i + 1)) {
                // とれない
//                System.out.println("とれない");
                sb.deleteCharAt(i);
                sb.deleteCharAt(i - 1);

                if (sb.length() <= 2) {
                    // give up
                    System.out.println((turn % 2 == 0) ? "Second" : "First");
                    return;
                }

                if (i >= length - 2) {
                    // give up
                    System.out.println((turn % 2 == 0) ? "Second" : "First");
                    return;
                }

            } else {
                // とれる
//                System.out.println("とれる");
                sb.deleteCharAt(i);
                turn++;
            }
        }
    }
}


Measured memory_bytes: 25880
from sys import stdin
import math


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = float('inf')
    for A in range(1,int(math.sqrt(N))+1):
        if N%A==0:
            B = N//A
            cnt = min(cnt,max(len(str(A)),len(str(B))))
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


Measured memory_bytes: 38768
import java.io.FileNotFoundException;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {

        Scanner in = new Scanner(System.in);
//        Scanner in = new Scanner(new File("input.txt"));

        int n = in.nextInt();
        BigInteger b = new BigInteger("1");
        BigInteger c = new BigInteger("1000000000000000000");
        long[] nums = new long[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextLong();
        }
        Arrays.sort(nums);

        if (nums[0] == 0) {
            System.out.println(0);
            return;
        }

        for (int i = 0; i < n; i++) {
            b = b.multiply(new BigInteger(String.valueOf(nums[i])));

            if (b.compareTo(c) > 0) {
                System.out.println(-1);
                return;
            }
        }

        System.out.println(b.toString());
    }
}


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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 2019

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ll n;
    cin >> n;
    vi dam(n);
    REP(i, 0, n) {
        cin >> dam[i];
        dam[i] *= 2;
    }
    ll a = dam[0], b = dam[n-1];
    REP(i, 1, n-1) {
        if (i%2)
            a -= dam[i];
        else
            a += dam[i];
    }
    vi mnt(n);
    mnt[0] = (a + b)/2;
    mnt[n-1] = b - mnt[0];
    REP(i, 1, n-1)
        mnt[i] = dam[i-1] - mnt[i-1];
    print(mnt);
    cout << endl;
    return 0;
}


Measured memory_bytes: 2944
#include<stdio.h>
int main(void){
    int a, b;
    scanf("%d%d", &a, &b);
    if(a<b){
        printf("a < b\n");
    }else{
        if(a>b){
            printf("a > b\n");
        }else{
            printf("a == b\n");
        }
    }
    return 0;
}

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

public class Main {
    static PrintWriter out;
    static CF_Reader in;
    static long[][] arr;
    static int n;
    static Long[][] dp;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new CF_Reader();

        n = in.intNext();
        long k = in.longNext();
        arr = new long[n][2];
        for (int i = 0; i < n; i++) arr[i] = new long[]{in.longNext(), in.longNext()};
        dp = new Long[n][(int)k + 1];
        for(Long[] row: dp) Arrays.fill(row, null);
        out.println(solve(0, k));

        out.close();
    }

    static long solve(int idx, long k) {
        if (idx >= n || k <= 0) return 0;
        if (dp[idx][(int)k] == null) {
            // skip
            long skip = solve(idx + 1, k);
            // add it
            long added = 0;
            if (arr[idx][0] <= k) added = arr[idx][1] + solve(idx + 1, k - arr[idx][0]);
            dp[idx][(int)k] = Math.max(skip, added);
        }
        return dp[idx][(int)k];
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}


Measured memory_bytes: 283916
import java.util.Scanner;


public class Main {
	
	static int cur=0, p, q, r;
	static String str;
	
	static int no() {
		int start=cur;
		while(cur<str.length()&&str.charAt(cur)=='-') {
			cur++;
		}
		int end=cur;
		int now=solve();
		//int now=str.charAt(cur)=='P'?p:(str.charAt(cur)=='Q'?q:(str.charAt(cur)=='R'?r:str.charAt(cur)-'0'));
		for(int i=0; i<(end-start); i++) {
			now=2-now;
		}
		return now;
	}
	
	static int solve2() {
		int a=solve();
		cur++;
		while(cur<str.length()&&(str.charAt(cur)=='+'||str.charAt(cur)=='*')) {
			char op=str.charAt(cur++);
			int b=solve();
			if(op=='+')	a=Math.max(a, b);
			else if(op=='*') a=Math.min(a, b);
		}
		return a;
	}
	
	static int solve() {
		if(str.charAt(cur)!='(') {
			if(str.charAt(cur)=='-') {
				return no();
			}
			else {
				return str.charAt(cur)=='P'?p:(str.charAt(cur)=='Q'?q:(str.charAt(cur)=='R'?r:str.charAt(cur)-'0'));
			}
		}
		cur++;
		int n=solve2();
		cur++;
		return n;
	}
	
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				str=sc.next();
				if(str.equals(".")) break;
				int count=0;
				for(p=0; p<3; p++){
					for(q=0; q<3; q++){
						for(r=0; r<3; r++){
							cur=0;
							if(solve()==2)  count++;
						}
					}
				}
				System.out.println(count);
			}
		}
	}
}


Measured memory_bytes: 31316
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <=0){
                return false;
            }
        }
        return true;
    }

    private int readByte(){
        if(hasNextByte())return buffer[ptr++];
        else return -1;
    }

    private static boolean isPrintableChar(int c){
        return 33<=c && c<=126;
    }
    public boolean hasNext(){
        while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;
        return hasNextByte();
    }

    public String next(){
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b<='9'){
                n*=10;
                n+=b-'0';
            }else if(b==-1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDoutble(){return Double.parseDouble(next());}
}
public class Main{
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
        }
        
        int max1,max2;
        if(a[0]<=a[1]){
            max1 = 1;
            max2 = 0;
        }else{
            max1 = 0;
            max2 = 1;
        }
        for(int i=2;i<n;i++){
            if(a[max1] <= a[i]){
                max2 = max1;
                max1 = i;
            }else if(a[max2] <=a[i]){
                max2 = i;
            }
        }
        for(int i=0;i<n;i++){
            if(i==max1){
                System.out.println(a[max2]);
            }else{
                System.out.println(a[max1]);
            }

        }
    }

}

Measured memory_bytes: 58048
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <regex>
#include <random>

#define ll long long
#define ld long double
#define ull unsigned ll
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int> 
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vector<int>>
#define forn(it,from,to) for(int (it)=from; (it)<to; (it)++)
const int  Inf = 2 * 1000 * 1000 * 1000;
ll LINF = (ll)4e18;
using namespace std;
#define M_PI       3.14159265358979323846   // pi

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<int>a(n);
	for (auto &x : a) cin >> x;
	
	vector<int>D(n + 1, 2e9);
	D[0] = 0;

	for (int i = 0; i < n; i++) {
		for (int j : { i + 1, i + 2 }) {
			if (j < n) {
				D[j] = min(D[j], D[i] + abs(a[j] - a[i]));
			}
		}
	}
	cout << D[n - 1];
 	return 0;
}

Measured memory_bytes: 1024
x = int(input())
nums = list(map(int,input().split()))

count = 0
flag = 1

while flag == 1:
    for i in range(len(nums)):
        x = nums[i]%2
        if x == 0:
            nums[i] = nums[i]/2
            continue
        else:
            flag = 0
            break
    if flag == 1:
        count = count+1

print(count)


Measured memory_bytes: 3060
n, kk, c = [int(i) for i in input().split()]
c = c+1
s = input()
dp1 = []
j = -c
k = 0
for i in range(n):
    if s[i] != "x" and j + c <= i:
        k += 1
        j = i
    dp1.append([k, j])

dp2 = []
j = n-1+c
k = 0
for i in reversed(range(n)):
    if s[i] != "x" and j - c >= i:
        k += 1
        j = i
    dp2.append([k, j])
dp2.reverse()


for i in range(n):
    if s[i] == "x":
        continue
    a, b = dp1[i - 1] if i > 0 else[0, -c]
    b += c
    b = max(b, i+1)
    if b == i:
        b += 1
    if b < n:
        a += dp2[b][0]
    if a < kk:
        print(i+1)


Measured memory_bytes: 71232
N, M, X = map(int, input().split())
Cost = []
A = []
for _ in range(N):
    temp = list(map(int, input().split()))
    Cost.append(temp[0])
    A.append(temp[1:])
mincos = float('inf')

flag = False
for i in range(1, 2**N):
    cost = 0
    Learn = [0] * M
    for j in range(N):
        if (i >> j) & 1 == 1:
            cost += Cost[j]
            for k in range(M):
                Learn[k] += A[j][k]
    fla = True
    for a in range(M):
        if Learn[a] < X:
            fla = False
            break
    if fla:
        flag = True
        mincos = min(mincos, cost)

if flag:
    print(mincos)
else:
    print(-1)


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

typedef long long ll;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ll MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0) ;

int main()
{
    ll arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51} ;
    ll n ;
    cin >> n ;
    cout << arr[n - 1] ;
    return 0 ;
}


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

using namespace std;

int main() {
	int n, i, j, k;
	vector<int>a, b;

	cin >> n;

	for (i = 0; i < n; i++) {
		cin >> j;
		a.push_back(j);
	}

	for (i = n - 1; i >= 0; i -= 2) {
		b.push_back(a[i]);
	}
	if (i == -1) {
		for (i = 0; i < n; i += 2) {
			b.push_back(a[i]);
		}
	}
	else {
		for (i = 1; i < n; i+=2) {
			b.push_back(a[i]);
		}
	}

	for (i = 0; i < n; i++) {
		cout << b[i] << " ";
	}
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
void fn(int a,int b,int n,vector<int> &z)
{
  static vector<int> d(n+1,0);
  if(a==-1)
  {
    z[0]=d[0];
    for(int i=1;i<n;i++)
    {
      z[i]=d[i]+z[i-1];
    }
    d=vector<int> (n+1,0);
  }
  else
  {
    d[a]+=1;d[b+1]-=1;
  }
}
int main()
{
  ios_base::sync_with_stdio(false);
	cin.tie(NULL);
  int n,k;
  cin>>n>>k;
  vector<int> a(n),c(n,0),d(n,0),q(n,n);
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  for(int i=0;i<k;i++)
  {
    for(int j=0;j<n;j++)
    {
      int k=max(0,j-a[j]),l=min(n-1,j+a[j]);
      fn(k,l,n,c);
    }
    fn(-1,-1,n,c);
    a=c;
    c=d;
    if(a==q)
      break;
  }
  for(int i=0;i<n;i++)
    cout<<a[i]<<" ";
}


Measured memory_bytes: 7936
#include "stdio.h"

int main(void)
{
    long int x;
    long int y;
    int turu=-1;
    int kame=-1;
    int flag=0;

    scanf("%ld",&x);
    scanf("%ld",&y);

    int i,j;
    for(i=0;i+j<=x;i++)
    {
        for(j=0;i+j<=x;j++)
        {
            if((x==i+j)&&(y==2*i+4*j))
            {
                flag =1;

            }
        }j=0;
    }
    if(flag ==1)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    
    return 0;
}

Measured memory_bytes: 1736
import math
import numpy as np
import re


def inputs(): return [int(s) for s in input().split()]


def main():
    s = input()
    buf = '-1'
    for st in s:
        if buf == st:
            return 'Bad'
        buf = st
    return 'Good'


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 21572
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,string> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int a,b;
	while(cin>>a>>b,a){
		int d=a*a+b*b;
		int outa=inf,outb=inf,outd=inf;
		loop(i,1,151)loop(j,i+1,151){
			int nd=i*i+j*j;
			if(i==a&&j==b)continue;
			if(nd==d&&i<a)continue;
			if(d>nd)continue;
			if(outd==nd){
				if(outa>i){
					outa=i;
					outb=j;
					outd=nd;
				}//16+49=65 1+64=65
			}else if(outd>nd){
				outa=i;
				outb=j;
				outd=nd;
			}
		}
		cout<<outa<<" "<<outb<<endl;
	}
}

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

int main() {
  long long N, K;
  vector <long long> x, cand;
  cin >> N >> K;
  for (long long i = 0; i < N; i++) {
    long long tmp;
    cin >> tmp;
    x.push_back(tmp);
  }
  long long begin, end;
  for(long long i = 0; i <= N - K; i++) {
    begin = i;
    end = i+K-1;
    if (x[begin] * x[end] < 0) {
      // inner
      long long dist = min(abs(x[begin]) + abs(x[begin] - x[end]), abs(x[end]) + abs(x[begin] - x[end]));
      cand.push_back(dist);
    } else {
      long long dist = max(abs(x[begin]), abs(x[end]));
      cand.push_back(dist);
    }
  }
  cout << *min_element(cand.begin(), cand.end());
  return 0;
}

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

using namespace std;

#define si(a) scanf("%d",&a)
#define f first
#define s second
#define mp(a,b) make_pair(a,b)
#define MAX 200005

long long kombe[MAX],cnt[MAX],arek[MAX];

int main()
{
    //freopen("input.txt","r",stdin);
    int n,m,i,now,prv;
    si(n);si(m);
    long long ans=0;
    for(i=0;i<n;i++){
        si(now);now--;
        int nn=now;
        if(i){
            if(prv>now)
                now+=m;
            ans+=(now-prv);
            cnt[prv+1]++;
            cnt[now]--;
            arek[now]+=(now-prv-1);
        }
        prv=nn;
    }
    long long str=0,tmp=0;
    long long mx=0;
    for(i=0;i<MAX;i++){
        tmp+=str;
        kombe[i%m]+=tmp;
        str+=cnt[i];
        tmp-=arek[i];
    }
    for(i=0;i<m;i++)mx=max(mx,kombe[i]);
    cout<<ans-mx<<endl;
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=998244353;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main() {
    string s;cin>>s;
    if(s.back()=='s')s+="es";
    else s+='s';
    out(s);
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define all(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

string solve(int n) {
	if (n == 0) return "0";
	string s = "";
	while (n != 1) {
		if (abs(n) % 2 == 0) {
			s = '0' + s;
			n /= -2;
		}
		else {
			s = '1' + s;
			n = (n - 1) / -2;
		}
	}
	return '1' + s;
}

int main() {
	int n;
	cin >> n;
	cout << solve(n) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <limits>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define lli long long int
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define um unordered_map
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define mem(data_structure, val) memset(data_structure, val, sizeof(data_structure))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define endl "\n"
const ll mod = 1e9+7;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 
um<pii, int, hash_pair> map_with_pair{};
priority_queue <int, vector<int>, greater<int> > pq_desc; // decreasing order

lli dfs(int node, lli *dp, vector<int> *graph) {
	if(dp[node] != -1) return dp[node];
	lli ans = 0;
	for(int child : graph[node]) {
		ans = max(ans, 1+dfs(child, dp, graph));
	}
	return dp[node] = ans;
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, m;
	cin >> n >> m;
	lli dp[n+1];
	mem(dp, -1);

	vector<int> graph[n+1];
	fo(i, n) graph[0].pb(i+1);

	fo(i, m) {
		int u, v;
		cin >> u >> v;
		graph[u].pb(v);
	}

	lli ans = dfs(0, dp, graph);

	cout << (ans-1) << endl;

	return 0;
}

Measured memory_bytes: 9592
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
N,Q = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N-1)]
PX = [tuple(map(int,input().split())) for i in range(Q)]
es = [[] for _ in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)
ps = [0] * N
for p,x in PX:
    ps[p-1] += x

ans = [0] * N
def dfs(v,p=-1):
    ans[v] = ans[p] + ps[v]
    for to in es[v]:
        if to==p: continue
        dfs(to,v)
dfs(0)
print(*ans)

Measured memory_bytes: 328152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using M = map<string,ll>;





int main(){
    int A;
    cin >> A;
    int B;
    cin >> B;
    if(0<A&&10>A&&0<B&&10>B)cout<<A*B<<endl;
    else cout<<-1<<endl;

return 0;


}  



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

int main() {
  #define int long long
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n + 1);
  vector<vector<int>> a(n + 1, vector<int>(m + 1));
  for (int i = 0; i < n; i++) {
    cin >> c.at(i);
    for (int j = 0; j < m; j++) {
      cin >> a.at(i).at(j);
    }
  }
  int cmin = 10000009;
  int d;
  int mayc;
  bool flag;
  for (int bit = 0; bit < (1<<n); bit++) {
    flag = true;
    mayc = 0;
    for (int i = 0; i < n; i++) {
      if (bit & (1<<i)) {
        mayc += c.at(i);
      }
    }
    for (int j = 0; j < m; j++) {
      d = 0;
      for (int i = 0; i < n; i++) {
        if (bit & (1<<i)) {
          d += a.at(i).at(j);
        }
      }
      if (d < x) {
        flag = false;
      }
    }
    if (flag) {
      cmin = min(cmin, mayc);
    }
  }
  if (cmin == 10000009) {
    cout << -1 << endl;
  }
  else {
    cout << cmin << endl;
  }
}


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

#define all(v) (v).begin(), (v).end()
using namespace std;

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

    vector <int> card(no_of_elements, 0);
    for(int i = 0; i < no_of_elements; i++)
        scanf("%d", &card[i]);

    sort(all(card));
    reverse(all(card));

    int difference = 0;
    for(int i = 0; i < no_of_elements; i++)
    {
        difference += (i%2 == 0 ? card[i] : -1*card[i]);
    }

    printf("%d\n", difference);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split(' ')))
ans1 = 0
ans2 = 0
sum1 = 0
sum2 = 0
flag = True
for i in range(len(A)):
    sum1 = sum1 + A[i]
    sum2 = sum2 + A[i]
    flag = not(flag)
    if flag:
        if sum1 > 0:
            pass
        else:
            ans1 += abs(1-sum1)
            sum1 = 1
        if sum2 < 0:
            pass
        else:
            ans2 += abs(-1-sum2)
            sum2 = -1
    else:
        if sum2 > 0:
            pass
        else:
            ans2 += abs(1-sum2)
            sum2 = 1
        if sum1 < 0:
            pass
        else:
            ans1 += abs(-1-sum1)
            sum1 = -1
print(min(ans1, ans2))


Measured memory_bytes: 14644