akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n,a[500001],c[500001],s[500001];
int sum(int x)
{
	int ans=0;
	while(x)ans+=c[x],x-=x&-x;
	return ans;
}
inline int query(int x){return sum(x+150000);}
void add(int x,int d){while(x<300001)c[x]+=d,x+=x&-x;}
inline void modify(int x,int d){add(x+150000,d);}
long long f(int x)
{
	memset(c,0,sizeof c);
	for(int i=1;i<=n;i++)s[i]=s[i-1]+(a[i]>=x?1:-1);
	long long ans=0;
	for(int i=1;i<=n;i++)modify(s[i-1],1),ans+=2*query(s[i])-i;
	return ans;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	int l=1,r=1e9;
	while(l+1<r)
	{
		int m=(l+r)/2;
		if(f(m)>=0)l=m;
		else r=m-1;
	}
	for(int i=r;i>=l;i--)
		if(f(i)>=0)return printf("%d\n",i),0;
	abort();
}


Measured memory_bytes: 2944
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
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;
}

void solve() {
		int a1, a2, a3; cin >> a1 >> a2 >> a3;
		cout << ((a1 + a2 + a3) >= 22 ? "bust" : "win") << endl;
    return;
}

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int  N;
  cin >> N;
  
  if( ((N/10)%111==0) || ( (N%1000)%111==0 ) ){
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;



long long N;
char st[11];
void f(char a,int s)
{
	if(s==N){
		puts(st);
		return;
	}
	for(char i='a';i<=a;i++){
		st[s]=i;
		f(a,s+1);
	}
	st[s]=a+1;
	f(a+1,s+1);
}

int main(){
    scanf("%lld",&N);
	st[0]='a';
    f('a',1);
    return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>
int main(){
  int a,b,c,d;
  scanf("%d %d %d",&a,&b,&c);
  if(a>b){
    d=a;
    a=b;
    b=d;
  }

 if(a>c){
    d=a;
    a=c;
    c=d;
  }

  if(b>c){
    d=b;
    b=c;
    c=d;
  }

  printf("%d %d %d\n",a,b,c);
  
  return 0;
}


Measured memory_bytes: 2712
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;

struct Data{
    long long A;
    long long B;
    long long C;
    
    // 最後のconstを忘れると"instantiated from here"というエラーが出てコンパイルできないので注意
    bool operator<( const Data& right ) const {
        return C == right.C ? B < right.B : C < right.C;
    }
};

int main(){
    int N;
    cin >> N;
    
    vector<Data> D(N);
    for (int i=0;i<N;i++) cin >> D[i].A >> D[i].B;
    for (int i=0;i<N;i++) D[i].C = -(D[i].A + D[i].B);
    
    sort(D.begin(), D.end());
    for (int i=0;i<N;i++) D[i].C = -D[i].C;
    
    long long result = 0;
    for (int i=0;i<N;i++) {
        if (i%2==0) result += D[i].A;
        else result -= D[i].B;
    }
    
    cout << result << endl;
    
    return 0;
}

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

int main(){

    string N;
    cin >> N;

    if(N[0] == N[1] && N[1] == N[2]) cout << "Yes" << endl;
    else if(N[1] == N[2] && N[2] == N[3]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
XY = [list(map(int, input().split())) for i in range(N)]
s = 0
import math
for i in range(N):
  for j in range(i+1,N):
    s += math.sqrt((XY[i][0]-XY[j][0])**2+(XY[i][1]-XY[j][1])**2)
    

    
ans = s*2/N
print(ans)


Measured memory_bytes: 3188
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
int main()
{
fast;
ll n,k;
cin>>n>>k;
vector<ll>v;
for(ll i=0;i<n;i++)
{
    ll a;
    cin>>a;
    v.pb(a);
}
ll cnt=0;
for(ll i=0;i<n;i++)
{
    if(v[i]>=k)
    {
        cnt++;
    }
}
cout<<cnt<<endl;
return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define INF 1007654321
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<typename U, typename V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

const int MAXN = 100;
int C[MAXN][MAXN];

int main() {
    FAST_IO();    
    int H, W, N; cin >> H >> W >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int c = 0;
    rep(i, H) {
        int j;
        rep(k, W) {
            if(i % 2 == 0) j = k;
            else j = W - 1 - k;
            C[i][j] = c + 1;
            if(--A[c] == 0) c++;
        }
    }
    rep(i, H) rep(j, W) {
        cout << C[i][j] << " \n"[j == W-1];
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  ll n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  string ans;
  for (int i = 0; i < n; ++i) {
    ans += s[i];
    ans += t[i];
  }
  cout << ans << endl;
}


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

int main()
{
    int a, b;
    cin >> a >> b;

    int res=0;
    if (a <= b){ res += b; b--;}
    else {res += a; a--;}
    if (a <= b) {res += b; b--;}
    else {res += a; a--;}

    cout << res << endl;
}

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

using namespace std;

const int N = 100010;

int a[N];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int p;
    cin >> p;
    a[i] = (p == i);
  }
  int ans = 0;
  for (int i = n; i >= 1; i--) {
    if (a[i] > 0) {
      ans++;
      a[i] = a[i - 1] = 0;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
s=input()

def dfs(i,f):
    global s_sum
    if i==len(s)-1:
        s_sum+=sum(map(int,f.split('+')))

    else:
        dfs(i+1,f+'+'+s[i+1])
        dfs(i+1,f+s[i+1])

s_sum=0
dfs(0,s[0])
print(s_sum)


Measured memory_bytes: 3060
//#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define ALL(a)					(a).begin(),(a).end()
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
/* N進数の文字列取得(負にも対応) */
ll totalCnt;
ll ans;
ll N, X;

static ll pList[55];
static ll totalList[55];

void dfs(ll depth)
{
	if (X <= totalCnt) return;
	
	if (depth == 0) {
		totalCnt++;
		ans++;
		return;
	}
	
	ll nextDepth = depth - 1;
	totalCnt++;
	if (totalCnt + totalList[nextDepth] < X) {
		totalCnt += totalList[nextDepth];
		ans += pList[nextDepth];
	} else {
		dfs(nextDepth);
	}

	if (X <= totalCnt) return;
	totalCnt++;
	ans++;
	
	if (totalCnt + totalList[nextDepth] < X) {
		totalCnt += totalList[nextDepth];
		ans += pList[nextDepth];
	} else {
		dfs(nextDepth);
	}
	totalCnt++;
}

int main()
{
	cin >> N >> X;
	totalList[0] = 1;
	pList[0] = 1;
	REPN(i, 1, 55) {
		totalList[i] = 2 * totalList[i - 1] + 3;
		pList[i] = 2 * pList[i - 1] + 1;
	}
	dfs(N);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ans=0, swi[100]={0}, k[100], s[100][100], p[100], n, m;
bool judge(){
    int i, j, cnt=0;
    for(i=0;i<m;i++){
        for(j=0;j<k[i];j++){
            if(swi[s[i][j]]==1) cnt++;
        }
        if(cnt%2!=p[i]) return false;
        cnt=0;
    }
    return true;
}
int search(int num){
    if(num==n){
        if(judge()) ans++;
        return 0;
    }
    swi[num]=0;
    search(num+1);
    swi[num]=1;
    search(num+1);
}
int main(){
    int i, j;
    cin >> n >> m;
    for(i=0;i<m;i++){
        cin >> k[i];
        for(j=0;j<k[i];j++){
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    for(i=0;i<m;i++){
        cin >> p[i];
    }
    search(0);
    cout << ans <<endl;
    return 0;

}

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

int main(void){
    int x, y;
    while(true) {
        cin >> x;
        cin >> y;
        //繰り返すプログラム
        if(x == 0 && y == 0) {
            break; // while から抜ける
    }
    if(x < y) {
        cout << x << " " << y << endl;
    }
    else {
        cout << y << " " << x << endl;
        }
    }

}



Measured memory_bytes: 3032
#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i=0; i<(long long)(n); i++)
#define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++)
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

int main(){
  int n, c, k;
  cin >> n >> c >> k;
  vl vec(n);
  rep(i, n) cin >> vec[i];
  sort(all(vec));
  int earliest = vec[0];
  int cnt = 1;
  int ans = 0;
  rep(i, 1, n){
    if(cnt == c){
      ans++;
      cnt = 1;
      earliest = vec[i];
    }else{
      if(earliest+k>=vec[i]){
      	cnt++;
      }else{
        ans++;
        cnt = 1;
        earliest = vec[i];
      }
    }
  }
  ans++;
  cout << ans << endl;
  return 0;
}
      


Measured memory_bytes: 4000
#include<iostream>
#include<vector>

using namespace std;


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

  vector<int> p;

  for(int i = 0; i < n; i++){
    int pp;
    cin >> pp;

    p.push_back(pp);
  }

  int cnt = 0;
  for(int i = 0; i < n-2; i++){
    if(p[i] < p[i+1] && p[i+1] < p[i+2])  cnt++;
    else if(p[i] > p[i+1] && p[i+1] > p[i+2]) cnt++;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <algorithm>

using namespace std;

int paper[10][10];

bool inField(int argX, int argY) {
	if (argX < 0 || argX > 9 || argY < 0 || argY > 9) return false;
	return true;
}

int main() {
	string input = "";
	cin >> input;
	
	int dx[13] = { 0, 0, 1, 0, -1, 1, 1, -1, -1, 0, 2, 0, -2 };
	int dy[13] = { 0, -1, 0, 1, 0, -1, 1, 1, -1, -2, 0, 2, 0 };
	
	for (int x = 0; x < 10; x++) {
		for (int y = 0; y < 10; y++) {
			paper[x][y] = 0;
		}
	}
	
	while (input.size() > 0) {
		
		int dropX = input[0] - '0';
		int dropY = input[2] - '0';
		int dropSize = input[4] - '0';
		int dropNum;
		
		if (dropSize == 1) dropNum = 5;
		else if (dropSize == 2) dropNum = 9;
		else dropNum = 13;
		
		for (int i = 0; i < dropNum; i++) {
			if (!inField(dropX + dx[i], dropY + dy[i])) continue;
			
			paper[dropX + dx[i]][dropY + dy[i]]++;
		}
		
		input = "";
		cin >> input;
	}
	
	int blankNum = 0;
	int maxDensity = 0;
	for (int x = 0; x < 10; x++) {
		for (int y = 0; y < 10; y++) {
			if (paper[x][y] == 0) {
				blankNum++;
			} else if (paper[x][y] > maxDensity) {
				maxDensity = paper[x][y];
			}
		}
	}
	
	cout << blankNum << endl;
	cout << maxDensity << endl;
	
	return 0;
}

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

using namespace std;

typedef long long int ll;

const int N = 1e+5 + 1;

const int M = 1e+9 + 7;

int main() {
    int n;
    cin >> n;
    vector<vector<pair<ll, ll>>> dp(n+1, vector<pair<ll, ll>>(n+1));
    ll x;
    for(int i=1; i<=n; ++i){
        cin>>x;
        dp[i][i].first = (x);
        dp[i][i].second = 0;
    }
    for(int i= n-1; i>=1; --i){
        for(int j=i+1; j<=n; ++j){
            if(dp[i][i].first + dp[i+1][j].second > dp[j][j].first + dp[i][j-1].second){
                dp[i][j].first = dp[i][i].first + dp[i+1][j].second;
                dp[i][j].second =   dp[i+1][j].first;
            }
            else{
                dp[i][j].second =  dp[i][j-1].first;
                dp[i][j].first =  dp[j][j].first + dp[i][j-1].second;
            }
        }
    }
    cout<<dp[1][n].first - dp[1][n].second;
}

Measured memory_bytes: 141184
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a,vector<vector<ll>> b,int n){
	int i,j,k,t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k]*b[k][j] % M)%M;
			c[i].push_back(t);
		}
	}
	return c;
}
int main() {
	int n, i, j,ans = 0,count;
	cin >> n;
	for (i = 1; i <= n; i+=2) {
		count = 0;
		for (j = 1; j <= i; j++)
			if (i%j == 0)
				count++;
		if (count == 8)
			ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 5120
n = int(input())
res = 0

for i in range(1,n+1):
    if i % 2 == 1:
        co = 0
        for j in range(1,i+1):
            if i % j == 0:
                co += 1
        else:
            if co == 8:
                res += 1
else:
    print(res)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD (int)1e9 + 7
#define atoi(x) ((x)-'0')
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;

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

int n;
string s;

int main() {
	cin >> n >> s;
	for (int i = 0; i < min(n, sz(s)); i++) {
		cout << s[i];
	}
	if (sz(s) > n) cout << "...";
}

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

#define vl vector<ll>
#define vs vector<string>
#define vll vector< vector<ll> >
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define psl pair<string,ll>
#define tll tuple<ll, ll, ll>
#define vp vector< pair<ll,ll> >
#define vt vector< tuple<ll, ll, ll> >
#define all(c) c.begin(),c.end()

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
 
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
#define NN 2020202

//command
//c++ atcoder.cpp -std=c++14
//./a.out

//cout << setprecision(12) << ans << endl;

int main(){
  ll N;
  cin>>N;
  //vl G(N);
  vl G[N];
  vp node;
  ll a,b;
  for(int i=1;i<N;i++){
    cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    node.emplace_back(a,b);
  }
 
  ll K=0;
  map<pll, ll> I;
  vl cs(N,0); // color of edge between its parent
 
  vl used(N,0);
  queue<ll> que;
  used[0]=1;
  que.emplace(0);
  while(!que.empty()){
    ll v=que.front();que.pop();
    if(K<G[v].size()) K=G[v].size();
    ll cur=1;
    for(ll u:G[v]){
      if(used[u]) continue;
      if(cur==cs[v]) cur++;
      cs[u]=I[pll(u,v)]=I[pll(v,u)]=cur++;
      used[u]=1;
      que.emplace(u);
    }
  }
 
  cout<<K<<endl;
  for(auto p:node) cout<<I[p]<<endl;
  return 0;
}

Measured memory_bytes: 22128
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s[3] = {"Sunny", "Cloudy", "Rainy"};
    string t;
    cin >> t;
    rep(i, 0, 3){
        if(s[i] == t){
            cout << s[(i + 1) % 3] << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	lli N,sum = 0, total = 0;
	cin >> N;

	lli A[1000] = {};

	FOR(N)
		cin >> A[i], total += A[i];

	lli ans = 1000000000;

	FOR(N) {
		sum += A[i];
		CHMIN(ans,abs(total - sum - sum));
	}

	COUT(ans);

	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

import queue

INF = 2000000000

class Edge:
    def __init__(self, to, weight, val):
        self.val = val
        self.to = to
        self.weight = weight
        
def bfs(s):
    global d
    d = [INF] * n
    Q.put(s)
    d[s] = 0
    
    while not Q.empty():
        u = Q.get()
        for i in range(len(G[u])):
            e = G[u][i]
            
            if d[e.to] == INF:
                d[e.to] = d[u] + e.weight
                Q.put(e.to)


def solve():
    bfs(0)
    
    tgt = 0
    maxv = 0
    for i in range(n):
        if d[i] == INF:
            continue
        if maxv < d[i]:
            maxv = d[i]
            tgt = i
    bfs(tgt)
    
    maxv = 0
    for i in range(n):
        if d[i] == INF:
            continue
        if maxv < d[i]:
            maxv = d[i]
    return maxv

n = int(input())

G = [[] for j in range(n)]
d = [INF] * n
for i in range(n-1):
    nums=list(map(int,input().split()))
    G[nums[0]].append(Edge(nums[1], nums[2], i))
    G[nums[1]].append(Edge(nums[0], nums[2], i))
Q = queue.Queue()
print(solve())
















Measured memory_bytes: 67572
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define M 1000000007
#define INF ((1LL<<62LL) - 1)

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

    string s; cin >> s;
    int n = s.size();
    int sum = 0;
    for(int i=0;i<n;i++){
        sum += (s[i]-'0');
    }

    if(sum%9==0) cout << "Yes\n";
    else cout << "No\n";



    

}


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


typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#define pb push_back
#define popb pop_back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define forz(i,n) for( int i=0;i<n;i++)
#define forl(i, n) for(int i = 1; i<= n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
// #define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)

using namespace std;

void cpc()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w" , stdout);
#endif
}
lli power(lli x, lli y)
{
	lli res = 1;     // Initialize result
	// lli p = mod;
	x = x ; // Update x if it is more than or
	// equal to p

	if (x == 0) return 0; // In case x is divisible by p;

	while (y > 0)
	{
		// If y is odd, multiply x with result
		if (y & 1)
			res = (res * x);

		// y must be even now
		y = y >> 1; // y = y/2
		x = (x * x);
	}
	return res;
}

int main()
{
	// cpc();
	string s, t;
	cin >> s >> t;
	lli n = s.size();
	if (s == t.substr(0, n)  && t.size() == (s.size() + 1))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;

import java.util.Stack;

public class Main {

   public static void main(String[] args) {
        Stack<Integer>stack = new Stack<>();
        
        Scanner scan = new Scanner(System.in);
 
        String input = scan.nextLine();
        String[] AK = input.split(" ",0);
        scan.close();
        int kfc = AK.length;   
        for(int i = 0; i < kfc; ++i) {
            
            if (AK[i].equals("+")) {
               int x = stack.pop(),y = stack.pop();
                stack.push(y + x);
            }
            else if (AK[i].equals("-")) {
                int x = stack.pop(),y = stack.pop();
                
                stack.push(y - x);
            }
            else if (AK[i].equals("*")) {
                int x = stack.pop(),y = stack.pop();
                int B = x*y;
                int C = B;
                stack.push(C);
            }
            else {
               stack.push(Integer.parseInt(AK[i]));
            }
        }
        System.out.println(stack.firstElement());
    }
 }


Measured memory_bytes: 26148
#include<bits/stdc++.h>
using namespace std;int a[25],p[10],i,j,n,q;
int main(){p[0]=1;for(i=1;i<10;i++){p[i]=p[i-1]*10;}while(true){memset(a,0,sizeof(a));cin>>a[0]>>q;if(a[0]==0){break;}for(i=1;i<25;i++){n=0;
for(j=9;j>=0;j--){for(int k=0;k<q;k++){if((a[i-1]/p[k])%10==j){a[i]+=j*p[q-1-n];a[i]-=j*p[n];n++;}}}
for(j=0;j<i;j++){if(a[i]==a[j]){cout<<j<<' '<<a[i]<<' '<<i-j<<endl;goto E;}}}
E:;}}

Measured memory_bytes: 1160
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- map read . words <$> getLine :: IO [Int]
  solve' n $ sort as

solve' n as = do
  print $ if minimum as > 0 
    then sum as - 2 * head as
    else if maximum as < 0
      then (negate . sum $ as) + 2 * last as
      else sum $ map abs as 
  putStr . unlines . map (unwords . map show) . unfoldr f $ (last as, as)
    where
      f :: (Int, [Int]) -> Maybe ([Int], (Int, [Int]))
      f (m, (a:b:[])) = Just ([m, a], (m - a, []))
      f (m, (a:b:as))
        | b < 0 = Just ([m, a], (m - a, b:as))
        | otherwise =  Just ([a, b], (m, (a-b):as))
      f _ = Nothing



Measured memory_bytes: 34684
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    int n, w;
    cin >> n >> w;
    vector<int> W(n), V(n);
    for(int i=0;i<n;i++){
        cin >> W[i] >> V[i];
    }
    vector<vector<ll>> dp(n+1, vector<ll> (n*1e3+1, 1e10));

    dp[0][0] = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=n*1e3;j++){
            if(j >= V[i]){
                dp[i+1][j] = min(dp[i][j-V[i]]+W[i], dp[i+1][j]);
            }
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
        }
    }

    ll ans = 0;
    for(int i=0;i<=n*1e3;i++){
        if(dp[n][i] <= w) ans = i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 80256
#include<cstdio>
#define maxn 10005
int a[maxn];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	int res = a-2*b;
	if(2*b>a){
		printf("0\n");
	}
	else{
		printf("%d\n",res);
	}
	return 0;
}

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

using namespace std;
typedef unsigned long long ull;
const ull P=1e9+7;

int n;
string s;
unordered_map<ull ,int > mp;

ull pw(ull p,ull n){
	ull ans=1;
	while(n){
		if(n&1) ans*=p;
		p=p*p;
		n=n>>1;
	}
	return ans;
}

bool check(int len){
	mp.clear();
	ull hash=0;
	for(int i=0;i<len;i++){
		hash=hash*P+s[i];
	}
	mp[hash]=1;
	for(int i=0;i+len<n;i++){
		hash=hash*P+(ull)s[i+len]-(ull)s[i]*pw(P,len);
		//&&mp[hash]<=i+1-len
		if(mp[hash]!=0&&mp[hash]<=i+2-len) return 1;
		if(mp[hash]==0) mp[hash]=i+2;
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(0);
	cin>>n>>s;
	if(!check(1)){
		cout<<0<<endl;
		return 0;
	}
	int head=1,tail=n/2+1;
	while(head<tail){
		int mid=(head+tail)/2;
		if(check(mid)) head=mid+1;
		else tail=mid;
	}
	cout<<head-1<<endl;
}

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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(a*b,c*d) << endl;
    return 0;
}

Measured memory_bytes: 256
// AtCoder Grand Contest 016
// A - Shrinking

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;


string s;
int ans;

int main() {

    int span, idx, pre_idx;

    cin >> s;

    ans = s.length();
    for (char c = 'a'; c <= 'z'; c++) {
        span = 0;
        pre_idx = -1;
        while ((decltype(string::npos))(idx = s.find_first_of(c, pre_idx + 1)) != string::npos) {
            span = max(span, idx - pre_idx - 1);
            pre_idx = idx;
        }
        span = max(span, (int)s.length() - pre_idx - 1);
        ans = min(ans, span);
    }

    cout << ans << endl;

    return 0;

}





Measured memory_bytes: 256
def main():
    n, m, k = map(int, input().split())
    f = False
    for i in range(n+1):
        for j in range(m+1):
            if i*j + (n-i)*(m-j) == k:
                f = True
    if f:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main(){
    ll Ca=0,C=0;
    string S;
    cin >> S;
    rep(i,S.size()){
        if(S[i]=='A'){
            if(S[i+1]=='B' && S[i+2]=='C'){
                C+=Ca+1;
                S[i+2]='A';
                i=i+1;
            }
            else{
                Ca++;
            }
        }
        else{
            Ca=0;
        }
    }
    cout << C << endl;
}

Measured memory_bytes: 1016
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)

def dfs(n):
    global P
    seen[n] = 1
    for g in G[n]:
        if seen[g] == 0:
            dfs(g)
            seen[g] = 0
    if not 0 in seen:
        P += 1
P = 0
seen = [0] * N
dfs(0)
print(P)

Measured memory_bytes: 9192
N, T = map(int, raw_input().split())
ans = 'TLE'
for i in range(0, N):
	c, t = map(int, raw_input().split())
	if t <= T:
		if ans == 'TLE':
			ans = str(c)
		elif c < int(ans):
			ans = str(c)
print ans

Measured memory_bytes: 2568
#include<stdio.h>
#include<string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
int main()
{
  int i=0,N=IN(),Q=IN(),H=N,W=N,col[N],row[N];long b=1l*(N-2)*(N-2);
  memset(col,N,sizeof(col));memset(row,N,sizeof(row));
  while(Q--)
  {
    int type=IN(),x=IN()-1;
    if(type==1){if(x<W){i=x;while(i<W-1){col[i++]=H;}W=x+1;}b-=col[x]-2;}
    else{if(x<H){i=x;while(i<H-1){row[i++]=W;}H=x+1;}b-=row[x]-2;}
  }
  return OUT(b),0;
}

Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;
int main(void) {
    
    int n,m;
    cin>>n>>m;

    double cp;
    double wp;
    double time = 1900*m+100*(n-m);

    double sum=0;
    double temp;

    cp = pow(0.5,double(m));
    //cout<<cp<<" ";
    wp = 1-cp;
   // cout<<wp<<" ";

    sum = cp*time;
    //cout<<sum<<endl;
    int i=2;

    while(1){

        temp=sum;
        sum+=(pow(wp,i-1)*cp)*i*time;
        //cout<<sum<<endl;
        if(sum-temp<0.0001)break;
        i++;
       // if(i>3)break;
    }

    cout<<ceil(sum)<<endl;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
for i in range(n):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] >v :
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    A_=' '.join(map(str,A))
    print(A_)


Measured memory_bytes: 5596
#include<stdio.h>
#include<string.h>
int main()
{
    char s[100005];
    scanf("%s", s);
    int n = strlen(s);
    int i, r, b;
    r = b = 0;
    for (i = 0; i < n; i++)
    {
        if (s[i] == '0')
            r++;
        else
            b++;
    }
    if (r < b)
        printf("%d\n", 2 * r);
    else
        printf("%d\n", 2 * b);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
ll mod=1e9+7;
ll MAX=2001005;
vector<ll> fact(MAX),fact_inv(MAX);
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b&1)res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}
ll comb(ll n, ll r){
    return (fact[n]*fact_inv[r])%mod*fact_inv[n-r]%mod;
}

int main(){
    ll x,y; cin>>x>>y;
    if((x+y)%3!=0)cout<<0<<endl;
    else{
        ll z=(x+y)/3;
        x-=z; y-=z;
        if(min(x,y)<0){cout<<0<<endl; return 0;}
        fact[0]=1;
      	ll n=x+y+1;
        rep(i,n)fact[i+1]=fact[i]*(i+1)%mod;
        fact_inv[n]=power(fact[n],mod-2);
        rep(i,n)fact_inv[n-1-i]=fact_inv[n-i]*(n-i)%mod;
        ll ans=comb(x+y,x);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 31488
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        // String s = sc.next();
        int[] a = new int[n];
        int ans = 0;
        for (int i = 0; i < m; i++) {
            a[i] = Integer.parseInt(sc.next());
            ans += a[i];
        }

        if (n >= ans) {
            System.out.println(n - ans);
        } else {
            System.out.println(-1);
        }
        sc.close();
    }
}

Measured memory_bytes: 45252
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <cassert>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple

using namespace std;

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

ll num(ll x){
	return x - (x / 3 + x / 5 - x / 15);
}

ll f(ll x){
	ll res = (x / 3 + x / 5) * 4;

	for (ll i = 1, j = 1; i <= x; i *= 10, ++j){
		res += (num(min(i * 10, x)) - num(i-1))*j;
	}
	return res;
}

int main(){
	ll x;
	cin >> x;

	ll lb = 0, ub = 1e18;
	while (ub - lb > 1){
		ll mid = (ub + lb) / 2;
		if (f(mid) >= x) ub = mid;
		else lb = mid;
	}
	//cout << lb << " " << f(lb) << endl;

	string s = "";
	for (ll i = lb + 1; i < lb + 20; ++i){
		bool b = true;
		if (i % 3 == 0) s += "Fizz", b = false;
		if (i % 5 == 0) s += "Buzz", b = false;
		if (b) s += to_string(i);
	}

	cout << s.substr(x - f(lb) - 1, 20) << endl;


	return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <random>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

llong pow(int x, int n) {
    llong ans = x;
    if (n == 0) return 1;

    for(int i = 0; i < n - 1; i++) {
        ans *= x;
    }

    return ans;
}

void swap(int *X, int *Y){
    int t = *X; *X = *Y; *Y = t;
}

const static int nmax = 40, abmax = 10;

int dp[nmax + 1][nmax * abmax + 1][nmax * abmax + 1];

int main() {
    vector<pair<pair<int ,int>, int> > Prod;
    int n, ma, mb, a, b, c;
    cin >> n >> ma >> mb;

    rep(i, n) {
        cin >> a >> b >> c;
        Prod.push_back(make_pair(make_pair(a, b), c));
    }

    for (int i = 0; i <= n; ++i) {
        for (int ca = 0; ca <= nmax * abmax; ++ca) {
            for (int cb = 0; cb <= nmax * abmax; ++cb) {
                dp[i][ca][cb] = INF;
            }
        }
    }

    dp[0][0][0] = 0;

    for (int i = 0; i < n; ++i) {
        for (int ca = 0; ca <= nmax * abmax; ++ca) {
            for (int cb = 0; cb <= nmax * abmax; ++cb) {
                if (dp[i][ca][cb] == INF) continue;
                dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb]);
                dp[i + 1][ca + Prod[i].first.first][cb + Prod[i].first.second] = min(dp[i + 1][ca + Prod[i].first.first][cb + Prod[i].first.second], dp[i][ca][cb] + Prod[i].second);
            }
        }
    }

    int ans = INF;
    for (int ca = 1; ca <= nmax * abmax; ++ca) {
        for (int cb = 1; cb <= nmax * abmax; ++cb) {
            if (ca * mb == cb * ma) ans = min(ans, dp[n][ca][cb]);
        }
    }

    if (ans == INF) ans = -1;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 25984
import java.util.Scanner;

public class Main {
  static final String IDENTICAL = "IDENTICAL";
  static final String CLOSE = "CLOSE";
  static final String DIFFERENT = "DIFFERENT";

  public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	while (true) {
	  String s1 = in.next();
	  if (s1.equals(".")) break;
	  String[] arrStr1 = s1.split("\"", -1);
	  String s2 = in.next();
	  String[] arrSrt2 = s2.split("\"", -1);

	  if (arrStr1.length == arrSrt2.length) {
		int result = 0;
		for (int i = 0; i < arrStr1.length; i++) {
		  if (i % 2 == 0 && !arrStr1[i].equals(arrSrt2[i])) {
			result += 2;
		  } else if (i % 2 == 1 && !arrStr1[i].equals(arrSrt2[i])) {
			result++;
		  }
		}
		if (result == 0) {
		  System.out.println(IDENTICAL);
		} else if (result == 1) {
		  System.out.println(CLOSE);
		} else {
		  System.out.println(DIFFERENT);
		}
	  } else {
		System.out.println(DIFFERENT);
	  }
	}
  }
}



Measured memory_bytes: 28652
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處
int N, M, X;
const int MAXN = 12;
const int MAXM = 12;
vector<int> C(MAXN);
vector<vector<int>> A(MAXN, vector<int>(MAXM));

int solve(int idx, int c, vector<int> v) {
    if (idx == N) {
        bool ok = true;
        for (int i = 0; i < M; ++i) {
            if (v[i] < X)  ok = false;
        }
        return (ok ? c : -1);
    }
    int ret1 = solve(idx+1, c, v);
    for (int i = 0; i < M; ++i) {
        v[i] += A[idx][i];
    }
    int ret2 = solve(idx+1, c + C[idx], v);
    int ret = 1e9;
    if (ret1 != -1)  ret = min(ret, ret1);
    if (ret2 != -1)  ret = min(ret, ret2);
    return  (ret == 1e9 ? -1 : ret);
}

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> M >> X;
    for (int i = 0; i < N; ++i) {
        cin >> C[i];
        for (int j = 0; j < M; ++j) {
            cin >> A[i][j];
        }
    }
    int res = solve(0, 0, vector<int>(M));
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
typedef complex<double> cd;
static const double pi = 3.141592653589793;
// if(nextH >= 0 && nextH < H && nextW >= 0 && nextW < W)

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

  int n; cin >> n;
  vector<ll> A(n), B(n);
  vector<int> List(n);
  rep(i, n) {
    List[i] = i;
    cin >> A[i] >> B[i];
  }

  sort(List.begin(), List.end(), [&A,&B](int&a, int&b) {
    return A[a] + B[a] > A[b] + B[b];
  });

  ll takaTotal = 0, aoTotal = 0;
  rep(i, n) {
    if(i % 2 == 0) {
      takaTotal += A[List[i]];
    } else {
      aoTotal += B[List[i]];
    }
  }

  ll ans = takaTotal - aoTotal;
  cout << ans << endl;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int N; cin >> N;
  int tmp = 0;
  vector<int> data(N+1); 
  for(int i = 0; i < N-1 ; i++){
	cin >> tmp;
    data.at(tmp)++;
  }
  for(int i =1;i < data.size(); i++) cout << data.at(i) << endl;
}

Measured memory_bytes: 4044
//AtCoder 
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    ll A,B;
    cin>>A>>B;
    ll ans=0;
    for(ll i=A;i<=B;++i){
        auto a=to_string(i);
        auto b=a;
        reverse(b.begin(),b.end());
        if (a==b) ++ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
t_list = [int(input()) for _ in range(n)]


def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)


def lcm(a, b):
    return a * b // gcd(b, a % b)


r = 1
for i in range(n):
    r = lcm(r, t_list[i])
print(r)


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define INF_LL 1e18
#define INF 1e9

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()

using namespace std;

using ll = long long;
using PII = pair<int, int>;

template<typename T>
void chmax(T &a, T &b){
	a = max(a, b);
}

template<typename T>
void chmin(T &a, T &b){
	a = min(a, b);
}

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

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

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(void){
	int N;
	vector<string> a;
	int blank[514] = {};
	int res = INF;
	bool zero = true;
	cin >> N;
	REP(i, N){
		string s;
		cin >> s;
		a.push_back(s);
		REP(j, s.size()){
			if(s[j] == '#'){
				zero = false;
			}
			if(s[j] == '.'){
				blank[j]++;
			}
		}
	}
	int c = 0;
	REP(i, a.size()){
		if(blank[i] != 0){
			c++;
		}
	}
	if(zero){
		cout << -1 << endl;
		return 0;
	}

	REP(i, a.size()){
		bool there = false;
		int cnt = 0;
		REP(j, a.size()){
			if(a[j][i] == '#')
				there = true;
		}
		if(!there) cnt++;
		REP(j, a.size()){
			if(a[i][j] == '.') cnt++;
		}
		res = min(res, cnt+c);
	}
	cout << res << endl;
}

/*
const ll mod = 1e9+7;
int N;
ll x[114514];
ll sp[114514];
ll st[114514] = {};
ll be = 0;
ll last = 0;

int ok(int x){
	if(x == 0) return 0;
	
	if(sp[x-1] > 0)
		return be;
	be++;
	return be;
}

int main(void){
	ll res = 1;
	ll rest = 0;
	cin >> N;
	rest = N;
	REP(i, N){
		cin >> x[i];
		if(i > 0){
			sp[i] = x[i]-x[i-1]-1;
			if(sp[i-1] > 1){
				sp[i] += sp[i-1]-1;
				sp[i-1] = 1;
			}
		}else{
			sp[i] = x[i];
		}
		st[ok(i)]++;
	}

	ll now = 0;
	while(rest > 0){
		res = (res * st[now]) % mod;
		st[now]--;
		st[now+2] += st[now] + st[now+1];
		now+=2;
		rest--;
	}
	cout << res << endl;
}
*/


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

using namespace std;
typedef long long ll;

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


}


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

int main(){
  for(int i=0;i<3;i++){
    char c;
    scanf("%c", &c);
    if(c=='1') c='9';
    else if(c=='9') c='1';
    printf("%c",c);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 128
#pragma once


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

class SumOfGcdOfTuples
{
private:
  struct TestCase
  {
    unsigned long long K = 0;

    unsigned long long result = 0;
  };
  TestCase T = {};

public:
  void run()
  {
    Input();

    Calc();

    Output();
  }


private:
  int gcd(int a, int b) {
    if (b == 0) return a;

    return gcd(b, a % b);
  };

  void Calc()
  {
    auto hash = [](int a, int b, int c) {return a + b * 1000 + c * 1000000; };

    for (int i = 1; i <= T.K; ++i)
    {
      for (int j = i; j <= T.K; ++j)
      {
        for (int k = j; k <= T.K; ++k)
        {
          int add = gcd(gcd(i, j), k);

          if (j == k)
          {
            if (i == j)
            {
              T.result += (add);
            }
            else
            {
              T.result += (add) * 3;
            }
          }
          else
          {
            if (i == j)
            {
              T.result += (add) * 3;
            }
            else
            {
              T.result += (add) * 6;
            }
          }
        }
      }
    }

  }

  void Input()
  {
    cin >> T.K;
  }

  void Output()
  {
    cout << T.result << "\n" << flush;
  }
};

int main()
{
  SumOfGcdOfTuples prob = {};
  prob.run();

  return 0;
}



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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

ll gcd(ll p, ll q){ 
    while(q != 0){
        ll r=p%q;
        p=q;
        q=r;
    }
    return p;
}

int main(){
    ll n,a,b,c,d,e;
    cin>>n>>a>>b>>c>>d>>e;
    ll bn=min(e,min(d,min(c,min(a,b))));
    cout<<(n+(bn-1))/bn+4<<endl;
return 0;
}


Measured memory_bytes: 256