akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
#define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
#define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/






int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.precision(10); cout << fixed;
#ifdef LOCAL
  freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
  int n; cin >> n;
  if (n >= 30) cout << "Yes\n";
  else cout << "No\n";






/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
  return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


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

using namespace std;

int count=0;

void bubbleSort(vector<int>& a) {
    bool flag = true;
    while(flag) {
        flag = false;
        for(int j=a.size()-1; j>=1; j--) {
            if(a[j]<a[j-1]) {
                swap(a[j], a[j-1]);
                flag = true;
                count++;
            }
        }
    }
}

int main() {
    int n;
    cin >> n;
    vector<int> a;
    for(int i=0; i<n; i++) {
        int e;
        cin >> e;
        a.push_back(e);
    }
    bubbleSort(a);
    for(auto it = a.begin(); it!=a.end(); it++) {
        if(next(it)==a.end()) cout << *it << endl;
        else cout << *it << " ";
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3144
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,W;
  int v,w;
  cin >> n >> W;
  int g[n][W+1];
  for(int i=0;i<n;i++){
    cin >> v >> w;
    for(int j=0;j<W+1;j++){
      if(i==0){
	if(j-w>=0)g[i][j]=g[i][j-w]+v;
	else g[i][j]=0;
      }
      else{
	if(j-w<0)g[i][j]=g[i-1][j];
	else g[i][j]=max(g[i-1][j],g[i][j-w]+v);
      }
    }
  }
  cout << g[n-1][W] << endl;
  return 0;
}

Measured memory_bytes: 5064
L, A, B, M = map(int, input().split())

def mat_pow(x, n) :
    y = [[0] * 3 for _ in range(3)]
        
    for i in range(3) :
        y[i][i] = 1
        
    while n > 0 :
        if n & 1 :
            y = mat_mul(x, y)
        x = mat_mul(x, x)
        n >>= 1
        
    return y
    
def mat_mul(a, b) :
    I, J, K = len(a), len(b[0]), len(b)
    c = [[0] * J for _ in range(I)]
    for i in range(I) :
        for j in range(J) :
            for k in range(K) :
                c[i][j] += a[i][k] * b[k][j]
            c[i][j] %= M
    return c

n0 = -(-(10 ** 0 - A) // B)
n1 = -(-(10 ** 1 - A) // B)

ret = [[0], [A], [1]]

for d in range(1, 19) :
    mat = [[10**d, 1, 0], [0, 1, B], [0, 0, 1]]
    if n0 < 0 and 0 < n1 :
        n0 = 0
        
    if 0 <= n0 < n1 :
        ret = mat_mul(mat_pow(mat, n1 - n0), ret)
    n0, n1 = n1, min(-(-(10 ** (d + 1) - A) // B), L)

print(ret[0][0])

Measured memory_bytes: 41328
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;

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

    vector<int> order(N);
    int size = 1;
    for(int i = 1; i <= N; i++) {
        order[i-1] = i;
        size *= i;
    }
    vector<int> list(size);

    a = 0;
    for(int i = 0; i < N; i++) {
        a *= 10;
        int tmp;
        cin >> tmp;
        a += tmp;
    }
    b = 0;
    for(int i = 0; i < N; i++) {
        b *= 10;
        int tmp;
        cin >> tmp;
        b += tmp;
    }

    int count = 0;
    do {
        int number = 0;
        for(int i = 0; i < N; i++) {
            number *= 10;
            number += order[i];
        }
        list[count] = number;
        count++;
    } while(next_permutation(order.begin(), order.end()));

    sort(list.begin(), list.end());
    vector<int>::iterator iter = find(list.begin(), list.end(), a);
    int a_idx = distance(list.begin(), iter);
    iter = find(list.begin(), list.end(), b);
    int b_idx = distance(list.begin(), iter);
    cout << abs(a_idx-b_idx) << endl;
    return 0;
}

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

const int MAX_E = 100000;
const int MAX_V = 1000;

struct edge{
	int u, v, cost;
	edge(int u_, int v_, int cost_ ){
		u = u_;
		v = v_;
		cost = cost_;
	} 
};

bool comp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

// 入力
int s, d;
// 親
int par[MAX_V];
// 木の深さ
int rank[MAX_V];

// union-find の初期化
void init_union_find(int n){
	for(int i=0 ; i < n ; i++ ){
		par[i] = i;
		rank[i] = 0;
	}
}

// x の root を返す
int find(int x){
	if( par[x] == x ){
		return x;
	}else{
		return par[x] = find( par[x] );
	}
}

// x と y の属する集合を併合
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]++;
	}
}

// x と y が同じ集合に属するかどうかを返す
bool same(int x, int y){
	return find(x) == find(y);
}

// ノード x が地区かどうか
bool is_district(int x){
	return ( x >= s );
}

int solve(vector<edge> v){
	init_union_find( d + s );
	sort( v.begin() , v.end() , comp );
	int used[MAX_V] = {0};
	
	int sum = 0;
	bool flag = false;
	for(int i=0 ; i < v.size() ; i++ ){
		edge e = v[i];
		
		if( !same( e.u , e.v ) ){
			if( !is_district( e.u ) && used[e.v] == 0 ){
				unite( e.u , e.v );
				flag = true;
				sum += e.cost;
				used[e.v] = 1;
				for(int i = s ; i < s+d ; i++ ){
					if( same( e.v , i ) ){
						used[i] = 1;
					}
				}
			}else if( is_district( e.u ) && is_district( e.v ) && !(used[e.u] && used[e.v]) ){ 
				unite( e.u , e.v );
				sum += e.cost;
				if( used[e.u] && !used[e.v] ){
					used[e.v] = 1;
					for(int i = s ; i < s+d ; i++ ){
						if( same( e.v , i ) ){
							used[i] = 1;
						}
					}
				}
				if( !used[e.u] && used[e.v] ){
					used[e.u] = 1;
					for(int i = s ; i < s+d ; i++ ){
						if( same( e.u , i ) ){
							used[i] = 1;
						}
					}
				}
			}
		}
		
		int cnt=0;
		for(int i = s ; i < s+d ; i++ ){
			cnt += used[i];
		}
		if( cnt == d && flag ){
			break;
		}
	}
	return sum;
}

int main(){
	
	while( cin >> s >> d , s || d ){
		vector<edge> v;		
		
		for(int i=0 ; i < s ; i++ ){
			for(int j=0 ; j < d ; j++ ){
				int cost;
				cin >> cost;
				if( cost == 0 ) continue;
				
				edge e( i , j+s , cost );
				v.push_back( e );
			}
		}
		for(int i=s ; i < d+s-1 ; i++ ){
			for(int j=i+1 ; j < d+s ; j++ ){
				int cost;
				cin >> cost;
				if( cost == 0 ) continue;
				
				edge e( i , j , cost );
				v.push_back( e );
			}
		}
		int ans = solve( v );
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
import numpy

n,d = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]
counter = 0

for i in range(n):
  for j in range(i+1,n):
    ans = numpy.sqrt(sum([(pair[0]-pair[1])**2 for pair in zip(X[i],X[j])]))
    if ans.is_integer():
      counter += 1
      
print(counter)

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

ll MAX = 1000000000000000000;

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}


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

    vector<ll> sum(n);
    sum[0] = a[0];
    rep(i,n-1){
        sum[i+1] = sum[i] + a[i+1];
    }
    ll ans = MAX;
    rep(i,n-1){
        ll snuke = sum[i], arai = sum[n-1] - sum[i];
        chmin(ans, abs(snuke - arai));
    }

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

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b) (v)[(a)].pb(b),(v)[(b)].pb((a))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 2*1e5+5,M = 105;

