akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void)
{
	long long int n,m,flg,i,j,a[1001],b[1001],c[1001];
	long long int e[1001],p[1001],q[1001];
	while(1){
		scanf("%lld",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			a[i]=0; b[i]=0; c[i]=0;
		}	
		for(i=0;i<n;i++){
			scanf("%lld %lld %lld",&e[i],&p[i],&q[i]);
			if(p[i]*q[i]>=1000000) a[i]=1;
			if(a[i]==0) b[i]=p[i]*q[i];
		}	
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(e[i]==e[j]){
					if(a[i]==0){
						b[i]+=b[j];
						b[j]=0;
					}
					if(b[i]>=1000000&&a[i]==0) a[i]=1;
				}
			}
		}
		flg=0;
		for(i=0;i<n;i++){
			if(a[i]!=0){
				printf("%lld\n",e[i]);
				flg=1;
			}
		}	
		if(flg==0) printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 2596
#!/usr/bin/ruby
n=gets.to_i
a=$<.map(&:to_i)
r=0
(0...n).each{|i|
	r+=a[i]/2
	a[i]%=2
	if i<n-1 && a[i]>0 && a[i+1]>0
		a[i]-=1
		a[i+1]-=1
		r+=1
	end
}
p r

Measured memory_bytes: 2684
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] cnt = new int[m+1];
		int i, j;
		for(i=0; i <= m; i++) cnt[i] = 0;
		for(i = 0; i < n; i++) {
			int k0 = sc.nextInt();
			for(j = 0; j < k0; j++) {
				cnt[sc.nextInt()]++;
			}
		}
		sc = null;
		int cnt2 = 0;
		for(i=1; i <= m; i++) {
			if(cnt[i] == n)	cnt2++;
		}
		System.out.println(cnt2);
	}

}


Measured memory_bytes: 24020
#define 
n=int(input())
a=list(map(int,input().split()))
countlist=[]

for x in range(n):
    count=0
    while a[x]%2==0:
        a[x]=int(a[x]/2)
        count=count+1
    countlist.append(count)

print(min(countlist))


Measured memory_bytes: 2940
from collections import defaultdict
def solve():
  N, M = map(int, input().split())
  d = defaultdict(lambda: -1)
  for i in range(M):
    x,y = map(int, input().split())
    if d[x]>=0 and d[x]!=y:
      return -1
    if N>1 and x==1 and y==0:
      return -1
    d[x] = y
  if N==1 and d[1]==-1:
    return 0
  if d[1]==-1:
    d[1] = 1
  for i in range(2,N+1):
    if d[i]==-1:
      d[i] = 0
  ans = ''
  for i in range(1,N+1):
    ans += str(d[i])
  return ans
print(solve())

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

using i64 = int64_t;

int cumsum[100005] = {0};

int main(){
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    for(int i=1;i<n;++i){
        cumsum[i] = cumsum[i-1];
        if(s[i-1] == 'A' && s[i] == 'C'){
            cumsum[i]++;
        }
    }

    for(int i=0;i<q;++i){
        int l, r;
        cin >> l >> r;
        cout << cumsum[r-1] - cumsum[l-1] << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
a, b, c, x, y = map(int, input().split())

if x < y:
    big_num = y
    small_num = x
    big_price = b
    #small_price = a
else:
    big_num = x
    small_num = y
    big_price = a
    #small_price = b
    
ans = 0
ans += min(a + b, 2 * c) * small_num
ans += min(big_price, 2 * c) * (big_num - small_num)

print(ans)

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

typedef long long int ll;

int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n,C;
    cin>>n>>C;
    
    vector<ll>w(n),v(n);
    // for(ll &x:w)cin>>x;
    for(ll i=0;i<n;i++){
        cin>>w[i]>>v[i];
    }
    
    vector<vector<ll> >dp(n,vector<ll>(C+1));
    
    for(ll i=0;i<n;i++){
        for(ll j=1;j<=C;j++){
            
            if(i==0 && w[i]<=j){
                dp[i][j]=v[i];
                continue;
            }
            
            if(i==0)continue;
            
            if(w[i]>j){
                dp[i][j]=dp[i-1][j];
            }
            
            else
            dp[i][j]=max(dp[i-1][j],v[i]+dp[i-1][j-w[i]]);
            
        }
    }
    
    cout<<dp[n-1][C]<<'\n';
    
    return 0;
    
}

Measured memory_bytes: 79488
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let a = v[0];
	let b = v[1];
	if b%a == 0 {
		println!("{}", a+b);
	}else{
		println!("{}", b-a);
	}
}

Measured memory_bytes: 4352
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
// #include <atcoder/all>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

struct union_find{
    VI par, sz;

    void init(int n){
        par.resize(n);
        REP(i,n) par[i] = i;
        sz.assign(n, 1);
    }

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

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

