akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    REP(i, N) cin>>A[i];
    sort(ALL(A));
    ll lower = 0, upper = 2e5+1000;
    ll y = 0;
    ll num = 0;
    while(upper>lower+1){
        ll mid = (upper+lower)/2;
        ll cnt = 0;
        REP(i, N){
            cnt += N - (lower_bound(ALL(A), mid-A[i]) - A.begin());
        }
        if(cnt>=M){
            lower = mid;
            y = mid;
            num = cnt;
        }
        else {
            upper = mid;
        }
    }
    ll res = 0;
    vector<ll> VS(N+1);
    REP(i, N){
        VS[i+1] = VS[i] + A[i];
    }
    ll cnt = 0;
    for(int i=N-1; i>=0; i--){
        ll idx = lower_bound(ALL(A), y-A[i]) - A.begin();
        if(idx>=N) continue;
        res += VS[N] - VS[idx] + (N-idx)*A[i];
    }
    cout << res - (num-M)*y << endl;
    return 0;
}

Measured memory_bytes: 1792
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
public:
  ll *fac,*finv,*inv;
//public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

ll gcd(ll x,ll y){
  if(x%y == 0) return y;
  else return gcd(y,x%y);
}

void dfs(int k,string sub,int n){
  if(sub.length() == n){
    cout << sub << endl;
    return;
  }
  for(int i=0;i<k;i++){
    char temp = 'a'+i;
    if(i != k-1){
      dfs(k,sub+temp,n);
    }
    else{
      dfs(k+1,sub+temp,n);
    }
  }
  return;
}
int main(){
  ll n;
  cin >> n;
  ll a[n];
  for(ll i=0;i<n;i++) cin >> a[i];
  unordered_map<ll,ll> table;
  for(ll i=0;i<n;i++){
    table[a[i]]++;
  }
  ll total = 0;
  for(ll i=1;i<n+1;i++){
    total += (table[i]*(table[i]-1))/2;
  }
  for(ll i=0;i<n;i++){
    ll diff = table[a[i]]-1;
    ll ans = total - diff;
    cout << ans << endl;
  }
  return 0;
}


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

int main() {
  string N, M, L;
  cin >> N >> M >> L;
  if(N.at(N.size()-1) == M.at(0) && M.at(M.size()-1) == L.at(0)){
      cout << "YES" << endl;
  }
  else cout << "NO" << endl;
}

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

using ld = double;
using ll = long long;
using ull = unsigned long long;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;

const int SZ = 1 << 13;
char buff[SZ], *pos = buff + SZ - 1;
#define getchar() (++ pos == buff + SZ ? fread(pos = buff, 1, SZ, stdin), *pos : *pos)

inline ll read() {
	ll x = 0; int f = 1, c = getchar();
	for (;!isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x<<3) + (x<<1) + (c^48);
	return x * f;
}

bool g[4][4];
int main() {
	for (int i = 1; i < 4; ++ i) {
		int a = read() - 1, b = read() - 1;
		g[a][b] = g[b][a] = 1;
	}
	int a[4];
	for (int i = 0; i < 4; ++ i) a[i] = i;
	do {
		bool ok = 1;
		for (int i = 1; i < 4; ++ i) {
			if (!g[a[i - 1]][a[i]]) ok = 0;
		}
		if (ok) {
			puts("YES"); return 0;
		}
	} while (next_permutation(a, a + 4));
	puts("NO");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void)
{    
    ll k, s;
    cin >> k >> s;
    ll r = 0;
    
    rep(i, k+1) {
        rep(j, k+1) {
            if(s-i-j >= 0 && s-i-j <= k) r++;
        }
    }
    
    mes(r);
	
    
    
    
    
    
    
    
    
    
}

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

void change(string &s)
{
	for (int i = 0; i < s.size(); ++i)
	{
		if (s[i] == 'b')
		{
			s[i] = 'd';
		}
		else if (s[i] == 'd')
		{
			s[i] = 'b';
		}
		else if (s[i] == 'p')
		{
			s[i] = 'q';
		}
		else if (s[i] == 'q')
		{
			s[i] = 'p';
		}
	}
}

int main()
{
	string s, s1;
	cin >> s;
	s1 = s;
	reverse(s1.begin(), s1.end());
	change(s1);
	if (s == s1)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long int
#define ull unsigned long long
#define si set <ll>
#define vi vector <ll>
#define popcount(x) __builtin_popcountll(x)
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define sz(c) (ll)c.size()
#define fr first
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,n) for(ll i=a ; i<n ; i++)
#define ld long double
const ll INF = __LONG_LONG_MAX__;
#define rall(a) (a).rbegin(),(a).rend()
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