using namespace std;

int main()
{
	abdelrahman001
	ll n,arr[N];
	cin >> n;
	for(int i = 0;i<n;i++)
		cin >> arr[i];
	ll low = -1e12,high = 1e12,mid1,mid2,ans;
	while(low<=high)
	{
		mid1 = low + (high - low)/3;
		mid2 = high - (high - low)/3;
		ll sum1 = 0,sum2 = 0;
		for(int j = 0;j<n;j++)
			sum1 += abs(arr[j] - (mid1+j+1));
		for(int j = 0;j<n;j++)
			sum2 += abs(arr[j] - (mid2+j+1));
		if(sum1 < sum2)
			ans = sum1,high = mid2 - 1;
		else
			ans = sum2,low = mid1 + 1;
	}
	cout << ans;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for (int i=0; i<N; i++) {
    cin >> s.at(i);
  }
  
  int M;
  cin >> M;
  vector<string> t(M);
  for (int i=0; i<M; i++) {
    cin >> t.at(i);
  }
  
  int max = 0;
  
  for (int i=0; i<N; i++) {
    int money = 0;
    for (int j=0; j<N; j++) {
      if (s.at(i) == s.at(j)) {
        money++;
      }
    }
    for (int j=0; j<M; j++) {
      if (s.at(i) == t.at(j)) {
        money--;
      }
    }
  	if (money > max) {
      max = money;
    }
  }
  
  cout << max << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,n) for(i=a;i<n;i++)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define sortrev(x) sort(all(x),greater<int>())
#define pi 3.1415926535897932384626

typedef pair<int,int> pii;
typedef pair<ll, ll> pl;
typedef vector<int>	vi;
typedef vector<ll>	vl;
typedef vector<pii>	vpii;
typedef vector<pl>	vpl;
typedef vector<vi>	vvi;
typedef vector<vl>	vvl;
typedef vector<double> vd;


const int mod = 100000007;
const int inf = 100000005;
const int N = 200005, M = N;
ll i,j,idx;
int dp[50][50];

void solve() {
  ll n;
  cin>>n;

  vl vec(n);
  fo(i,0,n) cin>>vec[i];

  sortall(vec);
  ll ans = 0 , k;

  fo(i,0,n-2) {
    fo(j,i+1,n) {
        idx = lower_bound(all(vec) , vec[i]+vec[j]) - vec.begin();
        k = idx - j - 1;
        ans+=k;
    }
  }
  cout<<ans<<"\n";
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

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

    return 0;
}




Measured memory_bytes: 3676
N, M = map(int, input().split())

A = []
d = [1 for i in range(N+1)]
for i in range(M):
    a = int(input())
    A.append(a)
    d[a] = 0
    if i != 0:
        if a-A[i-1] == 1:
            print(0)
            exit()

dp = [0 for i in range(N+1)]
dp[0] = 1
if d[1]:
    dp[1] = 1

for n in range(2,N+1):
    # if d[n] == 0:
        # dp[n] = (dp[n-1] if d[n-1] == 0 else dp[n-2]+dp[n-3])+(dp[n-2] if d[n-2] == 0 else 0)
    dp[n] = dp[n-1]+dp[n-2]
    buff = 0
    if d[n-1]:
        buff += dp[n-1]
    if d[n-2]:
        buff += dp[n-2]
    dp[n] = buff

# print(dp)
print(dp[N]%(10**9+7))


Measured memory_bytes: 463512
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>

using namespace std;

