akhauriyash/Code-Regression huggingface dataset:
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

i = 0
j = 0
k = 0
ans = 0
while  i+j+k < X+Y:
    if i == X:
        for n in range(Y-(j+k)):
            if k == C:
                ans += Q[j]
                j += 1
            elif Q[j] > R[k]:
                ans += Q[j]
                j += 1
            else:
                ans += R[k]
                k += 1
    elif j == Y:
        for n in range(X-(i+k)):
            if k == C:
                ans += P[i]
                i += 1
            elif P[i] > R[k]:
                ans += P[i]
                i += 1
            else:
                ans += R[k]
                k += 1
    elif k == C:
        if P[i] > Q[j]:
            ans += P[i]
            i += 1
        else:
            ans += Q[j]
            j += 1
    else:
        if P[i] >= max(Q[j], R[k]):
            ans += P[i]
            i += 1
        elif Q[j] >= max(P[i], R[k]):
            ans += Q[j]
            j += 1
        else:
            ans += R[k]
            k += 1

print(ans)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll h,w,n;
char s[700][700];
ll sumx[700][700],sumy[700][700];

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

  cin>>h>>w;
  rep(i,h){
    string in;
    cin>>in;
    rep(j,w){
      s[i+j][i-j+w-1]=in[j];
    }
  }
  n=h+w;
  rep(i,n)rep(j,n)if(s[i][j]==0)s[i][j]='.';
  ll res=0;
  rep(i,n)rep(j,n){
    if(s[i][j]=='#'){
      sumx[i][j+1]=sumx[i][j]+1;
      sumy[i+1][j]=sumy[i][j]+1;
    }else{
      sumx[i][j+1]=sumx[i][j];
      sumy[i+1][j]=sumy[i][j];
    }
  }
  rep(i,n){
    rep(j,n)repl(k,j+1,n){
      if(s[i][j]=='#'&&s[i][k]=='#'){
        ll d=k-j;
        if(i-d>=0)res+=sumx[i-d][k+1]-sumx[i-d][j];
        if(i+d<n)res+=sumx[i+d][k+1]-sumx[i+d][j];
      }
    }
  }
  rep(j,n){
    rep(i,n)repl(k,i+1,n){
      if(s[i][j]=='#'&&s[k][j]=='#'){
        ll d=k-i;
        if(j-d>=0)res+=sumy[k][j-d]-sumy[i+1][j-d];
        if(j+d<n)res+=sumy[k][j+d]-sumy[i+1][j+d];
      }
    }
  }

  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 7808
/* *
 *
 * Author: Hamkor
 *
 * */

#include <bits/stdc++.h>

using namespace std;

/* * * *   * * *   	* * * */
typedef long long ll;
const int oo = 1e9;
const ll mod = 100000000;
typedef complex<ll> P;
#define X real()
#define Y imag()
/* * * *   * * *   	* * * */
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int a[5];
	for(int i=0; i<5; ++i) cin>>a[i];
	sort(a, a+5);
	int m = 1e9;
	do{
        int c = 0;
        for (int j = 0; j <4; ++j){
            c+= a[j] + (10 - a[j]%10);
            if(a[j]%10 == 0) c-=10;
        }
        c+=a[4];
        m = min(m, c);
	}while (next_permutation(a, a+5));
	cout<<m;
	return 0;
}


Measured memory_bytes: 256
from sys import stdin

n = int(stdin.readline().strip())
count_dict = {}

for _ in range(n):
  s = stdin.readline().strip()
  count_dict[s] = count_dict.get(s, 0) + 1

max_count = max(count_dict.values())
freq_s_lst = [k for k, v in count_dict.items() if v == max_count]

print('\n'.join(sorted(freq_s_lst)))

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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

//#define int long long

/*************** using variables ***************/
int q;
vector<LL> a, b;
/**********************************************/

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

    cin >> q;
    a.resize(q);
    b.resize(q);
    REP(i, q){
        cin >> a[i] >> b[i];
    }
    REP(i, q){
        if(a[i] == b[i]){
            cout << 2 * a[i] - 2 << endl;
        }else if(a[i] + 1 == b[i]){
            cout << 2 * a[i] - 2 << endl;
        }else{
            LL ok = 0, ng = (LL)1e9+1;
            while(abs(ok - ng) > 1){
                LL mid = (ok + ng) / 2;
                if(mid*mid < a[i]*b[i]){
                    ok = mid;
                }else{
                    ng = mid;
                }
            }
            if(ok * (ok+1) >= a[i] * b[i]){
                cout << 2*ok - 2 << endl;
            }else{
                cout << 2*ok - 1 << endl;
            }
        }
    }
}


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

