akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define lli unsigned long long int
#define MOD 1000000007
#define DEBUG 0
#define REP(i,n) for(int i=0;i<n;i++)

using pii=pair<lli,lli>;

lli pa[100001],n;
vector<pii> xp,yp;

struct edge{
	lli u,v,w;
	edge(){}
	edge(lli u,lli v,lli w):u(u),v(v),w(w){}
	bool operator < (const edge &rhs)const{
		return w < rhs.w;
	}
};

vector<edge> ev;

void add(vector<pii> &arr){
	for(lli i=0;i<arr.size()-1;i++)ev.push_back(edge(arr[i].se,arr[i+1].se,arr[i+1].fi-arr[i].fi));
}

int find(int cur){return cur==pa[cur] ? cur:pa[cur]=find(pa[cur]);}

bool merge(lli u,lli v){
	u = find(u);
	v = find(v);
	if(u==v)return false;

	pa[v] = u;
	return true;
}

int main(){

	cin>>n;
	REP(i,n){
		lli x,y;
		cin>>x>>y;
		xp.push_back(pii(x,i));
		yp.push_back(pii(y,i));
	}
	sort(xp.begin(),xp.end());
	sort(yp.begin(),yp.end());

	add(xp);
	add(yp);

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

	lli ans = 0;
	REP(i,n)pa[i]=i;
	for(auto &e:ev){
		if(merge(e.u,e.v)){
			ans += e.w;
		}
	}

	cout<<ans<<endl;

	return 0;
}
 

Measured memory_bytes: 13024
#include <iostream>

using namespace std;

int main() {

    while (1){
        int x, y, z;
        cin >> x >> y;
        
        if (x == 0 && y == 0){
            break;
        }else if (x > y){
            z = y;
            y = x;
            x = z;
            cout << x << " " << y << endl;
        }else{
            cout << x << " " << y << endl;
        }
        
    }
    
    
    return 0;
}

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

int main(){
	int n;
	for(int i_=1 ; scanf("%d", &n) , n ; ++i_ ){
		double x[100],y[100];
		for(int i=0 ; i < n ; i++ ){
			scanf("%lf %lf", &x[i], &y[i]);
		}
		x[n] = x[0];
		y[n] = y[0];
		double s=0.0;
		for(int i=0 ; i <= n-1 ; i++ ){
			s += ( x[i] - x[i+1] ) * ( y[i] + y[i+1] );
		}
		s = fabs( s/2.0 );
		printf("%d %.1f\n", i_ , s );
	}
}

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 500100, MAXK = 30;
const ll MOD = 1e9+7;
const ll INF = 1e18;
const ld PI = asin(1) * 2;

//ll dp[MAXN][3];
string t;
int n, k;
ll r, s, p;
int played[MAXN];

