akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#ifdef DEBUG
	#define freopen(...)
#endif

#define Min(_A, _B) (_A < _B ? _A : _B)
#define Max(_A, _B) (_A > _B ? _A : _B)

/*void Build_rmq(int p)
{
	for(int i = 1; i <= n; ++i) r[p][0][i] = b[i][p];
	for(int i = 1; 1 << i <= n; ++i)
		for(int j = 1; j + (1 << i) <= n; ++j)
			r[p][i] = Max(r[p][i - 1][j], r[p][i - 1][j + (1 << i)]);
}
void Merge()
{
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			
}
int RMQ(int Ls, int Rs, int p)
{
	int len = Log[Rs - Ls + 1];
	int t1 = r[p][len][Ls], t2 = r[p][len][Rs - (1 << len) + 1];
	return Max(t1, t2);
}*/
long long ans;
int a[100010], d[100010], n, m;
bool vis[100010];
std::vector<int> b[100010];
namespace bf
{
	void main()
	{
		for(int i = 1; i <= n; ++i)
		{
			long long tmp = 0;
			int cnt = m;
			for(int j = 0; j < m; ++j) 
			{
				tmp += b[i][j];
				d[j] = b[i][j];
				vis[j] = 1;
			}
			ans = Max(tmp, ans);
			for(int j = i + 1; j <= n; ++j)
			{
				for(int k = 0; k < m; ++k) if(b[j][k] > d[k])
				{
					cnt -= vis[k];
					vis[k] = 0;
					tmp += b[j][k] - d[k];
					d[k] = b[j][k];
				}
				tmp -= a[j - 1];
				ans = Max(tmp, ans);
				if(!cnt) break;
			}
		}
		printf("%lld\n", ans);		
	}
}
/*namespace test
{
	long long calc(int lim)
	{
		long long ans = 0;
		for(int i = 1; i <= n; ++i) 
		for(int i = 1; i <= n; ++i)
		{
			long long tmp = 0;
			int cnt = m;
			for(int j = 0; j < m; ++j) 
			{
				tmp += b[i][j];
				d[j] = b[i][j];
				vis[j] = 1;
			}
			ans = Max(tmp, ans);
			for(int j = i + 1, lim = Min(i + 80, n); j <= lim; ++j)
			{
				for(int k = 0; k < m; ++k) if(b[j][k] > d[k])
				{
					cnt -= vis[k];
					vis[k] = 0;
					tmp += b[j][k] - d[k];
					d[k] = b[j][k];
				}
				tmp -= a[j - 1];
				ans = Max(tmp, ans);
			//	if(!cnt) break;
			}
		}
		printf("%lld\n", ans);		
	}
}*/
int main()
{
	//freopen("restaurants.in", "r", stdin);
	//freopen("restaurants.out", "w", stdout);
	
	scanf("%d %d", &n, &m);
	for(int i = 1; i < n; ++i) scanf("%d", &a[i]);
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
		{
			int t; scanf("%d", &t);
			b[i].push_back(t);
		}
	//if(1ll * n * n * m <= 2e8) 
	bf::main();
	//else test::main();
	return 0;
}

Measured memory_bytes: 9728
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

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

    int n,k;
	double ans=0;
	cin >> n;
	ll A[n];
	rep(i,n){
		cin >> A[i];
		ans += (double)1/A[i];
	}

	ans = (double)1/ans;

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
#include <omp.h>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;

const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 
//const long long int pl=1000000;

long long int N,K,s[200200],t[200200],x[200200];
int main(){
    cout << fixed << setprecision(18);
    cin>>N>>K;
    IFYES(N%2==0&&N>=K*2||N%2==1&&N+1>=K*2);
}



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

int main() {
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    int max1;
    max1 = max(abs(a1-a2), max(abs(a2-a3), abs(a3-a1)));
    int sum = 0;
    sum = sum+abs(a1-a2)+abs(a2-a3)+abs(a3-a1)-max1;
    cout << sum << endl;
}

Measured memory_bytes: 256
/* In the name of Anton */

/*
* Motto :)
*
*
*
*
*
*/

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,a,n) for(int i=a;i<=n;i++)
#define repb(i,a,n) for(int i=a;i>=n;i--)
#define trav(x,a) for(auto &x: a)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
#define fst first
#define snd second
#define pb push_back
#define mp make_pair
#define vt vector
typedef long double ld;
typedef pair <int,int> pii;
typedef vector <int> vi;
typedef long long ll;

template<class A> void read(vt<A>& v);
template<class T> void read(T& x){
  cin>>x;
}

void read(double &d){
  string t;
  read(t);
  d=stod(t);
}
void read(long double &d){
  string t;
  read(t);
  d=stold(t);
}

template<class H, class... T> void read(H &h, T&...t){
  read(h);
  read(t...);
}

