akhauriyash/Code-Regression huggingface dataset:
N, K  = [int(elm) for elm in input().split()]
S = input()

state = 2
counts = []
k_count = 0 # 0 -> 1, count++

end_lens = []
save_flag = False
end_i = -1
for s_in, s in enumerate(S):
    if s == "0":
        if state == 1: # 1 -> 0 (c_start)
            #k_count += 1
            #if save_flag: # end 1
            #print("1->0", s_in, k_count)
            if k_count >= K: # stop counter k_count-1
                end_i += 1
                
                #print("range", counts[end_i][0], s_in)
                len_ = s_in - counts[end_i][0]
                end_lens.append(len_)
                save_flag = False

            state = 0

        elif state == 2: # first
            new_count = [s_in, 0, -1]
            counts.append(new_count)
            state = 0
            pass
        else: # state = 0 cont.
            pass

    if s == "1":
        if state == 0: # 0 -> 1 (c_end)
            k_count += 1            
            #print("0->1", s_in, k_count)
            state = 1

            new_count = [s_in, 0, -1]
            counts.append(new_count)

        elif state == 2: # first 
            new_count = [s_in, 0, -1]
            counts.append(new_count)
            state = 1
        else: # state = 1 cont.
            pass

#if save_flag:
if True:
    s_in += 1
    end_i += 1
    #print("range", counts[end_i][0], s_in)
    len_ = s_in - counts[end_i][0]
    end_lens.append(len_)
    save_flag = False

if len(end_lens) == 0:
    out = len(S)
else:
    out = max(end_lens)

print(out)

Measured memory_bytes: 11380
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int A, B, C, D; cin >> A >> B >> C >> D;

    int total = 0;
    if (A <= C && C <= B) {
      total = min(B,D)-C;
    } else if (C <= A && A <= D) {
      total = min(B,D)-A;
    }

    cout << total << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
int e(int a,int b){if(a<b)a^=b^=a^=b;while(a%=b)a^=b^=a^=b;return b;}int main(){for(int a,b,c,s;s=!(std::cin>>a>>b).eof();s&&printf("%ld %ld\n",c,a/c*b))c=e(a,b);}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

class Graph{
    public:
    using PL = pair<ll, ll>;
    const ll INF = 1e15;

    ll size;
    // has dist, to
    vector<vector<PL> > g;
    vector<ll> dist;

    Graph(ll n){
        size = n;
        g = vector<vector<PL> >(size);
        dist = vector<ll>(size);
    }

    void add_edge(ll x, ll y, ll w){
        g[x].push_back(make_pair(w, y));
    }

    void dijkstra(ll s){
        priority_queue<PL, vector<PL>, greater<PL> > PQ;
        fill(dist.begin(), dist.end(), INF);
        dist[s] = 0;
        PQ.push(make_pair(0, s));

        while(!PQ.empty()){
            PL p = PQ.top(); PQ.pop();
            ll v = p.second;
            if(dist[v] < p.first) continue;
            for(PL np: g[v]){
                ll d = np.first;
                ll u = np.second;
                if(dist[u] > dist[v] + d){
                    dist[u] = dist[v] + d;
                    PQ.push(make_pair(dist[u], u));
                }
            }
        }
    }
};

// GRL_1_A: verified
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int v, e, r; cin >> v >> e >> r;
    Graph graph(v);
    for(int i=0;i<e;i++){
        int s, t, d; cin >> s >> t >> d;
        graph.add_edge(s, t, d);
    }
    graph.dijkstra(r);
    for(int i=0;i<v;i++){
        if(graph.dist[i] >= graph.INF)
            cout << "INF" << endl;
        else
            cout << graph.dist[i] << endl;
    }
}


Measured memory_bytes: 19344
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

ll N;