int main()
{
    FAST_IO;

    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;

    ll ans = 0;
    FOR(i, 1, n) {
        char c = t[i-1];
        if (c == 's' && (i <= k || played[i-k] != 1)) {
            ans += r;
            played[i] = 1;
        }
        if (c == 'r' && (i <= k || played[i-k] != 2)) {
            ans += p;
            played[i] = 2;
        }
        if (c == 'p' && (i <= k || played[i-k] != 3)) {
            ans += s;
            played[i] = 3;
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 848
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int a,b,c,x; cin>>a>>b>>c>>x;
    int ans=0;
    rep(i,a+1){
        rep(j,b+1){
            rep(K,c+1){
                if(x==i*500+j*100+K*50) ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
  int A, B, temp,sum=0;
  cin >> A;
  cin >> B;
  
  if(A<B){
    temp = B;
    B=A;
    A=temp;
  }
  sum +=A;
  if(A-1>B){
    sum +=A-1;
    cout << sum <<endl;
    return 0;
  }else{
    sum += B;
    cout << sum << endl;
    return 0;
  }
  return 0;
}

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

int main(){
    int nGroup, nPeople;
    nPeople = 0;

    int tmp[2];

    cin >> nGroup;

    for(int i = 0; i < nGroup; i++){
        cin >> tmp[0] >> tmp[1];
        nPeople += tmp[1] - tmp[0] + 1;
    }

    cout << nPeople;

    return 0;
}




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

int main(){
    using namespace std;
    unsigned long N, M, K;
    cin >> N >> M >> K;
    vector<unsigned long> A, B{0};
    copy_n(istream_iterator<unsigned long>(cin), N, back_inserter(A));
    copy_n(istream_iterator<unsigned long>(cin), M, back_inserter(B));
    partial_sum(begin(A), end(A), begin(A));
    partial_sum(begin(B), end(B), begin(B));
    A.erase(upper_bound(begin(A), end(A), K), end(A));
    B.erase(upper_bound(begin(B), end(B), K), end(B));
    A.push_back(2 * K);
    unsigned long ans{0};
    for(unsigned long i{0}; i < B.size(); ++i)ans = max<unsigned long>(ans, i + upper_bound(begin(A), end(A), K - B[i]) - begin(A));
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define IOS ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);

#define endl "\n";


#define mod 1000000007
#define loop(i,s,n)  for(ll i=s;i<n;i++)
#define test  ll t; cin>>t; while(t--)
#define p push_back
typedef long long ll;
ll gcd(ll a,ll b)
{
    if(a==0)
{return b;}

else
    {return gcd(b%a,a);}
}
int main()
{IOS
ll  n,i,j,k,sum=0,f=0;
cin>>n;
ll a[n]={0};
for(i=0;i<n;i++)
{cin>>a[i];}
ll m[1000001]={0};
for(i=0;i<n;i++)
{k=a[i];

for(j=2;j<=sqrt(k);j++)
{if(k%j==0)
{if(k/j!=j)
{
	m[k/j]++;
	
m[j]++;
if(m[j]>1||m[k/j]>1)
{break;}
	
}
else{m[j]++;
	if(m[j]>1)
	{break;}
}}}
if(a[i]!=1)
{m[a[i]]++;}
if(m[a[i]]>1)
{break;}
}
ll b=1000001;
sort(m,m+b);
if(m[1000000]>1)
{
    f=1;
}
if(f==0)
{
    cout<<"pairwise coprime";
}

if(f==1)
{
  ll g=a[0];
  for(i=1;i<n;i++)
  {g=gcd(g,a[i]);


  }
        if(g==1)
        {f=2;
            cout<<"setwise coprime";}
        }

        if(f==1)
        {
            cout<<"not coprime";}

return 0;
}


Measured memory_bytes: 19200
#!/usr/bin/env perl
use strict;
use warnings;

my $n = <>;
my $c = 0;
my $ma = 0;
for my $ch (split //, <>) {
  $c++ if $ch eq 'I';
  $c-- if $ch eq 'D';
  $ma = $c if $ma < $c;
}
print $ma;


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long n;
long long a,b;
long long sum,ans;
bool pd=1;
int main()
{
	cin>>n;
	sum=(1ll<<62);
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b;
		if(a!=b)pd=0;
		ans+=a;
		if(a>b)sum=min(sum,b);
	}
	if(pd)puts("0");
	else cout<<ans-sum<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint unsigned long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++)
#define DUMP(ar) for(auto itd=begin(ar); itd != end(ar); itd++) cout << "["s << itd - begin(ar) << "]:"s << *itd << endl
#define DUMPL(ar) for(auto itd=begin(ar); itd != end(ar); itd++) { cout << *itd; if(end(ar)-itd > 1) cout << ' '; } cout << endl
#define COUT(x) cout << (x) << endl
#define VCIN(ar) for(auto &vcin: (ar)) cin >> vcin
#define ALL(ar) ar.begin(), ar.end()
#define LOOPD(i) cout << "ループ["s << i << "]回目---------------"s << endl
using namespace std;
// lint:64ビット 10^19

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

    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    VCIN(h);
    sort(ALL(h), greater<int>());

    lint cnt = 0;

    for(int i=0; i<n; i++){
        if(i >= k){
            cnt += h[i];
        }
    }

    COUT(cnt);

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define DIV 1000000007
using namespace std;
using ll= long long;


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

    if (s[2] == s[3] && s[4] == s[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;


    

}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(){
    ll res = 0;
    ll X,Y; cin >> X >> Y;
    while(X<=Y){
        res++;
        X *= 2;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define INF 1000000009
typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int ll

signed main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    int A[114514],B[114514];
    int Asum=0;
    int num=0;
    cin >> N;
    int M=N*(N+1)/2;
    REP(i,N){
        cin >> A[i];
        Asum+=A[i];
    }
    if(Asum%M!=0){cout << "NO" << endl;return 0;}
    M=Asum/M;
    REP(i,N){
        B[i]=A[i]-A[(i+1+N)%N];
        B[i]+=M;
    }
    //REP(i,N){cout << B[i] << " ";}
    REP(i,N){
        if(B[i]%N!=0){
            cout << "NO" << endl;
            return 0;
        }else{
            if(B[i]/N>0){
                num+=B[i]/N;
            }
        }
    }
    if(num!=M){cout << "NO" << endl;return 0;}
    cout << "YES" << endl;
  return 0;
}


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

void solve(int n, int l, int r) {
	vector<int> a(n);
	REP(i,0,n) cin >> a[i];
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	int mx = 0, ans = 0;
	REP(i, l, r + 1) {
		if (mx <= a[i - 1] - a[i]) {
			mx = a[i-1]-a[i];
			ans = i;
		}
	}
	cout << ans << endl;
}

signed main(){
	int n, l, r;
	while (cin >> n >> l >> r,n) {
		solve(n,l,r);
	}
	return 0;
}



Measured memory_bytes: 3096
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    StringBuilder s = new StringBuilder();
    
    int n = in.nextInt();
    int[] array = new int[n];
    
    for (int i = n - 1; i >= 0; i--) {
      array[i] = in.nextInt();
    }
    
    for (int i = 0; i < n; i++) {
      s.append(array[i]);
      if (i != n - 1) s.append(" ");
    }
    System.out.println(s.toString());
  }
}

Measured memory_bytes: 18268
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b,c,k;
	string ans="No";
    cin>>a>>b>>c;
    cin>>k;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k-i;j++){
            for(int l=0;l<=k-i-j;l++){
                int A,B,C;
                A=a*pow(2,i);
                B=b*pow(2,j);
                C=c*pow(2,l);
                if(C>B&&B>A){
                  
                    ans="Yes";
                }
            }
        }
    }
    cout<<ans;

}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

ll arr[MX];

int main() {

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

    int n; cin >> n;

    ll sum = 0;
    F0R(i, n) {
        cin >> arr[i];

        sum += arr[i];
    }

    int Q; cin >> Q;

    while(Q--) {
        int p, x; cin >> p >> x;

        cout << sum-arr[p-1]+x << "\n";
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n) ; ++i)
#define sz(v) (ll)(v).size()
#define int long long

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int n; cin >> n;
        string str; cin >> str;
        int an = 0;
        str += '#';
        lp(i, n) {
                if (str[i] == str[i + 1]) continue;
                else an++;
        }
        cout << an;
return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define fr(i,x,y) for(int i=x;i<=y;++i)
#define rf(i,x,y) for(int i=x;i>=y;--i)
#define LL long long
using namespace std;
const int N=1e5+10,M=1e5;
int a[N];
struct data{
	int id,w;
}b[N],zz[5];
int vis[N];

bool cmp(data x,data y){
	return x.w>y.w;
}

int main(){
	int n;scanf("%d",&n);
	int ans=0,res=0;
	fr(i,1,n) scanf("%d",&a[i]);
	for(int i=1;i<=n;i+=2) vis[a[i]]++;
	fr(i,1,M) b[++res].id=i,b[res].w=vis[i];
	sort(b+1,b+1+res,cmp);
	zz[1]=b[1],zz[2]=b[2];
	memset(vis,0,sizeof vis);
	for(int i=2;i<=n;i+=2) vis[a[i]]++;
	res=0;
	fr(i,1,M) b[++res].id=i,b[res].w=vis[i];
	sort(b+1,b+1+res,cmp);
	zz[3]=b[1],zz[4]=b[2];
	int maxn=0;
	fr(i,1,2) fr(j,3,4){
		if(zz[i].id!=zz[j].id) maxn=max(maxn,zz[i].w+zz[j].w);
	}
	cout<<n-maxn<<endl;
	return 0;
}

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

typedef long long ll;
typedef vector<int> vec;

const int MAX = 1111111;

int main() {
    int N; cin >> N;
    vec A(N);
    for(auto &i : A) cin >> i;

    int M; cin >> M;
    vec B(M);
    vector<ll> C(M);
    for(auto &i : B) cin >> i;
    for(auto &i : C) cin >> i;

    vector<ll> V(MAX);
    for(int i = 0; i < N; i++) {
        V[A[i]]++;
    }
    V[0] = 0;
    for(int i = 1; i < MAX; i++) {
        V[i] = V[i] * i + V[i-1];
    }
    for(int i = 0; i < M; i++) {
        if(V[B[i]] >= C[i]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

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

int main(){
  int n,c;
	while(cin >> n,n){
		c=0;
		while(n!=1){
			if(n%2==0) n=n/2;
			else n=n*3+1;
			c++;
		}
		cout << c << endl;
	}
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  string s;
  cin >> s;
  int l = s.size();

  int a=0, b=0, c=0;
  rep(i,l) {
    if (s[i] == 'a') a++;
    else if (s[i] == 'b') b++;
    else c++;
  }
  if (abs(a-b)<=1 && abs(b-c)<=1 && abs(c-a)<=1) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    string s;
    ll ans = 700;
    cin >> s;
    rep(i, s.length()){
        if(s[i] == 'o'){
            ans += 100;
        }
    }
    cout << ans << endl;
}

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

int main() {
    int n,x,y;
    cin >> n >> x >> y;

    vector<vector<int>> dist;

    rep(i,n){
        vector<int> adist(n);
        rep(j,n){
            if(i>j){
                adist[j] = dist[j][i];
                continue;
            }
            int ld = abs(x-(i+1));
            int rd = abs(y-(j+1));
            int cd = j-i;
            if(cd < ld + rd + 1){
                adist[j] = cd;
            }
            else{
                adist[j] = ld + rd + 1;
            }
        }
        dist.push_back(adist);
    }

    vector<int> ct(n-1);
    rep(i,n){
        for(int j=i+1; j<n; j++){
            ct[dist[i][j]-1]++;
        }
    }
    rep(i,n-1){
        cout << ct[i] << endl;
    }
    // for(vector<int> v : dist){
    //     for(int a : v){
    //         cout << a << " ";
    //     }
    //     cout << endl;
    // }
}

Measured memory_bytes: 17920
from math import sqrt

N = int(input())
count = 0
for i in range(int(sqrt(N)), 0, -1):
    if N % i == 0:
        smallA = i
        break

bigA = N / smallA

while True:
    bigA /= 10
    count += 1
    if bigA < 1:
        break
print(count)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;
  n = n * 100;
  ll ans = 0;
  while(n > 0) {
    ll money;
    if(n >= 200) {
      n -= 200;
      money = min({q * 8, h * 4, s * 2, d});
    } else if(n >= 100) {
      n -= 100;
      money = min({q * 4, h * 2, s});
    } else if(n >= 50) {
      n -= 50;
      money = min(q * 2, h);
    } else {
      n -= 25;
      money = q;
    }
    ans += money;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;

	char buf[L], *S , *T, c;

	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}

	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}

	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	char B[45], *outs=B+40, *outr=B+40;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;

		if(!a)*--outs = '0';
		else
			while(a)
				*--outs = (a % 10) + 48, a /= 10;

		if(x)
			*--outs = x;

		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
//using i128 = __int128_t;
//using u128 = __uint128_t;
using i128 = i64;
using u128 = u64;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll px, py;
	ll d = exgcd(b, a%b, px, py);
	x = py;
	y = px-a/b*py;
	return d;
}

template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}

template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}