ll power(ll b,ll e,ll m)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b%m,e/2,m)%m;
  return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b,e/2);
  return power(b*b,e/2);
}  
bool isPowerOfTwo(ll x)
{
    // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
    return (x && !(x & (x - 1)));
}

void solve()
{
  ll n;
  cin>>n;
  ll c=0,flag=0;
  rep(i,0,n)
  {
    ll a,b;
    cin>>a>>b;
    if(a==b)
    {
      c++;
    }
    else
    {
      if(c==3)
        flag=1;
      c=0;
    }
  }
  if(flag or c>=3)
  {
    cout<<"Yes";
  }
  else cout<<"No";
}

int main()
{
  fastio
  ll tt=1;
  // cin>>tt;
  while(tt--)
  {
      solve();
      cout<<"\n";
  }
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

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

string s;
int base[100001];

int main() {
  cin >> s;
  int N = s.size();
  int back, front;
  if (N%2 == 0) {
    back = N/2-1;
    front = N/2;
  } else {
    back = N/2;
    front = N/2;
  }
  char med = s.at(back);
  while (s.at(back) == med && s.at(front) == med) {
    back--;
    front++;
    if (back < 0) {
      break;
    }
  }
  cout << front << endl;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
  int a,b,ans;
  cin>>a>>b;
  ans=a+b;
  if(ans==0){
    cout<<"0"<<endl;
  }else if(ans>0){
    cout<<"1"<<endl;
  }else if(ans<0){
    cout<<"-1"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vll = vector<vl>;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define RES(a, n) (a).resize(n)
ll n, m, k;
vl a, b, c, d;
class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;

    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }

    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }

    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

int main() {
	cin >> n >> m >> k;
	UnionFind friends(n);
	vll fr(n);
	vll bl(n);
	RES(a, m);
	RES(b, m);
	RES(c, k);
	RES(d, k);
	REP(i, m){
		cin >> a[i] >> b[i];
		friends.merge(a[i]-1, b[i]-1);
		fr[a[i]-1].push_back(b[i]-1);
		fr[b[i]-1].push_back(a[i]-1);
	}
	REP(i, k){
		cin >> c[i] >> d[i];
		if(friends.issame(c[i]-1, d[i]-1)){
			bl[c[i]-1].push_back(d[i]-1);
			bl[d[i]-1].push_back(c[i]-1);
		}
	}
	REP(i, n){
		cout << friends.size(i) - 1 - bl[i].size() - fr[i].size() << " ";
	}
	cout << endl;
	return 0;
}

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

int main(){ 
  int h, n;
  cin >> h >> n;
  rep(i,n) {
    int a;
    cin >> a;
    h -= a;
  }
  if (h <= 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
} 

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

using namespace std;
typedef long long ll;
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main() {
  ll a;
  string s;
  cin >> a;
  cin >> s;
  cout << ((a >= 3200) ? s : "red") << endl;
  ;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
using namespace std;

const int N = 200010;
int a[N], b[N];

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}

	for (int k = 1; k <= m; k++) {
		memset(b, 0, sizeof(b));
		for (int i = 1; i <= n; i++) {
			int x = max(1, i - a[i]);
			int y = min(n, i + a[i]);
			b[x]++;
			b[y + 1]--;
		}

		for (int i = 2; i <= n; i++)
			b[i] += b[i - 1];
		bool flag = true;
		for (int i = 1; i <= n; i++) {
			if (a[i] != b[i]) flag = false;
		}
		if (flag) break;
		memcpy(a, b, sizeof(b));
	}

	for (int i = 1; i <= n; i++) {
		printf("%d", a[i]);
		if (i == n) printf("\n");
		else printf(" ");
	}

	return 0;
}


Measured memory_bytes: 4788
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 + 7;
const ll N = 1e6 + 5;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;cin>>s;
    if(s[(int)s.size()-1]!='s') s+="s";
    else s+="es";
    cout<<s<<'\n';
    return 0;
}

Measured memory_bytes: 3660
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern

let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = read_line () |> split_string ~pattern:" " |> List.map int_of_string
let b = read_line () |> split_string ~pattern:" " |> List.map int_of_string

let () =
  let sum_a, sum_b = List.fold_left2 (fun (sum_a, sum_b) a b ->
      if a > b then (sum_a, sum_b + a - b)
      else (sum_a + (b - a) / 2, sum_b)
    ) (0, 0) a b in
  print_endline @@ if sum_a >= sum_b then "Yes" else "No"

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

public class Main {

