akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
 
int main(void){
 
  long long N,i;
  long long x = 0;
  long long max = 0;
  scanf("%lld",&N);
  char S[N];
  
  for(i=0;i<=N;i++){
  	scanf("%c",&S[i]);
  }
  
  for(i=0;i<=N;i++){
    if(S[i]=='D'){
      --x;
    }
    else if(S[i]=='I') ++x;
    if(x>max){
      max = x;
    }
  }
  printf("%lld",max);
  
  return 0;
  
}

Measured memory_bytes: 1704
#include<bits/stdc++.h>
//#include <time.h>
// #include<set>
// #include<vector>
// #include<algorithm>
// #include<iostream>
using namespace std;
#include <math.h>
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define maxn 3001
 
#define ll long long int
vector<vector<int> > mat(maxn,vector<int>(maxn,0));
int r,c,k;
ll dp[maxn][maxn][4];
long long int solve(int x,int y,int rn){
	//cout<<x<<" "<<y<<" "<<rn<<endl;
	if(x==r && y==c){
		if(rn==3)
			return 0;
		return mat[x][y];
	}
	ll ans=0;
	if(dp[x][y][rn]!=-1)
		return dp[x][y][rn];
	if(rn==3 || mat[x][y]==0 ){
		if(x<r){
			ans=max(ans,solve(x+1,y,0));
		}
		if(y<c){
			ans=max(ans,solve(x,y+1,rn));
		}
		//return ans;
	}
	else{
		if(x<r){
			ans=max(ans,mat[x][y] + solve(x+1,y,0));
		}
		if(y<c){
			ans=max(ans,mat[x][y] + solve(x,y+1,rn+1));
			ans=max(ans,solve(x,y+1,rn));
		}
		//return ans;
	}
	return dp[x][y][rn]=ans;

}

 
int main(){
	memset(dp,-1,sizeof(dp));
	cin>>r>>c>>k;
 	for(int i=0;i<k;i++){
 		int r1,c1,v1;
 		cin>>r1>>c1>>v1;
 		mat[r1][c1]=v1;
 	}

 	cout<<solve(1,1,0)<<endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define _1 first
#define _2 second
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)

int main() {
  int a, b;
  cin >> a >> b;
  FOR(i, 1, 3) if (i != a && i != b) cout << i;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
even=[]
for a in A:
    if a%2==0:
        even.append(a)
    
if len(even)==0:
    print("APPROVED")
    exit()
    
ans=False
    
for e in even:
    if e%3==0 or e%5==0:
        ans=True
    else:
        ans=False
        break

print("APPROVED" if ans else "DENIED")

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Console;

namespace ConsoleApplication1
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            Output(Solve(Input()));
        }

        static int Solve(IList<int> input)
        {
            var a = input[0];
            var b = input[1];
            return Math.Max(Math.Max((a + b), (a - b)), (a*b));
        }
            

        static IList<int> Input()
        {
            var input = ReadLine()
                .Split(' ')
                .Select(int.Parse)
                .ToList();

            return input;
        }

        static void Output<T>(T a)
        {
            WriteLine(a);
        }
        static void Output(IEnumerable<int> list)
        {
            var sw = new StreamWriter(OpenStandardOutput()) {AutoFlush = false};
            SetOut(sw);

            Out.Flush();
        }
    }
}

Measured memory_bytes: 13268
// ABC_065_D

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

ll floor(ll a, ll b, ll x) {
	return (a * x) / b + a * (x / b);
}


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

	if(b - 1 >= n) cout << floor(a, b, n) << "\n";
	else cout << floor(a, b, b-1) << "\n";

	return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int N;
int d[17][17];
int dp[1 << 20];

int solve(int S) {
    int& res = dp[S];
    if (res >= 0) return res;
    if (S == (1 << N) - 1) {
        return res = 0;
    }
    res = 1e9;
    for (int u=0; u<N; ++u) {
        if (!(S >> u & 1)) {
            int ma = d[u][0];
            for (int u2=1; u2<=N; ++u2) {
                if (S >> (u2-1) & 1) ma = min(ma, d[u][u2]);
            }
            res = min(res, solve(S | (1 << u)) + ma);
        }
    }
    return res;
}