    void merge(int x, int y){
        x = find(x);
        y = find(y);
        if (x == y) return;
        par[x] = y;
        sz[y] += sz[x];
    }

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

int main(void){
    int n;
    cin >> n;
    VI y(n), id(n);
    REP(i,n){
        int x = in() - 1, h = in() - 1;
        y[x] = h;
        id[x] = i;
    }
    union_find uf;
    uf.init(n);
    set<P> st;
    REP(i,n){
        if (st.empty() || st.begin()->first > y[i]){
            st.insert(P(y[i], id[i]));
        }else{
            P btm = *st.begin();
            while (!st.empty() && st.begin()->first < y[i]){
                P p = *st.begin();
                st.erase(p);
                uf.merge(id[i], p.second);
            }
            st.insert(btm);
        }
    }
    REP(i,n){
        printf("%d\n", uf.size(i));
    }

    return 0;
}


Measured memory_bytes: 12728
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String s = sc.next();
            int cnt = 0;
            for (char c : s.toCharArray()) {
                if (c == 'x') {
                    ++cnt;
                }
            }
            System.out.println(cnt < 8 ? "YES" : "NO");
        }
        sc.close();
    }
}


Measured memory_bytes: 22740
// Dāritys Morgho ban Rōvēgrie
// Math = ♥
// Sometimes it is people that no one imagines anything of who do things that no one can imagine
// After all this time? Always

#include <bits/stdc++.h>                        // uncomment before submission
//#include <ext/pb_ds/assoc_container.hpp>		// uncomment before submission
//#include <ext/pb_ds/tree_policy.hpp>			// uncomment before submission
//using namespace __gnu_pbds;					// uncomment before submission
using namespace std;
//<---------------------------------------------------Template----------------------------------------------------------->
#define int long long
#define ll long long
#define ld long double
const int INF = 1e15 + 7;
const int MAX = 1e5 + 7;
const int MOD = 1e9 + 7;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;                  // Vector of long long
typedef vector<vi> vvi;                 // Vector of vi
typedef vector<ii> vii;                 // Vector of pairs
typedef vector<vii> vvii;               // Vector of Vector of pairs
typedef vector<bool> vb;                // Vector of bool
#define pq priority_queue               // Max heap (To convert to min heap, use negative sign before every value)
#define ff first                        // For pairs
#define ss second                       // For pairs
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//<----------------------------------------------------------------------------------------------------------------------->

string num;
int K, D = 0;
vector<vvi> f(10005, vvi(105, vi(2, -1)));

int check(char c)
{
    return (c - '0');
}

int call(int pos, int sum, int flag)
{
    if (pos == num.size())
    {
        if (sum % D == 0) return 1;
        else return 0;
    }

    if (f[pos][sum][flag] != -1) return f[pos][sum][flag];

    int lim = 9;
    if (flag == 0) lim = check(num[pos]);

    int res = 0;
    for (int i = 0; i <= lim; i++)
    {
        int n_sum = (sum + i) % D;

        int n_flag = flag;
        if (i < lim) n_flag = 1;

        res = (res + call(pos + 1, n_sum, n_flag)) % MOD;
    }

    return f[pos][sum][flag] = res;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> num >> D;

    int ans = (call(0, 0, 0) + MOD - 1) % MOD;
    if (ans < 0) ans = 0;
    cout << (ans % MOD) << endl;
    return 0;
}


Measured memory_bytes: 61056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int N;
vector<vector<int>> G;
vector<int> A;

void dfs(int u, int p) {
    if (p != -1) A[u] += A[p];

    for (auto nv : G[u]) {
        if (nv == p) continue;

        dfs(nv, u);
    }
}