	static int N,M;
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		for(;;){
			N=Integer.parseInt(cin.nextLine());
			if(N==0)break;
			M=Integer.parseInt(cin.nextLine());
			Edge[] e=new Edge[M];
			for(int i=0;i<M;i++){
				String[] s = cin.nextLine().split(",");
				int a=Integer.parseInt(s[0]);
				int b=Integer.parseInt(s[1]);
				int c=Integer.parseInt(s[2]);
				e[i]=new Edge(a,b,c);
			}
			Arrays.sort(e);
			UnionFind union=new UnionFind(N);
			int ans=0;
			for(int i=0;i<e.length;i++){
				if(!union.find(e[i].a, e[i].b)){
					union.union(e[i].a, e[i].b);
					ans+=(e[i].cost/100) - 1;
				}
			}
			System.out.println(ans);
		}
	}
	static class Edge implements Comparable<Edge>{
		int a,b;
		int cost;
		Edge(int x,int y,int z){
			a=x;b=y;cost=z;
		}
		public int compareTo(Edge e){
			return cost-e.cost;
		}
	}
	static class UnionFind{
		final int[] tree;
		int num;
		public UnionFind(int n){
			this.tree=new int[n];
			Arrays.fill(tree,-1);
			num=n;
		}
		
		void union(int x,int y){
			x=root(x);
			y=root(y);
			if(x!=y){
				if(tree[x]<tree[y]){
					x ^= y;
					y ^= x;
					x ^= y;
				}
				tree[x]+=tree[y];
				tree[y]=x;
				num--;
			}
		}
		boolean find(int x,int y){
			return root(x)==root(y);
		}
		int root(int x){
			return tree[x]<0?x:(tree[x]=root(tree[x]));
		}
		int size(int x){
			return -tree[root(x)];
		}
		int getNum(){
			return num;
		}
	}
}

Measured memory_bytes: 46584
// https://atcoder.jp/contests/abc139/submissions/7356715

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    int n = sc.nextInt();
    List<Xy> l = new LinkedList<>();
    for (int i = 0; i < n; i++) {
      l.add(new Xy(sc.nextInt(), sc.nextInt()));
    }
    l.sort(Xy::hencom); // Sort by angle.

    long max2 = 0;
    for (int i = 0; i < n; i++) {
      long rx = 0;
      long ry = 0;
      for (int j = 0; j < n; j++) {
        rx += l.get(j).x;
        ry += l.get(j).y;
        max2 = Math.max(rx * rx + ry * ry, max2);
      }
      Xy r = l.remove(0);
      l.add(r);
    }
    System.out.println(Math.sqrt(max2));
  }

  static class Xy {
    int x;
    int y;

    Xy(int x, int y) {
      this.x = x;
      this.y = y;
    }

    public static int hencom(Xy s1, Xy s2) {
      return (int) Math.signum(Math.atan2(s1.y, s1.x) - Math.atan2(s2.y, s2.x));
    }

    public String toString() {
      return "[" + x + "," + y + "]";
    }
  }
}


Measured memory_bytes: 28884
def ascan; gets.split.map(&:to_i);end

n = gets.to_i

aa = ascan

c = 0
(-1..1).to_a.repeated_permutation(n) do |zz|
    a = aa.clone
    n.times do |i|
        a[i] += zz[i]
    end
    c+=1 if a.reduce(:*).even?
end


p c

Measured memory_bytes: 2044
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (k, x) = readIntegerList()
    val ans = (-1000000..1000000).filter { x - k < it && it < x + k }.joinToString(" ")
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 52224
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

