akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
using std::max;
const int MAXN=200005;
int n,i,a[MAXN],f[MAXN][3];
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
    	if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
inline void print(int x)
{
    if (x<0)
        putchar('-'),x=-x;
    if (x>9)
        print(x/10);
    putchar(x%10+'0');
}
signed main(void)
{
	read(n);
	for (i=1;i<=n;i++)
		read(a[i]);
	if (!(n%2))
	{
		f[1][0]=a[1];
		for (i=2;i<=n;i++)
			if (i%2)
				f[i][0]=f[i-2][0]+a[i];
			else
			{
				if (i>=3)
					f[i][1]=max(f[i-2][1],f[i-3][0])+a[i];
				else
					f[i][1]=f[i-2][1]+a[i];
			}
		return print(max(f[n-1][0],f[n][1])),0;
	}
	f[1][0]=a[1];
	for (i=2;i<=n;i++)
		if (i%2)
		{
			f[i][0]=f[i-2][0]+a[i];
			if (i>=4)
				f[i][2]=max(f[i-2][2],max(f[i-3][1],f[i-4][0]))+a[i];
			else
			{
				if (i>=3)
					f[i][2]=max(f[i-2][2],f[i-3][1])+a[i];
				else
					f[i][2]=f[i-2][2]+a[i];
			}
		}
		else
		{
			if (i>=3)
				f[i][1]=max(f[i-2][1],f[i-3][0])+a[i]; 
			else
				f[i][1]=f[i-2][1]+a[i];
		}
	print(max(f[n][2],max(f[n-1][1],f[n-2][0])));
	return 0;
}

Measured memory_bytes: 9880
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    VI imos(N+2,0);
    REP(i,M){
        int l,r; cin >> l >> r;
        l--; r--;
        imos[l]++;
        imos[r+1]--;
    }
    VI gate(N+2,0);
    int pre = 0;
    REP(i,N){
        gate[i] = pre + imos[i];
        pre = gate[i];
    }
    int ans = 0;
    REP(i,N){
        if(gate[i] == M) ans++;
    }
    cout << ans << endl;

}

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

typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++) // no semicoron
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>0;i--)
#define FORD(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく

using namespace std;

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

    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> C(N);

    REP(i, N) cin >> A[i];
    sort(ALL(A));
    REP(i, N) cin >> B[i];
    sort(ALL(B));
    REP(i, N) cin >> C[i];
    sort(ALL(C));

    ll count = 0;

    //vector<int>::iterator position;

    FOR(i, 0, N){
        //ll lower;
        //auto position;
        auto position1 = lower_bound(A.begin(), A.end(), B[i]);
        auto position2 = upper_bound(C.begin(), C.end(), B[i]);

        ll lower = distance(A.begin(), position1);
        ll upper = distance(position2, C.end());

        count += (lower ) * (upper );

    }

    cout << count << endl;




}

Measured memory_bytes: 2688
package main

import "fmt"

var e [][]int
var n, m int

func printEdge(e [][]int) {
	for i := 1; i < n+1; i++ {
		fmt.Printf("%d: ", i)
		for _, v := range e[i] {
			fmt.Printf("%d ", v)
		}
		fmt.Println()
	}
}

func dfs(v int, visited []bool) int {
	// visited[v] = true
	// fmt.Println(v, visited)

	comp := true
	for i := 1; i < n+1; i++ {
		if !visited[i] {
			comp = false
		}
	}

	if comp {
		return 1
	}

	count := 0
	for _, ne := range e[v] {
		// fmt.Printf("ne=%d\n", ne)
		if visited[ne] {
			continue
		}
		visited[ne] = true
		// if cmp, _ := dfs(ne, visited, count); cmp {
		// 	count++
		// }
		rst := dfs(ne, visited)
		// fmt.Println(rst)
		// count += dfs(ne, visited)
		count += rst
		visited[ne] = false
	}
	return count
}

func main() {
	fmt.Scan(&n, &m)

	e = make([][]int, n+1)
	for i := 1; i < n+1; i++ {
		e[i] = make([]int, 0)
	}
	for i := 0; i < m; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		e[a] = append(e[a], b)
		e[b] = append(e[b], a)
	}
	// printEdge(e)

	visited := make([]bool, n+1)
	visited[1] = true
	count := dfs(1, visited)
	fmt.Println(count)
}


Measured memory_bytes: 512
import math
def length(list1,list2):
    sum = math.sqrt((list1[0] - list2[0])**2 + (list1[1] - list2[1])**2)
    return(sum)


num = int(input())
data = ['' for i in range(num)]
for i in range(num):
    input_data = input().split(' ')
    int_data = [int(input_data[l]) for l in range(2)]
    data[i] = int_data

result = 0
for i in range(num):
    for l in range(num - i - 1):
        result += length(data[i],data[l + 1 + i])

result = result * 2 / num
print(result)


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;