int main() {
    int Q; cin >> N >> Q;
    G.resize(N);
    A.assign(N, 0);
    for (int i = 0; i < N - 1; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    for (int i = 0; i < Q; i++) {
        int p, x; cin >> p >> x;
        p--;
        A[p] += x;
    }

    dfs(0, -1);

    for (int i = 0; i < N; i++) {
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 23552
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void print() { cout << "\n"; }
template <class T, class... Args>
void print(const T &x, const Args &... args) { cout << x << " "; print(args...);}
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif


int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  double max_C = 0;
  int su_wa = 100*a, su = 0;
  auto update = [&](int x, int y, int z, int w) {
    double res = c*z + d*w;
    res /= double(100*(a*x+b*y)+c*z+d*w);
    if (res > max_C) {
      max_C = res;
      su_wa = 100*(a*x+b*y)+c*z+d*w;
      su = c*z+d*w;
    }
    return res;
  };
  for (int x = 0; x <= 30; ++x) {
    for (int y = 0; y <= 30; ++y) {
      if (x == 0 && y == 0) continue;
      for (int z = 0; z <= 3000; ++z) {
        if (f - 100*(a*x+b*y) - c*z < 0) break;
        int max_w = (f - 100*(a*x+b*y) - c*z)/d;
        for (int w = 0; w <= max_w; ++w) {
          double X = c*z+d*w;
          X /= double(a*x+b*y);
          if (X > e) break;
          update(x,y,z,w);
        }
      }
    }
  }
  cout << su_wa << " " << su << endl; 
  return 0;
}

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

using namespace std;

void solve()
{
	int N;
	while(cin >> N, N)
	{
		vector< vector<int> > Vec(N + 1, vector<int>(N + 1));
		for(int i = 0; i < N; ++i)
		{
			for(int j = 0; j < N; ++j)
			{
				cin >> Vec[i][j];
			}
		}
		for(int i = 0; i < N; ++i)
		{
			for(int j = 0; j < N; ++j)
			{
				Vec[i][N] += Vec[i][j];
				Vec[N][i] += Vec[j][i];
			}
		}
		for(int i = 0; i < N; ++i)
		{
			Vec[N][N] += Vec[i][N];
		}
		for(int i = 0; i < N + 1; ++i)
		{
			for(int j = 0; j < N; ++j)
			{
				printf("%5d", Vec[i][j]);
			}
			printf("%5d\n", Vec[i][N]);
		}
	}
}

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

Measured memory_bytes: 0
#include<stdio.h>
#include<stdio.h>

#define MAX 20000

int main(void)
{
  int i,j;
  int a[MAX],b[MAX],cal[MAX];
  char op[MAX];

  for(i=0;i<MAX;i++)
    {
      scanf("%d %c %d",&a[i],&op[i],&b[i]);
      if(op[i]=='?')
	break;
    }
  
  for(j=0;j<i;j++)
    {
      if(op[j]=='+')
	cal[j]=a[j]+b[j];
      else if(op[j]=='-')
	cal[j]=a[j]-b[j];
      else if(op[j]=='*')
	cal[j]=a[j]*b[j];
      else if(op[j]=='/')
	cal[j]=a[j]/b[j];
      
      printf("%d\n",cal[j]);
    }
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>p(n);
  int cnt=0;
  for(int i=0;i<n;i++)cin>>p[i];
  for(int i=1;i<n-1;i++){
    if((p[i-1]<p[i]&&p[i]<p[i+1])||(p[i-1]>p[i]&&p[i]>p[i+1])){
      cnt++;
      //cout<<p[i]<<endl;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3520
#include <iostream>
using namespace std;
int main(void){
    int c1,c5,c10,c50,c100,c500;
    cin >> c1 >> c5 >> c10 >> c50 >> c100 >> c500;
    int x=c1+c5*5+c10*10+c50*50+c100*100+c500*500;
    if(x >= 1000){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }
}


Measured memory_bytes: 3092
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdin = new Scanner(System.in);
		int a = stdin.nextInt();
		int b = stdin.nextInt();
		int c = stdin.nextInt();
		if(a<b) {if(a<=c&&c<=b) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		}else {
			if(b<=c&&c<=a) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}


	}

}


Measured memory_bytes: 21844
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>

#include<deque>
#define pi 3.141592653589793238
#include<chrono>

#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f0 get<0>
#define f1 get<1>
#define f2 get<2>
#define db double
using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll n, s;
        cin >> n >> s;
        vector<ll> v(n);
        for(i = 0 ; i < n ; i++){
            cin>> v[i];
        }
        ll mod = 998244353;
 
        ll dp[3001][3001] = { 0 };
        dp[0][0] = 1;
        for(i = 0 ; i < n; i++){
            for(j = 0; j <= s; j++){
                dp[i + 1][j] += 2 * dp[i][j];
              dp[i + 1][j] %= mod;
            }
            for(j = v[i]; j <= s; j++){
                dp[i + 1][j] += dp[i][j - v[i]];
                dp[i + 1][j] %= mod;
            }
        }
        cout << dp[n][s] % mod;
    }
    
    return 0;
}


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

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

  vector<int> a(n);
  for(int i = 0; i < n; i++){
      cin >> a.at(i);
  }

  vector<int> s = a;
  sort(s.rbegin(), s.rend());

  for(int i = 0; i < n; i++){
      if(a.at(i) == s.at(0)){
          int ans = s.at(1);
          cout << ans << endl;
      }
      else{
          int ans = s.at(0);
          cout << ans << endl;
      }
  }
  return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k); i > (n); i--)
#define FORre(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  int p, q, r;
  cin >> p >> q >> r;
  cout << min(p+q, min(q+r, r+p)) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
