akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<algorithm>
#include<cstring>
//#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define inf (int)1e9
ll dp[3001][3001];
ll game(ll arr[], ll n, ll i, ll j)
{
	if (i > j) return dp[i][j] = 0;
	if (dp[i][j] != -1)
		return dp[i][j];
	ll a = arr[i] + min(game(arr, n, i + 2, j), game(arr, n, i + 1, j - 1));
	ll b = arr[j] + min(game(arr, n, i, j - 2), game(arr, n, i + 1, j - 1));
	return dp[i][j] = max(a, b);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	// cin >> t;
	t  = 1;
	while (t--)
	{
		memset(dp, -1, sizeof(dp));
		ll n;
		cin >> n;
		ll arr[n];
		ll sum = 0;
		for (ll i = 0; i < n; i++)
		{
			cin >> arr[i];
			sum += arr[i];
		}
		ll p = game(arr, n, 0, n - 1);
		ll q = sum - p;
		cout << p - q << endl;
	}
	return 0;
}


Measured memory_bytes: 70784
#include <iostream>
using namespace std;
typedef long long ll;

int main () {
	ll N;
	cin >> N;
	ll m3 = N / 3;
	ll m5 = N / 5;
	ll m15= N / 15;
	ll res = N*(N+1)/2 + 15*m15*(m15+1)/2 - 3*m3*(m3+1)/2 - 5*m5*(m5+1)/2;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;
int nums[100009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    rep(i,N) cin>>nums[i];
    
    int cnt=0;
    rep(i,N){
        if(i+1==nums[i]){
            swap(nums[i],nums[i+1]);
            cnt++;
        }
    }
    cout1(cnt)
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main(){
  for(int H;cin>>H,H;){
    int g[99][5]={};
    for(int i=H-1;i>=0;i--){
      for(int j=0;j<5;j++){
	cin>>g[i][j];
      }
    }
    int ans=0;
    for(;;){
      bool f=false;
      for(int i=0;i<H;i++){
	bool d[99][5]={};
	for(int j=0;j<=2;j++){
	  if(g[i][j]&&g[i][j]==g[i][j+1]&&g[i][j+1]==g[i][j+2]){
	    d[i][j]=d[i][j+1]=d[i][j+2]=true;
	  }
	}
	for(int j=0;j<5;j++){
	  if(d[i][j]){
	    ans+=g[i][j];
	    g[i][j]=0;
	    f=true;
	  }
	}
      }
      if(!f)break;
      for(int i=0;i<5;i++){
	for(int j=0,r=0;j<H;j++,r++){
	  while(r<H&&g[r][i]==0){
	    r++;
	  }
	  g[j][i]=g[r][i];
	}
      }
    }
    cout<<ans<<endl;
  }
}

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

using namespace std;
using ll = long long int;
#define INF 20000000000000000;

int main(void){
  string str;
  cin >> str;
  int length = str.length();
  
  for(int i = 0;i < length;i++){
    string temp = str.substr(0, length-1-i);
    if(temp.length() % 2 == 0){
      string t1, t2;
      t1 = temp.substr(0, temp.length()/2);
      t2 = temp.substr(temp.length()/2);
      if(t1 == t2){
        cout << temp.length() << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, W, ans;
    cin >> N >> W;
    vector<ll> v(N);
    vector<ll> w(N);
    ll SumVal = 0;
    REP(ll,i,0,N){
        cin >> w.at(i) >> v.at(i);
        SumVal += v.at(i);
    }
    ll dp[SumVal+1];
    REP(int,i,0,SumVal+1) dp[i] = INT_MAX;
    dp[0] = 0;
    REP(ll,i,0,N){
        for ( int value = SumVal; value >= 0; value--){
            if ( value >= v.at(i) ) dp[value] = min( dp[ value - v.at(i) ] + w.at(i), dp[value]);
        }
    }
    REP(ll,value,0,SumVal+1) if ( dp[value] <= W ) ans = value;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;
 int n;
ll v[111111][3],dp[111111][3];

int main(){
   cin>>n;
   for(int i=1;i<=n;i++)cin>>v[i][0]>>v[i][1]>>v[i][2];
   for(int i=1;i<=n;i++){
     for(int j=0;j<3;j++)for(int k=0;k<3;k++){
       if(j!=k){
         dp[i][j]=max(dp[i][j],dp[i-1][k]+v[i][k]);
       }
     }
   }
   cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));

    
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
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<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	int N;
	cin>>N;
	vector<int> a(N);
	rep(i,N) cin>>a[i];
	rep(i,N) rep(j,i) if(abs(a[i]-a[j])%(N-1)==0){
		cout<<a[i]<<" "<<a[j]<<endl;
		return 0;
	}
}



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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



//メイン関数
int main()
{
	int N, K;
	cin >> N >> K;
	vector<int>a(N);
	vector<bool> win(K + 1, false);
	REP(i, N)cin >> a[i];

	FOR(j, a[0], K + 1)
	{
		win[j] = false;
		REP(i, N)
		{
			auto tmp = ((a[i] <= j) && !win[j - a[i]]);
			win[j] = win[j] || tmp;
		}
	}
	cout << (win.back() ? "First" : "Second") << endl;
	cin>>N;
	return 0;
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int main(){
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
return 0;
}

Measured memory_bytes: 3596
n = int(input())
h = list(map(int, input().split()))

dp = [float('inf')] * n
dp[0] = 0

for i in range(n):
    if i < n-1: dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1]-h[i]))
    if i < n-2: dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2]-h[i]))
    
