akhauriyash/Code-Regression huggingface dataset:
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

//x[0] ~ x[i]からj枚選んで合計をkにする通り数
LL dp[51][51][50 * 50 + 1];

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

    int n, a;
    cin >> n >> a;
    int x[n + 1];
    for( int i = 1; i <= n; ++i ) cin >> x[i];

    dp[0][0][0] = 1;
    for( int i = 1; i <= n; ++i ) {
        for( int j = 0; j <= n; ++j ) {
            for( int k = 0; k <= 2500; ++k ) {
                if( k >= x[i] && j > 0 ) {
                    dp[i][j][k] = dp[i - 1][j - 1][k - x[i]] + dp[i - 1][j][k];

                } else {
                    dp[i][j][k] = dp[i - 1][j][k];

                }
            }
        }
    }
    LL res = 0;
    for( int i = 1; i <= n; ++i ) {
        res += dp[n][i][i * a];

    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 50048
let n = Int(readLine()!)!

var tasks: [(cost: Int, deadline: Int)] = .init(repeating: (-1, -1), count: n)

for i in 0..<n {
  let inp = readLine()!.split(separator: " ").map { Int($0)! }
  tasks[i] = (inp[0], inp[1])
}

tasks = tasks.sorted { $0.deadline < $1.deadline }

var current = 0
var ans = true
for t in tasks {
  current += t.cost
  if current > t.deadline {
    ans = false
    break
  }
}
print(ans ? "Yes" : "No")

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

int main() {
  long long H, N;
  cin >> H >> N;
  vector<long long> A(N);
  long long A_sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> A.at(i);
    A_sum += A.at(i);
  }

  cout << (H <= A_sum ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
//#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<=(int)n;i++)
#define REP1(j,n) for(int j=0;j<=(int)n;j++)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
using namespace std;

int main(void) {
	int N;
	cin >> N;
	string ans = "";
	if (N == 0) { cout << "0" << endl; return 0; }
	while (N != 0) {
		if (N % 2 != 0) {
			N--;
			ans = "1" +ans;
		}
		else {
			ans = "0" + ans;
		}
		N /= -2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;

int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<int>> e(n+1,vector<int>(0));
    vector<int> a(n+1,0),d(n+1,0);
    rep(i,m){
        int f,g;
        cin >> f >> g;
        e.at(f).push_back(g);
        a.at(g)++;
    }
    queue<int> q;
    rep(i,n){
        if (a.at(i+1)==0) q.push(i+1);
    }
    while(!q.empty()){
        int f=q.front();
        q.pop();
        rep(i,e.at(f).size()){
            if (d.at(e.at(f).at(i))<d.at(f)+1) d.at(e.at(f).at(i))=d.at(f)+1;
            a.at(e.at(f).at(i))--;
            if (a.at(e.at(f).at(i))==0) q.push(e.at(f).at(i));
        }
    }
    int ans=0;
    rep(i,n) ans=max(ans,d.at(i+1));
    cout << ans << endl;
}

Measured memory_bytes: 6528
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    ll n;
    cin>>n;
    vector<ll> v(n);
    ll f=0;
    ll sum=0;
    rep(i,n){

        cin>>v[i];
        if(v[i]<0)f++;
        sum+=abs(v[i]);
        v[i]=abs(v[i]);
    }
    sort(v.begin(),v.end());

    if(f%2==0){
        cout<<sum<<endl;

    }else{
        sum-=v[0]*2;
        cout<<sum<<endl;

    }


    return 0;
}


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

int main(){
    map<string, int> M;
    string s,slongest,smost;
    cin >> s;
    slongest = s;
    smost = s;
    M[s]++;

    while (cin >> s){
        M[s]++;
        if (s.size() >= slongest.size())
            slongest = s;
        if (M[s] > M[smost])
            smost = s;
    }
    cout << smost << " " << slongest << endl;
}

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

int a, b, t, cnt;

int main() {
    scanf("%d %d %d", &a, &b, &t);
    while (1) {
        if (t - a < 0) break;
        cnt += b;
        t -= a;
    }
    printf("%d\n", cnt);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int jud(int);

int main(void) {
	int num, n, i, count = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &num);
		count += jud(num);
	}
	printf("%d\n", count);
	return 0;
}

int jud(int num) {
	int i;
	if (num == 2) {
		return 1;
	}
	if (num < 2 || num % 2 == 0) {
		return 0;
	}
	i = 3;
	while( i <=sqrt(num)) {
		if (num%i == 0) {
			return 0;
		}
		i = i + 2;
	}
	return 1;
}


Measured memory_bytes: 2048
#include<iostream>
#include<string>
using namespace std;
int h,w,ans;
string m[150];
void solve(int y,int x){
  char c = m[y][x];
  if(m[y][x] == '0') return;
  m[y][x] = '0';
  if(y+1 < h && m[y+1][x] == c) solve(y+1,x);
  if(x+1 < w && m[y][x+1] == c) solve(y,x+1);
  if(y-1 >= 0 && m[y-1][x] == c) solve(y-1,x);
  if(x-1 >= 0 && m[y][x-1] == c) solve(y,x-1);
}
int main(void){
  for(;;){
    cin >> h >> w;
    if(!h && !w) break;
    ans = 0;
    for(int i = 0;i < h; i++) cin >> m[i];
    for(int i = 0;i < h; i++){
      for(int j = 0; j < w; j++){
	if(m[i][j] != '0'){
	  solve(i,j);
	  ans++;
	}
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 2148
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
 
using namespace std;
 
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
 
typedef vector<int> vi;
typedef pair<int,int> pii;
 
int main(void) {
  int i,j,k;
  int n,ma,mb;
  cin>>n>>ma>>mb;
  int dp[45][405][405]; 
  rep(i,45)rep(j,405)rep(k,405)
    dp[i][j][k]=INF;
  dp[0][0][0]=0;
 
  rep(i,n){
    int a,b,c;
    cin>>a>>b>>c;
    rep(j,405)rep(k,405)
      if(dp[i][j][k]<INF){
        dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
        if(j+a<405 && k+b<405)
          dp[i+1][j+a][k+b]=min(dp[i+1][j+a][k+b],dp[i][j][k]+c);
     }
  }
 
  int ans=INF;
  for(i=1;i*max(ma,mb)<405;i++)
    ans=min(ans,dp[n][i*ma][i*mb]);
  if(ans<INF)
    cout<<ans<<endl;
  else
    cout<<-1<<endl;
}

Measured memory_bytes: 29056
N = int(input())
A = list(map(int, input().split()))
csum = list()
csum_set = dict()
ans = 0
csum.append(0)
for i in range(0, len(A)):
    if i == 0:
        csum.append(A[i])
    else:
        csum.append(csum[i] + A[i])

for x in csum:
    if str(x) not in csum_set:
        csum_set[str(x)] = 1
    else:
        csum_set[str(x)] += 1
    
for x in csum_set.values():
    ans += x * (x - 1) // 2

print(ans)


Measured memory_bytes: 52180
n = int(input())
preorder = list(map(int, input().split()))
inorder   = list(map(int, input().split()))

root_used = []

def find(c, branch):
    for i, x in enumerate(branch):
        if x==c:
            return i
    return None
    
i = 0
ans = []
    
def reconstruction(branch):
    global i
    
    if len(branch)==0:
        return
        
    if i>=len(preorder):
        return
    
    c = preorder[i]
    i += 1
    m = find(c, branch)
    
    if m is None:
        return 
    
    left_branch = branch[:m]
    right_branch = branch[m+1:]
    
    reconstruction(left_branch)
    reconstruction(right_branch)
    
    ans.append(c)
    
reconstruction(inorder)

print(*ans)


Measured memory_bytes: 5600
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std; using namespace placeholders;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector< int > VI;
typedef vector< vector< int > > VVI;
typedef vector< string > VS;
typedef stringstream SS;
typedef pair< int, int > PII;
typedef vector< pair< int, int > > VPII;
#define VT( T ) vector< T >
#define VVT( T ) vector< vector< T > >
#define LIM( T ) numeric_limits< T >

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; };
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &e : c )
#define ALL( c ) ( c ).begin(), ( c ).end()
#define AALL( a, t ) ( t* )a, ( t* )a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) ( c ).begin(), ( c ).begin() + p, ( c ).end()

#define SZ( v ) ( (int)( v ).size() )
#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define EXIST( c, e ) ( ( c ).find( e ) != ( c ).end() )

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

constexpr int MOD = 1000000007;

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

	for ( string A, B, C; cin >> A >> B >> C; )
	{
		const int L = SZ( A );

		VVI dp( L + 1, VI( 2 ) );
		dp[0][0] = 1;

		REP( i, L )
		{
			const int pos = L - 1 - i;

			REP( j, 2 )
			{
				REP( a, i + 1 == L ? 1 : 0, 10 )
				{
					REP( b, i + 1 == L ? 1 : 0, 10 )
					{
						if ( A[ pos ] != '?' && A[ pos ] != a + '0' ||
								B[ pos ] != '?' && B[ pos ] != b + '0' ||
								C[ pos ] != '?' && C[ pos ] != ( a + b + j ) % 10 + '0' )
						{
							continue;
						}

						const int nj = 10 <= a + b + j;
						( dp[ i + 1 ][ nj ] += dp[i][j] ) %= MOD;
					}
				}
			}
		}

		cout << dp[L][0] << endl;
	}

	return 0;
}

Measured memory_bytes: 1212
#include<stdio.h>
#include<algorithm>
using namespace std;
int c[7][7];
int v[10];
int pat[11][3][5]={
{{2,3,0,0,0},
{0,1,2,0,0},
{0,0,3,1,0}},
{{2,3,2,0,0},
{0,0,1,3,1},
{0,0,0,0,0}},
{{3,1,0,0,0},
{0,2,3,2,0},
{0,1,0,0,0}},
{{3,1,0,0,0},
{0,2,3,2,0},
{0,0,1,0,0}},
{{3,2,0,0,0},
{0,1,3,1,0},
{0,0,0,2,0}},
{{3,0,0,0,0},
{1,2,1,2,0},
{3,0,0,0,0}},
{{3,0,0,0,0},
{1,2,1,2,0},
{0,3,0,0,0}},
{{3,0,0,0,0},
{1,2,1,2,0},
{0,0,3,0,0}},
{{3,0,0,0,0},
{1,2,1,2,0},
{0,0,0,3,0}},
{{0,3,0,0,0},
{1,2,1,2,0},
{0,3,0,0,0}},
{{0,3,0,0,0},
{1,2,1,2,0},
{0,0,3,0,0}}
};
int to[10][10];
int tmp[10];
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		for(int i=0;i<5;i++)for(int j=0;j<5;j++)scanf("%d",&c[i][j]);
		bool dame=false;
		for(int i=0;i<10;i++)v[i]=0;
		for(int i=0;i<5;i++)for(int j=0;j<5;j++){
			if(c[i][j]){
				v[c[i][j]]++;
			}
		}
		for(int i=1;i<=6;i++)if(v[i]!=1)dame=true;
		if(dame){
			printf("false\n");
			continue;
		}
		bool ok=false;
		for(int s=0;s<2;s++){
		for(int r=0;r<4;r++){
		for(int i=0;i<11;i++){
			for(int j=0;j<4;j++){
				for(int p=0;p<2;p++){
				bool OK=true;
				for(int k=0;k<10;k++)tmp[k]=0;
				for(int k=0;k<3;k++){
					for(int l=0;l<5;l++){
						if(pat[i][k][l]){
							if(!c[j+k][p+l])OK=false;
							tmp[pat[i][k][l]]+=c[j+k][p+l];
						}
					}
				}
				for(int k=1;k<=3;k++)if(tmp[k]!=7)OK=false;
				if(OK)ok=true;
				}
			}
		}
		for(int i=0;i<5;i++)for(int j=0;j<5;j++)to[j][4-i]=c[i][j];
		for(int i=0;i<5;i++)for(int j=0;j<5;j++)c[i][j]=to[i][j];
		}
		for(int i=0;i<5;i++)for(int j=0;j<5;j++)to[i][4-j]=c[i][j];
		for(int i=0;i<5;i++)for(int j=0;j<5;j++)c[i][j]=to[i][j];
		}
		if(ok)printf("true\n");
		else printf("false\n");
	}
}

