akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		String t = scan.next();
		StringIndex si = new StringIndex(t, false);

		int q = scan.nextInt();
		for (int i = 0; i < q; i++)
			if (si.isExist(scan.next(), t))
				System.out.println("1");
			else
				System.out.println("0");

		scan.close();
		System.exit(0);
	}
}

class StringIndex {
	class StIdx {
		int pos;
		char ch;

		public StIdx(int i, char c) {
			pos = i;
			ch = c;
		}
	}

	List<StIdx> idx = new ArrayList<StIdx>();
	int[] seq;
	int compLen = 1;

	class strIndexComp implements Comparator<StIdx> {

		@Override
		public int compare(StIdx o1, StIdx o2) {
			return idxComp(o1, o2);
		}
	}

	private int idxComp(StIdx o1, StIdx o2) {
		if (compLen == 1)
			if (o1.ch > o2.ch)
				return 1;
			else if (o1.ch == o2.ch)
				return 0;
			else
				return -1;

		if (seq[o1.pos] > seq[o2.pos])
			return 1;
		if (seq[o1.pos] == seq[o2.pos]) {
			int npos1 = o1.pos + compLen / 2;
			int npos2 = o2.pos + compLen / 2;
			int nseq1 = 0, nseq2 = 0;
			if (npos1 < seq.length)
				nseq1 = seq[npos1];
			if (npos2 < seq.length)
				nseq2 = seq[npos2];
			if (nseq1 > nseq2)
				return 1;
			else if (nseq1 == nseq2)
				return 0;
			else
				return -1;
		}
		return -1;
	}

	boolean debug;

	public StringIndex(String t, boolean d) {
		debug = d;

		seq = new int[t.length()];
		for (int i = 0; i < t.length(); i++)
			idx.add(new StIdx(i, t.charAt(i)));

		for (compLen = 1; compLen < idx.size() * 2; compLen *= 2) {
			Collections.sort(idx, new strIndexComp());

			int[] tmp = new int[seq.length];

			tmp[idx.get(0).pos] = 1;
			for (int i = 1; i < tmp.length; i++)
				if (idxComp(idx.get(i - 1), idx.get(i)) == 0)
					tmp[idx.get(i).pos] = tmp[idx.get(i - 1).pos];
				else
					tmp[idx.get(i).pos] = tmp[idx.get(i - 1).pos] + 1;

			for (int i = 0; i < seq.length; i++)
				seq[i] = tmp[i];

			if (debug) {
				System.out.println("--------------------");
				for (int i = 0; i < idx.size(); i++)
					System.out.println(i + "\t" + seq[idx.get(i).pos] + "\t" + idx.get(i).pos + "\t"
							+ t.substring(idx.get(i).pos));
			}
		}

	}

	public boolean isExist(String p, String t) {
		int low = 0, hi = idx.size() - 1;
		return (findBin(p, t, low, hi));
	}

	private boolean findBin(String p, String t, int low, int hi) {
		if (low > hi)
			return false;
		int i = low + (hi - low) / 2;
		int len = p.length();
		if (len > t.length() - idx.get(i).pos)
			len = t.length() - idx.get(i).pos;

		int r = p.substring(0, len).compareTo(t.substring(idx.get(i).pos, idx.get(i).pos + len));
		if (r == 0)
			if (len == p.length())
				return true;
			else
				return findBin(p, t, i + 1, hi);
		else if (r < 0)
			return findBin(p, t, low, i - 1);
		else
			return findBin(p, t, i + 1, hi);
	}
}

Measured memory_bytes: 222748
#include<bits/stdc++.h>
using namespace std;
int main(){
   int N,K,count = 0;
   cin >> N >> K;
   vector<int> height(N);
   for(int i = 0;i < N; i++){
       cin >> height.at(i);
   } 
   sort(height.begin(),height.end());
   for(int i = height.size() - 1; i > -1; i--){
       if(height[i] >= K)
       count++;
       if(height[i] < K)
       break;
   }
   cout << count << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007

int main(){
	long int x;
	scanf("%ld", &x);
	long int point=0;
	long int count=0;
	count = x/11;
	point = count*11;
	count = count*2;
	while(point < x){
		if(count%2 == 0){
			point += 6;
			count++;
		}
		else{
			point += 5;
			count++;
		}
	}

	printf("%ld\n", count);
	
	return 0;
}

Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskB {
        static final int INF = (int) 1e9;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String[] g = new String[n];
            for (int i = 0; i < n; ++i) g[i] = in.next();
            int[] mark = new int[n];
            if (!dfs1(mark, 0, 1, n, g)) {
                out.println(-1);
                return;
            }
            int[][] d = new int[n][n];
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    d[i][j] = g[i].charAt(j) == '1' ? 1 : INF;
                }
                d[i][i] = 0;
            }
            for (int k = 0; k < n; ++k) {
                for (int i = 0; i < n; ++i) {
                    for (int j = 0; j < n; ++j) {
                        d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);
                    }
                }
            }
            int res = 1;
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    res = Math.max(res, 1 + d[i][j]);
                }
            }
            out.println(res);
        }

        private boolean dfs1(int[] mark, int at, int color, int n, String[] g) {
            if (mark[at] != 0) {
                if (mark[at] != color)
                    return false;
                return true;
            }
            mark[at] = color;
            for (int i = 0; i < n; ++i)
                if (g[at].charAt(i) == '1') {
                    if (!dfs1(mark, i, 3 - color, n, g)) return false;
                }
            return true;
        }

    }

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

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

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

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

    }
}



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

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

