akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <queue>
using ll = long long;
using namespace std;
vector<vector<int>> vec;
vector<int> d_1;
vector<int> d_n;
vector<int> reg;
vector<int> reg1;
int n;
void dfs(int x){
    for(int i=0;i<vec[x].size();i++){
    if(reg[vec[x][i]]==0){
        reg[vec[x][i]]=1;
        d_1[vec[x][i]]=d_1[x]+1;
        dfs(vec[x][i]);
    }
    }
}
void dfs1(int x){
    for(int i=0;i<vec[x].size();i++){
    if(reg1[vec[x][i]]==0){
        reg1[vec[x][i]]=1;
        d_n[vec[x][i]]=d_n[x]+1;
        dfs1(vec[x][i]);
    }
    }
}
int main(){
    cin >> n;
    vec.resize(n+1);
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }
    d_1.resize(n+1,1e9+7);
    d_n.resize(n+1,1e9+7);
    reg.resize(n+1);
    reg1.resize(n+1);
    d_1[1]=0;
    reg[1]=1;
    dfs(1);
    d_n[n]=0;
    reg1[n]=1;
    dfs1(n);
    int fe=0;
    int su=0;
  //  cout<<d_1[1]<<" "<<d_n[1]<<endl;
    for(int i=1;i<=n;i++){
        if(d_1[i]<=d_n[i]){
            fe++;
        //    cout<<"FE"<<i<<endl;
        }else{
            su++;
          //  cout<<"SU"<<i<<endl;
        }
    }
    if(su>=fe){
        cout<<"Snuke"<<endl;
    }else{
        cout<<"Fennec"<<endl;
    }
}

Measured memory_bytes: 10368
/* Author : Pranav Deshmukh
            PICT,Pune
   Purpose: Practice Atcoder
*/

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define int             long long
#define dip(type,var)   type var; cin>>var;
#define dipi(x)			int x; cin>>x;
#define w(x)            int x; cin>>x; while(x--)
#define mka(arr,n,type) type *arr=new type[n];
#define fo(i,n)			for(int i=0;i<n;i++)
#define mod             pow(10,9)+7
#define inf             1e18
#define pi 				3.141592653589793238
#define fo(i,n)        for(int i=0;i<n;i++)
#define endl			"\n"
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mimp             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >

void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
	c_p_c();
	dipi(n);
	int sum = 0;
	fo(i, n) {
		if (((i + 1) % 3) != 0 && ((i + 1) % 5) != 0) {
			sum += i + 1;
		}
	}
	cout << sum << endl;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n; cin>>n;
  vector<ll> c(3);
  cin>>c[0]>>c[1]>>c[2];
  vector<string> s(n);
  rep(i, n)cin>>s[i];

  map<string, pi>m;
  m["AB"] = {0,1};
  m["AC"] = {0,2};
  m["BC"] = {1,2};

  if(c[0]+c[1]+c[2]==0) { cout<<"No"<<endl; return 0; }

  if(c[0]+c[1]+c[2]==1) {
    vector<char> result;

  for(auto cs:s){
    int l = m[cs].first;
    int r = m[cs].second;
    if(c[l]>c[r]){
      c[r]++; c[l]--; result.push_back("ABC"[r]);
    }else{
      c[l]++; c[r]--; result.push_back("ABC"[l]);
    }
    if(c[0]<0 || c[1]<0 || c[2]<0) { cout<<"No"<<endl; return 0; }
  }
  cout<<"Yes"<<endl;
  for(auto cs: result)cout<<cs<<endl;
  return 0;

    return 0;
  }

  vector<char> result;
  rep(i, n){
    auto cs = s[i];
    int l = m[cs].first;
    int r = m[cs].second;

    if(c[l]>c[r]){
      c[l]--;c[r]++;
      result.push_back("ABC"[r]);
    }else if(c[r]>c[l]){
      c[r]--;c[l]++;
      result.push_back("ABC"[l]);
    }else{
      if(i<n-1 && (m[s[i+1]].first == l || m[s[i+1]].second == l) ){
        c[r]--;c[l]++;
        result.push_back("ABC"[l]);
      }else{
        c[l]--;c[r]++;
        result.push_back("ABC"[r]);
      }
    }
    if(c[0]<0 || c[1]<0 || c[2]<0) { cout<<"No"<<endl; return 0; }
  }

  cout<<"Yes"<<endl;
  for(auto cs: result)cout<<cs<<endl;

  return 0;
}


Measured memory_bytes: 6728
N,W=map(int,input().split())
w=[0]*N
v=[0]*N
for i in range(N):
    w[i],v[i]=map(int,input().split())
    
dp=[[0 for _ in range(N+1) ] for _ in range(W+1)]

for i in range(1,N+1):    #i番目の荷物
    for j in range(1,W+1):   #上限の重さ
        if j>=w[i-1]:
            dp[j][i]=max(dp[j-w[i-1]][i-1]+v[i-1],dp[j][i-1])
        else:
            dp[j][i]=dp[j][i-1]
            
print(dp[-1][-1])

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

int main(){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(a>=k){
        cout<<k<<endl;
    }
    else if(a+b>=k){
        cout<<a<<endl;
    }
    else{
        cout<<a-(k-(a+b))<<endl;
    }
}

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

using namespace std;

const int mod = 1e9 + 7;