template <class A> void read(vt<A> &x){
  trav(a,x)
    read(a);
}

string to_string(char c){
  return string(1,c);
}

string to_string(bool b){
  return b?"true":"false";
}

string to_string(const char* s){
  return string(s);
}

string to_string(string s){
  return string(s);
}

string to_string(vt<bool> v){
  string res;
  rep(i,sz(v)){
    res+=char('0'+v[i]);
  }
  return res;
}

template<class T> string to_string(T v){
  bool f=1;
  string res;
  trav(x,v){
    if(!f)
      res+=' ';
    f=0;
    res+=to_string(x);
  }
  return res;
}

template<class A> void write(A x){
  cout<<to_string(x);
}

template<class H, class...T> void write(const H& h, const T&...t){
  write(h);
  write(t...);
}

void print(){
  write("\n");
}

template<class H, class...T> void print(const H& h, const T&...t){
  write(h);
  if(sizeof...(t))
    write(' ');
  print(t...);
}

/* -----------------------------------------------------------------------------------------------*/

const int mxN=1e5+5;
bool visited[mxN];
vi adj[mxN];

void pre(){

}

void dfs(int v){
  visited[v]=true;

  for(auto x: adj[v]){
    if(!visited[x]){
      dfs(x);
    }
  }
}

void solve(){
  int n,m; read(n,m);

  rep(i,m){
    int x,y; read(x,y);
    x--; y--;

    adj[x].pb(y);
    adj[y].pb(x);
  }

  int ans=0;
  memset(visited,false,sizeof(visited));

  for(int i=0;i<n;i++){
    if(!visited[i]){
      ans++;
      dfs(i);
    }
  }

  print(ans-1);
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  pre();
  int t=1;
  // read(t);
  rep(i,t) solve();
  return 0;
}


Measured memory_bytes: 9780
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
#define inf 1000000000
typedef long long ll;

int main(){
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> vec;
  rep(i, m){
    int a, b;
    cin >> a >> b;
    vec.push_back(make_pair(a, b));
  }
  int cnt = 0;
  rep(k, m){
    vector<int> dest(n, inf);
  	dest[0] = 0;
    rep(i, n){
      rep(j, m){
        if(j == k) continue;
        if(dest[vec[j].first] + 1 < dest[vec[j].second]) dest[vec[j].second] = dest[vec[j].first] + 1;
        if(dest[vec[j].second] + 1 < dest[vec[j].first]) dest[vec[j].first] = dest[vec[j].second] + 1;
      }
    }
    bool reachable = true;
  	rep(i, n){
   	  if(dest[i] == inf) reachable = false;
  	}
    if(!reachable) cnt++;
  }
  cout << cnt << endl;
  return 0;
}
        
      
      
      
      
      
      
      
  

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

