akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int dp[100];
int n;

int main(void){

  dp[1] = dp[0] = 1;
  cin >> n;

  for( int i = 2 ; i <= n ; i++ )
    dp[i] = dp[i - 1] + dp[i - 2];

  cout << dp[n] << endl;

  return 0;
}

Measured memory_bytes: 1160
function Main(s){
  const n = parseInt(s);
  var a = [];
  var b = 0;
  var j = 3;
  for(var i = 0; i < (n + 1 >> 2) * 2; i++){
    while(j % 3 !== 0 && j % 5 !== 0){
      j += 2;
    }
    if(j > 30000) break;
    a[i] = j;
    b += j;
    j += 2;
  }
  j = 1;
  for(; i < n - 1; i++){
    a[i] = j++ * 2;
    b += a[i];
  }
  a[n-1] = Math.ceil(a[n-2] / 30) * 30 - b % 30 + 30;
  console.log(a.join(" "));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9036
from math import *
while True:
    n = 0
    n = int(input())
    if n == 0:
        break
    else :
        sco = map(int,raw_input().split())
        for i in range(n):
            ave=0.0
            for i in sco:
                ave += i
            ave /= n
            dev = 0.0
            for i in sco:
                dev += (i-ave)*(i-ave)
            dev /= n
        print sqrt(dev)

Measured memory_bytes: 6440
#include <iostream>
#include <queue>
#define MAX 5010
using namespace std;

class edge{
public:
    int start;
    int goal;
    int cost;
    edge(){
        start = 0;
        goal = 0;
        cost = MAX;
    }
};
bool operator< (const edge &edge1, const edge &edge2){
    return edge1.cost < edge2.cost;
}
bool operator> (const edge &edge1, const edge &edge2){
    return edge1.cost > edge2.cost;
}

int P[101];
void init(int N){
    for(int i=0;i<=N;i++)
        P[i] = i;
}
int root(int a){
    if(P[a]==a)
        return a;
    return(P[a] = root(P[a]));
}
bool is_same_set(int a, int b){
    return root(a) == root(b);
}
void unit(int a, int b){
    P[root(a)] = root(b);
}

int main(){
    int n,m;
    while(cin >> n >> m && n!=0){
        init(n);
        int total = 0;
        vector<edge> v;
        for(int i=0;i<m;i++){
            edge tmp;
            cin >> tmp.start >> tmp.goal >> tmp.cost;
            v.push_back(tmp);
        }
        priority_queue<edge, vector<edge>, greater<edge> > p(v.begin(),v.end());
        for(int i=0;i<m;i++){
            edge tmp = p.top();
            p.pop();
            if(!is_same_set(tmp.start,tmp.goal)){
                total += tmp.cost;
                unit(tmp.start,tmp.goal);
            }
        }
        cout << total << endl;
    }
}

Measured memory_bytes: 1204
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <string>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,P> pip;
typedef long long ll;
const int inf=1<<30;
const double pi=acos(-1);

int n;
vi sosu;
map<int,bool> m;

int main(){
	vector<bool> used(50005,1);
	for(int i=2;i<50000;i++){
		if(used[i]){
			sosu.push_back(i);
			m[i]=1;
			for(int j=i;j<50000;j+=i) used[j]=0;
		}
	}
	while(1){
		cin>>n;
		if(!n) break;
		int ans=0;
		if(n%2){
			if(m[n-2]) cout<<1<<endl;
			else cout<<0<<endl;
			continue;
		}
		for(int i=0;sosu[i]<=n/2;i++){
			if(m[n-sosu[i]]) ans++;
		}
		cout<<ans<<endl;
	}
}

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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


signed main(){
    int n;
    cin >> n;
    vector<int> u(n - 1), v(n - 1);
    vector<vector<int>> edges(n);
    for(int i = 0; i < n - 1; ++i){
        cin >> u[i] >> v[i];
        --u[i], --v[i];
        edges[u[i]].push_back(v[i]);
        edges[v[i]].push_back(u[i]);
    }
    vector<int> a(n), b(n);
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    for(int i = 0; i < n; ++i)
        cin >> b[i];
    vector<int> diff(n);
    for(int i = 0; i < n; ++i)
        diff[i] = b[i] - a[i];

    vector<int> siz(n, -MOD);
    siz[0] = diff[0];
    vector<tuple<int, int, int>> diff_edges;
    function<void(int)> f = [&](int x){
        for(auto y : edges[x]){
            if(siz[y] == -MOD){
                siz[y] = diff[y];
                f(y);
                // x側からy側にsiz[y]だけ送りたい
                diff_edges.emplace_back(x, y, siz[y]);
                siz[x] += siz[y];
            }
        }
    };
    f(0);

    // 逆辺
    vector<vector<pair<i64, i64>>> sc_edges(n);
    for(int i = 0; i < n - 1; ++i){
        sc_edges[get<0>(diff_edges[i])].emplace_back(get<1>(diff_edges[i]), get<2>(diff_edges[i]));
        sc_edges[get<1>(diff_edges[i])].emplace_back(get<0>(diff_edges[i]), -get<2>(diff_edges[i]));
    }
    vector<i64> val(n, -INF);
    function<void(int)> g = [&](int x){
        for(auto& ed : sc_edges[x]){
            i64 y, dist;
            tie(y, dist) = ed;
            if(val[y] == -INF){
                val[y] = val[x] - dist;
                g(y);
            }
        }
    };
    val[0] = 0;
    g(0);
    i64 min_elm = *min_element(val.begin(), val.end());

    for(int i = 0; i < n; ++i)
        val[i] -= min_elm;

    i64 ans = 0;
    for(int i = 0; i < n; ++i)
        ans += val[i];
    cout << ans << endl;

}



Measured memory_bytes: 25468
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 314159
#define  vi vector<int>
#define  v  vector

bool comp(int a,int b)
{
    return (10-a%10)%10<(10-b%10);
}

signed main() 
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int arr[6];
    forn(i,1,5)cin>>arr[i];
    
    sort(arr+1,arr+1+5,comp);
    int d=-1,ip=1;
    /*forn(i,1,5)
    {
        if(arr[i]%10)
        {
            if(d<10-arr[i]%10){
                d=arr[i]%10;
                ip=i;
            }
        }
    }
    swap(arr[ip],arr[5]);
    */
    //forn(i,1,5)cout<<arr[i]<<" ";
    int ans=0;
    forn(i,1,5)
    {
        ans+=arr[i];
        if(arr[i]%10 and i<5)ans+=10-arr[i]%10;
    }
    cout<<ans;


     return 0;

}