const int MOD = 1000000007;
const int INF = 1000000000;
const int MAXN = 100010;

int n, k;

void solve()
{
	int cur = (n-1)*(n-2)/2;
	if (cur < k)
	{
		puts("-1");
		return;
	}
	printf("%d\n", n-1+(cur-k));
	for (int i = 2; i <= n; ++ i)
		printf("%d %d\n", 1, i);
	for (int i = 2; i <= n; ++ i)
		for (int j = i+1; j <= n; ++ j)
		{
			if (cur == k) continue;
			cur --;
			printf("%d %d\n", i, j);
		}
}

int main()
{
	
	cin >> n >> k;
	solve();
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
	int d, t, s;
	cin >> d >> t >> s;
	if ((ll)t * s >= d) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;

//cout << N%10 << endl;
//cout << (N/10)%10 << endl;
//cout << ((N/10)/10)%10 << endl;
//cout << (((N/10)/10)/10)%10 << endl;
 
  if (
N%10 == (N/10)%10 && (N/10)%10 == ((N/10)/10)%10
)
  {
    cout << "Yes" << endl;
  }
  else if (
 (N/10)%10 == ((N/10)/10)%10 && ((N/10)/10)%10 == (((N/10)/10)/10)%10
 )
  {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;
fn main() {
    input! {
        N: usize, 
        A: usize,
        B: usize,
        h: [usize; N],
    }

    let mut max = 1_000_000_000;
    let mut min = 1;
    while min < max {
        let t = (max + min) / 2;
        let times = h.iter()
        .fold(0, |acc, hi| acc + (hi.saturating_sub(t*B)+A-B-1)/(A-B));
        if times <= t {
            max = t;
        } else {
            min = t+1;
        }
    }
    println!("{}", max);
}

Measured memory_bytes: 4352
// https: //atcoder.jp/contests/dp/tasks/dp_a

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define em emplace_back
#define M 1000000007
ll minReq(ll a[], ll n);
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	ll a[n+1];
	a[0] = 0;
	for (int i = 1; i <= n;i++){
		cin >> a[i];
	}
	ll min = minReq(a, n);
	cout << min;
}

ll minReq(ll a[], ll n){
	ll dp[n + 1];
	dp[1] = 0;
	dp[2] = abs(a[2] - a[1]);
	for (ll i = 3; i <= n;i++){
		dp[i] = min(dp[i-1]+abs(a[i] - a[i - 1]), dp[i-2]+abs(a[i] - a[i - 2]));
	}
	return dp[n];
}

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

int main(){
	int n;
	cin >> n;
	int odd = 0;
	if(n <= 9){
		odd = n;
	}else if(n < 99){
		odd = 9;
	}else if(n < 999){
		odd = 9 + (n-99);
	}else if(n <= 9999){
		odd = 909;
	}else if(n < 99999){
		odd = 909 + (n - 9999);
	}
	else if(n >= 99999){
		odd = 90909;
	}
	cout << odd << endl;
	return 0;
}


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

const ll INF = 1LL << 60;

ll N;
vector<ll> A;
int main() {
    cin >> N;
    A.resize(N);
    rep(i, N) cin >> A[i];

    multiset<ll> s;
    rep(i, N) {
        auto iter = s.lower_bound(A[i]);
        if (iter != s.begin()) {
            iter--;
            s.erase(iter);
        }
        s.insert(A[i]);
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 8584
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int H, W, N; cin >> H >> W >> N;
    set<pair<int,int>> V;
    set<pair<int,int>> S;
    int d[][2] = {
        {-1,-1}, {0, -1}, {1, -1},
        {-1, 0}, {0,  0}, {1,  0},
        {-1, 1}, {0,  1}, {1,  1}
    };
    rep (i,N) {
        int a, b;
        cin >> a >> b;
        V.insert({b,a});
        for (auto dp : d) {
            int nx = b + dp[0];
            int ny = a + dp[1];
            if (nx < 1 || nx > W) continue;
            if (ny < 1 || ny > H) continue;
            S.insert({nx,ny});
        }
    }

    vector<ll> res(10, 0);
    for (auto p : S) {
        int x,y;
        x = p.first; y = p.second;
        int cnt = 0;
        for (auto dp : d) {
            int nx = x + dp[0];
            int ny = y + dp[1];
            if (nx < 1 || nx > W) {cnt = 0; break;}
            if (ny < 1 || ny > H) {cnt = 0; break;}
            if (V.count({nx, ny}) > 0) cnt++;
        }
        res[cnt]++;
    }
    res[0] = 0;
    res[0] = (ll)(H - 2) * (W - 2) - accumulate(begin(res),end(res),0);
    rep(i,10) cout << res[i] << endl;
}


Measured memory_bytes: 47104
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int a, b, c, d;
  cin >> a;
  co(800*a-a/15*200);
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

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

R = {}
for i in range(N):
    R[i+1]=0

for i in range(M):
    a,b = map(int,input().split())
    R[a] += 1
    R[b] += 1

for i in range(N):
    print(R[i+1])

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n, m, l;
  cin >> n >> m >> l;
  int a[n][m]; int b[m][l];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < l; j++) {
      cin >> b[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      long long s = 0;
      for (int k = 0; k < m; k++) {
        s += a[i][k] * b[k][j];
      }
      if (j == l-1) {
        cout << s << endl;
      }
      else {
        cout << s << ' ';
      }
    }
  }
}