int main(){
	cin >> N;

	vector<pair<ll, ll> >BA(N);

	rep(i, N) {
		cin >> BA[i].second >> BA[i].first;
	}

	sort(BA.rbegin(), BA.rend());


	ll cur = 1e15;

	rep(i, N) {
		ll end = BA[i].first;
		ll t = BA[i].second;

		if(cur > end) {
			cur = end;
		}

		cur -= t;
	}

	if(cur >= 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


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

typedef long long ll;
typedef vector<ll> vl;

const ll MOD = (ll)1e9 + 7;
int N;
ll K;
vector<vl> A, ans;

void input_init(void) {
	cin >> N >> K;
	A.resize(N, vl(N));
	for (int j = 0; j < N; ++j) {
		for (int i = 0; i < N; ++i)
			cin >> A[j][i];
	}
	ans.resize(N, vl(N, 0));
	for (int i = 0; i < N; ++i)
		ans[i][i] = (ll)1;
}

void pow_A(ll x) {
	while (x > (ll)0) {
		if ((x & (ll)1) == (ll)1) {
			vector<vl> tmp(N, vl(N, (ll)0));
			for (int j = 0; j < N; ++j) {
				for (int k = 0; k < N; ++k) {
					for (int i = 0; i < N; ++i) {
						tmp[j][i] += (ans[j][k] * A[k][i]) % MOD;
						tmp[j][i] %= MOD;
					}
				}
			}
			for (int j = 0; j < N; ++j) {
				for (int i = 0; i < N; ++i)
					ans[j][i] = tmp[j][i];
			}
		}
		vector<vl> tmp(N, vl(N, (ll)0));
		for (int j = 0; j < N; ++j) {
			for (int k = 0; k < N; ++k) {
				for (int i = 0; i < N; ++i) {
					tmp[j][i] += (A[j][k] * A[k][i]) % MOD;
					tmp[j][i] %= MOD;
				}
			}
		}
		for (int j = 0; j < N; ++j) {
			for (int i = 0; i < N; ++i)
				A[j][i] = tmp[j][i];
		}
		x >>= 1;
	}
}

ll solve(void) {
	ll ret = 0;
	for (int j = 0; j < N; ++j) {
		for (int i = 0; i < N; ++i) {
			ret += ans[j][i] % MOD;
			ret %= MOD;
		}
	}
	return ret;
}

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

	input_init();
	pow_A(K);
	ll val = solve();

	cout << val << '\n';
	return 0;
}


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

namespace CSharp_practice
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            if (s == "SUN")
            {
                Console.WriteLine(7);
            }
            else if (s == "MON")
            {
                Console.WriteLine(6);
            }
            else if (s == "TUE")
            {
                Console.WriteLine(5);
            }
            else if (s == "WED")
            {
                Console.WriteLine(4);
            }
            else if (s == "THU")
            {
                Console.WriteLine(3);
            }
            else if (s == "FRI")
            {
                Console.WriteLine(2);
            }
            else if (s == "SAT")
            {
                Console.WriteLine(1);
            }
        }
    }
}


Measured memory_bytes: 11092
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [A, B, C, D] = input[0].map(Number);

  return Math.ceil(A / D) + 1 > Math.ceil(C / B) ? "Yes" : "No";
};

console.log(main(read()));


Measured memory_bytes: 29484
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define INF (int)1e9 + (int)1e8
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

ll dp[100005][3];

int main(){
    cpp();
    ll n;
    cin>>n;
    vector<vector<ll> > v(n);
    for(ll i=0; i<n; i++){
        ll a, b, c;
        cin>>a>>b>>c;
        v[i]={a, b, c};
    }
    dp[0][0] = v[0][0];
    dp[0][1] = v[0][1];
    dp[0][2] = v[0][2];
    for(ll i=1; i<n; i++){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2])+v[i][0];
        dp[i][1] = max(dp[i-1][2], dp[i-1][0])+v[i][1];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1])+v[i][2];
    }
    cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]})<<endl;
    return 0;
}






Measured memory_bytes: 11056
N = int(input())
a = list(map(int, input().split()))

A = [[0 for __ in range(N)] for _ in range(N)]
S = [[0 for __ in range(N)] for _ in range(N)]

for i in range(N-1):
    for j in range(i, N):
        S[i][j] = sum(a[i:j+1])

for w in range(1, N):
    for i in range(N):
        j = i + w
        if j >= N:
            break
        
        A[i][j] = min([
            A[i][k] + A[k+1][j] for k in range(i, j)
        ]) + S[i][j]

print(A[0][-1])