int main(){
	int n, m; scanf("%d %d", &n, &m);
	vector<pair<int, int> > v(m);
	for(int i = 0; i < m; i++){
		int a, b; scanf("%d %d", &a, &b);
		v[i] = make_pair(b, a);
	}
	sort(v.begin(), v.end());
	int res = 0, p = 0;
	for(int i = 0; i < m; i++) if(v[i].second > p){
		res++;
		p = v[i].first - 1;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 1024
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)5e5
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
ll calc(ll a,ll b,ll x){
	return (a*x)/b-a*(x/b);
}
int main(){
	ll a,b,n,l=1,r,m,c=0;cin>>a>>b>>n;
	r=min(n,b);
	while(c++<60){
		m=(l+r)/2;
		if(calc(a,b,m)>=calc(a,b,m-1)) l=m+1;
		else r=m-1;
	}cout<<calc(a,b,m)<<endl;
//	m=0;
//	for(int i=1;i<=n;i++){
//		cout<<i<<" "<<calc(a,b,i)<<endl;
//		m=max(calc(a,b,i),m);
//	}cout<<m<<endl;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 1000000007
#define inf 1000000000000000000
const double pi = acos(-1);
const int sz = 200002;
int n, m, k;
vector<int>a;
int main() {
	io
	cin>>n>>m;
	cout<<m*n;
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int a,b,c=0,i,p[1010];
int main()
{
	cin>>a>>b;
	for(i=0;i<a;++i)cin>>p[i];
	sort(p,p+a);
	for(i=0;i<b;++i)c+=p[i];
	cout<<c;
}


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

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

    int l,r,d; cin >> l >> r >> d;
    cout << r/d - (l-1)/d << endl;
}

Measured memory_bytes: 3616
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n + 2];
		int[] b = new int[n + 1];
		for ( int i = 1; i <= n + 1; i++ ) {
			a[i] = in.nextInt();
		}
		for ( int i = 1; i <= n; i++ ) {
			b[i] = in.nextInt();
		}

		long beated = 0;
		for ( int i = 1; i <= n; i++ ) {
			// モンスタの方が多いor同数の場合 bを使い切る
			if ( a[i] >= b[i] ) {
				beated += b[i];
				a[i] -= b[i];
				b[i] = 0;
			}
			// 勇者の方が多い場合 aを使い切る
			else if ( a[i] < b[i] ) {
				beated += a[i];
				b[i] -= a[i];
				a[i] = 0;

				// 次の町にも手を出す
				if ( a[i + 1] >= b[i] ) {
					beated += b[i];
					a[i + 1] -= b[i];
					b[i] = 0;

				} else if ( a[i + 1] < b[i] ) {
					beated += a[i + 1];
					b[i] -= a[i + 1];
					a[i + 1] = 0;
				}
			}
		}
		System.out.println(beated);
		in.close();
	}
}

Measured memory_bytes: 65000
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;

#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define Rep(i, a, b) for (int (i) = (a) - 1; (i) < (b); (i)++)
#define REP(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define Sort(a, len, cmp) sort(a + 1, a + len + 1, cmp)
#define ass(a, sum) memset(a, sum, sizeof(a))

#define ls ((rt) << 1)
#define rs ((rt) << 1 | 1)
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define ENDL cout << endl
#define SZ(x) ((int)x.size())

typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef pair <ll, ll> pll ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
typedef map <ll, ll> mll ;

const int N = 100010 ;
const double eps = 1e-8 ;
const int iinf = INT_MAX ;
const ll linf = 2e18 ;
const double dinf = 1e30 ;
const int MOD = 1000000007 ;

inline int read(){
    int X = 0, w = 0 ;
	char ch = 0 ;
    while (!isdigit(ch)) { w |= ch == '-' ; ch = getchar() ; }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar() ;
    return w ? - X : X ;
}

void write(int x){
     if (x < 0) putchar('-'), x = - x ;
     if (x > 9) write(x / 10) ;
     putchar(x % 10 + '0') ;
}

void print(int x) {
	cout << x << endl ;
	exit(0) ;
}

void PRINT(string x) {
	cout << x << endl ;
	exit(0) ;
}

void douout(double x){
	 printf("%lf\n", x + 0.0000000001) ;
}

int a[N], sum[N * 10], bit[N * 10] ;
int n, l, r ;

void add(int a) {
	for (; a <= 2 * N; a += lowbit(a)) bit[a]++ ;
}

int query(int a){
	int res = 0 ;
	for (; a; a -= lowbit(a)) res += bit[a] ;
	return res ;
}

int check(int x) {
	for (int i = 0; i <= 2 * N; i++) bit[i] = 0 ;
	clr(sum) ;
	for (int i = 1; i <= n; i++) {
		sum[i] = sum[i - 1] + (a[i] >= x ? 1 : -1) ;
	}
	ll ans = 0 ;
	for (int i = 0; i <= n; i++) {
		ans += query(sum[i] + N) ;
		add(sum[i] + N) ;
	}
	return ans >= 1ll * n * (n + 1) / 4 ;
}

signed main(){
	scanf("%d", &n) ;
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]), r = max(r, a[i]) ;
	while (l <= r) {
		int mid = (l + r) >> 1 ;
		if (check(mid)) l = mid + 1 ;
		else r = mid - 1 ;
	}
	printf("%d\n", r) ;
}

/*
写代码时请注意：
	1.是否要开Long Long？数组边界处理好了么？
	2.实数精度有没有处理？
	3.特殊情况处理好了么？
	4.做一些总比不做好。
思考提醒：
	1.最大值和最小值问题可不可以用二分答案？
	2.有没有贪心策略？否则能不能dp？
*/


Measured memory_bytes: 7168
package main

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

var sc *bufio.Scanner

func init() {
	// 100MB
	bufsize := 100 * 1024 * 1024
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
	sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
	s := readStringArray(n)
	a := make([]int, n)
	for i := range a {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i] = sc.Text()
	}
	return a
}
func max(ns ...int) int {
	max := ns[0]
	for _, n := range ns {
		if n > max {
			max = n
		}
	}
	return max
}
func min(ns ...int) int {
	min := ns[0]
	for _, n := range ns {
		if n < min {
			min = n
		}
	}
	return min
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	N, K := readInt2()
	var s string
	l := N
	for {
		r := l % K
		l /= K
		s = strconv.Itoa(r) + s
		//fmt.Printf("l: %d, r: %d, s: %s\n", l, r, s)
		if l == 0 {
			break
		}
	}

	fmt.Println(len(s))
}