Measured memory_bytes: 3152
import bisect
from collections import defaultdict
n = int(input())
s = input()

cnt = defaultdict(list)
for i, c in enumerate(s):
    cnt[c].append(i)


def is_Lucky(x):
    x = '{:03d}'.format(x)
    if not cnt[x[0]]:
        return False
    idx = cnt[x[0]][0]
    for c in x[1:]:
        i = bisect.bisect_right(cnt[c], idx)
        if len(cnt[c]) == i:
            return False
        idx = cnt[c][i]
    else:
        return True


ans = 0
for i in range(1000):
    if is_Lucky(i):
        ans += 1
print(ans)

Measured memory_bytes: 10620
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, temp,t, n,j, a[200600],b[200010], ans;
bool cond;
char c;
string s;
int main()
{
    //I am Monim, a tiny creature of Allah
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> n;
    for(i=1;i<=n;i++)
    {
        cin >> a[i];
        b[i] = a[i];
        a[i] = a[i-1]+a[i];
    }

    for(i=1;i<n;i++)
    {
        ans += (b[i]%1000000007)*((a[n]-a[i])%1000000007);
        ans %= 1000000007;
       // cout << ans << endl;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6692
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define int long long
using namespace std;

const int P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
  double N;
  cin >> N;
  cout << N*3.141592*2 << endl;
  return 0;
}

Measured memory_bytes: 3780
import java.util.*;
public class Main
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); int k = sc.nextInt();
         int [] a = new int [n];
         for (int i = 0; i < n; i++) a[i] = sc.nextInt();
         Arrays.sort(a);
         long ans = 0;
         for (int i =0; i < k; i++) ans += a[i];
        System.out.println(ans);
    }


}

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