int n,m;
int k[20],s[20][20],p[20];
ll ans;


void input(){
	cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>k[i];
        for(int j=0;j<k[i];j++){
            cin>>s[i][j];
        }
    }
    for(int i=0;i<m;i++){
        cin>>p[i];
    }
	return;
}

void solve(){
	for(int i=0;i<(1<<n);i++){
        int sum=0;
        for(int j=0;j<m;j++){
            int ss=0;
            for(int l=0;l<k[j];l++){
                if(i&(1<<(s[j][l]-1)))ss++;
            }
            if(ss%2==p[j])sum++;
        }
        if(sum==m)ans++;
    }
    cout<<ans<<endl;
	return;
}

int main(){
	input();
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    string w;
    cin >> w;
    int i;
    int alp[26];
    for(i=0;i<26;i++){
      alp[i]=0;
    }
    for(i=0;i<w.size();i++){
      alp[w[i]-97]++;
    }
    for(i=0;i<26;i++){
      if(alp[i]%2!=0){
          cout <<"No";
          return 0;
      }
    }
    cout <<"Yes";
    return 0;
}


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

int main(){
  int n, x, y;
  cin >> n >> x >> y;
  unordered_map<int, int> map;
  for(int i = 1; i < n; i++){
    for(int j = i+1 ; j <=n; j++){
      int dist = min(j-i, abs(x-i) + abs(y-j) + 1);
      map[dist]++;   
    } 
  }
  for(int i = 1; i <n; i++){
    cout << map[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<string.h>
#include<functional>
using namespace std;

#define INF 1<<21
#define DIV 1000000007

typedef pair<int, int>P;

int p, q, a;

int solve(int n, int next, int prod, int sum) {
  int cnt = 0;
  for (int i = next; i*prod <= a; i++) {
	int left = i*prod*p;
	int right = prod + i*sum;
	if (left < right*q)continue;
	if (left == right*q) { cnt++; continue; }
	if (n == 1)continue;
	cnt += solve(n - 1, i, i*prod, right);
  }
  return cnt;
}

int main(){
  int n;
  while (cin>>p>>q>>a>>n,(p||q||a||n)){
	cout << solve(n, 1, 1, 0) << endl;
  }
  return 0;
}

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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while(cur!=nil&&cur->key!=key){
    cur=cur->next;
  }
  return cur;
  /* your code */
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
  if(t==nil)return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  /* your code */
  deleteNode(nil->prev);
}

void delete(int key){
  /* your code */
  deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
  /*

   your code


  */

}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++;
      }
      size--;
    }
  }

  printList();
  return 0;
}



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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
//#define int ll
#define swap(x, y)((x)^=(y)^=(x)^=(y))
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define ff first
#define tcase int _; cin>> _; for( ; _; --_)
#define ss second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	for(;exp; exp>>=1){
		if(exp % 2 == 1) total = mod(((mod(total, m)) * (mod(base, m))), m);
		base= mod((mod(base, m) * mod(base, m)), m);
	}
	return total;
}

int n;

void solve(){
    int d, t, s;

    cin >> d >> t >> s;

    cout<< ((double) d / s <= t ? "Yes\n": "No\n");
}

int32_t main(){
	fastio;
	solve();
	return 0;
}



Measured memory_bytes: 3508
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>

using namespace std;