int main() {
    while (cin >> N, N) {
        fill(dp, dp+(1<<20), -1);
        rep(i, N) rep(j, N+1) cin >> d[i][j];
        cout << solve(0) << endl;
    }
    return 0;
}



Measured memory_bytes: 7160
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
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();
}

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

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

  int a, l;
  while (true) {
    cin >> a >> l;
    if (a == 0 && l == 0) break;
    map<int, pair<int, int>> mp;
    mp[a].first++;
    mp[a].second = 0;
    int cnt = 0, ans_i = 0, ans_j = 0, ans_a = 0;
    while (true) {
      cnt++;
      string s_a = to_string(a);
      for (int i = s_a.size(); i < l; i++) {
        s_a += "0";
      }
      sort(all(s_a));
      int amin = toInt(s_a);
      reverse(all(s_a));
      int amax = toInt(s_a);
      // cout << "amin = " << amin << "\n";
      // cout << "amax = " << amax << "\n";
      int diff = amax - amin;
      if (mp[diff].first > 0) {
        ans_j = mp[diff].second;
        ans_i = cnt;
        ans_a = diff;
        break;
      }
      mp[diff].first++;
      mp[diff].second = cnt;
      a = diff;
    }
    cout << ans_j << " " << ans_a << " " << ans_i - ans_j << "\n";
  }

  return 0;
}


Measured memory_bytes: 3280
#include<stdio.h>
#define ran 222222
int n;
int height[ran];
int L[ran],R[ran];
int st[ran],top;
int main(){
	int i;
	scanf("%d",&n);
		for(i=0; i<n; i++)
			scanf("%d",&height[i]);
//copied
		top=0;
		for(i=0; i<n; i++)
		{
			while(top>0 && height[st[top-1]]>=height[i])top--;
			if(top==0)L[i]=-1;else L[i]=st[top-1];
			st[top++]=i;
		}
		top=0;
		for(i=n-1; i>=0; i--)
		{
			while(top>0 && height[st[top-1]]>=height[i])top--;
			if(top==0)R[i]=n;else R[i]=st[top-1];
			st[top++]=i;
		}
		long long int ans=0,X;
		for(i=0; i<n; i++)
		{
			X=(R[i]-(long long int)i)*((long long int)i-L[i])*height[i];
			ans += X;
		}
//end of copy
		printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#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>
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)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  string s;
  cin >> s;
  string t="CODEFESTIVAL2016";
  int ans=0;
  rep(i,16){
    if(s[i]!=t[i])ans++;
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int X,Y,Z,K;cin>>X>>Y>>Z>>K;
    vector<int>A(X),B(Y),C(Z);
    REP(i,X)cin>>A[i];
    REP(i,Y)cin>>B[i];
    REP(i,Z)cin>>C[i];
    sort(A.rbegin(),A.rend());
    sort(B.rbegin(),B.rend());
    sort(C.rbegin(),C.rend());
    vector<int>ans;
    REP(i,X){
        REP(j,Y){
            REP(k,Z){
                if((i+1)*(j+1)*(k+1)>K)break;
                else ans.eb(A[i]+B[j]+C[k]);
            }
        }
    }
    sort(ans.rbegin(),ans.rend());
    REP(i,K)cout<<ans[i]<<endl;
}

Measured memory_bytes: 1404
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;