const int MAX = 5100000;
const int MOD = 1000000007;

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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){
	long long N,M;
	cin >> N >> M;
	COMinit();
	//まずMを素因数分解する
	vector<int> prime_factor;
	long long X = M;
	for(long long i=2;i*i<=X;i++){
		int cnt = 0;
		if(M%i==0){
			long long right = M/i;
			while(M%i==0 && M > 0){
				cnt++;
				M/=i;
			}
			prime_factor.push_back(cnt);
		}
	}
	if(M>1)prime_factor.push_back(1);
	long long ans = 1;
	//次に各素因数の右上に着目して
	//COM(N-1+b,b);
	for(auto b:prime_factor){
		ans *= COM(N-1+b,b);
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 119808
# -*- coding:utf-8 -*-

def solve():
    import sys
    import heapq

    N = int(sys.stdin.readline())
    graph = []
    for _ in range(N):
        _in = list(map(int, sys.stdin.readline().split()))
        if len(_in) == 2:
            graph.append([])
            continue
        u, k, Vs = _in[0], _in[1], _in[2:]
        As = []
        for v in Vs:
            As.append(v-1)
        graph.append(As)

    dist = [float("inf") for _ in range(N)]
    dist[0] = 0
    que = []
    heapq.heappush(que, (0, 0))  # (頂点番号, 最短距離の候補)
    while que:
        u, d = heapq.heappop(que)
        if dist[u] < d: continue

        for v in graph[u]:
            if dist[v] > dist[u]+1:
                dist[v] = dist[u]+1
                heapq.heappush(que, (v, dist[v]))

    for i in range(N):
        d = -1 if dist[i]==float("inf") else dist[i]
        print(i+1, d)


if __name__ == "__main__":
    solve()



Measured memory_bytes: 5704
#include<bits/stdc++.h>
using namespace std;
#define h first
#define w second
vector<pair<bool,pair<int,int> > >v;
int n,m,p,q,r,i;
void Vp(bool a,int b,int c){v.push_back(make_pair(a,make_pair(b,c)));}
int main(){
	while(cin>>n&&n){
	cin>>m>>p>>q>>r;v.clear();
	Vp(1,1,r);Vp(0,r+1,n);
	while(m--){
		int x,y;cin>>x>>y;
		for(i=0;i<v.size();i++){
			int a=v[i].w.h,b=v[i].w.w;bool c=v[i].h;
			if(a<=x&&x<b){
				Vp(c,x+1,b);
				b=x;
			}
			if(a<=y&&y<b){
				Vp(c,y+1,b);
				b=y;
			}
			if(0<a&&b<=x)a+=n-x,b+=n-x;
			else if(x<a&&b<=y)a+=n-x-y,b+=n-x-y;
			else if(y<a&&b<=n)a-=y,b-=y;
			v[i].w.h=a,v[i].w.w=b;
		}
	}
	int ans=0;
	for(i=0;i<v.size();i++){
		if(v[i].h)ans+=max(0,1+min(v[i].w.w,q)-max(v[i].w.h,p));
	}
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3164
#include <stdio.h>

int main(void)
{
    int sanka, hyouji;

    scanf("%d", &sanka);     scanf("%d", &hyouji);

    if (sanka >= 10)
        printf("%d", hyouji);
    else
        printf("%d", hyouji + 100*(10 - sanka));

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1e18;


ll dp[405][405];
vector<ll> s(405);

ll dfs(int l, int r){
  if (dp[l][r]!=-1)return dp[l][r];
  ll now=INF;
  for(int i=l;i<=r-1;i++){
      now=min(now,dfs(l,i)+dfs(i+1,r));
  }
  dp[l][r]=now+s[r+1]-s[l];
//  cout<<dp[l][r]<<"l"<<l<<"r"<<r<<endl;
  return dp[l][r];
}


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

  rep(i,405)rep(j,405)dp[i][j]=-1;
rep(i,n)dp[i][i]=0;

cout<<dfs(0,n-1);



}


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

void print_vec(vector<int> vec) {
  cout << "[";
  for (int i = 0; i < vec.size(); i++) {
    if (i) {
      cout << ", ";
    }
    cout << vec.at(i);
  }
  cout << "]...size: " << vec.size() << endl;
}

int main() {
  char str1[101], str2[101];
  scanf("%s", str1);
  scanf("%s", str2);

  char str3[202];
  strcpy(str3, str1);
  strcat(str3, str1);

  if (strstr(str3, str2) == NULL) {
    printf("No\n");
  } else {
    printf("Yes\n");
  }
}



Measured memory_bytes: 3168
let n = stdin.ReadLine() |> int
let abc =
    [|1..n|]
    |> Array.map (fun _ -> stdin.ReadLine().Split() |> Array.map int)

abc
|> Array.scan (fun [|la;lb;lc|] [|a;b;c|] -> [|a+max lb lc;b+max lc la;c+max la lb|]) [|0;0;0|]
|> fun x -> x.[n] |> Array.max
|> stdout.WriteLine

Measured memory_bytes: 50484
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <sstream>
#include <iostream>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
using namespace std;
//https://codeforces.com/contest/1228/problems
//https://codeforces.com/contest/1228/submit

int main() {
    int a,b,c,d;
    cin >> a >>b >>c >> d;
    if(a < c){
        a = c;
    }
    if(b > d){
        b = d;
    }
    if(a > b){
        puts("0");
    }else{
        p(b-a) pn
    }

    return 0;
}
/*

2
3 1 2
4 1 10


*/



Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1e9+7
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    ll len = s.size() - 1;
    while (1){
        if (len < 4)
            break;
        if (s.substr(len - 4, 5) == "dream" || s.substr(len - 4, 5) == "erase"){
            len -= 5;
        }else if (s.substr(len - 5, 6) == "eraser"){
            len -= 6;
        }else if (s.substr(len - 6, 7) == "dreamer"){
            len -= 7;
        }else{
            cout << "NO" << endl;
            return 0;
        }
	}
	cout << "YES"<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int N = 100001;
int n;
int arr[16][16];
ll cost[(1 << 16)];
int LG[(1 << 16) + 1];
ll dp[1<<16];
ll solve(int msk){
  if(msk == (1 << n) - 1)
    return 0;
  int rem = ~msk & ((1 << n) - 1);
  ll &res = dp[msk];
  if(res != -1)
    return res;
  res = -1e9;
  for(int x = rem;x;x = (x - 1) & rem)
    res = max(res, solve(msk | x) + cost[x]);
  return res;
}

string to_bin(int x){
  string res;
  for(int i = 0;i < n;i++){
    res += (x&1) + '0';
    x /= 2;
  }
  reverse(res.begin(), res.end());
  return res;
}
int main()
{
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  for(int i = 0;i < 16;i++)
    LG[(1 << i)] = i;
  cin >> n;
  for(int i = 0;i < n;i++)
    for(int j = 0;j < n;j++)
      cin >> arr[i][j];
  for(int i = 0;i < (1 << n);i++){
    vector<int> v;
    int x = i;
    while(x){
      v.push_back(LG[x & -x]);
//      cout << (x & -x) << endl;
      x &= x - 1;
    }
    for(int j = 0;j < v.size();j++){
      for(int k = 0;k < j;k++){
        cost[i] += arr[v[j]][v[k]];
      }
    }
//    cout << i << ' ' << to_bin(i) << ' ' << cost[i] << endl;
  }

  memset(dp, -1, sizeof(dp));
  cout << solve(0);
  return 0;
}



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

using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b!=c){cout<<"Yes";return 0;}
	if(a==c&&a!=b){cout<<"Yes";return 0;}
	if(b==c&&a!=b){cout<<"Yes";return 0;}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     string str;
     ll cnt=0;
     bool arr[30];
     cin>>str;
     mem(arr,0);
     for(int i=0;i<str.size();i++)
     {
         arr[str[i]-'a']=1;
     }
     char i;
     for(i='a';i<='z';i++)
     {
         if(arr[i-'a']==0)
         {
             cnt=10;
             break;
         }
     }
     if(cnt==10)
        cout<<i<<endl;
     else
        cout<<"None"<<endl;
}



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

int n;

int main(){
  
  cin >> n;
  vector<long long> a(n);
  long long ans = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  int l = 0, r = 0;
  long long s = a[0], x = a[0];
  while(l < n){
    if(s == x){
      
      if(r < n - 1){
        r++; s+=a[r]; x^=a[r];
      }else{
        ans+=r - l + 1;
        s -= a[l]; x^=a[l];
        l++;
      }
      
    }else{
      ans += r-l;
      s-=a[l]; x^=a[l];
      l++;
    }
  }
  
  cout << ans << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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);}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	ll n;cin>>n;
	ll ans=1;
	for(ll i=1;i<=n;++i){
		ans*=i;
		ans%=MOD;
	}
	cout<<ans%MOD<<endl;
}

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