int main()
{
	string s;
	cin >> s;

	string k1 = "dream";
	string k2 = "dreamer";
	string k3 = "erase";
	string k4 = "eraser";

	while (true)
	{
		if (s.length() >= k1.length() && s.substr(s.length() - k1.length()) == k1)
		{
			s = s.substr(0, s.length() - k1.length());
			continue;
		}
		if (s.length() >= k2.length() && s.substr(s.length() - k2.length()) == k2)
		{
			s = s.substr(0, s.length() - k2.length());
			continue;
		}
		if (s.length() >= k3.length() && s.substr(s.length() - k3.length()) == k3)
		{
			s = s.substr(0, s.length() - k3.length());
			continue;
		}
		if (s.length() >= k4.length() && s.substr(s.length() - k4.length()) == k4)
		{
			s = s.substr(0, s.length() - k4.length());
			continue;
		}
		break;
	}

	if (s.length() == 0)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 512
#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<bitset>
#include<stack>
#include<memory>
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=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
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(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m,X,Y,a;cin>>n>>m>>X>>Y;
	while(n--){cin>>a;maxeq(X,a);}
	while(m--){cin>>a;mineq(Y,a);}
	cout<<(X<Y?"No War":"War")<<endl;
	return 0;
}


Measured memory_bytes: 888
# -*- coding: utf-8 -*-

import re

s = input().strip()
answer = [0 for _ in range(len(s))]

# 例えば [R R L R L] みたいな入力があるとき、リストの順番を偶奇で分ける
# つまり [0 1 0 1 0] みたいな
# 10^100 は偶数だから、偶数回だけ移動しても偶奇判定は変わらない。0 にいた人は移動後も、いずれかの 0 の位置に来る
# R と L が交わるところに人は溜まるはずである
#
# 左から /R+L+/ な場所を探してリストをサブリスト化し、そこに集まりうる人を計算する
# 今回の場合はサブリスト化により、もともとのリストは [R R L], [R L] に分けられる

m = re.findall('R+L+', s)

# m = ['RRL', 'RL']
idx = 0
for substr in m:
    # 偶奇それぞれにいる人数を数え、R と L の境目に人を寄せる

    # 偶奇の人数
    substr_len = len(substr)
    if idx % 2 == 0:
        gu = (substr_len + 1) // 2
        ki = substr_len // 2
    else:
        gu = substr_len // 2
        ki = (substr_len + 1) // 2

    # R と L の境目
    l_idx = substr.find('L')
    if (idx + l_idx) % 2 == 0:
        answer[idx + l_idx] = gu
        answer[idx + l_idx - 1] = ki
    else:
        answer[idx + l_idx] = ki
        answer[idx + l_idx - 1] = gu

    idx += len(substr)

print(*answer)



Measured memory_bytes: 9712
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

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; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using Real = double;
using Point = complex<Real>;
const Real EPS = 1e-8;

using Points = vector<Point>;


int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n; cin >> n;
	Points p(n);
	for (int i = 0; i < n; i++) {
		int x, y; cin >> x >> y;
		p[i] = Point(x, y);
	}
	Real res = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			Real pr = (Real)(n - 1) / (n * (n - 1) / 2.0);
			res += abs(p[i] - p[j]) * pr;
		}
	}
	cout << fixed << setprecision(12) << res << endl;
	return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
int inf=1000001000;
ll INF=100000000000000000;
ll MOD=1000000007;
//int 2×10の9乗
//vector<vector<int>> a(n, vector<int>(m));
//rep(i,n) rep(j,m) cin >> a[i][j]; 
//cout << fixed << setprecision(10) << ans << endl;
//sort小さい順(昇順)
//g++ code.cpp   ./a.out 
 
int main() {
    ll a,b,k;
    cin >> a >> b >> k;
    if(a>k){
        cout << a-k << " " << b << endl;
    }   
    else {
        cout << 0 << " " << max((ll)0,a+b-k) << endl;
    }
}


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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    ans += (r - l + 1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n,l = map(int, input().split())
a = []
ans = 0
for i in range(1, n+1):
  a.append([l + i - 1, abs(l + i - 1)])
a = sorted(a, key = lambda x:x[1], reverse = True)
a.pop()
for i in range(n-1):
  ans += a[i][0]
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
int n,d[100101];
int head[100101],cnt;
int maxx,a[100101],b[100101];
map<pair<int,int>,int> ans;
struct node
{
	int next;
	int to;
}e[200101];
void add(int from,int to)
{
	e[++cnt].next=head[from];
	e[cnt].to=to;
	head[from]=cnt;
	d[to]++;
}
void dfs(int u,int fa,int c)
{
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].to;
		if(v==fa)
			continue;
		ans[make_pair(u,v)]=ans[make_pair(v,u)]=(++c)%maxx;
		dfs(v,u,c);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		add(a[i],b[i]);
		add(b[i],a[i]);
	}
	for(int i=1;i<=n;i++)
		maxx=max(maxx,d[i]);
	printf("%d\n",maxx);
	dfs(1,0,0);
	for(int i=1;i<n;i++)
		printf("%d\n",ans[make_pair(a[i],b[i])]+1);
	return 0;
}

Measured memory_bytes: 17664
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <numeric>
#include <bitset>
using namespace std;
#define lint long long
#define ll long long
#define pq priority_queue
long long INF = 1e10;
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
/******************************define*********************************/