Measured memory_bytes: 45660
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

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

    rep(i,Q){
        ll A,B; cin >> A >> B;
        if(A > B) swap(A,B);
        // A <= B
        // (1,B+A-1) (2,B+A-2) ... (A-2,B+2),(A-1,B+1) のペアは全てAB未満
        //     (A-x,B+x)の組み合わせは (A-x)(B+x) = AB + (A-B)x + x^2 < ABより
        // --> 2*(A-1)は確実
        ll ans = 2 * (A-1);

        // 1回目でA < t1 =< B,2回目で A <= t2 < Bの順位でペアを組める最大数を求めたい
        // 最大人数を二分探索
        int l,r;
        l = 0;
        r = B - A;
        auto isValid = [&](int m){
            for(int i=-1;i<=1;i++){
                const ll x = m/2 + i;
                const ll c = (A + x) * (A + m - x);
                if(c < A*B) continue;
                else return false;
            }
            return true;
        };

        while(r-l>1){
            int m = (l+r)/2;

            const bool ok = isValid(m);
            if(ok){
                l = m;
            }else{
                r = m;
            }
        }
        ans += l;
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PipedInputStream;
import java.util.*;

public class Main {
    private static final int MOD = (int) Math.pow(10, 9);
    private static final int[][] DIRS = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

    public static void main(String[] args) {
        FastReader sc = new FastReader();

        int h = sc.nextInt();
        int n = sc.nextInt();
        int sum = 0;

        for (int i = 0; i < n; i++) {
            sum += sc.nextInt();
        }

        if (sum >= h) {
            print("Yes");
        } else {
            print("No");
        }



        System.exit(0);
    }

    static  private void print(String s) {
        System.out.println(s);
    }

    static private int log2(int x) {
        return (int)(Math.log(x) / Math.log(2));
    }

    static private long gcd(long m, long n) {
        if (m < n) { return gcd(n, m); }
        if (m % n == 0) { return n; }
        return gcd(n, m%n);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try{
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int N, M, K;
vector<vi> graph;
vector<bool> visited;
vi inComponent;

void dfs(int node) {
	inComponent.push_back(node);
	visited[node] = true;
	for (int n : graph[node]) {
		if (!visited[n]) dfs(n);
	}
}
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> M >> K;
	graph.resize(N);
	F0R(i, M) {
		int a, b; cin >> a >> b; --a; --b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	visited = vector<bool> (N);
	vi ans (N);
	vi compCount (N);
	int curComponent = 0;

	F0R(i, N) {
		if (visited[i]) continue;
		++curComponent;
		inComponent = vi ();
		dfs(i);
		for (int pos : inComponent) {
			ans[pos] = inComponent.size() - 1;
			compCount[pos] = curComponent;
		}
	}

	F0R(i, K) {
		int a, b; cin >> a >> b; --a; --b;
		if (compCount[a] == compCount[b]) {
			ans[a]--;
			ans[b]--;
		}
	}

	F0R(i, N) {
		for (int nnode : graph[i]) {
			if (compCount[nnode] == compCount[i]) --ans[i];
		}
	}
	F0R(i, N) {
		cout << ans[i] << " ";
	}
	cout << endl;
}

Measured memory_bytes: 8132
#include<iostream>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<tuple>
#include<iomanip>
#include<climits>
#define ll long long int
#define mod 1000000007
#define pi acos(-1)
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin>>n;
  int t;
  int ans=1;
  for(int i=0;i<n;i++)
  {
    cin>>t;
    if(t%2==0)
    {
      if(t%6!=0&&t%10!=0)
    {
      ans=-1;
    }
    }
   
  }
  if(ans==1)
    cout<<"APPROVED";
 else
 {
   cout<<"DENIED";
 }
 
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<list>

int main(int argc, char const *argv[])
{
    int q,x;
    char com[20];
    std::list<int> v;

    scanf("%d",&q);

    for(int i = 0;i < q;i++){
        scanf("%s",com);

        if(com[0] == 'i'){
            scanf("%d",&x);
            v.push_front(x);
        }
        else if(com[6] == 'L'){
            v.pop_back();
        }
        else if(com[6] == 'F'){
            v.pop_front();
        }
        else if(com[0] == 'd'){
            scanf("%d",&x);
            for(std::list<int>::iterator it = v.begin();it != v.end();it++){
                if(*it == x){
                    v.erase(it);
                    break;
                }
            }
        }
    }
    
    int i = 0;
    for(std::list<int>::iterator it = v.begin();it != v.end();it++){
        if(i++) printf(" ");
        printf("%d",*it);
    }
    printf("\n");

    return 0;
}



Measured memory_bytes: 34380
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    a,b,k=parseMap(split(readline()))
    cnt=0
    for i in reverse(1:min(a,b))
        if a%i==0 && b%i==0
            cnt+=1
            if cnt==k
                println(i)
                break
            end
        end
    end
end
main()

Measured memory_bytes: 169464
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	ll n,k;
	cin >> n >> k;
	string s;
	cin >> s;
	vector<ll> v;
	ll cnt=1;
	FOR(i,n-1){
		if(s[i]==s[i+1]){
			cnt++;
		}else{
			v.push_back(cnt);
			cnt=1;
		}
	}
	v.push_back(cnt);
	ll ans=n-(ll)v.size();
	if((ll)v.size()/2<=k){
		ans=n-1;
	}else{
		ans+=k*2;
	}
	
	cout << ans << endl;

}

Measured memory_bytes: 1528
#include <stdio.h>
#include <ctype.h>

int main(void){
	short c,x;

	for(;;){
		// Input & CountUp
		x = 0;
		for(;;){
			c = getchar();
			// EOL/EOF Check
			if( c == EOF || c == '\n' ){
				break;
			}
			// Number Check
			if( !isdigit(c) ){
				continue;
			}
			// Convert & CountUp
			x += (char)(c-'0');
		}
		// Finish Check
		if( x == 0 ){
			break;
		}
		// Output
		printf("%d\n",x);
	}

	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cmath>

typedef long long ll;

using namespace std;

int main() {
	ll N;
    cin >> N;
    ll ans = N - 1;
    for (ll i = 2; i * i <= N; i++) {
        if (N % i == 0) {
            ans = min(ans, i + N / i - 2);
        }
    }
    cout << ans << "\n";
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  i64 a, b, c;
  cin >> a >> b >> c;
  if (a == b) cout << c;
  else if (a == c) cout << b;
  else cout << a;
  cout << '\n';
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
//get the biggest element.
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  });
}
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

ll n, k, ans;

void solve(ll p) {
  if (p % k == 0) ans = 0;
  else if (p / k == 0) {
    if (ans > abs(p - k)) {
      ans = abs(p - k);
      solve(ans);
    }
  } else {
    ans = p % k;
    solve(ans);
  }
}

int main() {
  cin >> n >> k;
  ans = 1e18 + 10;
  solve(n);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
N = gets.chomp.to_i
A = gets.chomp.split(' ').map(&:to_i)

A.sort! {|a, b| b <=> a }

temp = []
av = []
ans = 0
A.each do |a|
  if temp.include?(a)
    temp.delete(a)
    l = av.length
    if l == 0
      av.push a
    elsif l == 1
      ans = av[0] * a
      break
    end
  else
    temp.pop
    temp.push a
  end
end

print ans

Measured memory_bytes: 10240
import math

MOD = 10 ** 9 + 7

N, M = map(int, input().split())

if abs(N - M) > 1:
    print(0)
else:
    res = 1
    res = (res * math.factorial(N)) % MOD
    res = (res * math.factorial(M)) % MOD
    res = (res * (2 if N - M == 0 else 1)) % MOD
    print(res)


Measured memory_bytes: 4080
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e8 + 7;

bool p[1100000] = {};

int main(){
	
	int N = 1000000;
	
	for(int i = 0; i < N; i++){
		p[i] = true;
	}
	
	p[0] = false;
	p[1] = false;
	
	for(int i = 2; i < N; i++){
		if(p[i]){
			for(int j = i * 2; j < N; j += i){
				p[j] = false;
			}
		}
	}
	
	while(true){
		int a, b;
		cin >> a >> b;
		if(a == 0){
			break;
		}
		int Sa, Sb;
		int pmax = 0;
		int S = 0;
		for(int i = 1; i <= a; i++){
			if(a % i == 0 && p[i]){
				S += i;
				pmax = i;
			}
		}
		Sa = pmax * 2 - S;
		
		S = 0;
		for(int i = 1; i <= b; i++){
			if(b % i == 0 && p[i]){
				S += i;
				pmax = i;
			}
		}
		Sb = pmax * 2 - S;
		if(Sa > Sb){
			cout << "a" << endl;
		}else{
			cout << "b" << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 4036
#include <stdio.h>
#include <math.h>
int main(){
	double a[1010];
	int n;
	double m=0;
	double ans=0;
	int i;
	while(scanf("%d",&n),n!=0){
		m=0;
		ans=0;
		for(i=0;i<n;i++){
			scanf("%lf",&a[i]);
			m+=a[i];
		}
		m/=(double)n;
		for(i=0;i<n;i++){
			ans+=pow(a[i]-m,2.0);
		}
		ans/=(double)n;
		printf("%lf\n",sqrt(ans));
	}
	return 0;
}

Measured memory_bytes: 664
from collections import Counter

N = int(input())
a = list(map(int, input().split()))

c = Counter(a)

if c[0] == N:
    print("Yes")
elif N%3 == 0 and len(c) == 2:
    for A in a:
        if c[A] == (2*N)//3:
            print("Yes")
            break
    else:
        print("No")
elif N%3 == 0 and len(c) == 3:
    tmp = list(set(a))
    if c[tmp[0]] == c[tmp[1]] == c[tmp[2]] and tmp[0] ^ tmp[1] ^ tmp[2] == 0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 14468
#include<stdio.h>
int main(void){
  char s[4];
  int i;
  int sum=0;
  
  for(i=0;i<4;i++){
    scanf("%c",&s[i]);
    if(s[i]=='+')
      sum++;
    else
      sum--;
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main(void){

  int n,i,ans=0;
  vector<int> v(n), c(n);
  cin>>n;
  rep(i,n)cin>>v[i];
  rep(i,n)cin>>c[i];
  rep(i,n)if(v[i]-c[i]>0)ans+=v[i]-c[i];
  cout<<ans;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) cout << (x) << endl
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INF = 1<<29;
const int MOD = 1000000007;
 
void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll N;
    cin >> N;
    vector<ll> a(N);
    map<ll,ll> m;
    rep(i,N) cin >> a[i], m[a[i]]++;
    if(N % 3 != 0 || m.size() == 1){
      rep(i,N){
        if(a[i]) {
          print("No"); 
          return 0;
        }
      }
      print("Yes");
      return 0;
    }
    if(m.size() == 2){
      ll count = 0;
      rep(i,N) if(!a[i]) count++;
      if(count == N / 3){
        print("Yes"); 
        return 0;
      }
      print("No");
      return 0;
    }
    ll tmp = 0;
    if(m.size() == 3){
      for(auto itr = m.begin(); itr != m.end(); ++itr){
        if(itr->second != N / 3){ 
          print("No");
          return 0;
        }
        tmp ^= itr->first;
      }
      if(!tmp) {
        print("Yes"); 
        return 0;
      }
      print("No");
      return 0;
    }
    if(m.size() > 3) {
      print("No"); 
      return 0;
    }
}

Measured memory_bytes: 5760
import sys


try:
    sys.stdin = open(sys.path[0] + '\\input.txt', 'r')
    sys.stdout = open(sys.path[0] + '\\output.txt', 'w')
except FileNotFoundError:
    pass


k = int(input())
a, b = list(map(int, input().split()))

lower = k * int(a // k)
if lower < a:
    lower += k

if lower <= b:
    print('OK')
else:
    print('NG')


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> s(m);
  for (int i = 0; i < m; i++){
    int k;
    cin >> k;
    for (int j = 0; j < k; j++){
      int a;
      cin >> a;
      a--;
      s[i].push_back(a);
    }
  }
  vector<int> p(m);
  ll ans = 0;
  rep(i, m) cin >> p[i];
  for (int bit = 0; bit < (1 << n); bit++){
    bool ok = true;
    rep(i, m){
      int cn = 0;
      for(auto v :s[i]){
        if(bit & (1 << v))cn++;
      }
      if(cn % 2 != p[i]) ok = false;
    }
    if(ok) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

ll gcd(ll a, ll b) {
    if (a<b) swap(a, b);
    while(b!=0) {
        ll t = a;
        a = b;
        b = t%b;
    }
    return a;
}

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

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

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

    int n; cin >> n;
    vector<ll> c(n, 0);
    rep(i, n) cin >> c[i];
    sort(c.begin(), c.end());

    vector<ll> two(n+5, 0);
    two[0] = 1;
    repr(i, 1, n+5) { two[i] = two[i-1]*2; chmod(two[i]); }

    ll ans = 0;
    rep(i, n) {
        ll val = two[n-i-1];
        if (i!=n-1) { val += two[n-i-2] * (n-1-i) % mod; chmod(val); }
        val *= two[i] * two[n] % mod; chmod(val);
        val *= c[i]; chmod(val);
        ans += val; chmod(ans);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
    int n,k;cin>>n>>k;
    
    vi a(n);
    rep(i,n)cin>>a[i];
    
    vi l(n+1,0),r(n,0);
    
    for(int i=1; i<=n; i++){
        l[i] = l[i-1]+a[i-1];
    }
    
    for(int i=1; i<n; i++){
        r[i] = r[i-1]+a[n-i];
    }
    
    int ans = 0;
    
    for(int i=0; i<=n-k; i++){
        ans = max(ans, l[n]- l[i] - r[n-k-i]);
    }
    
    //cout << (ans+k)/2.0 << endl;
    printf("%.10lf\n", (ans+k)/2.0);
    return 0;
}


Measured memory_bytes: 5612
#include <vector> 
#include <list> 
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

string yes = "YES", no = "NO";

const int MAX_N = 123456;
int prime[MAX_N]; bool is_prime[MAX_N + 1];
bool sieve(int n) {
	int num = 0;

	REP(i, MAX_N) { is_prime[i] = true; }
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i<n; i++) {
		if (is_prime[i]) {
			prime[num++] = i;
			for (int j = 2 * i; j<n; j += i) {
				is_prime[j] = false;
			}
		}
	}
}


int main() {

	int Q;
	int min, max;

	VI mins, maxs;


	cin >> Q;
	mins.resize(Q);
	maxs.resize(Q);

	int maxA = 0;
	REP(q, Q) {
		cin >> mins[q] >> maxs[q];
		if (maxs[q]>maxA) { maxA = maxs[q]; }
	}
	cerr << "max" << maxA << endl;
	sieve(maxA);

	VI nums(maxA+1);
	fill(nums.begin(), nums.end(), 0);

	FOR(i, 2, maxA+1) {
		if (is_prime[i] && is_prime[(i + 1) / 2]) {
			nums[i] = nums[i - 1] + 1;
		}
		else {
			nums[i] = nums[i - 1];
		}
	}


	REP(q, Q) {
		min = mins[q]; max = maxs[q];
		cout << (nums[max] - nums[min-1]) << endl;
		// int num_=0;
		// for(int i=min;i<=max;i+=2){
		//     if(is_prime[i]&&is_prime[(i+1)/2]){
		//         num_++;
		//     }
		// }
		// cout<<num_<<endl;
	}
	//sieve(100);
	// REP(i,num){cout<<prime[i]<<" ";}
	// cout<<endl;
}


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

using namespace std;

typedef long long LL;
typedef long double LD;


void func()
{
  LL N,K;
  cin >> N;
  string S;
  cin >> S; 

  LL counter_max = 0;
  for (LL i = 0; i < N; ++i) { // 部分文字列1の先頭
    for (LL j = i + counter_max+1; j < N; ++j) { // 部分文字列2の先頭
      if (i > 0 && S[i-1] == S[j - 1]) {
        continue;
      }
      LL counter = 0;
      for (LL k = 0; k + j < N; ++k) { // 何文字目か
        if (i + k < j) {
          if (S[i + k] == S[j + k]) {
            counter++;
          }
          else {
            break;
          }
        }
      }
      //cerr <<i<<" : "<<j <<" : " << counter << endl;
      counter_max = max(counter, counter_max);
    }
  }

  cout << counter_max;

}

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,A,B;
  int wa=0;
  int syu=0;
  cin>>N>>A>>B;
  for (int X=1;X<=N;X++){
    wa=0;
    int M=X;
    for (int Y=1;Y<=X;Y*=10){
      if(Y==1){
        wa+=M%10;
      }
      else{
        M/=10;
        wa+=M%10;
      }
    }
    if (wa>=A && wa<=B){
      syu+=X;
    }
  }
  cout<<syu<<endl;
}

Measured memory_bytes: 3636
H, W, K = gets.split(" ").map(&:to_i)
mtr = Array.new(H, [])

H.times do |i|
    mtr[i] = gets.chomp.split("").map{|c| c == "#"}
end

ans = 0
(0...(1 << H)).each do |hi|
    (0...(1 << W)).each do |wi|
        count = 0
        (0...H).each do |i|
            (0...W).each do |j|
                if mtr[i][j] && hi[i] != 0 && wi[j] != 0
                    count += 1
                end
            end
        end
        ans +=1 if count == K 
    end
end

puts ans

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

int main() {
    
    int startNum, endNum;
    int palindromicNumbersCount = 0;
    
    cin >> startNum >> endNum;
    
    for (int i = startNum; i < endNum + 1; i++) {
    	
    	int numToCheck = i;
    	// 万の位の数
    	int a = numToCheck / 10000;
    	numToCheck -= a * 10000;
    	
    	// 千の位の数
    	int b = numToCheck / 1000;
    	numToCheck -= b * 1000;
    	
    	// 百の位の数
    	int c = numToCheck / 100;
    	numToCheck -= c * 100;
    	
    	// 十の位の数
    	int d = numToCheck / 10;
    	numToCheck -= d * 10;
    	
    	// 一の位の数
    	int e = numToCheck;
    	
    	if(a == e && b == d)
    	    palindromicNumbersCount++;
    }
    
    cout << palindromicNumbersCount << endl;
}

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

int main(){
  int n,x,i,j;
  cin>>n>>x;
  int L[n];
  for(i=0;i<n;i++)cin>>L[i];
  int d=0,cnt=1;
  for(i=0;i<n;i++){
    d=d+L[i];
    if(d<=x){
      cnt++;
    }
  }
  cout<<cnt;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>

using namespace std;
#define MAX 100000

int main(){
    string S;

    cin >> S;
    int dif = 999;
    for (int i = 0; i < S.length() - 2; i++){
        string tmp = S.substr(i, 3);
        int tmpdiff = abs(753 - atoi(tmp.c_str()));
        if (tmpdiff < dif){
            dif = tmpdiff;
        }
    }
    cout << dif << "\n";

    return 0;
}

Measured memory_bytes: 256
n=int(input())
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
a=[a1,a2]
s=[[0]*n for i in range(2)]

for i in range(n):
  s[0][i]=sum(a[0][:(i+1)])
  
for i in range(n):
  s[1][i]=max(s[0][i],s[1][i-1]) + a[1][i]
  
print(s[1][n-1])




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

B=[0]*N

for i in range(M):
    a,b=map(int,input().split())
    B[a-1]+=1
    B[b-1]+=1

for i in range(N):
    if B[i]%2==1:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 3828
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

using namespace std;

void solution()
{
    string s;
    cin >> s;
    cout << s << (s.back() == 's' ? "es" : "s") << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n; cin >> n;
    bool is_res = false;
    rep(i,n){
        char c; cin >> c;
        if(c=='Y')is_res=true;
    }
    cout << (is_res?"Four":"Three") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
typedef unordered_map<ll,ll> umap;
#define pb emplace_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repi(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
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); }
const ll mod = 1e9+7;

int main() {
    // your code goes here
    string s;
    cin >> s;
    if(s=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}

Measured memory_bytes: 3624
class Main {
    public static void main(String args[]) {
        java.util.Scanner sc = new java.util.Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] pre = new int[n];
        for(int i=0; i<n; i++)  pre[i] = Integer.parseInt(sc.next());
        int[] ino = new int[n];
        for(int i=0; i<n; i++)  ino[i] = Integer.parseInt(sc.next());

        Tree tree = new Tree(pre, ino);
        tree.rebuild(0, n);
        tree.showAns();
    }

    static class Tree{
        private final int[] pre;
        private final int[] ino;
        private int rootIdPre = 0;
        private int[] post;
        private int numAns = 0;

        public Tree(int[] pre, int[] ino){
            this.pre = pre;
            this.ino = ino;
            this.post = new int[pre.length];
        }

        private void rebuild(int left, int right){
            if(left >= right)   return;
            int rootNum = pre[this.rootIdPre++];
            int rootIdIno = searchRootInorder(rootNum, left, right);
            
            rebuild(left, rootIdIno);
            rebuild(rootIdIno+1, right);
            this.post[this.numAns++] = rootNum;
        }

        private int searchRootInorder( int rootValue, int left, int right){
            for(int i=left; i<right; i++){
                if(this.ino[i] == rootValue) return i;
            }
            return -1;
        }
        public void showAns(){
            for(int i=0; i<this.post.length; i++){
                if(i == this.post.length-1){
                    System.out.println(this.post[i]);
                } else {
                    System.out.print(this.post[i]+" ");
                }
            }
        }


    }
}




Measured memory_bytes: 26324
#include <bits/stdc++.h>
using namespace std;
 
int main(){

	int N,R=0;
	cin >> N;
  	N = N-1;
	int B[N-1];
	for ( int i = 0; i < N; i++){
		cin >> B[i];
	}

  
	R+= B[N-1];
	
	for ( int i = N; i > 1; i--){
		if(B[i-1]>=B[i-2]){
			R += B[i-2];
		}
		else {
			R += B[i-1];
		}
	}
	
	R+= B[0];
	
	cout << R << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>  
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vl vector<ll>
#define N 100005
#define mod 1000000007
vector<vector<ll> >G(60);
ll vis[60];ll intime[60],low[60];
ll timer;ll cnt=0;

ll dfs(ll node,ll pa)
{
	vis[node]=1;
	intime[node]=low[node]=timer;
	timer+=1;
	for(auto i:G[node])
	{
		if(i==pa)
		continue;
		if(vis[i])
		{
			low[node]=min(low[node],intime[i]);
		}
		else
		{
			dfs(i,node);
			if(low[i]>intime[node])
			cnt+=1;
			low[node]=min(low[node],low[i]);
		}
	}
	return cnt;
}
int main()
{
	ll n,m;cin>>n>>m;
	while(m--)
	{
		ll x,y;cin>>x>>y;
		G[x].pb(y);G[y].pb(x);
	}
	ll sol=0;
	for(ll i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			ll ans=dfs(i,-1);
			sol+=ans;
		}
	}
	cout<<sol<<"\n";
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int, int> PII;

int main(){
    FIO;
    int n;
    cin >> n;
    double arr[n];
    for(int i = 0 ; i < n ; i++){
        cin >> arr[i];
    }
    sort(arr, arr + n);
    for(int i = 1 ; i < n ; i++){
        double tmp = arr[i-1] + arr[i];
        tmp /= 2;
        arr[i] = tmp;
    }
    printf("%0.6lf", arr[n-1]);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<pair<int,int>,null_type, less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=3e3+10, mod=1e9+7;
ll dp[N][N][2],a[N];

ll calc(int l,int r,int x){
	if(l==r) return (x?a[l]:-a[l]);
	if(l>r) return 0;
	
	ll& ans=dp[l][r][x];
	if(ans!=-1) return ans;
	
	if(x==1){
		ans=-1e15;
		ans=max( ans, a[l]+ calc(l+1,r,x^1)  );
		ans=max( ans, a[r]+ calc(l,r-1,x^1)  );
	}else{
		ans=1e15;
		ans=min( ans, -a[l]+ calc(l+1,r,x^1)  );
		ans=min( ans, -a[r]+ calc(l,r-1,x^1)  );
	}
	return ans;
}

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	memset(dp,-1,sizeof dp);
	int n,i;
	cin>>n;
	for(i=0;i<n;i++)cin>>a[i];
	cout<<calc(0,n-1,1);
}
// check for any potential overflow before submitting


Measured memory_bytes: 142080
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	string n;
	string ans;
	//int ans=0;
	cin >>n;
	char last='2';
	rep(i,n.size()){
		if(last!=n[i]){
			last=n[i];
			ans+=n[i];
		}
	}
	cout<<ans.size()-1<<endl;
}
//1212121212
//

Measured memory_bytes: 640
#include<stdio.h>


int main(){
	int n;
	int id[4000],cid;
	long long int price,num,sale[4000];
	bool f;
	int i,j,idcount;
	while(scanf("%d",&n),n){

		f=true;
		idcount=0;

		for(i=0;i<n;i++){
			scanf("%d %lld %lld",&cid,&price,&num);
			for(j=0;j<idcount;j++){
				if(id[j]==cid){
					sale[j]=sale[j]+price*num;
					break;
				}
			}

			if(j==idcount){
				id[idcount]=cid;
				sale[idcount]=price*num;
				idcount++;
			}

		}



		for(i=0;i<idcount;i++){
			if(sale[i]>=1000000){
				printf("%d\n",id[i]);
				f=false;
			}
		}
		if(f)printf("NA\n");
	}
	return 0;
}

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

using namespace std;

const int N = 1234567;

struct coins_t {
  int a, b, c;
  coins_t() {}
  coins_t(int a, int b, int c) : a(a), b(b), c(c) {}
};

int x, y, z;
coins_t coins[N];
long long lf[N], rg[N];

int main() {
  scanf("%d %d %d", &x, &y, &z);
  int n = x + y + z;
  for (int i = 0; i < n; i++) {
    int a, b, c; scanf("%d %d %d", &a, &b, &c);
    coins[i] = coins_t(a, b, c);
  }
  sort(coins, coins + n, [&](const coins_t c1, const coins_t c2) {
    return c1.a - c1.b < c2.a - c2.b;
  });
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> first;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int dif = coins[i].b - coins[i].c;
    if (y <= i) {
      pair<int, int> top = first.top();
      if (top.first < dif) {
        first.pop();
        first.push(make_pair(dif, i));
        sum = sum - coins[top.second].b + coins[i].b + coins[top.second].c;
      } else {
        sum += coins[i].c;
      }
    } else {
      first.push(make_pair(dif, i));
      sum += coins[i].b;
    }
    lf[i] = sum;            
  }
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> second;
  sum = 0;
  for (int i = n - 1; i >= 0; i--) {
    int dif = coins[i].a - coins[i].c;
    if (x <= n - i - 1) {
      pair<int, int> top = second.top();
      if (top.first < dif) {
        second.pop();
        second.push(make_pair(dif, i));
        sum = sum - coins[top.second].a + coins[i].a + coins[top.second].c;
      } else {
        sum += coins[i].c;
      }
    } else {
      second.push(make_pair(dif, i));
      sum += coins[i].a;
    }
    rg[i] = sum;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (y <= i + 1 && x <= n - i - 1) ans = max(ans, lf[i] + rg[i + 1]);
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 8184