Measured memory_bytes: 1012
#include <cstdio>

long long a[1234];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", a + i);
  }
  long long k = 0;
  while (true) {
    int pos = -1;
    for (int i = 0; i < n; i++) {
      if (pos < 0 || a[i] > a[pos]) pos = i;
    }
    if (a[pos] < n) break;
    long long add = a[pos] / n;
    a[pos] %= n;
    for (int i = 0; i < n; i++) if (i != pos) a[i] += add;
    k += add;
  }
  printf("%lld\n", k);
}


Measured memory_bytes: 128
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def r_sort(a) a.sort{|a,b|b<=>a} end

n =gets.to_i
t = []
n.times do
  t.push(gets.to_i)
end
max2,max = t.sort()[-2,2]
t.each do |d|
  puts (d==max)? max2:max
end


Measured memory_bytes: 7900
#include <bits/stdc++.h>
#define endl '\n'
#define _ ios::sync_with_stdio(false);cin.tie(0);

using namespace std;

vector<int> ps;

int main() {_
    int n, k, p, o=0;
    cin >> n >> k;
    for(int i=0; i < n; i++){
        cin >> p;
        ps.push_back(p);
    }
    sort(ps.begin(), ps.end());
    for(int i=0; i < k; i++){
        o += ps[i];
    }
    cout << o << endl;

    return 0;
}