//       g++ -g c.cpp ; ./a.exe

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define pb emplace_back
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define rep(i, j, k) for(i=j; i<k; i++)
#define sep(i, j, k) for(i=j; i>k; i--)
const int N = 1e3+5, inf = 1e9+7;
int n, k, i, j;
int A[N], dp[N][N];
string s[N];

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int i, j, a, b, ans = 0;
    cin>>n>>k;
    rep(i, 0, n) cin>>s[i];
    dp[0][0] = 1;
    rep(i, 0, n) rep(j, 0, k) if(s[i][j]=='.'){
        if(i) dp[i][j] += dp[i-1][j];
        if(j) dp[i][j] += dp[i][j-1];
        dp[i][j]%=inf;
    }
    cout<<dp[n-1][k-1];
}

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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

template<const int CHAR_NUM = 26, const char FIRST_CHAR = 'a', const int NONE = -1>
struct Trie {
    struct Node {
        bool word_exists;
        int cnt[CHAR_NUM];
        int idxs[CHAR_NUM]; // idxs[c - FIRST_CHAR]: 次の文字がcであるNodeの場所(treeのindex)
        Node() : word_exists(false) {
            fill(idxs, idxs + CHAR_NUM, NONE);
            fill(cnt, cnt + CHAR_NUM, 0);
        };
    };

    vector<Node> tree;

    Trie() {
        tree.emplace_back();
    }

    void insert(string& s) {
        char last_char = s.back();
        s.pop_back();

        int cur = 0;
        for (char c : s) {
            if (tree[cur].idxs[c - FIRST_CHAR] == NONE) {
                tree[cur].idxs[c - FIRST_CHAR] = tree.size();
                tree.emplace_back();
            }
            cur = tree[cur].idxs[c - FIRST_CHAR];
        }
        tree[cur].word_exists = true;
        tree[cur].cnt[last_char - FIRST_CHAR]++;
    }

    bool find(const string& s) {
        int cur = 0;
        for (char c : s) {
            if (tree[cur].idxs[c - FIRST_CHAR] == NONE) {
                return false;
            }
            cur = tree[cur].idxs[c - FIRST_CHAR];
        }
        return tree[cur].word_exists;
    }

    int count(const string& s) {
        int res = 0;
        int cur = 0;
        array<int, CHAR_NUM> counter{};
        for (int i = 0; i < CHAR_NUM; i++) {
            counter[i] = tree[cur].cnt[i];
        }
        bool f = false;
        for (char c : s) {
            res += counter[c - FIRST_CHAR];
            counter[c - FIRST_CHAR] = 0;

            if (tree[cur].idxs[c - FIRST_CHAR] == NONE) {
                f = true;
            }
            if (f) continue;
            cur = tree[cur].idxs[c - FIRST_CHAR];

            for (int i = 0; i < CHAR_NUM; i++) {
                counter[i] += tree[cur].cnt[i];
            }
        }
        return res;
    }
};

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

    int n;
    cin >> n;

    vector<string> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        reverse(v[i].begin(), v[i].end());
    }
    sort(v.begin(), v.end(), [&](const string& s1, const string& s2) {
        return s1.size() < s2.size();
    });

    ll ans = 0;
    Trie<> t;
    for (string& s : v) {
        ans += t.count(s);
        t.insert(s);
    }
    cout << ans << newl;

    return 0;
}