print(dp[-1])

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    map<pair<int, int>, int> m;
    int a, b;
    REP(i, n) {
        cin >> a >> b;
        for (int j = max(1, a - 2); j <= min(h - 2, a); j++) {
            for (int k = max(1, b - 2); k <= min(w - 2, b); k++) {
                m[make_pair(j, k)]++;
            }
        }
    }
    vector<ll> sum(10);
    ll r = (ll)(h - 2) * (w - 2);
    for (auto x : m) {
        sum[x.second]++;
        r--;
    }
    sum[0] = r;
    REP(i, 10) cout << sum[i] << endl;
}


Measured memory_bytes: 56448
n, k = map(int,input().split())
s = list(input())

if s[k-1] == "A":
  s[k-1] = "a"
elif s[k-1] == "B":
  s[k-1] = "b"
elif s[k-1] == "C":
  s[k-1] = "c"

print("".join(s))

Measured memory_bytes: 3060
from collections import deque

n,m = map(int, input().split())
g = [[] for _ in range(n)] # 隣接リスト

for _ in range(m):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

# bfs
queue = deque([0])
d = [None] * n # init fromt rooms
d[0] = 0
while queue:
    v = queue.popleft()
    for i in g[v]:
        if d[i] is None:
            d[i] = v
            queue.append(i)
print('Yes')
for i in range(1, n):
    print(d[i]+1)

Measured memory_bytes: 34044
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int a[1000][1000],b[1000],i, j;
	int c[1000];
	cin >> i >> j;

	for (int m = 1;m <= i;m++) {
		for (int n = 1;n <= j;n++) {
			cin >> a[m][n];
			c[n] = 0;
		}

	}

	for (int o = 1;o <= j;o++) {
		cin >> b[o];
	}
	for (int l = 1;l <= i;l++) {
		for (int k = 1;k <= j;k++) {
			c[l] += b[k] * a[l][k];
		}
	}
	for (int h = 1;h <= i;h++) { cout << c[h] << endl; }
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define mm 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define siz(x) (int)x.size()

#define show(x) cout<<#x<<" "<<x<<'\n'
#define iosbase ios_base::sync_with_stdio(false); cin.tie(NULL);
#define oset tree<int , null_type, less_equal<int> , rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

vector<int> adj[100005];
int vis[100005];
int sz[100005];
void dfs(int x)
{
    vis[x]=1;
    if(adj[x].size()==0)
    {
        sz[x]=0;
        return;
    }
    
    int mx=-1;
    for(int i=0;i<adj[x].size();i++)
    {
        if(!vis[adj[x][i]])
            dfs(adj[x][i]);
        mx=max(mx,sz[adj[x][i]]);
    }
    sz[x]=1+mx;
}

int main()
{
    int n,m;
    cin>>n>>m;
    memset(sz,-1,sizeof(sz));
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        adj[x].pb(y);
    }
    
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
            dfs(i);
    }
    
    int ans=-1;
    for(int i=1;i<=n;i++) 
    {
        ans=max(sz[i],ans);
    }
    cout<<ans<<endl;
    return 0;
}

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

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

	string S;
	cin >> S;

	int result = 753;
	for( int i = 0; i <= S.size()-3; ++i ) {
		int x = abs( 753 - stoi( S.substr( i, 3 ) ) );
		if( x < result ) {
			result = x;
		}
	}

	cout << result << endl;
	return 0;
}


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


def answer(H: int, N: int, A: list) -> str:
    damage = 0
    for i in range(0, N):
        damage += int(A[i])
        i += 1
    if damage < H:
        return 'No'
    else:
        return 'Yes'

