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

const int N = 200005; 
const long long mod = 1000000007; 

using namespace std;

int n, T; 

bool oncir[N], vis[N]; 
int num, sum, cir[N], cur[N]; 

int tp, sta[N]; 
bool insta[N]; 

int match[N], ind[N], siz[N]; 
long long f[N]; 

vector< int > G[N]; 
vector< int > S[N]; 

long long fac[N], inv[N]; 

long long Pow(long long a, long long e) {
	long long ret=1, cnt=a%mod;
	while(e) {
		if(e & 1) ret = ret * cnt % mod;
		cnt = cnt * cnt % mod; 
		e >>= 1; 
	} 
	return ret; 
}

void prepare() {
	fac[1] = 1; 
	for(int i=2; i<=n; ++i) fac[i] = fac[i-1] * i % mod; 
	inv[n] = Pow(fac[n], mod-2); 
	for(int i=n-1; i>=0; --i) inv[i] = inv[i+1] * (i+1) % mod;  
}

long long C(int n, int m) {
	return fac[n] * inv[n-m] % mod * inv[m] % mod; 
}

void dfs_Circle(int u, int f) {
	if(insta[u]) {
		int now; 
		do {
			now = sta[tp--];
			insta[now] = 0; 
			cir[++num] = now; 
			oncir[now] = 1; 
		}while(now != u); 
		++T; 
		return ; 
	}
	vis[u] = 1; 
	insta[u] = 1; 
	sta[++tp] = u; 
	cur[++sum] = u; 
	int size = G[u].size();  
	for(int k=0; k<size; ++k) {
		int v = G[u][k]; 
		if(oncir[v] || v == f) continue; 
		dfs_Circle(v, u); 
	}
	if(insta[u]) {
		sta[tp--] = 0;
		insta[u] = 0;  
	}
}

void dfs_Tree(int u, int f) {
	match[u] = f; 
	int size = G[u].size();  
	for(int k=0; k<size; ++k) {
		int v = G[u][k]; 
		if(oncir[v] || v == f) continue; 
		dfs_Tree(v, u); 
	}
}

void dfs_calc(int u) {
	f[u] = 1; 
	siz[u] = 0; 
	int size = S[u].size(); 
	for(int k=0; k<size; ++k) {
		int v = S[u][k]; 
		dfs_calc(v);
		siz[u] += siz[v]; 
		f[u] = 1ll * f[u] * f[v] % mod * C(siz[u], siz[v]) % mod; 
	}
	++siz[u]; 
}

long long calc() {
	for(int i=1; i<=sum; ++i) ind[cur[i]] = 0; 
	for(int i=1; i<=sum; ++i) {
		int u = cur[i];
		S[u].clear();
		int size = G[u].size();  
		for(int k=0; k<size; ++k) {
			int v = G[u][k]; 
			if(v == match[u]) break; 
			S[u].push_back(v); 
			++ind[v]; 
		}
	}
	S[0].clear();
	for(int i=1; i<=sum; ++i) 
		if(!ind[cur[i]]) S[0].push_back(cur[i]);
	dfs_calc(0);
	return f[0];  
}

int main() {
	
	int u, v; 
	
	int psum=0; 
	long long ans = 1; 
	
	cin >> n; 
	for(int i=1; i<=(n<<1); ++i) {
		cin >> u >> v;  
		G[u].push_back(v+n); 
		G[v+n].push_back(u); 
	}
	
	n <<= 1; 
	for(int i=1; i<=n; ++i) sort(G[i].begin(), G[i].end()); 
	
	prepare(); 
	
	for(int i=1; i<=n; ++i) {
		
		if(vis[i]) continue; 
		
		T = sum = num = tp = 0; 
		dfs_Circle(i, 0); 
		
		if(T != 1) {
			ans = 0; 
			break; 
		}
		
		for(int j=1; j<=num; ++j) dfs_Tree(cir[j], 0); 
		
		long long tmp = 0; 
		
		for(int j=2; j<=num; ++j) match[cir[j]] = cir[j-1]; 
		match[cir[1]] = cir[num]; 
		tmp += calc(); 
		
		for(int j=1; j<num; ++j)  match[cir[j]] = cir[j+1];
		match[cir[num]] = cir[1];
		tmp += calc(); 
		
		psum += sum; 
		ans = 1ll * ans * tmp % mod * C(psum, sum) % mod; 
		
	}
	
	cout << ans << endl; 
	
	return 0; 
	
}

Measured memory_bytes: 32000
#include<stdio.h>
#define MAX 2000000

int n,A[MAX+1];

void maxHeapify(int i);
  
int main(){
  scanf("%d", &n);
  int i;
  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  for ( i = n/2; i >= 1; i-- ) maxHeapify(i);

  for ( i = 1; i <= n; i++ ) {
    printf(" %d", A[i]);
  }
  printf("\n");
  
  return 0;
}