vector <string> v;
int dp[100001][4][4][4];

int solve(int n,int a,int b,int c)
{
	if(a<0 || b<0 || c<0)
	{
		return 0;
	}
	if(dp[n][a][b][c]!=-1)
	{
		return dp[n][a][b][c];
	}
	if(n == v.size())
	{
		dp[n][a][b][c] = 1;
		return dp[n][a][b][c];
	}
	if(v[n]=="AB")
	{
		if(solve(n+1,a+1,b-1,c)==1 || solve(n+1,a-1,b+1,c)==1)
		{
			dp[n][a][b][c] = 1;
		}
		else
		{
			dp[n][a][b][c] = 0;
		}
	}
	else if(v[n]=="AC")
	{
		if(solve(n+1,a+1,b,c-1)==1 || solve(n+1,a-1,b,c+1)==1)
		{
			dp[n][a][b][c] = 1;
		}
		else
		{
			dp[n][a][b][c] = 0;
		}
	}
	else
	{
		if(solve(n+1,a,b-1,c+1)==1 || solve(n+1,a,b+1,c-1)==1)
		{
			dp[n][a][b][c] = 1;
		}
		else
		{
			dp[n][a][b][c] = 0;
		}
	}
	return dp[n][a][b][c];
}
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n,a,b,c;
	string s;

	cin >> n >> a >> b >> c;
	for(int i=0;i<n;i++)
	{
		cin >> s;
		v.push_back(s);
	}

	a = min(a,3);
	b = min(b,3);
	c = min(c,3);
	memset(dp,-1,sizeof(dp));
	if(solve(0,a,b,c)==1)
	{
		cout << "Yes" << '\n';
		int A = a;
		int B = b;
		int C = c;
		for(int i=0;i<n;i++)
		{
			if(v[i]=="AB")
			{
				if(dp[i+1][A+1][B-1][C]==1)
				{
					cout << "A" << '\n';
					A+=1;
					B-=1;
				}
				else if(dp[i+1][A-1][B+1][C]==1)
				{
					cout << "B" << '\n';
					A-=1;
					B+=1;
				}
			}
			else if(v[i]=="AC")
			{
				if(dp[i+1][A+1][B][C-1]==1)
				{
					cout << "A" << '\n';
					A+=1;
					C-=1;
				}
				else if(dp[i+1][A-1][B][C+1]==1)
				{
					cout << "C" << '\n';
					A-=1;
					C+=1;
				}
			}
			else
			{
				if(dp[i+1][A][B-1][C+1]==1)
				{
					cout << "C" << '\n';
					C+=1;
					B-=1;
				}
				else if(dp[i+1][A][B+1][C-1]==1)
				{
					cout << "B" << '\n';
					C-=1;
					B+=1;
				}
			}
		}
	}
	else
	{
		cout << "No" << '\n';
	}
	return 0;	
}