int main(){
  int N;
  cin >> N;
  
  double total = 0; 
  for(int i = 0; i < N; i++){
    double x;
    cin >> x;
    string u;
    cin >> u;
    if(u=="BTC"){
      total += 380000.0 * x;
    }else{
      total += x;
    }
  }

  cout << fixed << setprecision(10) << total << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

string s;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> s;
  int l = 0, r = s.size() - 1, ans = 0;
  while (l < r) {
    if (s[l] == 'x') {
      if (s[r] == 'x') {
        l++; r--;
      } else {
        l++; ans++;
      }
    } else {
      if (s[r] == 'x') {
        r--; ans++;
      } else if (s[l] == s[r]) {
        l++; r--;
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  }  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512
N = int(input())
H = list(map(int, input().split()))
count = True
m = 0
for i in range(N):
    if H[i] > m:
        m = H[i]-1
    elif H[i] == m:
        continue
    else:
        count = False
        break

print("Yes" if count else "No")

Measured memory_bytes: 14252
#include <bits/stdc++.h>
typedef long long Long;

#define MAX 100001

#define PB push_back
#define MP make_pair
#define FF first
#define SS second

#define PII pair<int, int>
#define VI vector<int>

#define FOR(a, n) for(int i=a;i<n;i++)
#define FORn(a, n) for(int i=a;i<=n;i++)

#define mm(a, n) memset(a, n, sizeof(a))

#define PF printf
#define PC putchar
#define GC getchar

#define printCase cout<<"Case "<<i<<": "vagfol
#define printCaseC PF("Case %d: ", i)

#define II() ({int a; scanf("%d", &a); a;})
#define LI() ({Long a; scanf("%I64d", &a); a;})
#define DI() ({double a; scanf("%lf", &a); a;})

#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
//double pi=atan(1)*4;

using namespace std;

void solve()
{
    string s;
    cin>>s;
    int cnt=0;
    for(int l=s.size(), i=l/2-1, j=(l%2?l/2+1:l/2); i>=0; i--, j++)
        if(s[j]!=s[i])
            cnt++;
    cout<<cnt<<endl;
}
int main()
{
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #else
//    #endif
    /* *******Bismillahir Rahmanir Rahim **** */
//    FastIO;
    int t=1;
//    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
N = input()
N = int(N)

H = []
H = input().split()
H = [int(n) for n in H]

step = []
maxi = H[0]
count = 0

for i in range(N-1) :
  if maxi >= H[i+1] :
    count = count + 1
    maxi = H[i+1]
  if maxi < H[i+1] :
    step.append(count)
    maxi = H[i+1]
    count = 0
step.append(count)

#print(N)
#print(H)
#print(count)
#print(step)
print(max(step))



Measured memory_bytes: 14224
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    int a, b;

    cin >> n >> a >> b;

    cout << min(a, b) << ' ' << ((a + b) - n < 0 ? 0 : (a + b) - n) << endl;
    return 0;
}


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

int main(void) {
    int n;
    cin >> n;
    
    int howmmany_arrived[n];
    int arrived_order[n];
    
    for (int i = 0; i < n; i++) {
        cin >> howmmany_arrived[i];
    }
    
    for (int k = 0; k < n; k++) {
        arrived_order[howmmany_arrived[k] - 1] = k + 1;
    }
    
    for (int l = 0; l < n; l++) {
        cout << arrived_order[l];
        if (l != n - 1) {
            cout << " ";
        }
    }
    
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
	
	ll n;
	cin>>n;
	ll ar[n];
	for(int i=0;i<n;i++){
		cin>>ar[i];
	}		
	ll ans = 0;
	for(int i=1;i<n;i++){
		if(ar[i-1]>ar[i]){
			ans += (ar[i-1]-ar[i]); 
			ar[i] = ar[i-1];
		}
	}
	cout<<ans;
				
	return 0;
}

Measured memory_bytes: 5192
using System;
using System.Collections.Generic;
using static System.Console;

class Program {
    static void Main() {
        var cnt = 0;
        var cntS = 0;
        var X = NextString();

        foreach (var v in X) {
            switch (v) {
                case 'S':
                    cntS++;
                    break;
                case 'T':
                    if (cntS == 0) { cnt++; }
                    cntS = Math.Max(0, cntS - 1);
                    break;
            }
        }
        WriteLine(cnt + cntS);
    }

    static string NextString() {
        var result = new List<char>();
        while (true) {
            int next = Read();
            if (next < 0)
                break;
            var nextChar = (char)next;
            if (!char.IsWhiteSpace(nextChar))
                result.Add(nextChar);
            else if (nextChar != '\r')
                break;
        }
        return string.Join("", result);
    }
}

Measured memory_bytes: 16988
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	private final static long MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[3];
		int[] b = new int[3];
		sc.fill(a, b);

		int[] count = new int[4];
		for (int i = 0; i < 3; i++) {
			count[a[i] - 1]++;
			count[b[i] - 1]++;
		}

		Arrays.sort(count);
		debug(count);

		if (count[0] == 1 && count[1] == 1 && count[2] == 2 && count[3] == 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;
		private StringBuilder buffer = new StringBuilder();

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			int read = skip();
			do {
				buffer.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			String text = buffer.toString();
			buffer.delete(0, buffer.length());

			return text;
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 21204
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), a[] = new int[n];
		for(int i = 0; i < n; ++i)a[i] = sc.nextInt();
		sc.close();
		int alice = 0, bob = 0, ans = 0;
		Arrays.sort(a);
		for(int i = n - 1; i >= 0; --i) {
			if(i % 2 == (n - 1) % 2) alice += a[i];
			else bob += a[i];
		}
		ans = alice - bob;
		System.out.println(ans);
	}

}


Measured memory_bytes: 22868
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(b-a==c-b) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int a[3];
    for(int i=0;i<3;i++){
    	cin >> a[i];
    }
    sort(a,a+3);
    int ans = 0;
    if((a[2] - a[1]) & 1){
    	ans += (a[2] - a[1]) / 2;
    	a[1] = a[2] - 1;
    }else{
    	ans += (a[2] - a[1]) / 2;
    	a[1] = a[2];
    }
    if((a[2] - a[0]) & 1){
    	ans += (a[2] - a[0]) / 2;
    	a[0] = a[2] - 1;
    }else{
    	ans += (a[2] - a[0]) / 2;
    	a[0] = a[2];
    }
    sort(a, a+3);
    if(a[1] < a[2]){
    	ans++;
    }else{
    	if(a[0] < a[1]){
    		ans += 2;
    	}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5;
long long dp[N];
int w[N],v[N];
int main(){
    long long n,W,sum=0;
    scanf("%lld %lld",&n,&W);
    for(int i=1;i<=n;i++){
        scanf("%d %d",&w[i],&v[i]);
        sum+=v[i];
    }
    for(int i=1;i<=sum;i++) dp[i] = 1e18;
    for(int i=1;i<=n;i++)
        for(int j=sum;j>=v[i];j--)
            dp[j] = min(dp[j],dp[j-v[i]]+w[i]);
    for(int i=sum;i>=0;i--){
        if(dp[i]<=W){
            printf("%d\n",i);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
double max(double a, double b) {
	if (a > b)return a;
	else return b;
}
int main()
{
	int ans;
	double l, a, b, c, d,res;
	cin >> l>>a >> b >> c >> d;
	res=max(a / c, b / d);
	if (res != (int)res)ans=l-(int)(res + 1);
	else ans = l - res;
	cout << ans << endl;
    return 0;
}



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

ll n,k,a[5005],p[5005],rez;

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

    cin>>n>>k;
    for(ll i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);

    ll l=0,r=n-1;
    while(l<=r)
    {
        ll ind=(l+r)/2;
        ll x=a[ind];
        memset(p,0,sizeof(p));
        p[0]=1;
        ll poz=-1;
        for(ll i=0;i<n;i++)
            if(a[i]==x&&poz==-1)
                poz=i;

        for(ll i=0;i<n;i++)
        {
            if(i!=poz)
            {
                for(ll j=k-1;j>=0;j--)
                    if(p[j]&&j+a[i]<k)
                        p[j+a[i]]=1;
            }
        }
        ll indi=0;
        for(ll i=0;i<k;i++)
            if(p[i]&&(i+x>=k))
                indi=1;

        if(indi==1)
            r=ind-1;
        else
            l=ind+1;
        //cout<<l<<" "<<r<<endl;
    }

    cout<<r+1<<endl;

    return 0;
}


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

int main() {
	int N;
	cin >> N;
	int D, X;
	cin >> D >> X;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
		X += (D - 1) / A.at(i) + 1;

	}
	cout << X << endl;
}

Measured memory_bytes: 3632
x = int(input())
ans = int(x//5.5)
half = ans//2

y = 6*half+5*half
ans = 2*half
if x <= y:
    print(ans)
else:
    for i in range(3):
        if i % 2 == 0:
            y += 6
        else:
            y += 5
        ans += 1
        if x <= y:
            print(ans)
            break


Measured memory_bytes: 9120
import java.util.*;

public class Main {
    public static void main(String arg[]) {
        Scanner scan = new Scanner(System.in);
        String S = scan.next();
        String T = scan.next();
        int l = S.length();
        String ans = "Yes";
        int[] A_S = new int[26];
        int[] A_T = new int[26];

        for (int i = 0; i < 26; i++) {
            A_S[i] = -1;
            A_T[i] = -1;
        }

        for (int i = 0; i < l; i++) {
            if (A_S[(char)S.charAt(i) - 'a'] == -1) {
                A_S[(char)S.charAt(i) - 'a'] = (char)T.charAt(i) - 'a';
            }
            else if (A_S[(char)S.charAt(i) - 'a'] != (char)T.charAt(i) - 'a') {
                ans = "No";
                // System.out.println("S -> T");
                break;
            }
        }

        for (int i = 0; i < l; i++) {
            if (A_T[(char)T.charAt(i) - 'a'] == -1) {
                A_T[(char)T.charAt(i) - 'a'] = (char)S.charAt(i) - 'a';
            }
            else if (A_T[(char)T.charAt(i) - 'a'] != (char)S.charAt(i) - 'a') {
                ans = "No";
                // System.out.println("T -> S");
                break;
            }
        }

        System.out.println(ans);       
        scan.close();
    }
}

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

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

const ll INF = 1e18;
const ll MOD = 1e9+7;

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

ll modpow(ll a, ll n)
{
    ll res = 1;
    while(n > 0)
    {
        if(n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll m, n; cin >> m >> n;
    cout << modpow(m, n) % MOD << endl;
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const ll inf=1e9;
ll ans[505][505],A,B,sum;
int H,W,h,w;

int main(){
	read(H),read(W);
	read(h),read(w);
	if(h*w==1){
		puts("No");
		return 0;
	}
	A=(inf-1)/(h*w-1),B=-A*(h*w-1)-1;
	rep(i,1,H){
		rep(j,1,W){
			ans[i][j]=(i%h==0&&j%w==0?B:A);
			sum+=ans[i][j];
		}
	}
	if(sum<=0) puts("No");
	else{
		puts("Yes");
		rep(i,1,H){
			rep(j,1,W) printf("%lld ",ans[i][j]);
			puts("");
		}
	}
	return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

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

    int N;

    string S;
    std::cin >> S;

    N = S.size();
    
    int pa = N / 2;
    reverse(S.begin(), S.end());

    int pt = 0;
    for(const char& c : S){
        if(pa == 0){
            pt -= c == 'p';
        }else{
            pt += c == 'g';
            --pa;
        }
    }

    std::cout << pt << std::endl;
}


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

int main(void) {
  int A, B;
  cin >> A >> B;
  
  if(A>=13)
    cout << B << endl;
  else if(A>=6)
    cout << B/2 << endl;
  else
    cout << 0 << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
char s[10007][12];
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;cin>>n;
    for(int i=1;i<=n;i++) cin>>s[i]+1;
    int ans=0,a=0,b=0,ab=0;
    for(int i=1;i<=n;i++){
        int len=strlen(s[i]+1);
        for(int k=1;k<len;k++){
            if(s[i][k]=='A'&&s[i][k+1]=='B') ans++;
        }
        if(s[i][len]=='A'&&s[i][1]!='B') a++;
        if(s[i][1]=='B'&&s[i][len]!='A') b++;
        if(s[i][len]=='A'&&s[i][1]=='B') ab++;
    }
    if(ab){
        ans+=ab-1;
        if(b) b--,ans++;
        if(a) a--,ans++;
        ans+=min(a,b);
    }
    else ans+=min(a,b);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
#define 	pi 				3.14159265358979
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define     inf             2e18
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define     sz              size()
#define     len             length()
#define 	F 				first
#define 	S 				second
#define 	PB 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define     RB              rbegin()
#define 	E 				end()
#define     UB              upper_bound
#define     LB              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define     pll             pair<ll, ll>
#define     vll             vector<ll>
#define     vpll            vector<pll>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define     sqr(a)          ((a)*(a))
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }

bool compare_float(double x, double y){
    return fabs(x - y) < DBL_EPSILON;
}

double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
vll pwx(32);
void cal(ll x){ pwx[0] = 1; rep(i, 1, 32)pwx[i] = x*pwx[i-1]; }
 
/* ################################################################ */

#define space 200005

void solve()
{
    ll a, tmpb = 0, base = 100;
    string b;
    cin>>a>>b;
    for(auto i : b){
        if(i != '.'){
            tmpb += (i-'0')*base;
            base /= 10;
        }
    }
    ll ans = a*tmpb;
    cout<<ans/100<<nl;
} 
 
int main(){
    // boost;
    // cal(2);
    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}

Measured memory_bytes: 3632
//Vinay
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define flash ios::sync_with_stdio(false);cin.tie(0);
//const int INF = 1e9+7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if(n == 0){
        cout <<"1" << endl;
    } 
    else
    cout << "0" << endl;
}


Measured memory_bytes: 3552
#include <iostream>
#include <iomanip>

using namespace std;

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

    int cnt = 0;
    if (n % 2){ //n是奇数
        cnt = n / 2 + 1;
        cout << fixed << setprecision(10) << static_cast<double>(cnt) / n << endl; 
    }
    else{
        cout << fixed << setprecision(10) << static_cast<double>(1) / 2 << endl; 
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }

}

class Program
{
    static List<int>[] v;
    static bool[] visited;

    static void dfs(int[] lens, int n, int x)
    {
	lens[n] = x;
	visited[n] = true;
	foreach (int m in v[n])
	{
	    if (!visited[m]) dfs(lens, m, x+1);
	}
    }
    
    public static void Main()
    {
	int n = int.Parse(ReadLine());

	v = new List<int>[n];
	for (int i = 0; i < n; i++)
	    v[i] = new List<int>();
	
	for (int i = 0; i < n-1; i++)
	{
	    var tmp = ReadIntArray();
	    int a = tmp[0] - 1, b = tmp[1] - 1;
	    v[a].Add(b); v[b].Add(a);
	}

	var flens = new int[n];
	var slens = new int[n];

	visited = new bool[n];
	dfs(flens, 0, 0);

	Array.Clear(visited, 0, visited.Length);
	dfs(slens, n-1, 0);

	int fmax=0, smax=0; // f: Fennec, s: Snuke

	for (int i = 1; i < n-1; i++)
	    if (flens[i] <= slens[i]) fmax++;
	    else		      smax++;

	WriteLine(fmax > smax ? "Fennec" : "Snuke");
    }
}


Measured memory_bytes: 40192
#include <iostream>
#include <vector>
using namespace std;
struct P{
  int x,y;
};

int main(){
  P p;
  int x,y;
  int n,m;
  vector<P> v;
  char c;
  int l;
  int dx,dy;
  while( cin>>n && n ){
    v.clear();
    for( int i=0;i<n;i++ ){
      cin >> p.x >> p.y;
      v.push_back( p );
    }
    x=10;
    y=10;
    cin >> m;
    for( int i=0;i<m;i++ ){
      cin >> c >> l;
      dx=0; dy=0;
      switch(c){
      case 'N': dy=1;  break;
      case 'E': dx=1;  break;
      case 'S': dy=-1; break;
      case 'W': dx=-1; break;
      }

      for( int k=0;k<l;k++ ){
	x+=dx; y+=dy;
	for( unsigned int j=0;j<v.size();j++ ){
	  if( v[j].x==x && v[j].y==y ){
	    v.erase( v.begin()+j );
	    break;
	  }
	}
      }
    }
    if( v.size() )
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

const int N = 1e5 + 10;
const int K = 20;
vector<int> a[N];
int dep[N], f[K][N];
bool leaf[N];

void DFS(int u, int parent) {
  f[0][u] = parent;
  for (int k = 1; k < K; ++k) {
    int v = f[k - 1][u];
    f[k][u] = v < 0 ? -1 : f[k - 1][v];
  }
  dep[u] = parent < 0 ? 0 : dep[parent] + 1;
  for (auto& v : a[u]) {
    if (v == parent) continue;
    leaf[u] = false;
    DFS(v, u);
  }
}

int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int k = 0, delta = dep[x] - dep[y]; k < K; ++k) {
    if (delta & (1 << k)) x = f[k][x];
  }
  for (int k = K - 1; k >= 0; --k) {
    if (f[k][x] != f[k][y]) {
      x = f[k][x];
      y = f[k][y];
    }
  }
  return x == y ? x : f[0][x];
}

int main() {
  int n, u, v;
  scanf("%d%d%d", &n, &u, &v);
  --u; --v;
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    a[x].push_back(y);
    a[y].push_back(x);
  }

  fill(leaf, leaf + n, true);
  DFS(v, -1);

  int best = 0;
  for (int i = 0; i < n; ++i) {
    if (!leaf[i]) continue;
    int lca = LCA(i, u);
    if (dep[lca] <= dep[u] - dep[lca]) {
      best = max(best, dep[u] / 2);
      continue;
    }
    best = max(best, dep[i] - 1);
  }
  printf("%d\n", best);

  return 0;
}


Measured memory_bytes: 17920
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n;
cin >> n;
set<int> s;
int i=1;
s.insert(n);
while(1) {
  if(n%2==0) {
    n /= 2;
  } else {
    n = 3*n+1;
  }
  i++;
  s.insert(n);
  if(s.size()!=i) break;
}
cout << i << endl;
return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int[] a = new int[3];
		for (int i = 0; i < 3; i++) {
			a[i] = stdIn.nextInt();
		}
		
		Arrays.sort(a);
		
		System.out.println(a[0] + " " + a[1] + " " + a[2]);
		
	}
}



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

const int len = 2e5+5;
int arr[len];

int main(){
    int n, t, ans = 0, cur = 0;
    scanf("%d %d", &n, &t);
    for (int i = 0; i < n; i++)
        scanf("%d", &arr[i]);

    while (cur < n){
        int r = arr[cur]+t, j = cur;
        while (j < n && arr[j] <= r){
            r = arr[j]+t;
            j++;
        }
        ans += arr[j-1]+t-arr[cur];
        cur = j;
    }

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0096
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                string line = ReadSt();
                if (line == null) break;

                int n = int.Parse(line);
                int cnt = 0;
                int repEnd = Math.Min(1000, n);

                n = n < 2000 ? n : 4000 - n;
                for (int i = 0 ; i <= repEnd ; i++)
                {
                    for (int j = 0 ; j <= repEnd ; j++)
                    {
                        if (n - (i + j) >= 0 && n - (i + j) <= 2000)
                        {
                            if (n - (i + j) <= 1000) cnt += n - (i + j) + 1;
                            else cnt += 2000 - (n - (i + j)) + 1;
                        }
                    }
                }
                Console.WriteLine(cnt);
            }
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 17992
#include <cstdlib>
#include <iterator>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <functional>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a <= b ? a : a - 1) << endl;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-12;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
//AGCばちゃ 1700~
/*
010
101
010
*/
int main(void){
	llint n,i,j,ans=0;
	string X;
	cin>>n>>X;
	static llint dp[200001]={};
	for(i=n+n%2-1;i>=1;i-=2){
		//分割
		if(n%i!=0){continue;}
		llint m=n/i;
		//ひっくり返し成功判定
		bool can=true;
		for(j=0;j<n;j++){
			int aaa=X[j%m]-'0';
			if((j/m)%2==1){aaa=1-aaa;}
			if(X[j]=='0'&&aaa==1){can=false;break;}
			if(X[j]=='1'&&aaa==0){can= true;break;}
		}
		llint kaz=0;
		for(j=0;j<m;j++){
			kaz*=2;
			if(X[j]=='1'){kaz++;}
			kaz%=mod;
		}
		if(can){kaz++;}
		
		
		for(j=i*2;j<=n;j+=i){kaz-=dp[j];}
		kaz%=mod;kaz+=mod;kaz%=mod;
		//cerr<<"kaz="<<kaz<<endl;
		dp[i]=kaz;
		ans+=kaz*m*2;
		ans%=mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 832
n = int(input())
x = [0]*n
count = 0
a = list(map(int,input().split()))
for ai in a:
  if ai > n:
    count += 1
  else:
    x[ai-1] += 1
for i in range(n):
  if x[i] >=  i+1:
    count += x[i]-i-1
  else:
    count += x[i]
print(count)
    

Measured memory_bytes: 64752
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;


int main()
{
	char* type[] = { "A", "B", "AB", "O" };
	int count[4];
	memset(count, 0, sizeof(count));
	int n;
	char buf[128];
	while (scanf("%d,%s\n", &n, buf) != EOF)
	{
		for (int i = 0; i < 4; ++i)
		{
			if (strcmp(buf, type[i]) == 0)
			{
				++count[i];
				break;
			}
		}
	}
	for (int i = 0; i < 4; ++i)
		printf("%d\n", count[i]);

	return 0;
}

Measured memory_bytes: 0
import Data.Monoid
import Data.Maybe
import qualified Data.ByteString.Char8 as B
import qualified Data.Set as S

readInt :: B.ByteString -> Int
readInt = maybe undefined fst . B.readInt

readInts :: B.ByteString -> [Int]
readInts = map readInt . B.words

main = do
  n <- readLn :: IO Int
  ps <- readInts <$> B.getLine
  putStrLn $ unwords $ map show (maids n ps)

maids n ps = go n treeEven treeOdd q
  where
    q = S.singleton (val treeEven, (1, n), False)
    treeEven = fromList n $ zipWith (\i p -> V p i) [1..] $ zipWith ($) (cycle [id, const maxBound]) ps
    treeOdd  = fromList n $ zipWith (\i p -> V p i) [1..] $ zipWith ($) (cycle [const maxBound, id]) ps

go n treeEven treeOdd q
  | S.null q = []
  | otherwise = pemin : pomin : go n treeEven treeOdd q2
  where
    ((V pemin i, (si,sj), flag), q1) = S.deleteFindMin q
    (V pomin j) = query n (if flag then treeEven else treeOdd) (i+1) sj
    seg1 = if si == i then Nothing else Just (query n (if not flag then treeEven else treeOdd) si (i-1), (si, i-1), flag)
    seg2 = if succ i == j then Nothing else
             Just (query n (if flag then treeEven else treeOdd) (i+1) (j-1), (i+1, j-1), not flag)
    seg3 = if j == sj then Nothing else Just (query n (if not flag then treeEven else treeOdd) (j+1) sj, (j+1, sj), flag)
    q2 = foldr S.insert q1 (catMaybes [seg1, seg2, seg3])

data V = V !Int !Index deriving (Eq, Ord, Show)

instance Monoid V where
  mempty = V maxBound undefined
  mappend v1@(V p1 _) v2@(V p2 _) = if p1 < p2 then v1 else v2

data SegTree m =
  Leaf !m |
  Node !m !(SegTree m) !(SegTree m)
  deriving (Eq, Show)

type Index = Int
type Size = Int

val :: Monoid m => SegTree m -> m
val (Leaf v) = v
val (Node v _ _) = v

fromList :: Monoid m => Size -> [m] -> SegTree m
fromList 1 [x] = Leaf x
fromList n xs = Node (val left <> val right) left right
  where
    m = div n 2
    (xs1, xs2) = splitAt m xs
    left = fromList m xs1
    right = fromList (n - m) xs2

query :: Monoid m => Size -> SegTree m -> Index -> Index -> m
query 1 (Leaf v) 1 1 = v
query _ (Leaf _) _ _ = undefined
query n (Node v l r) i j
  | (i, j) == (1, n) = v
  | j <= m = query m l i j
  | i > m = query (n - m) r (i - m) (j - m)
  | otherwise = query m l i m <> query (n - m) r 1 (j - m)
  where
    m = div n 2


Measured memory_bytes: 94844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5+1;

int n,a,b,q[N];

int main(){
	cin>>n>>a>>b;
	for(int i=1;i<=n;++i)q[i]=i;
	if((n+a-1)/a>b||a+b-n>1)return 0*printf("-1\n");
	if(a==1){
		for(int i=n;i>=1;--i)printf("%d ",i);
		return 0;
	}
	int duan=(n-b)/(a-1);
	int res=(n-b)%(a-1);
	reverse(q+1,q+b+1);
	int l=b+1;
	for(int i=2;i<=a;++i){
		if(res)reverse(q+l,q+l+duan+1),res--,l=l+duan+1;
		else reverse(q+l,q+l+duan),l=l+duan;
	}
	for(int i=1;i<=n;++i)printf("%d ",q[i]);
}

Measured memory_bytes: 3328
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.nextLine());
		String[] tokens = in.nextLine().split(" ");
		in.close();
		List<Integer> v = new ArrayList<>(n);
		for (int i = 0; i < n; ++i) {
			v.add(Integer.parseInt(tokens[i]));
		}
		Map<Integer, Integer> oddCount = count(v, false);
		Map<Integer, Integer> evenCount = count(v, true);
		int oddSelect = getMaxCountKey(oddCount);
		int evenSelect = getMaxCountKey(evenCount);
		if (oddSelect != evenSelect) {
			int result = getChangeCount(oddCount, oddSelect) + getChangeCount(evenCount, evenSelect);
			System.out.println(result);
		} else {
			int oddNum = oddCount.get(oddSelect);
			int evenNum = evenCount.get(evenSelect);
			// odd側に合わせる -> even側を変更する
			int evenSelect1 = getSecondCountKey(evenCount, evenSelect);
			int evenNum1 = getChangeCount(evenCount, evenSelect1);
			int oddNum1 = getChangeCount(oddCount, oddSelect);
			// even側に合わせる -> odd側を変更する
			int oddSelect2 = getSecondCountKey(oddCount, oddSelect);
			int oddNum2 = getChangeCount(oddCount, oddSelect2);
			int evenNum2 = getChangeCount(evenCount, evenSelect);
			int result = Math.min(oddNum1 + evenNum1, oddNum2 + evenNum2);
			System.out.println(result);
		}
	}

	private static int getChangeCount(Map<Integer, Integer> count, int select) {
		int result = 0;
		for (Integer key : count.keySet()) {
			if (key != select) {
				result += count.get(key);
			}
		}
		return result;
	}

	private static int getSecondCountKey(Map<Integer, Integer> count, int maxKey) {
		int result = -1;
		int index = -1;
		for (Integer key : count.keySet()) {
			if (key != maxKey) {
				if (result < count.get(key)) {
					result = count.get(key);
					index = key;
				}
			}
		}
		return index;
	}

	private static int getMaxCountKey(Map<Integer, Integer> count) {
		int result = -1;
		int index = -1;
		for (Integer key : count.keySet()) {
			if (result < count.get(key)) {
				result = count.get(key);
				index = key;
			}
		}
		return index;
	}

	private static Map<Integer, Integer> count(List<Integer> v, boolean isEven) {
		Map<Integer, Integer> result = new HashMap<>();
		if (!isEven) {
			// oddパターンをカウント
			for (int i = 0; i < v.size(); i = i + 2) {
				int num = v.get(i);
				if (!result.containsKey(num)) {
					result.put(num, 1);
				} else {
					int count = result.get(num);
					result.put(num, count + 1);
				}
			}
		} else {
			// evenパターンをカウント
			for (int i = 1; i < v.size(); i = i + 2) {
				int num = v.get(i);
				if (!result.containsKey(num)) {
					result.put(num, 1);
				} else {
					result.put(num, result.get(num) + 1);
				}
			}
		}
		return result;
	}
}

Measured memory_bytes: 50724
/*THERE'S ALWAYS SOMETHING , NOT THAT YOU WOULD UNDERSTAND . YOU ARE LIKE MY SISTER ,
 EVERYTHING ALWAYS CAME EASY TO HER .
 SHE'S A FIRE BENDING PRODIGY AND EVERY ONE ADORE HER . MY FATHER SAYS
 SHE WAS BORN LUCKY ,HE SAYS I WAS LUCKY TO BE BORN . I DON'T NEED LUCK THOUGH .
 I DON'T WANT IT . I'VE ALWAYS HAD TO STRUGGLE AND FIGHT
 AND THAT'S MADE ME STRONG . IT MADE ME WHO I AM .*/
#include<bits/stdc++.h>
using namespace std;
string solve(vector<int>& v,int k)
{
    bool dp[k+1];
    memset(dp,0,sizeof dp);
    for(int i=1;i<=k;i++)
    {
        for(int move:v)
        {
            if(move>i)continue;
            if(dp[i-move]==0)
                dp[i]=1;
        }
    }
    return dp[k]?"First":"Second";
}
main()
{
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    cout<<solve(v,k);
}
/* WHATEVER DOESNT KILL ME ONLY MAKES ME STRONGER .*/


Measured memory_bytes: 3700
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>

using namespace std;

#define mod 1000000007

int main()
{
    char c;
    cin >> c;
    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') cout << "vowel" << endl;
    else cout << "consonant" << endl;
}

Measured memory_bytes: 256