int main(){
    int l,r,d;
    cin >> l >> r >> d;
    int ans = 0;
    for(int i=l;i<=r;i++){
        if(i%d==0)ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3620
n = gets.to_i
s = gets.chomp
a = Array.new(4).map{Array.new}
a[0].push(1,1)
a[1].push(1,0)
a[2].push(0,1)
a[3].push(0,0)
n.times do |i|
  4.times do |j|
    if s[i] == "o"
      if a[j][i+1] == 1
        a[j] << a[j][i]
      else
        a[j] << 1-a[j][i]
      end
    else
      if a[j][i+1] == 1
        a[j] << 1-a[j][i]
      else
        a[j] << a[j][i]
      end
    end
  end
end
4.times do |i|
  if a[i][0] == a[i][-2] && a[i][1] == a[i][-1]
    n.times do |j|
      if a[i][j+1] == 1
        print "S"
      else
        print "W"
      end
    end
    puts ""
    exit
  end
end
puts "-1"

Measured memory_bytes: 5372
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 1234;
int X[MAXN], Y[MAXN];

int main() {
    int N;
    scanf("%d", &N);
    int cnt1 = 0, cnt2 = 0;
    for (int i = 0; i < N; i++) {
        scanf("%d %d", &X[i], &Y[i]);
        int tmp = X[i] + Y[i];
        if (tmp % 2) cnt1++;
        else cnt2++;
    }
    if (cnt1 && cnt2) return !printf("-1\n");
    int pw2 = 1;
    vector<int> joints;
    if (cnt2) joints.push_back(1);
    for (int i = 0; i <= 30; i++) {
        joints.push_back(pw2);
        pw2 *= 2;
    }
    printf("%d\n", (int)joints.size());
    for (int i : joints) printf("%d ", i);
    puts("");

    for (int i = 0; i < N; i++) {
        deque<char> ans;
        for (int j = (int)joints.size() - 1; j >= 0; j--) {
            int cur = joints[j];
            // abs(X[i]) will never same as abs(Y[i])
            if (abs(X[i]) > abs(Y[i])) {
                if (X[i] < 0) {
                    X[i] += cur;
                    ans.push_front('L');
                } else {
                    X[i] -= cur;
                    ans.push_front('R');
                }
            } else {
                if (Y[i] < 0) {
                    Y[i] += cur;
                    ans.push_front('D');
                } else {
                    Y[i] -= cur;
                    ans.push_front('U');
                }
            }
        }
        for (auto j : ans) printf("%c", j);
        puts("");
        int curX = 0, curY = 0;
        assert(ans.size() == joints.size());
        for (int j = 0; j < (int)ans.size(); j++) {
            char tmp = ans[j];
            if (tmp == 'R') curX += joints[j];
            else if (tmp == 'L') curX -= joints[j];
            else if (tmp == 'U') curY += joints[j];
            else curY -= joints[j];
        }
        //printf("X = %d Y = %d\n", curX, curY);
    }
    return 0;
}


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

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> h(N);
  for(int &i:h)
    cin>>i;
  sort(h.begin(),h.end());
  int j=1000000000;
  for(int i=0;i<=N-K;i++){
    j=min(j,h[i+K-1]-h[i]);
  }
  cout<<j<<endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;

int main(){
  ll n;cin>>n;
  vll b(n);
  rep(i,0,n){
    cin>>b[i];
  }
  rep(i,0,n){
    if(i+1<b[i]){
      cout<<-1<<endl;return 0;
    }
  }
  vll c(0);
  rep(j,0,n){
    drep(i,b.size()-1,0){
      if(b[i]==i+1){
        c.push_back(b[i]);
        b.erase(b.begin()+i);
        break;
      }
    }
    if(b.size()==0)break;
  }
  reverse(c.begin(),c.end());
  rep(i,0,n){
    cout<<c[i]<<endl;
  }
}




Measured memory_bytes: 3648
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include <map>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<bitset>
#include"time.h"
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define dump(x)  cerr << #x << " = " << (x) << endl
const int INF = (1 << 30);

//毎回変える場所
#define N_MAX 100000


//問題文のとおり
int N, K;
LL AB[N_MAX][2];
vector<bitset<30>> A;
vector<bitset<30>> Kr;
LL ans = 0;

int main() {
	//入力
	cin >> N >> K;
	REP(i, N)REP(j, 2)cin >> AB[i][j];
	REP(i, N)A.push_back(bitset<30>(AB[i][0]));

	//Krの計算
	string stK = bitset<30>(K).to_string();//Kを、30桁の2進数に変換
	Kr.push_back(bitset<30>(stK));         
	REP(r, 30) {
		//計算の都合上、上からr桁目としてます
		if (stK[r] == '1') {
			string tmp = stK.substr(0, r);
			tmp += '0';
			REP(i, 30 - r) { tmp += '1'; }
			//↑ここまでで、r桁目は0,それより右が1のみの2進数が出来た

			Kr.push_back(bitset<30>(tmp));
		}
	}

	//それぞれで探索していきますか！
	for (auto kr : Kr) {
		LL sumB = 0;              //価値の総和
		int oneNum = kr.count();  //2進数krにて、1になってる数
		REP(i, N) {
			//1の数が増えてなければ、つまりkrが0のところにA[i]は1がない。
			if ((kr | A[i]).count() == oneNum) {
				sumB += AB[i][1];
			}
		}
		//更新
		ans = max(ans, sumB);
	}
	cout << ans << endl;
	cin >> N;
	return 0;
}

Measured memory_bytes: 2936
N=int(input())
f=[0]*N
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            n=x**2+y**2+z**2+x*y+y*z+z*x
            if n<=N:
                f[n-1]+=1
print(*f,sep="\n")

Measured memory_bytes: 9240
package main

import "fmt"

func getCommons(s1, s2 string) (n int) {
	m1 := make(map[rune]int, 26)
	m2 := make(map[rune]int, 26)
	for _, r := range s1 {
		m1[r]++
	}
	for _, r := range s2 {
		m2[r]++
	}
	for k := range m1 {
		if m2[k] > 0 {
			n++
		}
	}
	return
}

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)
	v := 0
	for i := 0; i < n; i++ {
		if w := getCommons(s[:i], s[i:]); w > v {
			v = w
		}
	}
	fmt.Println(v)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)
 
 