int main() {

	int n;
	cin >> n;

	vector<pii> x(n);
	vector<pii> y(n);

	for (int i = 0; i < n; i++) {
		cin >> x[i].first;
		x[i].second = i;
		cin >> y[i].first;
		y[i].second = i;

	}

	sort(x.begin(), x.end());
	sort(y.begin(), y.end());


	vector<vector<pii>> e(n);
	for (int i = 1;i < n;i++) {
		int cost = abs(x[i].first - x[i - 1].first);
		e[x[i].second].emplace_back(make_pair(cost, x[i - 1].second));
		e[x[i - 1].second].emplace_back(make_pair(cost, x[i].second));
	}
	for (int i = 1;i < n;i++) {
		int cost = abs(y[i].first - y[i - 1].first);
		e[y[i].second].emplace_back(make_pair(cost, y[i - 1].second));
		e[y[i - 1].second].emplace_back(make_pair(cost, y[i].second));
	}

	priority_queue<pii,vector<pii>,greater<pii>> pq;
	ll sum = 0;
	vector<bool> isChecked(n, false);

	for (pii edge : e[0]) {
		pq.push(edge);
	}
	isChecked[0] = true;

	while (!pq.empty()) {
		pii edge = pq.top();
		pq.pop();
		if (!isChecked[edge.second]) {
			for (pii ed : e[edge.second]) {
				pq.push(ed);
			}

			isChecked[edge.second] = true;
			sum += edge.first;
		}

	}

	cout << sum << endl;
}




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

int main()
{
    vector<vector<int>> A(3, vector<int>(3));
    rep(i, 3){
        rep(j,3){
            cin >> A[i][j];
        }
    }
    int N;
    cin >> N;
    vector<int> b(N);
    rep(i,N){
        cin >> b[i];
    }

    for (size_t i = 0; i < N; i++)
    {
        for (size_t j = 0; j < 3; j++)
        {
            for (size_t k = 0; k < 3; k++)
            {
                if(A[j][k] == b[i]){
                    A[j][k] = -1;
                }
            }
        }
    }
    bool can = false;
    if(A[0][0] == A[1][1] && A[1][1] == A[2][2] || A[0][2] == A[1][1] && A[2][0] == A[1][1]){
                can = true;
    
    }
    rep(i,3){
        if(A[i][0] == A[i][1] && A[i][1] == A[i][2]){
            can = true;
        }
    }
    rep(i,3){
        if(A[0][i] == A[1][i] && A[1][i] == A[2][i]){
            can = true;
        }
    }
    // rep(i,3){
    //     rep(j,3){
    //         cout << A[i][j]<< " ";
    //     }
    //     cout << endl;
    // }
    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}

Measured memory_bytes: 256
#include<stdio.h>

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

Measured memory_bytes: 128
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll n, a, b; cin >> n >> a >> b;
	ll tot = a+b;
	ll ans = a*(n/tot);
	n %= tot;
	ans += min(a, n);
	println(ans);
}


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

int cnt,cnt2;
int main(){
  string s;
  bool flag=false;
  bool flag2=false;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='B'){
      flag=true;
    }else if(s[i]=='W'){
      flag2=true;
    }
    if(flag&&s[i]=='W'){
      cnt++;
      flag=false;
    }
    if(flag2&&s[i]=='B'){
      cnt2++;
      flag2=false;
    }
  }
  cout<<cnt+cnt2<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(50)
#define _popcnt __builtin_popcount

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long
#define double long double

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

int fact[2000], invfact[2000];

int invmod(int a, int p){ // a^-1 mod p
  int b = p, u = 1, v = 0;
  while(b){
    int t = a / b;
    a -= t*b; swap(a, b);
    u -= t*v; swap(u, v);
  }
  u %= p;
  if(u < 0) u += p;
  return u;
}

void factmod(int m){
  fact[0] = invfact[0] = 1;
  for(int i = 1; i < 2000; i++){
    fact[i] = (fact[i-1] * i) % m;
    invfact[i] = (invfact[i-1] * invmod(i, m)) % m;
  }
}

int nCrmod(int n, int r, int m){
  return (((fact[n] * invfact[r]) % m) * invfact[n-r]) % m;
}

signed main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  int A, B; cin >> A >> B;
  factmod(MOD);
  if(A > B) cout << 0 << endl;
  else{
    int ans = (nCrmod(B, A, MOD) * fact[A]) % MOD;
    cout << ans << endl;
  }
}



Measured memory_bytes: 3248
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;