typedef struct {
  int k;
  int pk;
  int lk;
  int rk;
} Array;

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i + 1;
}

int main(){
  int i, H;
  Array *A;

  scanf("%d ",&H);
  A = (Array *)malloc(sizeof(Array) * (H+1));
  for(i=1; i<=H; i++){
    scanf("%d ",&A[i].k);
  }

  for(i=1; i<=H; i++){
    printf("node %d: key = %d, ",i, A[i].k);
    if(parent(i) != 0){
      A[i].pk = A[parent(i)].k;
      printf("parent key = %d, ",A[i].pk);
    }
    if(left(i) <= H){
      A[i].lk = A[left(i)].k;
      printf("left key = %d, ",A[i].lk);
    }
    if(right(i) <= H){
      A[i].rk = A[right(i)].k;
      printf("right key = %d, ",A[i].rk);
    }
    puts("");
  }



  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,k,t,c=0;
    string a;
    cin>>n>>a;
    for(i=0; i<n; i++)
    {
        if(a[i]!=a[i+1])
        {//cout<<a[i]<<" ";
            c++;

        }

    }
    cout<<c<<endl;

}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>
using namespace std;
constexpr char nl = '\n';
using ll = long long;
using boost::irange;
using boost::adaptors::reversed;
namespace rng { using namespace boost; using namespace boost::range; }
struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> auto operator>>(istream& in, C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, istream&>::type {
    for (auto& v : c) { in >> v; } return in; }
template<class C> auto operator<<(ostream& out, const C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, ostream&>::type {
    int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
constexpr auto color_s_ = "\033[2m\033[33m", color_e_ = "\033[0m";
template<class T> void trace_(const T& v) { cerr << v; }
template<class T> void trace_(const vector<vector<T>>& m) { cerr << "\n"; for (const auto& v : m) { trace_(v); cerr << "\n"; } }
template<class T> void trace_(const char* s, const T& v) { cerr << color_s_ << s << "="; trace_(v); cerr << color_e_ << "\n"; cerr.flush(); }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { cerr << color_s_; for (; *s != ','; ++s) { cerr << *s; } cerr << "="; trace_(v); cerr << ","; trace_(++s, vs...); }
#define TRACE(...) trace_(#__VA_ARGS__, __VA_ARGS__)
#else
#define TRACE(...)
#endif

int main() {
    string terms[] = { "dream", "dreamer", "erase", "eraser" };
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    for (auto& t : terms) reverse(t.begin(), t.end());
    while (!s.empty()) {
        bool cut = false;
        for (const auto& t : terms) {
            if (t.size() <= s.size() && t == s.substr(0, t.size())) {
                s = s.substr(t.size());
                cut = true;
            }
        }
        if (!cut) break;
    }
    puts(s.empty() ? "YES" : "NO");
}


Measured memory_bytes: 512
while True:
    m,f,r = map(int,input().split())
    if m == -1 and f == -1 and r == -1:
        break

    if m == -1 or f == -1:
        print('F')
    elif m + f >=80:
        print('A')
    elif m + f >=65 and m + f < 80:
        print('B')
    elif m + f >=50 and m + f < 65:
        print('C')
    elif m + f >=30 and m + f < 50:
        if r >= 50:
            print('C')
        else:
            print('D')
    elif m + f < 30:
        print('F')


Measured memory_bytes: 5596
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<int> l(N), r(N);
  rep(i, N) cin >> l[i] >> r[i];
  int ans = 0;
  rep(i, N) ans += r[i]-l[i]+1;
  cout << ans << endl;
}

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

int main(){
	int n,ma,mb;
	cin>>n>>ma>>mb;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n);
	for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
	
	vector<vector<vector<int> > > dp(50,vector<vector<int> >(500,vector<int>(500,1e9)));
	dp[0][0][0]=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<401;j++){
			for(int k=0;k<401;k++){
				if(dp[i][j][k]!=1e9){
					dp[i+1][j][k]=min(dp[i][j][k],dp[i+1][j][k]);
					dp[i+1][j+a[i]][k+b[i]]=min(dp[i][j][k]+c[i],dp[i+1][j+a[i]][k+b[i]]);
				}
			}
		}
	}
	int ans=1e9;
	for(int i=1;i<500;i++){
		for(int j=1;j<500;j++){
			if(i*mb==j*ma){
				ans=min(ans,dp[n][i][j]);
			}
		}
	}
	
	if(ans!=1e9){
		cout<<ans<<endl;
	}else{
		cout<<-1<<endl;
	}
}

