akhauriyash/Code-Regression huggingface dataset:
H, W = map(int, input().split())

if H % 3 == 0 or W % 3 == 0:
    print(0)
    exit()

cand = []
for i in range(1, H+1):
    s_1 = i*W
    s_2_hor = (H-i)//2*W
    s_3_hor = (H-(i+(H-i)//2))*W
    s_2_ver = (H-i)*(W//2)
    s_3_ver = (H-i)*(W-W//2)
    ans_hor = abs(max(s_1, s_2_hor, s_3_hor) - min(s_1, s_2_hor, s_3_hor))
    ans_ver = abs(max(s_1, s_2_ver, s_3_ver) - min(s_1, s_2_ver, s_3_ver))
    cand.append(ans_hor)
    cand.append(ans_ver)

H, W = W, H
for i in range(1, H+1):
    s_1 = i*W
    s_2_hor = (H-i)//2*W
    s_3_hor = (H-(i+(H-i)//2))*W
    s_2_ver = (H-i)*(W//2)
    s_3_ver = (H-i)*(W-W//2)
    ans_hor = abs(max(s_1, s_2_hor, s_3_hor) - min(s_1, s_2_hor, s_3_hor))
    ans_ver = abs(max(s_1, s_2_ver, s_3_ver) - min(s_1, s_2_ver, s_3_ver))
    cand.append(ans_hor)
    cand.append(ans_ver)


print(min(cand))

Measured memory_bytes: 56760
// Author:: Mohammad Faisal
// BEGINNING WITH THE NAME OF ALMIGHTY GOD ALLAH
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int r,d,n;
  cin >> r >> d >> n;
  //int val;
  for(int i=1;i<=10;i++)
  {
   	cout<<r*n-d<<endl;
    n = r*n-d;
  }
  return 0;
}
  
  
    


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

int main(){
	int n, i;
	char c;
	int x;
	int a[52]={0};
	cin >> n;

	for(i=0; i<n; i++){
		cin >> c >> x;

		if(c=='S'){
			a[x-1]=1;
		}
		else if(c=='H'){
			a[x-1+13]=1;
		}
		else if(c=='C'){
			a[x-1+26]=1;
		}
		else if(c=='D'){
			a[x-1+39]=1;
		}
	}

	for(i=0; i<52; i++){
		if(a[i]==0){
			if(i<13) cout << 'S' << " " << i+1 << endl;
			else if(i<26) cout << 'H' << " " << i-12 << endl;
			else if(i<39) cout << 'C' << " " << i-25 << endl;
			else cout << 'D' << " " << i-38 << endl;

		}
	}
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        int hatipa = 0;

        for (int i = 1; i <= 1250; i++) {
            hatipa = (int) Math.floor(i * 0.08);
            if (hatipa == a) {
                if ((int) Math.floor(i * 0.1) == b) {
                    System.out.println(i);
                    return;
                }
            }
        }
        System.out.println("-1");
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
using namespace std; 
  
int main() 
{ 
  int n,t;
  bool f = false;
  cin>>n;
  t=n;
  vector<vector<int>> v;
  while(t--){
    int n1,n2;
    cin>>n1>>n2;
    v.push_back({n1,n2});
  }
  for(int i =0;i<n;i++){
    int c =0;
  if(v[i][0] == v[i][1]){
    c++;
    while((i+1)<n){
      i++;
      if(v[i][0] == v[i][1]){
        c++;
      }
      else
        break;
    }
  }
    if(c>=3){
    f = true;
    break;
    }
  }
  if(f)
  cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define FOR(i,a,b) for(register int i=(a);i<(b);++i)
#define ROF(i,a,b) for(register int i=(a);i>=(b);--i)
#define pi pair<int,int>
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 200005;
const int maxm = 100;
const int inf = 2147483647;
typedef long long ll;
const double eps = 1e-9;
const long long INF = 9223372036854775807ll;
ll qpow(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c;b>>=1;}return ans;}


int main(){
	int l,r,d;
	scanf("%d%d%d",&l,&r,&d);
	printf("%d\n",r/d-(l-1)/d);
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



ll merge_cnt(vector<int> &a) {
    int n = a.size();
    if (n <= 1) { return 0; }

    ll cnt = 0;
    vector<int> b(a.begin(), a.begin()+n/2);
    vector<int> c(a.begin()+n/2, a.end());

    cnt += merge_cnt(b);
    cnt += merge_cnt(c);

    int ai = 0, bi = 0, ci = 0;
    // merge の処理
    while (ai < n) {
        if ( bi < b.size() && (ci == c.size() || b[bi] <= c[ci]) ) {
            a[ai++] = b[bi++];
        } else {
            cnt += n / 2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}

int main() {
    int n; cin >> n;
    vector<int> a(n); rep(i,n) cin >> a[i];
    cout << merge_cnt(a) << endl;
}


Measured memory_bytes: 5340
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> a(N), b(N), c(M), d(M);
  rep(i,N){
    cin >> a.at(i) >> b.at(i);
  }
  rep(i,M){
    cin >> c.at(i) >> d.at(i);
  }
  rep(i,N){
    int dist = 1e9;
    int index;
    rep(j,M){
      int tmp = abs(a.at(i)-c.at(j))+abs(b.at(i)-d.at(j));
      if(tmp<dist){
        dist = min(dist,tmp);
        index = j+1;
      }
    }
    cout << index << endl;
  }
  return 0;
}

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

int main(){
    string s, t; cin >> s >> t;
    int a, b; cin >> a >> b;
    string u; cin >> u;
    if(u == s) a--;
    else b--;
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100
#define INFTY 100000000
#define WHITE 0
#define BLACK 2
#define GRAY 1

int n, M[MAX][MAX];

int prim(){
    int u,minv;
    int d[MAX],p[MAX],color[MAX];
    
    for(int i=0; i<n; i++){
        d[i]=INFTY;
        p[i]=-1;
        color[i]=WHITE;
    }
    
    d[0]=0;
    
    while (1) {
        minv=INFTY;
        u=-1;
        for(int i=0; i<n; i++){
            if(minv>d[i] && color[i] != BLACK){
                u=i;
                minv=d[i];
            }
        }
        
        if(u==-1) break;
        color[u]=BLACK;
        for(int v=0; v<n; v++){
            if(color[v] != BLACK && M[u][v] != INFTY){
                if(d[v] > M[u][v]){
                    d[v]=M[u][v];
                    p[v]=u;
                    color[v]=GRAY;
          }
            }
        }
    }
    
    int sum =0;
    for(int i=0; i<n; i++){
        if(p[i] != -1) sum+= M[i][p[i]];
    }
    return sum;
}

int main(){
    scanf("%d",&n);
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            int e;
            scanf("%d",&e);
            M[i][j] = (e == -1) ? INFTY:e;
            
        }
    }
    printf("%d\n", prim());
    return 0;
}


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

#define rep(i,n) for(ll i=0;i<n;i++)
#define repm(i,m,n) for(ll i=m;i<n;i++)
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define YesNo(a) (a)?cout<<"Yes"<<endl:cout<<"No"<<endl
#define YESNO(a) (a)?cout<<"YES"<<endl:cout<<"NO"<<endl
#define INF (2e9)
#define PI (acos(-1))
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007

typedef long long ll;

int main(){
  int n; cin >> n;
  double d; cin >> d;

  vector<double> x(n), y(n);
  rep(i,n){
    cin >> x[i];
    cin >> y[i];
  }

  int ans = 0;
  rep(i,n){
    double distance = sqrt(x[i]*x[i] + y[i]*y[i]);
    if(distance <= d) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 6492
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
using R = double;

int main() {

	int n;
	string s;

	cin >> n >> s;

	int c = 0;
	int d = 0;
	for (int i = 0; i < n; i++) {
		
		if (s[i] == '(') {
			c++;
		}
		else {
			c--;
		}

		d = min(d, c);
	}

	for (int i = 0; i < abs(d); i++) {
		cout << '(';
	}

	cout << s;

	int m = c -d;

	for (int i = 0; i < m; i++) {
		cout << ')';
	}

	cout << endl;
	return 0;
}

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

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> pn(N);
	for (int i = 0; i < N; i++) {
		cin >> pn[i];
	}
	sort(pn.begin(), pn.end());
	int ans = 0;
	for (int i = 0; i < K; i++) {
		ans += pn[i];
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 3632
// ABC 156-B
// 2020.2.23 bal4u

#include <stdio.h>

int X[105];
int main()
{
	int i, P, N, ans;

	scanf("%d", &N);
	for (i = 0; i < N; ++i) scanf("%d", X+i);
	ans = 0x7ffffff;
	for (P = 1; P <= 100; P++) {
		int s = 0; for (i = 0; i < N; ++i) {
			s += (X[i] - P) * (X[i] - P);
		}
		if (s < ans) ans = s;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))


int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	string S;
	cin >> S;
	map<char, vector<int>> m;
	for (size_t i = 0; i < 4; i++)
	{
		m[S[i]].push_back(i);
	}

	if (m[S[0]].size() == 2 && m[S[1]].size() == 2 && m[S[2]].size() == 2 && m[S[3]].size() == 2)
	{
		cout << "Yes" << "\n";
	} else {
		cout << "No" << "\n";
	}



	return 0;
}


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

int main(){
  int n;
  cin>>n;
  int a[110][110] = {};
  for(int i=1;i<=n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v;
      cin>>v;
      a[i][v]=1;
    }
  }

  int d[110];
  for (int i=1;i<=n;i++){
    d[i]=-1;
  }
  queue<int> q;
  d[1]=0;
  q.push(1);
  while(! q.empty()){
    int cur =q.front();
    q.pop();
    for(int i=1;i<=n;i++){
      if(a[cur][i]==1 && d[i]==-1){
	d[i]=d[cur]+1;
	q.push(i);
      }
    }
  }
  for(int i=1;i<=n;i++){
    cout<<i<<" "<<d[i]<<endl;
  }
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 


int main(){
  vec<char> S(3);
  rep(i, 3) cin >> S.at(i);
  
  if(S.at(0) == S.at(1) && S.at(1) == S.at(2)){
    cout << "No";
  }else{
    cout << "Yes";
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
    long i,b=1000000007;
    long a,p=1;
    scanf("%ld",&a);
    for (i=1; i<=a; i++) {
        p=p*i;
        p=p%b;
    }
    printf("%ld",p);
}

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


int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    rep(i, N-2) {
        if (S[i] == 'A') {
            if (S[i+1] == 'B') {
                if (S[i+2] == 'C') ans++;
            }
        }
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ll long long int
#define ld long double
#define el '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < int(n); i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vli vector<pair<ll,int>>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

vector<ll> parent, rak;

void make_set(int f){
    fo(i,f+1)parent.pb(i);
    rak.assign(f+1,1);
}

ll find_set(ll v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

ll union_sets(ll a, ll b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rak[a] < rak[b])
            swap(a, b);
        parent[b] = a;
        rak[a]+=rak[b];
        return (rak[a]-rak[b])*(rak[b]);
    }
    return 0;
}

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}
ll extend_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll ans =extend_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-(a/b)*y1;

    return ans;
}
ll inverse(ll a,ll m){
    ll x,y;
    extend_gcd(m,a,x,y);
    y%=m;
    y+=m;
    y%=m;
    return y;
}

unsigned long long fhash( vector<ll> p, ll len ) {
    unsigned long long h = 0xcbf29ce484222325ULL;//cout<<0x100000001b3ULL<<endl;
    for ( ll i = 0; i < len; i++ )
      h = ( h ^ p[i] ) * 0x100000001b3ULL;//cout<<h<<endl;

   return h;
}

/*const int N = 1000001;
int lp[N+1];
vector<int> pr;
void s(){
for (int i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }
}*/


ll kv;
ll t,n,x,y,h,k,z,p,q,w;
string s,s1,s2;
//vvl v;
//vl vis,d;


int main() {
    IOS;
    cin>>p>>q>>x;
    h=10;
    while(h--){
        x=p*x-q;
        cout<<x<<el;
    }
    return 0;
}


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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
#define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define dbg(x)                       cout << #x << " is " << x << endl;
#define endl                           '\n'

using namespace std;
ll dp[100002][3],n;
vll v[100002];

ll f(ll i,ll pr)
{
	if(i==n)
		return 0;
	if(dp[i][pr]!=-1)
		return dp[i][pr];
	ll val=0,j;
	rep(j,0,3)
	{
		if(j!=pr) val=max(val,f(i+1,j)+v[i][j]);
	}
	return dp[i][pr]=val;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	ll i,j,m,k,cnt=0,ans=0,t=1;
	cin>>n;
	rep(i,0,n)
	{
		cin>>j>>k>>t;
		v[i].pb(j);
		v[i].pb(k);
		v[i].pb(t);
	}
	rep(i,0,n+1)
	{
		rep(j,0,3) dp[i][j]=-1;
	}
	ans=max(v[0][0]+f(1,0),ans);
	ans=max(ans,v[0][1]+f(1,1));
	ans=max(ans,v[0][2]+f(1,2));
	ret(ans)
	return 0;
}

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

bool dfs(vector<vector<int>> &G, vector<int> &C, int v, int c = 0){
    C[v] = c;
    
    for(auto next_v : G[v]){
        if(C[next_v] != -1){
            if(C[next_v] == c) return false;
            continue;
        }
        if(!dfs(G, C, next_v, 1 - c)) return false;
    }
    return true;
}


int main(){
    ll N, M; cin >> N >> M;
    vector<vector<int>> G(N);
    rep(i, M){
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> C;
    C.assign(N, -1);
    bool isBiGraph = dfs(G, C, 0);
    ll ans;
    if(isBiGraph){
        ll cnt_0 = 0;
        ll cnt_1 = 0;
        rep(i, N){
            if(C[i] == 0) ++cnt_0;
            if(C[i] == 1) ++cnt_1;
        }
        ans = cnt_1 * cnt_0 - M;
    }else{
        ans = N * (N-1) / 2 - M;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9528
A, B, C, X, Y = gets.split.map(&:to_i)
ans = 0
x = X
y = Y
while x > 0 || y > 0
  if x > 0 && y > 0
    if C * 2 < A + B
      ans += C * 2
    else
      ans += A + B
    end
    x -= 1
    y -= 1
  elsif x > 0
    if C * 2 < A
      ans += C * 2
    else
      ans += A
    end
    x -= 1
  else # y > 0
    if C * 2 < B
      ans += C * 2
    else
      ans += B
    end
    y -= 1
  end
end
puts ans


Measured memory_bytes: 1788
#pragma GCC optimize("O3")
        #pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize("unroll-loops")
         
        #include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;
         
        typedef long long ll;
        typedef long double LD;
        #define int ll
        #define double LD
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
         
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;
        const double eps = 1e-9;
         
        mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
       
		signed main()
		{
			string s;
			cin>>s;
			if(s[2]==s[3] && s[4]==s[5])
			cout<<"Yes";
			else
			cout<<"No";
		}

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

using namespace std;

typedef tuple<int, int, int> TP;

int main() {
  int n, m;
  while (cin >> n >> m, n) {
    vector<TP> tsd;
    for (int i = 0; i < m; i++) {
      int t, s, d;
      cin >> t >> s >> d;
      s--, d--;
      tsd.emplace_back(t, s, d);
    }
    sort(tsd.begin(), tsd.end());
    vector<int> u(n, 0);
    u[0] = 1;
    for (int i = 0; i < m; i++) {
      int t, s, d;
      tie(t, s, d) = tsd[i];
      u[d] |= u[s];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      ans += u[i];
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3432
// JavaProgram.cpp
// Author : Priydarshi Singh (@dryairship)
// One cat just leads to another. One bug leads to two others.

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

// I like my types defined.
typedef long long           ll;
typedef pair<int, int>      pii;
typedef pair<ll, ll>        pll;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef vector<pii>         vii;
typedef vector<pll>         vll;
typedef set<int>            si;
typedef map<string, int>    msi;
typedef map<int, int>       mii;

// Traditional science is all about finding "hashtag define"s.
#define fr(i, n)            for(int i=0; i<(n); ++i)
#define frC(i, n, c)        for(int i=0; (i<(n)) && (c); ++i)
#define frA(i, a, n)        for(int i=a; i<=(n); ++i)
#define frD(i, a, n)        for(int i=a; i>=(n); --i)
#define fill(a)             memset(a, 0, sizeof(a))
#define fill1(a)            memset(a, -1, sizeof(a))
#define revsort(a, b)       sort(a, b, greater<int>())
#define ff                  first
#define ss                  second
#define pb                  push_back 
#define dout                if(DEBUGGING) cout
#define dbg                 if(DEBUGGING) 
#define endl                "\n"

// When you realize MOD > INF...
int DEBUGGING    =          0;
const int INF    =          1000000000;
const int MOD    =          1000000007;
const ll LINF    =          1e18;
const double PI  =          3.1415926535897932;
const double EPS =          1e-7;

// I'D SPAM. Hehe.
ll gcdEx                    (ll a, ll b, ll *x, ll *y){if(!a){*x=0;*y=1;return b;} 
ll x1,y1,gcd=gcdEx          (b%a,a,&x1,&y1); *x=y1-(b/a)*x1;*y=x1; return gcd;}
ll modI(ll b, ll m)         {ll x,y;gcdEx(b,m,&x,&y);return (x%m+m)%m;}
ll modD(ll a, ll b)         {return (modI(b,MOD)*(a%MOD))%MOD;}
ll modS(ll a, ll b)         {return ((a%MOD)-(b%MOD)+MOD)%MOD;}
ll modP(ll x, ll y)         {ll r=1; x%=MOD; while(y>0){if(y&1){r=(r*x)%MOD;} y=y>>1; x=(x*x)%MOD;} return r;}
ll modA(ll a, ll b)         {return ((a%MOD)+(b%MOD))%MOD;}
ll modM(ll a, ll b)         {return ((a%MOD)*(b%MOD))%MOD;}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int a[100005];
int dp[100005];

void solve(int TEST_CASE){
    int n, k;
    cin >> n >> k;
    fr(i,n) cin >> a[i];
    fr(i,n) dp[i]=INF;
    dp[0]=0;
    fr(i,n){
        frA(j,1,min(n-1-i,k))
            dp[i+j] = min(dp[i+j], dp[i]+abs(a[i+j]-a[i]));
    }
    cout << dp[n-1];
}

int main(int argc, char* argv[]){
    if(argc==2 && argv[1][1]=='v') DEBUGGING = 1;
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin.exceptions(cin.failbit);
    int nTestCases=1;
    //cin >> nTestCases;
    frA(i,1,nTestCases) solve(i);
    return 0;
}

Measured memory_bytes: 4360
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define gcd __gcd
#define lcm(n, m) n * m / gcd(n, m)
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define ea(i, n) for(auto&& i: n)
#define so(n) sort(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// rtsq ルート, int 2*10^9, __gcd

int main() {
  int A, B, a = 0;
  ci(A, B);
  a += max(A, B);
  if(A > B){
    A--;
  }
  else{
    B--;
  }
  a += max(A, B);
  co(a);
}

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

const int INF = (int)(1e+9) + 9;
int N, K;
vector<int> H;
vector<int> dp;

void input_init(void) {
	cin >> N >> K;
	H.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> H[i];
	dp.resize(N, INF);
}

void solve(void) {
	dp[0] = 0;
	for (int i = 1; i < N; ++i) {
		int min_step = INF;
		for (int j = K; j >= 1; --j) {
			int step = INF;
			if (i - j >= 0)
				step = dp[i - j] + abs(H[i - j] - H[i]);
			min_step = min(step, min_step);
		}
		dp[i] = min(min_step, dp[i]);
	}
}

int main(void) {
	input_init();
	solve();
	cout << dp[N - 1] << '\n';
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

int N, M;

class Color{
public:
    double L, a, b;
    Color(double L, double a, double b): L(L), a(a), b(b){};
};

double dist(Color c1, Color c2){
    return (c1.L-c2.L)*(c1.L-c2.L) + (c1.a-c2.a)*(c1.a-c2.a) + (c1.b-c2.b)*(c1.b-c2.b);
}

void solve(){
    vector<Color> colors;
    for(int i=0; i<N; i++){
        double L, a, b; cin >> L >> a >> b;
        colors.push_back(Color(L, a, b));
    }
    
    double ans = 0;
    
    for(int i=0; i<1<<N; i++){
        vector<int> vec;
        if(__builtin_popcount(i) != M) continue;
        
        for(int j=0; j<N; j++)
            if(i>>j&1)
                vec.push_back(j);
        
        double t = 0;
        for(int j=0; j<M; j++)
            for(int k=j+1; k<M; k++)
                t += dist(colors[vec[j]], colors[vec[k]]);
        ans = max(ans, t);
    }
    
    cout << ans << endl;
    //printf("%.6f\n", ans);
}

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(16);
    
    cin >> N >> M;
    solve();
    
    return 0;
}

Measured memory_bytes: 1320
#include<bits/stdc++.h>
#define MAXN 100005
using namespace std;
long long fa[MAXN],a[MAXN],b[MAXN],cnt[MAXN],ans[MAXN];
long long find1(long long v)
{
    return fa[v]=fa[v]==v?v:find1(fa[v]);
}
void merge1(long long x,long long y)
{
    fa[x]=y;
    cnt[y]+=cnt[x];
}
int main()
{

    long long n,m;
    cin>>n>>m;
    for(long long i=0;i<n;i++)
    {
        fa[i]=i;
        cnt[i]=1;
    }
    for(long long i=0;i<m;i++)
        cin>>a[i]>>b[i];
    ans[m-1]=n*(n-1)/2;
    for(long long i=m-1;i>0;i--)
    {
        long long x=find1(a[i]);
        long long y=find1(b[i]);
        if(x!=y)
        {
            ans[i-1]=ans[i]-cnt[x]*cnt[y];
            merge1(x,y);
        }
        else
            ans[i-1]=ans[i];
    }
    for(long long i=0;i<m;i++)
        cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

vector <ll> s;
ll n;

void modify(ll p,ll x,ll id = 1,ll l = 0,ll r = n+1){
	if(r - l < 2){
        s[id] = x;
		return ;
	}
	ll mid = (l + r)/2;
	if(p < mid)
		modify(p, x, id * 2, l, mid);
	else
		modify(p, x, id * 2 + 1, mid, r);
    s[id] = max(s[id*2],s[id*2+1]);
}

ll query(ll x,ll y,ll id = 1,ll l = 0,ll r = n+1){
	if(x >= r or l >= y)	return 0;
	if(x <= l && r <= y)	return s[id];
	ll mid = (l+r)/2;
	return max(query(x, y, id * 2, l, mid),
	       query(x, y, id * 2 + 1, mid, r));
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n;
    vector <ll> height(n);
    vector <ll> beauty(n);
    for (ll z=0;z<n;z++){
        cin >> height[z];
    }
    for (ll z=0;z<n;z++){
        cin >> beauty[z];
    }
    s.resize(n*4+4,0);
    vector <ll> dp(n);
    ll ans = 0;
    for (ll z=0;z<n;z++){
        dp[z] = query(0,height[z])+beauty[z];
        modify(height[z],dp[z]);
        ans = max(ans,dp[z]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 11264
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
typedef long long ll;
using namespace std;

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

int main()
{
    string s;
    cin >> s;
    ll count = 0;
    for(int i = 0; i < s.size() - 1; i++)
    {
        if(s[i] == '0' && s[i + 1] == '0')
        {
            s[i+1] = '1';
            count++;
        }
        if(s[i] == '1' && s[i + 1] == '1')
        {
            s[i+1] = '0';
            count++;
        }
    }
    cout << count << endl;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    double p = 0;
    double logK = log2(K);
    REPS(i, N)
    {
        int val = ceil(logK - log2(i));
        if (val < 0)
            val = 0;
        p += pow(.5, val);
    }
    p /= N;
    cout << fixed << setprecision(10) << p << "\n";
}

Measured memory_bytes: 512
#include <cstdio>
using namespace std;

int n;
int a[100];
long long int dp[100][21];

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

	dp[0][a[0]] = 1;
	for(int i=1; i<n-1; i++){
		for(int j=0; j<21; j++){
			for(int k=0; k<2; k++){
				int t = j + (k * 2 - 1) * a[i];
				if(0 <= t && t <= 20) dp[i][t] += dp[i-1][j];
			}
		}
	}
	
/*	for(int i=0; i<21; i++){
		for(int j=0; j<n; j++){
			printf("%lld  ", dp[j][i]);
		}
		printf("\n");
	}
*/
	printf("%lld\n", dp[n-2][a[n-1]]);
	return 0;
}

Measured memory_bytes: 2716
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
int main(void){
 while(1){
     int n;
     cin>>n;
     if(!n)break;
     int p[n];
     for(int i=0;i<n;i++){
         p[i]=0;
     }
     int ba=0;
     char f[101];
     scanf(" %s",f);
     for(int i=0;i<100;i++){
         int t=i%n;
         p[t]++;
         if(f[i]=='S'){
             ba+=p[i%n];
             p[i%n]=0;
         }else if(f[i]=='L'){
             p[i%n]+=ba;
             ba=0;
         }
     }
     sort(p,p+n);
     for(int i=0;i<n;i++){
         cout<<p[i]<<' ';
     }
     cout<<ba<<endl;
 }
}

Measured memory_bytes: 3252
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

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

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

// Range Sum Query
class SegmentTree{
public:
    int n;
    vector<ll> node;

    SegmentTree(vector<ll> v) {
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void add(int x, ll val){
        x += (n - 1);
        node[x] += val;
        while(0 < x){
            x = (x - 1) / 2;
            node[x] = node[2*x+1] + node[2*x+2];
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1){
        if(r < 0) r = n;
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];

        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);

        return vl + vr;
    }
};

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

    int n, q; cin>>n>>q;
    vector<ll> a(n, 0);
    SegmentTree seg(a);

    while(q--){
        int c, x, y; cin>>c>>x>>y;
        if(c == 0) seg.add(x-1, y);
        else cout << seg.getsum(x-1, y) << endl;
    }

    return 0;
}


Measured memory_bytes: 6452
#ifndef LOCAL
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

char go2(ll a, ll b, ll k, ll x) {
	ll c = min(a / k, b);
	if (k != 1)
		c = min(c, (k * a - b) / (k * k - 1));
	if (x <= c * (k + 1)) {
		x -= 1;
		x %= (k + 1);
		if (x < k)
			return 'A';
		else
			return 'B';
	}
	x -= c * (k + 1);
	a -= c * k;
	b -= c;
	ll lf = k * a - b;
	ll x1 = lf / k + 1;
	ll y = x1 * k - lf;
	if (x <= x1)
		return 'A';
	if (x <= x1 + y)
		return 'B';
	x -= x1 + y;
	a -= x1;
	b -= y;
	x -= 1;
	x %= (k + 1);
	if (x == 0)
		return 'A';
	else
		return 'B';
}

char go(ll a, ll b, ll k, ll x) {
	if (b > a * k) {
		ll g = b - a * k;
		if (x <= g)
			return 'B';
		return go2(a, a * k, k, x - g);
	}
	return go2(a, b, k, x);
}

ll du(ll a, ll b) {
	return (a + b - 1) / b;
}

void solve() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll k = max(du(a, b + 1), du(b, a + 1));
	for (ll i = c; i <= d; ++i)
		cout << go(a, b, k, i);
	cout << "\n";
}

int main() {
	int tt;
	cin >> tt;
	for (int i = 0; i < tt; ++i)
		solve();
	return 0;
}




Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-6;
const double PI = 3.14159265;
const ll MOD = 1e9 + 7;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 100005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
int arr[MAXN];
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    scanf("%d%d", &m, &n);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
        sum += arr[i];
    }
    if (sum >= m)
        printf("Yes");
    else
        printf("No");
    return 0;
}

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

bool compare(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }

int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    a[i] = make_pair(temp, i + 1);
  }

  sort(a.begin(), a.end(), compare);

  for (int i = 0; i < n; i++) {
    cout << a[i].second << endl;
  }
}

Measured memory_bytes: 1664
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var ab = Console.ReadLine().Split(' ');
        var a = long.Parse(ab[0]);
        var b = double.Parse(ab[1]);

        if (a == 0 || b == 0)
        {
            Console.WriteLine("0");
            return;
        }

        long syousuu0 = long.Parse(ab[1][0].ToString());
        long syousuu1 = long.Parse(ab[1][2].ToString());
        long syousuu2 = long.Parse(ab[1][3].ToString());

        long ans0 = a * syousuu0;
        long ans1 = a * syousuu1 / 10;
        long ans2 = a * syousuu2 / 100;

        // 少数の足し算がある

        double amari1 = (double)(a * syousuu1) / 10d - ans1;
        double amari2 = (double)(a * syousuu2) / 100d - ans2;

        long amari = (long)(amari1 + amari2);

        Console.WriteLine(ans0 + ans1 + ans2 + amari);
    }
}

Measured memory_bytes: 27560
#include <bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N=1e5+9;
int32_t main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int n,k,s;
	cin >> n >> k >> s;
	if(s<1000000000){
		for(int i=0;i<n;i++)
			if(i<k)
				cout << s << " ";
			else
				cout << s+1 <<" ";
	}
	else{
		for(int i=0;i<n;i++)
			if(i<k)
				cout << s << " ";
			else
				cout << 1 <<" ";
	}
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <vector>
#include <map>
#include <cassert>
using namespace std;

int main(){
	string s;
	while(cin >> s && s != "0000"){
		if( count(s.begin(),s.end(),s[0]) == 4 ){
			cout << "NA" << endl;
			continue;
		}
		int cnt = 0;
		while( s != "6174" ){
			string l,g;
			l=g=s;
			sort(l.begin(),l.end());
			sort(g.rbegin(),g.rend());
			int a = atoi(l.c_str());
			int b = atoi(g.c_str());
			int r = b - a;
			char c[10];
			sprintf(c,"%04d",r);
			s = string(c);
			cnt++;
		}
		cout << cnt << endl;
	}
}

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

int main() {

long long t;
t = 1;
while(t--){
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	int count = 0;
	for(int i = 0; i < n; ++i){
		if(a[i] == count + 1) count++;
	}
	cout << (count ? n - count : -1);
}
return 0;
}

Measured memory_bytes: 1024
def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())

    ac = [False] * N
    wa = [0] * N
    for _ in range(M):
        it = iter(input().split())
        p = int(next(it)) - 1
        s = next(it)
        if s == 'AC':
            ac[p] = True
        else:
            if not ac[p]:
                wa[p] += 1
    print(ac.count(True), sum(w for p, w in enumerate(wa) if ac[p]))


if __name__ == '__main__':
    main()


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

#define ll long long
#define ar array

const int mxN=2e5, M=998244353;
int n;
ar<int, 2> a[mxN];
ll dp[mxN+1];

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

	cin >> n;
	for(int i=0; i<n; ++i)
		cin >> a[i][0] >> a[i][1];
	sort(a, a+n);
	dp[n]=1;
	vector<ar<int, 2>> st{{n, (int)2e9}};
	for(int i=n-1; ~i; --i) {
		//int p=lower_bound(a, a+n, ar<int, 2>{a[i][0]+a[i][1], 0})-a;
		//dp[i]=dp[p];
		while(st.back()[1]<a[i][0]+a[i][1])
			st.pop_back();
		int p=st.back()[0];
		dp[i]=dp[p];
		st.push_back({i, a[i][0]});
		//cout << i << " " << p << endl;
		dp[i]=(dp[i]+dp[i+1])%M;
	}
	cout << dp[0];
}

Measured memory_bytes: 4340
#!/usr/bin/env python3
import sys


def solve(H: int, W: int, S: "List[str]"):
    L = [[0 for _ in range(W)] for _ in range(H)]
    R = [[0 for _ in range(W)] for _ in range(H)]
    D = [[0 for _ in range(W)] for _ in range(H)]
    U = [[0 for _ in range(W)] for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] != '#':
                if j == 0:
                    L[i][j] = 1
                else:
                    L[i][j] = L[i][j-1] + 1
            jj = W - 1 - j
            if S[i][jj] != '#':
                if jj == W-1:
                    R[i][jj] = 1
                else:
                    R[i][jj] = R[i][jj+1] + 1
            if S[i][j] != '#':
                if i == 0:
                    D[i][j] = 1
                else:
                    D[i][j] = D[i-1][j] + 1
            ii = H - 1 - i
            if S[ii][j] != '#':
                if ii == H-1:
                    U[ii][j] = 1
                else:
                    U[ii][j] = U[ii+1][j] + 1
    mx = 0 
    for i in range(H):
        for j in range(W):
            m = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
            if mx < m:
                mx = m
    print(int(mx))

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, S)

if __name__ == '__main__':
    main()

Measured memory_bytes: 181512
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
int read(){
	register int x = 0;
	register char f = 1, ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = 0;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');
	return f ? x : -x;
}
#define N 2505
#define M 5005
int n, m, p;
int ex[N], h, t, Q[13000005], vis[N], cnt[N];
long long dis[N];
struct Graph{
	int edge, to[M], pr[M], tw[M], hd[N], vis[N];
	void addedge(int u, int v, int w){
		to[++edge] = v, tw[edge] = w, pr[edge] = hd[u], hd[u] = edge;
	}
	void dfs(int u){
		vis[u] = 1;
		for (register int i = hd[u]; i; i = pr[i])
			if (!vis[to[i]]) dfs(to[i]);
	}
}G, Gv;
int spfa(int s){
	memset(vis, 0, sizeof vis);
	memset(cnt, 0, sizeof cnt);
	memset(dis, -0x3f, sizeof dis);
	dis[s] = 0, h = 0, t = 1, Q[t] = s, vis[s] = 1, cnt[1] = 1;
	while (h < t){
		int u = Q[++h];
		vis[u] = 0;
		for (register int i = G.hd[u], v, w; i; i = G.pr[i])
			if (dis[v = G.to[i]] < dis[u] + (w = G.tw[i]) && ex[v]){
				dis[v] = dis[u] + w;
				if (!vis[v]){
					++cnt[v];
					if (cnt[v] > n) return 0;
					Q[++t] = v, vis[v] = 1;
				}
			}
	}
	return 1;
}
int main(){
	n = read(), m = read(), p = read();
	for (register int i = 1; i <= m; ++i){
		int u = read(), v = read(), w = read() - p;
		G.addedge(u, v, w), Gv.addedge(v, u, w);
	}
	G.dfs(1), Gv.dfs(n);
	for (register int i = 1; i <= n; ++i) ex[i] = G.vis[i] && Gv.vis[i];
	if (!ex[1] || !ex[n]) return printf("0\n"), 0;
	if (!spfa(1)) printf("-1\n"); else printf("%lld\n", std :: max(0ll, dis[n]));
}


Measured memory_bytes: 26752
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

typedef pair<int, int> pi;

int n, m, l, r, d, dist[100001], vis[100001];
vector<pi> adj[100001];

void dfs(int node){
	vis[node] = 1;
	for(auto it:adj[node]){
		if(vis[it.first] != -1){
			if(dist[it.first] != dist[node]+it.second){ cout << "No"; exit(0); }
			continue;
		}
		vis[it.first] = 1;
		dist[it.first] = dist[node]+it.second;
		dfs(it.first);
	}
}

int main(){
	memset(vis, -1, sizeof(vis));
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> l >> r >> d;
		adj[l].push_back(pi(r, d));
		adj[r].push_back(pi(l, -d));
	}
	for(int i = 1; i <= n; i++){
		if(vis[i] == -1) dfs(i);
	}
	cout << "Yes";
}


Measured memory_bytes: 75648