akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;
template <typename T,typename E>
struct SegmentTree{
  typedef function<T(T,T)> F;
  typedef function<T(T,E)> G;
  int n;
  F f;
  G g;
  T d1;
  E d0;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(int n_,F f,G g,T d1,
	      vector<T> v=vector<T>()):
    f(f),g(g),d1(d1){
    init(n_);
    if(n_==(int)v.size()) build(n_,v);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,d1);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  void update(int k,E a){
    k+=n-1;
    dat[k]=g(dat[k],a);
    while(k>0){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
  inline T query(int a,int b){
    T vl=d1,vr=d1;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[(l++)-1]);
      if(r&1) vr=f(dat[(--r)-1],vr);
    }
    return f(vl,vr);
  }
  
};
     signed main(){
        int n;
        cin>>n;
        int a[n],b[n];
        for(int i=0;i<n;i++){
             cin>>a[i];
             b[i]=a[i];
        }
        sort(b,b+n);
        int ok=-1,ng=n,mid;
        int d[2*n+1];
        while(abs(ok-ng)>1){
             mid=(ok+ng)/2;
             fill(d,d+2*n+1,0);
             SegmentTree<int,int> rmq(2*n+2,
			   [](int a,int b){return a+b;},
			   [](int a,int b){return a+b;},
			   0);
             int t=0,s=0;
             rmq.update(n+t,1);
             
             for(int i=0;i<n;i++){
                  if(b[mid]<=a[i])t++;
                  else t--;
                    s+=rmq.query(0,n+t+1);
                 rmq.update(n+t,1);
             }
             if(((n+1)*n/2+1)/2 <=s)ok=mid;
             else ng=mid;
         // cerr<<s<<' '<<b[mid]<<endl;
        }
        cout<<b[ok]<<endl;
      //  cerr<<ok<<' '<<ng;
     }


 


 






    





      

        


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

int main() {
    int N, Y;
    cin >> N >> Y;
    int ans1000,ans5000,ans10000;
    ans1000 = -1;
    ans5000 = -1;
    ans10000= -1;
    for(int i =0; i<N+1;i++){
        for(int j=0; j<N+1-i;j++){
            int k = N-i-j;
                if(1000*i+5000*j+10000*k==Y){
                    ans1000 =i;
                    ans5000 =j;
                    ans10000=k;
                    break;
                }
            }
        }
    cout << ans10000 <<" " <<ans5000 <<" " <<ans1000<<endl;
}




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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  string s;
  cin >> s;

  int start, end;
  start = -1;
  end = -1;
  int i = 0;
  while (start == -1) {
    if (s[i] == 'A') {
      start = i;
    }
    i++;
  }

  i = s.length();
  while (end == -1) {
    if (s[i] == 'Z') {
      end = i;
    }
    i--;
  }

  cout << end - start + 1;
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


ll xC2(ll x){
  return x * (x - 1) / 2;
}