/*****************************functions********************************/
long long pow2(int n) {
	long long ans = 1;
	for (int i = 0; i < n; i++) {
		ans *= 2;
	}
	return ans;
}
/****************************main function*****************************/
int main(void) {

	unsigned ll A, B; cin >> A >> B;
	vector<unsigned ll> a(41), b(41);
	for (int i = 0; i <= 40; i++) {
		unsigned ll k = A, l = B + 1;

		a[i] = (pow2(i))*(A / (pow2(i+1)));
		//cout << a[i] << " ";
		k %= (pow2(i+1));
		if (k >= (pow2(i))) a[i] += k - (pow2(i));

		b[i] = (pow2(i))*(l / (pow2(i+1)));
		l %= (pow2(i+1));
		if (l >= (pow2(i))) b[i] += l - (pow2(i));
		
		//cout << a[i] << " " << b[i] << endl;

	}
	bool check = false;
	unsigned ll ans = 0;
	for (int i = 40; i >= 0; i--) {
		if (a[i] != 0 || b[i] != 0) {
			check = true;
		}
		if (check) {
			if ((b[i] - a[i]) % 2 != 0) {
				ans += (pow2(i));
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

string a;
int ct;

int main(){
    cin >> a;
    if (a[0] == '1') {
      ++ct;
    } 
    if (a[1] == '1') {
      ++ct;
    } 
    if (a[2] == '1') {
      ++ct;
    }
    cout << ct; 
    return 0;
}


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

int main(){
    int H, W;
    std::cin >> H >> W;
    std::vector<bool> isEmptyRow(H, true), isEmptyColumn(W, true);
    std::vector<std::vector<char>> pix(H, std::vector<char>(W));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            std::cin >> pix[i][j];
            if(pix[i][j] == '#'){
                isEmptyRow[i] = false;
                isEmptyColumn[j] = false;
            }
        }
    }

    for(int i = 0; i < H; i++){
        if(isEmptyRow[i]) continue;
        for(int j = 0; j < W; j++){
            if(isEmptyColumn[j]) continue;
            std::cout << pix[i][j];
        }
        std::cout << std::endl;
    }



    return 0;
}


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

using namespace std;

const int N = 5.1e5;

template <class T>
class Fenwick {
private:
  vector<T> bit_;
  int n_;
public:
  Fenwick(int n) : n_(n), bit_(n + 1) {}
  T Query(int pos) {
    T res{};
    for (int i = ++pos; i > 0; i -= i & -i)
      res += bit_[i];
    return res;
  }
  void Update(int pos, T delta) {
    for (int i = ++pos; i <= n_; i += i &-i) {
      bit_[i] += delta;
    }
  }
};

vector<pair<int, int> > quer[N];

void Run() {
  int n, q;
  cin >> n >> q;
  vector<int> c(n);
  for (int i = 0; i < n; ++i)
    cin >> c[i];
  for (int i = 0; i < q; ++i) {
    int lft, rgt;
    cin >> lft >> rgt;
    --lft, --rgt;
    quer[rgt].emplace_back(lft, i);
  }
  Fenwick<int> fenw(n);
  vector<int> last(n + 1, -1);
  vector<int> ans(q, -1);
  for (int i = 0; i < n; ++i) {
    if (last[c[i]] != -1) {
      fenw.Update(last[c[i]], -1);
    }
    fenw.Update(i, 1);
    last[c[i]] = i;
    for (auto& [lft, j] : quer[i]) {
      ans[j] = fenw.Query(i) - fenw.Query(lft - 1);
    }
  }
  for (int i = 0; i < q; ++i) {
    cout << ans[i] << '\n';
  }
}

int main() {
  srand(time(0));
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  Run();
  return 0;
}


Measured memory_bytes: 33504
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		System.out.println(solve(a, b, c));
		in.close();
	}

	private static int solve(int a, int b, int c) {
		a = a - b;
		if (a >= c)
			return 0;
		else
			return c - a;
	}
}

Measured memory_bytes: 21588
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1000000007;
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 (b < a) { a = b; return true; } return false; }

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...)); }
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }

template<class T, class ...Tail>
void tiedSort(vector<T> &a, vector<Tail>&... tail) {
	int n = a.size();
	using S = tuple<T, Tail...>;
	vector<S> s(n);
	for (int i = 0; i < n; i++)
		s[i] = make_tuple(a[i], tail[i]...);
	sort(s.begin(), s.end());
	for (int i = 0; i < n; i++)
		tie(a[i], tail[i]...) = s[i];
}