Measured memory_bytes: 3664
#include <stdio.h>

int main(void)
{
	int array[9][9];
	int i,j;
	
	for(i=0;i<9;i++){
		for(j=0;j<9;j++){
			array[i][j]=(i+1)*(j+1);
			printf("%dx%d=%d\n",i+1,j+1,array[i][j]);
		}
	}
	
	return 0;
}

Measured memory_bytes: 924
package main

import (
	"fmt"
	"sort"
)

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

func abs(s int) int {
	if s > 0 {
		return s
	}
	return -s
}

func main() {
	var n int
	fmt.Scan(&n)
	var ws []int
	for i := 0; i < n; i++ {
		var w int
		fmt.Scan(&w)
		ws = append(ws, w)
	}
	var results []int
	for i := 0; i < n; i++ {
		diff := abs(sum(ws[:i+1]) - sum(ws[i+1:]))
		results = append(results, diff)
	}
	sort.Ints(results)
	fmt.Println(results[0])
}


Measured memory_bytes: 512
/**OOO**/
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    ll n,h;
    cin>>n>>h;
    ll a[n+5],b[n+5];

    for(int i=0;i<n;i++)cin>>a[i]>>b[i];

    sort(a,a+n);
    sort(b,b+n);


    ll cnt=0;

    int flag=0;
    ll sum=0;
    int i=n-1;
    while(sum<h)
    { 
        if(b[i]<=a[n-1] || i<0){
            flag=1;
            break;
        }
        sum+=b[i--];
        cnt++;
    }

        i=n-1;
        if(flag==1){
            h-=sum;
            int quotient=h/a[i];
            if(h%a[i]==0)cout<<cnt+quotient<<endl;
            else{
                cout<<cnt+quotient+1<<endl;
            }
        }
        else{
            cout<<cnt<<endl;
        }

