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

int main() {
  int N, T, A;
  cin >> N >> T >> A;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H.at(i);
  
  int min = 1000000000;
  int number;
  for (int i = 0; i < N; i++) {
    int t = T*1000 - 6*H.at(i);
    int x;
    if (t < A*1000) x = A*1000 - t;
    else x = t - A*1000;
    if (x < min) {
      min = x;
      number = i;
    }
  }
  cout << number+1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

#define div 1000000000+7

typedef long long ll;

using namespace std;

int main(){
    ll a, b, x;
    ll sum;
    cin >> a >> b >> x;
    sum = b/x - a/x;
    if(a % x == 0){
        sum += 1;
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main (void) {
    int N;

    cin >> N;
    int A[N + 2];
    A[0] = 0;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    A[N + 1] = 0;

    int sum = 0;
    for (int i = 0; i <= N; i++) {
        sum += abs(A[i] - A[i + 1]);
    }
    for (int i = 1; i <= N; i++) {
        int a = abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i]);
        int b = abs(A[i + 1] - A[i - 1]);
        sum -= a;
        sum += b;
        cout << sum << endl;
        sum += a;
        sum -= b;
    }

    return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e15 + 5);

const int MAX_N = (int)(1e1 + 5);

ll n;
ll a[MAX_N];

ll ans;

int main(void) {
  // Here your code !
  scanf("%lld", &n);

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

  ll minimum = INF;

  for (int i = 0; i < 5; ++i) {
    minimum = min(minimum, a[i]);
  }

  ans = (n - 1) / minimum + 1 + 4;

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

  return 0;
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI a(n);
  rep(i,n) cin >> a[i];
  int ans = 0;
  int cnt = 0;
  rep(i,n-1){
    if(a[i] >= a[i+1]){
      cnt++;
      ans = max<ll>(cnt,ans);
    }else{
      cnt = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
N = int(input())
res = 1e6

for i in range(0, N + 1):
    cc = 0
    t = i
    while t > 0:
        cc += t % 6
        t //= 6
    t = N - i
    while t > 0:
        cc += t % 9
        t //= 9
    if cc < res:
        res = cc

print(res)


Measured memory_bytes: 3060
from math import gcd
k = int(input())
ar = [0] * 41000
for i in range(1, 201):
    for j in range(1, 201): ar[i*200+j] = gcd(i, j)

ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        d = ar[a*200+b]
        if d == 1:
            ans += k
            continue
        for c in range(1, k+1): ans += ar[d*200+c]
print(ans)



Measured memory_bytes: 68416
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main ()
{
	string a;
	while(cin>>a)
	{
		int sum1=0,sum2=0,sum3=0,sum=0;
		for(int i=0;i<3;i++)
		{
			if(a[i]=='a')
			   sum1=1;
			if(a[i]=='b')
			   sum2=1;
			if(a[i]=='c')
				sum3=1;	
		} 
		sum=sum1+sum2+sum3;
		if(sum==3)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl; 	
	} 	
} 	

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

vector<array<int,10>> f;
vector<array<int,11>> p;
array<bool,10> o;
int N;
int INF = 1e9+1;

int dfs(int cur)
{
    if(cur == 10)
    {
        int open_cnt = 0;
        for(auto oi:o)
            if(oi) open_cnt++;
        if(open_cnt == 0) return -INF;

        int total_p = 0;
        rep(i,N)
        {
            int same_cnt = 0;
            rep(j,10)
                if(o[j] && f[i][j]==1)
                    ++same_cnt;
            total_p += p[i][same_cnt];
        }
        return total_p;
    }
    
    o[cur] = false;
    int p0 = dfs(cur+1);
    o[cur] = true;
    int p1 = dfs(cur+1);

    return max(p0,p1);
}

int main()
{   
    cin >> N;
    f.resize(N);
    p.resize(N);
    rep(i,N) rep(j,10) cin >> f[i][j];
    rep(i,N) rep(j,11) cin >> p[i][j];
    rep(i,10) o[i] = false;

    cout << dfs(0) << endl;
    return 0;
}

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

using namespace std;
using namespace atcoder;

int main() {
	int n, q;
	scanf("%d %d", &n, &q);
	fenwick_tree<long long> fenw(n);
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		fenw.add(i, x);
	}
	for (int i = 0; i < q; i++) {
		int t, u, v;
		scanf("%d %d %d", &t, &u, &v);
		if (t) {
			printf("%lld\n", fenw.sum(u, v));
		} else {
			fenw.add(u, v);
		}
	}
	return 0;
}

Measured memory_bytes: 8220
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;

int main() {

	double N;
	cin >> N;
	double odd = 0;
	rep(i, N) {
		if ((i + 1) % 2 != 0) {
			odd++;
		}
	}

	cout << double(odd / N) << endl;
	
	return 0;
}

Measured memory_bytes: 256
use input::{Input, ReadMode};
use std::collections::HashMap;

fn main() {
    let mut input = Input::new(ReadMode::Line);

    let n = input.parse();
    let a = (0..n).map(|_| input.parse()).collect::<Vec<i64>>();

    let mut hp = HashMap::new();
    let mut hn = HashMap::new();

    for i in 0..n {
        let x = i as i64;
        let cp = hp.entry(a[i] + x).or_insert(0i64);
        *cp += 1;
        let cn = hn.entry(x - a[i]).or_insert(0i64);
        *cn += 1;
    }

    let mut ans = 0;
    for (k, v) in hp {
        if hn.contains_key(&k) {
            ans += v * hn[&k];
        }
    }
    println!("{}", ans);
}

#[allow(dead_code)]
pub mod input {
    use std::io::{BufRead, Read};

    pub enum ReadMode {
        Full,
        Line,
    }

    pub struct Input<'a> {
        lock: std::io::StdinLock<'static>,
        iter: Option<std::str::SplitAsciiWhitespace<'a>>,
        mode: ReadMode,
    }

    impl<'a> Input<'a> {
        fn naive_read(&mut self) -> Option<std::str::SplitAsciiWhitespace<'a>> {
            let mut s = Box::leak(Box::new(String::new()));
            let res = match self.mode {
                ReadMode::Full => self.lock.read_to_string(&mut s),
                ReadMode::Line => self.lock.read_line(&mut s),
            };
            res.ok().expect("failed to read");
            Some(s.split_ascii_whitespace())
        }
        pub fn new(mode: ReadMode) -> Self {
            let lock = Box::leak(Box::new(std::io::stdin())).lock();
            let iter = None;
            Self { lock, iter, mode }
        }
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            self.lock.read_line(&mut s).ok().expect("failed to read");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            match &mut self.iter {
                Some(iter) => {
                    let x = match iter.next() {
                        Some(x) => x,
                        None => {
                            self.iter = self.naive_read();
                            self.iter.as_mut().unwrap().next().expect("reached EOF")
                        }
                    };
                    x.parse().ok().expect("failed to parse")
                }
                None => {
                    self.iter = self.naive_read();
                    self.parse()
                }
            }
        }
    }
}