struct RangeUpdateQuery {
	int n;
	vector<int> d;
	vector<int> timestamp;
	int time;
	RangeUpdateQuery(int m) {
		for (n = 1; n < m; n *= 2);
		d.assign(n * 2, INF);
		time = 0;
		timestamp.assign(n * 2, 0);
	}
	void update(int l, int r, int x) {
		time++;
		for (; l && l + (l&-l) <= r; l += l & -l) {
			d[(n + l) / (l&-l)] = x;
			timestamp[(n + l) / (l&-l)] = time;
		}
		for (; l < r; r -= r & -r) {
			d[(n + r) / (r&-r) - 1] = x;
			timestamp[(n + r) / (r&-r) - 1] = time;
		}
	}
	int get(int i) {
		int ret = d[n + i];
		int max_time = timestamp[n + i];
		for (int j = (n + i) / 2; j > 0; j >>= 1) {
			if (max_time > timestamp[j])continue;
			max_time = timestamp[j];
			ret = d[j];
		}
		return ret;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M; cin >> N >> M;
	vector<int> L(M), R(M), C(M); rep(i, 0, M) {
		cin >> L[i] >> R[i] >> C[i];
		L[i]--;
	}

	tiedSort(L, R, C);

	RangeUpdateQuery ruq(N);
	ruq.update(0, 1, 0);

	rep(i, 0, M) {
		dump(i, L[i], R[i], C[i]);
		int mini = ruq.get(L[i]);
		if (mini == INF) {
			cout << -1 << endl;
			return 0;
		}
		int c = mini + C[i];

		auto f = [&](int x) {
			return ruq.get(x) > c;
		};
		auto binarySearch = [&](int ng, int ok) {
			if (f(ng))return ng;
			while (ng + 1 < ok) {
				int m = (ng + ok) / 2;
				if (f(m))
					ok = m;
				else
					ng = m;
			}
			return ok;
		};

		int l = binarySearch(L[i], N);
		dump(l);
		dump(ruq.get(l));

		//vector<int> tmp(N);
		//rep(i, 0, N) {
		//	tmp[i] = ruq.get(i);
		//}
		//dump(tmp);

		ruq.update(l, R[i], c);

	}
	int ans = ruq.get(N - 1);
	if (ans == INF)ans = -1;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6664
MOD = int(1e9)+7

def fact(x):
    k = 1
    for i in range(1,x+1):
        k = (k*i)%MOD
    return k

def inverse(b):
    r = 1
    e = MOD -2
    while e:
        if e%2==1:
            r = (r*b)%MOD
        b = (b*b)%MOD
        e >>=1
    return r

def comb(i,j):
    if i==0 or j==0:
        return 0
    num=fact(i+j)
    num*=inverse(fact(i))
    num%=MOD
    num*=inverse(fact(j))
    num%=MOD
    return num

rc = list(map(int, input().split()))
ans = 0
ans += comb(rc[2]+1,rc[3]+1)
ans -= comb(rc[0],rc[3]+1)
ans -= comb(rc[2]+1,rc[1])
ans += comb(rc[0],rc[1])
ans += MOD
ans += MOD
ans %=MOD
print(ans)

Measured memory_bytes: 38640
class Mint:
    
    MOD = 10**9+7
    
    def __init__(self, x=0):
        self.x = (x%self.MOD + self.MOD) % self.MOD
    
    def __iadd__(self, other):
        self.x += other.x
        if self.x >= self.MOD:
            self.x -= self.MOD
        return self
    
    def __isub__(self, other):
        self.x += self.MOD - other.x
        if (self.x >= self.MOD):
            self.x -= self.MOD
        return self
    
    def __imul__(self, other):
        self.x *= other.x
        self.x %= self.MOD;
        return self;
    
    def __add__(self, other):
        ans = Mint(self.x)
        ans += other
        return ans
        
    def __sub__(self, other):
        ans = Mint(self.x)
        ans -= other
        return ans
    
    def __mul__(self, other):
        ans = Mint(self.x)
        ans *= other
        return ans
    
    def __pow__(self, n):
        if n == 0:
            return Mint(1)
        a = self.__pow__(n >> 1)
        a *= a
        if n&1:
            a *= self
        return a
    
    def inv(self):
        return self**(self.MOD-2)
    
    def __ifloordiv__(self, other):
        self *= other.inv()
        return self
    
    def __floordiv__(self, other):
        ans = Mint(self.x)
        ans //= other
        return ans
        

    
def Main(N, K):
    ans = Mint(0)
    for i in range(K, N+2):
#         low = ((Mint(0)+Mint(i-1))*Mint(i))//Mint(2)
#         high =((Mint(N)+Mint(N-i+1))*Mint(i))//Mint(2)
        ans += Mint(i)*Mint(N-i+1)+Mint(1)
    return ans.x

def main():
    N, K = map(int, input().split())
    print(Main(N, K))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9296
import collections

n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr)
s=set()
cnt=collections.Counter(arr)
for i in range(n):
  if arr[i] in s:
    continue
  if cnt[arr[i]]>=2:
    s.add(arr[i])
  for j in range(2,10**6//arr[i]+1):
    s.add(arr[i]*j)
ans=0
for i in range(n):
  if arr[i] in s:
    continue
  if cnt[arr[i]]>=2:
    continue
  ans+=1
print(ans)

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

data = [[] for _ in range(N)]
ans = [None] * N

for i in range(N-1):
    u,v,w = map(int, input().split())
    u -= 1
    v -= 1
    w &= 1
    data[u].append((v, w))
    data[v].append((u, w))

import sys
sys.setrecursionlimit(10000000)
def f(i, color):
    for t, w in data[i]:
        if ans[t] is not None:
            continue
        ans[t] = color^w
        f(t, color^w)

f(0, 0)

for i in range(N):
    print(ans[i])


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

int main(){
    int a[3];
    int b[2];
    int m=10000;
    for(int i=0;i<3;i++){
        cin>>a[i];
    }
    for(int i=0;i<2;i++){
        cin>>b[i];
    }
    for(int i=0;i<3;i++){
        for(int j=0;j<2;j++){
            m=min(m,a[i]+b[j]-50);
        }
    }
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>
int main (){
char s[1001];
int i,n=0,k=0,w=0,e=0;
scanf ("%s",s);	
for (i=0; s[i]!=0;i++){
	if(s[i]=='N'){
	n++;}
	else if(s[i]=='S'){
	k++;}
	else if(s[i]=='W'){
	w++;}
	else if(s[i]=='E'){
	e++;}
	}
	
	if (n>0 && k>0 && w==0 && e==0){
		printf ("Yes");
		}
		else if (n==0 && k==0 && w>0 && e>0){
		printf ("Yes");
		}
		else if (n>0 && k>0 && w>0 && e>0){
		printf ("Yes");
		}
		else
		{
			printf ("No");
		}	
	return 0;
		}

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

using namespace std;
#define int long long
#define all(a) (a).begin(), (a).end()
#define ms(a,v) memset(a, v, sizeof(a))
#define sz(v) ((int)(v).size())
#define mp make_pair
#define pb push_back
#define prev biiiiirl_sai_de_casa_comi_pra_caralho
#define next trapezio_descendente
#define index eh_ele_que_nos_vai_buscar
#define left aqui_eh_37_anos_porra
#define R32 ({int32_t x; scanf("%d", &x); x;})
#define RL ({long long x; scanf("%lld", &x); x;})
#define RC ({char x; scanf(" %c", &x); x;})
#define RI RL
#define ff first
#define ss second
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef long long ll;

const int MOD = (int)1e9+7;
const int N = 1e6;
int c[N], w[N];
vector<int> adj[N];
int vis[N];
int fat[N], ifat[N], inv[N];

int sz;
map<int, int> freq;

struct Ball{
  int w, c, idx;
  bool operator<(const Ball & rhs) const {
    return w < rhs.w;
  }
};

void compute(){
  fat[0] = fat[1] = ifat[0] = ifat[1] = inv[1] = 1;
  for(int i = 2; i < N; i++){
    fat[i] = fat[i-1]*i%MOD;
    inv[i] = MOD - MOD/i*inv[MOD%i]%MOD;
    ifat[i] = ifat[i-1]*inv[i]%MOD;
  }
}

void dfs(int u){
  if(vis[u]) return;
  vis[u] = 1;
  freq[c[u]]++;
  sz++;
  for(int v : adj[u])
    dfs(v);
}

vector<Ball> buck[N];
int32_t main(){
  compute();
  int n = RI;
  int X = RI;
  int Y = RI;

  vector<Ball> balls;
  for(int i = 0; i < n; i++){
    c[i] = RI;
    w[i] = RI;
    balls.pb({w[i], c[i], i});
    buck[c[i]].pb({w[i], c[i], i});
  }

  sort(all(balls));
  for(int i = 1; i <= n; i++) sort(all(buck[i]));

  vector<Ball> re;
  re.pb(balls[0]);
  for(int i = 1; i < balls.size(); i++){
    if(balls[i].c != re[0].c){
      re.pb(balls[i]);
      break;
    }
  }

  for(Ball a : re){
    for(Ball b : balls){
      if(a.c == b.c) continue;
      if(a.w + b.w <= Y)
        adj[a.idx].pb(b.idx), adj[b.idx].pb(a.idx); 
    }
  }

  for(int i = 1; i <= n; i++){
    if(buck[i].size() <= 1) continue;
    for(int j = 1; j < buck[i].size(); j++){
      if(buck[i][j].w + buck[i][0].w <= X)
        adj[buck[i][j].idx].pb(buck[i][0].idx), adj[buck[i][0].idx].pb(buck[i][j].idx);
    }
  }

  int ans = 1;

  for(int i = 0; i < n; i++){
    if(!vis[i]){
      freq.clear();
      sz = 0;
      dfs(i);

      int acc = fat[sz];
      for(auto p : freq){
        acc *= ifat[p.second];
        acc %= MOD;
      }

      ans *= acc;
      ans %= MOD;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 110252
#include <bits/stdc++.h>
using namespace std;
 
int main(void) {
    char S[10];
    int flag=0;

    cin >> S;
 
    for(int i=0; i<strlen(S); i+=2){
        if(S[i]!='h' || S[i+1]!='i')    flag = 1;
    }

    if(flag)    cout << "No";
    else    cout << "Yes";
 
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main(){
	var x0,y0,r0,x1,y1,r1 int32
	var r_max,r_min int32
	var flag int8
	fmt.Scanf("%d %d %d",&x0,&y0,&r0)
	fmt.Scanf("%d %d %d",&x1,&y1,&r1)

	d := math.Sqrt(float64((x0-x1)*(x0-x1) + (y0-y1)*(y0-y1)))
	if r0>r1 {
		r_max=r0
		r_min = r1
	} else {
		r_max=r1
		r_min = r0
	}
	r_sum := r0+r1
	switch  {
	case d > (float64(r_sum)) :		flag = 4
	case d == (float64(r_sum)) :	flag = 3
	case d < (float64(r_sum)) :	{
		if d+float64(r_min)< float64(r_max){
			flag=0
		}else if d+float64(r_min)== float64(r_max) {
			flag = 1
		}else {
			flag = 2
		}
	}
	default:

	}
	fmt.Println(flag)
}


Measured memory_bytes: 1128
//Patwari26
//#include template<t> as mine
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=1000006;
ll cc[N];
void seive(ll n){
    rep(i,1,n){
        for(int j=i;j<=n;j+=i){
            cc[j]++;
        }
    }
}
void solve(){
    
    ll n;
    cin>>n;
    seive(n);
    ll ans=0;
    rep(i,1,n-1){
        ll temp=n-i;
        ans+=cc[temp];
    }
    cout<<ans<<endl;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    // time
    return 0;
}

Measured memory_bytes: 11416
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val ds = (1 to n).map(_ => sc.nextInt)
    .sorted
    .groupBy(i => i)
    .map(t => (t._1, t._2.length))
    .toStream
    .sortBy(t => t._1)

  val min = ds.head
  val max = ds.last
  val multi = ds.filter(_._2 >= 2).map(_._2).sum
  val ok = ds.length == (max._1 - min._1 + 1)

  if ((max._1 + 1) / 2 != min._1) {
    println("Impossible")
  } else if (ok && max._1 % 2 == 1 && min._2 == 2 && multi == n) {
    println("Possible")
  } else if (ok && max._1 % 2 == 0 && min._2 == 1 && multi == n - 1) {
    println("Possible")
  } else {
    println("Impossible")
  }
}


Measured memory_bytes: 27452
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int a, b;
    cin >> a >> b;

    cout << max({a+b, a-b, a*b}) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, k, r, s, p, z = 0;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    for (int i = 0; i < n; i++) {
        if (t[i] == 's') t[i] = 'r';
        else if (t[i] == 'r') t[i] = 'p';
        else t[i] = 's';
    }
    for (int i = 0; i < k; i++) {
        string u;
        for (int j = i; j < n; j += k) u += t[j];
        vector<int> d(u.length()), e(u.length());
        if (u[0] == 'r') e[0] = r;
        else if (u[0] == 's') e[0] = s;
        else e[0] = p;
        for (int j = 1; j < u.length(); j++) {
            d[j] = max(d[j - 1], e[j - 1]);
            if (u[j] == u[j - 1]) {
                if (u[j] == 'r') e[j] = d[j - 1] + r;
                else if (u[j] == 's') e[j] = d[j - 1] + s;
                else e[j] = d[j - 1] + p;
            } else {
                if (u[j] == 'r') e[j] = max(d[j - 1], e[j - 1]) + r;
                else if (u[j] == 's') e[j] = max(d[j - 1], e[j - 1]) + s;
                else e[j] = max(d[j - 1], e[j - 1]) + p;
            }
        }
        z += max(d[u.length() - 1], e[u.length() - 1]);
    }
    cout << z;
}


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

int main(){
    int n;
    cin >> n;
    int ans = 0;
    rep(i, n) {
        ll a;
        cin >> a;
        while(1) {
            if ( a % 2 != 0 ) break;
            ++ans;
            a /= 2; 
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
dp=[0]*(N+1)
dp[0]=1
mod=10**9+7
a=[False for _ in range(N+1)]
for _ in range(M):
    a[int(input())]=True
    
for i in range(1,N+1):
    if a[i]:
        continue
    dp[i]=(dp[i-1]+dp[i-2])%mod
 
print(dp[N])

Measured memory_bytes: 7832
#include<stdio.h>


int main(){
	int h1,h2,m1,m2,s1,s2,c,h,m,s,i;
	
	for(i=0;i<3;i++){
		scanf("%d%d%d%d%d%d",&h1,&m1,&s1,&h2,&m2,&s2);
		
		if(s2-s1<0){
			s=s2-s1+60;
			c=1;
		}else{
			s=s2-s1;
			c=0;
		}
		
		if(m2-m1-c<0){
			m=m2-m1-c+60;
			c=1;
		}else{
			m=m2-m1-c;
			c=0;
		}
		
		h=h2-h1-c;
		printf("%d %d %d\n",h,m,s);
	}
	return 0;
}

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


int main() {
  int x, a, b;
  cin >> x >> a >> b;
  string ans = "B";
  if(abs(b - x) > abs(a - x)) ans = "A";
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    cout << fixed << setprecision(12) << double((n+1)/2) / n << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9; 
int a[N];
void solve(){
    int n, m;
    cin >> n >> m;
    ll sum = 0;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        sum += a[i];
    }
    double p = (1.0 / (4 * m)) * sum;
    p = ceil(p); 
    sort(a + 1, a + n + 1);
    reverse(a + 1,a + n + 1);
    for(int i = 1; i <= m; ++i) {
        if(a[i] < p) {
            cout << "No";
            return;
        }
    }
    cout << "Yes";
}
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int n,k,m,i,j;
	cin>>n>>k;m=(1<<n)-1;
	
	if(k>m){
		cout<<-1;
		return 0;
	}
	
	if(n==1){
		if(k==0)
			printf("0 0 1 1");
		else
			cout<<-1;
		return 0;
	}
	
	n=m;
	cout<<k<<' ';
	for(i=0;i<=n;i++)
		if(i!=k) cout<<i<<' ';
	cout<<k<<' ';
	for(i=n;i>=0;i--)
		if(i!=k) cout<<i<<' ';
	return 0;
}

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

#define ll long long
#define ii pair<int, int>
#define dd pair<double, double>
#define pb(i) push_back(i)
const double PI = 3.14159265359;
const int inf = 1e9+77;
const int mod = 1e9+7;
const double eps = 1e-7;
//int dir1[8] = {0, 0, 1, -1, 1, -1, 1, -1};
//int dir2[8] = {1, -1, 0, 0, 1, 1, -1, -1};
int dir1[4] = {0, 0, 1, -1};
int dir2[4] = {1, -1, 0, 0};

int n, m;
char mat[20][20];
int dist[20][20];

bool valid(int x, int y)
{
    if(x < 0 || x >= n || y < 0 || y >= m)
        return false;
    
    if(mat[x][y] == '#')
        return false;
    
    return true;    
}

int bfs(int x, int y)
{
    int i, j;

    memset(dist, -1, sizeof(dist));
    dist[x][y] = 0;

    int ans = -1;
    queue<ii> q;
    q.push(ii(x, y));
    while(!q.empty())
    {
        x = q.front().first;
        y = q.front().second;
        q.pop();

        for(i = 0; i < 4; i++)
        {
            int x1 = x+dir1[i], y1 = y+dir2[i];
            if(valid(x1, y1) && dist[x1][y1] == -1)
                dist[x1][y1] = dist[x][y]+1, q.push(ii(x1, y1)), ans = max(ans, dist[x1][y1]);
        }
    }

    return ans;
}

int main()
{
    int i, j;


    cin >> n >> m;

    for(i = 0; i < n; i++)
        for(j = 0; j < m; j++)
            cin >> mat[i][j];
    
    int ans = -1;
    for(i = 0; i < n; i++)
        for(j = 0; j < m; j++)
            if(valid(i, j))
                ans = max(ans, bfs(i, j));
            
    if(ans == -1)
        ans = 0;
    cout << ans << '\n';
}

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

const int maxn = 1e5 + 10;
vector<int> G[maxn];

bool comp(int a, int b) {
	return a > b;
}

int d(int id) {
	if (G[id].size() == 0) {
		return 0;
	} else {
		vector<int> dis;
		for (int i = 0; i < G[id].size(); i++) {
			dis.push_back(d(G[id][i]));
		}
		sort(dis.begin(), dis.end(), comp);
		int res = -1;
		for (int i = 0; i < dis.size(); i++) {
			res = max(res, dis[i] + i);
		}
		return res + 1;
	}
}

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 2; i <= n; i++) {
		int x;
		cin >> x;
		G[x].push_back(i);
	}
	cout << d(1) << endl;
	return 0;
}

Measured memory_bytes: 13568
import sys
readline = sys.stdin.readline
from heapq import heapify, heappush, heappop

def dijkstra(path, N, start):
    visited = [False] * N
    mark = [-1] * N  # その頂点の次にどの頂点に行くか決定済みのもの
    que = [(0, start, -1)]  # (コスト、頂点、前の頂点)
    heapify(que)  # 始点aから各頂点への(距離, 頂点ID)
    dist = [-1] * N  # 始点aから各頂点への距離
    dist[start] = 0  # 始点aからaへの距離は0
    while que:
        d, v, pre = heappop(que)  # 始点から最短距離の頂点を(確定ノード)を取り出す
        visited[v] = True  # 確定フラグを立てる
        if v > 0:
            if mark[v] != -1 and mark[v] != pre:
                return 'No'
            mark[v] = pre
        # 接続先ノードの情報を更新する
        for d, to in path[v]:
            cost = dist[v] + d
            if dist[to] < 0 or cost < dist[to]:
                dist[to] = cost
                if not visited[to]:
                    heappush(que, (cost, to, v))

    return mark

def main():
    N, M = map(int, readline().rstrip().split())
    path = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, readline().rstrip().split())
        path[a-1].append((1, b-1))
        path[b-1].append((1, a-1))
    
    start = 0
    mark = dijkstra(path, N, start)
    if mark == 'No':
        print('No')
        return

    print('Yes')
    for v in range(1, N):
        print(mark[v] + 1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 64812
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

class Main {
    static int n, pos = 0;

    static ArrayList<Integer> preorder = new ArrayList<>();
    static ArrayList<Integer> inorder = new ArrayList<>();
    static ArrayList<Integer> postorder = new ArrayList<>();

    static void reconstruction(int l, int r){
        if (l >= r) return;

        int root = preorder.get(pos++);
        int m = inorder.indexOf(root);

        reconstruction(l,m);
        reconstruction(m+1,r);

        postorder.add(root);
    }


    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        n = sc.nextInt();

        for (int i = 0; i < n; i++) preorder.add(i,sc.nextInt());
        for (int i = 0; i < n; i++) inorder.add(i,sc.nextInt());

        reconstruction(0,n);

        StringBuilder sb = new StringBuilder().append(postorder.get(0));

        for (int i = 1; i < n; i++) {
            sb.append(" ").append(postorder.get(i));
        }
        System.out.println(sb.toString());

    }

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            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: 24500