print(answer(H, N, A))


Measured memory_bytes: 20504
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = [i-1 for i in A]

doubling = [[0] * N for _ in range(61)]
for i in range(N):
  doubling[0][i] = A[i]
  
for i in range(1,61):
  for j in range(N):
    doubling[i][j] = doubling[i-1][doubling[i-1][j]]
    
now = 0
i = 0
while K!=0:
  if K&1==1:
    now = doubling[i][now]
    K = K>>1
    i += 1
    
  else:
    K = K>>1
    i += 1
    
print(now+1)

Measured memory_bytes: 175700
#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()
using namespace std;

#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は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    string A, B;
    cin >> A >> B;
    size_t A_len = A.length(), B_len = B.length();
    
    if (A_len > B_len) {
        cout << "GREATER" << "\n";
    } else if (A_len < B_len) {
        cout << "LESS" << "\n";
    } else {
        // digits of A and B is equal
        if (A == B) {
            cout << "EQUAL" << "\n";
        } else {
            REP(i, A_len) {
                if (A[i] == B[i]) {
                    continue;
                } else if (A[i] > B[i]) {
                    cout << "GREATER" << "\n";
                    break;
                } else {
                    cout << "LESS" << "\n";
                    break;
                }
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    if (4 * a * b < (c - a - b) * (c - a - b) && (c - a - b) >= 0)
        cout << "Yes";
    else
        cout << "No";
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define forsn(i,x,y) for(long long i = (x) ; i <= (y) ; ++i)
typedef long long ll;
typedef long double ld;

int main() {
  vector<ll> a;
  int n;
  cin >> n;
  forn(i,n) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }

  ll total = 0;
  ll prev = 0;
  forn(i,n) {
    if(prev == 1 && a[i] != 0) {
      a[i]--;
      total++;
    }
    total += a[i] / 2;
    prev = a[i] % 2;
    //cout << i << " " << prev << " " << total << endl;
  }
  cout << total << endl;
  return 0;
}



Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define MOD 1000000007
#define mod 998244353
#define pie 3.14159265358979323846264338327950L
#define N 200009
#define M 2000009
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define umap unordered_map<int, int>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
#define int long long
using namespace std;
 
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}
 

vector<pair<int,int> > arr(10);

map<pair<int,int>,ld> mp;
ld ans = 0;
int n;
void fun(vector<int> temp, ld curr) {
    if(temp.size() == n) {
        ans+= curr;
        // for(auto it : temp) {
        //     cout<<it<<" ";
        // }
        // cout<<endl;
        return;
    }
    for(int i=0; i<n; i++) {
        if(find(all(temp),i) == temp.end()) {
            int prev = temp.back();
            temp.push_back(i);
            fun(temp,curr + mp[mpr(i,prev)]);
            temp.pop_back();
        }
    }
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
 

void test_case() {
    
    
    cin>>n;

    COMinit();

    
    rep(i,n) {
        int x,y;
        cin>>x>>y;
        arr[i] = mpr(x,y);
    }

    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            ld  d= pow(arr[i].first - arr[j].first,2) + pow(arr[i].second -arr[j].second,2);
            d = sqrt(d);
            // cout<<d<<endl;
            mp[mpr(i,j)] = d;
            mp[mpr(j,i)] = d;
        }
    }
    

    vec temp;
    for(int i=0; i<n; i++) {
        temp.push_back(i);
        fun(temp,0.0);
        temp.pop_back();

    }

    ld fin = ans/fac[n];

    // cout<<ans<<endl;

    cout<<fin<<endl;


}
    

signed main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(20);
 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
 
    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}

Measured memory_bytes: 15756
#include <stdio.h>

int main()
{
	unsigned int a   = 0;
	unsigned int b   = 0;
	unsigned int len = 0;
	char buff[8] = {0};

	while ( scanf("%d %d", &a, &b) != EOF )
	{
		len = sprintf(buff,"%d", a+b);
		printf("%d\n", len);
	}
	
	return 0;
}

Measured memory_bytes: 612
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
int main(){
    int n,ans=0;
    string a,b,c;
    cin>>n>>a>>b>>c;
    for(int i=0;i<n;i++){
        if(a[i]==b[i]&b[i]==c[i]) ans+=0;
        else if(a[i]==b[i]|b[i]==c[i]|c[i]==a[i]) ans++;
        else ans+=2;
    }
    cout<<ans;
}

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