//template functions
/////////////////////////
long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}
long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}
long GCM(long A,long B){
            long W,r;
    if(A<B){
 
        W=B;
        B=A;
        A=W;
    }
    while(A%B!=0){
        r=A%B;
        A=B;
        B=r;
    }
    return B;
}
long LCM(long A,long B){
    return (A*B)/GCM(A,B);
}
 
long upDiv(long a,long b){
  return (a+b-1)/b;
}
 
long fact(long N){
    if(N==0){
        return 1;
    }else{
        long ans=1;
        for(long i=1;i<N+1;i++){
        ans=ans*i;
        }
        return ans;
    }
 
 
 
}
 
/////////////////////////
 
 
//Answer
 
 
int main() {
 
long double N;
long double dis,sum=0.0,answer;
cin>>N;
vector<long double> x(N);
vector<long double> y(N);
for(long i=0;i<N;i++){
cin>>x.at(i);
cin>>y.at(i);
}
for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      double dx=x.at(i)-x.at(j);
      double dy=y.at(i)-y.at(j);
        sum+=pow((dx*dx+dy*dy),0.5);
    }
}
answer=sum*2.0/N;
 
cout<< fixed << setprecision(10) << answer<<endl;
 
}

Measured memory_bytes: 4212
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	long long N;
	long long K;
	
	vector<long long> D;
	cin >> N;

	for (long long i = 0; i < N; ++i) {
		long long d;
		cin >> d;
		D.push_back(d);
	}
	sort(D.begin(), D.end());


	long long ans;
	if (D[N / 2] != D[N / 2 - 1]) {
		ans = D[N / 2] - D[N / 2 - 1];
	}
	else ans = 0;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1400
// 2017-02-21
#include <iostream>
#include <string>
using namespace std;

int main() {
	int n;
	while (cin >> n, n) {
		int k[100];
		string s;
		for (int i = 0; i < n; i++) {
			cin >> k[i];
		}
		cin >> s;
		for (int i = 0; i < s.length(); i++) {
			char d;
			if (s[i] >= 'A' && s[i] <= 'Z') {
				d = s[i] - 'A';
			} else {
				d = s[i] - 'a' + 26;
			}
			d = (52 + d - k[i % n]) % 52;
			if (d < 26) {
				s[i] = d + 'A';
			} else {
				s[i] = d + 'a' - 26;
			}
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 3172
#include<iostream>
#include<algorithm>
#include <string>
#include<cstdio>
#include<stack>
#include<cstring>
#include<vector>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define D(n,retu) REP(i,n){cin>>retu[i];}

using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x%y) : x; }
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}

//------------------変数-----------------------//
ll n, m;
vector<vector<ll>>graph(19); bool graphb[19];
//-------------------関数----------------------//

ll DFS(ll point, ll count) {
	if (graphb[point]) { return 0; }
	count++;	
	if (count == n) { return 1; }
	graphb[point] = true;
	ll s = graph[point].size();
	ll a = 0;
	REP(i, s) {
		a+=DFS(graph[point][i], count);
	}
	graphb[point] = false;
	return a;
}