Measured memory_bytes: 16204
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <ctime>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <climits>
#include <set>
#include <vector>
using namespace std;
inline int read(){
	int k=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}
	return k*f;
}
inline void write(int x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
inline void writeln(int x){
	write(x);puts("");
}
int main()
{
	int n=read();
	int x=0,y=0,t=0;
	for(int i=1;i<=n;i++){
		int T=read(),X=read(),Y=read();
		int l=abs(X-x)+abs(Y-y);
		if(t+l>T)return puts("No")&0;
		if((T-t-l)&1)return puts("No")&0;
		t=T;x=X;y=Y;
	}
	puts("Yes");
}

Measured memory_bytes: 256
from itertools import product
import numpy as np

N, M = map(int, input().split())
liS_all = []
denkyuM = [0 for i in range(M)]
cnt = 0

for j in range(1, M + 1):
    liS = list(map(int, input().split()))
    denkyulist = [0 for k in range(N)]
    for l in liS[1:]:
        denkyulist[l-1] = 1
    liS_all.append(denkyulist)

liP = list(map(int, input().split()))

bit_list = list(product([0, 1], repeat = N))

for bit in bit_list:
    n = 0
    judge = True
    for denkyu in liS_all:
        ronriseki = np.logical_and(bit, denkyu)
        if sum(ronriseki) % 2 != liP[n]:
            judge = False
        n += 1
    if judge == True:
        cnt += 1
print(cnt)

Measured memory_bytes: 20312
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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; }
typedef long long ll;
int main()
{
  int n,k; cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];

  vector<ll> sum(n+1), psum(n+1);
  sum[0] = 0;
  psum[0] = 0;
  rep(i,n) {
    sum[i+1] = sum[i] + a[i];
    psum[i+1] = psum[i] + (a[i] > 0 ? a[i] : 0);
  }

  ll res = 0;
  rep(i,n-k+1) {
    ll tmp = psum[i] + psum[n] - psum[i+k];
    chmax(res, tmp);
    tmp += sum[i+k] - sum[i];
    chmax(res, tmp);    
  }
  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 2560
N = int(input())

A = list(map(int, input().split()))

L = []
R = []

for i in range(N):
    L.append(i+1 + A[i])
    R.append(i+1 - A[i])

L.sort()
R.sort()

#print(L)
#print(R)

temp = 0
ans = 0
j = 0
for i in range(N):
    if i >= 1 and L[i] == L[i-1]:
        ans += temp
        continue
    temp = 0
    while j < N and L[i] >= R[j]:
        if L[i] == R[j]:
            temp += 1
        j += 1
    ans += temp