Measured memory_bytes: 51200
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
    int d;
    cin>>d;
    int x;
    cin>>x;
    ll sum = 0;
    vector<mp> a;
    for(int i=0;i<x;i++){
	char tmp;
	cin>>tmp;
	int point;
	cin>>point;
	if(tmp=='D'){
	    a.push_back(mp(1,point));
	}
    }
    int y;
    cin>>y;
    for(int i=0;i<y;i++){
	string s;
	cin>>s;
	int point;
	cin>>point;
	if(s=="DD"){
	    a.push_back(mp(2,point));
	}
    }
    int n = a.size();
    vector<vector<ll> > dp( 102 , vector<ll>(n+1,(ll)inf) );
    dp[0][0] = 0;
    for(int i=0;i<n;i++){
	for(int j= 0 ; j<=100;j++){
	    dp[j][i+1] = dp[j][i];
	    if( j >= a[i].second ) dp[j][i+1] = min(dp[j][i+1],dp[j-a[i].second][i] + a[i].first);
	//    else dp[j][i+1] = 1;
	}
    }
    ll ma = 0;
 /*   for(int i=0;i<=100;i++){
	cout<<i<<' '<<dp[i][n]<<endl;
    }*/
    for(int i=0;i<=100;i++){
	if( dp[i][n] <= d){
	    ma = max(ma,(ll)i);
	}
    }
    cout<<  ma <<endl;

	return 0;
}



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

