akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())

L = []
R = []

for i in range(M):
    inp = input().split()
    L.append(int(inp[0]))
    R.append(int(inp[1]))
    
if max(L) <= min(R):
    print(min(R)-max(L)+1)
else:
    print(0)

Measured memory_bytes: 10996
#include "iomanip"
#include "iostream"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
void drop(const T& x) {
  cout << x << endl;
  exit(0);
}

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

  string S;
  cin >> S;

  rep(i, S.size()) { printf("x"); }
  printf("\n");
}


Measured memory_bytes: 256
N = gets.to_i
as = [0] + gets.split.map(&:to_i)

l = Array.new(N+2, 0)
r = Array.new(N+2, 0)


(1..N).each do |i|
    l[i] = l[i-1].gcd(as[i])
end

N.downto(1) do |i|
    r[i] = r[i+1].gcd(as[i])
end

ans = 0
(1..N).each do |i|
  res = l[i-1].gcd(r[i+1])
  ans = res if ans < res
end
puts ans


Measured memory_bytes: 10892
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  int mx = 0, sec = 0;
  vi A(n);
  rep(i, n){
    int a;
    cin >> a;
    A[i] = a;
    if(mx < a) mx = a;
    else if(sec < a) sec = a;
  }
  rep(i, n){
    if(A[i] == mx) cout << sec << endl;
    else cout << mx << endl;
  }
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007