Measured memory_bytes: 640
# N
# A1 AN
# k番目のボールを取り除いたN-1個の中から書かれている数字が同じボールを選べる数を出力(1つずつ)
N = gets.to_i
A = gets.split.map(&:to_i)
H = Hash.new(0)
A.each do |i|
  H[i] += 1
end
sum = 0
H.each do |k, v|
  sum += v * (v - 1) / 2
end
A.each do |i|
  puts sum - (H[i] * (H[i] - 1)) / 2 + ((H[i] - 1) * (H[i] - 2)) / 2
end

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

struct UnionFind {
  vector<int> par, siz;
  UnionFind (int n) {
    par.resize(n);
    siz.resize(n);
    for (int i = 0; i < n; i++) {
      par[i] = i, siz[i] = 1;
    }
  }
  int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  bool unit(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return false;
    if (siz[x] > siz[y]) {
      par[y] = x, siz[x] += siz[y];
    } else {
      par[x] = y, siz[y] += siz[x];
    }
    return true;
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

int main() {
  ios::sync_with_stdio(false);
  int N, M, K;
  cin >> N >> M >> K;
  UnionFind UF(N);
  vector<int> V(N, -1);
  for (int i = 0, A, B; i < M && cin >> A >> B; i++) {
    UF.unit(--A, --B);
    V.at(A)--, V.at(B)--;
  }
  for (int i = 0; i < N; i++) V.at(i) += UF.siz.at(UF.find(i));
  for (int i = 0, C, D; cin >> C >> D; i++)
    if (UF.same(--C, --D)) V.at(C)--, V.at(D)--;
  for (int i = 0; i < N; i++) cout << V.at(i) << "\n";
}

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

using namespace std;

#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000000
#define INFL (1LL << 60)
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
  int n;
  cin >> n;
  int a[n+2] = { };
  FOR(i, 1, n+1) cin >> a[i];
  ll t = 0;
  REP(i, n+1){
    t += abs(a[i+1] - a[i]);
  }
  REP(i, n){
    cout << t - abs(a[i+2]-a[i+1]) - abs(a[i+1] - a[i]) + abs(a[i+2] - a[i]) << endl;
  }
	return 0;
}

Measured memory_bytes: 1664
def comb(n, r):
  if n < 0 or r < 0:
    raise ValueError
  r = min(r, n - r)
  if n == 0 or r == 0:
    return 1
  return (n - r + 1) * comb(n, r - 1) // r

N, K = list(map(int, input().split()))
for i in range(K):
  if N - K + 1 < i + 1:
    print('0')
    continue
  print(comb(N - K + 1, i + 1) * comb(K - 1, i) % (10 ** 9 + 7))

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

int main() {

	int N, A, B;
	cin >> N >> A >> B;

	if (A > B) {
		if (A + B > N) {
			cout << B << " " << A + B - N << endl;
		}
		else {
			cout << B << " " << "0" << endl;
		}
	}
	else {
		if (A + B > N) {
			cout << A << " " << A + B - N << endl;
		}
		else {
			cout << A << " " << "0" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
Ai = list(int(input()) for j in range(int(input())))
chck_nmbrs = []
cnt = 1
lghtd = 1
while cnt <= len(Ai):
    lghtd = Ai[lghtd - 1]
    if lghtd == 2:
        print(cnt)
        exit()
    cnt += 1
print(-1)


Measured memory_bytes: 7072
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long int n;
    cin>>n;
    long double  m;
    cin>>m;
    long long l=m*100 + 0.5;
    long long int ans = (n*l)/100;
    cout<<ans<<endl;
   
    
}


Measured memory_bytes: 3700
import java.io.*;
import java.util.*;
public class Main
{
	final int logn=20;
	int n,x[],l,dp[][];
	private void solve()throws IOException
	{
		n=nextInt();
		x=new int[n+1];
		for(int i=1;i<=n;i++)
			x[i]=nextInt();
		l=nextInt();
		init();
		int q=nextInt();
		while(q-->0)
		{
			int a=nextInt();
			int b=nextInt();
			if(a>b)
			{
				int t=a;
				a=b;
				b=t;
			}
			int ans=0;
			for(int i=logn;i>=0;i--)
				if(dp[i][a]<b)
				{
					ans+=1<<i;
					a=dp[i][a];
					if(a==b)
						break;
				}
			out.println(ans+1);
		}
	}
	void init()
	{
		dp=new int[logn+1][n+1];
		for(int i=1;i<=n;i++)
			dp[0][i]=floor(x[i]+l);
		for(int i=1;i<=logn;i++)
			for(int j=1;j<=n;j++)
				dp[i][j]=dp[i-1][dp[i-1][j]];
	}
	int floor(int d)
	{
		int low=1,high=n,ans=0;
		while(low<=high)
		{
			int mid=(low+high)/2;
			if(x[mid]<=d)
			{
				ans=mid;
				low=mid+1;
			}
			else
				high=mid-1;
		}
		return ans;
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 58852
#include<iostream>

using namespace std;

int n[44];

int fib(int x) {
	n[0] = 1;
	n[1] = 1;
	for (int i = 2; i <= x; i++) {
		n[i] = n[i - 1] + n[i - 2];
	}
	return n[x];
}

int main() {
	int n;
	cin >> n;
	cout << fib(n) << endl;
	return 0;
}

Measured memory_bytes: 3104
import itertools
def main():
    n = int(input())
    p_list = list(itertools.permutations ([i+1 for i in range(n)]))
    p = tuple(map(int, input().split(" ")))
    q = tuple(map(int, input().split(" ")))
    pn = 0
    qn = 0
    for i in range(len(p_list)):
        if p == p_list[i]:
            pn = i
        if q == p_list[i]:
            qn = i
    print(abs(pn-qn))

if __name__ == "__main__":
    main()

Measured memory_bytes: 13896
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int aa = abs(b-a), bb = abs(c-a), cc = abs(b-c);
  cout << min(aa + bb, min(aa + cc, bb + cc)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
ll ceil1(ll a,ll b)
{
	if(a%b==0)
		return a/b;
	else
		return a/b+1;
}

void solve()
{
	string s;
	cin>>s;
	string s1="gp",s2="pgg";
	while(s1.size()<=1e5+3)
	{
		s1+=s1;
	}
	while(s2.size()<=1e5+3)
	{
		s2+=s2;
	}
	ll ans=0;
	for(ll i=0;i<s.size();i++)
	{
		if(s[i]=='g')
		{
			if(s1[i]=='p')
				ans++;
		}
		else
		{
			if(s1[i]=='g')
				ans--;
		}
	}
	ans=max(ans,0ll);
	ll cnt=0;
	for(ll i=0;i<s.size();i++)
	{
		if(s[i]=='g')
		{
			if(s2[i]=='p')
				cnt++;
		}
		else
		{
			if(s2[i]=='g')
				cnt--;
		}
	}
	cout<<max(ans,cnt);
	return;
}

int main()
{
	fast;
	ll q=1;
	// cin>>q;
	while(q--)
		solve();
	return 0;
}



Measured memory_bytes: 4016
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	a1 := readInt()
	b1 := readInt()
	a2 := readInt()
	b2 := readInt()
	a3 := readInt()
	b3 := readInt()

	answer := solve(a1, b1, a2, b2, a3, b3)
	fmt.Printf("%v\n", answer)
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	i, e := strconv.Atoi(readString())
	if e != nil {
		panic(e)
	}
	return i
}

func solve(a1, b1, a2, b2, a3, b3 int) string {
	nums := []int{a1, b1, a2, b2, a3, b3}
	if sumSlice(nums) != 15 {
		return "NO"
	}
	path1 := []int{a1, b1}
	path2 := []int{a2, b2}
	path3 := []int{a3, b3}
	paths := [][]int{path1, path2, path3}
	for i, p1 := range paths {
		a := p1[0]
		b := p1[1]
		otherPaths := append(paths[:i], paths[i+1:]...)
		for j, p2 := range otherPaths {
			if a == p2[0] || b == p2[0] || a == p2[1] || b == p2[1] {
				lastPath := append(otherPaths[:j], otherPaths[j+1:]...)
				if lastPath[0][0] == p2[0] || lastPath[0][1] == p2[0] || lastPath[0][0] == p2[1] || lastPath[0][1] == p2[1] {
					return "YES"
				}
			}
		}
	}
	return "NO"
}

func sumSlice(nums []int) (sum int) {
	for _, n := range nums {
		sum += n
	}
	return
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
 
#define N 1000
#define max(a,b) ( a > b ? a : b )
 
int main(void)
{
    int iii, i, j, m, n;
    char x[N], y[N];
    int table[N+1][N+1];
    int num;
    scanf( "%d", &num );
 
    for( iii=0; iii<num; ++iii ) {
        scanf( "%s", x );
        scanf( "%s", y );
 
        m = strlen(x);
        n = strlen(y);
 
        for( i=0; i<=m; ++i )
            for( j=0; j<=n; ++j )
                table[i][j] = 0;
 
        for( i=1; i<=m; ++i )
            for( j=1; j<=n; ++j )
                if ( x[i-1] == y[j-1] )
                    table[i][j] = table[i-1][j-1] + 1;
                else
                    table[i][j] = max( table[i][j-1], table[i-1][j] );
 
        printf( "%d\n", table[m][n] );
    }
 
    return 0;
}

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

#define Max 1000

int s[Max],top;


void push(int);
int pop(void);

int main(){
  char A[100];
  int i,x,first,second;
  

  while(scanf("%s",A)!=EOF){
    if(A[0]=='+'){
      first=pop();
      second=pop();
      push(first+second);
    }
    else if(A[0]=='-'){
      second=pop();
      first=pop();
      push(first-second);
    }
    else if(A[0]=='*'){
      first=pop();
      second=pop();
      push(first*second);
     
    }
    else{
      x=atoi(A);
      push(x);
    }
  }
  
  printf("%d\n",pop());
  
  
    
  
  return 0;
}



int pop(){
  top--;
  return s[top+1];
}

void push(int x){
  
  
  s[++top]=x;
}

  

  



Measured memory_bytes: 2036
/* C++標準ヘッダファイル */
/* 文字列ライブラリ */
#include <string>

/* コンテナライブラリ */
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>

/* アルゴリズムライブラリ */
#include <algorithm>

/* 数値演算ライブラリ */
#include <cmath>

/* 入出力ライブラリ */
#include <iostream>

/* std使用<-namespace */
using namespace std;

/* define, typedef */
#define rpt(i, n) for(ll i = 0; i < (n); i++)  // リピート
typedef long long ll;


/* main関数 */
int main(void) {
	int a, b;
	cin >> a >> b;
	int c;
	c = a - 2 * b;
	if (c < 0) cout << 0;
	else cout << c;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const ll is_query = -(1LL << 62);
struct Line{
    ll m, b;
    mutable function <const Line*()> succ;
    bool operator <(const Line &rhs) const {
        if (rhs.b != is_query) return m < rhs.m;
        const Line *s = succ();
        if (!s) return 0;
        ll x = rhs.m;
        return b - s->b < (long double)(s->m - m) * x;
    }
};
struct CHT : public multiset<Line> {
    bool bad(iterator y) {
        auto z = next(y);
        if (y == begin()) {
            if (z == end()) return 0;
            return y->m == z->m && y->b <= z->b;
        }
        auto x = prev(y);
        if (z == end()) return y->m == x->m && y->b <= x->b;
        return (long double)(x->b - y->b) * (z->m - y->m) >= (long double)(y->b - z->b) * (y->m - x->m);
    }
    void add(ll m, ll b) {
        m = -m; b = -b;
        auto y = insert({ m, b });
        y->succ = [=] {return next(y) == end() ? 0 : &*next(y);};
        if (bad(y)) { erase(y); return; }
        while (next(y) != end() && bad(next(y))) erase(next(y));
        while (y != begin() && bad(prev(y))) erase(prev(y));
    }
    ll eval(ll x) {
        auto l = *lower_bound((Line) { x, is_query });
        return -(l.m * x + l.b);
    }
};

ll n, C, x;
ll dp[200001];
vector <ll> a;
CHT cht;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> C;
    for(int i = 0 ; i < n && cin >> x ; i++)
        a.push_back(x);
    dp[0] = 0;
    cht.add(a[0], a[0] * a[0]);
    for(int i = 1 ; i < n ; i++){
        dp[i] = cht.eval(-2 * a[i]) + a[i] * a[i] + C;
        cht.add(a[i], a[i] * a[i] + dp[i]);
    }
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 22128
const log = console.log;

const createScanFunctions = (input: string) => {
  const str = input.trim();
  const len = str.length;
  let index = 0;

  const scan = () => {
    const startIndex = index;

    while (index < len) {
      const char = str[index];

      if (char === " " || char === "\n")
        return str.substring(startIndex, index++);

      index++;
    }

    return str.substr(startIndex);
  };

  const scanInt = () => parseInt(scan());

  return { scan, scanInt };
};

// ----

interface Restaurant {
  no: number;
  city: string;
  point: number;
}

function Main(input: string): void {
  const { scan, scanInt } = createScanFunctions(input);

  const n = scanInt();

  const restaurantList = new Array<Restaurant>(n);

  for (let i = 1; i <= n; i++) {
    restaurantList[i] = {
      no: i,
      city: scan(),
      point: scanInt()
    };
  }

  restaurantList.sort((a, b) => {
    const cityComparison = a.city.localeCompare(b.city);

    return cityComparison || b.point - a.point;
  });

  const answerList = new Array<number>(n);

  for (let i = 0; i < n; i++) {
    answerList[i] = restaurantList[i].no;
  }

  log(answerList.join("\n"));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7756
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))

//辺の情報を個別に持つタイプ
typedef struct edge{ll s,g,c;}E;
typedef struct graph{
	int vcnt,ecnt;
	E  e[200010];//適宜変える
	int id[100010];//適宜変える
}G;

int esort(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	if((*p).g<(*q).g)return -1;
	return 1;
}

G g;
void readgraph(){
	//適宜変える
	ll n;
	scanf("%lld",&n);
	rep(i,0,n-1){
		ll x,y,c;
		scanf("%lld%lld%lld",&x,&y,&c);
		g.e[2*i].s=x;
		g.e[2*i].g=y;
		g.e[2*i].c=c;
		g.e[2*i+1].s=y;
		g.e[2*i+1].g=x;
		g.e[2*i+1].c=c;
	}
	g.vcnt=n;
	g.ecnt=2*n-2;
	qsort(g.e,g.ecnt,sizeof(E),esort);
 
	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//番兵
}

ll dp1[100010];//頂点に対する答え
ll dp2[200010];//辺に対する答え
ll cum[2][200010];//累積和
ll munit=0;//単位元
ll monoop(ll x,ll y){return max(x,y);}

ll dfs2(int);
ll dfs1(int v){
	if(dp1[v]!=-1)return dp1[v];
	rep(i,g.id[v],g.id[v+1]){
		if(i==g.id[v])cum[0][i]=munit;
		else cum[0][i]=monoop(cum[0][i-1],dfs2(i-1)+g.e[i-1].c);
	}
	for(int i=g.id[v+1]-1;i>=g.id[v];i--){
		if(i==g.id[v+1]-1)cum[1][i]=munit;
		else cum[1][i]=monoop(cum[1][i+1],dfs2(i+1)+g.e[i+1].c);
	}
 
	ll temp=munit;
	rep(i,g.id[v],g.id[v+1])temp=monoop(temp,dfs2(i)+g.e[i].c);
	return dp1[v]=temp;
}
ll dfs2(int e){
	if(dp2[e]!=-1)return dp2[e];
	if(dp1[g.e[e].g]!=-1){
		//逆辺のindexが必要
		int v=g.e[e].g;
		int l=g.id[v],r=g.id[v+1];
		while(r-l>1){
			int m=(l+r)/2;
			if(g.e[m].g<=g.e[e].s)l=m;
			else r=m;
		}
		return dp2[e]=monoop(cum[0][l],cum[1][l]);
	}
	ll temp=munit;
	int v=g.e[e].g;
	rep(i,g.id[v],g.id[v+1]){
		if(g.e[i].g!=g.e[e].s)temp=monoop(temp,dfs2(i)+g.e[i].c);
	}
	return dp2[e]=temp;
}

int main(){
	readgraph();
	rep(i,0,g.vcnt)dp1[i]=-1;
	rep(i,0,g.ecnt)dp2[i]=cum[0][i]=cum[1][i]=-1;
	rep(i,0,g.vcnt)printf("%lld\n",dfs1(i));
}


Measured memory_bytes: 3448
#include <iostream>
#include <climits>
#include <algorithm>

int n;

bool isOpen[100][10];
int price[100][11];

int count[100];
int profit(int bits) {
	for (auto&& e : count)
		e = 0;
	
	for (int i = 0; i < 10; ++i) {
		if (((bits >> i) & 1) == 0)
			continue;

		for (int j = 0; j < n; ++j)
			if (isOpen[j][i])
				++count[j];
	}

	int ret = 0;
	for (int i = 0; i < n; ++i)
		ret += price[i][count[i]];

	return ret;
}

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

	for (int i = 0; i < n; ++i)
		for (auto&& e : isOpen[i])
			std::cin >> e;

	for (int i = 0; i < n; ++i)
		for (auto&& e : price[i])
			std::cin >> e;

	int ans = std::numeric_limits<int>::min();
	for (int i = 1; i < (1 << 10); ++i)
		ans = std::max(ans, profit(i));

	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1000005;

int s[N],top,a[N],l[N],r[N],n,ans;

signed main() {
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++) {
        while(top && a[i]<a[s[top]]) r[s[top]]=i, --top;
        s[++top]=i;
    }
    while(top) r[s[top]]=n+1, --top;
    for(int i=n;i>=1;--i) {
        while(top && a[i]<a[s[top]]) l[s[top]]=i, --top;
        s[++top]=i;
    }
    while(top) l[s[top]]=0, --top;
    for(int i=1;i<=n;i++) {
        ans += a[i] * (r[i]-i) * (i-l[i]);
    }
    cout<<ans;
}


Measured memory_bytes: 14080
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <stack>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

using namespace std;

bool is_integer( float x ){
    return floor(x)==x;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

//yakusuu rekkyo
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // push its partner
            if (N/i != i) res.push_back(N/i);
        }
    }

    sort(res.begin(), res.end());
    return res;
}


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // exponential

        // divide as much as you can
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // push the result
        res.push_back({a, ex});
    }

    // last num (if the lasting n is prime number and not 1)
    if (N != 1) res.push_back({N, 1});
    return res;
}



int main() {
    string s;cin >> s;
    stack<char> tmp;
    int ans = 0;
    rep(i,s.length()){
        if(tmp.empty()) tmp.push(s[i]);
        else{
            if(tmp.top() != s[i]){
                ans ++;
                tmp.pop();
            }else{
                tmp.push(s[i]);
            }
        }
    }

    cout << ans*2;

    return 0;
}











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

ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
  return a / gcd(a, b) * b;
}