Measured memory_bytes: 223640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n, m;
    cin >> n >> m;
    string ans(n, 'x');
    rep(i, m) {
        int s, c;
        cin >> s >> c;
        c += '0';
        --s;
        if(ans[s] == 'x') ans[s] = c;
        else if(ans[s] != c) {
            cout << -1 << endl;
            return 0;
        }
    }
    if(ans[0] == 'x') {
        if(n == 1) ans[0] = '0';
        else ans[0] = '1';
    }
    REP(i, 1, 3) if(ans[i] == 'x') ans[i] = '0';
    if(n > 1 && ans[0] == '0') {
        cout << -1 << endl;
        return 0;
    } 
    cout << ans << endl;
    return 0;
}

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

using namespace std;

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

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 100;
int64 C[N][N];

int main() {
  for (int i = 0; i < N; ++i) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; ++j) {
      C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    }
  }
  int n, L, R;
  scanf("%d%d%d", &n, &L, &R);
  vector<int64> a(n);
  map<int64, int> A, B;
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
    A[a[i]]++;
  }
  sort(a.begin(), a.end());
  double ret = 0;
  for (int i = n - L; i < n; ++i) {
    ret += a[i];
  }
  ret /= L;
  int64 ans = 0;
  for (int k = n - L; k >= n - R; --k) {
    if (k != n - L && a[k] != a[n - 1]) break;
    int64 cur = 1;
    B.clear();
    for (int i = k; i < n; ++i) {
      B[a[i]]++;
    }
    for (int i = k; i < n; ++i) {
      if (i > k && a[i] == a[i - 1]) continue;
      int64 x = a[i];
      cur *= C[A[x]][B[x]];
    }
    ans += cur;
  }
  printf("%.10f\n%lld\n", ret, ans);
  return 0;
}


Measured memory_bytes: 384
/*huzaifa242 copyright*/
#include <bits/stdc++.h>
using namespace std;
#define PI 3.1415926535897932384626
#define mod 1000000007
#define MAX 100005
int dp[MAX];
vector<int> adj[MAX];
int dfs(int x)
{
    if(dp[x]!=0)
    return dp[x];
    for(int i=0;i<adj[x].size();i++)
    {
        dp[x]=max(dp[x],dfs(adj[x][i])+1);
    }
    return dp[x];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);  
    #endif
    int i,n,m,u,v;
    memset(dp,0,sizeof(dp));
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>u>>v;
        adj[u].push_back(v);
    }
    for(i=1,u=0;i<=n;i++)
    {
        if(dp[i]==0)
        dfs(i);
        u=max(u,dp[i]);
        //cout<<i<<" "<<dp[i]<<"\n";
    }
    cout<<u<<"\n";
    return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int inf = 1e9;

int n, k, s;

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