print(ans)

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

int main() {
  int h,w,n;
  cin>>h>>w>>n;
  int a[n];
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    a[i]=k;
  }
  int k=0,l=0;
  int b[h][w];
  for(int i=0;i<n;i++){
    for(int j=0;j<a[i];j++){
      b[k][l]=i+1;
      if(k%2==0&&l==w-1)k++;
      else if(k%2==0)l++;
      else if(k%2==1&&l==0)k++;
      else l--;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(j!=w-1)cout<<b[i][j]<<" ";
      else cout<<b[i][j];
    }
    cout<<endl;
  }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#include <math.h>
const int INF = 1001001001;
int main() {
    int N;
    cin>>N;
    vector<tuple<string,int,int>>T;
    for(int i=1;i<=N;i++){
        string S;
        int P;
        cin>>S>>P;
        P=-P;
        T.push_back(tie(S,P,i));
    }
    sort(T.begin(),T.end());
    for(int i=0;i<N;i++){
        string S;
        int P;
        int id;
        tie(S,P,id)=T[i];
        cout<<id<<endl;
    }
    return 0;
}

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

int main()
{
    int N;
    cin >> N;

    int *t = new int[N+1];
    int *x = new int[N+1];
    int *y = new int[N+1];
    t[0] = 0;
    x[0] = 0;
    y[0] = 0;
    for(int i=1; i<=N; i++)
    {
        cin >> t[i] >> x[i] >> y[i];
    }

    bool can = true;
    for(int i=1; i<=N; i++)
    {
        int dt = t[i] - t[i-1]; 
        int dl = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]);

        if(dt < dl)
        {
            can =false;
            break;
        }
        if((dt-dl)%2==1)
        {
            can =false;
            break;
        }
    }

    if(can)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    delete [] t, x, y;

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

const int inf = 1e9;
const int mod = 1e9+7;

struct edge {
    int from, to, cost;
};

typedef pair<int, int> P;
typedef vector<vector<edge> > G;

G graph;
int n, m;

int d[105][105];
bool used[105][105];
vector<edge> dist;

void warshall_floyd(){
    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(d[i][j] > d[i][k] + d[k][j]){
                    d[i][j] = d[i][k] + d[k][j];
                }
            }
        }
    }
}

int main(void){
    cin >> n >> m;
    graph = G(n);

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i == j){
                d[i][j] = 0;
            }else{
                d[i][j] = inf;
            }
        }
    }
    int cnt = 0;
    for(int i=0; i<m; i++){
        int x, y, c;
        cin >> x >> y >> c;
        x--;
        y--;
        d[x][y] = c;
        d[y][x] = c;
        edge e;

        e.from = x;
        e.to = y;
        e.cost = c;
        dist.push_back(e);
        e.from = y;
        e.to = x;
        e.cost = c;
        dist.push_back(e);

    }

    warshall_floyd();
    int ans = 0;
    for(int i=0; i<dist.size(); i++){
        bool flag = false;
        for(int s=0; s<n; s++){
            for(int t=0; t<n; t++){
                if(d[s][dist[i].from] + dist[i].cost + d[dist[i].to][t] == d[s][t]){
                    flag = true;
                }
            }
        }
        if(!(flag)){
            ans++;
        }
    }
    cout << ans/2 << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=(int)n;i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1001001001; const long long INFLL=1001001001001001001ll;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
    #ifdef int
        cerr<<"\x1b[7m"<<"'int' is defined as 'long long' !!!!"<<"\x1b[m"<<endl;
    #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