int main() {
	cin >> n >> m;
	REP(i, m) {
		ll a, b; cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	cout << DFS(1, 0) << endl;;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define int long long
#define MOD 998244353ll
using namespace __gnu_pbds;
using namespace std;

int n,s,a[3010],dp[3010][3010];

inline void add(int &x,int y)
{
	x+=y;
	if(x>=MOD) x-=MOD;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>s;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++){
		for(int j=0;j<=s;j++){
			add(dp[i][j],dp[i-1][j]);
			if(j-a[i]>=0ll){
				add(dp[i][j],dp[i-1][j-a[i]]);
				if(j-a[i]==0ll) add(dp[i][j],i);
			}
		}
	}
	int sum=0ll;
	for(int i=1;i<=n;i++){
		add(sum,dp[i][s]);
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 70784
#include <algorithm>
#include <iostream>
#include <utility>
#include <map>
#include <vector>
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> balls(n);
    for (int i=0;i<n;i++){
        cin >> balls[i];
    }

    map<int, int> counter;
    for(auto &i : balls){
        ++counter[i];
    }
    vector<pair<int,int>> counter_vec( counter.begin(), counter.end() );

    sort(counter_vec.begin(), counter_vec.end(), 
           []( const auto & lhs, const auto & rhs ) 
           { return lhs.second > rhs.second; } );
    
    int top_k=0;
    for (int i=0;i<k;i++){
        if (i < counter_vec.size()){
            top_k += counter_vec[i].second;
        } else {
            break;
        }
    }
    cout << n - top_k << endl;


    return 0;
}

Measured memory_bytes: 12032
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
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);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int main(){
    ll N,A[100007],K,M,ma=0,T=0;
    cin >> N >> K;
    rep(i,N){
        cin >> A[i];
        ma=max(A[i],ma);
        if(i==0){
            M=A[0];
        }
        if(A[i]==K){
            cout << "POSSIBLE" << endl;
            return 0;
        }
        if(i>0){
            if(A[i]!=A[i-1]){
                M=gcd(abs(A[i]-A[i-1]),M);
                T=1;
            }
        }
        else if(T==1 && A[i]!=A[i-1]){
            M=gcd(abs(A[i]-A[i-1]),M);
        }
        else if(T==1 && A[i]==A[i-1]){
            M=gcd(abs(A[i]),M);
        }
    }
    if(K>ma){
        cout << "IMPOSSIBLE" << endl;
    }
    else if(T==0){
        if(A[0]==K){
            cout << "POSSIBLE" << endl;
        }
        else{
            cout << "IMPOSSIBLE" << endl;
        }
    }
    else{
        if((ma-K)%M==0){
            cout << "POSSIBLE" << endl;
        }
        else{
            cout << "IMPOSSIBLE" << endl;
        }
    }
}


Measured memory_bytes: 1024
use proconio::{
   fastout, input,
   marker::{Bytes, Chars, Isize1, Usize1},
};

fn main() {
   input! {
      n:usize,m:usize
   }
   let mut f = 1;
   let mut t = if m % 2 == 0 { m + 1 } else { m };
   for i in 0..m {
      if f == t {
         f = if m % 2 == 0 { m + 2 } else { m + 1 };
         t = 2 * m + 1
      }
      println!("{} {}", f, t);
      f += 1;
      t -= 1;
   }
}


Measured memory_bytes: 2136
#include"bits/stdc++.h"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
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 A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill( (T*)array, (T*)(array+N), val ); }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
int main() {
    int n;
    cin >> n;
    cout << 1000 * ceil((double)n / 1000) - n << endl;
    return 0;
}