int main() {
    read(n), read(k), read(s);
    for (R int i = 1; i <= k; ++i)
        printf("%d ", s);
    for (R int i = k + 1; i <= n; ++i)
        printf("%d ", s % inf + 1);
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s, t;
    bool ans = true;
    cin >> s >> t;
    vector<int> table_s(26, 0), table_t(26, 0);
    for (int i = 0; i < s.size(); ++i)
    {
        table_s[s[i] - 'a']++;
        table_t[t[i] - 'a']++;
    }
    sort(table_s.begin(), table_s.end());
    sort(table_t.begin(), table_t.end());
    for (int i = 0; i < table_s.size(); ++i)
    {
        if (table_s[i] != table_t[i])
        {
            ans = false;
            break;
        }
    }
    if (ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 776
#include <iostream>
#include <string>
using namespace std;
 
// http://www.prefield.com/algorithm/misc/dice.html
enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
class dice {
public:
    dice(int top,int front,int right,int left,int back,int bottom) {
        id[TOP] = top; id[FRONT] = front; id[RIGHT] = right;
        id[LEFT] = left; id[BACK] = back; id[BOTTOM] = bottom;
    }
    int& operator[] (FACE f) { return id[f]; }
    const int& operator[] (FACE f) const { return id[f]; }
    bool operator==(const dice &b) const {
        const dice &a = *this;
        return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
            a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
             a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
    }
    void roll_north() { roll(TOP, FRONT, BOTTOM, BACK); }
    void roll_south() { roll(TOP, BACK, BOTTOM, FRONT); }
    void roll_east() { roll(TOP, LEFT, BOTTOM, RIGHT); }
    void roll_west() { roll(TOP, RIGHT, BOTTOM, LEFT); }
    void roll_right() { roll(FRONT, LEFT, BACK, RIGHT); }
    void roll_left() { roll(FRONT, RIGHT, BACK, LEFT); }
private:
    void roll(FACE a, FACE b, FACE c, FACE d){
        int tmp = id[a];
        id[a] = id[b]; id[b] = id[c];
        id[c] = id[d]; id[d] = tmp;
    }
    int id[6];
};
 
int main(){
    int d[6];
    for(int i=0;i<6;i++)cin>>d[i];
    dice di(d[0],d[1],d[2],d[3],d[4],d[5]);
    string line;
    cin>>line;
    for(int i=0;i<line.size();i++){
        if(line[i]=='N')di.roll_north();
        if(line[i]=='E')di.roll_east();
        if(line[i]=='W')di.roll_west();
        if(line[i]=='S')di.roll_south();
    }
    cout<<di[TOP]<<endl;
}


Measured memory_bytes: 3180
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  //input
  int N;
  long long int W;
  cin >> N >> W;
  long long int w[N];
  long long v[N];
  long long int totalw;
  for(int i=0; i<N; i++){cin >> w[i] >> v[i];}
  
  //main
  int INF = 1e9;
  long long memo[N+10][W+10];
  
  //DPtable i番目(0~N)まででjの重さ
  for(int i=0; i<N+1; i++){
    for(int j=0; j<W+1; j++){
      //if(i==0) memo[i][j] = 0;
      memo[i][j] = 0;
    }
  }
  
  for(int i=0; i<N; i++){
    for(int sum=0; sum<W+1; sum++){
      // i 番目の品物を選ぶ場合
            if (sum - w[i] >= 0) {
                chmax(memo[i+1][sum], memo[i][sum - w[i]] + v[i]);
            }

            // i 番目の品物を選ばない場合
            chmax(memo[i+1][sum], memo[i][sum]);
    }
  }
  
  //output  
  cout << memo[N][W] << endl;
}


Measured memory_bytes: 80640
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cstdio>

using namespace std;

int main()
{
    int64_t n, k;
    cin >> n >> k;
    auto a = n % k;
    auto b = std::abs(a - k);
    if (a < b)
        cout << a;
    else
    {
        cout << b;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
inline long long in(){long long x=0;char c=getchar();bool neg=false;while(c!='-'&&('0'>c||c>'9')) c=getchar();if(c=='-') neg=true,c=getchar();while('0'<=c&&c<='9') x=10*x+c-'0',c=getchar();if(neg) x=-x;return x;}
inline void out(long long x){if(x<0) putchar('-'),x=-x;if(x>9) out(x/10);putchar(x%10+'0');}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "h"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define _ putchar(' ')
#define __ putchar('\n')
const int N=1010;
const int M=1e9+7;
int m,n;
char ch;
int f[N][N];
main()
{
    fasty;
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    cin>>m>>n;
    f[1][1]=1;
    forinc(i,1,m) forinc(j,1,n)
    {
        cin>>ch;
        if(ch=='#') continue;
        f[i][j]+=(f[i-1][j] + f[i][j-1])%M;
    }
    cout<<f[m][n];
}



Measured memory_bytes: 8192
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 98765
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

int a[100005], tree[200010], n;
void upd(int i)
{
	while (i <= 2 * n + 5)
	{
		tree[i]++;
		i += (i&-i);
	}
}
int sum(int i)
{
	int c = 0;
	while (i > 0)
	{
		c += tree[i];
		i -= (i&-i);
	}
	return c;
}
bool ok(int m)
{
	MEM0(tree);
	ll rlwns = (1LL * n*(n + 1) / 2 + 1) / 2;
	ll c = 0;
	int now = n + 1;
	upd(now);
	fup(i, 0, n - 1, 1)
	{
		now += (a[i] >= m ? 1 : -1);
		c += sum(now);
		upd(now);
	}
	return c >= rlwns;
}
int main() {
	scanf("%d", &n);
	fup(i, 0, n-1, 1)scanf("%d", a + i);
	int l = 1, r = 1e9;
	while (l <= r)
	{
		int m = (l + r) >> 1;
		if (ok(m))l = m + 1;
		else r = m - 1;
	}
	printf("%d", r);
}


Measured memory_bytes: 1408
n=int(input())
s=[list(map(int, input().split())) for i in range(n)]

dp0=[0]*n
dp1=[0]*n
dp2=[0]*n

dp0[0]=s[0][0]
dp1[0]=s[0][1]
dp2[0]=s[0][2]

for i in range(1,n):
    dp0[i]=max(dp1[i-1]+s[i][0],dp2[i-1]+s[i][0])
    dp1[i]=max(dp0[i-1]+s[i][1],dp2[i-1]+s[i][1])
    dp2[i]=max(dp0[i-1]+s[i][2],dp1[i-1]+s[i][2])

print(max(dp0[n-1],dp1[n-1],dp2[n-1]))

Measured memory_bytes: 42444
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<vector<int> > x(n+1), d(n+1);
        vector<vector<vector<int> > > dp(n+1);
        for(int i=1; i<=n; ++i){
            int k;
            cin >> k;
            for(int j=0; j<k; ++j){
                int a, b;
                cin >> a >> b;
                x[i].push_back(a);
                d[i].push_back(b);
                if(i <= 2){
                    dp[i].push_back(vector<int>(m+1, 0));
                    if(i == 2)
                        dp[i].back()[m] = INT_MAX/2;
                }
                else
                    dp[i].push_back(vector<int>(m+1, INT_MAX/2));
            }
        }

        for(int i=1; i<n; ++i){
            for(unsigned j=0; j<x[i].size(); ++j){
                for(unsigned k=0; k<x[i+1].size(); ++k){
                    for(int l=0; l<=m; ++l)
                        dp[i+1][k][l] = min(dp[i+1][k][l], dp[i][j][l] + (d[i][j]+d[i+1][k]) * abs(x[i][j]-x[i+1][k]));
                }
                if(i == n-1)
                    continue;
                for(unsigned k=0; k<x[i+2].size(); ++k){
                    for(int l=1; l<=m; ++l)
                        dp[i+2][k][l-1] = min(dp[i+2][k][l-1], dp[i][j][l] + (d[i][j]+d[i+2][k]) * abs(x[i][j]-x[i+2][k]));
                }
            }
        }

        int ret = INT_MAX;
        for(unsigned i=0; i<x[n].size(); ++i)
            ret = min(ret, dp[n][i][0]);
        if(m > 0){
            for(unsigned i=0; i<x[n-1].size(); ++i)
                ret = min(ret, dp[n-1][i][1]);
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 1424
def resolve():
    n = int(input())
    ans = [0]*(n+1)
    for i in range(1, int(n**0.5)+1):
        for j in range(1, int(n**0.5)+1):
            for k in range(1, int(n**0.5)+1):
                if (i**2 + j**2 + k **2 + i*j+i*k+j*k) <= n:
                    ans[i**2 + j**2 + k **2 + i*j+i*k+j*k] += 1
    for i in range(1,n+1):
        print(ans[i])
resolve()

Measured memory_bytes: 69556
n,m=map(int,input().split());a,b=[set(map(int,input().split())) for j in range(2)];c=1;N=M=0
for k in range(m*n,0,-1):
 A=k in a;B=k in b
 if A and B:M+=1;N+=1
 elif A:c*=M;N+=1
 elif B:c*=N;M+=1
 else:c*=M*N-m*n+k
 c%=10**9+7
print(c)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N;
    int ans = INT_MAX;
    int A;
    cin >> N;
    for(int i=0; i<N; i++){
        int crack_count = 0;
        cin >> A;
        while(A%2 == 0){
            A/=2;
            crack_count++;
        }
        ans = min(ans,crack_count);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect
import functools

def BubbleSort(A):
    cnt = 0
    for i in range(len(A)):
        for j in range(len(A)-1,i,-1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                cnt += 1
    return cnt
n = int(input())
A = list(map(int,input().split()))
cnt = BubbleSort(A)
print(*A)
print(cnt)


Measured memory_bytes: 6364
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 1000000000
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
//int fx[]={0,0,1,-1};
//int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
const int N=100010;
int dp[1040][10004];
int Hp[1040],mp[1003];
int n;
int call(int idx,int hp)
{
    if(hp<=0)return 0;
    if(idx==n)return inf;
    if(dp[idx][hp]!=-1)return dp[idx][hp];
    int f1=mp[idx]+call(idx,hp-Hp[idx]);
    int f2=call(idx+1,hp);
    return dp[idx][hp]=min(f1,f2);
}
int main()
{
    IOS;
    meM(dp,-1);
    int h;
    cin>>h>>n;
    for(int i=0;i<n;i++)
        cin>>Hp[i]>>mp[i];
    cout<<call(0,h)<<endl;
}








Measured memory_bytes: 44800
#include <stdio.h>

void move(int dir, int* i, int* j, int k);
void forward(int dir, int* i, int* j, int k);
void backward(int dir, int* i, int* j, int k);

void turn(int turn, int* currentDir);
void right(int* currentDir);
void left(int* currentDir);
	
int main(void){
	
	int m, n,
		i, j, dir,
		k;
	char com[9];
	
	// BEGIN OF BOARD
	while(1){
		
		/*
		*	dir
		*	0:north, 1:east, 2:south, 3:west
		*
		*/
		i = 0; j = 0; dir = 0;
		scanf("%d", &m);
		scanf("%d", &n);
		if(m==0 && n==0) break;
		
		// BEGIN OF COMMAND
		while(1){
			
			scanf("%s", com);
			
			if(com[0] == 'S') break;
			if(com[0] == 'F'){
				scanf("%d", &k);
				forward(dir, &i, &j, k);
			}
			if(com[0] == 'B'){
				scanf("%d", &k);
				backward(dir, &i, &j, k);
			}
			if(com[0] == 'R'){
				right(&dir);
			}
			if(com[0] == 'L'){
				left(&dir);
			}
			
			if(i >= m) i = m-1;
			if(j >= n) j = n-1;
			if(i < 0) i = 0;
			if(j < 0) j = 0;
			
		}
		// END OF COMMAND
		
		printf("%d %d\n", i+1, j+1);
		
	}
	// END OF BOARD
	
	return 0;
}

void forward(int dir, int* i, int* j, int k){
	move(dir, i, j, k);
}

void backward(int dir, int* i, int* j, int k){
	move(dir, i, j, -k);
}

void move(int dir, int* i, int* j, int k){
	switch(dir){
	case 0:
		*j += k;
		break;
	case 1:
		*i += k;
		break;
	case 2:
		*j -= k;
		break;
	case 3:
		*i -= k;
		break;
	}
}

void turn(int turn, int* currentDir){
	*currentDir = (*currentDir + turn) % 4;
	if(*currentDir < 0) * currentDir += 4;
}

void right(int* currentDir){
	turn(1, currentDir);
}

void left(int* currentDir){
	turn(-1, currentDir);
}

Measured memory_bytes: 0
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long 
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define print_time cerr << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
   // cout<<x<<' '<<y<<endl;
    if(y==0)
    return x;
    else
    return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
    if(m%2)
        r=(r*n)%p;
    n=(n*n)%p;
    m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
 
    // This is checked so that we can skip 
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (int i=5; i*i<=n; i=i+6)
    if (n%i == 0 || n%(i+2) == 0)
       return false;
 
    return true;
}
vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r)
        z[i] = min (r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]])
        ++z[i];
    if (i + z[i] - 1 > r)
        l = i, r = i + z[i] - 1;
    }
    return z;
}
int32_t main()
{
   IOS;
   /*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin); 
   freopen("output.txt","w",stdout);
   #endif
   /********************* Code starts here ***********************/
   int a,b,c;
   cin>>a>>b>>c;
   int ans=0;
   if(a+b>=c)
   {
   	ans=c+b;
   }
   else
   {
   	ans=2*(b);
   	c-=b;
   	ans=ans+(min(c,a));
   	c-=min(a,c);
   	if(c>0)
   		ans++;	
   }
   cout<<ans<<endl;
}       	     	

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