using namespace std;

using ll = long long;

constexpr char endl('\n');

#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define INF 100000000000ULL

vector<size_t> r;
vector<size_t> g;
vector<size_t> b;
size_t dp2[6][8000];

int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    size_t n, sum;
    cin >> n;
    string s;
    cin >> s;
    sum = 0;
    memset(dp2, 0, sizeof(size_t) * 6 * 8000);


    REP(i, n) {
        char c = s.at(i);
        if (c == 'R') {
            r.push_back(i);
            for (auto v : g) {
                dp2[2][2 * i - v] += 1;
            }
            for (auto v : b) {
                dp2[4][2 * i - v] += 1;
            }
            REP(j, 8000) {
                if (j != i)
                    sum += dp2[3][j] + dp2[5][j];
            }

        }
        else if (c == 'G') {
            g.push_back(i);
            for (auto v : r) {
                dp2[0][2 * i - v] += 1;
            }
            for (auto v : b) {
                dp2[5][2 * i - v] += 1;
            }
            REP(j, 8000) {
                if (j != i)
                    sum += dp2[1][j] + dp2[4][j];
            }
        }
        else if (c == 'B') {
            b.push_back(i);
            for (auto v : r) {
                dp2[1][2 * i - v] += 1;
            }
            for (auto v : g) {
                dp2[3][2 * i - v] += 1;
            }
            REP(j, 8000) {
                if (j != i)
                    sum += dp2[0][j] + dp2[2][j];
            }
        }
    }

    cout << sum << ::endl;
    

    return 0;
}


Measured memory_bytes: 4040
H, W = map(int, input().split())
T = [","*W + ",,"]  + ["," + input() + "," for _ in range(H)] + [","*W + ",,"]
ans = ""
d = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]
for i in range(1, H+1):
    for j in range(1, W+1):
        if T[i][j] == "#":
            ans += "#"
        else:
            ans += str(sum(T[i+x][j+y] == "#" for x, y in d))
    ans += "\n"
print(ans)



Measured memory_bytes: 3064
chars = 'abcdefghij'

n = int(input())

def f(gen):
    for x,s in gen:
        for i in range(x+1):
            yield (max(x,i+1), s + chars[i])

gen = [(0, "")]
for _ in range(n):
    gen = f(gen)

for __, s in gen:
    print(s)


Measured memory_bytes: 4412
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll n,n_use=1;
  string s;
  cin >> s;
  n = s.size();
  ll v = n-1;
  if(s.front()=='0'||s.back()=='1'){
    cout <<-1<<endl;
    return 0;
  }
  for(int i=0;i<n/2;i++){
    if(s[i]!=s[n-2-i]){
      cout << -1<<endl;
      return 0;
    }
  }
  s[n-1] = '1';
  for(int i=n-2;i>=0;i--){
    cout << v+1 <<" "<<i+1<<endl;
    if(s[i]=='1'){
      v = i;
    }
  }
}


Measured memory_bytes: 1616
import math

def factorize(n):
    d = {}
    temp = int(math.sqrt(n))+1
    for i in range(2, temp):
        while n%i== 0:
            n //= i
            if i in d:
                d[i] += 1
            else:
                d[i] = 1
    if d == {}:
        d[n] = 1
    else:
        if n in d:
            d[n] += 1
        elif n != 1:
            d[n] =1
    return d

n, m = map(int, input().split())

if m == 1:
    print(1)
    exit()