int main()
{
  ll n, c=0;
  cin >> n;
  vecll a(n);
  map <ll, ll> m;
  forll(i, 0, n){
	cin >> a[i];
	m[a[i]]++;
  }
  
  for(auto i=m.begin(); i!=m.end(); ++i){
	c += xC2(i->second);
  }
  
  forll(i, 0, n){
	cout << c - m[a[i]] + 1 << endl;
  }
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int x = 1;
  for(int i = 0; i < n; i++) {
    if(x > k) x += k;
    else x *= 2;
  }
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

//GCD
int gcd(int a, int b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  int k;
  scanf("%d", &k);
  long ans = 0;
  for (int i=0; i<k; i++) {
    for (int j=0; j<k; j++) {
      int tmp = gcd(i+1, j+1);
      for (int l=0; l<k; l++) {
        ans += gcd(tmp, l+1);
      }
    }
  }
  printf("%ld\n", ans);
  return 0;
}


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

signed main(void)
{
	int h, w, k, sum, ans;
	cin >> h >> w >> k;
	string c[h];
	int t[h], y[w];
	sum = 0;
	rep(i, h) cin >> c[i];
	rep(i, h)  rep(j, w)
	{
		if (c[i][j] == '#')
			sum++;
	}
	rep(i, h) 
	{
		int tmp = 0;
		rep(j, w)
		{
			if (c[i][j] == '#')
				tmp++;
		}
		t[i] = tmp;
	}
	rep(j, w)
	{
		int tmp = 0;
		rep(i, h) 
		{
			if (c[i][j] == '#')
				tmp++;
		}
		y[j] = tmp;
	}
	ans = 0;
	for (int bit = 0; bit < (1 << h); bit++)
	{
		vector<int> tate;
		for (int i = 0; i < h; i++)
		{
			if (bit & (1 << i))
				tate.push_back(i);
		}
		for (int bit2 = 0; bit2 < (1 << w); bit2++)
		{
			vector<int> yoko;
			for (int i = 0; i < w; i++)
			{
				if (bit2 & (1 << i))
					yoko.push_back(i);
			}
			int cnt = 0;
			rep(i, tate.size()) cnt += t[tate[i]];
			rep(i, yoko.size()) cnt += y[yoko[i]];
			rep(i, tate.size()) rep(j, yoko.size())
			{
				if (c[tate[i]][yoko[j]] == '#')
					cnt--;
			}
			if (sum - cnt == k)
				ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3584
# AGC017A - Biscuits
def main():
    n, p = tuple(map(int, input().rstrip().split()))
    A = tuple(map(lambda x: int(x) % 2, input().rstrip().split()))
    if sum(A) == 0:  # all numbers are even
        print(2 ** n if p == 0 else 0)
    else:
        print(2 ** (n - 1))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int D;
    cin >> D;
    if ( D == 22 ) cout << "Christmas Eve Eve Eve" << endl;
    else if ( D == 23 ) cout << "Christmas Eve Eve" << endl;
    else if ( D == 24 ) cout << "Christmas Eve" << endl;
    else if ( D == 25 ) cout << "Christmas" << endl;
    return 0;
}

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

int main()
{
    int N;
    int D1,D2;
    int count,flag;
    int i;

    count=0;
    flag=0;

    scanf("%d\n",&N);

    for(i=0;i<N;i++){
        scanf("%d %d\n",&D1,&D2);

        if(D1==D2){
            count++;

            if(count==3){
                flag++;
            }
        }
        else{
            if(count>0){
                count=0;
            }
        }
    }

    if(flag>0){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
 
    return 0;
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll memo[100005];
ll arr[100005];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    
    memo[0]=0;
    memo[1]=abs(arr[1]-arr[0]);
    
    for(int i=2;i<n;i++)
    {
        memo[i]=min(memo[i-1]+abs(arr[i]-arr[i-1]),memo[i-2]+abs(arr[i]-arr[i-2]));
    }
    
    printf("%lld\n",memo[n-1]);
}

Measured memory_bytes: 1792
from math import gcd

K = int(input())

memo = []
memolist = []
for i in range(1,K+1):
    if i != 1:
        memo.append(memolist)
    memolist = []
    for j in range(1,K+1):
        memolist.append(gcd(i,j))
memo.append(memolist)

result = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            result += gcd(memo[i-1][j-1],k)

print(result)

Measured memory_bytes: 9484
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


int main(){
  ll r;
  cin >> r;
  ll d,x;
  cin >> d >> x;
  FOR(i,10){
    x=r*x-d;
    cout << x << endl;
  }
}


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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

ll gcd(ll x, ll y)
{
    ll r;
    if (x == 0 || y == 0)
        return 0;
    while ((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    SORT(a);
    vector<ll> res;
    FOR(i, 1, n)
    {
        ll g = gcd(a[0], a[i]);
        if (g == 1)
        {
            cout << 1 << endl;
            return 0;
        }
        res.push_back(g);
        // dump(g);
    }
    cout << *min_element(ALL(res)) << endl;
    return 0;
}

Measured memory_bytes: 2168
#include<stdio.h>
main(){
  long long a,b,i,x,y,temp;
  while(scanf("%lld %lld",&a,&b)!=EOF){
    x=a;
    y=b;
    if(x<y){
      temp=x;
      x=y;
      y=temp;
    }
    while(y!=0){
      temp=y;
      y=x%y;
      x=temp;
    }
    printf("%lld %lld\n",x,a*b/x);
  }
  return 0;
}

Measured memory_bytes: 596
//P.C.2.O.
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a;
	int b;
	cin>>a;
	cin>>b;
	int q=a+b;
	int w=a-b;
	int e=a*b;
	int r=max(q,max(w,e));
	cout<<r;
	return 0;
}

Measured memory_bytes: 256
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

n = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7

x = lcm(*A) % mod
ans = sum([x * pow(a, mod-2, mod) for a in A]) % mod
print(ans)

Measured memory_bytes: 69336
#include <iostream>
#include <string>

using namespace std;

int main(){
	
	int sx, sy, tx, ty;
	cin >> sx;
	cin >> sy;
	cin >> tx;
	cin >> ty;
	
	int dx = tx - sx;
	int dy = ty - sy;
	string result = "";
	
	int i;
	
	// 一周目
	while(i < dy){
		result += "U";
		i++;
	}
	i = 0;
	while(i < dx){
		result += "R";
		i++;
	}
	i = 0;
	while(i < dy){
		result += "D";
		i++;
	}
	i = 0;
	while(i < dx){
		result += "L";
		i++;
	}
	i = 0;
	
	// 二週目
	result += "L";
	while(i <= dy){
		result += "U";
		i++;
	}
	i = 0;
	while(i <= dx){
		result += "R";
		i++;
	}
	i = 0;
	
	result += "D";
	result += "R";
	while(i <= dy){
		result += "D";
		i++;
	}
	i = 0;
	while(i <= dx){
		result += "L";
		i++;
	}
	i = 0;
	result += "U";
	
	cout << result << endl;
	
	return 0;
	
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
LL a[210000],s[210000];
int main()
{
	int n;
	scanf("%d",&n);
	s[0]=0;
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]),s[i]=s[i-1]+a[i];
	LL sum=1LL<<63-1;
	for(int i=2;i<n-1;i++)
	{
		int l1=1,r1=i,l2=i+1,r2=n;
		int t1,t2,t3,t4;
		t1=t2=t3=t4=-1;
		int ans=-1,mid;
		while(l1<=r1)
		{
			mid=(l1+r1)/2;
			if(s[mid]==s[i]-s[mid]){t1=mid;break;}
			else if(s[mid]>s[i]-s[mid]) ans=mid,r1=mid-1;
			else l1=mid+1;
		}
		if(t1==-1)
		{
			if(ans==i) t1=i-1;
			else
			{
				t1=ans;
				if(ans!=1) t2=ans-1;
			}
		}
		ans=-1;
		while(l2<=r2)
		{
			mid=(l2+r2)/2;
			if(s[mid]-s[i]==s[n]-s[mid]){t3=mid;break;}
			else if(s[mid]-s[i]>s[n]-s[mid]) ans=mid,r2=mid-1;
			else l2=mid+1;
		}
		if(t3==-1)
		{
			if(ans==n) t3=n-1;
			else
			{
				t3=ans;
				if(ans!=i+1) t4=ans-1;
			}
		}
		sum=min(sum,max(s[t1],max(s[i]-s[t1],max(s[t3]-s[i],s[n]-s[t3])))-min(s[t1],min(s[i]-s[t1],min(s[t3]-s[i],s[n]-s[t3]))));
		if(t4!=-1) sum=min(sum,max(s[t1],max(s[i]-s[t1],max(s[t4]-s[i],s[n]-s[t4])))-min(s[t1],min(s[i]-s[t1],min(s[t4]-s[i],s[n]-s[t4]))));
		if(t2!=-1) sum=min(sum,max(s[t2],max(s[i]-s[t2],max(s[t3]-s[i],s[n]-s[t3])))-min(s[t2],min(s[i]-s[t2],min(s[t3]-s[i],s[n]-s[t3]))));
		if(t2!=-1&&t4!=-1) sum=min(sum,max(s[t2],max(s[i]-s[t2],max(s[t4]-s[i],s[n]-s[t4])))-min(s[t2],min(s[i]-s[t2],min(s[t4]-s[i],s[n]-s[t4]))));
	}
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 3328
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(N)]

AB_s=sorted(AB)

ans=0
cnt=0
for a,b in AB_s:
    ans+=a*b
    cnt+=b
    if cnt>=M:
        ans-=a*(cnt-M)
        print(ans)
        exit()

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

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
// clang-format on

int N, Q;
char S[MAX_N + 1];
int l[MAX_N], r[MAX_N];
int d[MAX_N];

void solve()
{
  int cnt = 0;
  for (int i = 1; i < N; i++) {
    if (S[i - 1] == 'A' && S[i] == 'C') cnt++;
    d[i] = cnt;
  }
  for (int i = 0; i < Q; i++) {
    cout << d[r[i] - 1] - d[l[i] - 1] << endl;
  }
}

int main(void)
{
  cin >> N >> Q;
  cin >> S;
  REP(i, Q) cin >> l[i] >> r[i];
  solve();
  return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

#define INF 100000000

int main()
{
	int N;
	cin >> N;
	vi seq(N);
	for (int n = 0; n < N; n++)
	{
		cin >> seq[n];
		seq[n] -= (n+1);
	}
	sort(seq.begin(), seq.end());
	LL d = 0;
	for (int n = 0; n < N; n++)
		d += abs(seq[n] - seq[N/2]);
	cout << d << endl;
}



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

using namespace std;
int w,h,x,y;
int main()
{
    //freopen("C.inp","r",stdin);
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> w >> h >> x >> y;
    int f=0;
    if (2*x==w&&2*y==h) f=1;
    cout << setprecision(10) << (double)(((double)w*(double)h)/2.0) << " " << f;
}


Measured memory_bytes: 256
import math
i = list(map(int, input().split()))
a, b, x = i[0], i[1], i[2]

y = (a**2) * b / 2
if y <= x:
    ans = math.degrees(math.atan((2*((a**2)*b-x))/(a**3)))
else:
    ans = math.degrees(math.atan(a*(b**2)/(2*x)))

print(ans)

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

int main(){
  string X;
  cin >> X;
  
  int i = 0;
  while(i < X.size() - 1){
    if(X.at(i) == 'S' && X.at(i + 1) == 'T'){
      X.erase(X.begin() + i, X.begin() + i + 2);
      if(i > 0) i--;
    }
    else{
      i++;
    }
    if(X.size() == 0) break;
  }
  
  cout << X.size() << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

#define MAX_N 100000

using namespace std;

int field[MAX_N];
int dp[MAX_N + 1][2];

int n;
int k;

bool flag = false;

int ans;

void solve(){
	for(int i = 0;i < MAX_N;i++){
		dp[i][0] = 1;
		dp[i][1] = 2;
	}

	sort(field,field + k);

	for(int i = 0;i < k;i++){
		if(field[i + 1] == field[i] + 1){
			dp[i + 1][0] = max(dp[i + 1][0],dp[i][0] + 1);
			dp[i + 1][1] = max(dp[i + 1][1],dp[i][1] + 1);
		}
		else if(field[i + 1] == field[i] + 2){
			dp[i + 1][1] = max(dp[i + 1][1],dp[i][0] + 2);
		}
	}

	ans = 0;
	for(int i = 0;i < k;i++){
		ans = max(ans,dp[i][0]);
	}
	if(flag){
		for(int i = 0;i < k;i++){
			ans = max(ans,dp[i][1]);
		}
	}

	return ;
}

int main (){

	while(true){

	scanf("%d%d",&n,&k);
	if(n == 0 && k == 0)break;
	flag = false;
	for(int i = 0;i < k;i++){
		scanf("%d",field + i);
		if(field[i] == 0) flag = true;
	}

	solve();

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

	return 0;
}

Measured memory_bytes: 2300
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
int main()
{
    fast;
    ll n;
    cin>>n;
    ll a[n];
    f(i,n)
    {
        cin>>a[i];
    }
    ll dp[n];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(ll i=2;i<n;i++)
    {
        dp[i]=min((dp[i-1]+abs(a[i]-a[i-1])),(dp[i-2]+abs(a[i]-a[i-2])));
        //cout<<dp[i]<<endl;
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;

#define MOD 998244353


ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}
  
  

int main(){
    ll a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    ll n=5;
    
    vector <ll> time {a,b,c,d,e};
    vector <ll> nexttime(n);
    
    for (ll i= 0; i < n; i++){
        if(time[i]%10 == 0)nexttime[i] = time[i];
        else nexttime[i] = time[i] - time[i]%10 + 10;
    }
    
    ll besttime = 1e9;
    for (ll i = 0; i < n; i++){
        ll sumtime = 0;
        for(ll j = 0; j < n;j++){
            if(i == j){
                sumtime += time[j];
            }
            else {
                sumtime += nexttime[j];
            }
        }
        besttime = min(besttime, sumtime);
    }
    cout << besttime << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	long long a,b,i;
	while(cin>>a>>b){
		for(i=a;i<2000000000;i+=a){
			if(i%b==0)break;
		    }
		    cout<<a*b/i<<" "<<i<<endl;
		}
	return 0;
	}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }



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

  ll ans = a[0] - 1, res = 2;
  FOR(i, 1, n) {
    if (a[i] == res) {
      res++;
    }
    else if (a[i] > res) {
      ans += (a[i] - 1) / res;
    }
  }
  cout << ans << endl;

  


  
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = pow(10,9) + 7;

int main(){
	ll N,M;
	cin >> N >> M;
	vector<ll> S(N),T(M);
	for(ll i(0);i<N;++i){
		cin >> S[i];
	}
	for(ll i(0);i<M;++i){
		cin >> T[i];
	}
	ll dp[N][M],sum[N+1][M+1],ans(1);
	for(ll i(0);i<N+1;++i){
		for(ll j(0);j<M+1;++j){
			if(i == 0 || j == 0){
				sum[i][j] = 1;
			}else{
				if(S[i-1] != T[j-1]){
					dp[i-1][j-1] = 0;
				}else{
					dp[i-1][j-1] = sum[i-1][j-1]%MOD;
					ans += dp[i-1][j-1];
					ans %= MOD;
				}
				sum[i][j] = (sum[i][j-1] + sum[i-1][j] - sum[i-1][j-1] + dp[i-1][j-1] + MOD)%MOD;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 62848
#include <bits/stdc++.h> 
using namespace std;
#define ll long long 
#define f(i, a, b) for(ll i=a;i<b;i++)
#define fi(i, a, b) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define ml map<ll,ll> 
#define pll pair<ll,ll>

ll M = (ll)(1e9+7);

void solve()
{
    ll n;
    cin>>n;
    int a[n][n];
    f(i,0,n)
    f(j,0,n)cin>>a[i][j];
    // cout<<"1\n";

    vector<vector<int>> dp(n+1,vector<int>(1<<n,0));
    // memset(dp, 0, sizeof dp);
    // dp[0][0]=1;
    for(ll i=0;i<(1<<n);i++)
    {
        // cout<<i<<" ";
        if(__builtin_popcount(i)==1 )
        {
            f(k,0,n)
            {
                // cout<<k<<" ";
                if(((i>>k) & 1 )==1 && a[0][k]==1)dp[1][i]++;
            }
        }
        // cout<<"\n";
    }

    f(i,1,1<<n)
    {
        // cout<<i<<" ";
        int j = __builtin_popcount(i);
        f(k,0,n)
        {
            // cout<<k<<" ";
            if(((i>>k) & 1 )==1 && a[j-1][k]==1)
            {
                dp[j][i] += dp[j-1][i - (i&(1<<k))];
                dp[j][i]%=M;
            }
        }
        // cout<<"\n";
    }
    cout<<dp[n][(1<<n)-1];
}

int main()
{
   ll t;
   t=1;
//    cin>>t;
   while (t--)
   {
       solve();
   }  
}

Measured memory_bytes: 188800
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])

  if temp!=1:
    arr.append([temp, 1])

  if arr==[]:
    arr.append([n, 1])

  return arr

n = int(input())
a = factorization(n)
c = 0
if n == 1:
  print(0)
  exit()
for d in a:
  s = d[1]
  if s > 44:
    c += 9
  elif s > 35:
    c += 8
  elif s > 27:
    c += 7
  elif s > 20:
    c += 6
  elif s > 14:
    c += 5
  elif s > 9:
    c += 4
  elif s > 5:
    c += 3
  elif s > 2:
    c += 2
  elif s > 0:
    c += 1
print(c)

Measured memory_bytes: 9512
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>

using namespace std;

int main() {
	
	long long a, b, n;
	cin >> a >> b >> n;
	long long ans = -1;

	/*for (int i = 1;i <= n;i++) {
		long long tmp = (long long)floorl(a * i / b) - a * (long long)floorl(i / b);
		ans = max(ans, tmp);
	}

	cout << ans << endl;*/

	if (n >= b - 1 && b != 1)  {
		long long i = b - 1;
		ans = (long long)floorl(a * i / b) - a * (long long)floorl(i / b);
	}
	else {
		long long i = n;
		ans = (long long)floorl(a * i / b) - a * (long long)floorl(i / b);
	}


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

Measured memory_bytes: 3584
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] in = new int[4];
		for (int i = 0; i < 4; i++) {
			String line = br.readLine();
			in[i] = Integer.parseInt(line);
		}
		if (in[0] < in[1]) {
			in[1] = in[0];
		}
		System.out.println((in[1] * in[2]) + ((in[0] - in[1]) * in[3]));
	}

}


Measured memory_bytes: 8148
/*
 * FileName:     A
 * CreatedDate:  2020-04-19 20:57:47 +0900
 * LastModified: 2020-04-19 21:05:11 +0900
 */

#include <stdio.h>

int main(void){
    double R;
    scanf("%lf",&R);
    printf("%lf\n",2*3.1415926*R);
    return 0;
}


Measured memory_bytes: 1752
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())

sys.setrecursionlimit(10 ** 9)


def main():
    A, B = MAP()
    print(A + B if B % A == 0 else B - A)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
import java.util.*;
import java.io.*;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.nio.charset.StandardCharsets;
//给出两个数a,b 求出[a,b]中各位数字之和能整除原数的数的个数。
public class Main {

    int mod ;
    void solve(int x, int y) {
        //2x1+4x2 = y
        //x1+x2 = x
        //2*(x-i)+4*i = y
        //2*i = y-2*x;
        //(y-2*x)/2<=x
        if(y<2*x){
            System.out.println("No");
        }else if((y-(2*x))%2!=0){
            System.out.println("No");
        }else if((y-2*x)/2>x){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }

    }


    public static void main(String[] args)  throws IOException {
        // Use the Scanner class

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[]  s = br.readLine().split(" ");
        Main test = new Main();
//
//        int n = Integer.parseInt(s[0]);
//        int w = Integer.parseInt(s[1]);
//        int[] volumn = new int[n];
//        int[] values = new int[n];
//        for(int i=0;i<n;i++) {
//            s = br.readLine().split(" ");
//            volumn[i] = Integer.parseInt(s[0]);
//            values[i] = Integer.parseInt(s[1]);
//        }

        test.solve(Integer.parseInt(s[0]),Integer.parseInt(s[1]));
        //int tot = Integer.parseInt(br.readLine());


//        int i =1;
//        System.out.println();
//        while(tot>0){
//
//            String s = br.readLine();
//            String[] sr = s.split(" ");
//            List<Long> ls = new ArrayList<>();
//            for(String ss:sr){
//                ls.add(Long.parseLong(ss));
//            }
//            Main tt = new Main();
//            tt.sol(ls);
//            // String Buffer to store answer
//            StringBuffer sb = new StringBuffer();
////            Solution obj = new Solution();
////
////            System.out.println("Case #"+i+": "+obj.sol());
//            tot--;
//            i++;
//        }
    }

}


Measured memory_bytes: 32656
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;

const int MAXN=100005;

int n;
int sg[MAXN];
vector<int> E[MAXN];

void dfs(int u,int fa=0){
    sg[u]=0;
    for(int i=0;i<(int)E[u].size();i++){
        int v=E[u][i];
        if(v==fa) continue;
        dfs(v,u);
        sg[u]^=(sg[v]+1);
    }
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        E[u].push_back(v);
        E[v].push_back(u);
    }
    dfs(1);
    if(sg[1]) puts("Alice");
    else puts("Bob");
}


Measured memory_bytes: 13952
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m, x = map(int, readline().split())
c = [list(map(int, readline().split())) for _ in range(n)]

ans = float('inf')
# bit全探索
for i in range(2 ** n):
    bag = [0]*(m+1)
    for j in range(n):
        if ((i >> j) & 1):
            bag = [x + y for (x, y) in zip(bag, c[j])]
        if min(bag[1::]) >= x:
            ans = min(ans, bag[0])
            
print('-1'if ans == float('inf') else int(ans))


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

namespace id_0358cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var money = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            Console.WriteLine(Debt(money));
        }
        static string Debt(int[] vs)
        {
            var myMoney = vs[0];
            var friendMoney = vs[1];
            var bookMoney = vs[2];

            if (myMoney > bookMoney) return "0";
            if (myMoney + friendMoney < bookMoney) return "NA";
            return (bookMoney - myMoney).ToString();

        }
    }
}



Measured memory_bytes: 9560
#define TEST_MODE true

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;             \
                                   c > 0 ? i < b : i > b; \
                                   i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long

#ifdef LOCAL_ENV

#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << " "
#define dumpl(x) dump(x) << endl
#else
const bool test = false;
#define dump(x) 
#define dumpl(x)
#endif

#else
const bool test = false;
#define dump(x) 
#define dumpl(x)
#endif

int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };
const int INF = (int)1 << 62;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep))
	{
		v.push_back(buffer);
	}
	return v;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
	return accumulate(begin, end, 0ll);
}