int dp[41][420][420];
// dp[k][x][y] := k番目まで見た時のAの合計がx,Bの合計がyになるための最小コスト
signed main() {
    REP(k,41) REP(i,420) REP(j,420) dp[k][i][j]=INFLL;
    int n,ma,mb;
    cin>>n>>ma>>mb;
    vi a(n),b(n),c(n);
    REP(i,n) {
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[0][a[0]][b[0]]=c[0];
    dp[0][0][0]=0;
    FOR(k,1,n) {
        REP(i,401) {
            REP(j,401) {
                if(dp[k-1][i][j]!=INFLL) {
                    chmin(dp[k][i+a[k]][j+b[k]],dp[k-1][i][j]+c[k]);
                    chmin(dp[k][i][j],dp[k-1][i][j]);
                }
            }
        }
    }

    int ans=INFLL;
    for(int i=1; i*ma<410; i++) {
        if(chmin(ans,dp[n-1][i*ma][i*mb])) {
            // printf("%lld,%lld,%lld\n",i*ma,i*mb,dp[n-1][i*ma][i*mb]);
        }
    }
    cout<<(ans==INFLL?-1:ans)<<endl;
    return 0;
}


Measured memory_bytes: 56832
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string s;cin >> s;
  s[5] = ' ';
  s[13] = ' ';
  cout << s << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x,y;
    cin >> x >> y;
    bool ok=0;
    for(int i=0;i<=x;i++) ok|=(i*2+(x-i)*4==y);
    if(ok) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>
#include<string.h>
int main(void)
{
    char s[10];
    int j=0;
    scanf("%s",s);

    while(s[j]){
        if(strlen(s)%2==0 && s[j]=='h' && s[j+1]=='i'){
            printf("Yes\n"); return 0;
        } else if(strlen(s)%2==0 &&s[j]=='i' && s[j+1]=='h'){
            printf("Yes\n"); return 0;
        } else { 
            printf("No\n"); return 0;
        }
        j++;
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#include <math.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 10007;
const int INF = LLONG_MAX/3;
const int MAX = 710000;

/*-----Library-----*/

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

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

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*-----Library-----*/
vector<int> es[110000];
map<pair<int,int>,int> c;
bool reached[110000]={};
void dfs(int s,int co){
    reached[s]=true;
    int cnt=1;
    for(int i=0;i<es[s].size();i++){
        if(reached[es[s][i]]==true)continue;
        if(cnt==co)cnt++;
        c[P(s,es[s][i])]=cnt;
        c[P(es[s][i],s)]=cnt;
        dfs(es[s][i],cnt);
        cnt++;
    }
}
signed main(){
    int n;
    cin>>n;
    int cnt[110000]={};
    P t[110000];
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        cnt[a-1]++;
        cnt[b-1]++;
        es[a-1].push_back(b-1);
        es[b-1].push_back(a-1);
        t[i]=P(a-1,b-1);
    }
    int k=0;
    for(int i=0;i<n;i++){
        k=max(k,cnt[i]);
    }
    cout<<k<<endl;
    dfs(0,0);
    for(int i=0;i<n-1;i++){
        cout<<c[P(t[i].first,t[i].second)]<<endl;
    }
    return 0;
}


Measured memory_bytes: 25216
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
int num(State &a) {
	int ans = 0;
	while (*a >= '0' && *a <= '9') {
		ans *= 10;
		ans += *a - '0';
		a++;
	}
	return max(ans, 1LL);
}

int die = 0;

map<string, int> mols;

int Molecule(State& a) {
	int ans = 0;
	while (*a != ')') {
		int tmp = 0;
		if (*a == '(') {
			a++;
			tmp = Molecule(a);
		}
		else {
			string s;
			s.push_back(*a);
			a++;
			if ((*a >= 'a' && *a <= 'z')) {
				s.push_back(*a);
				a++;
			}
			tmp = mols[s];
			if (tmp == -1) die = 1;
		}
		tmp *= num(a);
		ans += tmp;
	}
	a++;
	return ans;
}

void solve(){
	string s;
	cin >> s;
	REP(i, 26) {
		string s;
		s.push_back('A' + i);
		mols[s] = -1;
		REP(q, 26) {
			s.push_back('a' + q);
			mols[s] = -1;
			s.pop_back();
		}
	}
	while (s != "END_OF_FIRST_PART") {
		int b;
		cin >> b;
		mols[s] = b;
		cin >> s;
	}
	cin >> s;
	while (s != "0") {
		s.push_back(')');
		State start = s.begin();
		die = 0;
		int ans = Molecule(start);
		if (die == 1) {
			cout << "UNKNOWN" << endl;
		}
		else {
			cout << ans << endl;
		}
		cin >> s;
	}
}
#undef int

int main() {
	solve();
}


Measured memory_bytes: 3220
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<bool> vb;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int n,k,x,y,ans=0;

int main(){
	cin>>n>>k>>x>>y;
	for(int i=0;i<n;i++){
		if(i<k) ans+=x;
		else ans+=y;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}

	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	s := getNextInt(scanner)
	aa := make([]int, n)

	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	dp := make([]int, s+1)
	ans := 0
	for i := 0; i < n; i++ {
		dp[0]++
		for j := s; j >= aa[i]; j-- {
			dp[j] = mod(dp[j] + dp[j-aa[i]])
		}
		ans = mod(ans + dp[s])
	}
	fmt.Fprintln(writer, ans)
}

func mod(x int) int {
	m := int(998244353)

	return (x%m + m) % m
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
 
#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif
 
using namespace std;
 
//conversion
//------------------------------------------
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();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD=(LL)1e9+7;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
#define INF 1LL << 50
 
 
int main(){
    LL N;
    cin>>N;
    vector<LL>a(N);
    REP(i,N)cin>>a[i];
    SORT(a);
    LL cnt=0;
    while(a.back()>2*N){
        REP(i,N)if(a[i]>N){
            LL b=a[i]/N;
            a[i]-=(b*N+b);
            cnt+=b;
            REP(j,N)a[j]+=b;
        }
        SORT(a);
    }

    while(a.back()>=N){
        REP(i,N-1)a[i]++;
        a[N-1]-=N;
        SORT(a);
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define debug(var) std::cout << #var << " : " << var << std::endl;
using ll = long long;
using ull = unsigned long long;
ll mod = 1e9 + 7;


int main(){


	int N, K; std::cin >> N >> K;
	std::vector<int> h(N);
	rep(i, N)std::cin >> h[i];

	std::vector<int> dp(N, INT_MAX - 2000);
	dp[0] = 0;

	rep(i, N){
		for(int j = 1; j <= K; j++){
			if(i + j < N){
				dp[i + j] = std::min(dp[i + j], dp[i] + std::abs(h[i + j] - h[i]));
			}
		}
	}

	std::cout << dp[N - 1];

	
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
const int N=1005;
char ans4[15][15]={
"abcc",
"abdd",
"eefh",
"ggfh"
};
char ans5[15][15]={
"abbcc",
"ad..e",
"fd..e",
"f.ggh",
"iijjh"
};
char ans6[15][15]={
"ijk...",
"ijk...",
"ll.bcc",
"mm.bdd",
"..eefh",
"..ggfh"
};
char ans7[15][15]={
"klm....",
"klm....",
"oo.bbcc",
"pp.d..e",
"..fd..e",
"..f.ggh",
"..iijjh"
};
int n,i,j;
char ans[N][N];
inline void cov(int x,int y,int m){
	for(int i=0;i<m;++i){
		char*p;
		if(m==4)p=ans4[i];
		if(m==5)p=ans5[i];
		if(m==6)p=ans6[i];
		if(m==7)p=ans7[i];
		memcpy(ans[x+i]+y,p,m);
	}
}
int main(){
	scanf("%d",&n);
	if(n==2){puts("-1");return 0;}
	if(n==3){printf("aab\nd.b\ndcc\n");return 0;}
	for(i=1;i<=n;++i)memset(ans[i]+1,'.',n);
	int tn=n;
	for(;tn>7;tn-=4)cov(tn-3,tn-3,4);
	cov(1,1,tn);
	for(i=1;i<=n;++i)puts(ans[i]+1);
	return 0;
}

Measured memory_bytes: 2176
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;
int sx,sy,tx,ty,i;
int main()
{
    scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
    swap(sx,sy);
    swap(tx,ty);
    if (sx<tx&&sy<ty)
    {
        for (i=sx;i<tx;++i) printf("U");
        for (i=sy;i<ty;++i) printf("R");

        for (i=tx;i>sx;--i) printf("D");
        for (i=ty;i>sy;--i) printf("L");
        printf("L");
        for (i=sx;i<=tx;++i) printf("U");
        for (i=sy;i<=ty;++i) printf("R");
        printf("DR");
        for (i=tx;i>=sx;--i) printf("D");
        for (i=ty;i>=sy;--i) printf("L");
        printf("U");
    }
    else if (sx<tx&&sy>ty)
    {
        for (i=sx;i<tx;++i) printf("U");
        for (i=ty;i<sy;++i) printf("L");

        for (i=tx;i>sx;--i) printf("D");
        for (i=ty;i<sy;++i) printf("R");
        printf("R");
        for (i=sx;i<=tx;++i) printf("U");
        for (i=ty;i<=sy;++i) printf("L");
        printf("DL");
        for (i=tx;i>=sx;--i) printf("D");
        for (i=ty;i<=sy;++i) printf("R");
        printf("U");
    }
    else if (sx>tx&&sy<ty)
    {
        for (i=tx;i<sx;++i) printf("D");
        for (i=sy;i<ty;++i) printf("R");

        for (i=tx;i<sx;++i) printf("U");
        for (i=ty;i>sy;--i) printf("L");
        printf("L");
        for (i=tx;i<=sx;++i) printf("D");
        for (i=sy;i<=ty;++i) printf("R");
        printf("UR");
        for (i=tx;i<=sx;++i) printf("U");
        for (i=ty;i>=sy;--i) printf("L");
        printf("D");
    }
    else if (sx>tx&&sy>ty)
    {
        swap(sx,tx);swap(sy,ty);
        for (i=sx;i<tx;++i) printf("D");
        for (i=sy;i<ty;++i) printf("L");

        for (i=tx;i>sx;--i) printf("U");
        for (i=ty;i>sy;--i) printf("R");
        printf("R");
        for (i=sx;i<=tx;++i) printf("D");
        for (i=sy;i<=ty;++i) printf("L");
        printf("UL");
        for (i=tx;i>=sx;--i) printf("U");
        for (i=ty;i>=sy;--i) printf("R");
        printf("D");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
import numpy as np
import math

N = int(input())

A = []
for i in range(N):
    A.append(list(map(int, input().split())))
ans = 0

for i in range(N-1):
    for j in range(i+1, N):
        ans += np.sqrt((A[i][0]-A[j][0])**2+(A[i][1]-A[j][1])**2)
        
f = math.factorial(N)
ans *= 2/N
#ans *= N*(N-1)*(N-1)
print(ans)


Measured memory_bytes: 22800
S = int(input())

l = [0,0]
if S <= 10 ** 9:
    a = [S, 0, 0, 1]
else:
    u = S // 10 ** 9
    if S % 10 ** 9 != 0:
        u += 1
    d = u * (10 ** 9) - S
    a = [u, d, 1, 10 ** 9]
l.extend(a)
print(" ".join(map(str, l)))

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

using namespace std;

int N, M, dp[309][309], p[309][309], invp[309][309], c[309][309];
const int mod = 1e9 + 7;

int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int subtract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}
void adto (int &x, int y) {x += y; if (x >= mod) x -= mod;}

int power (int a, int b)
{
    int p = 1;
    for (int i=0; (1<<i) <= b; i++)
    {
        if (b & (1 << i)) p = mul (p, a);
        a = mul (a, a);
    }
    return p;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &M);
for (int i=1; i<=N; i++)
{
    p[i][0] = 1;
    for (int j=1; j<=M + 1; j++)
        p[i][j] = mul (p[i][j - 1], i);
    invp[i][0] = 1;
    int aux = power (i, mod - 2);
    for (int j=1; j<=M + 1; j++)
        invp[i][j] = mul (invp[i][j - 1], aux);
}
c[0][0] = 1;
for (int i=1; i<=N; i++)
    for (int j=0; j<=i; j++)
        c[i][j] = add (c[i - 1][j], (j == 0 ? 0 : c[i - 1][j - 1]));
for (int i=0; i<=M; i++)
    dp[1][i] = 1;
for (int i=2; i<=N; i++)
{
    for (int j=1; j<=M; j++)
        dp[i][j] = p[i][j + 1];
    for (int k=1; k<i; k++)
    {
        int curr = 0;
        for (int l=0; l<=M; l++)
        {
            adto (curr, mul (mul (c[i][k], dp[k][l]), invp[i - k][l]));
            if (l > 0)
                dp[i][l] = subtract (dp[i][l], mul (curr, p[i - k][l]));
        }
    }
}
printf ("%d\n", mul (dp[N][M], power (N, mod - 2)));
return 0;
}


Measured memory_bytes: 1664
import sys

n = int(input())
w = [input() for _ in range(n)]

s = set()
# print(w)
for a, i in enumerate(w):
    if a == 0:
        lastword = i[-1]
        s.add(i)
        continue
    if i[0] != lastword or i in s:
        print("No")
        sys.exit()
    lastword = i[-1]
    s.add(i)
print("Yes")



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

//bool compare()

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n;
	cin >> n;
	pii ab[n];
	zip(i, 0, n)
	{
		cin >> ab[i].ff >> ab[i].ss;
		swap(ab[i].ff, ab[i].ss);
	}
	sort(ab, ab + n);
	zip(i, 1, n)
	{
		ab[i].ss = ab[i].ss + ab[i - 1].ss;
	}

	// zip(i, 0, n)
	// {
	// 	if (a[i] < b[i] && i < n - 1)
	// 	{
	// 		a[i + 1] -= (b[i] - a[i]);
	// 	}
	// }
	zip(i, 0, n)
	{
		if (ab[i].ss > ab[i].ff)
		{
			cout << "No" << en;
			return 0;
		}
	}
	cout << "Yes" << en;
	return 0;


	return 0;
}



Measured memory_bytes: 3328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a, b;
            a = int.Parse(str[0]); 
            b = int.Parse(str[1]);
            if(a <= b)
            {
                Console.WriteLine(a);
            }
            else
            {
                Console.WriteLine(a - 1);
            }

        }
    }
}


Measured memory_bytes: 11092
a,b = map(int, raw_input().split())
 
if a==b:
	print "Draw"
else:
	if a!=1 and b!=1:
		if a<b:
			print "Bob"
		else:
			print "Alice"
	elif a==1 and b!=1:
		print "Alice"
	else:
		print "Bob"


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> H(N);
    for(int & x : H)
        cin >> x;
    vector<long long> dp(N, INT_MAX);
    dp[0] = 0;
    for(int i=0; i<N; i++) {
        for(int k=1; k<=K && i+k<N; k++) 
            dp[i+k] = min(dp[i+k], dp[i] + abs(H[i]-H[i+k]));
    }
    cout << dp[N-1] << "\n";
}

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

int H, W, K;

void blockfall(vector<string> &board) {
    for(int i=H-1; i>=0; i--) {
        for(int j=0; j<W; j++) {
            int x = i, y = j;
            while(x < H-1 && board[x+1][y] == '.') {
                swap(board[x][y], board[x+1][y]);
                x++;
            }
        }
    }
}

vector<string> erase_one(vector<string> board, int x, int y) {
    board[x][y] = '.';
    blockfall(board);
    return board;
}

int solve(vector<string> board) {
    int ret = 0;

    // for(int i=0; i<H; i++) cout << board[i] << endl;

    for(int z=0; ; z++) {
        bool changed = false;
        vector<string> chg(H, string(W, '.'));

        int sum = 0;
        for(int i=0; i<H; i++) {
            char pre = '#';
            int cons = 0;
            for(int j=0; j<=W; j++) {
                // printf("i = %d, j = %d, cons = %d\n", i, j, cons);
                if(j == W || pre != board[i][j]) {
                    if(cons >= K) {
                        if(cons > 0 && board[i][j-1] != '.') {
                            changed = true;
                            // printf("char: %c\n", board[i][j-1]);
                            sum += cons * (board[i][j-1] - '0');
                        }
                        for(int k=j-cons; k<j; k++) {
                            board[i][k] = '.';
                        }
                    }
                    cons = 1;
                }
                else cons++;
                pre = board[i][j];
            }
        }

        // printf("sum = %d\n", sum);
        if(!changed) break;
        ret += sum * (1 << z);
        blockfall(board);
    }
    return ret;
}

int main() {
    cin >> H >> W >> K;
    vector<string> board(H);
    for(int i=0; i<H; i++) cin >> board[i];

    int ans = 0;
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            vector<string> n_board = erase_one(board, i, j);
            ans = max(ans, solve(n_board));
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define num sizeof(a)/sizeof(int)
#define N 100000

int main(){
    char s[3*N],add[2],sagyou[3*N],emp[3*N];
    int q,size,t,f,number=0,i,ins,distin=0;
    scanf("%s%d",s,&q);
    s[N-1]='\0';
    strcpy(sagyou,s);
    for(size=0;s[size]!='\0';size++);

    while(q!=0){
        scanf("%d",&t);
        if(t==1){
            //hanntenn
            distin+=1;
            distin%=2;
        }else if(t==2){
            scanf("%d",&f);
            if((f==1 && distin%2==0) || (f==2 && distin%2)==1){
                //senntoutuika
                scanf("%s",add);
                strcat(emp,add);
                number++;
            }else if((f==2 && distin%2==0) || (f==1 && distin%2==1)){
                //matubituika
                scanf("%s",add);
                strcat(sagyou,add);
                size++;
            }
        }
        q--;
    }

    if(distin%2==0){
        for(i=number-1;i>=0;i--){
            putchar(emp[i]);
        }
        printf("%s\n",sagyou);
    }else{
        for(i=size-1;i>=0;i--){
            putchar(sagyou[i]);
        }
        printf("%s\n",emp);
    }
    return 0;
}

Measured memory_bytes: 896
def weight
  master = Array.new(10) { |i| 2**i }
  while gets
    element = $_.to_i
    spindles = master.select { |i| i <= element }
    result = []
    while true
      break if element <= 0
      minus = spindles.max
      if minus > element
				spindles.delete(minus)
        next
      end
      element -= minus
      result << spindles.delete(minus)
    end
    puts result.sort.join(' ')
  end
end

weight

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

int* mallocint(int si)
{
    return (int*) malloc(si * sizeof(int));
}

int* _minn;
int* _total;

bool compare(int i1, int i2)
{
    if( _minn[i1] != _minn[i2] ) return _minn[i1] > _minn[i2];
    return _total[i1] > _total[i2];
}

bool comparen(int i1, int i2)
{
    return _minn[i1] < _minn[i2];
}

bool check(int &count, vector<int> &l)
{
    sort(l.begin(), l.end(), compare);
    queue<int> q;
    int current = 0;
    for( auto itr = l.begin(); itr != l.end(); itr++ ) 
    {
        if( current + _minn[*itr] < 0 )
        {
            return false;
        }
        current += _total[*itr];
    }
    count = current;
    return true;
}

bool check(vector<int> &pindex, vector<int> &nindex, int lminmin, int rminmin)
{
    int c1 = 0;
    int c2 = 0;
    if( !check(c1, pindex) ) return false;
    if( !check(c2, nindex) ) return false;
    if( c1 != c2 ) return false;
    if( lminmin + c1 < 0 ) return false;
    if( rminmin + c2 < 0 ) return false;
    return true;
}

int main()
{
    int n;
    string s;
    cin >> n;
    getline(cin, s);
    int* minn = mallocint(n);
    int* total = mallocint(n);
    _minn = minn;
    _total = total;
    vector<int> pindex;
    vector<int> nindex;
    int lminmin = 0;
    int rminmin = 0;
    for( int i = 0; i < n; i++ )
    {
        getline(cin, s);
        int lcount = 0;
        int lmin = 0;
        int rcount = 0;
        int rmin = 0;
        for( int j = 0; j < s.length(); j++ )
        {
            if (s.at(j) == '(') lcount++;
            if (s.at(j) == ')') lcount--;
            if( lcount < lmin ) lmin = lcount;
        }

        for( int j = s.length() - 1; j >= 0; j-- )
        {
            if (s.at(j) == ')') rcount++;
            if (s.at(j) == '(') rcount--;
            if( rcount < rmin ) rmin = rcount;
        }
        
        if( lcount > 0 )
        {
            minn[i] = lmin;
            total[i] = lcount;

            pindex.push_back(i);
        }
        else if( rcount > 0 )
        {
            minn[i] = rmin;
            total[i] = rcount;
            nindex.push_back(i);                    
        }
        else
        {
            if( lmin < lminmin ) lminmin = lmin;
            if( rmin < rminmin ) rminmin = rmin;
        }
        
    }

    if(check(pindex, nindex, lminmin, rminmin))
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }    
}


Measured memory_bytes: 15112
#include<bits/stdc++.h>
#define LL long long
#define L(x) x<<1    //左儿子 x*2
#define R(x) x<<1|1 //右儿子  x*2+1
using namespace std;
typedef long long ll;
ll mod=1e9+7;
int main() {
    ll a,b;
    cin>>a>>b;
    if(abs(a-b)==0)
    {
        ll ans=1;
        for(int i=1;i<=a;i++)
            ans=(ans*i)%mod;
        cout<<((ans*ans)%mod*2)%mod<<endl;
    }
    else if(abs(a-b)==1)
    {
        ll ans=1;
        for(int i=1;i<=a;i++)
            ans=(ans*i)%mod;
        for(int i=1;i<=b;i++)
            ans=(ans*i)%mod;
        cout<<ans<<endl;
    }
    else
        cout<<"0"<<endl;
    return 0;
}


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

string s;

void solve()
{
	pair<int,int> ans ={-1,-1};
	const int n = s.length();
	for(int i=0;i+1<n;++i)if(s[i]==s[i+1]){
		ans={i+1,i+2};
		break;
	}
	if(ans.first==-1)for(int i=0;i+2<n;++i){
		if(s[i]==s[i+2]){
			ans={i+1,i+3};
			break;
		}
	}
	cout << ans.first << " " << ans.second << endl;
	
}

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

Measured memory_bytes: 512
n = int(input())
x = list(input())

def popcount(n):
    bin_n = bin(n)[2:]
    count = 0
    for i in bin_n:
        count += int(i)
    return count

cnt = 0
for i in range(n):
    if x[i] == '1':
        cnt += 1

lst = [0 for i in range(n+1)]
for i in range(1, n+1):
    num = i%popcount(i)
    lst[i] = lst[num] + 1

plus = [0 for i in range(n)]
minus = [0 for i in range(n)]
plus[0] = 1
if cnt != 1:
    minus[0] = 1
for i in range(1, n):
    plus[i] = (plus[i-1]*2) % (cnt+1)
    if cnt != 1:
        minus[i] = (minus[i-1]*2) % (cnt-1)

origin = int(''.join(x), base=2)
amariplus = origin % (cnt+1)
if cnt != 1:
    amariminus = origin % (cnt-1)

for i in range(n):
    if x[i] == '0':
        amari = (amariplus + plus[n-i-1]) % (cnt+1)
        print(lst[amari] + 1)
    else:
        if cnt != 1:
            amari = (amariminus - minus[n-i-1]) % (cnt-1)
            print(lst[amari] + 1)
        else:
            print(0)

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

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

    array<int, 3> a = {0, 0, 0}, b;
    int t, x, y;
    for (int i = 0; i < n; i++) {
        cin >> b[0] >> b[1] >> b[2];
        t = b[0] - a[0];
        x = abs (b[1] - a[1]);
        y = abs (b[2] - a[2]);
        if (x+y > t || x+y < t && (x+y-t)&1) {
            cout << "No" << endl;
            return 0;
        }
        a = b;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

void solve(int n, int x) {
    if(n == 0 && x == 0) return;
    int count = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = i + 1; j <= n; j++) {
            for(int k = j + 1; k <= n; k++) {
                if(i + j + k == x) count++;
            }
        }
    }
    cout << count << endl;
}

int main() {
    int n, x;
    do {
        cin >> n >> x;
        solve(n, x);
    }while(n != 0 || x != 0);
}


Measured memory_bytes: 3064