int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		char d;
		cin >> d;
		if (d == 'W') {
			a[i] = 0;
		}
		else {
			a[i] = 1;
		}
	}
	int sum = 0;
	for (int i = 1; i < n; i++) {
		sum += a[i];
	}
	int temp = sum;
	for (int i = 1; i < n; i++) {
		
		if (a[i] == 1) {
			temp--;
		}

		if (a[i - 1] == 0) {
			temp++;
		}

		sum = min(sum, temp);
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)
int main(){
    ll n, k, check, m = pow(10, 9);
    cin >> n >> k;
    ll X[n];
    RAP(i, n){
        cin >> X[i];
    }
    RAP(i,n){
        if(i+k-1>=n){
            break;
        }
        check = min(abs(X[i]), abs(X[i+k-1])) + abs(X[i]-X[i+k-1]);
        m = min(m, check);
    }
    cout << m << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int ans=0;
    string S;cin>>S;
    char c='0';
    int case1=0,case2=0;
    for(int i=0;i<S.size();i++){
        if(S[i]!=c) case1++;
        if(c=='0') c='1';
        else c='0';
    }
    c='1';
    for(int i=0;i<S.size();i++){
        if(S[i]!=c) case2++;
        if(c=='0') c='1';
        else c='0';
    }
    ans=min(case1,case2);
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n, m;
char str[1000];
int cost[1000];
int power[3][1000];
int dp[1000];

int main() {
  while (scanf("%d %d", &n, &m) != EOF) {
    assert(1 <= n && n <= 300);
    assert(1 <= m && m <= 300);
    fgets(str, 999, stdin);
    REP(i, n) {
      fgets(str, 999, stdin);
      scanf("%d %d %d %d", &cost[i], &power[0][i], &power[1][i], &power[2][i]);
      fgets(str, 999, stdin);
      assert(1 <= cost[i] && cost[i] <= 300);
      REP(j, 3) {
        assert(1 <= power[j][i] && power[j][i] <= 300);
      }
    }
    int ans = 0;
    REP(iter, 3) {
      MEMSET(dp, 0);
      REP(i, n) {
        FOREQ(j, 0, m) {
          dp[j] = max(dp[j], dp[j]);
          int ncost = j + cost[i];
          if (ncost <= m) {
            dp[ncost] = max(dp[ncost], dp[j] + power[iter][i]);
          }
          ans = max(ans, dp[j]);
        }
      }
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 904
import math
import re
T=input()
x=0
Td=T
d = len(re.sub(r'0', '', Td))
x += math.ceil((d/2+1)*d/2)
spT = T.split('0')
lenT = list(map(len, spT))

tmpX = math.ceil(d/2)
bT = 0
aT = d
tmp = ''
for i in range(len(spT) - 1):
    tmp += spT[i]
    bT += lenT[i]
    aT -= lenT[i]
    if bT % 2==1:
        bT += 1
        if aT % 2 ==1:
            tmpX += 1
        x += tmpX
        tmp += '0'
    else:
        tmp +='+'
tmp += spT[-1]

spT = tmp.split('+')
vT =[]
aT = bT
bT = 0

odT = 0
tmpOd = True

for i in range(len(spT)):
    
    od = len(re.sub(r'0', '', spT[i][0 if tmpOd else 1::2]))
    ev = len(re.sub(r'0', '', spT[i][1 if tmpOd else 0::2]))
    odT += od
    vT.append(od - ev)
    if len(spT[i]) %2 == 1:
        tmpOd = not tmpOd

for i in reversed(range(1, len(spT))):
    odT = odT - vT[i]
    x += odT
    vT[i-1] -= vT[i]


print(x)

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

int main() {
    int N, M;
    while (cin >> N >> M, N || M) {
        vector<long long int> v(N);
        for (int i = 0; i < N; i++) {
            cin >> v[i];
            if (i > 0) v[i] += v[i-1];
        }

        long long int ans = -10000000000;
        for (int i = 0; i < N - M; i++) {
            ans = max(ans, v[i+M] - v[i]);
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
class Solution:
    def isEven(self, a: int, b: int):
        if (a * b) % 2 == 0:
            print("Even")
        else:
            print("Odd")


if __name__ == "__main__":
    a, b = map(int, input().split())
    solution = Solution()
    solution.isEven(a, b)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

using pil = pair<int, lint>;
using pli = pair<lint, int>;

int n;
vector<int> G[MAX];
vector<pil> H[MAX];
lint a[MAX], b[MAX], sum[MAX];
lint m = 0, ans = 0;

lint dfs_sum(int v, int pv){
    lint ret = b[v] - a[v];
    for(int nv: G[v])if(nv != pv){
        lint tmp = dfs_sum(nv, v);
        ret += tmp;
        H[v].emplace_back(nv, tmp);
    }
    return ret;
}

void dfs(int v, lint d){
    for(auto e: H[v]){
        lint tmp = d - e.se;
        ans += tmp;
        chmin(m, tmp);
        dfs(e.fi, tmp);
    }
}

int main(){
    scanf("%d", &n);
    rep(i, n-1){
        int u, v;
        scanf("%d%d", &u, &v);
        --u; --v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    rep(i, n) scanf("%lld", &a[i]);
    rep(i, n) scanf("%lld", &b[i]);

    dfs_sum(0, -1);
    dfs(0, 0);
    printf("%lld\n", ans - m*n);
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int A, P; cin >> A >> P;
  cout << (A*3+P) / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
	int n; cin >> n;
	int M; cin >> M;
	int m[20][20]; fill(&m[0][0], &m[0][0]+20*20, 1e9);
	for (int i = 0; i < M; ++i) {
		int a, b, c, d; scanf("%d,%d,%d,%d", &a, &b, &c, &d); --a, --b;
		m[a][b] = c;
		m[b][a] = d;
	}
	for (int i = 0; i < n; ++i) m[i][i] = 0;

	for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
		m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
	}

	int s, t, award, cost; scanf("%d,%d,%d,%d", &s, &t, &award, &cost); --s, --t;
	award -= cost + m[s][t] + m[t][s];
	cout << award << endl;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
int arr[100005],n,dp[100005],k;

int recur(int i){
    //cout<<i<<"\n";
    if(i >= n)return 99999;
    if(i == n-1)return 0;
    if(dp[i] != -1)return dp[i];
    int minVal = INT_MAX;
    for(int j=i+1;j<=min(i+k,n);j++){
        int opt = abs(arr[i] - arr[j]) +  recur(j);
        minVal = min(minVal,opt);
    }
    return dp[i] = minVal;
}

int main() {
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        dp[i]=-1;
    }
    int ans = recur(0);
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 5760
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;

#define DB double
#define LL long long
#define MAXN 10000
#define MOD 998244353
#define Pr pair<int,int>
#define X first
#define Y second
#define INF 1000000001
#define mem(x,v) memset(x,v,sizeof(x))

LL read(){
	LL x=0,F=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*F;
}

int add(int a,int b){return (a+b>=MOD)?a+b-MOD:a+b;}
int dec(int a,int b){return (a-b<0)?a-b+MOD:a-b;}
int mul(int a,int b){return (1LL*a*b)%MOD;}
int fst_pow(int a,int b){
	int res=1;
	while(b){
		if(b&1)res=mul(res,a);
		a=mul(a,a),b>>=1;
	}
	return res;
}
void upd(int &a,int b){a=add(a,b);}

int n,s,t,ans;
char a[MAXN+5],b[MAXN+5];
int f[MAXN+5][MAXN+5],fac[MAXN+5],ifac[MAXN+5];

void prepare(){
	fac[0]=1;
	for(int i=1;i<=n;i++)fac[i]=mul(fac[i-1],i);
	ifac[n]=fst_pow(fac[n],MOD-2);
	for(int i=n;i>=1;i--)ifac[i-1]=mul(ifac[i],i);
}
int Comb(int a,int b){
	return mul(fac[a],mul(ifac[b],ifac[a-b]));
}

int main(){
	scanf("%s%s",a+1,b+1);
	n=strlen(a+1);
	prepare();
	for(int i=1;i<=n;i++)
	if(a[i]=='1'&&b[i]=='1')s++;
	else if(a[i]>b[i])t++;
	f[0][0]=1;
	for(int i=0;i<=s;i++)
		for(int j=0;j<=t;j++)
		if(f[i][j]){
			upd(f[i+1][j],mul(f[i][j],mul(i+1,j)));
			upd(f[i][j+1],mul(f[i][j],mul(j+1,j+1)));
		}
	for(int i=0;i<=s;i++)
	ans=add(ans,mul(mul(Comb(s,i),Comb(s+t,i)),mul(mul(fac[i],fac[i]),f[s-i][t])));
	printf("%d\n",ans);
}

Measured memory_bytes: 73900
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func main() {
	N := getInt()
	A := getInt()
	B := getInt()

	x := N / (A + B)
	y := N % (A + B)

	sum := A * x
	if A <= y {
		sum += A
	} else {
		sum += y
	}
	fmt.Println(sum)
}

type Graph struct {
	n     int
	edges [][]int
}

func NewGraph(n int) *Graph {
	g := &Graph{
		n:     n,
		edges: make([][]int, n),
	}
	return g
}

func (g *Graph) AddEdge(u, v int) {
	g.edges[v] = append(g.edges[v], u)
	g.edges[u] = append(g.edges[u], v)
}

func dfs(c int, edges [][]int, visited map[int]struct{}) {
	visited[c] = struct{}{}

	for _, v := range edges[c] {
		_, flag := visited[v]
		if flag {
			continue
		}
		dfs(v, edges, visited)
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func powMod(n, p int) int {
	if p == 0 {
		return 1
	} else if p%2 == 0 {
		t := powMod(n, p/2)
		return calcMod(t * t)
	} else {
		return n * powMod(n, p-1)
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main () {
	set<string> s;
	string S;
	int K;
	cin >> S >> K;
	int l = S.length();
	for (int i = 0; i < l; i++) {
		string c = "";
		for (int j = 0; j < 5 && (i+j) < l; j++) {
			c += S[i+j];
			s.insert(c);
		}
	}
	auto x = s.begin();
	for (int i = 0; i < K-1; i++) {
		x++;
	}
	cout << (*x) << endl;
}

Measured memory_bytes: 1664
import sys
rl = sys.stdin.readline
n = int(rl())
x, y, z = 0, 0, 0
for _ in range(n):
  a, b, c = map(int, rl().split())
  x, y, z = max(y, z) + a, max(x, z) + b, max(x, y) + c
print(max(x, y, z))


Measured memory_bytes: 43116
#include<stdio.h>
int gcd(int x,int y){
    int r,m;
    if(x < y){
        m=x;
        x=y;
        y=m;
    }
    while(y > 0){
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}
int main()
{
    unsigned long long int a,b,x,n;
    while(scanf("%lld%lld",&a,&b)!=EOF){
        x=gcd(a,b);
        printf("%lld ",x);
        n=a/x*b;
        printf("%lld\n",n);
    }
    return 0;
}

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

int main()
{
    int n, k; cin>>n>>k;
    vector<int> L(n);
    for(auto& e: L) cin>>e;
    sort(rbegin(L), rend(L));
    cout<<accumulate(begin(L), begin(L)+k, 0)<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

    int N, M;
    cin >> N >> M;
    int a, b;
    map<int, int> mp;
    for(int i = 0; i < M; i++){
        cin >> a >> b;
        mp[a]++;
        mp[b]++;
    }
    bool ans = true;
    for(auto itr = mp.begin(); itr!=mp.end(); itr++){
        if(itr->second%2 != 0){
            ans = false;
            break;
        }
    }
    ans?cout << "YES" << endl:cout << "NO" << endl;

    return 0;
}

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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> mii;
typedef map<ll,int> mli;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;  ///1e9+7

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=2;ii<=mx;ii++)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///



void _case()
{
    ll n,i;
    cin>>n;
    string a;
    map<string,ll> m;
    while(n--){
        cin>>a;
        m[a]++;
    }
    cout<<"AC x "<<m["AC"] el;
    cout<<"WA x "<<m["WA"] el;
    cout<<"TLE x "<<m["TLE"] el;
    cout<<"RE x "<<m["RE"] el;
}

main()
{
        fastio();
//    test _case();
//    while(1) _case();
    _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 3660
use std::io;
use std::cmp;
use std::collections::HashMap;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}



fn main() {
    let n  = read_t_in_line::<i32>()[0];
    let aa = read_t_in_line::<i32>();
    

    let mut hash : HashMap<i32, i32> = HashMap::new();
    for i in 0..n {
        let a : i32 = aa[i as usize];
        if hash.contains_key(&a) {
            *hash.get_mut(&a).unwrap() += 1;
        }
        else {
            hash.insert(a, 1);
        }
    }

    let mut sum : i32 = 0;
    for (k, v) in hash.iter() {
        if k <= v {
            sum += v - k;
        }
        else {
            sum += *v;
        }
    }
    println!("{}", sum);
    
}


Measured memory_bytes: 10740
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

void Main() {
  Cin(string, s);
  Cin(int, w);

  int n = sz(s);
  for (int i = 0; i < n; i += w) cout << s[i];
  cout << endl;
}

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

#define ll long long
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	if(n>=64) cout<<64<<endl;
	else if(n>=32) cout<<32<<endl;
	else if(n>=16) cout<<16<<endl;
	else if(n>=8) cout<<8<<endl;
	else if(n>=4) cout<<4<<endl;
	else if(n>=2) cout<<2<<endl;
	else if(n==1) cout<<1<<endl;

return 0;
}


Measured memory_bytes: 256
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func main() {
	n,m := nextInt(), nextInt()
	acCnt, waCnt := 0, 0
    ac := make([]int, n)
    wa := make([]int, n)
	
	for i:=0;i<m;i++ {
	    p,s := nextInt(), next()
	    p--
	    if ac[p] > 0 {
	        continue
	    }
	    if s == "AC" {
	        ac[p]=1
	        acCnt++
	    } else {
            wa[p]++
	    }
	}
	for i:=0;i<n;i++ {
	    if ac[i] > 0 {
	        waCnt += wa[i]
	    }
	}
	fmt.Println(acCnt, waCnt)
}

func printInt(n int) {
    fmt.Println(n)
}

func next() (s string) {
    fmt.Scan(&s)
    return
}

func nextInt() (n int) {
    fmt.Scan(&n)
    return
}

func nextInts(n int) (arry []int) {
    arry = make([]int, n)
    for i:=0; i<n; i++ { fmt.Scan(&arry[i]) }
    return
}

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func nextSlice() []string {
	return strings.Split(readLine(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func scanSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func scanFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

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

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func larger(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func smaller(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}

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

func yesOrNo(b bool) {
	if b {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func yesorNO(b bool) {
	if b {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}


Measured memory_bytes: 5504
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
// utility
#define all(i) (i).begin(), (i).end()
#define rep(i, n) for(int i=0;i<int(n);++i)
#define rrep(i, n) for(int i=int(n)-1;i>=0;--i)
#define in(a, x, b) (a<=x && x<b)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr int MOD = 1000000007;

using namespace std;


signed main() {
  int N, a;
  std::cin >> N;

  priority_queue<int> q;

  rep(i, N){
    std::cin >> a;
    q.push(a);
  }

  int ans = 0;
  int cnt = 0;
  while(!q.empty()){
    if(cnt%2 == 0) ans += q.top();
    else ans -= q.top();
    q.pop();
    cnt++;
  }

  std::cout << ans;
  std::cout << std::endl;

  return 0;
}

Measured memory_bytes: 256
n = int(input())
v = [0, 0]
c = 0
ans = 1
for _ in range(n):
    t, x, y = map(int, input().split())
    m = t - c
    d = abs(x - v[0]) + abs(y - v[1])
    if d > m:
        ans = 0
    if d % 2 != m % 2:
        ans = 0
    v = [x, y]
    c = t
print("Yes" if ans == 1 else "No")

Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <ctime>
#include <vector>
#include <climits>
#include <algorithm>
#include <random>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <bitset> 
#include <queue>
#define inf 0x3f3f3f3f
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define rep(i, a, n) for(register int i = a; i <= n; ++ i)
#define per(i, a, n) for(register int i = n; i >= a; -- i)
#define ONLINE_JUDGE
using namespace std;
typedef long long ll;
const int mod=1e9+7;
template<typename T>void write(T x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
}
 
template<typename T> void read(T &x)
{
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;};
ll ksm(ll a,ll n){//看是否要mod 
	ll ans=1;
	while(n){
		if(n&1) ans=(ans*a)%mod;
		a=a*a%mod;
		n>>=1;
	}
	return ans%mod;
}
//==============================================================



int main()
{
	#ifndef ONLINE_JUDGE
	#endif
	//===========================================================
	int x,y;
    read(x),read(y);
    int a=y/2-x,b=x-a;
    if((y-2*x)%2==0&&(4*x-y)%2==0&&b>=0&&a>=0){
        puts("Yes");
    }
    else{
        puts("No");
    }
	//===========================================================
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc047_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int W, H, N;
  cin >> W >> H >> N;

  vector<int> x(N);
  vector<int> y(N);
  vector<int> a(N);
  rep(i, N) {
    cin >> x[i];
    cin >> y[i];
    cin >> a[i];
  }

  ll ans = 0;
  int minX = 0, maxX = W, minY = 0, maxY = H;
  rep(i, N) {
    switch (a[i]) {
      case 1:
        minX = max(minX, x[i]);
        break;
      case 2:
        maxX = min(maxX, x[i]);
        break;
      case 3:
        minY = max(minY, y[i]);
        break;
      case 4:
        maxY = min(maxY, y[i]);
        break;

      default:
        break;
    }
  }

  if ((maxX - minX) < 0 || (maxY - minY) < 0) {
    cout << 0 << endl;
  } else {
    ans = (maxX - minX) * (maxY - minY);
    cout << (ans > 0 ? ans : 0) << endl;
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define ull unsigned long long
#define EPS 1e-8
using namespace std;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
const double pi = acos(-1.0);
int read()
{
	int ret=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	for(;ch>='0'&&ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret;
}
const int MAX_N=2e5+7;
ll a[MAX_N],sum[MAX_N];
ll ans=1e18;
int n;
int main()
{
 	#ifdef TEST
	 	freopen("input.txt","r",stdin);
	#endif
	sum[0]=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",a+i);
		sum[i]=sum[i-1]+a[i];
	}
	for(int i=1;i<n;i++)
	{
		ans=min(ans,abs(sum[n]-2*sum[i]));
	}
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 3328
#include <cstdio>

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

    int a[100005] = {};
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
    }

    int cnt = 1;
    int i = 1;
    while (n--) {
        if (a[i] == 2) {
            printf("%d\n", cnt);
            return 0;
        }
        i = a[i];
        ++cnt;
    }
    printf("-1\n");
}

Measured memory_bytes: 512
#include <cstdio>  
#include <iostream>  
#include <cstring>  
#include <string>  
#include <cmath>  
#include <algorithm>  
#include <cstdlib>  
#include <utility>  
#include <map>  
#include <stack>  
#include <set>  
#include <vector>  
#include <queue>  
#include <deque>  
#include <sstream>  
#include <bitset>
#include<bits/stdc++.h>   
#define mp make_pair  
#define pb push_back  
#define LL long long  
#define ld long double  
#define Pair pair<int,int>    
using namespace std;  

using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    if (x%y==0) cout<<"-1";
    else
	cout<<x;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int64_t N;
    cin >> N;
    vector<int64_t> A(N);
    for(int i=0; i<N; i++)
    {
        cin >> A.at(i);
    }
    int64_t step=0;
    for(int i=0; i<N-1; i++)
    {
        if(A.at(i)-A.at(i+1)>0)
        {
            step+=A.at(i)-A.at(i+1);
            A.at(i+1)=A.at(i);
        }
    }
    cout << step << endl;

}

Measured memory_bytes: 4844