ll a[1005][1005];
int n;
int pri[10005],tot;
bool mk[10005];
ll lcm(ll a,ll b) {
	if((!a)||(!b)) return a+b;
	return 1ll*a/__gcd(a,b)*b;
}
int main() {
	scanf("%d",&n);
	if(n==2) {
		printf("4 7\n23 10");
		return 0;
	}
	mk[1] = mk[0] = 1;
	for(int i=2;i<=10000;i++) {
		if(!mk[i]) { pri[++tot]=i; }
		if(tot==1000) break;
		for(int j=1;j<=tot&&1ll*pri[j]*i<=10000;j++) {
			int k = pri[j] * i;
			mk[k] = 1;
			if(i%pri[j]==0) break;
		}
	}
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=n;j++) {
			if((i+j)%2==0) a[i][j] = pri[(i + j) / 2] * pri[n+((i-j)/2+(n+1)/2)];
		}
	}
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=n;j++) {
			if((i+j)%2==1) a[i][j] = lcm( lcm(a[i-1][j],a[i+1][j]),lcm(a[i][j-1],a[i][j+1]) ) + 1;
			printf("%lld ",a[i][j]);
		}
		puts("");
	}
}

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

int main(){
  string S;
  cin >> S;
  
  for(int i=0; i<4; i++){
    int cnt = 0;
    for(int j=0; j<4; j++){
      if(S[i]==S[j]){
        cnt++;
      }
    }
    if(cnt != 2){
      cout << "No";
      return 0;
    }
  }
  
  cout << "Yes";
  return 0;
}

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

int n;
string s;

void go (int i, char c, int f) {
	if (i == n) {
		cout << s << endl;
		return;
	}

	for (char x = 'a'; x <= c; x++) {
		s[i] = x;
		go(i + 1, c, 1);
	}

	if (f) {
		s[i] = c + 1;
		go(i + 1, c + 1, 1);
	}
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	s.resize(n);
	go(0, 'a', 0);

	return 0;
}


Measured memory_bytes: 1536
import sys
def input(): return sys.stdin.readline().rstrip()

A,B,C,K = map(int,input().split())

point = 0

if A <= K:
    point += A
    K -= A
else:
    point += K
    K = 0

if B <= K:
    K -= B
else:
    K = 0

point -= K

print(point)

Measured memory_bytes: 9152
N = int(input())
a = list(map(int, input().split()))

mx = max(a)
mn = min(a)
if (mx-mn) >= 2 :
    print('No')
elif mx == mn == N-1 :
    print('Yes')
elif mx == mn :
    if N >= mx*2 :
        print('Yes')
    else :
        print('No')
elif (mx-mn) == 1 :
    mx_cnt = 0
    mn_cnt = 0
    for i in range(N) :
        if a[i] == mx :
            mx_cnt += 1
        else :
            mn_cnt += 1

    if mn < mn_cnt :
        print('No')
    elif mx_cnt >= (mx-mn_cnt)*2:
        print('Yes')
    else :
        print('No')

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;

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

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int n; cin >> n;
    vec<PII> xl(n); rep(i,n) cin >> xl[i].first >> xl[i].second;
    //sort(all(xl));
    vec<PII> ul(n);
    for(int i = 0; i < n; i++) {
        ul[i].first = xl[i].first+xl[i].second;
        ul[i].second = xl[i].first-xl[i].second;
    }
    sort(all(ul));

    int ans = 0;
    int t = -inf;
    for(int i = 0; i < n; i++) {
        if(t <= ul[i].second) {
            ans++;
            t = ul[i].first;
        }
    }
    //vi low(n); rep(i,n) low[i] = xl[i].first - xl[i].second;
    //vi up(n); rep(i,n) up[i] = xl[i].first + xl[i].second;

    cout << ans << '\n';    

}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

const int MAX_N = 100000;

int main () {
    string s;
    cin >> s;
    int n = s.size();

    int t[MAX_N] = {0};
    int a[MAX_N] = {0};

    for (int i = 0; i < n - 1; i++) {
        if (s[i] == 'R' && s[i + 1] == 'L') {
            t[i] = 1;
        }
    }

    for (int i = 0; i < n - 1; i++) {
        if (t[i] == 1) {
            int index = i - 1;
            int j = 1;
            int count1 = 1;
            int count2 = 0;
            while (index >= 0 && s[index] == 'R') {
                if (j % 2 == 0) {
                    count1++;
                } else {
                    count2++;
                }
                j++;
                index--;
            }
            index = i + 1;
            j = 1;
            while (index < n && s[index] == 'L') {
                if (j % 2 == 0) {
                    count1++;
                } else {
                    count2++;
                }
                j++;
                index++;
            }
            a[i] = count1;
            a[i+1] = count2;
        }
    }

    for (int i = 0; i < n; i++) {
        if (i == n - 1) {
            cout << a[i];
        } else {
            cout << a[i] << " ";
        }
    }

    cout << endl;
}


Measured memory_bytes: 1408
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}