int main() {
  string S;
  cin >> S;
  
  int N = S.size();
  
  
  for (int i = 0; i < N / 2; i++) {
    if (S.at(i) != S.at(N-1-i)) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  for (int i = 0; i < N/4; i++) {
    if (S.at(i) != S.at(N/2 -1-i)) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  
}

Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

void yesno(int ans) {
	if (ans == 1) {	printf("Yes\n");
	} else {		printf("No\n");	}
	return;
}

void okng(int ans) {
	if (ans == 1) { printf("OK\n");
	} else { 		printf("NG\n");	}
	return;
}

int main()
{
	int A = 0, B = 0, C = 0;
	scanf("%d %d %d", &A, &B, &C);
	int K = 0;
	scanf("%d", &K);

	// A aka, B green, C blue
	int i = 0;
	for (i = 0; i < K; i++) {
		if (A >= B) {
			B = B*2;
//			printf("B %d %d %d\n", A, B, C);
		} else if (B >= C) {
			C = C*2;
//			printf("C %d %d %d\n", A, B, C);
		}
	}

	int ans = 0;
//	printf("xx %d %d %d\n", A, B, C);
	if ((B > A) && (C > B)) {
		ans = 1;
	}
	yesno(ans);
	return 0;
}


Measured memory_bytes: 1616
a = input()
b = input()
c = input()

def match(c1, c2):
    return c1 == c2 or c1 == "?" or c2 == "?"

def check(x, y, l_m=2000):
    xy = [0] * (l_m * 8 + 1)
    mid = l_m * 4
    for i in range(len(x)):
        for j in range(len(y)):
            if not match(x[i], y[j]):
                xy[i - j + mid] = 1
    return xy

l_a = len(a)
l_b = len(b)
l_c = len(c)

ab = check(a, b)
ac = check(a, c)
bc = check(b, c)

l_m = 2000
mid = l_m * 4

ans = 3 * l_m
for i in range(-2 * l_m, 2 * l_m + 1):
    if ab[i + mid]:
        continue
    for j in range(-2 * l_m, 2 * l_m + 1):
        if ac[j + mid] or bc[j - i + mid]:
            continue

        lb = min(0, min(i, j))
        ub = max(l_a, max(l_b + i, l_c + j))
        ans = min(ans, ub - lb)

print(ans)


Measured memory_bytes: 53724
N,Q = map(int,input().split())
S = input()
point = [list(map(int,input().split())) for i in range(Q)]
ac_list = [0]*(N+1)
 
for i in range(N):
  if S[i:i+2] == 'AC':
    ac_list[i+1] = ac_list[i] + 1
  else:
    ac_list[i+1] = ac_list[i]
 
 
for i in range(Q):
  print(ac_list[point[i][1]-1] - ac_list[point[i][0]-1])

Measured memory_bytes: 30652
import Data.List (foldl1', sort)

intersection :: Ord a => [a] -> [a] -> [a]
intersection [] ys = []
intersection xs [] = []
intersection xs@(x:xs') ys@(y:ys')
  | x == y = x : intersection xs' ys'
  | x < y  = intersection xs' ys
  | x > y  = intersection xs ys'

main :: IO ()
main = do
  _ <- getLine
  ls <- map (sort . map read . tail. words) . lines 
            <$> getContents :: IO [[Int]]
  print $ length $ foldl1' intersection ls



Measured memory_bytes: 1020
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<59;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,q;

int main(){
	cin>>n>>q;
	for(int i=0;i<q;i++){
		int u,v;
		cin>>u>>v;
		if(n==1) cout<<min(u,v)<<endl;
		else{
			while(u!=v){
				if(u<v) swap(u,v);
				u=(u+n-2)/n;
			}
			cout<<u<<endl;
		}
	}
}

Measured memory_bytes: 1280
import sys
sys.setrecursionlimit(10**7)

n,m,*l=map(int,open(0).read().split())
graph=[[]*n for _ in range(n)]
unvis={i:True for i in range(n)}

def dfs(x):
	for y in graph[x]:
		if unvis[y]:
			unvis[y]=False
			dfs(y)
			
for i,j in zip(l[::3],l[1::3]):
	graph[i-1].append(j-1)
	graph[j-1].append(i-1)

ans=0
for x in range(n):
	if unvis[x]:
		unvis[x]=False
		dfs(x)
		ans+=1
print(ans)

Measured memory_bytes: 129036
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

using ld = long double;

const ll INF = 1ll << 60; 

ll solve(const vector<ld>& A, ll X) {
  int N = A.size();
  ll cnt = 0;
  for (int i = 0; i < N - 1; i++) {
	  if (A[i] == 0) {
		  if (X >= 0) {
			  cnt += N - i - 1;
		  }
		  continue;
	  }
	  if (A[i] < 0) {
		  auto it = lower_bound(A.begin() + i + 1, A.end(), (ld)X / A[i]);
		  cnt += distance(it, A.end());
	  } else {
		  auto it = upper_bound(A.begin() + i + 1, A.end(), (ld)X / A[i]);
		  cnt += distance(A.begin() + i + 1, it);
	  }
  }
	return cnt;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  ll K;
  while (cin >> N >> K) {
    vector<ld> A(N);
    for (auto& x : A) cin >> x;
    sort(A.begin(), A.end());
    ll fail = -INF, pass = INF;
    while (pass - fail > 1) {
      ll X = (pass + fail) / 2;
      if (solve(A, X) >= K) {
        pass = X;
      } else {
        fail = X;
      }
    }
    cout << pass << endl;
  }
  return 0;
}


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

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

int n;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	if (n % 2 == 0)
		n--;
	cout << n / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
// Date: 2020-04-27

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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout)
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define D(x) cout << #x << " = " << x << endl;
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int a[N], b[N], n;
int main() {
    FIO;
    cin >> n;
    rep(i, 1, n) cin >> a[i], b[i] = a[i];
    sort(b+1, b+1+n);
    int p = n / 2;
    rep(i, 1, n) {
        int j = lower_bound(b+1, b+1+n, a[i])-b;
        int tp = p-j+1;
        if(tp <= 0) cout << b[p] << '\n';
        else cout << b[j+tp] << '\n';
    }

    return 0;
}

Measured memory_bytes: 3840
#include <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
const char f[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
typedef unsigned long long ull;
int H, W, X, p[133], th[109][109], b[109][109]; char s[1009][177], t[109][22]; ull sh[1009][1009], sh1[1009][1009], sh2[1009][1009]; bool ok[1009][1009];
void rotate() {
	for (int i = 0; i < X; i++) {
		for (int j = 0; j < X; j++) {
			b[X - j - 1][i] = th[i][j];
		}
	}
	for (int i = 0; i < X; i++) {
		for (int j = 0; j < X; j++) {
			th[i][j] = b[i][j];
		}
	}
}
int main() {
	for (int i = 0; i < 64; i++) p[f[i]] = i;
	while (scanf("%d%d%d", &W, &H, &X), W) {
		for (int i = 0; i < H; i++) {
			scanf("%s", s[i]);
			for (int j = 0; j * 6 < W; j++) {
				for (int k = 0; k < 6; k++) {
					sh[i][j * 6 + k] = ((p[s[i][j]] & (1 << (5 - k))) ? 1 : 0);
				}
			}
		}
		ull base1 = 257, pw1 = 1;
		for (int i = 0; i < X; i++) pw1 *= base1;
		for (int i = 0; i < H; i++) {
			ull h = 0;
			for (int j = 0; j < X; j++) h = h * base1 + sh[i][j];
			for (int j = 0; j <= W - X; j++) {
				sh1[i][j] = h;
				if (j != W - X) h = h * base1 - pw1 * sh[i][j] + sh[i][j + X];
			}
		}
		ull base2 = 997, pw2 = 1;
		for (int i = 0; i < X; i++) pw2 *= base2;
		for (int i = 0; i <= W - X; i++) {
			ull h = 0;
			for (int j = 0; j < X; j++) h = h * base2 + sh1[j][i];
			for (int j = 0; j <= H - X; j++) {
				sh2[j][i] = h;
				if (j != H - X) h = h * base2 - pw2 * sh1[j][i] + sh1[j + X][i];
			}
		}
		for (int i = 0; i < X; i++) {
			scanf("%s", &t[i]);
			for (int j = 0; j * 6 < X; j++) {
				for (int k = 0; k < 6; k++) {
					th[i][j * 6 + k] = ((p[t[i][j]] & (1 << (5 - k))) ? 1 : 0);
				}
			}
		}
		for (int i = 0; i <= H - X; i++) {
			for (int j = 0; j <= W - X; j++) {
				ok[i][j] = false;
			}
		}
		for (int u = 0; u < 2; u++) {
			for (int i = 0; i < 4; i++) {
				ull ph = 0;
				for (int j = 0; j < X; j++) {
					ull sum = 0;
					for (int k = 0; k < X; k++) {
						sum = sum * base1 + th[j][k];
					}
					ph = ph * base2 + sum;
				}
				for (int j = 0; j <= H - X; j++) {
					for (int k = 0; k <= W - X; k++) {
						if (sh2[j][k] == ph) ok[j][k] = true;
					}
				}
				rotate();
			}
			for (int i = 0; i < X; i++) reverse(th[i], th[i] + X);
		}
		int ret = 0;
		for (int i = 0; i <= H - X; i++) {
			for (int j = 0; j <= W - X; j++) {
				if (ok[i][j]) ret++;
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 27268
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s;

    cin >> s;

    if (s[2] == s[3] && s[4] == s[5])
    {
        cout << "Yes"  << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
mt19937 R(chrono::system_clock().now().time_since_epoch().count());

const int N = 666666;
int n;ll a[67],c[N];char s[N];
void ins(ll x){
	per(i,60,0)if(x>>i&1)
		if(!a[i]){a[i]=x;return;}
		else x^=a[i];
}
bool qry(ll x){
	per(i,60,0)if(x>>i&1)x^=a[i];
	return x==0;
}
int main() {
	int T;read(T);while(T--){
		read(n);rep(i,1,n)read(c[i]);scanf("%s",s+1);
		memset(a,0,sizeof(a));bool ok=1;
		per(i,n,1){
			if(s[i]=='0')ins(c[i]);
			else ok&=qry(c[i]);
		}
		printf("%d\n",ok^1);
	}
	return 0;
}


Measured memory_bytes: 3776
#include <iostream>
#include <math.h>
using namespace std;
int n, res;
int main(void){
    // Your code here!
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a, cou = 0;
        cin >> a;
        for (int j = 2; j <= sqrt(a); j++) {
            if (a % j == 0) cou++;
        }
        if (cou == 0) res++;
    }
    cout << res << endl;
}



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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;



template<typename T>
struct Segtree{
    int n;
    T op;
    vector<T> elm;
    function<T(T, T)> f;

    Segtree(int n, T init, function<T(T, T)> f, T op = T()) :
        n(n),
        op(op),
        elm(2 * n, init),
        f(f)
    {
        for(int i = n - 1; i >= 1; --i)
            elm[i] = f(elm[2 * i], elm[2 * i + 1]);
    }

    Segtree(int n, vector<T> init, function<T(T, T)> f, T op = T()) :
        n(n),
        op(op),
        elm(2 * n),
        f(f)
    {
        for(int i = 0; i < n; ++i)
            elm[i + n] = init[i];
        for(int i = n - 1; i >= 1; --i)
            elm[i] = f(elm[2 * i], elm[2 * i + 1]);
    }

    void set(int x, T val){
        x += n;
        elm[x] = val;
        while(x >>= 1)
            elm[x] = f(elm[2 * x], elm[2 * x + 1]);
    }

    void update(int x, T val){
        x += n;
        elm[x] = f(val, elm[x]);
        while(x >>= 1)
            elm[x] = f(elm[2 * x], elm[2 * x + 1]);
    }

    T get(int x, int y) const{
        T l = op, r = op;
        for(x += n, y += n - 1; x <= y; x >>= 1, y >>= 1){
            if(x & 1)
                l = f(l, elm[x++]);
            if(!(y & 1))
                r = f(elm[y--], r);
        }
        return f(l, r);
    }
};


signed main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    vector<vector<int>> v(n);
    vector<int> cnt(n, 0);
    for(int i = 0; i < n - 1; ++i){
        cin >> a[i] >> b[i];
        --a[i], --b[i];
        v[a[i]].emplace_back(i);
        v[b[i]].emplace_back(i);
    }

    vector<int> ans(n - 1, -1);
    int ret = 0;
    function<void(int, int)> f = [&](int x, int col){
        int cnt = 0;
        for(auto& idx : v[x]){
            if(ans[idx] != -1)
                continue;
            ++cnt;
            if(cnt == col)
                ++cnt;
            ans[idx] = cnt;
            f(a[idx] == x ? b[idx] : a[idx], cnt);
        }
        ret = max(ret, cnt);
    };
    f(0, -3);
    cout << ret << endl;
    for(int i = 0; i < n - 1; ++i)
        cout << ans[i] << endl;
}


Measured memory_bytes: 8960
// ------------------------------------
// Date:2018/ 3/ 1
// Problem:ABC 059 Comparison b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

int main()
{
  string A, B;
  string ans;
  cin >> A >> B;
  if (A.size() > B.size()) {
    ans = "GREATER";
  } else if (A.size() < B.size()) {
    ans = "LESS";
  } else {
    if (A == B) ans = "EQUAL";
    else if (A > B) ans = "GREATER";
    else ans = "LESS";
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
url = "https://atcoder.jp//contests/abc160/tasks/abc160_b"

def main():
    N = int(input())
    n, m = divmod(N, 500)
    # print(n, m)
    print((1000 * (N // 500)) + (5 * ((N % 500) // 5)))

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940