return 0;
}


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

#define Fast           ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO             freopen("in.txt", "r", stdin)
#define FC             freopen("out.txt", "w", stdout)
#define aise           cout<<"aise"<<endl
#define pb             push_back
#define pf             push_front
#define ppb            pop_back
#define ppf            pop_front
#define mp             make_pair
#define ll             long long
#define all(x)         x.begin(), x.end()
#define mset(v, a)     memset(v, a, sizeof(v))
#define pll            pair< ll, ll >
#define pd             pair< double, double >
#define ff             first
#define ss             second
#define pi             acos(-1.0)
#define mxN            2010
#define inf            1e14
#define mod            1000000007

//NCR iterative
/*voidcomb_table(intN)
{
    for(inti=0; i<=N; ++i)
    {
        for(intj=0; j<=i; ++j)
        {
            if(j==0or j==i)
            {
                C[i][j]=1LL;
            }
            else
            {
                C[i][j]=(C[i-1][j-1]+C[i-1][j]);
            }
        }
    }
}*/


//NCR recursive
/*ll dp[55][55];

ll NCR(ll n,ll r)
{

    if(n==r)
        return dp[n][r]=1;
    if(r==0)
        return dp[n][r]= 1;
    if(r==1)
        return dp[n][r]=n ;
    if(dp[n][r] != -1)
        return dp[n][r];
    return dp[n][r] = NCR(n-1,r)+NCR(n-1,r-1);
}*/

//Sieve:
/*bool Flag[1000010];
vector<ll> Prime;

void sieve()
{

    ll val=sqrt(1000010);
    for(ll i=4;i<=1000005; i+=2) Flag[i]=1;
    for(ll i=3;i <= val;i+=2)
    {

        if(Flag[i]==0)
        {

            for(ll j=i*i;j<=1000005;j+=i) Flag[j]=1;
        }
    }
    Flag[1]=1;
    for(ll i=1;i<=1000000;i++)
        if(Flag[i]==0) Prime.pb(i);
}*/


//Conversion
/*string bin(ll x)
{

    string ret;
    while(x)
    {

        ll t=x%2;
        char c;
        if(t==1)
            c='1';
        else
            c='0';
        ret.pb(c);
        x/=2;
    }
    reverse(all(ret));
    return ret;
}*/

/*ll lcm(ll x, ll y)
{

    ll ret=__gcd(x,y);
    return (x*y)/ret;
}*/

/*ll dx[]= {0,0,1,-1};
ll dy[]= {1,-1,0,0};*/

int main()
{

    string ss;
    cin >> ss;
    ll en, be;
    for(ll i=ss.size()-1;i>=0;i--)
    {

        if(ss[i]=='Z')
        {

            en=i;
            break;
        }
    }
    for(ll i=0;i<ss.size();i++)
    {

        if(ss[i]=='A')
        {

            be=i;
            break;
        }
    }
    cout << en-be+1;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int main(void){
	int n;
	int a[100];
	int b[100];
	scanf("%d",&n);
	
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	
	int j = 0;
	for(int i = n - 1; i >= 0; i--){
		b[j] = a[i];
		j++;
	}
	
	for(int i = 0; i < n - 1; i++){
		printf("%d ",b[i]);
	}
	
	printf("%d\n",b[n - 1]);
	
	
	return 0;
}


Measured memory_bytes: 2732
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	
	
		Scanner sc=new Scanner(System.in);
		String a=sc.nextLine();
		String b=sc.nextLine();
		String res= "";
		
		for(int i=0;i<a.length()+b.length();i++)
		{
			if(i%2==0)
			{
				res+=a.charAt(i/2);
			}
			
			else
			{
				res+=b.charAt((i-1)/2);
			}
		}
		
		System.out.println(res);
		 
			
		
	
		
		sc.close();

	}

}


Measured memory_bytes: 39244
#include<bits/stdc++.h>
#define int long long

using namespace std;

int group[100001], cnt;

int fnd(int x)
{
    if (group[x] == x)
        return x;
    else
        return group[x] = fnd(group[x]);
}