Measured memory_bytes: 40936
n, k = map(int, input().split())
s = input()
ans = []

for i in range(n):
  if i+1 == k:
    if s[i] == 'A':
      ans.append('a')
    elif s[i] == 'B':
      ans.append('b')
    elif s[i] == 'C':
      ans.append('c')
  else:
    if s[i] == 'A':
      ans.append('A')
    elif s[i] == 'B':
      ans.append('B')
    elif s[i] == 'C':
      ans.append('C')
    
      
print(''.join(ans))

Measured memory_bytes: 3064
n, m=[int(i) for i in input().split()]
h =[int(i) for i in input().split()]

l = []
for i in range(m):
  a, b = [int(j) for j in input().split()]
  if h[a-1] == h[b-1]:
    l.append(a-1)
    l.append(b-1)
  elif h[a-1] < h[b-1]:
    l.append(a-1)
  else:
    l.append(b-1)
    
print(n-len(set(l)))

Measured memory_bytes: 20108
//TINY_OUNCE911666
// You are not prepared!

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

int n, m;
bool check;

int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	cin >> n >> m;
	
	vector<int> pos(m);
	vector <char> val(m);
	
	for (int i = 0; i < m; ++i) {
		cin >> pos[i] >> val[i];
		pos[i]--;
	}
	
	for (int i = 0; i <= 999; ++i) {
		string str = to_string(i);
		
		if (n == (int) str.size()) {
			check = 1;
			for (int j = 0; j < m; ++j) {
				if (str[pos[j]] == val[j]) continue;
				else {
					check = 0;
					break;
				}
			}
			
			if (check) {
				cout << str;
				return 0;
			}
		}
		
	}
	cout << -1;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int top,S[100];

void push(int x){
  top++;
  S[top] = x;
}

int pop(void){
  top--;
  return S[top+1];
}