void maxHeapify(int i){
  int l, r, largest, t;
  l = 2*i;
  r = 2*i+1;
  if ( l <= n && A[l] > A[i] ) largest = l;
  else largest = i;
  if ( r <= n && A[r] > A[largest] ) largest = r;
  if ( largest != i ){
    t = A[i]; A[i] = A[largest]; A[largest] = t;
    maxHeapify(largest);
  }
}



Measured memory_bytes: 3684
//In The Name Of GOD

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll mod = 998244353;
const ll inf = 2000000000;
const ll infll = (ll)2*1000*1000*1000*1000*1000*1000;
const ll maxn = 100*1000+1;
#define pb push_back
#define pp pop_back
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);

int main(){
  IO;
  ll n,m;
  cin>>n>>m;
  ll i=0;
  while(n<=m){
    // cout<<n<<" "<<m<<' '<<i<<endl;
    i++;
    n*=2;
  }
  cout<<i;
}


Measured memory_bytes: 256
n=int(input())
a=[]
b=[]
for i in range(n):
  c=int(input())
  a.append(c)
  b.append(c)
b.sort()
b.reverse()
for i in range(n):
  if a[i]<b[0]:
    print(b[0])
  elif a[i]>=b[0]:
    print(b[1])


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

int main(){
    int a,b,c,d,e,k;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cin >> e;
    cin >> k;
    if (abs(a-b) > k || abs(a-c) > k || abs(a-d) > k || abs(a-e) > k || abs(b-c) > k || abs(b-d) > k || abs(b-e) > k || abs(c-d) > k || abs(c-e) > k || abs(d-e) > k){
        cout << ":(" << endl;
        return 0;
    }
    cout << "Yay!" <<endl;
}


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

// templates -------------------------------------

#define ULL unsigned long long
#define LL long long
#define LLD long long double
#define REP(i, n) for(LL i = 0; i < n; i++)
#define INV_REP(i, n) for(LL i = n; 0 <= i; i--)