int main() {
	int N;
	cin>>N;
	long long H[N];
	for(int i=0;i<N;++i){
		cin>>H[i];
	}
	int ans = 0;
	int tmp = 0;
	long long h = H[0];
	for(int i=1;i<N;++i){
		if(H[i] <= h){
			tmp++;
		}
		else {
			if(ans < tmp) {
				ans = tmp;
			}
			tmp = 0;
		}
		h = H[i];
	}
	if (ans < tmp) ans = tmp;
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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 ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  string n;
  cin >> n;
  ll cnt = 0;

  for(char c : n) {
    cnt += c - '0';
  }

  if (cnt % 9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3728
#include <iostream>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;

llint x, y, z, K;
llint a[1005], b[1005], c[1005];
vector<llint> vec, vec2;

int main(void)
{
	cin >> x >> y >> z >> K;
	for(int i = 1; i <= x; i++) cin >> a[i];
	for(int i = 1; i <= y; i++) cin >> b[i];
	for(int i = 1; i <= z; i++) cin >> c[i];
	sort(a+1, a+x+1);
	sort(b+1, b+y+1);
	sort(c+1, c+z+1);
	
	for(int i = 1; i <= x; i++){
		for(int j = 1; j <= y; j++){
			vec.push_back(a[i]+b[j]);
		}
	}
	sort(vec.rbegin(), vec.rend());
	if(vec.size() > K) vec.erase(vec.begin()+K, vec.end());
	
	for(int i = 0; i < vec.size(); i++){
		for(int j = 1; j <= z; j++){
			vec2.push_back(vec[i]+c[j]);
		}
	}
	sort(vec2.rbegin(), vec2.rend());
	
	for(int i = 0; i < K; i++) cout << vec2[i] << endl;
	
	return 0;
}

Measured memory_bytes: 43364
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N+10];
		for (int i = 0; i < N; i++) {
			A[sc.nextInt()] = i;
		}
		sc.close();

		for (int i = 1; i <= N; i++) {
			System.out.print(A[i] + 1 + " ");
		}
	}
}


Measured memory_bytes: 65052
#include<stdio.h>
#include <math.h>
#define PI 3.141592653589793
int main()
{
  
  
  
  double a,b,C,c,L,S,H;
  scanf("%lf %lf %lf",&a,&b,&C);
  
  c=sqrt(((a*a)+(b*b))-(2*a*b*cos(C*PI/180)));
    L=a+b+c;
    S=(a*b*sin(C*PI/180))/2;
    H=S*2/a;
  printf("%f %f %f",S,L,H);
  
  
 
  return 0;
 
}



Measured memory_bytes: 2108
#include<stdio.h>

typedef struct{char suit, value;}Card;

void bubble(Card A[], int N){
    int i,j;
    Card t;
    for(i=0; i<N; i++){
        for(j=N-1; j>=i; j--){
            if(A[j].value<A[j-1].value){
                t=A[j];A[j]=A[j-1];A[j-1]=t;
            }
        }
    }
}

void selection(Card A[], int N){
    int i,j,minj;
    Card t;
    for(i=0;i<N;i++){
        minj=i;
        for(j=i;j<N;j++){
            if(A[j].value<A[minj].value)minj=j;
        }
        t=A[i];A[i]=A[minj];A[minj]=t;
    }
}

void print(Card A[], int N){
    int i;
    for(i=0;i<N;i++){
        if(i>0)printf(" ");
        printf("%c%d",A[i].suit,A[i].value);
    }
    printf("\n");
}

int isStable(Card C1[], Card C2[], int N){
      int i;
  for(i=0; i<N; i++) {
    if(C1[i].suit != C2[i].suit) return 0;
  }
  return 1;
}

/* オリジナル関数を追加 */
void str2Card(Card *t,char str[]) {
    t->suit  = str[0];
    t->value = str[1] - '0';
}

int main(void) {
  Card C1[100], C2[100];
  int N,i;
  char str[3];

  scanf("%d",&N);
  for(i=0;i<N; i++) {
    scanf("%s",str);
    str2Card(&C1[i],str);
  }

  for(i=0; i<N; i++) C2[i] = C1[i];

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  printf("Stable\n");
  print(C2,N);
  if(isStable(C1,C2,N)) {
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int mod = 1000000007;
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
        //cout<<sum<<" without"<<endl;
        sum %= mod;
        //cout<<sum<<" with"<<endl;
    }
 
    long long ans = 0;
 
    //Search for all i
    for (int i = 0; i < N; i++)
    {
        //Update the values of A[i+1] ... A[N]
        sum -= A[i];
        if (sum < 0) sum += mod;
 
        ans += A[i] * sum;
        ans %= mod;
    }
 
    cout << ans << endl;
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

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

    ll N;
    string S;
    cin >> N;
    vector<ll> A(N);
    
    REP(i,N){
        cin >> A.at(i);
    }
	sort(A.begin(), A.end());
    Bint ans = 1;
    bool flag = true;

    REP(i,N){
        ans *= A.at(i);
        if(ans>1000000000000000000){
            cout << -1 << endl;
            flag = flase;
            break;
        }
    }
    if(flag){
        cout << ans << endl;
    }
}