void solve() {
	int N, a, b; cin >> N >> a >> b;
	COMinit();
	ll sum = sub(bin_pow(2, N), 1);
	ll res1 = 1;
	FOR(i, N - a + 1, N + 1) {
		res1 *= i;
		res1 %= MOD;
	}
	res1 = mult(res1, finv[a]);

	ll res2 = 1;
	FOR(i, N - b + 1, N + 1) {
		res2 *= i;
		res2 %= MOD;
	}
	res2 = mult(res2, finv[b]);
	sum = sub(sum, res1);
	sum = sub(sum, res2);
	print(sum);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


map<string,int> MAP;

int main(){

	int num_query;
	scanf("%d",&num_query);

	int command,x;

	for(int loop = 0; loop < num_query; loop++){

		string tmp;
		scanf("%d",&command);

		if(command == 0){

			cin >> tmp >> x;
			MAP[tmp] = x;

		}else{

			cin >> tmp;
			printf("%d\n",MAP[tmp]);
		}
	}

	return 0;
}




Measured memory_bytes: 27932
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int K = sc.nextInt();
        long[] A = new long[N+1];
        long[] B = new long[M+1];
        A[0] = 0;
        B[0] = 0;
        for (int i=1; i<=N; i++) {
            A[i] = A[i-1] + sc.nextInt();
        }
        for (int i=1; i<=M; i++) {
            B[i] = B[i-1] + sc.nextInt();
        }
        int j = M;
        int count = 0;
        for (int i=0; i<=N; i++) {
            if (A[i]>K) {
                break;
            }
            while (B[j]+A[i]>K) {
                j--;
            }
            count = Math.max(count, i+j);
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 62992
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    ll N;
    cin >> N;
    vec<int> A(N);
    A[0] = 0;
    map<int,int> mp;
    rep(i,N-1){
        cin >> A[i+1];
        mp[A[i+1]]++;
    }
    for(int i=1;i<=N;++i){
        cout << mp[i] << endl;
    }
}


Measured memory_bytes: 13556
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
    public static void main (String[] args) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String[] inputs = br.readLine().split(" ");
	int n = Integer.parseInt(inputs[0]);
	int k = Integer.parseInt(inputs[1]);
	int[] w = new int[n];
	int min = 0, maxWeight = 0;
	for (int i = 0; i < n; i++) {
	    w[i] = Integer.parseInt(br.readLine());
	    maxWeight += w[i];
	    if (min < w[i]) {
		min = w[i];
	    }
	}

	int p = 0, sum, cnt;
	while (min != maxWeight) {
	    p = (min + maxWeight) / 2;
	    sum = 0;
	    cnt = 1;
	    for (int i = 0; i < n; i++) {
		if (sum + w[i] > p) {
		    cnt++;
		    sum = w[i];
		} else {
		    sum += w[i];
		}
	    }
	    if (cnt <= k) {
		maxWeight = p;
	    } else {
		min = p + 1;
	    }
	}
	System.out.println(min);
    }
}

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

int main(){
 string s;
 cin >> s;
 int check = 0;
 for(int i=0;i<s.size();i++){
   if( ((i+1) % 2 == 1) && s.at(i) == 'L'){
     check++;
     break;
   }else if(((i+1) % 2 == 0) && s.at(i) == 'R'){
     check++;
     break;
   }
 }
 if(check != 0){
   cout << "No";
 }else{
   cout << "Yes";
 }
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

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

    int ans = 0;
    for(int i=1; i < (n + 1)/2; i++) ans++;

    cout << ans << endl;


    return 0;

}



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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int i,n,m,x,y,a=-1000,b=1000,t;
	cin>>n>>m>>x>>y;
	for (i=0;i<n;i++){
		cin>>t;
		a=max(a,t);
	}
	for (i=0;i<m;i++){
		cin>>t;
		b=min(b,t);
	}
	if (a>=b){
		cout<<"War";
	}
	else {
		if (b>x&&b<=y){
			cout<<"No War";
		}
		else {
			cout<<"War";
		}
	}
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	double a, b, c, d, e, f;
	for (; cin >> a >> b >> c >> d >> e >> f;)
	{
		double x, y;
		if (a == 0 || b == 0 || d == 0 || e == 0)
		{
			if (a == 0)
			{
				y = c / b;
				x = (f - e * y) / d;
			}
			else if (b == 0)
			{
				x = c / a;
				y = (f - d * x) / e;
			}

			if (d == 0)
			{
				y = f / e;
				x = (c - b * y) / a;
			}
			else if (e == 0)
			{
				x = f / d;
				y = (c - a * x) / b;
			}
		}
		else
		{
			double a0 = a * e;
			double c0 = c * e;

			double d0 = d * b;
			double f0 = f * b;

			x = (f0 - c0) / (d0 - a0);

			y = (c - a * x) / b;
		}

		cout << fixed << setprecision(3) << x + 0 << " " << y + 0 << endl;

	}
}