void uni(int x, int y)
{
    int a = fnd(x), b = fnd(y);
    if (a == b)
        return;
    else
        group[a] = b, cnt--;
}

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

    int n, m, a, b, c;
    cin >> n >> m;
    cnt = n;
    for (int i = 1; i <= n; i++)
        group[i] = i;
    while (m--)
        cin >> a >> b >> c, uni(a, b);
    cout << cnt << '\n';

    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N;
    cin>>N;
    vint A;
    rep(i,N){
        int a;cin>>a;
        if(A.size()==0||A.back()!=a)A.pb(a);
    }

    int ans=1;
    int cur=0;
    while(cur+1<A.size()){
        int nex=cur+1;
        while(nex+1<A.size()&&(A[nex+1]-A[nex])*(A[cur+1]-A[cur])>0)nex++;
        chmax(ans,nex-cur+1);
        cur=nex;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  string s;
  cin>>a>>b>>s;
  for(int i=0;i<s.size();i++){
    
    if(s[i]=='-' && i!=a){
      cout<<"No"<<endl;
      return 0;
    }
  }
  if(a+b+1==s.size() && s[a]=='-'){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
}


Measured memory_bytes: 256
#include<iostream>
#include <stdio.h>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <map>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){

int a,b,c;
cin >> a >> b >> c;
int B = b - a;
int C = c - a;
for(int i = 0; i < 2; i++){
cin >> a >> b >> c;
if(b - a != B || c - a != C) {cout << "No" << endl; return 0;}
 }

cout << "Yes" << endl;

return 0;
}

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

struct Card
{
        char suit;
        int num;

        Card () {}
        Card ( char suit, int num ) : suit(suit), num(num) {}

        bool operator < ( const Card &d ) const { return ( num < d.num ); }
        bool operator <= ( const Card &d ) const { return ( num <= d.num ); }
        bool operator == ( const Card &d ) const { return ( suit == d.suit && num == d.num ); }
        
        friend istream &operator >> (istream &is, Card &a)
        {
                return ( is >> a.suit >> a.num );
        }

        friend ostream &operator << (ostream &os, const Card &a)
        {
                return ( os << a.suit << " " << a.num );
        }

        static Card INF()
        {
                static const Card inf = Card(' ', (1 << 30) - 1);
                return ( inf );
        }
};

template < typename T >
int Partition(T *A, int p, int r)
{
        T x = A[r];
        int i = p;
        for ( int j = p; j < r; j++ ) {
                if ( A[j] <= x ) {
                        swap(A[i], A[j]);
                        i++;
                }
        }
        swap(A[i], A[r]);
        return ( i );
}

template < typename T >
void Quicksort(T *A, int p, int r)
{
        if ( p < r ) {
                int q = Partition(A, p, r);
                Quicksort(A, p, q - 1);
                Quicksort(A, q + 1, r);
        }
}

template < typename T >
void Merge(T *A, int l, int m, int r)
{
        int i, j, k;
        int n1 = m - l;
        int n2 = r - m; 
        
        auto L = make_unique < T[] > (n1 + 2);
        auto R = make_unique < T[] > (n2 + 2);

        for ( i = 0; i < n1; i++ ) L[i] = A[l + i];
        for ( i = 0; i < n2; i++ ) R[i] = A[m + i];

        L[n1] = T::INF(), L[n2] = T::INF();
        i = 0, j = 0;
        for ( k = l; k < r; k++ ) {
                if ( j >= n2 || L[i] <= R[j] ) A[k] = L[i++];
                else A[k] = R[j++];
        }
}

template < typename T >
void Mergesort(T *A, int l, int r) 
{
        if ( l + 1 < r ) {
                int m = (l + r) / 2;
                Mergesort(A, l, m);
                Mergesort(A, m, r);
                Merge(A, l, m, r);
        }
}

int main()
{
        int n;
        Card A[100005], B[100005];
        int idx;

        cin >> n;
        for ( int i = 0; i < n; i++ ) {
                cin >> A[i];
                B[i] = A[i];
        }
        
        Quicksort(A, 0, n - 1);
        Mergesort(B, 0, n);
        
        bool stable = true;
        for ( int i = 0; i < n; i++ ) {
                stable &= (A[i] == B[i]);
        }

        if ( stable ) cout << "Stable" << endl;
        else cout << "Not stable" << endl;

        for ( int i = 0; i < n; i++ ) {
                cout << A[i] << endl;
        }

        return ( 0 );
}



Measured memory_bytes: 5064
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;




public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7);
	static long cf = 998244353;
    static final int N = (int) 1e3+10;
    public static List<Integer>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static int[] Bit;
    public static long[] fact,inv;
    public  static int[] prime; 
	public static Map<Integer, Integer> map; 
	static char ch = 'z';
	static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		int ans = (n - s.replace("ABC","").length())/3;
		out.print(ans);
		out.close();
	}
	
}


Measured memory_bytes: 24532
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define ll long long
#define N 100005
#define mp map<int,int>
using namespace std;
int main() {
	char s[4];
	cin>>s;
	sort(s,s+4);
	if(s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2])
		cout<<"Yes";
	else cout<<"No";
	return 0;
}


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

int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    string halfS[2];
    halfS[0] = S.substr(0, N);
    halfS[1] = S.substr(N, N);
    reverse(halfS[1].begin(), halfS[1].end());
    unordered_map<string, long long> cnt[2];
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < (1 << N); j++){
            string tmp[2];
            tmp[0].reserve(N);
            tmp[1].reserve(N);
            for(int k = 0; k < N; k++){
                if( j & (1 << k)){
                    tmp[1].push_back(halfS[i][k]);
                }else{
                    tmp[0].push_back(halfS[i][k]);
                }
            }
            cnt[i][tmp[0] + "," + tmp[1]]++;
        }
    }
    long long ans = 0;
    for(unordered_map<string, long long>::iterator it = cnt[0].begin(); it != cnt[0].end(); it++){
        ans += cnt[0][it->first] * cnt[1][it->first];
    }
    cout << ans << endl;
}