Measured memory_bytes: 4044
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;

int main() {
    int h,n;
    cin >> h >> n;
    vector<int>a(n);
    rep(i,n) cin >> a[i];
    bool ans = false;
    rep(i,n) {
        h -= a[i];
        if(h<=0) {
        ans = true;
        break;}
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 640
/********************************
*** ******** ********** *********
*** * ****** ********* * ********
*** ** ***** ******** *** *******
*** *** **** ******* ***** ******
*** **** *** ****** ******* *****
*** ***** ** ***** +++++++++ ****
*** ****** * **** *********** ***
*** *******  *** ************* **
*** ******** ** *************** *
**********_**********************
* |   /  / \  \     /    /\     *
* |  /  |   |  \   /    /  \    *
* | /   |   |   \ /    /    \   *
* |+\   |   |    |    /______\  *
* |  \  |   |    |   |        | *
* |   \  \_/     |   |        | *
********************************/
#include<bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define KING 1000000002
#define queen 1000002
#define fi first
#define se second
#define se second
#define lsb(i) (i & -i)
#define Pi 3.141592653589793238
#define nl cout<<'\n'
#define TEST cout<<"TEST",nl
#define all(a) a.begin(), a.end()
#define remax(a, b) (a = ((a<b) ? b : a))
#define remin(a, b) (a = ((a<b) ? a : b))
#define pr pair<lli,lli>
#define pb push_back
#define eb emplace_back
#define precise(a) cout<<fixed<<setprecision(a)
#define mp make_pair
#define vi vector<lli>
#define vpi vector<pr> 
#define P pair<lli,pr>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define NA(i,s,n) for(lli i=s;i<n;i++)
using namespace std;

lli power(lli x,lli y,lli p = (lli)(1e13)) { 
	lli res = 1;	 
	x = x % p; 
	while (y > 0) 
	{ 
		if (y & 1) 
			res = (res*x) % p; 
		y = y>>1; 
		x = (x*x) % p; 
	} 
	return res; 
}

const lli N = 2e5 + 2;
lli n, a[N], mx = -1, k; 

bool fun(lli x) {
    lli sm = 0;
    NA(i,0,n) sm += ((a[i]/x) - ((a[i]%x==0 ? 1 : 0)));
    return sm <= k;
}

void solve(){
    cin >> n >> k;
    NA(i,0,n) cin >> a[i], mx = max(mx, a[i]);
    lli l = 0, r = mx, ans = r;
    while(l+1 < r) {
        lli mid = (l+r) >> 1;
        if(fun(mid)) ans = mid, r = mid;
        else l = mid;
    }
    cout << ans;
    return;
}

int main(){
    fastIO;
    lli t = 1;
    // cin >> t;
    NA(i,0,t){ 
		// cout << "Case #" << i+1 << ": \n";
		solve();
	}
	return 0;
}
		

Measured memory_bytes: 5088
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> p;

int field[55][55];
int w, h;
int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};

void dfs(int x, int y){
  field[x][y] = 0;
  for(int i = 0; i < 8; i++){
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(nx < 0 || nx > h) continue;
    if(ny < 0 || ny > w) continue;
    if(field[nx][ny] == 1) dfs(nx, ny);
  }
}

int main(){

  while(cin >> w >> h, w|h){
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        cin >> field[i][j];
      }
    }
    int sum = 0;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        if(field[i][j] == 1){
          sum++;
          dfs(i, j);
        }
      }
    }
    cout << sum << endl;
  }
  return 0;
}


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