Measured memory_bytes: 3784
#include<cstdio>
#include<algorithm>
int main(){
	int n,c;
	scanf("%d%d",&n,&c);
	int d[c][c]={};
	for(int i=0;i<c;i++){
		for(int j=0;j<c;j++){
			scanf("%d",&d[i][j]);
		}
	}
	int a[n][n]={};
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			scanf("%d",&a[i][j]);
			a[i][j]--;
		}
	}
	int b[3][50]={};
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<c;k++){
				b[(i+j)%3][k]+=d[a[i][j]][k];
			}
		}
	}
	int ans=b[0][0]+b[1][1]+b[2][2];
	for(int i=0;i<c;i++){
		for(int j=0;j<c;j++){
			for(int k=0;k<c;k++){
				if(i!=j && j!=k && k!=i){
					ans=std::min(ans,b[0][i]+b[1][j]+b[2][k]);
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1152
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n,k = i_map()
    a = i_list()
    print(math.ceil((n-1)/(k-1)))

if __name__=="__main__":
    main()


Measured memory_bytes: 85172
// In The Name Of Allah
// Mehrkish Makuei

#include <bits/stdc++.h>

#define pb push_back
#define debug1(x) cerr << #x << " : " << x << endl;
#define debug2(x, y ) cerr << #x << " : " << x << "  " << #y << " : " << y << endl;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef vector <ll> vll;
typedef set <char> sch;
typedef set <ll> sll;

const ll MOD = 1e9 + 7;
const ll MAXN = 1e5 + 19;

ll n, a[MAXN], dp[MAXN], k;

int main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	for ( int i = 0; i < n; i++ )
		cin >> a[i];
	dp[1] = abs( a[1] - a[0] );
	for ( int i = 2; i < n; i++ ){
		dp[i] = 9999999999999;
		ll y = i;
		ll x = min(k, y );
		for ( int j = i - x; j < i; j++ ){
			dp[i] = min( dp[i], abs( a[i] - a[j] ) + dp[j] );
		}
	}
	for ( int i = 0; i < n; i++ )
		cerr << dp[i] << " ";
	cerr << endl;
	cout << dp[n - 1] << endl;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  int Alice = 0;
  int Bob = 0;
  vector<int> Card(N);
  for(int i = 0; i < N; i++){
    cin >> Card.at(i);
  }
  sort(Card.begin(), Card.end());
  reverse(Card.begin(), Card.end());
  for(int a = 0; a < N; a++){
    if(a % 2 == 0){
      Alice += Card.at(a);
    }
    if(a % 2 != 0){
      Bob += Card.at(a);
    }
  }
  cout << Alice - Bob << endl;
  
  

}


Measured memory_bytes: 3628
# include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
template<typename T>vector<T> make_v(size_t a){ return vector<T>(a); }
template<typename T,typename... Ts>auto make_v(size_t a, Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_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); }
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, k;

int main(){
    cin >> n >> k;
    cout << n - k + 1 << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+50;
inline int gi() {
  char ch=getchar(); int q=0,x=0;
  while(ch<'0'||ch>'9') q=(ch=='-'?1:q),ch=getchar();
  while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
  return q?(-x):x;
}
int a[N],f[N],P;
void ins(int x){
  while(x<=P)
    ++f[x],x+=x&-x;
  return;
}
int qry(int x){
  if (x<=0) return 0;
  int s=0;
  while(x)
    s+=f[x],x-=x&-x;
  return s;
}
int main(){
  int n=gi(),l=0,r=0,mid;
  for (int i=1; i<=n; ++i) a[i]=gi(),r=max(r,a[i]);
  ll ans,sum=1ll*n*(n+1)/2-1ll*n*(n+1)/4; P=2*n;
  while(l<=r){
    mid=(l+r)>>1,ans=0;
    memset(f,0,sizeof(f));
    int num=0;
    for (int i=1; i<=n; ++i){
      ins(num+n);
      if (a[i]>=mid) ++num;
      else --num;
      ans+=qry(num+n);
    }
    if (ans>=sum) l=mid+1;
    else r=mid-1;
  }
  cout<<r;
  return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
int main(void){
  char s[100000];
  int length,i,count1,count2;
  scanf("%s",s);

  for(length=0;s[length]=='1'||s[length]=='0';length++);
  for(i=0;i<length;i++){
    if(i%2==0){
      if(s[i]!='0'){
        count1++;
      }
    }else if(i%2!=0){
      if(s[i]=='0'){
        count1++;
      }
    }
    }

  for(i=0;i<length;i++){
    if(i%2!=0){
      if(s[i]!='0'){
        count2++;
      }
    }else if(i%2==0){
      if(s[i]=='0'){
        count2++;
      }
    }
  }

  if(count1>count2){
    printf("%d\n",count2);
  }else{
    printf("%d\n",count1);
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e9;
const int Bmax=2e5;
const int Nd=61;

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int main(){
  ll a,b; cin>>a>>b;
  ll g=gcd(a,b);
  auto s=prime_factorize(g);
  cout<<int(s.size())+1<<endl;



}


Measured memory_bytes: 3616
//2018.9.27 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-15
inline int read(){
    res s=0;
    bool w=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=1;ch=getchar();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return w?-s:s;
}
inline void _swap(res &x,res &y){
    x^=y^=x^=y;
}
inline int _abs(const res &x){
    return x>0?x:-x;
}
inline int _max(const res &x,const res &y){
    return x>y?x:y;
}
inline int _min(const res &x,const res &y){
    return x<y?x:y;
}
const int N=1e4+10;
namespace MAIN{
    char str[N];
    int w,e,n,s;
    inline void MAIN(){
        scanf("%s",str);
        for(res i=0,siz=strlen(str);i<siz;i++)
            if(str[i]=='W')w=1;
            else if(str[i]=='E')e=1;
            else if(str[i]=='N')n=1;
            else if(str[i]=='S')s=1;
        puts(w==e&&n==s?"Yes":"No");
    }
}
int main(){
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 256
#include<queue>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=100000+15;
struct number
{
	int v,cnt;
	#define v(a,i) a[i].v
	#define v(b,i) b[i].v
	#define c(a,i) a[i].cnt
	#define c(b,i) b[i].cnt
}a[MAXN],b[MAXN];
bool cmp(number a,number b)
{return a.cnt > b.cnt;}
int main()
{
    int n,v;
    scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&v);
		if(i%2==1){c(a,v)++;v(a,v)=v;}
		else{c(b,v)++;v(b,v)=v;}
	} 
	sort(a+1,a+1+MAXN,cmp);
	sort(b+1,b+1+MAXN,cmp);
	if(v(a,1)!=v(b,1))printf("%d",n-c(a,1)-c(b,1));
	else
	{
		if(c(a,2)>c(b,2))printf("%d",n-c(a,2)-c(b,1));
		else printf("%d",n-c(a,1)-c(b,2));
	}return 0;
}

Measured memory_bytes: 1792
n,l= map(int,input().split())
li = []
for i in range(n):
    li.append(l)
    l += 1
ans = 0
li_min = float('inf')
for i in range(len(li)):
    li_min = min(abs(li[i]),li_min)
for i in range(len(li)):
    if li_min == abs(li[i]):
        li[i] = 0
print(sum(li))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>

using namespace std;
#define mod 1000000007
#define ll long long 


ll n,w, a[100009], b[100009];
ll dp[109][100009];

// map<int, map<ll, ll> > dp;
 
ll solve(int idx, ll W) {
    if(idx == n)
        return 0;
    
    if(dp[idx][W] != -1)
    	return dp[idx][W];

    // if(dp.find(idx) != dp.end() && dp[idx].find(W) != dp[idx].end())
    // 	return dp[idx][W];

    ll ans = solve(idx + 1, W);
    if(a[idx] <= W)
    	ans = max(ans, b[idx] + solve(idx + 1, W - a[idx]));
    return dp[idx][W] = ans;
}
 
int main() {
 
    // int t;
    // cin>>t;
    // while(t--) {
        cin>>n>>w;
        memset(dp, -1, sizeof(dp));

        for(int i = 0; i < n; i++) {
            cin>>a[i]>>b[i];
        }
 
        cout<<solve(0, w)<<endl;
}

Measured memory_bytes: 86272
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

//mod(1e9+7)
const ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x = 0) : x(x % mod){}
    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
};

// nCr
struct com {
    ll MAX;
    ll mod;
    vll fac, finv, inv;
    com(ll n, ll MOD) {
        mod = MOD; 
        COMinit(n);
    }
    void COMinit(ll n) {
        MAX = n;
        fac.resize(MAX);
        finv.resize(MAX);
        inv.resize(MAX);
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i <= MAX; i++) {
            fac[i] = fac[i-1] * i % mod;
            inv[i] = mod - inv[mod%i] * (mod/i) % mod;
            finv[i] = finv[i-1] * inv[i] % mod;
        }
    }   

    ll cal(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
    } 
};

int main() {
    int n; cin >> n;
    map<int,int> ct;
    vint a(n+1);
    rep(i,n+1) {
        int a_; cin >> a_;
        ct[a_]++;
        a[i] = a_;
    }
    int x;
    for (auto itr = ct.begin(); itr != ct.end(); itr++) {
        if (itr->second == 2) x = itr->first;
    }
    int len_r;
    for (int i = n; i >= 0; i--) {
        if (a[i] == x) {len_r = n-i; break;}
    }
    int len_l;
    for (int i = 0; i <= n; i++) {
        if (a[i] == x) {len_l = i; break;}
    }
    if (len_l > len_r) swap(len_l,len_r);
    // cout << len_l << len_r << endl;
    com cm(MAX+5,mod);
    REP(i,n+2) {
        mint tmp;
        tmp = cm.cal(n+1,i);
        if (i == 1) tmp -= 1;
        else tmp -= cm.cal(len_l+len_r,i-1);
        printf("%lld\n",tmp.x);
    }
}

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

using namespace std;

int main(){
  long long int n, x;
  cin >> n >> x;
  vector<long long int> vec(n);
  for(int i = 0; i < n; ++i) cin >> vec[i];
  long long int ans = 0;
  for(int i = 1; i < n; ++i){
    if ( vec[i]+vec[i-1] <= x) continue;
    ans += max((vec[i]+vec[i-1])-x, 0ll);
    vec[i] -= min(vec[i], (vec[i]+vec[i-1])-x);
  }

  cout << ans << endl;

}


Measured memory_bytes: 1152
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,a[101010]={},b[101010]={};
	cin>>n;
	FOR(i,0,n)cin>>a[i];
	sort(a,a+n);
	LL sum=0;
	FOR(i,0,n-1){
		sum+=a[i];
		if(sum*2>=a[i+1]){
			b[i]=1;
		}
	}
	b[n-1]=1;
	FORD(i,n,0){
		if(b[i]==0){
			cout<<n-1-i<<endl;
			return 0;
		}
	}
	cout<<n<<endl;

    return 0;
}


Measured memory_bytes: 1024