template<typename T>
T gcd(T a, T b)
{
	T c;
	while (a != 0) {
		c = a; a = b%a;  b = c;
	}
	return b;
}

template<typename T>
T bit_count(T N) {
	T cnt = 0;
	while (N) {
		if (N & 1) cnt++;
		N >>= 1;
	}
	return cnt;
}

struct Point {
	int y, x;
	bool operator < (const Point& r) {
		if (x < r.x) return true;
		else return false;
	}
};

class Solver {
public:
	string S;

	bool can() {
		bool pre_a = false;
		string S2 = "AKIHABARA";
		int i2 = 0;
		rep(i, S.size()) {
			auto& c = S[i];
			auto& c2 = S2[i2];
			// dump(c); dumpl(c2);
			if (i2 >= S2.size()) return false;
			if (c2 == 'A') {
				if (c != 'A') {
					i -= 1;
				}
			}
			else if (c != c2) return false;
			i2 += 1;
		}
		if (i2 + 1 >= S2.size()) return true;
	}

	void solve() {
		cin >> S;
		cout << (can() ? "YES" : "NO") << endl;
	}
};

signed main()
{
	srand((unsigned int)time(NULL));
	cout << fixed << setprecision(20);
	auto ptr = new Solver();
	ptr->solve();
	delete ptr;
	//while (true) {
	//	if (cin.eof() == true) break;
	//	auto ptr = new Solver();
	//	ptr->solve();
	//	delete ptr;
	//}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
#include <functional>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
int n, m, x;
string s, t;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m >> x;
    int left=0; int right=0;
    for(int i=0; i<m; ++i){
        int a; cin >> a;
        if(a<x) left++;
        else if(a>x) right++;
    }
    cout << min(right, left) << endl;
    return 0;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
// constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;




int main(){
  int x;
  cin >> x;
  cout << (x ? "0" : "1") << endl;
  return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define BASE 1000000007
using namespace std;

/*
struct Node {
    int id, can;
};
*/

int main(void) {
    int n, k;
    cin >> n >> k;
    vector<int> es[n];
    for (int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        es[a].push_back(b);
        es[b].push_back(a);
    }
    bool used[n];
    fill(used, used + n, false);
    queue<int> que;
    long ans = k;
    que.push(0);
    used[0] = true;
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        int i = k - ((v == 0) ? 1 : 2);
        for (int u: es[v]) {
            if (used[u])
                continue;
            used[u] = true;
            que.push(u);
            ans = (ans * i) % BASE;
            //cout << ans << endl;
            i--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6648
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n,m;cin>>n>>m;
    vvin ship(200010);
    rep(i,m){
        int a,b;cin>>a>>b;
        ship[a].push_back(b);
        ship[b].push_back(a);
    }
    for(auto s:ship[1]){
        for(auto l:ship[s]){
            if(l==n){
                cout<<"POSSIBLE"<<endl;
                return 0;
            }
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
}

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

int main(){
  long long N;
  while(cin >> N, N){
    long long s = 0;
    for(long long i = 1; i*i <= N; ++i){
      if(N%i) continue;
      s += i;
      if(i != N/i) s += N/i;
    }
    if(s-N < N) puts("deficient number");
    else if(s-N == N) puts("perfect number");
    else puts("abundant number");
  }
}



Measured memory_bytes: 2916
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
#define n_max 100000

#define rep(i,n) for(int i = 0; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

int main()
{
    int n,m;
    int ans = 0;
    int l_s = -1, r_s = 100100100;
    cin >> n >> m;
    vector<int> key(n,0);

    rep(i,m) {
        int l,r;
        cin >> l >> r;
        l_s = max(l_s, l);
        r_s = min(r_s, r);
        //for(int j = l; j <= r; j++) { key[j]++; }
    }
    //rep(i,n) { if(key[i] == m) { ans++; } }
    if(r_s-l_s < 0) { cout << 0 << endl; }
    else            { cout << r_s-l_s+1 << endl; }

    return 0;
}


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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  cout << s.substr(0,n-8) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
using namespace std;
using ll = long long;
ll MOD = 1e9+7;


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    int t = 1, ans = 0;
    if(B == 1){
        cout << 0 << endl;
        return 0;
    }
    while(true){
        t--;
        t += A;
        ans++;
        if(t >= B){
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

bool solve(int n, int m, const vector<int>& l, const vector<int>& r, const vector<int>& d) {
	vector<vector<pair<int, int>>> graph(n);
	for (int i = 0; i < m; i++) {
		graph[l[i]].emplace_back(r[i], d[i]);
		graph[r[i]].emplace_back(l[i], -d[i]);
	}

	vector<bool> used(n);
	vector<int> dist(n);
	for (int i = 0; i < n; i++) {
		if (used[i]) {
			continue;
		}

		queue<int> que;
		que.push(i);
		used[i] = true;
		dist[i] = 0;
		while (!que.empty()) {
			int now = que.front(); que.pop();
			for (auto e : graph[now]) {
				int next = e.first;
				int cost = e.second;

				if (used[next] && dist[now] + cost != dist[next]) {
					return false;
				} else if (!used[next]) {
					used[next] = true;
					dist[next] = dist[now] + cost;
					que.push(next);
				}
			}
		}
	}
	return true;
}

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

	int n, m;
	cin >> n >> m;

	vector<int> l(m), r(m), d(m);
	for (int i = 0; i < m; i++) {
		cin >> l[i] >> r[i] >> d[i];
		l[i]--; r[i]--;
	}

	cout << (solve(n, m, l, r, d) ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 11776
#include <iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
for (int i=0;i<10000;i++)
{
int za=i*8 /100;
int zb=i*10/100;
if(za==a&&zb==b){cout <<i;return 0;}

}
cout <<-1;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

int main() {
  ll N, A, B, ans = 0;
  cin >> N >> A >> B;

  
  ll C = N/(A+B);
  ll D = N - (A+B)*C;
  ans = A * C + min(D, A);
  
  
  cout << ans << endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000



int main(){

  while(true){
    int n;
    scanf("%d\n", &n);
    if(n==0)break;

    bool r=false, l=false; // false: on floor.
    bool last=false;
    int cnt=0;
    rep(i,n){
      char a,b;
      scanf("%c%c ", &a, &b);
      if(a=='r' && b=='u') r=true;
      else if(a=='r' && b=='u') r=true;
      else if(a=='r' && b=='d') r=false;
      else if(a=='l' && b=='u') l=true;
      else if(a=='l' && b=='d') l=false;

      if(last!=r && last!=l){
	cnt++;
	last=!last;
      }
    }
    cout << cnt << endl;

  }

}

Measured memory_bytes: 1212
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <functional>
#include <ctime>
#include <queue>
#include <string>
#include <map>
#include <utility>
#include <sstream>
#include <cmath>
#define MAX_U   10
#define MIN_U   0
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define form(i,a,b) for(int i=(a);i<(b);i++)
#define sz(x) ((int)(x).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<char> vc;
typedef vector<string> vs;
typedef queue<int> qi;
const int INF=numeric_limits<int>::infinity();
void printa(){cout<<"\n";}
template<class T, class... A>void printa(const T&first,const A&... rest){cout<<first;printa(rest...);}
template<class... A>void printa(const A&... rest){printa(rest...);}
void prints(){cout<<" ";}
template<class T, class... A>void prints(const T&first,const A&... rest){cout<<first;prints(rest...);}
template<class... A>void prints(const A&... rest){prints(rest...);}
int factorial(int x){int f=1;for(int i=1;i<x+1;i++)f=f*i;return f;}
int sigma(int x){int s;for(int i=1;i<x+1;i++)s=s+i;return s;}
int middle(int x){if(x%2==0)return x/2;else return x/2+1;}
double heron(int a,int b,int c){double s;s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}
double trapezium(int a,int b,int h){return (a+b)*h/2;}
double triangle(int a,int h){return a*h/2;}
void sorm(vector<int> vec){sort(vec.begin(),vec.end());}
void sorg(vector<int> vec){sort(vec.begin(),vec.end(),greater<int>());}
int cmp( const void *p, const void *q ) {if( *(double*)p > *(double*)q ) return 1;if( *(double*)p < *(double*)q ) return -1;return 0;}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //int a,b,c,d;
    string st;
    //vi ad,bd,cd,dd;
    //vs as,bs,cs,ds;
    cin>>st;
    if(st=="a"||st=="e"||st=="i"||st=="o"||st=="u")printa("vowel");
    else printa("consonant");
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
// bool operator<(const pair<int, int> &a, const pair<int, int> &b)
// {
//     if (a.first == b.first)
//         return a.second < b.second;
//     return a.first < b.first;
// };

/*unsigned int xor128(void)
{
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
unsigned int xor128rnd(unsigned int m)
{
    return xor128() % m;
}*/

/*bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return a.second < b.second;
    }
    return a.first < b.first;
}*/

string arr[10010];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(8);

    string s;
    cin >> s;
    if ((int)s.size() == 1)
    {
        cout << "YES" << endl;
        return 0;
    }
    int a = count(s.begin(), s.end(), 'a');
    int b = count(s.begin(), s.end(), 'b');
    int c = count(s.begin(), s.end(), 'c');
    int arr[3] = {a, b, c};
    sort(arr, arr + 3);
    if ((arr[2] == arr[1] + 1 && arr[1] == arr[0]) || (arr[2] == arr[1] && arr[0] == arr[1] - 1) || (arr[2] == arr[1] && arr[1] == arr[0]))
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
    
using namespace std;
bool sortin(const pair<ll,ll> &a,  
               const pair<ll,ll> &b) 
{ 
       return (a.first < b.first); 
} 
bool isPrime(ll k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    ll i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}
 
ll de(ll N) 
{ 
  
    // To store the binary number 
    ll B_Number = 0; 
    ll cnt = 0; 
    while (N != 0) { 
        int rem = N % 2; 
        ll c = pow(10, cnt); 
        B_Number += rem * c; 
        N /= 2; 
  
        // Count used to store exponent value 
        cnt++; 
    } 
  
    return B_Number; 
} 
  
  
int main(){
    IOS;
char x;cin>>x;
if(x-'a'>=0&&x-'a'<=25) cout<<"a";else cout<<"A";

    return 0;}

Measured memory_bytes: 3692
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i, a, b) for(int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b) for(int i = (a), i##_end_ = (b); i >= i##_end_; --i)

typedef long long LL;
const int Maxn = (int)(1e6);
LL a[Maxn], b[Maxn], n, ans;
int main() {
	scanf("%lld", &n);
	rep(i, 1, n) 
		scanf("%lld%lld", &a[i], &b[i]);
	drep(i, n, 1) {
		a[i] += ans;
		if(a[i] % b[i] == 0) 
			ans += a[i] / b[i] * b[i] - a[i];
		else 
			ans += (a[i] / b[i] + 1) * b[i] - a[i];
	}
	printf("%lld\n", ans);
	return 0;
}
			

Measured memory_bytes: 4992
#include<iostream>
#include<queue>
#include<map>
#include<array>
using namespace std;
array<string,6>s;
bool check(string s)
{
	return s[6]=='*'||s[7]=='*'||s[8]=='*';
}
string rotate(string s,int dir)
{
	string ret="";
	if(dir==0)ret=s;
	else if(dir==1)
	{
		ret+=s[6];
		ret+=s[3];
		ret+=s[0];
		ret+=s[7];
		ret+=s[4];
		ret+=s[1];
		ret+=s[8];
		ret+=s[5];
		ret+=s[2];
	}
	else if(dir==2)
	{
		for(int i=9;i--;)ret+=s[i];
	}
	else if(dir==3)
	{
		ret+=s[2];
		ret+=s[5];
		ret+=s[8];
		ret+=s[1];
		ret+=s[4];
		ret+=s[7];
		ret+=s[0];
		ret+=s[3];
		ret+=s[6];
	}
	return ret;
}
main()
{
	string input;
	while(cin>>input,input!="#")
	{
		string input2,input3;
		cin>>input2>>input3;
		s[0]=input+input2+input3;
		for(int i=1;i<6;i++)
		{
			cin>>input>>input2>>input3;
			s[i]=input+input2+input3;
		}
		map<array<string,6>,int>M;
		M[s]=0;
		queue<array<string,6> >P;
		P.push(s);
		while(true)
		{
			array<string,6>t=P.front();P.pop();
			int now=M[t];
			if(check(t[0])&&check(t[2]))
			{
				cout<<now<<endl;
				break;
			}
			{
				array<string,6>nxt;
				nxt[0]=rotate(t[5],0);
				nxt[1]=rotate(t[1],1);
				nxt[2]=rotate(t[4],2);
				nxt[3]=rotate(t[3],3);
				nxt[4]=rotate(t[0],0);
				nxt[5]=rotate(t[2],2);
				if(M.find(nxt)==M.end())
				{
					M[nxt]=now+1;
					P.push(nxt);
				}
			}
			{
				array<string,6>nxt;
				nxt[0]=rotate(t[4],0);
				nxt[1]=rotate(t[1],3);
				nxt[2]=rotate(t[5],2);
				nxt[3]=rotate(t[3],1);
				nxt[4]=rotate(t[2],2);
				nxt[5]=rotate(t[0],0);
				if(M.find(nxt)==M.end())
				{
					M[nxt]=now+1;
					P.push(nxt);
				}
			}
			{
				array<string,6>nxt;
				nxt[0]=rotate(t[0],1);
				nxt[1]=rotate(t[4],1);
				nxt[2]=rotate(t[2],3);
				nxt[3]=rotate(t[5],1);
				nxt[4]=rotate(t[3],1);
				nxt[5]=rotate(t[1],1);
				if(M.find(nxt)==M.end())
				{
					M[nxt]=now+1;
					P.push(nxt);
				}
			}
			{
				array<string,6>nxt;
				nxt[0]=rotate(t[0],3);
				nxt[1]=rotate(t[5],3);
				nxt[2]=rotate(t[2],1);
				nxt[3]=rotate(t[4],3);
				nxt[4]=rotate(t[1],3);
				nxt[5]=rotate(t[3],3);
				if(M.find(nxt)==M.end())
				{
					M[nxt]=now+1;
					P.push(nxt);
				}
			}
		}
	}
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n,k; cin>>n>>k;
	int maxi=(n-2)*(n-1)/2;
	if(k>maxi){
		cout<<-1<<endl;
		return 0;
	}
	vector<int> u,v;
	for(int i=2;i<=n;i++){
		u.push_back(1);
		v.push_back(i);
	}
	int nn=maxi-k;
	int from=2;
	while(nn>0){
		bool flg=0;
		for(int to=from+1;to<=n;to++){
			u.push_back(from);
			v.push_back(to);
			nn--;
			if(nn==0){
				flg=1;
				break;
			}
		}
		from++;
		if(flg) break;
	}
	int m=u.size();
	cout<<m<<endl;
	rep(i,m){
		cout<<u[i]<<" "<<v[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 384