int main(){

  int n;

  cin>>n;

  int card[4][13] = {};

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

    string suit;

    int num;

    cin>>suit>>num;

    if( suit == "S") card[0][num-1] = 1;
    if( suit == "H") card[1][num-1] = 1;
    if( suit == "C") card[2][num-1] = 1;
    if( suit == "D") card[3][num-1] = 1;
  }

  string str[4] = { "S","H","C","D"};
  for (int i=0; i<4; i++){
    for ( int j=0; j<13; j++){
      if (card[i][j] == 1) continue;
      cout<<str[i]<<" "<<j+1<<endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)

int main()
{
  char s[5];
  int cnt = 0;
  scanf("%s", s);
  for(int i=0; s[i] != '\0'; ++i)if(s[i] == '1')++cnt;
  outl(cnt);
}



Measured memory_bytes: 256
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{	
	//#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);  // for getting input from input.txt
    //freopen("output.txt", "w", stdout);	 // for writing output to output.txt	
	//#endif
    int n;
    cin>>n;
    int x=7;
    int count=0;
    for(int i=1;i<=n;i++)
    {
        if(x%n==0) {
        	cout<<i<<"\n"; 
        	count=1; 
        	break;
        }
        else x = ( (x*10) +7) %n;
    }
    if(count==0) 
    	cout<<-1<<"\n";
    return 0;
}


Measured memory_bytes: 3572
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, m, R = LI()
    r = LI_()
    edg = [[inf] * n for i in range(n)]
    for _ in range(m):
        a, b, c = LI_()
        c += 1
        edg[a][b] = c
        edg[b][a] = c
    for i in range(n):
        edg[i][i] = 0
    for k in range(n):
        for i in range(n):
            for j in range(n):
                edg[i][j] = min(edg[i][j], edg[i][k] + edg[k][j])
    fulls = itertools.permutations(range(R), R)
    ans = inf
    for full in fulls:
        b = -1
        tmp = 0
        for f in full:
            if b == -1:
                b = r[f]
                continue
            tmp += edg[r[f]][b]
            b = r[f]
        ans = min(ans, tmp)
    print(ans)

    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 57564
#include <bits/stdc++.h>
using namespace std;
int a[101];
int main()
{
	int n,x;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		a[x]=1;
	}
	int s=0;
	for(int i=1;i<=100;i++)
	if(a[i]==1)s++;
	cout<<s;
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[5020],f[5020],s;
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]=min(a[i],k);
        s+=a[i];
    }
    sort(a,a+1+n);
    f[0]=1;
    for(int i=n;i>=0;i--)
    {
        bool flag=1;
        for(int j=k-1;j>=k-s&&j>=0;j--)
            if(f[j]) flag=0;
        if(flag)
        {
            cout<<i;
            return 0;
        }
        for(int j=k;j>=a[i];j--)
            f[j]|=f[j-a[i]];
        s-=a[i];
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/math>
//using namespace atcoder;
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <numeric>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;
ll  LINF = 1e18;


int main(){
	int n;cin >> n;
	vector<int> hat(n);
	int mi=INF,ma=0;
	rep(i,n) {
		cin >> hat[i];
		mi = min(hat[i],mi);
		ma = max(hat[i],ma);
	}
	if(ma-mi>1) {
		cout << "No"<< endl;
		return 0;
	}
	int nmi = 0,nma = 0;
	rep(i,n){
		if(hat[i]==mi) nmi++;
		else nma++;
	}
	if(mi==ma){
		if(1<=mi && mi <= n/2) cout << "Yes" << endl;
		else if(mi == n-1) cout << "Yes" << endl;
		else cout << "No" << endl;
		return 0;
	}
	if(nmi <= mi && ma <= nmi+nma/2) cout << "Yes" << endl;
	else cout << "No" << endl;	
}

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

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

  vector<long long> num(K, 0);
  for (int i = 1; i <= N; i++) {
    num[i % K]++;
  }

  long long ans = num[0] * num[0] * num[0];
  if (K % 2 == 0) ans += num[K / 2] * num[K / 2] * num[K / 2];

  printf("%lld", ans);
  return 0;
}

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

using namespace std;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	int a[n];
	int sum=0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		sum+=a[i];
	}
	int rp = 4*m;
	int c=0;//count
	for(int i=0;i<n;i++){
		if(rp*a[i]>=sum){
			c++;
		}
	}
	//printf("%d\n",atleast);
	if(c>=m){
		printf("Yes");
	}
	else{
		printf("No");
	}
}


Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