Measured memory_bytes: 3212
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    string s;
    cin>>s;
    int count=0;
    bool flag=false;
    if(s.at(0)=='A'){
      	if((s.at(1)>='A'&&s.at(1)<='Z')||(s.at(s.size()-1)>='A'&&s.at(s.size()-1)<='Z')){
          count=2;
        }
        for(int i=2;i<=s.size()-2;i++){
            if(s.at(i)=='C'){
                count++;
            }
            else if(s.at(i)>='A'&&s.at(i)<='Z'){
                    count=2;
                }   
        }
        if(count==1){
            flag=true;
        }
    }
    if(flag==true){
        cout<<"AC"<<endl;
    }
    else{
        cout<<"WA"<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const int N=3e2+20;
set<ii> s[N];
int main()
{
	ll h,w,n,a,b;
	while(cin>>h>>w)
	{
		cin>>n;
		for(int i=0;i<=10;i++)
			s[i].clear();
		for(int i=0;i<n;i++)
		{
			scanf("%lld%lld",&a,&b);
			for(int i=0;i<3;i++)
			{
				for(int j=0;j<3;j++)
				{
					int pos=0;
					if(a+i>h||b+j>w||a+i<3||b+j<3)
						continue;
				//	cout<<a+i<<' '<<b+j<<endl;
					for(int k=0;k<10;k++)
					{
						ii t=ii(a+i,b+j);
						if(s[k].find(t)!=s[k].end())
						{
							pos=k;
						//	cout<<pos<<endl;
							break;
						}
					}
					if(pos)
						s[pos].erase(ii(a+i,b+j));
					s[pos+1].insert(ii(a+i,b+j));
				}
			}	
		}
		ll cnt=0;
		for(int k=1;k<=9;k++)
			cnt+=s[k].size();
		printf("%lld\n",(h-2ll)*(w-2ll)-cnt);
		for(int k=1;k<=9;k++)
			printf("%lld\n",s[k].size());	
	}
	
	return 0;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int ans = 0;
    map<string, int> m;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        string s; int t;
        cin >> s >> t;
        sum += t;
        m[s] = sum;
    }
    string x; cin >> x;
    cout << sum - m[x] << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
typedef long long ll;

using namespace std;

int main(){
    ll a,b,n;
    ll max = 0,i = 0;
    cin >> a >> b >> n;
      
    if(b > n){
        cout << floor((a*n)/b) << endl;
    }else if(b == 1){
        cout << max << endl;
    }else{
        for(i = b-1; i <= n; i += b){
            if(max < (floor((a*i)/b) - a * floor(i/b))) max = floor((a*i)/b) - a * floor(i/b);

        }
        cout << max << endl;
    }
    return 0;
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<lld,lld> P;
#define INF ((lld)1<<55)

lld M,N,K;
vector<P> X[100010],Y[100010];
vector<P> node[400010];
lld min_cost[400010];

int main(){
  cin >> M >> N >> K;
  for(int i=0;i<K;i++){
    lld A,B; cin >> A >> B;
    X[A].push_back(P(B,i));
    Y[B].push_back(P(A,i));
  }
  X[1].push_back(P(1,K));
  Y[1].push_back(P(1,K));
  X[M].push_back(P(N,K+1));
  Y[N].push_back(P(M,K+1));
  K += 2;
  for(int i=1;i<=M;i++){
    sort(X[i].begin(),X[i].end());
    for(int j=1;j<X[i].size();j++){
      P p1 = X[i][j-1] , p2 = X[i][j];
      node[p1.second].push_back(P(p2.second,llabs(p1.first-p2.first)));
      node[p2.second].push_back(P(p1.second,llabs(p1.first-p2.first)));
    }
  }
  for(int i=1;i<=N;i++){
    sort(Y[i].begin(),Y[i].end());
    for(int j=1;j<Y[i].size();j++){
      P p1 = Y[i][j-1] , p2 = Y[i][j];
      node[p1.second+K].push_back(P(p2.second+K,llabs(p1.first-p2.first)));
      node[p2.second+K].push_back(P(p1.second+K,llabs(p1.first-p2.first)));
    }
  }
  for(int i=0;i<K-2;i++){
    node[i].push_back(P(i+K,1));
    node[i+K].push_back(P(i,1));
  }
  fill_n(min_cost,400010,INF);
  priority_queue<P,vector<P>,greater<P> > que;
  min_cost[K-2] = 0;
  que.push(P(0,K-2));
  while(!que.empty()){
    P p = que.top(); que.pop();
    lld cost = p.first , pos = p.second;
    if(pos == K-1 || pos == 2*K-1){
      cout << cost << endl;
      exit(0);
    }
    if(min_cost[pos] < cost) continue;
    for(int i=0;i<node[pos].size();i++){
      P pi = node[pos][i];
      lld next = pi.first , dis = pi.second;
      if(min_cost[next] > cost + dis){
	min_cost[next] = cost + dis;
	que.push(P(cost+dis,next));
      }
    }
  }
  cout << "-1" << endl;
}

Measured memory_bytes: 63220
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn read_vec_char() -> Vec<char> {
    read::<String>().chars().collect()
}

fn read_mat<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let s = read_vec_char();
    let ans = s.iter().fold(700,|acc, &x| if x == 'o' { acc + 100 } else { acc });
    println!("{}",ans);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] a = new int[n][2];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 2; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            int b = a[i][1] - a[i][0];
            count += b + 1;
        }
        System.out.println(count);

    }
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define UB upper_bound
#define LB lower_bound
#define PB push_back
#define mp make_pair
#define F first
#define S second
#define be(a) (a).begin(),(a).end()
#define deb(x) cout<< #x <<" "<<endl;
#define deb2(x, y) cout<< #x <<" "<< x <<endl<< #y <<" "<<y<<endl
#define fo(i, n) for(long long i=0; i<n; i++)
#define Fo(i, n, k) for(long long i=k; i<n; i++)
#define mod 1000000007
#define int long long