const long XMAX = (long) 1e9 +7;

void devisor(long n, vector<long>& x ){
    long rn = (long) sqrt(n);
    for(long i=2; i<=rn; i++){
        if( n%i==0 ){
            x.push_back(i);
        }
    }

    return;
}

int main(){
    long X;
    cin >> X;

    long ans;
    for(long i=X; i<=XMAX; i++){
        vector <long> a;
        devisor(i,a);

        //cout << "i a.size() " << i << " " << a.size() << endl;

        if(a.size()==0){
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (B <= C || D <= A)
		cout << 0;
	else if (A >= C)
	{
		if (B >= D)
			cout << D - A;
		else if (B < D)
			cout << B - A;
	}
	else if (A < C)
	{
		if (B >= D)
			cout << D - C;
		else if (B < D)
			cout << B - C;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int total = 0;
	// int max = 0;
	int n;
	cin >> n;
	int a, b;
	for (int i = 0; i < n; ++i) {
		cin >> a >> b;
		total += b - a +1;

		// if ()
	}

	cout << total << endl;
}



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

int main() {
    int N, D, X;
    cin >> N >> D >> X;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    
    rep(i, N) {
        X += (D - 1) / A[i] + 1;
    }
    cout << X << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

using ull = unsigned long long;

ull dpL[2002][32]; // dp[i][*]
ull dpR[2002][32]; // dp[*][j]
ull A[2002][32];

void set(ull *a, int k) {
  a[k >> 6] |= 1ULL << (k & 0x3f);
}

bool test(ull *a, int k) {
  return a[k >> 6] >> (k & 0x3f) & 1;
}

bool exists(ull *a, int l, int r) {
  while (l < r) {
    if (l % 64 == 0 && l + 64 <= r) {
      if (a[l / 64]) return true;
      l += 64;
    } else {
      if (test(a, l++)) return true;
    }
  }
  return false;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i = 2; i <= N; i++) {
    string s;
    cin >> s;
    for (int j = 1; j <= i - 1; j++) {
      if (s[j-1] == '1') {
        set(A[i], j);
      } else {
        set(A[j], i);
      }
    }
  }
  for (int i = 0; i+1 <= N+1; i++) {
    set(dpL[i], i + 1);
    set(dpR[i + 1], i);
  }
  for (int d = 2; d <= N; d++) {
    for (int i = 0; i + d <= N+1; i++) {
      int j = i + d;
      ull tmp[32] = {};
      for (int k = 0; k < 32; k++) {
        tmp[k] = A[i][k] | A[j][k];
      }
      for (int k = 0; k < 32; k++) {
        tmp[k] &= dpL[i][k] & dpR[j][k];
      }
      // i < k < j
      if (exists(tmp, i + 1, j)) {
        set(dpL[i], j);
        set(dpR[j], i);
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (test(dpL[0], i) && test(dpL[i], N+1)) {
      ans++;
    }
  }
  cout << ans << '\n';
}


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

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

    vector<int> a(n+10);
    ll ans = 0;
    cin >> a[0];
    if(a[0] > x) ans += a[0] - x,a[0] = x;
    for(int i = 1; i < n; i++){
        cin >> a[i];
        if(a[i-1] + a[i] > x){
            ans += a[i-1] + a[i] - x;
            a[i] -= a[i-1] + a[i] - x;
        }
    }

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

Measured memory_bytes: 640
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int H = sc.nextInt();
    int W = sc.nextInt();
    String[][] C = new String[H][W];

    for (int i = 0; i < H; i++) {
      String C_ = sc.next();
      C[i] = C_.split("");
    }

    sc.close();

    int i = 0;
    int j = 0;
    while (i < H) {
      for (int k = 0; k < W; k++) {
        System.out.print(C[i][k]);
      }
      if (j % 2 == 0) {
        j++;
      } else {
        j = 0;
        i++;
      }
      System.out.println("");
    }

  }

}

Measured memory_bytes: 27452
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;

class Pos {
public:
    int r, c;
    Pos() {}
    Pos( int r_, int c_ )
    {
        r = r_, c = c_;
    }
    bool operator == ( const Pos& right ) const
    {
        return r == right.r && c == right.c;
    }
    bool operator < ( const Pos& right ) const
    {
        return r == right.r ? c < right.c : r < right.r;
    }
};

class Node {
public:
    int c, a;
    Pos p;
    bool operator < ( const Node& right ) const
    {
        return c < right.c;
    }
    bool operator > ( const Node& right ) const
    {
        return c > right.c;
    }
    Node(){}
    Node( int c_, int a_, Pos p_ ) { c = c_, a = a_, p = p_; }
};

// globals
const int inf = 1<<24;
const int size = 31;
int w, h;
int s[size][size];
int c[4];

typedef priority_queue <Node, vector <Node>, greater <Node> > QUEUE;
int mc[4][size][size];

// a % b
int getrem( int a, int b )
{
    return a < 0 ? (b-(-a%b)) : a % b;
}

bool isValid( Pos p )
{
    return p.r >= 0 && p.r < h && p.c >= 0 && p.c < w;
}

int solve()
{
    QUEUE Q;
    Node start( 0, 0, Pos(0,0) );
    Q.push( start );
    Pos goal( h-1, w-1 );

    while ( !Q.empty() ) {
        Node node = Q.top();
        Q.pop();

        int cost = node.c;
        int a = node.a;
        Pos p = node.p;

        if ( p == goal ) {
            return cost;
        }

        for ( int i = 0; i < 4; i++ ) {
            int next_cost = cost;
            if ( i != s[p.r][p.c] ) {
                next_cost += c[i];
            }

            int next_a = a;
            if ( i == 1 ) {
                next_a = getrem( a+1, 4 );
            } else if ( i == 2 ) {
                next_a = getrem( a+2, 4 );
            } else if ( i == 3 ) {
                next_a = getrem( a-1, 4 );
            }

            Pos next_p = p;
            if ( next_a == 0 ) {
                next_p.c++;
            } else if ( next_a == 1 ) {
                next_p.r++;
            } else if ( next_a == 2 ) {
                next_p.c--;
            } else if ( next_a == 3 ) {
                next_p.r--;
            }
            if ( !isValid( next_p ) ) continue;

            if ( next_cost >= mc[next_a][next_p.r][next_p.c] ) continue;
            mc[next_a][next_p.r][next_p.c] = next_cost;
            Node next_node( next_cost, next_a, next_p );
            Q.push( next_node );
        }
    }

    return -1;
}

int main()
{
    while ( cin >> w >> h && w && h ) {
        // init
        for ( int k = 0; k < 4; k++ ) {
            for( int i = 0; i < size; i++ ) {
                for ( int j = 0; j < size; j++ ) {
                    mc[k][i][j] = inf;
                }
            }
        }

        // input
        for ( int i = 0; i < h; i++ ) {
            for ( int j = 0; j < w; j++ ) {
                cin >> s[i][j];
            }
        }
        for ( int i = 0; i < 4; i++ ) {
            cin >> c[i];
        }

        // proc
        cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
while True:
   try:
      j = input()
      p=0
      q=0
      for i in range(len(j)-2):
         if j[i:i+3] == 'JOI':
            p += 1
         elif j[i:i+3] == 'IOI':
            q += 1
         else:
            pass
      print(p)
      print(q)
   except EOFError:
      break


Measured memory_bytes: 5568
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

#include <bits/stdc++.h>
using namespace std;

signed main(){
    string N; cin>>N;
    int ans = 0;
    REP(i,N.size()) if(N[i]=='2') ans ++;
    Out(ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include <cmath>
//#include <bits/stdc++.h>
using namespace std;

int main(){
    string S;
    cin>>S;
    if (S[2]==S[3]&&S[4]==S[5]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	vector<string>words(26);
	iota(words.begin(), words.end(), 'a');
	vector<string>twowords{ "ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw",  "ts" };
	words.insert(words.end(), twowords.begin(), twowords.end());
	vector<vector<string>>stset;
	vector<vector<int>>anss(38, vector<int>(38));
	{
		int N; cin >> N;

		string st;
		while (cin >> st) {
			int i = 0;
			vector<string>sts;
			while (i+2<=st.size()) {
				auto it = find(words.begin(), words.end(), st.substr(i, 2));
				if (it != words.end()) {
					sts.push_back(*it);
					i += 2;
				}
				else {
					sts.push_back(st.substr(i, 1));
					i++;
				}
			}
			if (i + 1 == st.size())sts.push_back(st.substr(i, 1));
			
			for (int i = 0; i < int(sts.size()) - 1; ++i) {
				string a = sts[i], b = sts[i + 1];
				auto at = find(words.begin(), words.end(), a);
				auto bt = find(words.begin(), words.end(), b);
				anss[at - words.begin()][bt - words.begin()]++;
			}
		}
	}
	for (int i = 0; i < 38; ++i) {
		pair<int, int>p = make_pair(-1, -1);
		for (int j = 0; j < 38; ++j) {
			auto q = make_pair(anss[i][j], 37-j);
			p = max(p, q);
		}
		cout << words[i] << ' ' << words[37-p.second] << ' ' << p.first << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3040
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int N,c[20];

int f(int *c,int l){
	if(!l)return 0;
	int res=l;
	//cout<<l<<": ";rep(i,20)cout<<c[i]<<(i<19?" ":"\n");
	rep(i,l){
		//cout<<"i"<<i<<" ";
		if(c[i]==-1)break;
		if(i%4<3&&c[i]==c[i+1]){
			if(l==2)return 0;
			int d[20];
			rep(j,20)d[j]=c[j];
			for(int j=i;j<l-2;j++)d[j]=d[j+2];
			d[l-2]=-1;d[l-1]=-1;
			res=min(res,f(d,l-2));
		}
		if(i/4<4&&c[i]==c[i+4]){
			if(l==2)return 0;
			int d[20];
			rep(j,20)d[j]=c[j];
			for(int j=i;j<=i+2;j++)d[j]=d[j+1];
			for(int j=i+3;j<l-2;j++)d[j]=d[j+2];
			d[l-2]=-1;d[l-1]=-1;
			res=min(res,f(d,l-2));
		}
		if(i%4<3&&i/4<4&&c[i]==c[i+5]){
			if(l==2)return 0;
			int d[20];
			rep(j,20)d[j]=c[j];
			for(int j=i;j<=i+3;j++)d[j]=d[j+1];
			for(int j=i+4;j<l-2;j++)d[j]=d[j+2];
			d[l-2]=-1;d[l-1]=-1;
			res=min(res,f(d,l-2));
		}
		if(i%4>0&&i/4<4&&c[i]==c[i+3]){
			if(l==2)return 0;
			int d[20];
			rep(j,20)d[j]=c[j];
			for(int j=i;j<=i+1;j++)d[j]=d[j+1];
			for(int j=i+2;j<l-2;j++)d[j]=d[j+2];
			d[l-2]=-1;d[l-1]=-1;
			res=min(res,f(d,l-2));
		}
		//if(!res)return 0;
	}
	//cout<<l<<"return "<<res<<endl;
	return res;
}

int main(){
	cin>>N;
	while(N--){
		rep(i,20)cin>>c[i];
		cout<<f(c,20)<<endl;
	}
}

Measured memory_bytes: 864
#include <bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;

int main(){
  int n,x,y;
  cin>>n>>x>>y;
  Graph g(n);
  for(int i=0;i<n-1;i++){
    g[i].push_back(i+1);
    g[i+1].push_back(i);
  }
  g[x-1].push_back(y-1);
  g[y-1].push_back(x-1);
  
  vector<int> ans(n,0);
  
  for(int i=0;i<n;i++){
  
  	vector<int> d(n,-1);
 	 queue<int> q;
  
 	 d[i]=0;
 	 q.push(i);
  
 	 while(!q.empty()){
  	  int v=q.front(); q.pop();
     
  	  for(int &nv: g[v]){
    	  if(d[nv]!=-1) continue;
       
    	  d[nv]=d[v]+1;
   	      ans[d[nv]-1]++;
    	  q.push(nv);
      }
     }
  }
  for(int i=0;i<n-1;i++) cout<<ans[i]/2<<endl;
}
  

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	ll N; cin >> N;
	ll A;
	ll cntMax = 1 << 21;
	rep(i, 0, N) {
		cin >> A;
		ll cnt = 0;
		while (A != 0)
		{
			if (A % 2 != 0) {
				break;
			}
			A /= 2;
			cnt++;
		}
		cntMax = min(cntMax, cnt);
	}
	cout << cntMax << endl;

	return 0;
}

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

int main() {
 
	int n;
	string s;
	int    start_pos;
	int    pos;
	int    len;
	
	cin >> n;
	cin >> s;
	
	len = s.length();
	if (len % 2 != 0) {
		cout << "No" << endl;
		exit(0);
	}
	bool flg = true;
	for (int i = 0; i < len / 2; i++) {
		if (s[i] == s[len / 2 + i]) {
			;
		} else {
			cout << "No" << endl;
                        exit(0);
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
import sys
import numpy as np
def input(): return sys.stdin.readline().rstrip()

def main():
    A=int(input())
    B=int(input())
    C=int(input())
    X=int(input())
    arr=np.add.outer(np.arange(0,100*B+1,100).T,np.arange(0,500*A+1,500))
    arr= X-arr
    print(arr[(arr>=0) & (arr<=50*C)].size)

if __name__ == '__main__':
    main()

Measured memory_bytes: 27268
from bisect import bisect
n = int(input())
a = [int(input()) for _ in range(n)]
update_list=[11 for _ in range(n+1)]
for old_element in range(n):
    update_position=bisect(update_list,-a[old_element])
    update_list[update_position]=-a[old_element]

ans=0
while update_list[ans] <= 0:
	ans += 1
print(ans)

Measured memory_bytes: 11036
#include <stdio.h>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)>(b)?(b):(a))

int main()
{
    int n;
    int a[n];
    int max;
    int min;
    int i, j;
    
    scanf("%d", &n);
    for(i=0;i<n;i++) scanf("%d", &a[i]);
    
    max = a[0];
    min = a[0];
    
    for(i=0;i<n;i++){
        max = max(max, a[i]);
        min = min(min, a[i]);
    }
    
    printf("%d", max-min);

    return 0;
}

Measured memory_bytes: 128
import fractions
n, k = map(int, input().split())
a = list(map(int, input().split()))

if max(a)<k:
    print("IMPOSSIBLE")
    exit()

g = a[0]
for i in range(1, n):
    g = fractions.gcd(g, a[i])

if k % g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 16240
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define F first 
#define S second 
#define pb push_back 

using namespace std;

void test(){
	ll n,d;
	cin>>n>>d;
	ll cnt = 0;
	d = d*d;
	f(i,n){
		ll x,y;
		cin>>x>>y;
		x = x*x, y = y*y;
		if((x+y)<=d)cnt++;
	}
	cout<<cnt<<"\n";
	
}

int main(){
	int tests=1;
	// cin>>tests;
	while(tests--){
		test();
	}
}


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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int solve(int n, int m, const vector<int>& l, const vector<int>& r, const vector<int>& d) {
	vector<vector<pair<int, int>>> g(n);
	for (int i = 0; i < m; i++) {
		g[l[i]].emplace_back(r[i], d[i]);
		g[r[i]].emplace_back(l[i], -d[i]);
	}


	vector<int> dist(n);
	vector<bool> used(n);
	for (int i = 0; i < n; i++) {
		if (used[i]) {
			continue;
		}

		queue<int> que;
		que.emplace(i);
		dist[i] = 0;
		used[i] = true;
		while (!que.empty()) {
			int now = que.front(); que.pop();
			for (auto e : g[now]) {
				int next = e.first;
				int cost = e.second;

				if (used[next] && dist[now] + cost != dist[next]) {
					return false;
				} else if (!used[next]) {
					dist[next] = dist[now] + cost;
					used[next] = true;
					que.emplace(next);
				}
			}
		}
	}

	return true;
}

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

	int n, m;
	cin >> n >> m;

	vector<int> l(m), r(m), d(m);
	for (int i = 0; i < m; i++) {
		cin >> l[i] >> r[i] >> d[i];
		l[i]--; r[i]--;
	}

	cout << (solve(n, m, l, r, d) ? "Yes" : "No") << endl;
	return 0;
}


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

int main(){
    int n, d;
    cin >> n >> d;
    int data[50][50];

    rep(i, n){
        rep(j, d){
            cin >> data[i][j];
        }
    }
    int ans = 0;
    rep(i, n){
        for(int j = i+1; j < n; j++){
            double sum = 0;
            for(int k = 0; k < d; k++){
                sum += pow(data[i][k]-data[j][k], 2.0);
            }
            sum = sqrt(sum);

            if(floor(sum)==sum)ans++;

        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main(void){
    int N;
    cin>>N;
    vector<int> L(N);
    for(int i=0;i<N;i++){
        cin>>L[i];
    }
    sort(L.begin(),L.end());
    int sum=0;
    for(int i=0;i<N-1;i++){
        sum+=L[i];
    }
    if(L[N-1]<sum) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

ll dp[1000001][2];
int main(void) {
    string s;
    cin >> s;
    ll n = s.size();

    dp[n][1] = INF; 
    for(ll i=n; i>=1; --i) {
        dp[i-1][0] = dp[i][0] + s[i-1]-'0';
        chmin(dp[i-1][0], dp[i][1] + s[i-1]-'0'+1);
        dp[i-1][1] = dp[i][0] + 10-(s[i-1]-'0');
        chmin(dp[i-1][1], dp[i][1] + 10-(s[i-1]-'0'+1));
    }
    cout << min(dp[0][0], dp[0][1]+1) << endl;

    return 0;
}

Measured memory_bytes: 17052
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
using namespace std;

int main(){
    fastio;
    int n, k;
    cin>>n>>k;

    vector<int> v(n);
    vector<bool> dp(k+1, false);

    for(int & x : v)
        cin>>x;
    
    sort(all(v));

    for(int p = v[0]; p <= k; p++){
        for(int i = 0; i < v.size(); i++){
            if(p - v[i] < 0)
                break;
            
            if(!dp[p - v[i]]){
                dp[p] = true;
                break;
            }
        }
    }

    if(dp[k])
        cout<<"First\n";
    else
        cout<<"Second\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

long long LCM(long long x, long long y) {
    long long q, a = x, b = y;
    while (b) {
        q = a % b;
        a = b;
        b = q;
    }
    return x / a * y;
}

/* main */

// １〜AのBの倍数の個数
ll func(ll A, ll B) {
    return A / B;
}

signed main() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll ans = func(B, C) + func(B, D) - func(B, LCM(C, D)) - (func(A - 1, C) + func(A - 1, D) - func(A - 1, LCM(C, D)));
    cout << B - A + 1 - ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,ara[100002][4],visit[1000002][4];

ll dp(ll pos, ll i)
{
    ll j,p,q;
    if(pos==n)return 0;
    if(visit[pos][i]!=-1)return visit[pos][i];
    p=ara[pos][i]+dp(pos+1,(i+1)%3);
    q=ara[pos][i]+dp(pos+1,(i+2)%3);
    return visit[pos][i]=max(p,q);
}

int main()
{
    ll i,ans;
    scanf("%lld",&n);
    for(i=0; i<n; i++)scanf("%lld %lld %lld",&ara[i][0],&ara[i][1],&ara[i][2]);
    memset(visit,-1,sizeof(visit));
    ans=dp(0,0);
    ans=max(ans,dp(0,1));
    ans=max(ans,dp(0,2));
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 40832
#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ld dp[333][333][333];
int ans[3];
int main()
{
	ld n;
	cin>>n;
	REP(i,n)
	{
		int a;
		cin>>a;
		a--;
		ans[a]++;
	 } 
	REP(k,303)
		REP(j,303)
			REP(i,303)
			{
				ld tot=i+j+k;
				if(!tot)continue;
				if(i)dp[i][j][k]+=dp[i-1][j][k]*i/n;
				if(j)dp[i][j][k]+=dp[i+1][j-1][k]*j/n;
				if(k)dp[i][j][k]+=dp[i][j+1][k-1]*k/n;
				dp[i][j][k]=(dp[i][j][k]+1)*n/tot;
			}
	cout<<fixed<<setprecision(10)<<dp[ans[0]][ans[1]][ans[2]]<<endl;
	return 0;
}



Measured memory_bytes: 526592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();

		if(X>=Y) {
			System.out.println(10);
		}else {
			System.out.println(0);
		}
	}
}


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

#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
using ll = long long;

const int maxn = 2e5 + 10; 
const int INF = 0x3f3f3f3f;
const double eps = 1e-7;

int main()
{
	fastIO;
	double a,b;
	cin >> a >> b;
	//cout << ceil(0.5) << endl;
	int l1 = ceil(a / 0.08), r1 = floor((a + 1 - eps) / 0.08);
	int l2 = ceil(b / 0.1), r2 = floor((b + 1 - eps) / 0.1);
	int l = max(l1,l2), r = min(r1,r2);
	if(l <= r) cout << l << endl;
	else cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, a: "List[int]"):
    print(min(sum((ai - y) ** 2 for ai in a) for y in range(-100, 101)))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
	"strconv"
	"strings"
)

const debug = false

type point struct {
	x, y int
	red  bool
}

type pointList []point

func (p pointList) Len() int {
	return len(p)
}

func (p pointList) Less(i, j int) bool {
	return p[i].x < p[j].x
}

func (p pointList) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p *problem) solve() {
	N := p.nextInt()
	points := pointList{}
	for i := 0; i < N; i++ {
		l := p.nextInts()
		points = append(points, point{x: l[0], y: l[1], red: true})
	}
	for i := 0; i < N; i++ {
		l := p.nextInts()
		points = append(points, point{x: l[0], y: l[1], red: false})
	}
	var c int

	sort.Sort(points)
	log.Printf("points: %v", points)

	var redSet pointList
	for _, p := range points {
		if p.red {
			redSet = append(redSet, p)
		} else {
			maxYIdx := 999
			maxY := -1
			for i, rp := range redSet {
				if rp.y < p.y && rp.y > maxY {
					maxYIdx = i
					maxY = rp.y
				}
			}
			if maxYIdx != 999 {
				log.Printf("PAIR! bp(%v) selected %v from %v.", p, redSet[maxYIdx], redSet)
				c++
				redSet = append(redSet[:maxYIdx], redSet[maxYIdx+1:]...)
			} else {
				log.Printf("NO PAIR! bp:%v, redSet:%v", p, redSet)
			}
		}
	}
	p.printf("%d", c)
}

func main() {
	if debug {
		log.SetOutput(os.Stdout)
	} else {
		log.SetOutput(ioutil.Discard)
	}

	p := problem{
		in:  bufio.NewReader(os.Stdin),
		out: bufio.NewWriter(os.Stdout),
	}
	p.solve()

	if err := p.out.Flush(); err != nil {
		panic(err)
	}
}

type problem struct {
	in  *bufio.Reader
	out *bufio.Writer
}

func (p *problem) printi(d int) {
	if err := p.out.WriteByte(byte(d)); err != nil {
		panic(err)
	}
}

func (p *problem) printf(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, format, a...); err != nil {
		panic(err)
	}
}

func (p *problem) nextInt() int {
	return stoi(p.next())
}

func (p *problem) nextInts() []int {
	line := p.nextSSLine()
	ds := make([]int, len(line))
	for i, s := range line {
		ds[i] = stoi(s)
	}
	return ds
}

func (p *problem) nextSSLine() []string {
	return strings.Split(p.next(), " ")
}

// Next reads line and return string.
func (p *problem) next() string {
	var b []byte
	for {
		l, pre, err := p.in.ReadLine()
		if err != nil {
			panic(err)
		}
		b = append(b, l...)
		if !pre {
			break
		}
	}
	return string(b)
}

func stoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		fmt.Println(i)
		fmt.Println(err)
	}
	return i
}


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

ll cmb(ll x, ll y){
    if(y>x||y<0) return 0LL;
    ll c = 1;
    for(ll i = 0LL; i < y; i++) {
        c*=x-i;
      	c/=i+1;
    }
    return c;
}

int main() {
    ll N,A,B;
    cin>>N>>A>>B;
    vector<ll> v(N);
    map<ll,ll> m;
    for(int i = 0; i < N; i++) {
        cin>>v[i];
        m[v[i]]++;
    }
    sort(v.begin(),v.end());
    ll ans = 0LL;
    ll cnt = 0LL;;
    ll s = 0LL;
    for(ll i = 0; i < A; i++) {
        ans+=v[N-1-i];
        if(v[N-1-i]==v[N-A]) s++;
    }
  	if(v[N-1]==v[N-A]){
    	for(ll i = s; i <= min(m[v[N-A]],s+B-A);i++){
      		cnt+=cmb(m[v[N-A]],i);
    	}
    }
  	else cnt = cmb(m[v[N-A]],s);
    double t = (double)ans/A;
    cout<<fixed<<setprecision(10)<<t<<endl;
    cout<<cnt<<endl;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define reverse(x) reverse(x.begin(), x.end())
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long,long long>
#define f first
#define s second
typedef long long ll;
const int mod = 1e9+7;
const int N = 1005;
using namespace std;
ll x, y, z ,K;
//ll a[N], b[N], c[N], n;

int main(){
	ll a,b,v,w, t;
	cin >> a >> v >> b >> w >> t;
	ll A = a+v*t;
	ll B = b+w*t;
	if(b<a){
		if((a-v*t)<=(b-w*t)){
			cout << "YES";
		}else {
			cout << "NO";
		}return 0;
	}else if(B<=A){
		cout << "YES";
	}else {
		cout << "NO";
	}
}


Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Scanner;


class Main{
    public static void main(String[] a){
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		
		int[] array = new int[10];
		
		for(int i = 0; i < 10 ; i++){
			array[i] = sc.nextInt();
		}
		
		Arrays.sort(array);
		
		System.out.println(array[9]);
		System.out.println(array[8]);
		System.out.println(array[7]);
    }
}

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

int max(int a,int b){
  if(a>b) return a;
  else return b;
}
int absolute(int a,int b){
  if(a-b<0) return -(a-b);
  else return a-b;
}
int main(){
  int A,B;
  cin >> A >> B;
  
  if(A+B >= 10) cout << "error" << endl;
  else cout << A+B << endl;
}

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

using namespace std;

vector<int> prefix_sum;
vector<int> input;

int main() {
    int n;
    int sum = 0;
    cin >> n;
    prefix_sum.push_back(0);
    for(int i=0;i<n;i++){
        int p;
        cin >> p;
        input.push_back(p);
        sum+=p;
        prefix_sum.push_back(sum);
    }

    int ans =1000000;

    for(int i=1;i<=n;i++){
        //cout << i << ' ' << sum-prefix_sum[i-1] << ' ' << prefix_sum[i-1]<< endl;
        ans = min(abs(sum-2*prefix_sum[i-1]),ans);
    }

    cout << ans;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    string s;
    cin >> s;
    int k;
    cin >> k;
    int n = s.size();
    if(n < 4) {
        int num = stoi(s);
        int ans = 0;
        for(int i = 1; i <= num; i++) {
            string str = to_string(i);
            ll tmp = str.size();
            if(count(all(str), '0') == tmp - k) {
                ans++;
                // cout << str << endl;
            }
        }
        cout << ans << endl;
        return 0;
    }
    ll ans = 0;
    ll t = 9;
    vector<vector<vector<ll>>> dp(n + 1,
                                  vector<vector<ll>>(2, vector<ll>(4, 0)));
    for(ll i = 1; i <= n; i++) {
        dp[i][0][0] = 1;
        dp[i][0][1] = (i - 1) * t;
        dp[i][0][2] = (i - 1) * (i - 2) * t * t / 2;
        dp[i][0][3] = (i - 1) * (i - 2) * (i - 3) * t * t * t / 6;
    }
    ll c = 0;
    for(int i = 1; i <= n; i++) {
        ll m = s[i - 1] - '0';
        if(m == 0) {
            continue;
        }
        ans += (m - 1) * dp[n - i + 1][0][k - 1 - c];
        ans += dp[n - i + 1][0][k - c];
        c++;
        if(k - 1 - c < 0) {
            break;
        }
    }
    ll res = 1;
    if(c < k) {
        res = 0;
    }
    cout << ans + res << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {

  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);

    int n = in.nextInt();
    int[] h = new int[n];
    for (int i = 0; i < n; i++)
      h[i] = in.nextInt();

    boolean term = false;

    int res = 0;

    while (!term) {
      term = true;
      for (int i = 0; i < n; i++) {
        if (h[i] > 0) {
          term = false;
          h[i]--;
          if (i == n - 1 || h[i + 1] == 0)
            res++;
        }
      }
    }

    out.println(res);

    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }
  }

  static void print(int[] arr) {
    Arrays.stream(arr).forEach(i -> System.out.print(i + " "));
    System.out.println();
  }

}



Measured memory_bytes: 23124
#include<stdio.h>
#include<string.h>

int main(void)
{
	int i,j=0;
	char st[21],st1[21];
	
	scanf("%s",st);
	for(i=strlen(st)-1;i>=0;i--)
	{
		st1[j]=st[i];
		j++;
	}
	st1[j]='\0';
	printf("%s\n",st1);
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<long long,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define w(t) while(t--)
#define c(n); cin>>n;
#define p(n) cout<<n;
#define pl(n) cout<<n<<"\n";
#define ps(n); cout<<n<<" ";
#define F first
#define S second
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define ull unsigned long long
#define vll vector<ll>
#define vii vector<ii>
#define mkp make_pair
#define ld long double
#define arrin(a,n) f(i,0,n){cin>>a[i];}
#define arrout(a,n) f(i,0,n){cout<<a[i]<<" ";}
#define printclock cerr<<"Time : "<<*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define PI (2*acos(0))
#define EPS 1e-18
int main(void){
    fastio;
    ll k;
    cin>>k;
    string s = "ACL";
    f(i,0,k){
        p(s);
    }
}




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

bool f(vector<queue<pair<int, int>>>(&que), vector<int>(&x), int idx, int start, vector<bool>(&is_calculated))
{
    bool ret = false;
    if (is_calculated[idx])
    {
        if (x[idx] != start)
        {
            ret = true;
        }
    }
    else
    {
        is_calculated[idx] = true;
        x[idx] = start;
    }

    while (que[idx].size() > 0)
    {
        int next_idx = que[idx].front().first;
        int next_val = que[idx].front().second + start;
        que[idx].pop();
        ret |= f(que, x, next_idx, next_val, is_calculated);
    }
    return ret;
}

int main()
{
    int N, M;
    cin >> N >> M;
    int L;
    int R;
    int D;
    vector<queue<pair<int, int>>> que(N + 1);
    for (int i = 0; i < M; i++)
    {
        cin >> L >> R >> D;
        que[L].push(make_pair(R, -D));
        que[R].push(make_pair(L, D));
    }

    vector<bool> is_calculated(N + 1, 0);
    vector<int> x(N + 1, 0);
    string ans = "Yes";
    for (int i = 1; i <= N; i++)
    {
        if (!is_calculated[i])
        {
            if (f(que, x, i, 0, is_calculated))
            {
                ans = "No";
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 95616
#include<bits/stdc++.h>
using namespace std;
#define ioS            ios::sync_with_stdio(false);cin.tie(0);
#define li             long int
#define ll            long li
#define ull            unsigned ll
#define pi             pair<int,int>
#define vi             vector<int>
#define vli            vector<li>
#define vll           vector<ll>
#define vvi            vector<vector<int>>
#define pb             push_back
#define mp             make_pair
#define forn(i,s,n)    for(auto i=s;i<n;++i)               
#define forr(i,s,n)    for(auto i=s;i>=n;--i) 
const ll MOD = 1e9+7;
const li mx = 1e9; 

void solve()
{
    int n;
    int count=0;
    cin>>n;
    vi a(n);
    forn(i,0,n)
        cin>>a[i];
    forn(i,0,n)
    {
        if(a[i]%2 && (i+1)%2)
        count++;
    }
    cout<<count<<endl;
}
int32_t main()
{
    ioS
    int t;
    // cin>>t;
    // while(t--)
        solve();
}


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

#include <assert.h>    // LON
#include <math.h>    // sqrt()


using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;


int main() {

    int n, m;
    cin >> n >> m;
    vector<int> counts(n, 0);

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        counts[a]++;
        counts[b]++;
    }

    for (int c : counts) {
        cout << c << endl;
    }

}



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

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = 0;
    if((b-a)%2==0) {
        ans += abs(a-b)/2;
    } else {
        ans += min(a-1, n-b);
        ans += (1 + (b-a-1)/2);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n,ans=1e5;
  cin>>n;

  for(int i=0;i<=n;++i){
    int a=i;
    int cnt=0;
    while(a>0)cnt+=a%6,a/=6;
    a=n-i;
    while(a>0)cnt+=a%9,a/=9;
    ans=min(ans,cnt);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
package main


import (
    "fmt"
)

func main() {
  var N,K int
  var S int = 1

  fmt.Scan(&N, &K)

  for i := 0; i < N; i++ {
    if S * 2 < S + K {
      S *= 2

    } else {
      S += K

    }
  }


  fmt.Println(S)


}


Measured memory_bytes: 512