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

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define nfor(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define fore(i, l, r) for (int i = int(l); i < int(r); i++)
#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define mp(x, y) make_pair((x), (y))
#define x first
#define y second

using namespace std;

typedef long long li;
typedef long double ld;
typedef pair<int, int> pti;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

template<typename A, typename B> inline ostream& operator<< (ostream& out, const pair<A, B>& p) { return out << "(" << p.x << ", " << p.y << ")"; }
template<typename T> inline ostream& operator<< (ostream& out, const vector<T>& a) { out << "["; forn(i, sz(a)) { if (i) out << ','; out << ' ' << a[i]; } return out << " ]"; }
template<typename T> inline ostream& operator<< (ostream& out, const set<T>& a) { return out << vector<T>(all(a)); }
template<typename X, typename Y> inline ostream& operator<< (ostream& out, const map<X, Y>& a) { return out << vector<pair<X, Y>>(all(a)); }
template<typename T> inline ostream& operator<< (ostream& out, const pair<T*, int>& a) { return out << vector<T>(a.x, a.x + a.y); }

inline ld gett() { return ld(clock()) / CLOCKS_PER_SEC; }

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9, PI = 3.1415926535897932384626433832795;

#ifdef SU1
#define LOG
#endif

const int N = 55;

int n, p;
int a[N];

bool read() {
  if (!(cin >> n >> p)) return false;
  forn(i, n) assert(cin >> a[i]);
	return true;
}

li z[N][2];

void solve() {
  memset(z, 0, sizeof(z));

  z[0][0] = 1;
  forn(i, n)
    forn(j, 2) {
      li dv = z[i][j];
      z[i + 1][j] += dv;
      z[i + 1][j ^ (a[i] & 1)] += dv;
    }
  cout << z[n][p] << endl;
}

int main() {
#ifdef SU1
    assert(freopen("input.txt", "rt", stdin));
    //assert(freopen("output.txt", "wt", stdout));
#endif

    cout << setprecision(10) << fixed;
    cerr << setprecision(5) << fixed;

    while (read()) {
			ld stime = gett();
			solve();
			cerr << "Time: " << gett() - stime << endl;
			//break;
		}

    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;
const int wa=1e9+7;
string a, b;
int A[100000], B[100000];
unsigned long long ans = 0;
 
int main(void) {
	cin >> a >> b;
	for (int i = 0; i < a.length(); i++) {
		if (A[a[i]] == 0)A[a[i]] = b[i];
		else if (A[a[i]] != b[i])ans = -1;
	}
	for (int i = 0; i < a.length(); i++) {
		if (B[b[i]] == 0)B[b[i]] = a[i];
		else if (B[b[i]] != a[i])ans = -1;
	}
	if (ans == 0)cout << "Yes";
	else cout << "No";
	cout << endl;
	return 0;
}

Measured memory_bytes: 776
n,a=map(int,input().split())
X=list(map(int,input().split()))
dp=[[[0]*55 for _ in range(2555)] for _ in range(55)]
ans=0
dp[0][0][0]=1
for i in range(n):
    for j in range(52+50*i):
        for k in range(n):
            ni=i+1
            nj=j+X[i]
            nk=k+1
            dp[ni][nj][nk]+=dp[i][j][k]
            dp[ni][j][k]+=dp[i][j][k]
ans=0
for i in range(1,n+1):
    ans+=dp[n][i*a][i]
print(ans)

Measured memory_bytes: 113628
#include<bits/stdc++.h>
using namespace std;
void pr(char a,int A,char b,int B)
{
    for(int i=0;i<A;++i)
        cout<<a;
    for(int i=0;i<B;++i)
        cout<<b;
    cout<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    int H,W,A,B;
    cin>>H>>W>>A>>B;
    /*if(A==0||B==0)
    {
        if(A!=0||B!=0)
        {
            cout<<-1<<endl;
            return 0;
        }
    }*/
    for(int i=0;i<B;++i)
        pr('0',A,'1',W-A);
    for(int i=B;i<H;++i)
        pr('1',A,'0',W-A);
    return 0;
}

Measured memory_bytes: 1280
def main():
    N = int(input())
    *A, = map(int, input().split())

    even = 0

    for a in A:
        if a % 2 == 0: even += 1

    odd = N - even

    if odd % 2 == 1:
        return False
    else:
        return True

print('YES' if main() else 'NO')

Measured memory_bytes: 14108
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
////////////////////////////////////////
const int MC = 100010;
int N, M;
vector<vector<pii>>V(MC, vector<pii>());
bool b[MC];
int x[MC];
bool dfs(int q) {
	b[q] = 1;
	for (auto u : V[q]) {
		if (b[u.first]) {
			if (x[u.first] != x[q] + u.second)return 0;
			continue;
		}
		else {
			x[u.first] = x[q] + u.second;
			if (!dfs(u.first)) {
				return 0;
			}
		}
	}
	return 1;
}
int main() {
	cin >> N >> M;
	memset(x, 0, sizeof(x));
	for (int i = 0; i < M; ++i) {
		int l, r, d;
		cin >> l >> r >> d;
		V[l].push_back(make_pair(r, d));
		V[r].push_back(make_pair(l, -d));
	}
	for (int i = 1; i <= N; ++i) {
		if (b[i])continue;
		if (!dfs(i)) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


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

int main() {
	int n,a,b,c,sum;
  	cin>>n;
  a =n;
  sum=0;
  while(a>0){
  	sum += a%10;
    a = a/10;
  }
  
  if(n%sum==0){
  	cout<<"Yes"<<endl;
  }
  else
    cout<<"No"<<endl;
  
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int c = (int)(s.length() - t.length() );
    for ( int i = c ; i >= 0 ; i-- ) {
        bool y = 0;
        for ( int j = 0 ; j < t.length() ; j++ ) if ( s[j + i] != '?' && s[j + i] != t[j] ) y = 1;
        if ( y == 0 ) {
            for ( int j = 0 ; j < t.length() ; j++ ) s[j + i] = t[j];
            for ( int j = 0 ; j < s.length() ; j++ ) if ( s[j] == '?' ) s[j] = 'a';
            cout << s;
            return 0;
        }
    }
    cout << "UNRESTORABLE";
}


Measured memory_bytes: 3664
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	int N, A, B; cin >> N >> A >> B;

	int ans = 0;
	FOR(i,1,N+1){
		int tmp = i;
		int sum = 0;
		while(tmp){
			sum += tmp%10;
			tmp /= 10;
		}
		if(sum >= A and sum <= B) ans += i;

	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
def main():
    n = int(input())
    print(dfs("0",n))



def dfs(s,n):
    counter = 0
    if int(s) > n:
        return 0
    counter += 1 if (s.count("3") >= 1 and s.count("5")>= 1 and s.count("7") >= 1) else 0
    for c in "357":
        counter += dfs(s+c,n)
    return counter


if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int A, B, C;
	cin >> A >> B >> C;
	if (C - (A - B) <= 0) {
		cout << 0;
	} else {
		cout << C - (A - B);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <limits>
#include <map>

using namespace std;

int main(){
    int n;
    long long ans=0;
    cin >> n ;
    map<string,int> cnt;
    string s;
    while(n--){
        cin >> s;
        sort(s.begin(),s.end());
        ans+=cnt[s];
        cnt[s]++;
    }
    cout << ans <<endl;
    return 0;
}

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

int main() {
  
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int t = 0;
  int k = 0;
  
  if (c % b != 0) {
    t = c / b + 1;
  } else {
    t = c / b;
  }
  
  if (a % d != 0) {
    k = a / d + 1;
  } else {
    k = a / d;
  }
  
  if (t <= k) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  
}


Measured memory_bytes: 3516
#include<stdio.h>

int f(int n)
{
  if(n == 0)
    return 1;
  return (n * f(n - 1));
}

int main(){
  int n;
  int a = 0;
  int b = 0;
  scanf("%d",&n);
  int p[n], q[n];
  //標準入力
  int i;
  i = 0;
  while (i < n)
  {
    scanf("%d",&p[i]);
    i++;
  }
  i = 0;
  while (i < n)
  {
    scanf("%d",&q[i]);
    i++;
  }
  i = 0;
  while (i < n)
  {
    int c = 0;
    int d = 0;
    int j = 0;
    while (j < i)
    {
      if(p[j] < p[i])
      {
        c ++;
      }
      if(q[j] < q[i])
      {
        d ++;
      }
      j++;
    }
    //printf("%d",c);
    if(p[i] - c - 1 > 0)
    {
      a += (p[i] - c - 1) * f(n - i - 1);
      //printf("%d",a);
    }
    if(q[i] - d - 1 > 0)
    {
      b += (q[i] - d - 1) * f(n - i - 1);
    }
    i++;
  }
  if (a - b < 0)
  {
  	printf("%d\n", b - a);
  }
  else
  {
    printf("%d\n", a - b);
  }
  return 0;
}

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

int main(){
	int n;
	cin>>n;
	bool flag=0;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		if(x%2==0){
			if(x%3!=0 && x%5!=0) flag=1;
		}
	}
	if(flag) cout<<"DENIED\n";
	else cout<<"APPROVED\n";
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define MAX 128
#define fst first
#define sec second
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define bit(n) (1LL << (n))
#define int long long
const double PI = 3.141593;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double EPS = 1e-9;
template <class T>
bool chmax(T &a, const T &b){if (a < b){a = b;return 1;}return 0;}
template <class T>bool chmin(T &a, const T &b){if (b < a){a = b;return 1;}return 0;}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }     //最小公倍数
ll combination(ll n, ll r){if (r * 2 > n)r = n - r;ll dividend = 1;ll divisor = 1;for (ll i = 1; i <= r; ++i){dividend *= (n - i + 1);divisor *= i;}return dividend / divisor;}


signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int t=0;
  while(c>0&&a>0){
      if(t%2==0){
          c-=b;
      }
      else{
          a-=d;
      }
      t++;
  }
  if(c<=0){
      cout<<"Yes"<<endl;
  }
  else{
      
      cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3552
K = [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]
n = int(input())
print(K[n-1])


Measured memory_bytes: 2940
#include <stdio.h>
int main(void) 
{
    int m, f, r;
    while(1) 
    {
        scanf("%d %d %d", &m, &f, &r);
        if(m == -1 && f == -1 && r == -1) 
        {
            break;
        }
        if(m == -1 || f == -1) 
        {
            printf("F\n");
        }
        else if(m + f >= 80) 
        {
            printf("A\n");
        }
        else if(m + f >= 65 && m + f < 80) 
        {
            printf("B\n");
        }
        else if(m + f >= 50 && m + f < 65) 
        {
            printf("C\n");
        }
        else if(m + f >= 30 && m + f < 50) 
        {
            if(r < 50) 
            {
                printf("D\n");
            }
            else {
                printf("C\n");
            }
        }
        else if(m + f < 30) 
        {
            printf("F\n");
        }
    }
    
    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

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

	int n;
	scanf("%d", &n);
	vi a(n);
	bool zero = false;
	int neg = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		if (a[i] < 0) {
			a[i] = -a[i];
			++neg;
		}
		else if (a[i] == 0)
			zero = true;
	}

	//ll ans = 0;
	//for (int x : a) ans += x;
	ll ans = accumulate(all(a), 0LL);
	if (neg % 2 == 1 && !zero)
		ans -= 2 * (*min_element(all(a)));
	printf("%lld\n", ans);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((int)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

void print(Vl v){
    rep(i, 0, sz(v)){
        if(i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}

////////////////////////////////////////////////////////

ll dp[105][100005];

int main() {
    ll n, W; cin >> n >> W;
    Vl w(n), v(n);
    rep(i, 0, n) cin >> w[i] >> v[i];

    rep(i, 0, n){
        Rep(j, 0, W){
            chmax(dp[i+1][j], dp[i][j]);
            if(j+w[i] <= W) chmax(dp[i+1][j+w[i]], dp[i][j]+v[i]);
        }
    }


    co(dp[n][W]);


    return 0;
}


Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

const int N = 1e5;

int dp[N+5][4];
int arr[N+5][4];

int main(){

	ios_base::sync_with_stdio(0);
	int n; cin >>n;
	for(int i = 1; i<=n; i++){
		cin >>arr[i][1] >>arr[i][2] >>arr[i][3];
	}

	for(int i = 1; i<=n; i++){
		dp[i][1] = arr[i][1] + max(dp[i-1][2], dp[i-1][3]);
		dp[i][2] = arr[i][2] + max(dp[i-1][1], dp[i-1][3]);
		dp[i][3] = arr[i][3] + max(dp[i-1][1], dp[i-1][2]);
	}	

	cout <<max({dp[n][1], dp[n][2], dp[n][3]}) <<endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int h, w; scanf("%d%d", &h, &w);
	std::vector<std::string> A(h), B(h);
	for(int i = 0; i < h; i++) cin >> A[i];
	for(int i = 0; i < h; i++) cin >> B[i];

	int ans = 0;
	for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) ans += (A[i][j] != B[i][j]);
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 11192
//aoj0535
#include<iostream>
using namespace std ;

int ans ;
int table[100][100] = {} ;
int dx[] = {-1,0,1,0} ;
int dy[] = {0,-1,0,1} ;

void f( int y , int x , int sum ){
	
	table[y][x] = 0 ;
	
	int p = 0 ;
	for( int k=0 ; k<4 ; k++ ){
		if( table[y+dy[k]][x+dx[k]] ) f( y+dy[k] , x+dx[k] , sum+1 ) ;
		else p++ ;
	}
	table[y][x] = 1 ;
	
	if( p == 4 ){
		if( ans < sum ) ans = sum ;
	}
}

int main(){
	
	int n , m ;
	while( cin >> n >> m , n ){
		
		ans = 0 ;
		for( int i=0 ; i<100 ; i++ ){
			for( int j=0 ; j<100 ; j++ ) table[i][j] = 0 ;
		}
		
		for( int i=1 ; i<=n ; i++ ){
			for( int j=1 ; j<=m ; j++ ) cin >> table[i][j] ;
		}
		
		for( int i=1 ; i<=n ; i++ ){
			for( int j=1 ; j<=m ; j++ ){
				if( table[i][j] ) f(i,j,1) ;
			}
		}
		
		cout << ans << endl ;
		
	}
	
return 0 ;
}

Measured memory_bytes: 1200
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
S = list(sr())
base = ord('A')
for i in range(len(S)):
    s = S[i]
    S[i] = chr(base + (ord(s) + N - base) % 26)

print(*S, sep='')


Measured memory_bytes: 14056
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int func(int last,int state,vector<vector<int>>& dp,vector<vector<pair<int,int>>>&path){
//	clog << last << " " << bitset<16>(state) <<endl;
	if (dp[last][state] == -1)
	{
		dp[last][state]=INF;
		for(auto itr=path[last].begin();itr!=path[last].end();itr++){
			if(state&(1<<(last))){
				chmin(dp[last][state],func(itr->F,state&~(1<<last),dp,path)+(itr->S));
			}
		}
	}
//	clog <<last<<" "<< bitset<16>(state)<<" -> "<<dp[last][state] << endl;
	return dp[last][state];
}
int main(){
	int v,e;
	int ans=INF;
	cin >>v>>e;
	vector<vector<pair<int,int>>>path(v);
	int s,t,d;
	rep(i,e){
		cin>>s>>t>>d;
		path[s].emplace_back(t,d);
	}
	vector<vector<int>>dp(v,vector<int>(1<<v,-1));
	rep(i,v){
		dp[i][0]=0;
		func(i,(1<<v)-1,dp,path);
		chmin(ans,dp[i][(1<<v)-1]);
	//	clog<<endl;
		rep(I,v){
			rep(J,1<<v){
				dp[I][J]=-1;
			}
		}
	}
	cout<<(ans==INF?-1:ans)<<endl;
}


Measured memory_bytes: 4928
#include<cstdio>
#include<algorithm>
using namespace std;
inline int read() {
	int x=0; char c=0;
	while(c<'0'||c>'9') c=getchar();
	while('0'<=c&&c<='9')x=10*x+c-'0',c=getchar();
	return x;
}
const int N=200005;
int head[N],ecnt;
int to[N<<1],nxt[N<<1];
inline void AddEdge(int u,int v) {
	to[++ecnt]=v, nxt[ecnt]=head[u], head[u]=ecnt;
	to[++ecnt]=u, nxt[ecnt]=head[v], head[v]=ecnt;
}
int n,ans[N];
int son[N],mv[N];
int siz[N],d[N];
int Calc(int u,int fa,int lim) {
	son[u]=1;
	for(int i=head[u];i;i=nxt[i]) {
		int v=to[i];
		if(v!=fa&&v<lim)
			son[u]+=Calc(v,u,lim);
	}
	return son[u];
}
int Dfs(int u,int fa) {
	mv[u]=max(mv[fa],u);
	siz[u]=1;
	for(int i=head[u];i;i=nxt[i]) {
		int v=to[i];
		if(v==fa) continue;
		siz[u]+=Dfs(v,u);
		d[u]+=d[v];
	}
	if(mv[u]==u) {
		Calc(u,fa,mv[fa]);
		d[u]=-siz[u];
	}
	if(mv[fa]==fa)
		d[u]+=siz[u];
	return siz[u];
}
void Solve(int u,int fa) {
	if(fa) {
		if(mv[u]==u) ans[u]+=son[u];
		else if(mv[fa]==fa) ans[u]+=d[u]-son[u];
		ans[u]+=ans[fa];
	}
	for(int i=head[u];i;i=nxt[i])
		if(to[i]!=fa) Solve(to[i],u);
}
int main() {
	n=read();
	for(int i=1;i<n;i++)
		AddEdge(read(),read());
	Dfs(1,0);
	Solve(1,0);
	for(int i=2;i<n;i++)
		printf("%d ",ans[i]);
	printf("%d\n",ans[n]);
	return 0;
}

Measured memory_bytes: 24368
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		long ans = 0;
		Main main = new Main();

		for (int i = 1; i <= A; i++) {
			for (int j = 1; j <= A; j++) {
				for (int k = 1; k <= A; k++) {
					ans += main.GCD(i, main.GCD(j, k));
				}
			}
		}

		System.out.println(ans);

	}

	public int GCD(int num1, int num2) {
		if (num2 == 0) {
			return num1;
		} else {
			return GCD(num2, num1 % num2);
		}
	}

}

Measured memory_bytes: 35852
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, m = sc.nextInt
    val xs = new Array[Int](m)
    for (i <- 0 until m) {
      xs(i) = sc.nextInt
    }

    val sortedXs = xs.sorted
    val diffs = new Array[Int](m - 1)
    for (i <- 0 until m - 1) {
      diffs(i) = sortedXs(i + 1) - sortedXs(i)
    }
    val ans = diffs.sorted.reverse.slice(n - 1, diffs.length).sum
    println(ans)

  }
}


Measured memory_bytes: 54544
N = int(input())
A = list(map(int,input().split()))

number_list = [0]*1000010
for a in A:
    number_list[a] += 1
    
flag1 = True
flag2 = True

for i in range(2,1000001):
    count = 0
    for j in range(1,1000001):
        if i*j > 1000000:
            break
        tmp = i*j
        count += number_list[tmp]
    if count > 1:
        flag1 = False
    if count == N:
        flag2 = False
        
if flag2 == False and flag1 == False:
    print("not coprime")
elif flag2 == True and flag1 == False:
    print("setwise coprime")
else:
    print("pairwise coprime")

Measured memory_bytes: 194596
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
#define ALL(W) (W).begin(),(W).end()
int N;
tuple<string,int,int> P[100+10];
signed main(){
  cin >> N;
  rep(i,N){
    string a;
    int b;
    cin >> a >> b;
    P[i]=make_tuple(a,-b,i+1);
  }
  sort(P,P+N);
  rep(i,N) cout << get<2>(P[i]) << endl;
  return 0;
}


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

#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)

namespace solver {
  using namespace std;
  typedef long long ll;

  string S;

  void init() {
    cin >> S;
  }

  void solve() {
    ll ans = 0;
    if(S[2] == S[3] && S[4] == S[5])  printf("Yes\n");
    else printf("No\n");
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

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

using namespace std;

struct BinaryIndexedTree
{
  vector< int > data;

  BinaryIndexedTree(int sz)
  {
    data.assign(++sz, 0);
  }

  int sum(int k)
  {
    int ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, int x)
  {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

int main()
{

  int N, M;
  cin >> N >> M;

  vector< int > in[300002], out[300002];
  for(int i = 0; i < N; i++) {
    int L, R;
    cin >> L >> R;
    in[L].push_back(L);
    out[R].push_back(L);
  }

  // lastupdate, idx
  queue< tuple< int, int > > nxt[300002];
  for(int i = 1; i <= M; i++) nxt[i].emplace(0, i);

  int sum[100002] = {};
  BinaryIndexedTree bit(M + 5);
  for(int i = 1; i <= M; i++) {
    for(auto &pp : in[i]) bit.add(pp, +1);
    auto &q = nxt[i];
    while(!q.empty()) {
      int lastupdate, idx;
      tie(lastupdate, idx) = q.front();
      q.pop();
      sum[idx] += bit.sum(i) - bit.sum(lastupdate);
      nxt[idx + i].emplace(i, idx);
    }
    for(auto &pp : out[i]) bit.add(pp, -1);
  }

  for(int i = 1; i <= M; i++) {
    cout << sum[i] << endl;
  }

}


Measured memory_bytes: 222720
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;

int main(){
    int n,l,max=0,res;
    cin >> n >>l;
    VI a(n);
    for(int i = 0;i < n;i++){  a[i] = i+1; }
    for(int i = 0;i<n;i++){ a[i] = l+i+1-1; }
    for(int i = 0;i<n;i++){
        max += a[i];
    }

    for(int i = 0;i < n;i++){
        if (a[i]==0){
            res = max;
            cout << res << endl;
            return 0;
        }
    }


    if(max < 0) {
        cout << max - a[n-1] << endl;
    }
    else{
        cout << max - a[0] << endl;
    }
    return 0;
}
   


Measured memory_bytes: 256
'use strict';
(function(stdin) {
    var inputs = stdin.toString().split(' ').map(Number);
    var a = inputs[0];
    var b = inputs[1];
    var d = Math.floor(a / b);
    var r = a % b;
    var f = Number((a / b).toFixed(5));
    console.log(d,r,f);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15796
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = ;
const long long INF_LL = 1e18+3; const int INF_int = 1e9+3;
#define ll long long
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto itr = a.begin();itr!=a.end();itr++) cout << *itr << " ";cout << endl;
bool ok(string s){
    bool fl = true;
    rep(i,s.size()/2){
        if(s[i]!=s[s.size()-1-i]) fl = false;
    }
    return fl;
}
int main(){
    string s;
    cin >> s;
    int n = s.size();
    string s1 = s.substr(0,((n-1)/2));
    string s2 = s.substr((n+1)/2,n-((n+1)/2));
    //cout << s1 << " " << s2 << endl;
    if(ok(s)&&ok(s1)&&ok(s2)){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

Measured memory_bytes: 256
# coding: utf-8

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    if sum(A) < sum(B):
        return -1

    diff_sum = 0
    diff_cnt = 0
    diff_list = [0] * N
    for i in range(N):
        diff_list[i] = A[i] - B[i]
        if A[i] < B[i]:
            diff_sum += B[i] - A[i]
            diff_cnt += 1

    diff_list_sorted = sorted(diff_list, reverse=True)

    use_sum = 0
    for i in range(N):
        if use_sum >= diff_sum:
            break
        use_sum += diff_list_sorted[i]
        diff_cnt += 1

    return diff_cnt


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


Measured memory_bytes: 18612
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;

// typedef
typedef long long ll;
typedef unsigned long ul;
// #define int long long

// macro
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define DESCEND greater<int>()  // sort 降順 大きい順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから
#define MIN(vec) min_element(ALL((vec)))  // 値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)  // 直後の要素をパディング
#define space_pad(num) setfill(' ') << std::right << setw(num)  // 直後の要素をパディング

// func declaration
template <class T> void print2DVec(vector< vector<T> >&);
template <class T> void calcVec(vector<T>&, int, char);
int char_to_int(const char);

// const
const int INF = 10000000;

/*MEMO
・辞書順
abc < abcd, atcoder < atlas
・イテレータ
std::vector<int>::iterator とタイプするのは面倒なので、
 通常は型推論の auto を使用する。
 auto iter = max_element(ALL(vec));
・2次元配列
vector<vector<int>> vec = {{1, 2, 3}, {4, 5, 6}}
・20×10の配列
vector<vector<int>> vec(20, vector<int>(10, 0));
・(n, m)の多次元配列
vector< vector<int> > vec(n, vector<int>(m, 0))  // 0で初期化
*/

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

    // input
    int N, A;
    cin >> N >> A;
    
    // calculation
    N -= N/500 * 500;
    if (A >= N) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
    
    return 0;
}


// function
template <class T> void print2DVec(vector< vector<T> >& vec) {
    REP(i, vec.size()) {
        REP(j, vec.front().size()) {
            cout << vec.at(i).at(j);
        }
        cout << endl;
    }
}

template <class T> void calcVec(vector<T> &vec, int num, char ch) {
    // vec全体への演算
    switch (ch) {
        case '+':
            REP(i, vec.size()) vec.at(i) += num; break;
        case '-':
            REP(i, vec.size()) vec.at(i) -= num; break;
        case '*':
            REP(i, vec.size()) vec.at(i) *= num; break;
        case '/':
            REP(i, vec.size()) vec.at(i) /= num; break;
        case '%':
            REP(i, vec.size()) vec.at(i) %= num; break;
        default:
            cout << "Incorrect Operator" << endl;
    }
}

int char_to_int(const char c) {
    if('0' <= c && c <= '9') return (c - '0');
    return -1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
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; }
using namespace std;
int N,ma,mb;
int a[45],b[45],c[45];
int dp[45][410][410];
signed main(){
    cin>>N>>ma>>mb;
    rep(i,N)cin>>a[i]>>b[i]>>c[i];
    rep(i,45)rep(j,410)rep(k,410)dp[i][j][k]=INF;
    dp[0][0][0]=0;
    rep(i,N){
        rep(ca,410){
            rep(cb,410){
                if(dp[i][ca][cb]==INF)continue;//there are no ways to make ca and cb with i materials
                chmin(dp[i+1][ca][cb], dp[i][ca][cb]);
                chmin(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i]);
            }
        }
    }
    int ans=INF;
    for(int ca=1; ca<410; ca++){
        for(int cb=1; cb<410; cb++){
            if(ca*mb==cb*ma)chmin(ans, dp[N][ca][cb]);
        }
    }
    cout<<(ans==INF?-1:ans)<<endl;
}

Measured memory_bytes: 59392
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
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();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXIST2(s,e) (find(ALL(s),(e))!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
int main(){
	int c,d,w,x;
	while(cin>>c>>d>>w>>x,c|d|w|x){
		vvi e(c,vi(d));
		REP(i,c){
			REP(j,d){
				cin>>e[i][j];
			}
		}
		vvi f(c,vi(d));
		REP(i,c){
			REP(j,d){
				cin>>f[i][j];
			}
		}
		vvvi dp(d+1,vvi(w+1,vi(x+1)));
		REP(day,d){
			REP(futan,w+1){
				REP(renzoku,x+1){
					REP(from,c){
						FOR(to,from,c+1){
							bool ng=false;
							FOR(i,from,to){
								if(e[i][day]==0){
									ng=true;
									break;
								}
							}
							if(ng){
								continue;
							}

							int cur_futan=0;
							FOR(i,from,to){
								cur_futan+=f[i][day];
							}
							int cur_money=0;
							FOR(i,from,to){
								cur_money+=e[i][day];
							}
							bool cur_renzoku=(to-from>=2);

							if(futan+cur_futan<w+1&&renzoku+cur_renzoku<x+1){
								dp[day+1][futan+cur_futan][renzoku+cur_renzoku]=
									max(dp[day+1][futan+cur_futan][renzoku+cur_renzoku],
									dp[day][futan][renzoku]+cur_money);
							}
						}
					}
				}
			}
		}
		int ans=0;
		REP(futan,w+1){
			REP(renzoku,x+1){
				ans=max(ans,dp[d][futan][renzoku]);
			}
		}
		cout<<ans<<endl;
	}

}

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

int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i=0;i<n;i++) cin >> s[i];
  int m;
  cin >> m;
  vector<string> t(m);
  for(int i=0;i<m;i++) cin >> t[i];
  map<string,int> mp;
  for(auto i:s){
    if(mp[i] == 0) mp[i] = 1;
    else mp[i]++;
  }
  for(auto i:t){
    if(mp[i]==0) mp[i] = 0;
    else{
      if(mp[i] == 0) continue;
      else mp[i]--;
    }
  }
  int max = 0;
  for(auto itr = mp.begin();itr !=mp.end();itr++){
    if(max<itr->second) max = itr->second;
  }
  cout << max << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
    map<long long,long long> M;
    long long n;
    cin >> n;
    long long ans = 0;
    M[0] = 1;
    long long S = 0;
    for (long long i= 1; i <= n; i++){
        long long a;
        cin>>a;
        S += a;
        ans += M[S];
        M[S] ++;
    }
    cout<<ans << endl;
}


Measured memory_bytes: 12800
/*zxj*/
#include<iostream> 
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);
using namespace std;
#define csh(a,n) memset(a,n,sizeof(a));
int main(){
	int n;
	cin>>n;
	int a=0,b=0,c=0;
	for(int i=0;i<n;i++){
		int d;
		cin>>d;
		if(d%2==0){
			if(d%4==0){
				c++;
			}
			else{
				b++;
			}
		}
		else{
			a++;
		}
	}
	if(b!=0){
		a++;
	}
	if(a-1<=c){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

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

int main () {
  string S ;
  cin >> S ;
  bool pre = false ;
  int ans = 0 ;
  for(int i = 1 ; i < S.size()/2 ; i++ ){
    bool can = true ;
    for(int j = 0 ; j < S.size()/2 - i ; j++ ){
      if(S[j]!=S[(S.size()/2-i)+j])
        can = false ;
    }
    if(can == true ){
      ans = i ;
      break ;
    }
  }
  cout << S.size() - ans * 2  << endl ;
}

Measured memory_bytes: 256
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 10, LOG_A = 61;

int basis[LOG_A];

int sz;

void insertVector(int mask) {
  for (int i = 0; i < LOG_A; i++) {
    if ((mask & 1LL << i) == 0) continue;

    if (!basis[i]) {
      basis[i] = mask;
      ++sz;
      
      return;
    }

    mask ^= basis[i];
  }
}

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  int T;
  cin >> T;
  while(T--){
    int n;
    cin >> n;
    int a[n]={0};
    for(int i=0;i<n;i++){
      cin >> a[i];
    }
    for(int i=0;i<LOG_A;i++){
      basis[i]=0;
    }
    sz = 0;
    string s;
    cin >> s;
    bool f = true;
    for(int i=n-1;i>=0;i--){
      if(s[i]=='0')insertVector(a[i]);
      else {
        int mask = a[i];
        for (int i = 0; i < LOG_A; i++) {
          if ((mask & 1LL << i) == 0) continue;
          mask ^= basis[i];
        }
        if(mask)f = false;
      }
    }
    cout << (f^1) << endl;
  }

return 0;
}
///....


Measured memory_bytes: 3584
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
	for(;;){
		long long a;
		cin >> a;
		if(a == 0)
			return 0;

		bool plus = true;
		if(a < 0){
			a *= -1;
			plus = false;
		}

		vector<int> x(12, 0);
		for(int i=0; i<10; ++i){
			int b = a % 10;
			a /= 10;

			if(plus){
				b += x[i];
				if(b <10)
					x[i] = b;
				else{
					x[i+2] = 1;
					x[i+1] = 9;
					x[i] = b - 10;
				}
			}else{
				if(b != 0){
					b = 10 + b - x[i];
					if(b <= 10)
						x[i] = 10 - b;
					else{
						x[i+1] += 1;
						x[i] = 20 - b;
					}
				}
			}

			plus = !plus;
		}

		int i = 11;
		while(x[i] == 0)
			-- i;
		do{
			cout << x[i];
		}while(--i >= 0);
		cout << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll a[100010];

int main() {
	ll n,m;
	string s;
	cin>>n>>m>>s;
	for(int i=1;i<n;i++){
		if(s[i]=='C'&&s[i-1]=='A'){
			a[i]=1;
		}
					a[i]=a[i-1]+a[i];
	}
	for(int i=0;i<m;i++){
		ll l,r;
		cin>>l>>r;
		l--;r--;
		cout << a[r]-a[l]<<endl;
	}

}

Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    akari<pair<seika, i64>> as(n);
    for (int i = 0; i < n; i++)
    {
        cin >> as[i].first >> as[i].second;
    }
    seika x;
    cin >> x;
    i64 ans = 0;
    bool f = 0;
    for (int i = 0; i < n; i++)
    {
        if (f)
        {
            ans += as[i].second;
        }
        if (as[i].first == x)
        {
            f = 1;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;

const int mod = 1e9+7;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int N = s.size();
  int i = 0;
  while(i < N) {
    int now = i;
    if (s.find("dream", i) == i) {
      i += 5;
      if (s.find("eraser", i) == i) {
        i += 6;
      } else if (s.find("erase", i) == i) {
        i += 5;
      } else if (s.find("er", i) == i) {
        i += 2;
      }
    } else if (s.find("eraser", i) == i) {
      i += 6;
    } else if (s.find("erase", i) == i) {
      i += 5;
    } else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

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

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̒萔 (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;

    rep(i, n) {
        if ((i + 1) % 2 == 1 && a[i] % 2 == 1)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 3724
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

mod  binary_indexed_tree{

type VecType = usize;

///Binary Indexed Tree
pub struct BIT {
    v: Vec<VecType>,
}

impl BIT {
    ///BIT木を構築する。
    ///
    ///n:要素数
    pub fn new(n: usize) -> BIT {
        let v = vec![0; n + 1];
        BIT { v: v }
    }

    ///任意の要素に値を加算する。
    ///
    /// index:加算する場所(0-indexed)
    /// value:加算する値
    pub fn add(&mut self, index: usize, value: VecType) {
        let mut i = (index + 1) as isize;
        while i <= (self.v.len() - 1) as isize {
            self.v[i as usize] += value;
            i += i & -i;
        }
    }

    ///[0,index]の区間和を求める。
    pub fn get(&mut self, index: usize) -> VecType {
        let mut i = (index + 1) as isize;
        let mut res = 0 as VecType;
        while i > 0 {
            res += self.v[i as usize];
            i -= i & -i;
        }
        res
    }
}

}

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

use binary_indexed_tree::*;

#[fastout]
fn main() {
    input! {
        n:usize,q:usize,
    }
    let mut bit = BIT::new(n);
    for i in 0..n {
        input! {
            ai:usize
        }
        bit.add(i, ai);
    }
    for _ in 0..q {
        input! {
            t:usize,p:usize,x:usize
        }
        if t == 0 {
            bit.add(p, x);
        } else {
            let res = bit.get(x - 1) - if p == 0 { 0 } else { bit.get(p - 1) };
            println!("{}", res);
        }
    }
}



Measured memory_bytes: 21476
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int a,b,c;
    int k;
    Scd3(a,b,c);
    Scd(k);

    printf( "%d\n", a+b+c+((max(max(a,b),c))*((1<<k)-1)) );

    return 0;
}



Measured memory_bytes: 256