int main(){
  int N;
  cin>>N;
  vector<ll> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  vector<ll> count(60,0);
  ll res=1;
  ll ans=0;
  for(int i=0;i<60;i++){
    for(int j=0;j<N;j++){
      count.at(i)+=A.at(j)%2;
      A.at(j)/=2;
    }
    ans+=(count.at(i)*(N-count.at(i))%MOD)*res%MOD;
    ans%=MOD;
    res*=2;
    res%=MOD;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

  int ans = numeric_limits<int>::max();
  REP(i, s.size()-2){
    string sub = s.substr(i, 3);
    int n = stoi(sub);

    ans = min(ans, abs(n-753));
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int mi=1000001,ma=-1000001;
long su=0;
void min(int x){
if(mi>x)
mi=x;
}
void max(int x){
  if(ma<x)
  ma=x;
}
void sum(int x){
  su+=x;
}
int main(){
int a,b;
  cin>>a;
for(int i=0;i<a;i++){
  cin>>b;
  min(b);
  max(b);
  sum(b);
  
  
}
cout<<mi<<' '<<ma<<' '<<su<<'\n';
return 0;
}

Measured memory_bytes: 3088
import java.io.*;
import java.util.*;

public class Main{

	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		public FastReader(){
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public String next(){
			try{
				while(st==null||!st.hasMoreElements()){
					st = new StringTokenizer(br.readLine());
				}
			}catch(Exception e){
				e.printStackTrace();
			}
			return st.nextToken();
	
		}
		public int nextInt(){
			return Integer.parseInt(next());
		}
		public long nextLong(){
			return Long.parseLong(next());
		}
		public double nextDouble(){
			return Double.parseDouble(next());
		}
		public String nextLine(){
			String s = "";
			try{
				s = br.readLine();
			}catch(Exception e){
				e.printStackTrace();
			}	
			return s;		
		}
	} 
	
	public static void main(String[] args){
		FastReader in = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int w = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();
		int moves = 0;
		if(a<=b){
			if(a+w<b){
				moves = b-(a+w);
			}
			else{
				moves = 0;
			}
		}
		else{
			if(b+w<a){
				moves =a-(b+w);
			}
		}
		out.println(moves);
		out.flush();
		out.close();  
	}

}





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

int main(void) {
	int n,ans = 0;
	char pass[30001], check[4], k;
	scanf("%d", &n);
	scanf("%s", pass);
	for (int i = 0; i < 1000; i++) {
		check[0] = '0' + i / 100;
		check[1] = '0' + (i / 10) % 10;
		check[2] = '0' + i % 10;
		check[3] = '\0';

		k = 0;
		for (int j = 0; j < n; j++) {
			if (check[k] == pass[j]) {
				if (k == 2) {
					ans++;
					break;
				}
				else {
					k++;
				}
			}
		}
	}

	printf("%ld\n", ans);
}

Measured memory_bytes: 128
#include <stdio.h>

typedef struct {
	int key, id;
} data;

typedef struct {
	data obj[200001];
	int size;
} max_heap;

void push(data x, max_heap* h)
{
	int i = ++(h->size);
	data tmp;
	h->obj[i] = x;
	while (i > 1) {
		if (h->obj[i].key > h->obj[i>>1].key) {
			tmp = h->obj[i>>1];
			h->obj[i>>1] = h->obj[i];
			h->obj[i] = tmp;
			i >>= 1;
		} else break;
	}
}

data pop(max_heap* h)
{
	int i = 1, j = 2;
	data output = h->obj[1], tmp;
	h->obj[1] = h->obj[(h->size)--];
	while (j <= h->size) {
		if (j < h->size && h->obj[j^1].key > h->obj[j].key) j ^= 1;
		if (h->obj[j].key > h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j = i << 1;
		} else break;
	}
	return output;
}

int main()
{
	int i, N;
	data d;
	max_heap h;
	h.size = 0;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &(d.key));
		push(d, &h);
	}

	int count = 1;
	long long ans = pop(&h).key;
	while (count < N - 1) {
		d = pop(&h);
		if (count < N - 2) {
			ans += d.key * 2;
			count += 2;
		} else {
			ans += d.key;
			count++;
		}
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main() {
  ll w, h, x, y;
  cin >> w >> h >> x >> y;

  double ans = w * h / 2.0;

  int multi = 0;
  if (x * 2 == w && y * 2 == h) {
    multi = 1;
  }

  printf("%.2f0000000000 %d\n", ans, multi);
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 2e5+5;

int main(int argc, char** argv) {
	int x; scanf("%d", &x);
	printf("%d\n", 1-x);
	return 0;
}


Measured memory_bytes: 3816
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
    unsigned short *A, *B;
    
    int C[VMAX+1];
    int n,j,i;
    scanf("%d",&n);
    
    A=malloc(sizeof(short)*n+1);
    B=malloc(sizeof(short)*n+1);
    
    for(i=0;i<=VMAX;i++) C[i]=0;
    
    for(i=0;i<n;i++){
        scanf("%hu",&A[i+1]);
        C[A[i+1]]++;
    }
    for(i=1;i<=VMAX;i++) C[i]=C[i]+C[i-1];
    
    for(j=1;j<=n;j++){
        B[C[A[j]]]=A[j];
        C[A[j]]--;
    }
    
    for(i=1;i<=n;i++){
        if(i>1)printf(" ");
        printf("%d",B[i]);
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 9620
#include <stdio.h>
int main(){
    int i, o[10000];
    for (i=0;i<10000;i++){
        scanf("%d", &o[i]);
        if (o[i]==0){
            break;
        }
    }
    for (i=0;i<10000;i++){
        if (o[i]==0){
            break;
        }
        else{
            printf("Case %d: %d\n", i+1,o[i]);
        }
    }
    return 0;
}

Measured memory_bytes: 2588
#include <stdio.h>
#include <string.h>

int main(int argc, char const *argv[]) {
	char str[101];
	int n, m;
	int ans;
	char w[101][100] = {};

	fgets(str, 100, stdin);
	sscanf(str, "%d\n", &n);

	int i;
	int j;
	for (i = 0; i < n; i++) {
		scanf("%s", &w[i]);
	}

	for (i = 1; i < n; i++) {
		int last;
		for (last = 0; w[i-1][last] != 0; last++);
		last --;

		if (w[i][0] != w[i-1][last]) {
			printf("No\n");
			return 0;
		}

		for (j = 0; j < i; j++) {
			if (strcmp(w[i], w[j]) == 0) {
				printf("No\n");
				return 0;
			}
		}
	}

	printf("Yes\n");

	return 0;
}


Measured memory_bytes: 128
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
tmp = 9
last = 0
for i in [A, B, C, D, E]:
    if i % 10 == 0:
        continue
    else:
        if i % 10 <= tmp:
            tmp = i % 10
            last = i

ans = 0
for i in [A, B, C, D, E]:
    if i % 10 == 0:
        ans += i
    else:
        ans += i + (10-i%10)

print(ans-(10-last%10) if last != 0 else ans)

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

A=sorted(A)
maxA=max(A)
limit=maxA/2
tmp=10**9
for i in range(N):
    if(abs(limit-A[i])<tmp):
        tmp=abs(limit-A[i])
        comb=A[i]
    else:
        break

print(maxA,comb)

Measured memory_bytes: 14428
#include <stdio.h>

using namespace std;

int main(){
	int r,c,sum,total_sum = 0;
	scanf("%d %d",&r,&c);
	int table[r+1][c+1];

	for(int i = 0; i < r+1; i++){
		for(int j = 0; j < c+1; j++){
			table[i][j] = 0;
		}
	}

	for(int i = 0; i < r; i++){
		sum = 0;
		for(int j = 0; j < c; j++){
			scanf("%d",&table[i][j]);
			sum += table[i][j];
			table[r][j] += table[i][j];
		}
		table[i][c] = sum;
		total_sum += sum;
	}
	table[r][c] = total_sum;

	for(int i = 0; i < r+1; i++){
		for(int j = 0; j < c; j++){
			printf("%d ",table[i][j]);
		}
		printf("%d\n",table[i][c]);
	}
}



Measured memory_bytes: 2596
#include <bits/stdc++.h>
            using namespace std;
            vector<int> num;
            int k;
            int dp[109][109][2];
            int call(int pos,int m,int f)
            {
                // cout << pos << " " << m << " " << f << endl;
                if(dp[pos][m][f]!=-1)return dp[pos][m][f];
                if(pos==num.size())
                {
                    if(m==k)return 1;
                    else return 0;
                }
                int limit;
                if(f==0)limit=num[pos];
                else limit=9;
                int res=0;
                for(int digit=0; digit<=limit; digit++)
                {
                    int nf=f;
                    int nm=m;
                    if(f==0&&digit<limit)nf=1;
                    nm=m;
                    if(digit != 0)
                        res+=call(pos+1,nm+1,nf);
                    else
                        res+=call(pos+1,nm,nf);
                }
                return dp[pos][m][f]=res;
            }
            int solve(string s)
            {
               
                num.clear();
                int n = s.size();
                for(int i = 0 ;i < n; i++)
                    num.push_back(s[i] - '0');
                memset(dp,-1,sizeof(dp));
                // reverse(num.begin(),num.end());
                return call(0,0,0);

            }

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

                cout << solve(s) << endl;
                
            }

Measured memory_bytes: 384
import java.util.*;

class Main {

  static int d[][];
  static char map[][];
  static int x4[] = {0, 1, 0, -1};
  static int y4[] = {1, 0, -1, 0};
  static int H, W;
  static int count = 0;
  static class Point{
    int x, y;
    Point(int a, int b) {
      this.x = a;
      this.y = b;
    }
  }

  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    H = sc.nextInt();
    W = sc.nextInt();
    d = new int[H][W];
    map = new char[H][W];
    for (int i = 0; i < H; i++) {
      String s = sc.next();
      for (int j = 0; j < W; j++) {
        map[i][j] = s.charAt(j);
        if (map[i][j] == '#')
          count++;
        if (i != 0 || j != 0)
          d[i][j] = -1;
      }
    }

    ArrayDeque<Point> q = new ArrayDeque<>();
    q.addFirst(new Point(0, 0));

    while (!q.isEmpty()) {
      Point p = q.removeFirst();
      for (int i = 0; i < 4; i++) {
        int nx = p.x + x4[i];
        int ny = p.y + y4[i];
        if (nx >= 0 && ny >= 0 && nx < W && ny < H) {
          if (map[ny][nx] == '.' && d[ny][nx] == -1) {
            d[ny][nx] = d[p.y][p.x] + 1;
            q.addLast(new Point(nx, ny));
          }
        }
      }
    }
    /*
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (d[i][j] == -1)
          System.out.print("   ");
        else
          System.out.printf("%3d", d[i][j]);
      }
      System.out.println();
    }
    */
    if (d[H-1][W-1] == -1)
      System.out.println("-1");
    else
      System.out.println(H*W-(count+d[H-1][W-1]+1));
  }
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define piii pair<int,pii>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head

const int N = 2e5 + 5;
const LL INF = 0x3f3f3f3f3f3f3f3f;
int a[N], n;
LL check(int m) {
    LL ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += abs(a[i] - (m+i));
    }
    return ans;
}
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    LL l = -2e9, r = 2e9, m1 = (l+l+r)/3, m2 = (l+r+r)/3;
    while(l < r - 2) {
        if(check(m2) > check(m1)) r = m2;
        else l = m1;
        m1 = (l+l+r)/3;
        m2 = (l+r+r)/3;

    }
    LL ans = INF;
    for (int i = l; i <= r; i++) ans = min(ans, check(i));
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

int n;

double dp[303][303][303];
bool vis[303][303][303];

double f(int k1, int k2, int k3){
	double& r=dp[k1][k2][k3];
	if(vis[k1][k2][k3])return r;
	vis[k1][k2][k3]=true;
	r=0;
	if(!k1&&!k2&&!k3)return r;
	if(k1)r+=1.*k1/n*(1+f(k1-1,k2,k3));
	if(k2)r+=1.*k2/n*(1+f(k1+1,k2-1,k3));
	if(k3)r+=1.*k3/n*(1+f(k1,k2+1,k3-1));
	int k0=n-k1-k2-k3;
	r=(r+1.*k0/n)/(1-1.*k0/n);
	return r;
}


int main(){
	int k1=0,k2=0,k3=0;
	scanf("%d",&n);
	fore(i,0,n){
		int t;
		scanf("%d",&t);
		if(t==1)k1++;
		else if(t==2)k2++;
		else k3++;
	}
	printf("%.12lf\n",f(k1,k2,k3));
	return 0;
}

Measured memory_bytes: 243968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  string s;
  cin>>s;
  int f=1;
  int n=s.size();
  if(s.size()>=2 && n%2==0)
  {
    f=1;
  }
  else 
  {
    f=-1;
  }
  for(int i=0;i<s.size();i++)
  {
    if(i%2==0)
    {
      if(s[i]=='h')
        continue;
      else 
      {
        f=-1;
        break;
      }
    }
    else 
    {
      if(s[i]=='i')
      {
        continue;
      }
      else 
      {
        f=-1;
        break;
      }
    }
  }
  if(f==1)
  {
    cout<<"Yes";
  }
  else
  {
    cout<<"No";
  }
    
}

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

class UnionFind
{
private:
    vector<int> par;
    vector<int> rank;
    vector<int> sz;

public:
    UnionFind(int n) : par(n), rank(n, 0), sz(n, 1) {
        iota(par.begin(), par.end(), 0);
    }

    int find(int x) {
        if (par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return;

        if (rank[x] < rank[y]) {
            par[x] = y; sz[y] += sz[x];
        } else {
            par[y] = x; sz[x] += sz[y];
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return sz[find(x)];
    }
};

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

    UnionFind uf(n);
    for (int i = 0; i < m; i++) {
        int x, y; cin >> x >> y; x--, y--;
        uf.unite(x, y);
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (uf.same(i, p[i])) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
while True:
    try:
        p, q = map(int, raw_input().split())
    except EOFError:
        break
    ans, ls = [], [p]
    for i in range(80):
        p = p%q*10
        ans.append(p/q)
        if p%q in ls or p%q == 0:
            break
        ls.append(p%q)
    print ''.join(map(str, ans))
    if p%q != 0: print ' '*(ls.index(p%q))+'^'*(len(ls)-ls.index(p%q))

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

using namespace std;

typedef long double ld;

int n;
ld p[3005], dp[3005];

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1 ; i <= n ; ++i){
	cin >> p[i];
}
dp[0] = 1;
for(int i = 1 ; i <= n ; ++i){
	for(int j = n ; j >= 0 ; --j){
		dp[j] = (dp[j] * (1 - p[i]) + dp[j - 1] * p[i]);
	}
}
ld sol = 0;
for(int i = n / 2 + 1 ; i <= n ; ++i){
	sol += dp[i];
}
cout << fixed << setprecision(10) << sol << endl;

return 0;
}



Measured memory_bytes: 384
import sys
input = sys.stdin.readline
N, M = map(int, input().split())

N0 = 2**((N+1).bit_length())
INF = 10**18
data = [0]*(2*N0)
lazy = [0]*(2*N0)

def gindex(l, r):
    L = l + N0; R = r + N0
    lm = (L // (L & -L)) >> 1
    rm = (R // (R & -R)) >> 1
    while L < R:
        if R <= rm:
            yield R
        if L <= lm:
            yield L
        L >>= 1; R >>= 1
    while L:
        yield L
        L >>= 1

def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if not v:
            continue
        lazy[2*i-1] += v; lazy[2*i] += v
        data[2*i-1] += v; data[2*i] += v
        lazy[i-1] = 0
        
def update(l, r, x):
    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] += x; data[R-1] += x
        if L & 1:
            lazy[L-1] += x; data[L-1] += x
            L += 1
        L >>= 1; R >>= 1

    for i in gindex(l, r):
        data[i-1] = max(data[2*i-1], data[2*i]) + lazy[i-1]

def update2(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = max(data[2*k+1], data[2*k+2])

def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r
    s = -INF
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])
        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

xs = [0]*(N+1)
ys = [[] for _ in range(N+1)]
for _ in range(M):
    l, r, a = map(int, input().split())
    xs[l] += a
    ys[r].append((l,a))

for i in range(1, N+1):
    update(0,i,xs[i])
    update2(i, query(0, i))
    for l, a in ys[i]:
        update(0, l, -a)
print(query(0,N+1))


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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define all(v) (v).begin(),(v).end()
typedef long long ll;

ll dp[3000];

int main(){
	string s;
	cin >> s;
	
	reverse(all(s));
	ll val = 0;
	ll ans = 0;
	dp[0] = 1;
	ll mult = 1;
	fr(i,sz(s)){
		//prin(s[i]);
		//prin(val);
		val = (val+mult*(s[i]-'0'))%2019;
		mult = (mult*10%2019);
		//prin(val);
		//cout << endl;
		ans+=dp[(val)%2019];
		dp[val]++;
	}
	
	//prin(18171%2019);
	//prin(8171%2019);
	/*
	prin(1817%2019);
	prin(181718171%2019);
	prin(181712114%2019);
	prin(2114%2019);
*/	
	cout << ans << endl;
}

Measured memory_bytes: 3768
def main():
    from sys import stdin
    input = stdin.readline

    n, m, r = map(int, input().split())
    l = [int(i) - 1 for i in input().split()]
    d = [[10**8] * n for _ in range(n)]
    for _ in range(m):
        i, j, k = map(int, input().split())
        d[i-1][j-1] = k
        d[j-1][i-1] = k

    # Warshall-Floyd algorithm
    for k in range(n):
        for i in range(n-1):
            for j in range(i+1, n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]
                    d[j][i] = d[i][j]

    # full search
    # 8! = 40320
    from itertools import permutations

    answer = float('inf')
    for i in permutations(l):
        ans = 0
        for j in range(r-1):
            ans += d[i[j]][i[j+1]]
        if ans < answer:
            answer = ans

    print(answer)

main()


Measured memory_bytes: 74208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];

    int ans=0;
    rep(i,n){
        if(h[i] >= k) ans ++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 3752
#!/usr/bin/env python3

A, B, K = list(map(int, input().split()))
nokori = K
if A > 0:
    if K <= A:
        nokori = 0
        A = A - K
    else:
        nokori = K - A
        A = 0
if nokori > 0 and B > 0:
    if nokori <= B:
        B = B - nokori
        nokori = 0
    else:
        nokori -= B
        B = 0

ans = "{} {}".format(A, B)

print(ans)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int go[10][10] = {};
int main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		string s = to_string(i);
		go[s[0] - '0'][s.back() - '0']++;
	}
	for (int i = 1; i <= n; ++i) {
		string s = to_string(i);
		ans += go[s.back() - '0'][s[0] - '0'];
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import sys

def parent(i, n):
    tmp = i/2
    if tmp <=0 or tmp>=n: return None
    else: return tmp

def left(i, n):
    tmp = 2*i
    if tmp>=n: return None
    else: return tmp
    
def right(i, n):
    tmp = 2*i+1
    if tmp>=n: return None
    else: return tmp

def maxheapify(A, i):
    n = len(A)
    f = [0,0,0]
    f[0] = A[i]

    l=left(i, n)
    if l == None:
        f[1]=None
    else:
        f[1]=A[l]
    
    r=right(i,n)
    if r == None:
        f[2]=None
    else:
        f[2]=A[r]
        
    tmp = f.index(max(f))
    if tmp == 1:
        tmp=A[i]
        A[i]=A[l]
        A[l]=tmp
        maxheapify(A, l)
    elif tmp == 2:
        tmp=A[i]
        A[i]=A[r]
        A[r]=tmp
        maxheapify(A, r)

def buildmaxheap(A):
    for i in range(1,len(A))[::-1]:
        maxheapify(A,i)
        
n = int(input())
x = map(int, [0] + raw_input().split()) 
buildmaxheap(x)
print " "+" ".join(map(str, x[1:]))

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

int main() {
	ll n;
	cin >> n;
	vector<vector<ll>> g(n);
	rep(i, n) {
		int a, k;
		cin >> a >> k;
		rep(j, k) {
			int t;
			cin >> t;
			t--;
			g[i].push_back(t);
		}
	}

	vector<bool> visit(n, false);

	vector<int> start(n);
	vector<int> finish(n);

	int t = 0;

	function<void(int)> dfs = [&](int current){
		if (visit[current]) return;
		visit[current] = true;
		t++;
		start[current] = t;
		for (auto p : g[current]) {
			dfs(p);
		}
		t++;
		finish[current] = t;
		return;
	};
	rep(i, n) {
		dfs(i);
	}
	rep(i, n) {
		cout << i + 1 << " " << start[i] << " " << finish[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 3168
function Main(input: string) {
  const lines: string[] = input.split('\n');
  const params1 = lines[0].split(' ');
  const params2 = lines[1].split(' ');

  const n = parseInt(params1[0]);
  const x = params2.map(x => parseInt(x));

  const y = sort(x);

  const l = Math.floor(n / 2);
  const y1 = y[l - 1];
  const y2 = y[l];

  x.forEach(a => {
    const b = (a <= y1) ? y2 : y1;
    console.log(b);
  });
}

function sort(a: number[]): number[] {
  let b = [...a];
  b.sort((x, y) => x - y);
  return b
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const ll MOD = (ll)(1e9 + 7);

ll n;
string s;

string d;

int main(void) {
  // Here your code !
  scanf("%lld", &n);
  cin >> s;

  for (int i = 0; i < s.size(); ++i) {
    if (i % 2 == 0) s[i] = (s[i] == 'W') ? 'B' : 'W';
  }

  for (auto &e : s) {
    d.push_back((e == 'B') ? 'R' : 'L');
  }

  int cnt_l = 0;
  int cnt_r = 0;

  for (auto &e : d) {
    cnt_l += (e == 'L') ? 1 : 0;
    cnt_r += (e == 'R') ? 1 : 0;
  }

  if (cnt_l != cnt_r) {
    printf("0\n");
    return 0;
  }

  ll ans = 1LL;

  ll cur_l = 0LL;
  ll cur_r = 0LL;

  for (auto &e : d) {
    if (e == 'R') {
      ans *= cur_l - cur_r;
      ans %= MOD;

      cur_r += 1LL;
    } else {
      cur_l += 1LL;
    }
  }

  for (ll i = 1LL; i <= n; ++i) {
    ans *= i;
    ans %= MOD;
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
vector <int> g[N];
vector <pair <int, int> > ans;
bool used[N];
int h[N];
bool dfs(int u, int p) {
    used[u] = 1;
    int pw = 0;
    for (int v : g[u]) {
        if (v == p) continue;
        if (!used[v]) {
            h[v] = h[u] + 1;
            if (dfs(v, u)) {
                ans.push_back({u, v});
                ++pw;
            }   
        }   
        else {
            if (h[v] < h[u]) {
                ans.push_back({u, v});
                ++pw;
            }   
        }   
    }   
    if (pw & 1) {
        if (p == -1) {
            exit(1);
        }   
        ans.push_back({u, p});
        return 0;
    }   
    return 1;
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n, m;
    cin >> n >> m;

    if (m & 1) {
        cout << "-1\n";
        exit(0);
    }   

    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v); g[v].push_back(u);
    }   
    
    dfs(1, -1);

    for (auto e : ans) {
        cout << e.first << ' ' << e.second << '\n';
    }   
}   

Measured memory_bytes: 17652
/*
This code By @1353055672(Ligen)
[Warning]You're not excepted to understand this code!
RP++
*/
//#pragma GCC optimize(3)
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#define ll long long
#define ull unsigned long long
#define mn 500020
#define mod (int)(1e9+7)
#define inf (1<<30)
#define FOR(a,b,c) for (register ll a=b;a<=c;a++)
#define FORD(a,b,c) for (register ll a=b;a>=c;a--)
using namespace std;
inline ll read(){
    ll x=0,f=1;
    char c=getchar();
    while (c<'0'||c>'9'){
        if (c=='-')f=-1;
        c=getchar();
    }
    while (c>='0'&&c<='9'){
        x=x*10+c-'0';
        c=getchar();
    }
    return x*f;
}
inline void writeln(ll a){
    if(a==0){puts("0");return;}
    if(a<0)putchar('-'),a=-a;
    char c1[120];
    int h=0;
    while(a)c1[++h]=a%10+'0',a/=10;
    FORD(i,h,1)putchar(c1[i]);putchar('\n');
    return;
}
inline ll Max(ll a,ll b){return (a>b)?a:b;}
inline ll Min(ll a,ll b){return (a<b)?a:b;}
inline ll Abs(ll x){return (x<0)?-x:x;}
inline void Swap(ll &x,ll &y){ll t=x;x=y;y=t;}

int main(){
	int n=read(),m=read(),x=read(),y=read(),xm=-2147483647,ym=2147483647,xx,yy;
	FOR(i,1,n)xx=read(),xm=Max(xm,xx);
	FOR(i,1,m)yy=read(),ym=Min(ym,yy);
	FOR(i,x+1,y)if(xm<i&&ym>=i){
		puts("No War");
		return 0;
	}
	puts("War");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
#define dis distance
#define so sort
#define rev reverse
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;


int main (){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector< int > V(n);
    REP(i,n){
        cin >> V[i];
    }
    int ans = INT_MAX;
    FOR(i,-100,101){
        int cost = 0;
        REP(j,n){
            cost += (i-V[j])*(i-V[j]);
        }
        ans = min(ans,cost);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = list(map(int, input().split()))

if n == 1:
    print(s[0])
    exit()

b = 0
res = 0
for i in range(n - 1):
    if s[i] <= s[i + 1]:
        continue
    else:
       res += s[i] - b
       b = s[i + 1]

if s[n - 1] >= s[n - 2]:
    res += s[n - 1] - b
print(res)


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    ll n, p;
    cin >> n >> p;
    if(n == 1){
        cout << p << endl;
        return 0;
    }
    ll ans = 1;
    for(ll now = 2; now <= 1e6; now++){
        ll copy = p;
        ll index = n;
        while(copy % now == 0){
            copy = copy / now;
            index--;
        }
        if(index <= 0) ans = now;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#8
n = int(input())
a = list(map(int,input().split()))
num = [0 for i in range(8)]
cnt = 0

for i in a:
    x = i//400
    if x >=8:
        cnt +=1
    else:
        if num[x] == 0:
            num[x] +=1
    
if cnt == 0:
    print(sum(num),sum(num))
elif sum(num) == 0:
    print(1,cnt)
else:
    print(sum(num),sum(num)+cnt)
    
    

Measured memory_bytes: 9172
n = raw_input()
num = raw_input()
array = []
array = num.strip().split(" ")
int_array = map(int, array)

for i in range(1, int(n)):
    array = map(str, int_array)
    print " ".join(array)
    v = int_array[i]
    j = i - 1
    while j >= 0 and int_array[j] > v:
        int_array[j + 1] = int_array[j]
        j -= 1
    int_array[j + 1] = v
array = map(str, int_array)
print " ".join(array)

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli n,m;
vll x,y,z;
vll all;
vll idx;
lli ans = 0;

int main(){
  cin >> n >> m;
  x = y = z = vll(n);
  for(lli i = 0;i < n;i++){
    cin >> x[i] >> y[i] >> z[i];
  }
  idx = vll(n);
  for(lli i = -1;i <= 1;i += 2){
    for(lli j = -1;j <= 1;j += 2){
      for(lli k = -1;k <= 1;k += 2){
        all = vll(n);
        iota(idx.begin(), idx.end(), 0ll);
        for(lli l = 0;l < n;l++){
          all[l] = x[l]*i+y[l]*j+z[l]*k;
          sort(idx.rbegin(), idx.rend(), [](lli a, lli b){
            return all[a] < all[b];
          });
          lli allx = 0;
          lli ally = 0;
          lli allz = 0;
          for(lli i = 0;i < m;i++){
            allx += x[idx[i]];
            ally += y[idx[i]];
            allz += z[idx[i]];
          }
          ans = max(ans, abs(allx)+ abs(ally)+ abs(allz));
          // ans = max(ans, accumulate(all.begin(), all.begin()+m, 0ll));
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>> a >> b >> c >> d;
    if(abs(a-c) <= d)
    {
        cout<<"Yes";
        return 0;
    }
    else if(abs(a-b) <= d&& abs(b-c) <= d)
    {
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

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

const int INF = 100000000;
int dist[1000005];
struct Edge { int from; int to; int cost; };

bool shortest_path(int s, vector<Edge>& edge, int V, int E) {
  for(int i = 0; i < V; i++) dist[i] = INF;
  dist[s] = 0;
  int cnt = 0;
  while(true) {
    bool update = false;
    for(Edge& e : edge) {
      if(dist[e.from] != INF && dist[e.from] + e.cost < dist[e.to]) {
	dist[e.to] = dist[e.from] + e.cost;
	update = true;
      }
    }
    if(!update) break;
    cnt++;
    if(V + 1 < cnt) return true;
  }
  
  return false;
}

int main(){
  int V, E, r;
  cin >> V >> E >> r;
  vector<Edge> edge(E);
  for(int i = 0; i < E; i++) {
    int from, to, cost;
    cin >> from >> to >> cost;
    edge[i] = { from, to, cost };
  }
  if(shortest_path(r, edge, V, E)) {
    cout << "NEGATIVE CYCLE" << endl;
    return 0;
  }
  
  for(int i = 0; i < V; i++) {
    if(dist[i] == INF) cout << "INF" << endl;
    else cout << dist[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3124
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXN = 300 * 1000 + 100;

int m[MAXN + 10];
bool p[MAXN + 10];
int mps[MAXN + 10];

int main()
{
    int num = 0;
    REP(MAXN / 7)
    {
        m[num] = 7 * i + 1;
        num++;
        m[num] = 7 * i + 6;
        num++;
    }
    p[m[0]] = 1;

    REP(num)if(!p[m[i]])for(int j = m[i]*2;j<MAXN; j+= m[i]) p[j] = 1;
    

    int nmps = 0;
    REP(MAXN)if(!p[m[i]]){mps[nmps] = m[i]; nmps++;}

    int n;
    while(cin >> n)
    {
        if(n == 1) break;

        cout << n << ":";
        REP(nmps)
        {
            if( mps[i] > n) break;
            
            if((n % mps[i]) == 0) 
                cout << " " << mps[i] ;
        }
        cout << endl;

    }
    return 0;
}

Measured memory_bytes: 3308
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#define INF 1000000005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main()
{
	int Q;
	scanf("%d",&Q);
	while(Q--)
	{
		int A,B;
		scanf("%d %d",&A,&B);
		if(A<B) swap(A,B);
		//A>=B -> (A+1)*(B-1) < A*B -> (A+i)*(B-i) < A*B
		//1~B-1 はすべて作れる
		//B+1～は傾き同じになるところを二分探索
		ll l=B,r=INF;
		while(r-l>1)
		{
			ll m=(l+r)/2;
			if(((ll) A*(ll) B-1) >= m*(m+1)) l=m;
			else r=m;
		}
		//r は ok
		ll ret=r-2;
		ret+=((ll) A*(ll) B-1)/r;
		printf("%lld\n",ret);
		//printf("%d %d : %lld\n",A,B,r);
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;

    if (a%500 > b) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int d[100][2],n,num = 0,i,j;
	scanf("%d",&n);
	for(i = 0; i < n; i++){
		for(j = 0;  j < 2; j++){
			scanf("%d",&d[i][j]);
			if(i > 1 &&j == 1){
				if(d[i - 2][0] == d[i - 2][1] && d[i - 1][0]== d[i - 1][1] && d[i][0] == d[i][1]){
					num = 1;
				}
			}
		}
	}
	if(num == 0){
		printf("No");
	}
	else{
		printf("Yes");
	}
}

Measured memory_bytes: 1736
#include<stdio.h>
int i;
char c;
int main(){
  c=getchar();
  putchar(c-'a'+'A');
  while(c!=32){
    c=getchar();
  }
  c=getchar();
  putchar(c-'a'+'A');
  while(c!=32){
    c=getchar();
  }
  c=getchar();
  putchar(c-'a'+'A');
  putchar(10);
}


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


def divisors(n):
    ret = set()
    for i in range(1, int(n**(0.5))+1):
        if n % i == 0:
            ret.add(i)

    return(ret)


ans = N-1
for x in divisors(N):
    ans = min(ans, x-1+(N//x)-1)

print(ans)


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

using namespace std;

typedef vector<int> Pile;
typedef vector<Pile> Piles;

struct P { int p, h; P(int p, int h) : p(p), h(h) {} };

P get_pos(Piles &piles, int id)
{
    for (int i = 0; i < (int)piles.size(); i++) {
        for (int j = 0; j < (int)piles[i].size(); j++) {
            if (piles[i][j] == id) return P(i, j);
        }
    }
    return P(-1, -1);
}

void move(Piles &piles, int pos)
{
    int id = piles[pos].back();
    piles[pos].pop_back();
    piles.push_back(Pile(1, id));
}

int main()
{
    int M, a, b;
    while (cin >> M, M) {
        Piles piles(M);
        for (int i = 0; i < M; i++) {
            piles[i] = Pile(1, i+1);
        }
        while (cin >> a >> b, (a | b)) {
            auto p1 = get_pos(piles, a), p2 = get_pos(piles, b);
            if (b == 0 && p1.h == 0) continue;
            if (p1.p == p2.p && p1.h >= p2.h) continue;
            
            while (piles[p1.p].back() != a) {
                move(piles, p1.p);
            }
            piles[p1.p].pop_back();
            if (b == 0) {
                piles.push_back(Pile(1, a));
            } else {
                p2 = get_pos(piles, b);
                piles[p2.p].push_back(a);
            }
        }
        vector<int> res;
        for (auto &pile: piles) {
            if (pile.size() > 0) {
                res.push_back(pile.size());
            }

        }
        sort(res.begin(), res.end());
        for (int i = 0; i < (int)res.size(); i++) {
            cout << res[i] << endl;
        }
        cout << "end" << endl;
    }    
    return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
int main() {
  int n;
  std::cin >> n;
  std::vector<std::pair<int,int>> a(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.begin(), a.end());
  std::vector<int> ans(n);
  for (int i = 0; i < n; i++) {
    if (i < n/2) {
      ans[a[i].second] = a[n/2].first;
    } else {
      ans[a[i].second] = a[n/2-1].first;
    }
  }
  for (int i = 0; i < n; i++) {
    std::cout << ans[i] << "\n";
  }
  return 0;
}

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

int main()
{

#ifdef _d
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif

    int x;
    cin >> x;
    if (x >= 30) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

#ifdef _d
    cerr << "Time: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
#endif

    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
using namespace std;

int main()
{
    int X, A, B;
    cin >> X >> A >> B;

    X -= A;
    while (X >= B)
    {
        X -= B;
    }

    cout << X << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int n,m;
vector<int> yet[10];
int dp[10][2000100];
int x[100],y[100];
int f[10][10];
int fpow[20];
int tmp[20];
int k;
int encode(int s){
	int res = 0;
	for(int i=s;i<n;i++){
		res = res*5+tmp[i];
	}
	return res;
}
void decode(int S){
	for(int i=n-1;i>=0;i--){
		tmp[i]=S%5;
		S/=5;
	}
}
void print(){
	for(int i=0;i<n;i++){
		cout << tmp[i] << ' ';
	}
	cout << endl;
}
bool solve(){
	scanf("%d",&n);
	if(n==0)return false;
	scanf("%d",&m);
	memset(f,-1,sizeof(f));
	memset(dp,0,sizeof(dp));
	for(int i=0;i<n;i++)yet[i].clear();
	k = (n-1)/2;
	for(int i=0;i<m;i++){
		scanf("%d %d",&x[i],&y[i]);
		x[i]--;y[i]--;
		f[x[i]][y[i]]=1;
		f[y[i]][x[i]]=0;
	}
	/*for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cout << f[i][j] << ' ';
		}
		cout << endl;
	}*/
	for(int i=0;i<n;i++){
		tmp[i]=k;
		for(int j=0;j<n;j++){
			if(i==j)continue;
			if(f[i][j]==1)tmp[i]--;
		}
		if(tmp[i]<0){
			printf("0\n");
			return true;
		}
	}
	/*for(int i=0;i<n;i++){
		cout << tmp[i] << endl;
	}*/
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(f[i][j]==-1)yet[i].pb(j);
		}
	}
	/*for(int i=0;i<n;i++){
		for(int j=0;j<yet[i].size();j++){
			cout << yet[i][j] << ' ';
		}
		cout << endl;
	}*/
	dp[0][encode(0)]=1;
	for(int i=0;i<n-1;i++){
		int yy = yet[i].size();
		for(int j=0;j<fpow[n-i];j++){
			if(dp[i][j]==0)continue;
			decode(j);
			for(int k=0;k<(1<<yy);k++){
				int cnt=0;
				for(int l=0;l<yy;l++){
					if((k>>l)&1){
						cnt++;
					}else{
						if(tmp[yet[i][l]]==0){
							cnt=-1;
							break;
						}
					}
				}
				if(cnt!=tmp[i])continue;
				for(int l=0;l<yy;l++){
					if(!((k>>l)&1)){
						tmp[yet[i][l]]--;
					}
				}
				dp[i+1][encode(i+1)]+=dp[i][j];
				decode(j);
			}

		}
	}
	printf("%d\n",dp[n-1][0]);
	return true;
}
int main(){
	fpow[0]=1;
	for(int i=0;i<10;i++)fpow[i+1]=fpow[i]*5;
	while(solve()){}
	return 0;
}


Measured memory_bytes: 81264
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
#include <cstdint>
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 sc second
#define fr first
#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'
#define mod 1000000007
typedef long long ll;

unsigned gcd(int a, int b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}


ll comb(int n, int r) {
	if (r * 2 > n) r = n - r;
	uintmax_t dividend = 1;
	uintmax_t divisor = 1;
	for (unsigned int i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}

int compare_char(const void* left, const void* right) {
	char *left_char = (char *)left;
	char *right_char = (char *)right;

	return strcmp(left_char, right_char);
}

int main(){


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

	//int N, M, *A, *B, i, j, *W, *flag, sum=0, start, end, length, tmp;
	ll i, j, k, l, m, n, len;
	ll A, B, C, D, N, M, K, num_R, num_G, num_B, ans;
	ll sum = 0, sum_B = 0, sum_C = 0, max, min, count = 0, Q, W, X;
	ll **dp;
	char S[3];


	ll temp1, temp2;




	cin >> S;


	if (strcmp(S,"ARC")==0)
	cout << "ABC" << endl;
	else
	cout << "ARC" << endl;

	return 0;

}//1 2 3 4 5 6
    

Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.StringTokenizer;

/**
 * Baton Relay Game
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			StringTokenizer st = new StringTokenizer(line);
			int N = Integer.parseInt(st.nextToken());

			Deque<Integer> relays = new ArrayDeque<Integer>();
			Deque<Integer> duties = new ArrayDeque<Integer>();

			for (int i = 0; i < N; i++) {
				relays.offer(i);
			}

			st = new StringTokenizer(br.readLine());
			while (st.hasMoreTokens()) {
				int a = Integer.parseInt(st.nextToken());
				if (a % 2 == 0) {
					for (int i = 0; i < a; i++) {
						relays.offer(relays.poll());
					}
				} else {
					for (int i = 0; i < a; i++) {
						relays.offerFirst(relays.pollLast());
					}
				}
				duties.offer(relays.pollFirst());
			}

			StringBuilder sb = new StringBuilder();
			st = new StringTokenizer(br.readLine());
			while (st.hasMoreTokens()) {
				int q = Integer.parseInt(st.nextToken());
				sb.append(duties.contains(q) ? "0\n" : "1\n");
			}
			System.out.print(sb.toString());

		} // end while
	} // end main
}

Measured memory_bytes: 42024