Measured memory_bytes: 86132
#include <bits/stdc++.h>
using namespace std;
int main() {
    int H,W,X,Y;
    cin>>H>>W;
    X=H;
    Y=W;
    string a[H];
    for(int i=0;i<H;i++){
        cin>>a[i];
    }
    vector<vector<char>> b(100,vector<char>(100));
    for(int i=0;i<X;i++){
        for(int j=0;j<Y;j++){
            b.at(i).at(j)=a[i].at(j);
        }
    }

    for(int i=X-1;i>-1;i--){
        bool x=true;
        for(int j=Y-1;j>-1;j--){
            if(b.at(i).at(j)=='#'){
              x=false;  
            }      
        }
        if(x){
            for(int k=i;k<X-1;k++){
                for(int j=Y-1;j>-1;j--){
                    b.at(k).at(j)=b.at(k+1).at(j);
                    b.at(k+1).at(j)=' ';    
                }
            }
            X--;
        }
    }
    for(int i=Y-1;i>-1;i--){
        bool x=true;
        for(int j=X-1;j>-1;j--){
            if(b.at(j).at(i)=='#'){
               x=false;
            }     
        }
        if(x){
            for(int k=i;k<Y-1;k++){ 
                for(int j=X-1;j>-1;j--){
                    b.at(j).at(k)=b.at(j).at(k+1);
                    b.at(j).at(k+1)=' ';
                }
            }
            Y--;
        }
    }

    for(int i=0;i<X;i++){
        for(int j=0;j<Y;j++){
            cout<<b.at(i).at(j);
            if(j==Y-1)
              cout<<endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int n,m;
vector<ll> s,t;
ll dp[2010][2010];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    s.resize(n); t.resize(m);
    rep(i,0,n) cin>>s[i];
    rep(i,0,m) cin>>t[i];
    rep(i,0,n+1){
        unordered_map<ll, ll> M;
        rep(j,0,m+1){
            if(i==0||j==0) dp[i][j]=0;
            else{
                if(s[i-1]==t[j-1]){
                    dp[i][j]=dp[i-1][j]+dp[i-1][j-1]+M[s[i-1]]+1;
                    dp[i][j]%=MOD;
                    M[s[i-1]]+=dp[i-1][j-1]+1;
                    M[s[i-1]]%=MOD;
                }
                else{
                    dp[i][j]=(dp[i-1][j]+M[s[i-1]])%MOD;
                }
            }
        }
    }
    cout <<dp[n][m]+1<<"\n";
}

Measured memory_bytes: 31744
#include<iostream>
using namespace std;
int main(){
	int a,b,c,t;
    cin >> a >> b >> c;
    if(a<b){
    	t=a;
      	a=b;
    	b=t;  
    }
    if(a<c){
    	t=a;
      	a=c;
      	c=t;
    }
  	if(a==7 && b==5 && c==5){
      	cout << "YES\n";
    }
  	else{
      	cout << "NO\n";
    }
	return 0;
}	

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int[] ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int a = ab[0];
        int b = ab[1];

        Console.WriteLine(Math.Max(0, a - b * 2));
    }

}


Measured memory_bytes: 11348
n,x,m=map(int,input().split())
if n<=m+1:
    s=0
    a=x
    for c in range(n):
        s+=a
        a=pow(a,2,m)
else:
    l=[0]*m
    a=x
    l[a]=1
    for c in range(2,m+2):
        a=pow(a,2,m)
        if l[a]>0:
            d1=l[a]
            d2=c
            d3=a
            break
        l[a]=c
    q=(n-d1)//(d2-d1)
    r=(n-d1)%(d2-d1)+d1
    s=0
    for c in range(d2-d1):
        s+=a
        a=pow(a,2,m)
    s*=q
    for c in range(r):
        s+=x
        x=pow(x,2,m)
print(s)

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100],b[100],tr[100],ra[100];
int lowbit(int x){
	return x&-x;
}
void add(int pos,int c,int n){
	while(pos<=n){
		tr[pos]+=c;
		pos+=lowbit(pos);
	}
}
int getsum(int n){
	int ret=0;
	while(n){
		ret+=tr[n];
		n-=lowbit(n);
	}
	return ret;
}
int kt(int a[],int n){
	int ret=0;
	for(int i=n;i>=1;i--){
		ret+=ra[n-i]*getsum(a[i]-1);
		add(a[i],1,n);
	}
	return ret;
} 
void init(int n){
	ra[0]=1;
	for(int i=1;i<=n;i++) ra[i]=i*ra[i-1];
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) cin>>b[i];
	init(30);
	int num1=kt(a,n);
	memset(tr,0,sizeof tr);
	int num2=kt(b,n);
	cout<<abs(num1-num2)<<'\n';
	return 0;
 } 

Measured memory_bytes: 3592
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