int main(void){

  int a,b;
  top = 0;
  char s[100];
  
  while(scanf("%s", s) != EOF){
  
    if(s[0] == '+'){
      a = pop();
      b = pop();
      push(a + b);
    }else if(s[0] == '-'){
      a = pop();
      b = pop();
      push(b - a);
    }else if(s[0] == '*'){
      a = pop();
      b = pop();
      push(a * b);
    }else{
      push(atoi(s));
    }
  }
  printf("%d\n",pop());
  
  return 0;
}



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

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int ans = 0;
  int N; cin>>N;
  vector<int> a(N+2,0);
  REP(i,N) cin>>a[i+1];
  for(int h = 1; h <= 100; h++) {
    bool in = false;
    for(int i =	0; i < a.size(); i++) {
      if(in == false &&	a[i] >=	h) {
	in = true;
      } else if(in == true && a[i] < h) {
	in = false;
	ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define re(i,n) for(ll i=0;i<(n);++i)
#define itn int
#define ocut cout
#define ouct cout
#define outc cout

int main(){
    int n,k,s;
    cin >> n >> k >> s;
    re(i,n){
        if(i<k){
            cout << s << " ";
        }
        else{
            if(s==1000000000){
                cout << 1 << " ";
            }
            else{
                cout << s+1 << " ";
            }
        }
    }
}


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

int main()
{
    int n,i,j,t1,cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&t1);
        if(t1%2)
            cnt++;
    }
    if(cnt%2)
        printf("NO\n");
    else
        printf("YES\n");
    return 0;
}


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



int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int r=min(b,d);
    int l=max(a,c);
    if(r-l>0) cout << r-l << endl;
    else cout << 0 << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int A, B; scanf("%d %d", &A, &B);
  int ans = 0;
  for (int i = A; i <= B; ++i) {
    string s = to_string(i);
    string t = s;
    reverse(t.begin(), t.end());
    if (s == t) { ++ans; }
  }
  printf("%d\n", ans);
  return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int h,w;
    cin >> h >> w;
    vector<vector<string>> s(h,vector<string>(w));
    rep(i,0,h) rep(j,0,w) cin >> s[i][j];
    rep(i,0,h){
        rep(j,0,w){
            if(s[i][j]=="snuke"){
                cout << char('A'+j) << i+1 << endl;
                return;
            }
        }
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


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

int64_t INF=(int64_t)pow(10,15);

int main(){
  int N,M;
  cin>>N>>M;
  vector<vector<int64_t>> x(3,vector<int64_t>(N));
  for(int i=0;i<N;++i) cin>>x[0][i]>>x[1][i]>>x[2][i];


  int64_t ans=-INF;
  for(int tmp=0;tmp<(1<<3);++tmp){
    bitset<3> s(tmp);
    vector<int64_t> y(N,0);
    int64_t sum=0;
    for(int i=0;i<N;++i){
      for(int j=0;j<3;++j){
        if(s.test(j)) y[i] -= x[j][i];
        else y[i] += x[j][i];
      }
    }
    sort(y.begin(),y.end(),greater<int64_t>());
    for(int i=0;i<M;++i) sum += y[i];

    ans=max(ans,sum);
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
b,c= map(int, input().split())
a=[]
while b>0:
    s=int(input())
    a.append(s)
    b=b-1
a.sort()
for i in a:
    c=c-i
re=len(a)
for i in a:
    if c>i:
        re=re+int(c/i)
        c=c-int(c/i)*i
print(re)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

void solve()
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	int t = 0;
	while (true)
	{
		if (a == 0)
		{
			cout << "No" << ln;
			return;
		}
		if (c == 0)
		{
			cout << "Yes" << ln;
			return;
		}
		if (t == 0)
			c -= min(c, b);
		else
			a -= min(a, d);
		t = 1 - t;
	}
	return;
}

int main()
{
	FASTIO;
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve();
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 3648
import sys
readline = sys.stdin.readline

N, M, V, P = map(int, readline().split())
A = list(map(int, readline().split()))

A.sort(reverse = True)


ok = P-1
ng = N

while abs(ok-ng) > 1:
    med = (ok+ng)//2
    R = A[med] + M
    J = max(0, V - (N-med))*M
    res = 0
    for i in range(P-1):
        res += M
    for i in range(P-1, med):
        if R-A[i] < 0:
            res = -1
            break
        res += R-A[i]
    if res >= J:
        ok = med
    else:
        ng = med
print(ok+1)

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


int main(){
    int n, l;

    cin >> n;
    cin >> l;
    int tmp = abs(l);
    int tmpi = 1;
    for(int i = 2;i <=n; i++){
        if(abs(l+i-1) < tmp){
            tmp = abs(l+i-1);
            tmpi = i;
        }
    }
    int ans = 0;
    for(int i = 1;i <=n; i++){
        ans = ans+l+i-1;
    }
    ans = ans -l-tmpi+1;
    cout << ans <<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
using namespace std;

int main(){
    int n,k; cin >> n >> k;
    string s; cin >> s;
    vector<int> left,right;
    bool hav=false;
    int memo;
    if(s[0]=='0') left.push_back(1);
    rep(i,n){
        if(s[i]=='1' && hav==false){
            memo=i;
            hav=true;
        } 
        if(s[i]=='0' && hav==true){
            left.push_back(memo+1);
            hav=false;
        }
    }
    hav=false;
    if(s[n-1]=='0') right.push_back(n);
    for(int i=n-1; i>=0; i--){
        if(s[i]=='1' && hav==false){
            memo=i;
            hav=true;
        } 
        if(s[i]=='0' && hav==true){
            right.push_back(memo+1);
            hav=false;
        }
    }
    reverse(all(right));
    //rep(i,right.size()) cout << left[i] << ' ' << right[i] << endl;
    if(left.size()<=k){
        cout << n << endl;
        return 0;
    }
    int ans=0;
    rep(i,right.size()-k+1){
        ans=max(ans,right[i+k-1]-left[i]+1);
    }
    cout << ans << endl;
return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> ii;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
const int INF=2012345678;
const ll LLINF=4012345678012345678LL;
const ll MOD=1000000007;
const long double PI=3.1415926535;
const long double EPS=1e-9;
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll expo(ll b,ll p,ll m){ll res=1; while(p){if(p&1)res=(res*b)%m; b=(b*b)%m; p>>=1;} return res;}
inline ll modinv(ll a,ll m){return expo(a,m-2,m);}


int main(){
	int n;
	scanf("%d",&n);
	int x=n%10;
	if(x==0||x==1||x==6||x==8)printf("pon");
	else if(x==3)printf("bon");
	else printf("hon");
}


Measured memory_bytes: 3824
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795


struct cc_t
{
	vi cc;
	cc_t(){cc.resize(26);}
};


template<typename X>
struct segtree_t
{
	int m_n;
	int m_base;
	std::vector<X> m_t;
	segtree_t(int n) : m_n(n)
	{
		for(m_base=1;m_base<=n;m_base*=2)
			;

		m_t.resize(m_base*2);
	}

	void get_i(int idx, vi&ret)
	{
		if(idx<=0) return;
		if(idx&1)
		{
			const auto&w=m_t[idx-1];
			for(int i=0;i<26;i++)
			{
				ret[i]+=w.cc[i];
			}
		}
		get_i(idx/2, ret);
	}

	vi get(int idx)
	{
		auto&w=m_t[m_base+idx];
		vi ret=w.cc;
		get_i(m_base+idx, ret);
		return ret;
	}

	void incdec_i(int idx, int cinc, int cdec)
	{
		if(idx<=0) return;
		auto&w=m_t[idx];
		w.cc[cinc]++;
		if(cdec>=0) w.cc[cdec]--;
		incdec_i(idx/2, cinc, cdec);
	}

	void incdec(int idx, int cinc, int cdec)
	{
		incdec_i(m_base+idx, cinc, cdec);
	}

};


int main(void)
{
	int n, q;
	char s[500000+2];
	while(scanf("%d\n%500000[a-z]%d", &n, s, &q)==3)
	{
		int l=strlen(s);
		segtree_t<cc_t> st(l);

		for(int i=0;i<l;i++)
		{
			st.incdec(i, s[i]-'a', -1);
		}

		for(int i=0;i<q;i++)
		{
			int t;
			scanf("%d", &t);
			if(t==1)
			{
				int x;
				char c;
				scanf("%d %c", &x, &c);
				st.incdec(x-1, c-'a', s[x-1]-'a');
				s[x-1]=c;
			}
			else
			{
				int l, r;
				scanf("%d%d", &l, &r);
				auto rc=st.get(r-1);
				vi lc(26);
				if(l>1) lc=st.get(l-2);

				int ans=0;
				for(int i=0;i<26;i++)
				{
					if(rc[i]-lc[i]) ans++;
				}
				printf("%d\n", ans);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 140160
n, m = map(int, input().split())
ab = [list(map(int,input().split())) for i in range(n)]
cd = [list(map(int,input().split())) for i in range(m)]

def manhattan(place, target):
	return abs(target[0] - place[0]) + abs(target[1] - place[1])
ans = [0] * n
for i in range(n):
	dmin = 10**9
	for j in range(m):
		d = manhattan(ab[i],cd[j])
		if dmin > d:
			dmin = d
			ans[i] = j

for i in range(n):
	print(ans[i]+1)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define sqr(x) ((x)*(x))
 
using namespace std;
const double eps = 1e-7;
const int INF = (int)1e9 + 7;
const long long linf = (long long)1e16 + 7;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const int MAXN =(int)1e5 + 7;
 
int main() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    ll up = 0, low = INF;
    ll curu, curd;
    for (ll i = 0; i * a * 100 <= f; ++i)
        for (ll j = 0; (j * b + i * a) * 100 <= f; ++j) {
            for (ll k1 = 0; k1 * c <= (i * a + j * b) * e && k1 * c <= (f - 100 * i * a - 100 * j * b); ++k1)
                for (ll k2 = 0; (k2 * d + k1 * c) <= (i * a + j * b) * e && k2 * d <= (f - 100 * i * a - 100 * j * b - k1 * c); ++k2) {
                    curu = c * k1 + d * k2;
                    curd = 100 * (a * i + b * j) + curu;
                    if (curu * low > curd * up && curd != 0) {
                        up = curu;
                        low = curd;
                    }
                }
        }
    if (low == INF) {
        low = 100 * a;
        up = 0;
}
    cout << low << " " << up;
    return 0;
}

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

int m,n;
vector<int> a;

bool ok(int x){
    int k = 0;
    rep(i,m){
        int t = 0;
        while(k != n){
            if(t + a[k] > x) break;
            t += a[k];
            k++;
        }
    }
    return k == n;
}

int main(){
    while(cin >> m >> n && m){
        a.resize(n);
        rep(i,n) cin >> a[i];
        int l = 0, r = 1e8;
        while(l+1 < r){
            int m = (l+r)/2;
            if(ok(m)) r = m; else l = m;
        }
        cout << r << endl;
    }
}

Measured memory_bytes: 1216
//============================================================================
// Name        : abc141_a.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : https://atcoder.jp/contests/abc141/tasks/abc141_a
//============================================================================

#include <iostream>
using namespace std;

int main() {
	string weather;
	cin >> weather;
	if (weather == "Sunny") {
		cout << "Cloudy" << endl;
	} else if (weather == "Cloudy") {
		cout << "Rainy" << endl;
	} else {
		cout << "Sunny" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
 
		long sum = 0;
		int i = 0;
 
		for (int j = i + 1; j < n; j++) {
			if (a[i] >= a[j]) {
				sum += a[i] - a[j];
			} else {
				i = j;
			}
		}
		
		
		
		System.out.println(sum);
		sc.close();
	
	}
}

Measured memory_bytes: 63228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define ff first
#define ss second
#define debug(x) cerr<<#x<<" : "<<x<<endl;
#define dbg2(x, y) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl;
#define dbg3(x, y, z) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl;
#define debugv(v) cerr <<endl; for(int i = 0; i<(int)(v.size()); i++){ cerr<<#v<<"["<<i<<"] = "<<v[i]<<endl;} cerr<<endl;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define MOD 1000000007
#define BIGMOD 32361122672259149LL

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//functions - find_by_order(index) - returns iterator, order_of_key(key) - number of values less than key
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll md(ll a) {
	return ((a%MOD)+MOD)%MOD;
}

ll po(ll a, ll b) {
	if (b==0) return 1LL;
	ll x = po(a, b>>1);
	x = md(x*x);
	if (b&1) x = md(x*a);
	return x;
}

void solve() {
	string s, t;
	cin>>s>>t;
	int n = (int)s.length();
	for (int i=0; i<n; i++) {
		if (s[i]!=t[i]) {
			cout << "No\n";
			return;
		}
	}
	cout << "Yes\n";
}	

int main() {
	#ifdef LOCAL
	freopen("i.txt", "r", stdin);
	freopen("o.txt", "w", stdout);
	#endif

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


	int num_tests = 1;
	// scanf("%d ", &num_tests);
	// cin>>num_tests;

	for (int tc=1; tc<=num_tests; tc++) {
		// printf("Case #%d: ", tc);
		// cout << "Case #" << tc << ": ";
		solve();
	}
	printclock
	return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A=0;
    int B=0;
    int C=0;
    cin >> A>>B>>C;
    int ans=0;
    if(A==B)ans=C;
    if(A==C)ans=B;
    if(B==C)ans=A;
    cout<<ans<<endl;
}

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

int main(){
    int a,b,c;
    cin >> a  >> b >> c;
    
    
    int A,B,C;
    for(int i=0; ;i++){
        if(a % 2 == 1 || b % 2 == 1 || c % 2 == 1){
            cout << i << endl;
            return 0;}
        if(a == b && b == c){
        cout << -1 << endl;
        return 0;
        }
        
        
        A=a;
        B=b;
        C=c;
        a = B/2 + C/2;
        b = A/2 + C/2;
        c = A/2 + B/2;
    }
}


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

const int mod=1e9+7;
int fact[100005];
void cal()
{
    fact[0]=1;
    fact[1]=1;
    for(int i=2;i<=100000;i++)
    fact[i]=(fact[i-1]*i)%mod;
}

int32_t main()
{
    cal();
     int n,m;
      cin>>n>>m;
      if(abs(m-n)>1)
      cout<<0<<endl;
    else  if(n!=m)
      cout<<((fact[n]*fact[m])%mod)<<endl;
     else 
     cout<<((2*(fact[n]*fact[m])%mod)%mod)<<endl;
}


Measured memory_bytes: 4348
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;

#define int long long

signed main(){
  int h[20];
  int N;
  int nh = 0;
  cin >> N;
  int ans = 0;
  LOOP(i,N){
    cin >> h[i];
  }
  LOOP(i,N){
    if(h[i]>=nh){
      nh = h[i];
      ans++;
    }
  }
  cout << ans << endl;
}


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

#define rp(i, k, n) for (ll i = k; i < n; i++)
#define ll  long long

ll mod = 1e9 + 7;

ll ED (ll a, ll b) {
    ll c = max(a,b);
    ll d = min(a,b);
    ll e = 0;
    while (c % d != 0) {
        e = d;
        d = c%d;
        c = e;
    }
    return a * b / d;
}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = b - a + 1;
    ll e = ED(c, d);
    ans -= (b/c) - ((a-1)/c);
    ans -= (b/d) - ((a-1)/d);
    ans += (b/e) - ((a-1)/e);
    cout << ans;
    return 0;
}

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

 int main()
 {
 	int n,m;
 	cin >> m>>n;
 	if(m>=n){
 		cout << 0 << endl;
 		return 0;
 	}
 	int x[n];
 	for (int i = 0; i < n; i++){
 		cin >> x[i];
 	}
 	sort(x,x+n);
 	int y[n-1];
 	for (int i = 0; i < n-1; i++){
 		y[i]=x[i+1]-x[i];
 	}
 	int ans=x[n-1]-x[0];
 	sort(y,y+n-1);
 	for (int i = 0; i < m-1; i++){
 		ans=ans-y[n-2-i];
 	}
 	cout << ans << endl;
 }

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

int main() {
	int n,h;
	h = 0;
	cin >> n;
	int n_cn = n;
	for (int i = 0; i < 8; i++)
	{
		h += n_cn % 10;
		n_cn /= 10;
	}
	
	if (!(n % h)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main()
{
    string s; cin >> s;
    ll now = 0;
    ll ans = 0;
    rep(i, ll(s.size())){
        if (s[i] == 'W'){
            ans += i-now;
            now++;
        }
    }
    cout << ans << endl;

}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    long long ans = 0, b = 0;
    for(int i = 1; i <= n; i++){
        long long a;
        cin >> a;
        if(b+1 < a || (i == 1 && a > 0)){
            ans = -1;
            break;
        }
        if(b+1 == a) ans++;
        else ans += a;
        b = a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;
using System.Timers;

static class MainClass
{
    public static void Main(string[] args)
    {
        var n = Console.ReadLine();
        Console.WriteLine(n.Replace('1','x').Replace('9','z').Replace('x','9').Replace('z','1'));

       }


    //public class Edge
    //{
    //    public int From;
    //    public int To;
    //    public int Cost;
    //}

    //public static List<KeyValuePair<int, int>> GetShortestPathes(int s, IEnumerable<Edge> edges, int vertices)
    //{
    //    var ls = new KeyValuePair<int, int>[vertices];

    //    return ls.ToList();
    //}


    #region ライブラリ

    #region 文字列処理

    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();

    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    #endregion
    #region DeepClone
    public static T DeepClone<T>(this T src)
    {
        using (var memoryStream = new MemoryStream())
        {
            var binaryFormatter
              = new BinaryFormatter();
            binaryFormatter.Serialize(memoryStream, src);
            memoryStream.Seek(0, SeekOrigin.Begin);
            return (T)binaryFormatter.Deserialize(memoryStream);
        }
    }
    #endregion

    public static int Gcd(int a, int b)
    {
        if (b == 0)
            return a;
        return Gcd(b, a % b);
    }
    public static BigInteger Gcd(BigInteger a, BigInteger b)
    {
        if (b == 0)
            return a;
        return Gcd(b, a % b);
    }


    public static BigInteger Factorial(int n)
    {
        var dp = new BigInteger[n];
        dp[0] = 1;
        for (int i = 1; i < n; i++)
        {
            dp[i] = dp[i - 1] * (i + 1);
        }
        return dp[n - 1];
    }

    public static List<int> PrimeFactorize(int n)
    {
        var bases = n;
        var num = (int)Math.Pow(n, 0.5);
        var ls = new List<int>();
        for (int i = 2; i <= num; i++)
        {
            if (n % i == 0)
            {
                n = n / i;
                ls.Add(i);
                i--;
                continue;
            }
        }
        var nnn = 1;
        foreach (var item in ls)
        {
            nnn = nnn * item;
        }
        if (nnn != bases)
            ls.Add(n);
        return ls;
    }

    #endregion

}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 1e5+10;

int N;
ll K;
ll A[MAX];
int X[55];

ll f(ll x) {
    ll res = 0;
    REP (i, N) {
        res += (A[i] ^ x);
    }
    return res;
}

ll g(int n) {
    int count = 0;
    REP (i, N) {
        if ((1ll<<n)&A[i]) count++;
    }
    if (count * 2 == N) return 0;
    return (count <= N/2);
}

ll solve() {
    REP (i, 55) X[i] = g(i);
    ll res = 0;
    REPR (i, 55) if (X[i]) {
        if (res + (1ll<<i) <= K) res += (1ll<<i);
    }
    return f(res);
}

int main() {
    cin >> N >> K;
    REP (i, N) cin >> A[i];
    cout << solve() << endl;
}

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

int main(){
  int n; string s;
  cin >> n; cin >> s;
  long long ans = 0;
  vector<pair<long long, long long>> v;
  map<pair<long long, long long>, long long> m;
  for (int k = 0; k < (1 << n); k++) {
    bitset<20> c = k;
    long long a = 0; long long b = 0;
    for (int d = 0; d < n; d++) {
      if (c[d]) {
        a *= 30;
        a += s[d] - 'a' + 1;
      } else {
        b *= 30;
        b += s[d] - 'a' + 1;
      }
    }
    v.push_back({a, b});
  }
  sort(v.begin(), v.end());
  for (int k = 0; k < (1 << n); k++) {
    bitset<20> c = k;
    long long a = 0; long long b = 0;
    for (int d = 0; d < n; d++) {
      if (c[d]) {
        a *= 30;
        a += s[2*n-d-1] - 'a' + 1;
      } else {
        b *= 30;
        b += s[2*n-d-1] - 'a' + 1;
      }
    }
    if (m[make_pair(a, b)] != 0) ans += m[make_pair(a, b)];
    else {
      long long tmp = upper_bound(v.begin(), v.end(), make_pair(a, b)) - lower_bound(v.begin(), v.end(), make_pair(a, b));
      m[make_pair(a, b)] = tmp;
      ans += tmp;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 20716
def smaller(x, y):
	if x < y: return x
	return y

def larger(x, y):
	if x > y: return x
	return y

N, x = map(int, input().split())
A = list(map(int, input().split()))
sum1 = 0
for i in range(0, N):
	sum1 += A[i]
for i in range(1, N-1):
	leftadd = A[i-1] + A[i]
	rightadd = A[i]+ A [i+1]
	left = leftadd - x
	if left < 0: left = 0
	if A[i] < left: left = A[i]
	right = rightadd - x
	if right < 0: right = 0
	if A[i] < right: right = A[i]
	A[i] -= smaller(left, right)
for i in range(1, N-1):
	leftadd = A[i-1] + A[i]
	rightadd = A[i]+ A [i+1]
	left = leftadd - x
	if left < 0: left = 0
	if A[i] < left: left = A[i]
	right = rightadd - x
	if right < 0: right = 0
	if A[i] < right: right = A[i]
	A[i] -= larger(left, right)
if A[0]+A[1] > x:
	A[0] -= smaller(A[0], A[0]+A[1]-x)
	if A[0]+A[1] > x:
		A[1] -= A[0]+A[1]-x
if A[N-2]+A[N-1] > x:
	A[N-1] -= smaller(A[N-1], A[N-2]+A[N-1]-x)
	if A[N-2]+A[N-1] > x:
		A[N-2] -= A[N-2]+A[N-1]-x
sum2 = 0
for i in range(0, N):
	sum2 += A[i]
print(sum1-sum2)

Measured memory_bytes: 63984
#include <stdio.h>

int isleap(int x){
	if((x % 4 == 0) && (x % 100 != 0) || (x % 400 == 0)){
		return 1;
	}else{
		return 0;
	}
}

int main(){
	int i,a,b,flag;

	scanf("%d %d",&a,&b);
	if(a == 0 && b == 0){
		return 0;
	}
	flag = 0;
	for(i = a;i <= b;i++){
		if(isleap(i)){
			flag = 1;
			printf("%d\n",i);
		}
	}
	if(!flag){
		printf("NA\n");
	}

	while(1){
		scanf("%d %d",&a,&b);
		if(a == 0 && b == 0){
			break;
		}
		printf("\n");
		flag = 0;
		for(i = a;i <= b;i++){
			if(isleap(i)){
				flag = 1;
				printf("%d\n",i);
			}
		}
		if(!flag){
			printf("NA\n");
		}
	}

	return 0;
}

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

using namespace std;

#define USE_IOSTREAM \
{\
	ios::sync_with_stdio(false);\
	cin.tie(0);\
	cout.tie(0);\
}

#define pii pair<int, int>
#define mp make_pair

typedef long long ll;



int main()
{
	// USE_IOSTREAM;
	string s1, s, s2;
	cin >> s1 >> s >> s2;
	
	string ans;
	ans.push_back('A');
	ans.push_back(s[0]);
	ans.push_back('C');
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}


int main(){
  ll N;
  cin>>N;
  vector<pll> A(N);
  for(int i=0;i<N;i++){cin>>A[i].F; A[i].S=i;}
  sort(A.begin(),A.end());
  vector<ll> ans(N);
  for(int i=0;i<N;i++){ans[i]=A[i].S+1;}
  cout<<ans<<endl;
  
  
  return 0;
}


Measured memory_bytes: 5468
#include <iostream>
#include <algorithm>
#include <string>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main() {
    int n, k; cin >> n >> k;
    string s = "";
    while (n > 0){
        s += to_string(n % k);
        n /= k;
    }
    cout << s.size() << endl;
    
	return 0;
}


Measured memory_bytes: 384