LL sumOfDigits(LL n)
{
  LL sum = 0;
  while(0 < n)
  {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

LL combination(LL n, LL m)
{
  LL nume = 1;
  REP(i, m) nume *= (n-i);
  LL demo = 1;
  for(int i = 1; i <= m; i++) demo *= i;
  return nume / demo;
}

template<class T>
class UnionFind
{
private:
  vector<T> par;
  vector<T> rank;
  vector<T> size;

public:
  UnionFind(T N) :
    par(N, T()), rank(N, T()), size(N, T())
  {
    REP(i, N)
    {
      par[i] = i;
      rank[i] = 0;
      size[i] = 1;
    }
  }

  inline T root(T x)
  {
    return par[x] == x ? x : par[x] = root(par[x]);
  }

  inline bool same(T x, T y)
  {
    return root(x) == root(y);
  }

  inline T getSize(T x)
  {
    return size[root(x)];
  }

  void unite(T x, T y)
  {
    T r1 = root(x);
    T r2 = root(y);
    if(r1 == r2) return;

    if(rank[r1] < rank[r2]) swap(r1, r2);
    if(rank[r1] == rank[r2]) rank[r1]++;
    par[r2] = r1;
    size[r1] += size[r2];
  }
};

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

int x;

void input()
{
  cin >> x;
}

void solve()
{
  if(x == 22) cout << "Christmas Eve Eve Eve";
  else if(x == 23) cout << "Christmas Eve Eve";
  else if(x == 24) cout << "Christmas Eve";
  else if(x == 25) cout << "Christmas";
}

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

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

int x[310][310];
int tmp[310][310];
int n;

ll sumcost;
int mincost[310];
bool used[310];

void warshallFloid() {
	rep(k, n) rep(i, n) rep(j, n)
		tmp[i][j] = min(tmp[i][j], tmp[i][k] + tmp[k][j]);
}

int main()
{
	cin >> n;
	rep(i, n) {
		rep(j, n) {
			cin >> x[i][j];
			sumcost += x[i][j];
			tmp[i][j] = x[i][j];
		}
	}

	sumcost /= 2;

	warshallFloid();

	bool f = true;
	rep(i, n) {
		rep(j, n) {
			if (x[i][j] != tmp[i][j])
				f = false;
		}
	}

	if (f) {
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				for (int k = 0; k < n; k++) {
					if (k == i || k == j)continue;

					if (tmp[i][j] == (tmp[i][k] + tmp[k][j])) {
						sumcost -= tmp[i][j];
						break;
					}
				}
			}
		}
		cout << sumcost << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
/// referenced: https://beta.atcoder.jp/contests/abc066/submissions/2252964
#include <bits/stdc++.h>
using namespace std;

constexpr int64_t MOD = 1000000007;

int64_t Power(int64_t base, int64_t exp) {
  int64_t x = 1;
  while (exp) {
    if (exp % 2) {
      x = x * base % MOD;
    }
    base = base * base % MOD;
    exp /= 2;
  }
  return x;
}

int64_t Inv(int64_t x) {
  return Power(x, MOD - 2);
}

int64_t Factorial(int64_t x) {
  static vector<int64_t> xs;
  if (xs.size() == 0) {
    xs.resize(100002);
    xs[0] = 1;
    for (int i = 1; i < xs.size(); ++i) {
      xs[i] = xs[i - 1] * i % MOD;
    }
  }
  return xs[x];
}

int64_t InvFact(int64_t x) {
  static vector<int64_t> xs;
  if (xs.size() == 0) {
    xs.resize(100002);
    xs[100001] = Inv(Factorial(100001));
    for (int i = 100000; i >= 0; --i) {
      xs[i] = xs[i + 1] * (i + 1) % MOD;
    }
  }
  return xs[x];
}

int64_t Combination(int64_t n, int64_t r) {
  if (n < r) return 0;
  int64_t x = Factorial(n);
  x = x * InvFact(r) % MOD;
  x = x * InvFact(n - r) % MOD;
  return x;
}


int main(){
  int64_t n,a;
  bool c[100002];
  cin >> n;
  for(int64_t i=1;i<=n;i++) c[i]=false;
  int64_t p[100002];
  int64_t l,r;

  for(int64_t i=0;i<=n;i++){
    cin >> a;
    if(c[a]){
      l=p[a];
      r=i;
    }
    c[a]=true;
    p[a]=i;
  }
  for (int k = 1; k <= n + 1; ++k) {
    int64_t x0, x1, x2;
    x0 = Combination(n + 1, k);
    x1 = Combination((l - 1) + (n + 1 - r), k - 1);
    x2 = (x0 - x1 + MOD) % MOD;
    cout << x2 << endl;
  }
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<sqrt(n);i++)
    {
        if(n%i==0)
        {
          c++;
        }
    }
    c=c*2;
    if(pow(sqrt(n),2)==(sqrt(n)*sqrt(n)))
        c++;
    return  c;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   int n;
   cin>>n;
   vector<int> v;
   set<int> s;
   s.insert(n);
   v.push_back(n);
   int c=1;
   while(1)
   {   c++;
       if(n%2==0)
       {
        v.push_back(n/2);
        s.insert(n/2);
        n=n/2;
       }
       else
       {
        v.push_back(3*n+1);
        s.insert(3*n+1);
        n=3*n+1;
       }
       if(s.size()!=v.size())
       {
        cout<<c;
        return 0;
       }

   }



 return 0;
}








Measured memory_bytes: 3600
a,b = map(int,input().split())

p=a-1
if (a-1)%4==0:
  p=a-1
elif (a-1)%4==1:
  p=1
elif (a-1)%4==2:
  p=(a-1)^1
else:
  p=0
  
if b%4==0:
  b=b
elif b%4==1:
  b=1
elif b%4==2:
  b=b^1
else:
  b=0
print(p^b)

Measured memory_bytes: 9148
# https://atcoder.jp/contests/abc063/tasks/arc075_b
n, a, b = map(int, input().split())

monster = []
for i in range(n):
    monster.append(int(input()))

def damage(monster, t):
    temp = []
    for hp in monster:
        s = hp - t * b
        if s > 0:
            temp.append(s)
    ans = 0
    for hp in temp:
        if hp % (a - b) != 0:
            ans += 1
        ans += hp // (a - b)
    return True if ans <= t else False

ans = float('inf')
l = 0
r = 10 ** 9
while l <= r:
    mid = (l + r) // 2
    if damage(monster, mid):
        ans = min(ans, mid)
        r = mid - 1
    else:
        l = mid + 1
print(ans)

Measured memory_bytes: 118488
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=((ll)n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=((ll)a);i<((ll)n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,y;
    cin>>x>>y;
    tf(abs(x-y)>1, "Alice", "Brown");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,q;
    cin>>n>>q;
    for(;q--;){
        int v,w;
        cin>>v>>w;
        if(n==1){
            cout<<min(v,w)<<endl;
        }else{
            v+=n-2;
            w+=n-2;
            while(v!=w){
                if(v>w){
                    v=v/n+n-2;
                }else{
                    w=w/n+n-2;
                }
            }
            cout<<v-n+2<<endl;
        }
    }
}


Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<map>
#include<iomanip>
#define INF 100000000
using namespace std;
int N,A,B,C;
vector<int> L;

int enumeration(int n,int a, int b, int c){
 int res1,res2,res3,res4;
 if(n==N){
  if(min({a,b,c})>0)return (abs(a-A)+abs(b-B)+abs(c-C))-30;
  else return INF;
 }

 res1=enumeration(n+1,a,b,c);
 res2=enumeration(n+1,a+L[n],b,c)+10;
 res3=enumeration(n+1,a,b+L[n],c)+10;
 res4=enumeration(n+1,a,b,c+L[n])+10;

 return min({res1,res2,res3,res4});
}

int main(void){
 int l;
 cin>>N>>A>>B>>C;
 for(int i=0; i<N;i++){
  cin>>l;
  L.push_back(l);
 }
 cout<<enumeration(0,0,0,0)<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int a[101];
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<=n;i++)
    {
        for(int j=0;i+j<=n;j++)
        {
            if(i*10000+j*5000+(n-i-j)*1000==m)
            {
                printf("%d %d %d",i,j,n-i-j);
                return 0;
            }
        }
    }
    printf("-1 -1 -1");
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

#define ANS(a) cout<<a<<endl

bool is_even_string(const string& s)
{
    int l = s.size();
    if (l == 0 || l % 2 == 1)
        return false;

    l /= 2;
    for (int i = 0; i < l/2; i++)
        if (s[i] != s[i+l])
            return false;

    return true;
    
}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    string S; cin >>S;
    while (S.size() >= 2) {
        S.erase(S.size() - 2, 2);
        if (is_even_string(S)) {
            cout << S.size() << endl;
            return 0;
        }
    }
    cout << "OMG!" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main()
{
  int k;
  scanf("%d",&k);
  if(k==1){
    printf("ACL");
  }
  else if(k==2){
    printf("ACLACL");
  }
   else if(k==3){
    printf("ACLACLACL");
  }
   else if(k==4){
    printf("ACLACLACLACL");
  }
   else if(k==5){
    printf("ACLACLACLACLACL");
  }
}

Measured memory_bytes: 1668
a = int(input())
b = [list(map(int, input().split()))for _ in range(a)]
c = []
for i in range(len(b)):
    c.append(b[i].copy())
    if len(c) != 1:
        while True:
            if c[i][0] < c[i-1][0] or c[i][1] < c[i-1][1]:
                c[i][0] = b[i][0] * max((c[i-1][0] + b[i][0] - 1) // b[i][0], (c[i-1][1] + b[i][1] - 1) // b[i][1])
                c[i][1] = b[i][1] * max((c[i-1][0] + b[i][0] - 1) // b[i][0], (c[i-1][1] + b[i][1] - 1) // b[i][1])
            else:
                break
print(c[len(c)-1][0] + c[len(c)-1][1])


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

LL n, m, dp[10001][2][101], mod = 1000000007;
vector<int> v;

LL solve(int pos, bool f1, int sum) {
	sum %= m;
	if(pos == v.size()) return sum == 0;
	LL &ret = dp[pos][f1][sum];
	if(ret != -1) return ret;
	ret = 0;
	for(int i = 0; i < 10; i++) {
		if(f1) ret += solve(pos+1, 1, sum + i);
		else {
			if(i == v[pos]) ret += solve(pos+1, 0, sum + i);
			else if(i < v[pos]) ret += solve(pos+1, 1, sum + i);
		}
		ret %= mod;
	}
	return ret;
}

int main() {
	string s;
	memset(dp, -1, sizeof(dp));
	cin>>s>>m;
	for(char c : s) v.push_back(c-'0');
	LL ans = solve(0, 0, 0);
	ans = (ans - 1 + mod) % mod;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 16768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <functional>
#include <limits>
#include <queue>
#include <iomanip>
#include <deque>
#include <stack>
#include <cstdio>
#include <cmath>
#include <complex.h>
#include <cstdio>
#include <random>
#include <chrono>
#include <numeric>

using namespace std;

int p[100100];

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

	int n;
	cin >> n;

	for (int i = 1; i <= n; i++)
		cin >> p[i];

	int swaps = 0;
	for (int i = 1; i <= n; i++)
		if (i == p[i])
		{
			int j = i + 1;
			if (j > n)
				j = i - 1;

			swaps++;
			swap(p[i], p[j]);
		}

	cout << swaps;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n;
  cin >> n;
  int ans = 1<<30;
  for(int i = 1 ; i <= sqrt(n);i++){
    long I = i;
    long N;
    int ketaA = 1;
    int ketaB = 1;    
    if( n % i == 0){
      N = n / i;
      while(true){
        if( I / 10 != 0){
          ketaA += 1;
          I /= 10;
        }
        else{
          break;
        }
      }
      while(true){
        if( N / 10 != 0){
          ketaB += 1;
          N /= 10;
        }
        else{
          break;
        }
      }
      if( ans > max(ketaA,ketaB)){
        ans = max(ketaA,ketaB);
      }
    }
  }
  cout << ans << endl ;
}

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

int main(){
  int N,M,i,j,k,l;
  cin>>N>>M;
  ll x[N],y[N],z[N];
  for(i=0;i<N;i++) cin>>x[i]>>y[i]>>z[i];
  ll ans=-1000000000000;
  for(k=1;k<=8;k++){
	ll xx[N],yy[N],zz[N],su[N];
	for(i=0;i<N;i++){
	xx[i]=(2*(k&1)-1)*x[i];
	yy[i]=(2*(k>>1&1)-1)*y[i];
	zz[i]=(2*(k>>2&1)-1)*z[i];
	su[i]=xx[i]+yy[i]+zz[i];
	}
	sort(su,su+N);
	reverse(su,su+N);
	ll temp=0;
	for(i=0;i<M;i++){
		temp+=su[i];
	}
	ans=max(ans,temp);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define ms(a, b)  memset((a), (b), sizeof(a))
//#define LOCAL
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int maxn = 50+10;
const LL mod = 1000000000+7;
char s[maxn];
int main()
{
    #ifdef LOCAL
        freopen("input.txt" , "r", stdin);
    #endif // LOCAL
    int n;
    scanf("%d", &n);
    int ans[maxn];
    for(int i=0;i<26;i++)
        ans[i] = maxn;
    while(n--)
    {
        scanf("%s", s);
        int len = strlen(s);
        int num[26]={0};
        for(int i=0;i<len;i++)
            num[s[i]-'a']++;
//        for(int i = 0;i<26;i++)
//            if(num[i])  printf("%c", i+'a');
//        printf("\n");
        for(int i=0;i<26;i++)
            ans[i] = min(ans[i], num[i]);
    }
    for(int i=0;i<26;i++)
        while(ans[i]--)
            printf("%c", 'a'+i );
    printf("\n");
    return 0;
}


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

#define lli long long int
#define pb push_back

int main()
{
    int n , aux , ans , max , min ;
    cin >> n ;
    ans = n ;
    cin >> max ;
    min = max ;

    for (int i = 1 ; i < n ; i++)
    {
        cin >> aux ;

        if (aux > max)
        {
            max = aux ;
            ans-- ;
        }
        else if (aux < min)
        {
            min = aux ;
        }
        else
        {
            ans-- ;
        }
        
    }
    cout << ans << endl ;

    return 0 ;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

int n;

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n;
    vector<pair<ll, ll>> points;
    for (int i = 0; i < n; ++i) {
        ll a, b;
        cin >> a >> b;
        points.push_back({a, 0});
        points.push_back({b, 1});
    }

    sort(points.begin(), points.end());

    ll lb = -1, rb = -1;
    ll ahead = 0, after = 0;
    // Fine for odd and bottom half for even
    ll need = (ll)ceil((long double)n / 2) - 1;
    for (auto point : points) {
        ll loc = point.first, type = point.second;
        if (ahead - type >= need && ahead - after <= need) {
            if (lb == -1) {
                lb = loc;
                rb = loc;
            } else {
                rb = loc;
            }
        } else if (lb != -1) break;

        if (type) --after;
        else {
            ++ahead;
            ++after;
        }
    }

    if (!(n % 2)) {
        ll ulb = -1, urb = -1;
        ll ahead = 0, after = 0;
        // Fine for odd and bottom half for even
        ll need = n / 2;
        for (auto point : points) {
            ll loc = point.first, type = point.second;
            if (ahead - type >= need && ahead - after <= need) {
                if (ulb == -1) {
                    ulb = loc;
                    urb = loc;
                } else {
                    urb = loc;
                }
            } else if (ulb != -1) break;

            if (type) --after;
            else {
                ++ahead;
                ++after;
            }
        }
        // cout << lb << ' ' << rb << ' ' << ulb << ' ' << urb << '\n';
        ld tlb = (ulb + lb) / (long double)2, trb = (urb + rb) / (long double)2;
        // cout << tlb << ' ' << trb << '\n';
        cout << (ll)((trb - tlb) * 2 + 1);
    } else {
        // Range is inclusive
        cout << rb - lb + 1;
    }
}


Measured memory_bytes: 11600
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  unsigned ll  h,w;
  cin >> h >> w;
  unsigned long long ret = 0;
  if( h == 1 || w == 1){
    cout << 1 << endl;
    return 0;
  }
  if ( h % 2 == 0 ) {
    ret = (h/2) * w;
  }
  else {
    unsigned ll  a = (h+1)/2;
    ret = (a + a - 1) * (w/2);
    if( w % 2 == 1 ) ret += a;
  }
  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    ll n, m, ans = 0;
    cin >> n >> m;
    m /= 2;
    ans += min(n,m);
    n -= ans; m -= ans;
    if(m)ans += m/2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoderMake.ABC169
{
    class ABC169B
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select((x) => long.Parse(x)).ToArray();
            long ans = a[0];
            long maxans = 1;
            for(int i = 0; i < 18; i++)
            {
                maxans *= 10;
            }
            try
            {
                checked
                {
                    for(int i = 1; i < n; i++)
                    {
                        ans *= a[i];
                        if (ans > maxans)
                        {
                            ans = -1;
                            break;
                        }
                    }
                }
            }
            catch
            {
                ans = -1;
            }

            if (a.Count((x) => x == 0) > 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(ans);
            }
        }
    }
}


Measured memory_bytes: 42816
#include <stdio.h>
#include <stdlib.h>
 
void unite(long *affiliation, long *group, long p, long q) {
  long i,j;
  j = 0;
  for (i = 0; j < group[q]; i++) {
    if(affiliation[i] == q) {
      affiliation[i] = p;
      j++;
    }
  }
  group[p] += group[q];
}
 
int main()
{
  long n,m,i,s,t,p,q;
  long *affiliation,*group;
  scanf("%ld %ld",&n,&m);
  affiliation = (long*)malloc(sizeof(long) * n);
  for (i = 0; i < n; i++) affiliation[i] = -1;
  group = (long*)malloc(sizeof(long) * m);
  for (i = 0; i < m; i++) group[i] = 0;
  p = 0;
  for (i = 0; i < m; i++) {
    scanf("%ld %ld", &s, &t);
    if(affiliation[s] == -1 && affiliation[t] == -1) {
      affiliation[s] = p;
      affiliation[t] = p;
      group[p] += 2;
      p++;
    }
    else if(affiliation[s] != -1 && affiliation[t] == -1) {
      affiliation[t] = affiliation[s];
      group[affiliation[s]]++;
    }
    else if(affiliation[s] == -1 && affiliation[t] != -1) {
      affiliation[s] = affiliation[t];
      group[affiliation[t]]++;
    }
    else if(affiliation[s] != affiliation[t]){
      (affiliation[s] < affiliation[t]) ? unite(affiliation,group,affiliation[s],affiliation[t]):unite(affiliation,group,affiliation[t],affiliation[s]);
    }
  }
  scanf("%ld",&q);
  for (i = 0; i < q; i++) {
    scanf("%ld %ld", &s, &t);
    if(affiliation[s] == affiliation[t] && affiliation[s] != -1) printf("yes\n");
    else printf("no\n");
  }
  free(affiliation);
  free(group);
   
  return 0;
}

Measured memory_bytes: 1944
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, M; cin >> n >> M;
    using AB = tuple<int, int>;
    vector<AB> ab(n);
    for(auto& e : ab){
        int a, b; cin >> a >> b;
        e = AB(a, -b);
    }
    sort(_all(ab));

    int res = 0;
    priority_queue<int> q;
    int i = 0;
    rep(cday, 1, M + 1){
        while(i < n){
            int a, b; tie(a, b) = ab[i]; b *= -1;
            if(a > cday) break;
            q.push(b);
            i++;
        }
        if(q.size()){
            res += q.top();
            q.pop();
        }
    }

    cout << res << endl;

    return 0;
}


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

int main(){
  int a,b;
  cin>>a>>b;
  if(a<=0&&b>=0) cout<<"Zero"<<endl;
  else if(a>0||(b-a)%2) cout<<"Positive"<<endl;  
  else cout<<"Negative"<<endl;
  return 0;
} 

Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 3/17
// Problem:Be together . a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
static const int INF = 1000000001;
static const int MAX_N = 100;

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

  CIN(N);
  vector< int > a(N);
  REP(i, N) {
    cin >> a[i];
  }
  sort(ALL(a));

  ll ans = INF;
  FOR(i, -100, 100 + 1) {
    ll cnt = 0ll;
    REP(j, N) {
      cnt += (a[j] - i) * (a[j] - i);
    }
    ans = min(cnt, ans);
  }

  cout << ans << endl;
  
  return 0;
}



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

using namespace std;

int main()
{
  string a, b, c, d;

  cin >> d;

  a = d[0];

  b = d[1];

  c = d[2];

  if (a == b && b == c)
  {
    cout << "No" << endl;
  }
  else
  {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#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 mp make_pair
#define pb push_back

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

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



int main() {
  int n, k;
  cin >> n >> k;

  int ans = 0;
  rep(i, n) {
    int x;
    cin >> x;
    ans += 2*min(x, abs(x-k));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $a);
fscanf(STDIN, "%d", $b);
fscanf(STDIN, "%d", $c);
fscanf(STDIN, "%d", $d);
fscanf(STDIN, "%d", $e);
fscanf(STDIN, "%d", $k);
if (($e - $a) > $k) {
    echo ':(';
} else {
    echo 'Yay!';
}


Measured memory_bytes: 16068
#include<bits/stdc++.h>
#define pp pair<int,int>
#define MZ 1000000007
#define pq priority_queue
using namespace std;
struct Edge
{
    int dis,u,v;
    friend bool operator <(Edge x1,Edge x2)
    {
        return x1.dis>x2.dis;
    }
}temp;
struct Node
{
    int x,y,no;
}num[100005];
int root[100005];
bool cmp1(Node x1,Node x2)
{
    return x1.x<x2.x;
}
bool cmp2(Node x1,Node x2)
{
    return x1.y<x2.y;
}
pq <Edge> q;
int findr(int x)
{
    if(root[x]==x)
        return x;
    else
        return root[x]=findr(root[x]);
}
int main()
{
    int u,v;
    long long ans=0;
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&num[i].x,&num[i].y);
        num[i].no=i+1;
        root[i+1]=i+1;
    }
    sort(num,num+n,cmp1);
    for(int i=1;i<n;i++)
    {
        temp.u=num[i].no;
        temp.v=num[i-1].no;
        temp.dis=num[i].x-num[i-1].x;
        q.push(temp);
    }
    sort(num,num+n,cmp2);
    for(int i=1;i<n;i++)
    {
        temp.u=num[i].no;
        temp.v=num[i-1].no;
        temp.dis=num[i].y-num[i-1].y;
        q.push(temp);
    }
    while(!q.empty())
    {
        temp=q.top();
        q.pop();
        u=findr(temp.u);
        v=findr(temp.v);
        if(u!=v)
        {
            root[u]=v;
            ans+=temp.dis;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

typedef long long int ll;



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

	ll i,j,t,k,l,m,n,x,y,z,a,b,c;

	cin >> n;

	string s;

	cin >> s;

	ll red = 0,white = 0;

	for(i=0;i<n;i++)
	{
		if(s[i] == 'R')
			red++;
		else
			white++;
	}

	ll ans = min(white,red);

	l = 0;
	for(i=0;i<red;i++)
	{
		if(s[i]!='R')
			l++;

	}

	ans = min(ans,l);

	l = 0;
	for(i=n-1;i>=(n-white);i--)
	{
		if(s[i] != 'W')
			l++;
	}

	ans = min(ans,l);

	cout << ans << '\n';

	

}

Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F(i,a,b) for(int i = a ; i <=b ; i++)
#define R(i,a,b) for(int i = a ; i >= b ; i--)
#define pb push_back
#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ALL(v)   v.begin(),v.end()
bool comp(pair<pair<string,int> , int> a, pair<pair<string,int> , int> b )
{
	if(a.first.first  != b.first.first)
		return a.first.first < b.first.first;
	else
		return a.first.second >  b.first.second;
}
int main()
	{
		
		int n;
		cin >> n;
		vector<pair <pair<string, int>, int >> vec(n);
		for(int x=0; x<n;x++)
		{
			cin >> vec[x].first.first >> vec[x].first.second ;
			vec[x].second = x;
		}
		sort(vec.begin(), vec.end(), comp);

		int parent[n+1];
		int index =1;
		for(auto D: vec)
		{
			parent[index -1] = D.second;
			index++;
		}
		for(int x=0; x <n;x++)
		{
			cout << parent[x]  +1 << endl;
		}

		
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()


int table[1000][1001];
void solve(int lim,int n,int *weight,int *value){
  rep(i,n){
    rep(j,lim+1){
      table[i][j]=0;
    }
  }
  

  if (weight[0] <= lim)table[0][weight[0]]=value[0];
  
  REP(i,1,n){
    rep(j,lim+1){
      table[i][j]=table[i-1][j];
      if (j-weight[i]<0)continue;
      table[i][j]=max(table[i][j],table[i-1][j-weight[i]]+value[i]);
    }
  }
  
  int maxi=0,answ;
  rep(i,lim+1){
    if (table[n-1][i] > maxi)maxi=table[n-1][i],answ=i;
  }
  cout << maxi<<endl;
  cout << answ << endl;
}

main(){
  int n,w;
  int value[1000],weight[1000];
  int tc=1;
  while(cin>>w>>n && w){
    char dummy;
    rep(i,n){
      cin>>value[i]>>dummy>>weight[i];
    }
    cout << "Case "<< tc++ << ":" << endl;

    solve(w,n,weight,value);
  }
  return false;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int H[N];
    int sum=1;
    int max=1;
    for (int i=0 ; i<N ;i++){
       cin >> H[i];
       if (H[i]>=max){
           max=H[i];
           
       if (i!=0){
          sum=sum+1;}
       }
       }
       cout << sum <<endl;
       return 0;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int sign(int x) { return (x > 0) - (x < 0); }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const deque<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const set<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int X, K, D;
signed main() {
    cin >> X >> K >> D;
    X = abs(X);
    if (K < cdiv(X, D)) { fin(X - K * D); }
    if (((X / D) ^ K) & 1) { cout << D - X % D << endl; }
    else { cout << X % D << endl; }
}


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

int32_t main()
{
	int n,k,r,s,p;
	cin>>n>>k;
	cin>>r>>s>>p;
	string t;
	cin>>t;

	char ans[n];
	for (int i=0;i<n;i++)ans[i]='z';
	int val=0;
	for (int i=0;i<n;i++){
		if (t[i]=='r'){
			int y=i-k;
			if (y>=0) {
				if (ans[y]!='p')
					ans[i]='p',val+=p;
			}
			else
				ans[i]='p',val+=p;
		}
		else if (t[i]=='s')
		{
			int y=i-k;
			if (y>=0) {
				if (ans[y]!='r')
					ans[i]='r',val+=r;
			}
			else
				ans[i]='r',val+=r;
		}
		else{
			int y=i-k;
			if (y>=0) {
				if (ans[y]!='s')
					ans[i]='s',val+=s;
			}
			else
				ans[i]='s',val+=s;

		}

	}

	//for (auto k:ans)cout<<k<<" ";

	cout<<val<<'\n';


}

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

int main(){
    int n;
  	cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    cout << a[n-1] - a[0] << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("03")
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
//	ifstream cin("tst.in");
//	ofstream out("tst.out");
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	int cnt = 0;
	cin >> n;
	for(int i = 2; i <= n; i += 2)
		for(int j = 1; j <= n; j += 2)
			cnt++;
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
from fractions import gcd

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

G = gcd(N, M)
L = N*M//G
n = N//G
m = M//G

ans = True
for k in range(G):
    if S[k*n] != T[k*m]:
        ans = False
        break
print(L if ans else -1)


Measured memory_bytes: 5432
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
#define pint pair<string, int>
bool desc(pint a, pint b) {
	return a.second > b.second;
}
int main() {
	int n;
	bool f = 0;
	while(cin >> n, n) {
		if(f) cout << endl;
		f = 1;
		vector<pint> v;
		rep(i,n) {
			string t;
			int tmp, s = 0;
			cin >> t;
			cin >> tmp;
			s += tmp * 3;
			cin >> tmp;
			cin >> tmp;
			s += tmp;
			v.push_back(make_pair(t,s));
		}
		sort(v.begin(), v.end(), desc);
		for(pint p : v) {
			cout << p.first << "," << p.second << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1220
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 ans = a - b * 2 < 0 ? 0 : a - b * 2;
        System.out.println(ans);
    }
}


Measured memory_bytes: 21716
#include <cstdio>
#include <iostream>
#include <utility>
#include <queue>
using namespace std;
typedef pair<int,int> ii;

struct ufds{
    int p[200005];

    ufds(){
        for (int x=0;x<200005;x++){
            p[x]=x;
        }
    }
    int parent(int i){return (p[i]==i)?i:p[i]=parent(p[i]);}
    void unions(int i,int j){
        i=parent(i),j=parent(j);
        p[i]=j;
    }
}dsu=*new ufds();

struct E{
    int zero,one;
    int index;

    E(int a,int b,int c){
        zero=a,one=b,index=c;
    }

    bool operator<(const E &i)const{
        return (long long)one*i.zero>(long long)i.one*zero;
    }
};

int n;
int p[200005];
ii val[200005];
priority_queue<E> pq;
long long ans=0;

int main(){
    scanf("%d",&n);
    for (int x=2;x<=n;x++) scanf("%d",&p[x]);
    for (int x=1;x<=n;x++){
        scanf("%d",&val[x].second);
        val[x].first=1-val[x].second;
    }

    for (int x=2;x<=n;x++){
        pq.push(*new E(val[x].first,val[x].second,x));
    }

    int node;
    while (!pq.empty()){
        E temp=pq.top();pq.pop();
        //cerr<<temp.index<<" "<<temp.zero<<" "<<temp.one<<endl;
        if (val[temp.index]!=ii(temp.zero,temp.one)) continue;

        node=dsu.parent(p[temp.index]);
        ans+=(long long)val[node].second*val[temp.index].first;
        val[node].first+=val[temp.index].first;
        val[node].second+=val[temp.index].second;
        if (node!=1) pq.push(*new E(val[node].first,val[node].second,node));
        dsu.unions(temp.index,node);
    }

    printf("%lld\n",ans);
}


Measured memory_bytes: 19760
#include <iostream>

int main(int argc, char const* argv[]) {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int A, B, C, D;
    std::cin >> A >> B >> C >> D;
    std::cout << std::min(A, B) + std::min(C, D) << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt(),b=s.nextInt();
        int max = Math.max(a,b);
        System.out.println(max+Math.max(max-1,Math.min(a,b)));

    }




}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25304
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
///////////////////////////////////////

int main() {
	int N; cin >> N;
	string s[110];
	int p[110];
	vector<tuple<string,int,int>>S;
	for (int i = 0; i < N; ++i) {
		cin >> s[i] >> p[i];
		S.emplace_back(s[i],-p[i],i );
	}
	sort(begin(S),end(S));
	int ans[110];
	for (int i = 0; i < S.size(); ++i) {
		int x = get<2>(S[i]);
		ans[i] = x+1;
	}
	for (int i = 0; i < N; ++i) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256