int main(){
    long long n, cnt=0;
    cin >> n;
    for(long long i=1; i<n+1; i++){
        if(i%3!=0 && i%5!=0) cnt += i;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	cin >> n;
	vector<int> a(n), b(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	sort(all(a)); sort(all(b));
	int ans = 0;
	for (int i = 29; i >= 0; i--) {
		int x = (1 << i);
		int y = (1 << (i + 1));
		rep(j, n) {
			int cntx = lower_bound(all(b), x - a[j] % y) - b.begin();
			int cnty = lower_bound(all(b), y - a[j] % y) - b.begin();
			cntx += lower_bound(all(b), x + y - a[j] % y) - b.begin();
			cnty += lower_bound(all(b), 2 * y - a[j] % y) - b.begin();
			int cnt = (cnty - cntx) & 1;
			if (cnt) ans ^= x;
		}
		rep(j, n) b[j] %= x;
		sort(all(b));
	}
	cout << ans << endl;
} 

Measured memory_bytes: 3328
#include <stdio.h>

int h, w, cont=0, m[55][55];
char mat[55][55];
bool b=false;

void f(int i, int j){
    if(i < 0 || j < 0)
        return;
    if(i >= h || j >= w)
        return;
    if(mat[i][j] == '.')
        return;
    if(m[i][j] == 1 )
        return;
        //printf("%d %d\n", i, j);
        cont += 1;
        m[i][j] = 1;

    f(i, j+1);
    f(i+1, j);
    f(i, j-1);
    f(i-1, j);
}

void r(){
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(mat[i][j] == '#' && m[i][j]==0){
                cont = 0;
                f(i, j);
                //printf("%d %d %d\n", i, j, cont);
                if(cont == 1){
                    b = false;
                    break;
                }
            }
        }
        if(!b)
            break;
    }
}

int main(){
    scanf("%d%d", &h, &w);
    int x, y;
    for(int i=0; i<h; i++){
        scanf("%s", mat[i]);
        if(!b){
            for(int j=0; j<w; j++){
                if(mat[i][j] == '#'){
                    b = true;
                    x = i; y=j;
                }
            }
        }
    }
    b=true;
    r();

    if(!b)
        printf("No\n");
    else
        printf("Yes\n");
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
const in mx=109*109;
VI ps(mx);
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n;
  cin>>n;
  in s;
  ps[0]=1;
  forn(z,n){
    cin>>s;
    for(in i=mx-1-s;i>=0;--i)
      ps[i+s]|=ps[i];
  }
  in b=0;
  forn(i,mx)
    if(ps[i] && i%10)
      b=i;
  cout<<b<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
    int S;
    cin >> S;
    if(S < 60){
        cout << 0 << ':' << 0 << ':' << S << endl;
    }
    else if(S < 3600){
        cout << 0 << ':' << S / 60 << ':' << S % 60 << endl;
    }
    else{
        cout << S / 3600 << ':' << S % 3600 / 60 << ':' << S % 60 << endl;
    }
}


Measured memory_bytes: 3096
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s : String = read();
    let s = s.chars().collect::<Vec<_>>();


    if s[0] != 'A' {
        println!("WA");
        return;
    }
    let mut cnt = 0;
    let mut ok = true;
    for i in 1..s.len() {
        if s[i] == 'C' && i >= 2 && i <= s.len() - 2 {
            cnt += 1;
        } else if !s[i].is_lowercase() {
            ok = false;
        }
    }
    println!("{}", if ok && cnt == 1 {
        "AC"
    } else {
        "WA"
    });
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define INF LLONG_MAX/2
#define PI acos(-1.0)
//#define MOD 1000000007

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

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;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(long long K, long long N, std::vector<long long> A){
    int max_distance=0;
    REP(i,0,N-1){
        chmax(max_distance,A[i+1]-A[i]);
    }
    chmax(max_distance,K+A[0]-A[N-1]);
    cout<<K-max_distance<<endl;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    long long K;
    scanf("%lld",&K);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(K, N, std::move(A));
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<list>
using namespace std;
const int MAX = 100000;
vector<int> G[MAX];
list<int> L;
bool book[MAX];
int n;
void depthFSearch(int u)
{
	book[u] = true;
	for (int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if (!book[v])
			depthFSearch(v);
	}
	L.push_front(u);
}
void topologicalSort()
{
	for (int i = 0; i < n; i++)
		if (!book[i])
			depthFSearch(i);
}
int main()
{
	int m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
	}
	topologicalSort();
	for (auto it = L.begin(); it != L.end(); it++)
		cout << *it << endl;
}


Measured memory_bytes: 6212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 2e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
int n, k;
int a[maxx];
ll ans;