int main()
{
  ll a, b;
  cin >> a >> b;
  ll ans = lcm(a, b);
  cout << ans << endl;
}


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

int main()
{
  string a,b;cin>>a>>b;
  if(a.size()>b.size()){printf("GREATER\n");return 0;}
  else if(a.size()<b.size()){printf("LESS\n");return 0;}
  for(int i=0;i<a.size();i++)
  {
    if(a[i]>b[i]){printf("GREATER\n");return 0;}
    else if(a[i]<b[i]){printf("LESS\n");return 0;}
  }
  printf("EQUAL\n");
}

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

long long int a, d;
struct query
{
	int x, y, z;
};

vector<query>all;

long long int saiki( long long int K, long long int N ) {
	if( N == all.size() ) {
		return a + d*K;
	}
	query now = all[N];
	if( now.x == 0 ) {
		if( now.y <= K&&K <= now.z ) {
			long double center = (now.y + now.z) / 2;
			K = center * 2 - K;
		}
	} else if( now.x == 1 ) {
		if( now.y <= K&&K <= now.z ) {
			return 1 + saiki( K, N + 1 );
		}
	} else {
		if( now.y <= K&&K <= now.z ) {
			return saiki( K, N + 1 ) / 2;
		}
	}
	return saiki( K, N + 1 );
}