def cmb1(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
N = 2*10**5+5
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

d = factorize(m)
ans = 1
for v in d.values():
    ans *= cmb1(v+n-1, v, mod)
    ans %= mod
print(ans%mod)


Measured memory_bytes: 80880
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define SIZE 2010
int sum[SIZE];
int main()
{
    int n, m;
    int a[SIZE], b[SIZE];
    scanf("%d%d", &n, &m);
    for(int i=0; i<n; i++) scanf("%d", &a[i]);
    for(int i=0; i<m; i++) scanf("%d", &b[i]);
    ll ans = 0;
    for(int i=0; i<n; i++)
    {
        ll l = 0;
        for(int j=0; j<m; j++)
        {
            ll k = 0;
            if (a[i] == b[j])
            {
                k = l + 1;
                ans = (ans + k) % mod;
            }
            l = (l + sum[j]) % mod;
            sum[j] = (sum[j] + k) % mod;
        }
    }
    cout << (ans + 1) % mod << endl;
    return 0;
}


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

class Dice{
public: 
    int n[6];
    const int order[6][4] = {
                             {0, 1, 5, 4},
                             {0, 4, 5, 1},
                             {0, 3, 5, 2},
                             {0, 2, 5, 3},
                             {1, 2, 4, 3},
                             {1, 3, 4, 2}
                            };
    
    void roll(int dir);
};

void Dice::roll(int dir){
    int temp;
    
    temp = n[order[dir][0]];
    for(int i = 0; i < 4; i++){
        if(i == 3) n[order[dir][i]] = temp;
        else n[order[dir][i]] = n[order[dir][i + 1]];
    }
}

int main(){
    Dice dice1, diceX;
    int num, check_n, check_d;
    check_d = 0;
    
    cin >> num;
    
    for(int i = 0; i < 6; i++) cin >> dice1.n[i];
    
    for(int x = 0; x < num - 1; x++){
        for(int i = 0; i < 6; i++) cin >> diceX.n[i];
        
        for(int i = 0; i < 4; i++){
            diceX.roll(0);
            for(int j = 0; j < 4; j++){
                diceX.roll(2);
                
                for(int k = 0; k < 4; k++){
                    check_n = 0;
                    diceX.roll(4);
                    
                    for(int l = 0; l < 6; l++){
                        if(dice1.n[l] == diceX.n[l]) check_n++;
                        else break;
                    }
                    if(check_n == 6){
                        check_d++;
                        break;
                    }
                }
                if(check_n == 6) break;
            }
            if(check_n == 6) break;
        }
    }
    
    if(check_d == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}




Measured memory_bytes: 3108
n = int(input())
INF = 10 ** 8
dp = [INF] * 100010
dp[0] = 0

for i in range(1, n + 1):
    p = 1
    while p <= i:
        dp[i] = min(dp[i], dp[i - p] + 1)
        p *= 6

    p = 1
    while p <= i:
        dp[i] = min(dp[i], dp[i - p] + 1)
        p *= 9

print(dp[n])


Measured memory_bytes: 42220
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

uint64_t f (uint64_t i)
{
    switch (i % 4) {
        case 0:
            return i;
            break;
        case 1:
            return 1;
            break;
        case 2:
            return 1 ^ i;
            break;
        case 3:
            return 0;
        default:
            return i;
            break;
    }
}

int main (int argc, char const *argv[])
{
    uint64_t A, B;

    scanf("%"PRIu64"%"PRIu64, &A, &B);

    printf("%"PRIu64"\n", f(A - 1) ^ f(B));

    return 0;
}


Measured memory_bytes: 128
n=int(input())
lst=[int(input()) for x in range(n)]
M=sorted(set(lst))[-1]
num=lst.count(M)
if num>=2:
  for x in lst:
    print(M)
else:
  m=sorted(set(lst))[-2]
  for x in lst:
    if x==M:
      print(m)
    else:
      print(M)

Measured memory_bytes: 19112
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>


#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;

ll modd = 1000 * 1000 * 1000 + 7;


int main()   {

      ios_base::sync_with_stdio(false);

      cout.precision(17);
      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
      uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n);
        forr(i,0,n) {
            cout << "ACL";
        }                
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3540
#include <iostream>
#include <algorithm>

using namespace std;

typedef pair<int, int> P;
P p[100000];

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        int A;
        cin >> A;
        p[i] = P(A, i+1);
    }
    sort(p, p+N);
    for(int i = 0; i < N-1; i++){
        cout << p[i].second << ' ';
    }
    cout << p[N-1].second << endl;
}

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

int main() {
	//入力
	int h[2], k[2], a, b, c, d;
	cin >> h[0] >> h[1] >> k[0] >> k[1] >> a >> b >> c >> d;
	//計算&得点の算出
	int hiroshi = 0, kenjiro = 0;
	hiroshi = a * h[0] + c * (h[0] / 10) + b * h[1] + d * (h[1] / 20);
	kenjiro = a * k[0] + c * (k[0] / 10) + b * k[1] + d * (k[1] / 20);
	//出力
	if (hiroshi == kenjiro) cout << "even" << endl;
	else if (hiroshi > kenjiro) cout << "hiroshi" << endl;
	else cout << "kenjiro" << endl;
	return 0;
}


Measured memory_bytes: 3104
#include<iostream>
using namespace std;
int main(void){
      int h,w,k;
      while(1){
            cin>>h>>w;
            if(h==0&&w==0)break;
            for(int i=0;i<h;i++){
                  for(int j=0;j<w;j++){
                        k=i+j;
                        if(k%2!=0){
                              cout<<".";
                        }
                        else{
                              cout<<"#";
                        }
                  }
                  cout<<endl;
            }
            cout<<endl;
      }
      return 0;
}
      


Measured memory_bytes: 3100