int main() {
	scanf("%d %d", &n, &k);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n - k; i++) ans += (ll)a[i];
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	int[][] ps;
	int[] heap;
	int n, q;
	void run() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt(); q = sc.nextInt();
		ps = new int[n+1][2];ps[0][0] = INF;
		heap = new int[n+1];
		for(int i=1;i<=n;i++) {
			ps[i][0] = 0; ps[i][1] = i;
			heap[i] = i;
		}
		for(int i=0;i<q;i++) {
			int a = sc.nextInt(), v = sc.nextInt();
			ps[a][0] += v;
			if( v > 0 )up(ps[a][1]);
			else down(ps[a][1]);
			System.out.println(heap[1] + " " + ps[heap[1]][0]);
//			debug(heap);
//			debug(ps);
		}
	}
	
	void up(int p) {
		int cur = p;
		while( ps[heap[cur]][0] >= ps[heap[cur/2]][0] ) {
			if(ps[heap[cur]][0] > ps[heap[cur/2]][0]) swap(cur, cur/2);
			else {
				if(heap[cur] < heap[cur/2]) swap(cur, cur/2);
				else break;
			}
			cur /= 2;
		}
	}
	
	void down(int p) {
		int cur = p;
		while( cur*2 <= n ) {
			int sel = cur*2;
			if( cur*2+1 <= n ) {
				if(ps[heap[cur*2]][0] < ps[heap[cur*2+1]][0]) {
					sel = cur*2+1;
				}
				if( ps[heap[cur*2]][0] == ps[heap[cur*2+1]][0] ) {
					if(heap[cur*2] > heap[cur*2+1])
						sel = cur*2+1;
				}
			}
			if( ps[heap[cur]][0] < ps[heap[sel]][0] ) {
				swap(cur, sel);
			}
			else if( ps[heap[cur]][0] == ps[heap[sel]][0] ){
				if( heap[cur] > heap[sel] ) swap(cur, sel);
				else break;
			}
			else break;
			cur = sel;
		}
	}
	
	void swap(int p, int q) {
		int tmp = ps[heap[p]][1];
		ps[heap[p]][1] = ps[heap[q]][1];
		ps[heap[q]][1] = tmp;
		tmp = heap[p];
		heap[p] = heap[q];
		heap[q] = tmp;
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main() {
    int a, b;
    cin >> a;
    cin >> b;
    vector<int> h(999);
    for (int i = 1; i <= 999; i++) {
        if (i == 1) h[i] = 1;
        else h[i] = h[i-1] + i;
    }
    int k = b - a;
    int ans = h[k] - b;
    cout << ans << endl;
}

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

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define gcd(x,y) __gcd((x),(y))

#ifndef ONLINE_JUDGE
  #define db(x) cerr << #x << " == " << x << endl
  #define dbs(x) cerr << x << endl
  #define _ << ", " <<
#else
  #define db(x) ((void)0)
  #define dbs(x) ((void)0)
#endif

typedef long long ll;
typedef long double ld;

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

const ld EPS = 1e-9, PI = acos(-1.);
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

int n, f;
char s[10];

int ask(int x) {
  printf("%d\n", x); fflush(stdout);
  scanf("%s", s);
  if (s[0] == 'M') return 0;
  if (s[0] == 'F') return 1;
  if (s[0] == 'V') exit(0);
  return -1;
}

int main() {
  scanf("%d", &n);
  f = ask(0);

  int lo = 1, hi = n-1;
  while (lo < hi) {
    int mid = (lo+hi)/2;
    int t = ask(mid);
    if (f^(mid%2) == t) lo = mid+1;
    else hi = mid;
  }

  ask(lo);

  return 0;
}


Measured memory_bytes: 852
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

ll N,M;

int main(){
    cin>>N>>M;

    ll ans=abs((N-2)*(M-2));

    cout<<ans<<endl;
}

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

int main(){
    int n;
    cin >> n;
    long long sum = 0;
    for(int i=0;i<n;i++){
        if((i+1)%3!=0 && (i+1)%5!=0){
            sum += i+1;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
int N;
vector<ll> as;
int main(){
	cin>>N;
	as.resize(N);
	rep(i,N) cin>>as[i];
	ll L=2,R=2;
	for(int i=N-1;i>=0;i--){
		ll a = as[i];
		L = (L-1)/a*a+a;
		R = R/a*a;
		if(L>R){
			puts("-1");
			return 0;
		}
		R += a-1;
	}
	cout<<L<<" "<<R<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int N;
    ll rs = 0;
    cin >> N;
    vector<ll> A(N);
    bool kisuu = false;

    for(int i = 0;i < N;i++)
        cin >> A.at(i);

    sort(A.begin(),A.end());

    while(true){
        for(int i = 0;i < N;i++){
            if(A.at(i) % 2 != 0){
                kisuu = true;
                break;
            }
            A.at(i) /= 2;
        }

        if(kisuu)
            break;
        else
            rs++;
    }

    cout << rs << endl;

}

Measured memory_bytes: 3576
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
int dx8[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int N,K;
vll p;

int main(){
   
    
    cin >> N >> K;
    p.resize(N);
    rep(i,N){
        cin >>p[i];
        p[i]++;//出る目の期待値は(Pi+1)/2なので、期待値の線形性により最後に/2すればいい
    }
    vll s(N+1,0);
    rrep(i,N){
         s[i] += s[i-1]+p[i-1];
    }
    ll res = 0;
    for(int i=0;i+K<=N;i++){
        //0~K、1~K+1と見ていく,でi+KがNを超えるまで
        res = max(res,s[i+K]-s[i]);//わからなくなったら累積和がどこからどこまでか書いてみればいい、累積和はs[0]=0で常に一つずれる
    }

    cout << fixed << setprecision(10) << (double)(res)/2 << endl;
    
    
}
  

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

ll sum=0;
void plu(string s){
    string now;
    ll ans =0;
    rep(i,s.size()){
        if(s[i] =='+'){
            sum+=stoll(now.c_str());
            now="";
        }else now+=s[i];
    }
    sum+=stoll(now.c_str());
}
void sumrp(int si,string s){
    if(si<0){  
        plu(s);
        return;
    }
    sumrp(si-1,s);
    if(si>0){
        s.insert(si,"+");
        sumrp(si-1,s);
    }
}
int main(){
    string s;
    cin >> s;
    sumrp(s.size()-1,s);
    cout << sum <<endl;
}


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

using namespace std;

int main() {
    int n;  cin >> n;
    vector<long long> a(n);
    long long ans = 0;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a.begin(), a.end(), greater<long long>());
    if (n % 2) {
        ans += a[0];
        for (int i = 1; i < n/2; i++)
            ans += a[i] * 2;
        ans += a[n/2];
    }
    else {
        for (int i = 1; i <= n/2-1; i++)
            ans += a[i] * 2;
        ans += a[0];
    }

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

Measured memory_bytes: 4848
#include<iostream>
using namespace std;
int a[51];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int sum=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			sum+=a[i]*a[j];
		}
	}
	cout<<sum;
}

Measured memory_bytes: 256
N=int(input())
res=0
if(N>=105):
    pass
else:
    print(0)
    exit(0)

for i in range(105,N+1):
    #print('for in ')
    counter=0
    if(i%2==0):
        pass
    else:
        for s in range(1,i+1):
            if(i%s==0):
                counter=counter+1

    if(counter==8):
        res=res+1
    #print(f'{i} is {counter}')
print(res)


Measured memory_bytes: 3060
#include <iostream>

int main(){
    int N, M, C, S = 0, X = 0;
    
    std::cin >> N >> M >> C;
    int A[N][20], B[20];
    
    for(int b = 0; b < M; b++){
        std::cin >> B[b];
    }
    for(int n = 0; n < N; n++){
        for (int m = 0; m < M; m++){
            std::cin >> A[n][m];
        }
    }
    
    for(int nn = 0; nn < N; nn++){
        for(int mm = 0; mm < M; mm++){
            S += A[nn][mm] * B[mm];
        }
        S += C;
        if(S > 0){
            X++;
        }
        S = 0;
    }
    std::cout << X << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int s(int n) {
    int res = 0;
    while(n != 0) {
        res += n % 10;
        n /= 10;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    bool ans = n % s(n) == 0;
    cout << (ans? "Yes" : "No") << endl;
}

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

ll lpow(ll x, ll y, ll m){
  ll r = 1;
  x %= m;
  while (y) {
    if (y & 1) r = (r * x) % m;
    x = (x * x) % m;
    y >>= 1;
  }
  return r;
}

void fast_io() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
}

int main() {
  fast_io();

  ll n;
  cin >> n;
  ll mod = 1e9 + 7;
  ll ans = lpow(10, n, mod) - 2 * lpow(9, n, mod) + lpow(8, n, mod);
  cout << (ans + 2 * mod) % mod << '\n';
}


Measured memory_bytes: 3616
/*
  AOJ 1291
  Title:Search of Concatenated Strings
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

int n,m;
char e[12][21];
int  len[12];
char t[5001];
char flag[5001][4096];
void dump_flag(char flag[5001][4096],int len)
{
  int i,j;
  for(i=0;i<len;i++)
    for(j=0;j<4096;j++)
      if(flag[i][j])
	printf("%d %d\n",i,j);
}
main()
{
  int l,ln,l_s,i,j,k,cnt,loop,mask,pat;
  char buf[101];
  while(scanf("%d %d",&n,&m) && (n||m))
    {
      memset(flag,0,sizeof(flag));
      for(i=0;i<n;i++)
	{
	  scanf("%s",&e[i][0]); 
	  len[i]=strlen(&e[i][0]);
	}
      t[0]='\0';
      for(i=0;i<m;i++)
	{
	  scanf("%s",buf);
	  ln=strlen(buf);
	  if(buf[ln-1]<' ')
	    buf[ln-1]='\0';
	  strcat(t,buf);
	}
      l_s=strlen(t);
      loop=1<<n;
      for(i=0,cnt=0;i<l_s;i++)
	{
	  for(j=0;j<loop;j++)
	    {
	    if(j && flag[i][j]==0)
	    continue;
	    for(k=0,mask=1;k<n;k++,mask<<=1)
		{
		  if(j & mask)
		    continue;
		  if(0==strncmp(&e[k][0],&t[i],(l=len[k])))
		    {
		      pat=j|mask;
		      flag[i+l][pat]=1;
		    }
		}
	    }
	}
      for(i=0,cnt=0;i<=l_s;i++)
	cnt += flag[i][loop-1];
      printf("%d\n",cnt);
    }
  return(0);
}

Measured memory_bytes: 20652
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
	
	vector<ll> vec1;
	vector<ll> vec2;

	
	ll n;
	while (cin>>n){
		vec1.clear();
		vec2.clear();
		ll a[n];
		for (ll i = 0;i<n;i++){
			cin>>a[i];
			
		}
		for (ll i =0;i<n;i++){
		
			if (i%2==0){
				vec1.push_back(a[i]);
				
			}else {
				vec2.push_back(a[i]);
			}
			
			
		}
		if (n%2==0){
			for (ll i= vec2.size()-1;i>=0;i--){
				cout<<vec2[i]<<" ";
				
			}
			for (ll i= 0;i<vec1.size();i++){
				cout<<vec1[i]<<" ";
				
			}
			
		}else {
			for (ll i= vec1.size()-1;i>=0;i--){
				cout<<vec1[i]<<" ";
				
			}
			for (ll i= 0;i<vec2.size();i++){
				cout<<vec2[i]<<" ";
				
			}
			
		}
		cout<<endl;
	}
	
	return 0;
} 

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> L(N + 1);
  L.at(0) = 2;
  L.at(1) = 1;
  for (int i = 2; i <= N; i++) {
    L.at(i) = L.at(i - 2) + L.at(i - 1);
  }
  cout << L.at(N) << endl;
}

Measured memory_bytes: 256
//Cubelover RipOff
#include <cstdio>
#include <algorithm>

using namespace std;

int a[300005];

int main() {
    int i, j, k, l, m, n;
    scanf("%d%d%d", &n, &m, &l);
    if (n > 1ll * m * l || n + 1 < m + l) {
        puts("-1");
        return 0;
    }
    for (i = 0; i < n; i++) a[i] = i + 1;
    j = 0;
    for (i = 1; i <= m; i++) {
        k = min(j + l, n - m + i);
        reverse(a + j, a + k);
        j = k;
    }
    for (i = 0; i < n; i++) printf("%d ", a[i]);
}

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

int main(void) {
  ll N, M;
	cin >> N >> M;
  ll out;

  if (M==0) M++;
  if (N >= M/2) {
    out = M/2;
  } else {
    out = (N+M/2)/2;
  }

  cout << out << '\n';
}


Measured memory_bytes: 256
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    A = list(map(int, readline().rstrip().split()))
    sumA = 0
    money = 1000
    for i in range(n - 1):
        if A[i + 1] - A[i] > 0:
            money += (A[i + 1] - A[i]) * math.floor(money / A[i])
    print(money)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
const ll INF=1e9+7;
const ll N = 51;

char a,b;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>a>>b;
	bool ans=false;
	if(b=='H')ans=true;
	if(a=='D'){
		if(ans)ans=false;
		else ans=true;
	}
	cout<<TO(ans,"H","D")<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000)

N, M, R = map(int, input().split())
dest = list(map(int, input().split())) #訪れないと行けない街r1, r2, ..., rR

d = [[float('inf')] * N for _ in range(N)]
for i in range(N):
    d[i][i] = 0
for _ in range(M):
    A, B, C = map(int, input().split())
    d[A - 1][B - 1] = C
    d[B - 1][A - 1] = C

#ワーシャルフロイト法
#d[i][j]はi→jの最短経路長
for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

c = [[d[dest[i] - 1][dest[j] - 1] for j in range(R)] for i in range(R)]

dp_memo = [[float('inf')] * R for _ in range(1 << R)]

def TSP(T, v):
    #今まで訪れた頂点の集合：T　今いる頂点：vとしたときの残りを全部巡回する最短の長さ

    if dp_memo[T][v] != float('inf'):
        return dp_memo[T][v]

    elif T == (1 << R) - 1 :
        #全部訪れたとき
        dp_memo[T][v] = 0
        return 0
    else:
        res = float('inf')
        for u in range(R):
            if (T >> u) & 1 == 0:
                res = min(res, TSP(T | (1 << u), u) + c[v][u])
        dp_memo[T][v] = res
        return res

ans = float('inf')
for i in  range(R):
    ans = min(ans, TSP(0, i))
print(ans)

Measured memory_bytes: 75352
#include<iostream>
#define M 500009
#define int long long
using namespace std;
struct st {
  int puzzle[3][3],cnt,x0,y0;
};
int dx[] = { -1,0,1,0 }, dy[] = { 0,-1,0,1 };
int used[M];
int fhash(int x) {
  for (int i = 1;; ++i) 
    if (used[i*x%M] == 0 || used[i * x % M] == x) return i;
}
signed main() {
  struct st p;
  p.cnt = 0;
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j) {
      cin >> p.puzzle[i][j];
      if (p.puzzle[i][j] == 0) { p.x0 = j; p.y0 = i; }
    }
  int head = 0, tail = 0;
  struct st que[M];
  que[tail++] = p;
  while (head != tail) {
    p = que[head%M]; ++head;
    int flag = 1;
    for (int i = 0; i < 3; ++i)
      for (int j = 0; j < 3; ++j)
	if (p.puzzle[i][j] != (3 * i + j + 1) % 9) flag = 0;
    if (flag) {
      cout << p.cnt << endl;
      return 0;
    }
    int x = 0, k = 1;
    for (int i = 2; i >= 0; --i)
      for (int j = 2; j >= 0; --j, k *= 10) x += p.puzzle[i][j] * k;
    int y = fhash(x);
    if (used[y*x%M] == x) continue;
    used[y*x%M] = x;
    for (int i = 0; i < 4; ++i) {
      if (p.x0 + dx[i] >= 0 && p.x0 + dx[i] < 3 && p.y0 + dy[i] >= 0 && p.y0 + dy[i] < 3) {
	struct st q;
	for (int i = 0; i < 3; ++i)
	  for (int j = 0; j < 3; ++j) q.puzzle[i][j] = p.puzzle[i][j];
	int tmp;
	tmp = q.puzzle[p.y0][p.x0];
	q.puzzle[p.y0][p.x0] = q.puzzle[p.y0+dy[i]][p.x0+dx[i]];
	q.puzzle[p.y0 + dy[i]][p.x0 + dx[i]] = tmp;
	q.cnt = p.cnt + 1; q.x0 = p.x0 + dx[i]; q.y0 = p.y0 + dy[i];
	que[tail%M] = q; ++tail;
      }
    }
  }
}



Measured memory_bytes: 52360
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int N;
  get(N);
  vector<int> A(N);
  getv(A);
  map<int, int> list;
  FOR(i, N) { list[A[i]]++; }
  int mx = list.rbegin()->first, cnt = list.rbegin()->second;
  if (cnt > 1) {
    FOR(i, N) { print(mx); }
  } else {
    vector<int> B(A);
    sort(ALL(B), greater<int>());
    FOR(i, N) {

      if (A[i] != mx) {
        print(mx);
      } else {
        print(B[1]);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 8704
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        long H = int.Parse(str[0]);
        long W = int.Parse(str[1]);
        long count = 0;
        if(H % 3 == 0 || W % 3 == 0){
            count = 0;
        }
        else{
            count = Math.Min(H,W);
            for(int i=0;i<H;i++){
                long a = i*W;
                long b = (H-i)*(W/2);
                long c = (H-i)*((W+1)/2);
                long max = Math.Max(a,Math.Max(b,c));
                long min = Math.Min(a,Math.Min(b,c));
                count = Math.Min(max-min,count);
            }
            for(int i=0;i<W;i++){
                long a = i*H;
                long b = (W-i)*(H/2);
                long c = (W-i)*((H+1)/2);
                long max = Math.Max(a,Math.Max(b,c));
                long min = Math.Min(a,Math.Min(b,c));
                count = Math.Min(max-min,count);
            }
        }
        sb.Append(count+"\n");
    }
}

Measured memory_bytes: 11220
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

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

// max_flow
const int MAX_V = 1050;
class FordFulkerson {
public:
    struct edge {
        int to;
        int cap;
        int rev;
        edge() {}
        edge(int t, int c, int r) : to(t), cap(c), rev(r) {}
    };
    vector<edge> G[MAX_V];
    void add_edge(int from, int to, int cap) {
        G[from].push_back(edge(to, cap, G[to].size()));
        G[to].push_back(edge(from, 0, G[from].size() - 1));
    }
    int max_flow(int s, int t) {
        int flow = 0;
        while (1) {
            for (int i = 0; i < MAX_V; i++) used[i] = false;
            int f = dfs(s, t, INF);
            if (f == 0) return flow;
            flow += f;
        }
    }
private:
    int dfs(int v, int t, int f) {
        if (v == t) return f;
        used[v] = true;
        for (int i = 0; i < G[v].size(); i++) {
            edge &e = G[v][i];
            if (!used[e.to] && e.cap > 0) {
                int d = dfs(e.to, t, min(e.cap, f));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    bool used[MAX_V];
};

int b[600], r[600];

int main(void) {
    int m, n;
    while (cin >> m >> n) {
        if (m == 0 && n == 0) break;
        FordFulkerson ff;
        for (int i = 0; i < m; i++) {
            cin >> b[i];
        }
        for (int i = 0; i < n; i++) {
            cin >> r[i];
        }
        int s = m+n, t = s+1;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (__gcd(b[i], r[j]) > 1) {
                    ff.add_edge(i, m+j, 1);
                }
            }
        }
        for (int i = 0; i < m; i++) {
            ff.add_edge(s, i, 1);
        }
        for (int i = 0; i < n; i++) {
            ff.add_edge(i+m, t, 1);
        }
        cout << ff.max_flow(s, t) << endl;
    }
    return 0;
}

Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

ull h, w;

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> h >> w;
    if (h == 1 || w == 1)
    {
        cout << 1;
        return 0;
    }
    cout << ((h * w) / 2) + ((h * w) % 2);
    cin >> h;
}

Measured memory_bytes: 256
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    n,m,x = map(int,input().split())
    maps=[]
    maps=list(map(int,input().split()))
    dp=[0]*(n+1)
    left=0
    right=0

    for i in maps:
        dp[i]=1

    left = sum(dp[x:])
    right = sum(dp[:x])

    print(min(left,right))

if __name__=="__main__":
    main()

Measured memory_bytes: 9200
S = int(input())

M = 10**9+7

F = [0]*10000
F[0] = 1
for i in range(1, 10000):
  F[i] = i*F[i-1]%M

ans = 0
for n in range(1, S//3+1):
  t = S-n*3
  ans += F[t+n-1]*pow(F[t], M-2, M)*pow(F[n-1], M-2, M)
print(ans%M)


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

ll n, a, b, c, d, e;

int main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        cin >> n>> a>> b>> c>> d>> e;
        ll mn = 1e18;
        mn = min(a, b);
        mn = min(mn, c);
        mn = min(mn, d);
        mn = min(mn, e);
        ll nm = (n + mn - 1) / mn;
        cout << nm + 4;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int>top;
pair<int,int> con[200005];
bool vis[200005];
bool vis2[200005];
bool vis3[200005];
int ind[200005];
int sum[200005];
int ans[200005];
vector<vector<int> >adj;
int cnt = 0;
void dfs(int u) {
    if(vis[u])
        return;
    vis[u] = true;
    for(auto v:adj[u])
        dfs(v);
    ind[u] = cnt;
}
void dfs2(int u) {
    if(vis[u])
        return;
    vis[u] = true;
    sum[ind[u]]++;
    for(auto v:adj[u])
        dfs2(v);

}void dfs3(int u) {
    if(vis2[u])
        return;
    vis2[u] = true;
    ans[u]+=sum[ind[u]];
    for(auto v:adj[u])
        dfs3(v);

}
void dfs4(int u) {
    if(vis3[u])
        return;
    vis3[u] = true;
    sum[ind[u]] = 0;
    for(auto v:adj[u])
        dfs4(v);
}
int main() {
    int n, k, m;
    cin >> n >> k >> m;
    int u, v;
    adj.resize(n);
    while(k--) {
        cin >> u >> v;
        u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i = 0 ; i < n ; i++) {
        if(!vis[i]) {
            dfs(i);
            cnt++;
        }
    }
    adj.clear();
    adj.resize(n);
    memset(vis, 0, sizeof(vis));
    while(m--) {
        cin >> u >> v;
        u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i = 0 ; i < n ; i++) {
        if(!vis[i]){
            dfs2(i);
            dfs3(i);
            dfs4(i);
        }
    }
    for(int i = 0 ; i < n ; i++)
        cout << ans[i]<<(i+1==n?'\n':' ');


}


Measured memory_bytes: 11008
#include<iostream>
#include<algorithm>
using namespace std;
long n,a[1<<17],b[1<<17],c[1<<17],s[1<<17];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	for(int i=0;i<n;i++)cin>>c[i];
	sort(b,b+n);
	sort(c,c+n);
	int j=0;
	for(int i=0;i<n;i++)
	{
		while(j<n&&b[i]>=c[j])j++;
		s[i]=n-j;
	}
	for(int i=n;i--;)s[i]+=s[i+1];
	long ans=0;
	for(int i=0;i<n;i++)
	{
		ans+=s[upper_bound(b,b+n,a[i])-b];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL n;
int num[1111];
int main(){
    cin>>n;
    n++;
    int hd, tl;
    hd = 500;
    tl = hd - 1;
    int ma = 0;
    for(int i = 0;i <= 40; i++)if(n >> i & 1)ma = i;
    int tot = 1;
    for(int i = ma - 1;i >= 0; i--){
        num[++tl] = tot;
        tot++;
        if(n >> i & 1)num[--hd] = tot, tot++;
    }
    printf("%d\n", tot * 2 - 1);
    for(int i = hd;i <= tl; i++)printf("%d ", num[i]);
    for(int i = 1;i <= tot; i++)printf("%d ", i);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
struct Node;
vector<Node> V;
struct Node {
  vector<int> nbr;
  vector<int> edge;
  bool vst = false;
  int idx;
  lint dfs(int v, int lastedge) {
    vst = true;
    if(idx == v) {
      return 1LL << lastedge;
    }
    REP(i, nbr.size()) {
      if(!V[nbr[i]].vst) {
        lint ret = V[nbr[i]].dfs(v, edge[i]);
        if(ret > 0) {
          if(lastedge != -1) ret += 1LL << lastedge;
          return ret;
        }
      }
    }
    return 0;
  };
};
lint power(lint x, lint n, lint mod) {
  lint ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lint N;
  cin >> N;
  REP(i, N) {
    V.emplace_back();
    V[i].idx = i;
  }
  REP(i, N-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    V[a].nbr.push_back(b);
    V[a].edge.push_back(i);
    V[b].nbr.push_back(a);
    V[b].edge.push_back(i);
  }
  int M;
  cin >> M;
  vector<lint> white(M);
  REP(i, M) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    white[i] = V[u].dfs(v, -1);
    REP(j, N) V[j].vst = false;
  }
  lint ans = 0;
  REP(i, 1LL << M) {
    lint whiteor = 0;
    lint connum = 0;
    REP(j, M) {
      if((i >> j & 1) == 1) {
        whiteor |= white[j];
        connum++;
      }
    }
    lint whitenum = 0;
    REP(j, N-1) {
      if((whiteor >> j & 1) == 1) {
        whitenum++;
      }
    }
    if(connum%2 == 0) {
      ans += 1LL << (N-1-whitenum);
    } else {
      ans -= 1LL << (N-1-whitenum);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
var lines = [];
var N, M;
var a, dp;

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var number = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6];

    N = Number(lines[0].split(" ")[0]);
    M = Number(lines[0].split(" ")[1]);
    var cont = "";

    a = Array(M + 1);
    a[0] = { number: 0, match: 0 };

    dp = Array(N + 1); dp.fill("");

    var tmp = lines[1].split(" ");
    for (var i = 1; i <= M; i++) {
        a[i] = {
            number: Number(tmp[i - 1]),
            match: Number(number[tmp[i - 1]]),
        }
        if (dp[a[i].match] == "" || dp[a[i].match] < a[i].number.toString()){
            dp[a[i].match] = a[i].number.toString();
        }
    }

    // w : Weigt
    // n : Match Number
    for (var w = 1; w <= N; w++) {
        for (var n = 1; n <= M; n++) {
            match = w - a[n].match;

            if (match < 0) { continue; }
            if (dp[match] === "") { continue; }

            else {
                cont = dp[match] + a[n].number;
                if (dp[w].length < cont.length || (dp[w].length === cont.length && dp[w] < cont)) {
                    dp[w] = cont;
                }
            }
        }
    }

    console.log(dp[N]);

});


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

int main()
{
	int A, B, K;
	int i = 0;

	cin >> A >> B >> K;

	for (; i < K; i++)
	{
		if (A % 2)//奇数
		{
			A--;
		}

		B += A / 2;
		A /= 2;
		i++;

		if (i >= K)	break;

		if (B % 2)//奇数
		{
			B--;
		}

		A += B / 2;
		B /= 2;
	}

	cout << A <<' '<< B;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    map<int, vector<int>> mp;
    for (int j = 0; j < n; j++)
    {
        int d;
        cin >> d;
        int r;
        for (int i = 0; i < d; i++)
        {
            cin >> r;
            mp[r].push_back(d);
        }
    }
    cout << n - mp.size();
}

Measured memory_bytes: 3668
N = int(input())
C1 = list(input().split()) 
C2 = C1[:]

def get_card_suit(card):
    return card[:1]

def get_card_value(card):
    return card[1:]

def bubble_sort(card):
    r_exists = True

    while r_exists == True:

        r_exists = False

        i = N - 1

        while i >= 1:

            if get_card_value(card[i]) < get_card_value(card[i - 1]):
                
                card[i], card[i - 1] = card[i - 1], card[i]

                r_exists = True
            
            i -= 1

def select_sort(card):
    i = 0

    while i < N:

        min_j = i
        j = i

        while j < N:

            if get_card_value(card[j]) < get_card_value(card[min_j]):

                min_j = j

            j += 1

        card[i], card[min_j] = card[min_j], card[i]

        i += 1

def output(card):
    s = ''

    for x in card:

        s = s + str(x) + ' '

    print(s.rstrip())

def is_stable():
    i = 0

    while i < N:
        if get_card_suit(C1[i]) != get_card_suit(C2[i]):
            return False
        i += 1
    
    return True

bubble_sort(C1)
select_sort(C2)

output(C1)
print('Stable')

output(C2)
if is_stable() == True:
    print('Stable')
else:
    print('Not stable')



Measured memory_bytes: 5608