int main() {
	long long int N;
	cin >> N;
	cin >> a >> d;

	long long int M;
	cin >> M;
	all.resize( M );
	for( size_t i = 0; i < M; i++ ) {
		long long int x, y, z;
		cin >> x >> y >> z;
		all[i].x = x;
		y--;
		all[i].y = y;
		z--;
		all[i].z = z;
	}
	reverse( all.begin(), all.end() );
	long long int K;
	cin >> K;
	K--;
	cout << saiki( K, 0 ) << endl;
}

Measured memory_bytes: 5728
// #include {{{
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <random>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>
// }}}

using namespace std;

// macros {{{
template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

template<typename InputIt>
void PRINT_RANGE(InputIt first, InputIt last)
{
    for(; first != last; ++first)
        cout << *first << (first==last ? "" : " ");
    cout << "\n";
}

template<typename T>
void PRINT_MATRIX(T mat, size_t nr, size_t nc)
{
    for(size_t r = 0; r < nr; ++r) {
        for(size_t c = 0; c < nc; ++c) {
            cout << mat[r][c] << (c==nc-1 ? "" : " ");
        }
        cout << "\n";
    }
}

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)
// }}}

// types {{{
using ll  = long long;
using ull = unsigned long long;
// }}}

int N, Q, K;
vector<pair<int,int>> G[100001];