int main()
{
  int n, m;
  cin >> n >> m;
  cout << (n + m) * (n + m - 1) / 2 - n * m << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

unsigned long long int GCD(unsigned long long int A,unsigned long long int B){
	if(A == 0) return B;
	return GCD(B%A,A);
}

int main()
{
	unsigned long long int A,B;
	cin>>A>>B;
	cout<<A*B/GCD(A,B)<<endl;
	return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 15 16:57:18 2018
ABC085C
@author: maezawa
"""
n, y = list(map(int, input().split()))
y = y // 1000
yn = y - n
is_ok = False
for i in range(n+1):
    if (yn - 9*i) % 4 == 0:
        a0, a1 = i, (yn - 9*i) // 4
        if a1 >= 0 and n - a0 - a1 >= 0:
            is_ok = True
            break
if is_ok:
    print(a0, a1, n - a0 - a1)
else:
    print(-1, -1, -1)
    

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC099_A solver = new ABC099_A();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC099_A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            if (in.nextInt() <= 999) {
                out.print("ABC");
            } else {
                out.print("ABD");
            }
        }

    }
}



Measured memory_bytes: 23252
#include <stdio.h>

int main(void)
{
	int n, m, l, i, j, k, x, A[100][100], B[100][100];
	double C[100][100];
	
	for(j = 0; j < 100; j++){
		for(k = 0; k < 100; k++){
			C[j][k] = 0;
		}
	}
	
	scanf("%d%d%d%*c", &n, &m, &l);
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			scanf("%d", &x);
			A[i][j] = x;
		}
	}
	for(j = 0; j < m; j++){
		for(k = 0; k < l; k++){
			scanf("%d", &x);
			B[j][k] = x;
		}
	}
	
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			for(k = 0; k < l; k++){
				C[i][k] += (A[i][j] * B[j][k]);
			}
		}
		for(k = 0; k < l; k++){
			if(k != 0) printf(" ");
			printf("%.0lf", C[i][k]);
		}
		printf("\n");
	}
	
	return(0);
}



Measured memory_bytes: 1952
import java.io.*;
import java.util.*;
public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int[] a = new int[10];
		
		String s;
		for(int i=0;i<10;i++)
				a[i] = Integer.parseInt(br.readLine());

		Arrays.sort(a);
		
		System.out.println(a[9]);
		System.out.println(a[8]);
		System.out.println(a[7]);
		
	}
}

Measured memory_bytes: 24188
#include<bits/stdc++.h>
#define REP(i, n) for (int i=0; i<n; ++i)
#define print(x) cout << x << endl;
typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;
    vector<vector<int> > A(2, vector<int>(N));

    REP(i, 2) {
        REP(j, N) {
            cin >> A[i][j];
        }
    }

    A[1][0] += A[0][0];
    for (int i = 1; i < N; i++) {
        A[0][i] += A[0][i-1];
        A[1][i] += max(A[0][i], A[1][i-1]);
    }
    print(A[1][N-1]);

}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;

const int SIZE = 50;

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

	vector<ll> a(SIZE, k / SIZE + SIZE - k%SIZE-1);
	for (int i = 0; i < k %SIZE;i++) {
		a[i] += k % SIZE - i + 1;
	}
	cout << SIZE << endl;
	for (int i = 0; i < SIZE;i++) {
		cout << a[i] << " ";
	}
	

	
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main(void) {
    
    
    string s;
    cin>>s;
    rep(i,s.size())cout<<'x';
    cout<<endl;
}


Measured memory_bytes: 256
package main

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

func solve() {
	s := getRunes()

	ans := 0
	for i := 0; i < len(s)/2; i++ {
		r1 := s[i]
		r2 := s[len(s)-i-1]
		if r1 != r2 {
			ans++
		}
	}

	fmt.Fprintln(wr, ans)
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


Measured memory_bytes: 640
loop do
    n = gets.to_i
    break if n == 0
    s = (1..n).map { gets }.join
    k = gets.chomp
    a = s.scan(/\b#{k}\w*/)
    if a.empty?
        puts 'NA'
    else
        h = Hash.new(0)
        a.each {|w| h[w] += 1}
        puts h.sort_by {|w, c| [-c, w]}.map(&:first)[0..4] * ' '
    end
end


Measured memory_bytes: 7916
//BISMILLAH
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,sum=0,humty=0;
    cin>>n>>m;
    vector<int> v(m);
    for(int i=0;i<v.size();i++)
    {

        cin>>v[i];
        sum+=v[i];
    }

    if(sum>n)
        cout<< "-1"<<endl;
    else
        cout<<n-sum<<endl;



}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  bool ok = false;
  rep(i,k+1){
    int nc=c*pow(2,i);
    int nb=b*pow(2,k-i);
    if(nc>nb && nb >a)ok=true;
  }
  if(ok)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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


int k;
int t;

priority_queue<pair<int,int> > q;

int main(){
	cin >> k >> t;
	for (int i = 0; i < t; i++){
		int a;
		scanf("%d", &a);
		q.push(make_pair(a,i) );
	}
	int ans = 0;
	int pr = -1;
	while (!q.empty()){
		pair<int, int> f1 = q.top();
		q.pop();
		if (f1.second != pr){
			f1.first--;
			pr = f1.second;
			if (f1.first){
				q.push(f1);
			}
			continue;
		}
		else{
			if (q.size()){
				pair<int, int> f2 = q.top();
				q.pop();
				f2.first--;
				pr = f2.second;
				if (f2.first){
					q.push(f2);
				}
				q.push(f1);
			}
			else{
				ans++;
				f1.first--;
				if (f1.first){
					q.push(f1);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val h, w = sc.nextInt
    val n = sc.nextInt
    val as = Vector.fill(n)(sc.nextInt)

    val rows = split(go(1, as, Vector[Vector[Int]]()).flatten, w)
    val ans = reverseOdd(rows)

    ans.foreach{ a =>
      a.foreach { b =>
        printf("%s ", b)
      }
      println()
    }

  }

  @tailrec
  def go(i: Int, seq: Seq[Int], result: Seq[Seq[Int]]): Seq[Seq[Int]] = {
    if (seq.length == 0) result
    else go(i+1, seq.tail, result :+ Seq.fill(seq.head)(i))
  }

  def split(seq: Seq[Int], n: Int): Seq[Seq[Int]] = {
    def go(s: Seq[Int], result: Seq[Seq[Int]]): Seq[Seq[Int]] = {
      if (s.length == 0) result
      else go(s.drop(n), result :+ s.dropRight(s.length - n))
    }
    go(seq, Seq[Seq[Int]]())
  }

  def reverseOdd(seq: Seq[Seq[Int]]): Seq[Seq[Int]] = {
    def go(i: Int, s: Seq[Seq[Int]], result: Seq[Seq[Int]]): Seq[Seq[Int]] = {
      if (s.length == 0) result
      else if (i % 2 == 0) go(i+1, s.tail, result :+ s.head)
      else go(i+1, s.tail, result :+ s.head.reverse)
    }
    go(0, seq, Seq[Seq[Int]]())
  }
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll a[200000];
int main(){
	int n,m;cin>>n>>m;
	ll L=-1;
	rep(i,n){
		scanf("%lld",&a[i]);
		a[i]/=2;
		if(i==0)L=a[i];
		else L=L/__gcd(L,a[i])*a[i];
		if(L>m){
			puts("0");return 0;
		}
	}
	rep(i,n){
		if((L/a[i])%2==0){
			puts("0");return 0;
		}
	}
	cout<<(m-L)/(2*L)+1<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int count=0;
  string s;
  cin>>s;
  n=s.length();
  vector<char> c(n);
  for(int i=0;i<n;i++){
    c[i]=s.at(i);
    if(c[i]=='0'){
      count++;
    }
  }
  cout<<2*min(count,n-count);
}
  

Measured memory_bytes: 512
class Tree
  attr_accessor :id,:parent,:children
  def initialize(id)
    @id=id
    @parent=-1
    @children=[nil,nil]
  end
  def preorder
    print " #{id}"
    children[0].preorder if children[0]
    children[1].preorder if children[1]
  end
  def inorder
    children[0].inorder if children[0]
    print " #{id}"
    children[1].inorder if children[1]
  end
end
def insert(id)
  z=Tree.new(id)
  y=nil
  x=$root
  while x
    y=x
    x= z.id < x.id ? x.children[0] : x.children[1]
  end
  unless y
    $root=z
  else
    z.id < y.id ?  y.children[0]=z : y.children[1]=z
  end
end
N=gets.to_i
N.times do
  cmd,id=gets.split
  case cmd
  when "insert" 
    insert(id.to_i)
  else
    $root.inorder
    puts ""
    $root.preorder
    puts ""
  end
end

Measured memory_bytes: 80212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807

//二項係数mod
    const int MAX = 510000;
    const int MOD = 1000000007;
    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;
    }


int main()
{
ll n;
cin >> n;
ll t[n+1] = {};
ll tt[n+1] = {};
ll r,y;
rep(i, n+1)
{
    cin >> t[i];
    if(tt[t[i]]!=0){
        r=tt[t[i]]-1;
        y=i;
        break;
    }
    tt[t[i]]=i+1;
}

//cout << r<<" "<<y << endl;
COMinit();
rep1(i,n+2){
    ll ans;
    ans=COM(n+1,i);
    ans+=mo;
    ans-=COM(r+n-y,i-1);
    ans%=mo;
    cout << ans << endl;
}
return 0;
}

Measured memory_bytes: 14720
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define repf(i, n) for(int i=1; i<(int)(n+1); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    int in, sum=0;
    rep(i, 3){
        cin >> in;
        sum += in;
    }
    if(sum <= 21) cout << "win" << endl;
    else cout << "bust" << endl;
}

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000001)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  int N,x;
  cin >> N >> x;
  if(x==1 || x==2*N-1){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  if(x<=N){
    reps(i,x+N,2*N)cout << i << endl;
    reps(i,1,x+N)cout << i << endl;
  }else{
    reps(i,x-N+1,2*N)cout << i << endl;
    reps(i,1,x-N+1)cout << i << endl;
  }
}

Measured memory_bytes: 1536