typedef long long ll;

void fileIO()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
 
typedef vector<pair<int, int>> vll;
typedef unordered_map<int, int> ump;



bool sortbysecdesc(const pair<int, int> &a, 
                    const pair<int, int> &b) 
{ 
    return a.second>b.second;
}


vector<vector<int>> dp(400, vector<int>(400, -1));


int slimeCost(vector<int> &a, int i, int j, vector<int> &prefix_sum)
{
    int &val = dp[i][j];

    if(val != -1) return val;

    if(i >= j) val = 0;

    else
    {

        int ans = 1e16;

        for(int k = i; k<j; k++)
        {
            int temp = slimeCost(a, i, k, prefix_sum) + slimeCost(a, k+1, j, prefix_sum);
            if(i == 0) {temp += prefix_sum[k];}
            else temp += (prefix_sum[k] - prefix_sum[i-1]);

            temp += prefix_sum[j] - prefix_sum[k];

            ans = min(ans, temp);
        }

        val = ans;

    }

    

    return val; 
}



int32_t main()
{
    IOS;
    fileIO();
    int T;
    T = 1;
    //cin>>T;

    while(T--)
    {
        int n;

        cin>>n;

        vector<int> a(n);

        for(int i = 0; i<n; i++) cin>>a[i];

        vector<int> prefix_sum(n);

        prefix_sum[0] = a[0];

        for(int i = 1; i<n; i++) prefix_sum[i] = prefix_sum[i-1] + a[i];

        int res = slimeCost(a, 0, n-1, prefix_sum);

        cout<<res<<"\n";

    }
    
    return 0;
}

    


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


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

    int n,k,q;
    cin >> n >> k >> q;
    vector<int> a(n);
    vector<int> b(q);
    rep (i, q) {
        cin >> b[i];
        b[i]--;
    }
    vector<int> d(n);
    rep (i, q)  d[b[i]]++;
    rep (i, n) {
        a[i] = k - q + d[i];
        if (a[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 4508
/// In The Name Of God

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

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

using namespace std;

int n;
int a[N], pr[N];

struct fenwick {
	int f[N];
	void clear() {
		memset(f, 0, sizeof(f));
	}
	void upd(int p, int x) {
		p += n;
		for (; p <= n + n; p |= p + 1) f[p] += x;
	}
	int get(int p) {
		int res = 0;
		p += n;
		for (; p >= 0; p = (p & (p + 1)) - 1) res += f[p];
		return res;
	}
} t;

ll cnt(int x) {
	ll res = 0;
	t.clear();
	rep(i, 1, n) {
		pr[i] = pr[i - 1] + (a[i] >= x ? 1 : -1);
		t.upd(pr[i - 1], 1);
		res += t.get(pr[i]);
		// rep(j, 1, i) res += (pr[i] >= pr[j - 1]);
	}
	return res;
}
int main() {
	#ifdef wws
		freopen ("in.txt", "r", stdin);
	#endif
	Kazakhstan
	cin >> n;
	rep(i, 1, n) {
		cin >> a[i];
	}
	int l = 1, r = inf, ans = -1;
	ll atl = (ll)n * (n + 1) / 2;
	atl = atl - (atl / 2 + 1) + 1;
	while (l <= r) {
		int mid = l + (r - l) / 2;
		if (cnt(mid) >= atl) ans = mid, l = mid + 1;
		else r = mid - 1;
	}
	cout << ans;
	ioi
}


Measured memory_bytes: 4608
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

static const int MAX = 2000000;
static const int INFTY = (1 << 30);

int H, A[MAX+1];

void maxHeapify(int i){
 int l, r, largest;

  l = 2 * i;
  r = 2 * i + 1;

  if(l <= H && A[l] > A[i]){
    largest = l;
  }
  else largest = i;
  if(r <= H && A[r] > A[largest]){
    largest = r;
  }
  if(largest != i){
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}

int extract(){
  int maxv;

  if(H < 1) return -INFTY;
  maxv = A[1];
  A[1] = A[H--];
  maxHeapify(1);

  return maxv;
}

void increaseKey(int i, int key){
  if(key < A[i]) return ;
  A[i] = key;

  while(i > 1 && A[i / 2] < A[i]){
    swap(A[i], A[i / 2]);
    i = i / 2;
  }
}

void insert(int key){
  H++;

  A[H] = -INFTY;
  increaseKey(H, key);
}

int main(){
    int key, i = 0, B[MAX];
    char com[10];

  while(1){
    cin >> com;

    if(com[0] == 'e' && com[1] == 'n') break;
    if(com[0] == 'i'){
      cin >> key;
      insert(key);
    }
    else{
     B[i] = extract();
     i++;
    }
  }
  for(int j = 0; j < i; j++){
    cout << B[j] << endl;
  }
  
  return 0;
}



Measured memory_bytes: 8888
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int A[20];
int Ans[2001];
int Ans2[2001];
int n;

void getAns() {
	Ans[0] = 1;
	int maxI = 0;
	int maxI2;
	int i, j;
	for (j = 0; j < n; ++j) {
		i = 0;
		while(1){
			if (i > maxI) {
				break;
			}
			if (Ans[i] == 1) {
				if (i + A[j] <= 2000) {
					maxI2 = i + A[j];
					Ans2[maxI2] = 1;
				}
				else {
					break;
				}
			}
			++i;
		}
		maxI = maxI2;
		for (i = 0; i <= maxI; ++i) {
			if (Ans2[i] == 1) {
				Ans[i] = 1;
			}
		}
	}
}

int main() {
	int q;
	int m;
	int i;

	for (i = 0; i < 2001; ++i) {
		Ans[i] = 0;
		Ans2[i] = 0;
	}

	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		scanf("%d", A + i);
	}

	getAns();

	scanf("%d", &q);
	for (i = 0; i < q; ++i) {
		scanf("%d", &m);
		if (Ans[m]) {
			printf("yes\n");
		}
		else {
			printf("no\n");
		}
	}


	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<utility>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
#define MP make_pair
#define PB push_back
#define F_d first
#define S_d second
#define LARGE 100000000
#define MOD 100000
#define LL long long

int N, K, M;

int main() {
	cin >> N >> K;
	if (N % 2 == 0)M = N / 2;
	else M = N / 2 + 1;
	if (M >= K)cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int d, n;
  cin >> d >> n;
  int base = pow(100, d);
  if (n == 100) {
    P(base * n + base);
  } else {
    P(base * n);
  }
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a==b){
		puts("Draw");
		return 0;
	}
	if(a==1){
		puts("Alice");
		return 0;
	}
	if(b==1){
		puts("Bob");
		return 0;
	}
	if(a>b){
		puts("Alice");
		return 0;
	}
	if(a<b){
		puts("Bob");
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll a;
  	ci(a);
  if(a<=999) co("ABC")
  else co("ABD")
    }

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# INF=10^7程度じゃインプットの桁数ふえた時に更新処理が正しく走らず結果エラーになってしまう..
INF = 1000000000
n, k = map(int,  input().split())
h = list(map(int, input().split()))
dp = [INF]*n
dp[0] = 0

for i in range(n):
    for j in range(1, k+1):
        if i + j < n:
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i]-h[i+j]))

print(dp[n-1])


Measured memory_bytes: 52592
let _ = Int(readLine()!)!
let A = readLine()!.split(separator: " ").compactMap { Int($0) }
var result = 0
var minimum = A[0]
for i in 1..<A.count {
    let diff = A[i] - minimum
    if diff < 0 {
        result += -diff
    } else {
        minimum = A[i]
    }
}
print(result)


Measured memory_bytes: 21348
<?php
$N = trim(fgets(STDIN));
$L = explode(" ",trim(fgets(STDIN)));
sort($L);
$ans = 0;
for($i = 0;$i < $N * 2 - 1;){
    $ans += min($L[$i],$L[$i + 1]);
    $i += 2;
}
echo $ans ."\n";
?>

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

signed main() {
    int n;
    string s;
    int p;
    priority_queue<pair<string, int>, vector<pair<string, int>>, greater<pair<string, int>>> rst;
    
    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        cin >> s >> p;
        rst.push(make_pair(s, (100-p)*n+i) );
    }
    
    for ( int i = 0; i < n; i++ ) {
        cout << rst.top().second % n + 1 << endl;
        rst.pop();
    }
    return (0);
}

Measured memory_bytes: 3656
#include <stdio.h>
 
int main()
{
 
  int i;

  char moji[10];
 
  scanf("%s", moji);
 
  for(i=0; moji[i]!='\0'; ++i);

  if(i==2) printf("%s",moji);
  else if(i==3) printf("%c%c%c",moji[2],moji[1],moji[0]);
  
  return 0;
}


Measured memory_bytes: 128