ll dist[100001]; // K からの最短距離

void dfs(int v, int v_prev, ll d_total)
{
#ifdef DEBUG
    cout << "dfs: " << v << "\n";
#endif
    dist[v] = d_total;

    for(auto p : G[v]) {
        int v_next = p.first;
        int d      = p.second;
        if(v_next == v_prev) continue;
        dfs(v_next, v, d_total+d);
    }
}

void solve()
{
    dfs(K, -1, 0);

    REP(i, Q) {
        int x, y;
        cin >> x >> y;
        cout << dist[x] + dist[y] << "\n";
    }
}

int main()
{
    cin >> N;
    REP(i, N-1) {
        int a, b, c;
        cin >> a >> b >> c;
        G[a].push_back(make_pair(b,c));
        G[b].push_back(make_pair(a,c));
    }
    cin >> Q >> K;

    solve();

    return 0;
}


Measured memory_bytes: 12800
N, M, X = map(int, input().split())
Ai = list(map(int, input().split()))
m = [i for i in Ai if i < X]
M = [o for o in Ai if o > X]
a = len(m)
b = len(M)
if a > b:
  print(b)
if b > a:
  print(a)

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cstring>
#define INT long long
#define MOD 1000000007
#define oo 99999999987654321ll
using namespace std;

INT n, w, a[110], b[110], dt[110][110][310];