bool chk[100050];
int main() {
	int N, i, j;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		int t;
		scanf("%d", &t);
		if (t == i) chk[i] = true;
	}

	int ans = 0;
	for (i = 1; i <= N;) {
		if (!chk[i]) {
			i++;
			continue;
		}
		for (j = i; j <= N; j++) if (!chk[j]) break;
		j--;
		ans += (j - i + 2) / 2;
		i = j + 1;
	}
	return !printf("%d\n", ans);
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    VL b_cnt(s.size() + 1, 0);  // 1-indexed
    FOR(i, 1, s.size()) {
        if(s[i - 1] == 'B') b_cnt[i] = b_cnt[i - 1] + 1;
        else b_cnt[i] = b_cnt[i - 1];
    }

    ll ans = 0;
    REP(i, s.size()) {
        if(s[i] == 'W') ans += b_cnt[i];
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
int n, a[401];
long long dp[401][401], pref[401];
long long calc(int l, int r){
    if(dp[l][r] != -1){
        return dp[l][r];
    }
    long long ans = 1e18;
    for(int i = l + 1; i <= r; i++){
        ans = min(ans, calc(l, i - 1) + calc(i, r) + (pref[r] - pref[l - 1]));
    }
    return dp[l][r] = ans;
}
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        pref[i] = a[i] + pref[i - 1];
        for(int j = 1; j <= n; j++){
            if(i == j) continue;
            dp[i][j] = -1;
        }
    }
    cout << calc(1, n);
}


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

typedef long long LL;
typedef pair<int, int> pii;

#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int maxn = 2e5 + 10;
const int oo = 0x7fffffff;

template<typename T> T read() {
	T n(0), f(1);
	char ch = getchar();
	for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
	for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

int n, m;
vector<pii> P;
vector<int> R;
priority_queue<int, vector<int>, greater<int> > q;

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif

    scanf("%d%d", &n, &m);
    for(int i = 0; i < n; i++) { 
        int l, r;
        scanf("%d%d", &l, &r); P.pb(pii(l, r));
    }

    int col = 0, col2 = 0;

    sort(P.begin(), P.end());
    for(int i = 0; i < n; i++) {
        q.push(P[i].snd);
        if(P[i].fst <= col) { R.pb(q.top()); q.pop(); } else ++ col;
    }

    int ans = 0;
    sort(R.begin(), R.end(), greater<int>());
    for(int i = 0; i < int(R.size()); i++) {
        if(m - col2 == col) ++ ans;
        else if(m - R[i] + 1 <= col2) ++ ans;
        else ++ col2;
    }

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


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

int main() {
    string S;
    cin >> S;
    long long ptn0=0; // 0101...
    long long ptn1=0; // 1010...
    for (long long i=0; i<S.size(); i++) {
        if (i%2==0) {
            if (S.at(i)!='0') ptn0++;
            else ptn1++;
        }
        else {
            if (S.at(i)!='1') ptn0++;
            else ptn1++;
        }
    }
    cout << min(ptn0, ptn1) << endl;
}

Measured memory_bytes: 512
// B - Counting of Trees
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)
#define MOD 998244353

int main(){
	int N; cin>>N;
	vi C(N);
	rpz(i, N){
		int d; scanf("%d",&d);
		if((i==0 && d!=0) || (i>0 && d<=0)){
			cout<< 0 <<endl;
			return 0;
		}
		C[d]++;
	}
	ll ans = 1;
	rp(d, 1, C.size()) rpz(i, C[d]) ans  = ans * C[d-1] % MOD;
	cout<< ans <<endl;
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(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);
}

//実行部
void Main()
{
  ll a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  a *= 100;
  b *= 100;
  ld flag = 0;
  ll sw = f, s = 0;
  for(ll A = 0;A * a <= f;A++)
  {
    for(ll B = 0;A * a + B * b <= f;B++)
    {
      for(ll C = 0;(e + 100) * 100 * C * c <= 100 * e *(A * a + B * b + C * c)&&A * a + B * b + C * c <= f;C++)
      {
        for(ll D = 0;(e + 100) * 100 * (C * c + D * d) <= 100 * e * (A * a + B * b + C * c + D * d)&&A * a + B * b + C * c + D * d <= f;D++)
        {
          if (flag <= 100. * (C * c + D * d) / (A * a + B * b + C * c + D * d))
          {
            flag = 100. * (C * c + D * d) / (A * a + B * b + C * c + D * d);
            sw = A * a + B * b + C * c + D * d;
            s = C * c + D * d;
          }
        }
      }
    }
  }
  cout << sw << " " << s << endl;
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/


Measured memory_bytes: 256
n,m=map(int,input().split())
pref=[[] for _ in range(n+1)]
py = [[i]+list(map(int,input().split())) for i in range(m)]
py.sort(key=lambda x: (x[1],x[2]))
ans=list()
now=0
cnt=0
for x in py:
  cnt = 1 if now != x[1] else cnt + 1
  now = x[1]
  ans.append([x[0],x[1],cnt])
ans.sort(key=lambda x:x[0])
for x in ans:
  print(str(x[1]).zfill(6)+str(x[2]).zfill(6))




Measured memory_bytes: 50716
#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e5+5;
vector<int> e[N];
struct node{
	int l,r,c;
	node(){}
	node(int _l,int _r,int _c) : l(_l), r(_r), c(_c) {}
	inline bool check(ri x){
		return l<=x&&x<=r&&(x&1)==c;
	}
	inline node rev(){
		return node(l-1,r+1,c^1);
	}
}q[N];
int v[N];
inline node merge(node a,node b){
	if(a.c!=b.c)
		puts("No"),exit(0);
	return node(max(a.l,b.l),min(a.r,b.r),a.c);
}
inline node dfs(ri x,ri fa,node info){
//	printf("dfs in %d\n",x);
	if(v[x]!=-1){
		if(!info.check(v[x]))
			puts("No"),exit(0);
		info=node(v[x],v[x],v[x]&1);
	}
//	printf("dfs %d\n",x);
	for(int y:e[x])
		if(y!=fa)
			info=merge(info,dfs(y,x,info.rev()));
	if(v[x]!=-1){
		if(!info.check(v[x]))
			puts("No"),exit(0);
	}
	q[x]=info;
//	printf("dfs out %d\n",x);
	return info.rev();
}
inline void dfs2(ri x,ri fa){
	for(int y:e[x])
		if(y!=fa){
			if(v[y]!=-1){
				dfs2(y,x);
				continue;
			}
			v[y]=q[y].check(v[x]-1)?v[x]-1:v[x]+1;
			dfs2(y,x);
		}
}
int main(){
	ri n,k,i,x,y;
	gi(n);
	for(i=1;i<=n;++i) v[i]=-1;
	for(i=1;i^n;++i) gi(x),gi(y),e[x].push_back(y),e[y].push_back(x);
	gi(k);
	while(k--) gi(x),gi(v[x]);
	dfs(x,0,node(v[x],v[x],v[x]&1));
	dfs2(x,0);
	puts("Yes");
	for(i=1;i<=n;++i) print(v[i]),putc('\n'); 
	return 0;
}

Measured memory_bytes: 31232
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    for(int i = s.size() - 1; i >= 0; i--){
        string s2 = s;
        bool ok = true;
        for(size_t j = 0; j < i; j++){
            if(s2[j] == '?'){
                s2[j] = 'a';
            }
        }
        size_t j;
        for(j = 0; j < t.size(); j++){
            if(i + j >= s2.size()){
                ok = false;
                break;
            }else if(s2[i + j] == '?'){
                s2[i + j] = t[j];
            }else if(s2[i + j] != t[j]){
                ok = false;
                break;
            }
        }
        if(!ok){ continue; }
        for(; i + j < s.size(); j++){
            if(s2[i + j] == '?'){
                s2[i + j] = 'a';
            }
        }
        cout << s2 << '\n';
        return 0;
    }
    cout << "UNRESTORABLE" << '\n';
}


Measured memory_bytes: 888
#include <iostream>
using i64 = long long;

int main() {
    int a[5] {};
    for (auto &e : a) std::cin >> e;
    for (int i = 0; i < 5; i++) if (!a[i]) {
        std::cout << i + 1 << std::endl;
        return 0;
    }

    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

// head

const int N=310;
int n,ret;
char s[N][N],t[N][N];
int main() {
	scanf("%d",&n);
	rep(i,0,n) scanf("%s",s[i]);
	rep(B,0,n) {
		rep(i,0,n) rep(j,0,n) t[i][j]=s[i][(j+B)%n];
		bool sym=1;
		rep(i,0,n) rep(j,0,n) if (t[i][j]!=t[j][i]) sym=0;
		if (sym) ret+=n;
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 384
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>

using namespace std;

int main() {
 vector<int> ans(4);
  vector<int> vec(6);
  for(int i=0;i<6;i++){
    cin >> vec.at(i);
  }
  for(int i=0;i<6;i++){
    if(vec.at(i)==1){
      ans.at(0)++;
    }
     if(vec.at(i)==2){
      ans.at(1)++;
    }
     if(vec.at(i)==3){
      ans.at(2)++;
    }
     if(vec.at(i)==4){
      ans.at(3)++;
    }
  }
    bool vio=true;
    for(int i=0;i<4;i++){
      if(ans.at(i)>=3){
        vio=false;
        break;
      }
      if(ans.at(i)=0){
        vio=false;
        break;
      }
    }
    if(vio){
      cout << "YES" << endl;
    }
  else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256