INT dp(int x, int y, int z)
{
    if( y*a[0]+z > w ) return -oo;
    if( x == n ) return 0;
    if( ~dt[x][y][z] ) return dt[x][y][z];
    INT &ret = dt[x][y][z] = 0;
    return ret = max( dp(x+1, y+1, z+(a[x]-a[0]))+b[x], dp(x+1, y, z) );
}

int main()
{
    ios::sync_with_stdio(false);
    memset(dt, -1, sizeof(dt));
    cin>>n>>w;
    for(int i = 0 ; i < n ; i++ ) cin>>a[i]>>b[i];
    cout<<dp(0, 0, 0)<<endl;
    return 0;
}


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

int main(){
    int X,N,i,j,s,o;
    o=-1;
    s=100000;
    int error[110];
    cin>>X>>N;
    int num[110];
    for (i=0;i<110;i++){
        num[i]=0;
        error[i]=1000000;
    }
    for (i=0;i<N;i++){
        cin>>j;
        num[j]=1;
    }
    for (i=0;i<110;i++){
        if (num[i]==1){
            continue;
        }
        if (i>=X){
            error[i]=i-X;
        }
        else{
            error[i]=X-i;
        }
    }
    for (i=0;i<110;i++){
    }
    for(i=0;i<110;i++){
        if(error[i]<s){
            s = error[i];
            o = i;
        }
    }
    if (o==-1){
        o = X;
    }
    cout<<o<<endl;
}


Measured memory_bytes: 3608
N = int(input())
now = (0,0,0)
for i in range(N):
    bx,by,bt = now
    t,x,y = map(int,input().split())
    if abs(x-bx)+abs(y-by) <= t-bt and (abs(x-bx)+abs(y-by))%2 == (t-bt)%2:
        now = (x,y,t)
        continue
    else:
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 3060
import java.io.*
import java.util.*

fun solve(N: Long, S: Array<String>){
    val variety = S.toList().groupBy{ it }.size
    when(variety){
        3 -> "Three"
        else -> "Four"
    }.let{ println(it) }
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val S = StringArray(N.toInt())
    for (i in 0 until N.toInt()) {
        S[i] = sc.next()
    }
    solve(N, S)
}



Measured memory_bytes: 34032
import math
def resolve():
    K = int(input())
    temp = 0
    for i in range(1, K + 1, 1):
        for j in range(1, K + 1, 1):
            for k in range(1, K + 1, 1):
                Result = math.gcd(i, j)
                temp += math.gcd(Result, k)
    print(temp)


resolve()

Measured memory_bytes: 69684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
int main() {
    vector<vector<int>> a(3,vector<int>(3));
    int n;
    vector<int> b(n);
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> a[i][j];
        }
    }
    bool ok[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            ok[i][j]=false;
        }
    }
    cin >> n;
    for(int i=0;i<n;i++) cin >> b[i];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<n;k++){
                if(a[i][j]==b[k]) ok[i][j]=true;
            }
        }
    }
    bool ans=false;
    for(int i=0;i<3;i++){
        int cnt=0;
        for(int j=0;j<3;j++){
            if(ok[i][j]) cnt++;
        }
        if(cnt==3) ans=true;
    }
    for(int j=0;j<3;j++){
        int cnt=0;
        for(int i=0;i<3;i++){
            if(ok[i][j]) cnt++;
        }
        if(cnt==3) ans=true;
    }
    if(ok[0][0]==true&&ok[1][1]==true&&ok[2][2]==true) ans=true;
    if(ok[2][0]==true&&ok[1][1]==true&&ok[0][2]==true) ans=true;
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    map<int,int> mp;
    for(int i = 0; i < n; ++i){
        int a; cin >> a;
        mp[a]++;
    }
    int cnt = 0;
    vector<long long> a;
    for(auto it = mp.end(); ; --it){
        if(it == mp.end()) continue;
        if(it->second >= 2){ 
            if(cnt == 0 && it->second >= 4){
                cout << (long long)(it->first)*(it->first) << endl;
                return 0;
            }
            cnt++;
            a.push_back(it->first);
        }
        if(cnt == 2) break;
        if(it == mp.begin()) break;
    }
    if(cnt == 2) cout << a[0]*a[1] << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 8292
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s;
	cin>>s;
	for(int i=s.size()-3;i>0;i=i-2)
	{
		char a[i/2+1],b[i/2+1];
		for(int j=0;j<=i/2;j++)
		{
			a[j]=s[j];
		}
		int p=0;
		for(int j=i/2+1;j<=i;j++)
		{
			b[p]=s[j];
			p++;
		}
		bool ss=true;
		for(int j=0;j<=i/2;j++)
		{
			if(a[j]!=b[j])
			{
				ss=false;
				break;
			}
		}
		if(ss==true)
		{
			cout<<i+1;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int, input().split()))
ans = 1
ng = 0
if 0 in A:
  print("0")
else:
  for i in range(N):
    ans *= A[i]
#    print(i,ans)
    if ans > 1000000000000000000:
      print("-1")
      ng = 1
      break
  if ng==0:
    print(ans)


Measured memory_bytes: 21700