akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,k;
    cin>>n>>k;
    vi h(n);
    rep(i,n)cin>>h[i];
    RSORT(h);
    int ans=0;
    Rep(i,k,n)ans+=h[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int N;
	int s[100];
	int sum = 0;
	cin >> N;
	for(int i = 0; i < N; ++i){
		cin >> s[i];
		sum += s[i];
	}
	sort(s, s + N);
	for(int i = 0; i < N; ++i){
		if(sum % 10 == 0){
			if(s[i] % 10 != 0){
				sum -= s[i];
			}
			if(i == N -1){
				sum = 0;
			}
		}else{
			break;
		}
	}
	cout << sum << endl;
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int a[2][n];
	for (int i = 0; i < 2; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			cin>>a[i][j];
		}
	}
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		int nans=0;
		for (int j = 0; j < n; ++j)
		{
			if (j<=i)
			{
				nans+=a[0][j];
			}
			if (i<=j)
			{
				nans+=a[1][j];
			}
		}
		ans=max(ans,nans);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
d, x = map(int, input().split())
a = [int(input()) for i in range(n)]

ans = x
for i in range(n):
    count = 1
    num = 1
    while num + a[i] <= d:
        count += 1
        num += a[i]
    ans += count

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';
ll num=1, ans=0, cnt=0, sum=0;

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

  ll N;
  string str;
  cin >> N;
  set<string> S;
  rep(_, N) {
    cin >> str;
    S.insert(str);
  }
  cout << S.size() << newl;
  return 0;
}

Measured memory_bytes: 19204
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  ll H;
  cin >> H;
  vl dp(42,0);
  dp[0] = 1;
  srep(i,1,42) {
    dp[i] = dp[i-1] * 2 + 1;
  }
  int i = 0;
  while(pow(2,i) <= H) i++;
  cout << dp[i-1] << endl;
  return 0;
}

Measured memory_bytes: 256
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("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let n: u64 = read();
    let p: u64 = read();
    let mut m = p;
    let mut ret = 1;

    for i in 2..p {
        if p < i * i {
            break;
        }
        let mut tmp = 0;
        while m % i == 0 {
            tmp += 1;
            m /= i;
        }
        ret *= pow(i, tmp / n);
    }
    if m > 1 {
        ret *= pow(m, 1 / n);
    }
    println!("{}", ret);
}

fn pow(a: u64, b: u64) -> u64 {
    if b == 0 {
        return 1;
    } else if b == 1 {
        return a;
    }

    let prev = pow(a, b / 2);
    if b % 2 == 0 {
        prev * prev
    } else {
        prev * prev * a
    }
}


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

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

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--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    int n;
    cin>>n;
    int ans=0;
    int a;
    rep(i,n){
        cin>>a;
        if(i%2==0 && a%2==1) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>

#define SIZEN 10000

int main(){
  int n,q,i,j,x,count = 0,A[SIZEN];

  scanf("%d",&n);

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

  scanf("%d",&q);

  for(i = 0;i < q;i++){
    scanf("%d",&x);
    for(j = 0;j < n;j++){
      if(x == A[j]){
        count++;
        break;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2048
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pd(x) cerr<<"//"<<(x)<<endl;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,ok,ng,l,q;
ll x[500005],y[500005],z[500005];
char s[500005],t[500005];
bool flag,dame;

ll  fact[1200005];
ll rfact[1200005];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<1200000; i++){
        fact[i] = (fact[i-1]*i) % mod;
        rfact[i] = rui(fact[i],mod - 2);
    }
}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;
}
 
int main(){
    cin >> n;
	cin >> s;

	for(i = 0;i<n;i++){
		if(s[i] == 'B')a++;
	}
	b= n - a;
	Yes(b > a);
	return 0;
}

Measured memory_bytes: 26496
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<=n;i++)
#define sint(i) scanf("%d",&i);
#define sintt(i,j) scanf("%d%d",&i,&j);
#define sinttt(i,j,k) scanf("%d%d%d",&i,&j,&k);

int main(){
	while(1){
		int n,m;
		sintt(n,m);
		if(n==0)break;
		int masu[6000]={0};
		rep(i,n){
			sint(masu[i]);
		}
		
		int iti=0;
		int ans=0;
		int flg=0;
		rep(j,m){
			int a;
			sint(a);
			
			if(flg==1)continue;
			
			iti+=a;
			if(iti>=n-1){
				ans=j;
				flg=1;
			}
			iti+=masu[iti];
			if(iti>=n-1){
				ans=j;
				flg=1;
			}
		}
		printf("%d\n",ans+1);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1001001001
#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 show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


#define MAP_MAX 55
//0を通れないとする
int s[MAP_MAX][MAP_MAX];

vector<vector<int>> len(MAP_MAX, vector<int>(MAP_MAX, INF));
P root[4] = {
    {1,0},
    {-1,0},
    {0,1},
    {0,-1}
};

int h, w;
int bfs(){
    len[1][1] = 0;
    queue<P> q;
    q.push({1,1});

    while(!q.empty()){
        auto now = q.front(); q.pop();
        rep(i,4){
            P next = {now.first + root[i].first, now.second + root[i].second};
            if (s[next.first][next.second] && len[next.first][next.second]==INF){
                len[next.first][next.second] = len[now.first][now.second] + 1;
                q.push(next);
            }
        }
    }
    return len[h][w];
}

int main()
{
    cin >> h >> w;
    int _ans=0;
    rep(i,h)rep(j,w){
        char tmp; cin >> tmp;
        if (tmp == '.') {s[i+1][j+1] = 1; _ans++;}
    }

    int ans = bfs();
    // rep(i,h+2){
    //     rep(j,w+2){
    //     cout << len[i][j] << ":";
    //     }
    //     cout << endl;
    // }
    if(ans==INF) cout << -1 << endl;
    else cout << _ans-(ans+1) << endl;

}


Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn are_all_true(status: &Vec<bool>) -> bool{
    for x in status{
        if *x == false{return false}
    }
    true
}

fn solve(n: u64, status: &mut Vec<bool>, m: u64) -> u64{
    //println!("n = {}, status =  {:?},  m={}", n, status, m);
    let tmp = vec![3, 5, 7];
    let mut counter = 0;
    if are_all_true(status) && n >= m{
        //println!("m = {} is answer!", m);
        counter += 1;
    }

    if n < 10*m{
        //println!("n < m*10, so stop searching");
        return counter;
    }
    for i in 0..tmp.len(){
        //status[i] = true;
        let mut tmp_status = status.clone();
        tmp_status[i] = true;
        counter += solve(n, &mut tmp_status.clone(), m*10+tmp[i]);
    }
    counter

}

fn main(){
    let n: u64 = read_as_vec()[0];

    //get the nubmer of digits
    //let num_digits = get_digits(n);
    
    let mut status = vec![false;3];
    let answer = solve(n, &mut status, 0);
    println!("{}", answer);
}

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

void push(priority_queue<int>&q,int n){
	for(int i=0,tmp;i<n;++i){
		cin>>tmp;
		q.push(tmp);
	}
}

void pushcp(priority_queue<int>&q,priority_queue<int>&qq,int n){
	for(int i=0;i<n;++i){
		q.push(qq.top());
		qq.pop();
	}
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	priority_queue<int>r,g,t,mix;
	push(r,a),push(g,b),push(t,c);
	pushcp(mix,r,x),pushcp(mix,g,y),pushcp(mix,t,t.size());
	int64_t ans=0;
	for(int i=0;i<x+y;++i){
		ans+=mix.top();
		mix.pop();
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    int N;
    cin >> N;
    if (N <= 111)
    {
        cout << "111" << endl;
    }
    else if (N <= 222)
    {
        cout << "222" << endl;
    }
    else if (N <= 333)
    {
        cout << "333" << endl;
    }
    else if (N <= 444)
    {
        cout << "444" << endl;
    }
        else if (N <= 555)
    {
        cout << "555" << endl;
    }
    else if (N <= 666)
    {
        cout << "666" << endl;
    }
        else if (N <= 777)
    {
        cout << "777" << endl;
    }
    else if (N <= 888)
    {
        cout << "888" << endl;
    }
    else if (N <= 999)
    {
        cout << "999" << endl;
    }
}


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

int main()
{
  string S;
  int s1;
  int count=0;
  cin >> S;
  if(S[0]!='A') cout<<"WA"<<endl;
  else if(S.find('C')!=S.rfind('C'))  cout<<"WA"<<endl;
  else if(2>S.find('C') || S.rfind('C')>S.size()-2) cout<<"WA"<<endl;
  else
  {
    S[0]='a';
    s1 = S.find('C');
    S[s1]='c';
    for(int i=0;i<S.size();i++)
    {
      if('a'<=S[i]  &&  S[i]<='z') ;
      else count++;
    }
    if(count==0)cout <<"AC"<<endl;
    else cout <<"WA"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
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 n, a[100005];
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    erep(i, 1, n) cin >> a[i];
    ll all_cost = 0;
    a[0] = a[n+1] = 0;
    erep(i, 0, n) all_cost += abs(a[i+1] - a[i]);
    erep(i, 1, n) {
        ll ans = abs(a[i+1] - a[i-1]) - (abs(a[i] - a[i-1]) + abs(a[i+1] - a[i]));
        cout << all_cost + ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> v(1 << (n+1));
    for (int i = 0; i < 1 << n; ++i) {
        scanf("%d", &v[i+(1 << n)]);
    }
    for (int i = (1 << n)-1; i >= 1; --i) {
        int l = (i << 1), r = (i << 1) | 1;
        if(v[l] != v[r]) v[i] = abs(v[l]-v[r]);
        else v[i] = v[l];
    }
    cout << v[1] << "\n";
    return 0;
}

Measured memory_bytes: 2304
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)

ans = a[0]
n -= 2
now = 1
while n > 0:
    if n >= 2:
        ans += a[now]*2
        now += 1
        n -= 2
    elif n == 1:
        ans += a[now]
        n -= 1
        now += 1
print(ans)

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

int main(){
	int min,P,Q,R;
	cin>>P>>Q>>R;
	min=P+Q;
	if(Q+R<min){
		min=Q+R;
		}
	if(P+R<min){
		min=P+R;
		}
	cout<<min;
	cin>>P;
	}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<int> A(N);
		vector<int> B(N);
		for(int i = 0; i < N; ++ i)
			scanf("%d%d", &A[i], &B[i]);

		bool ok = true;
		set<pair<int, int>> coordinates;
		map<pair<int, int>, vector<int>> unmatched;
		rep(i, N) {
			ok &= (A[i] == 0) == (i == 0);
			ok &= (B[i] == 0) == (i == 1);
			coordinates.insert(make_pair(A[i], B[i]));
			unmatched[{A[i], B[i]}].push_back(i);
		}
		vector<pair<int, int>> ord(N);
		rep(i, N)
			ord[i] = {A[i], i};
		sort(ord.begin(), ord.end());
		vector<bool> matched(N);
		int matching = 0;
		rep(ix, N) {
			int i = ord[ix].second;
			if(i != 0) {
				bool ook = false;
				rer(d, -1, 1)
					ook |= coordinates.count({ A[i] - 1, B[i] + d }) != 0;
				ok &= ook;
			}
			if(i != 1) {
				bool ook = false;
				rer(d, -1, 1)
					ook |= coordinates.count({ A[i] + d, B[i] - 1 }) != 0;
				ok &= ook;
			}
			if(!matched[i] && coordinates.count({ A[i] - 1, B[i] - 1 })) {
				++ matching;
			} else {
				auto &v = unmatched[{ A[i] + 1, B[i] - 1 }];
				if(!v.empty()) {
					matched[v.back()] = true;
					v.pop_back();
					++ matching;
				}
			}
		}
		if(!ok) {
			puts("-1");
			continue;
		}
		int ans = N * 2 - 2 - matching;
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 25216
function main(input) {
	var s=input.split("\n")[1];
	var n=s.length;
	var count=0;
	for(var i=1;i<n;i++){
		if(s[i]=="E")count++;
	}
	var min=count;
	for(var i=0;i<n-1;i++){
		count+=(s[i]=="W")-(s[i+1]=="E");
		if(min>count)min=count;
	}
	console.log(min);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 11468
#include<bits/stdc++.h>
#define pb push_back
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
#define skip continue
#define NAME "code"
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
 
const int MAXN = 1e5 + 1;
const int INF = 1e9 + 2;
const ld pi = acos(-1);

ll n, ans, sum, a[MAXN];

int main() {

    faster();

    cin >> n;

    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        sum += a[i];
        if(a[i] == 0){
            ans += sum / 2;
            sum = 0;
        }
    }
    ans += sum / 2;

    cout << ans;


    return 0;
}

Measured memory_bytes: 1024
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <stdio.h>
#include <math.h>
#include <utility>
#include <algorithm>

class A {
public:
	long long a;
	long long b;
};

int compare(const void * a, const void * b)
{
	return ((long long)((A*)a)->a - (long long)((A*)b)->a);
}

int main()
{
	long long N, M;
	std::cin >> N >> M;
	std::vector<A> a(N);
	for (long long i = 0; i < N; i++) {
		std::cin >> a[i].a >> a[i].b;
	}

	std::qsort(&a.at(0), N, sizeof(A), compare);

	long long cnt = 0;
	long long cost = 0;
	for (long long i = 0; i < N; i++) {

		long long nes = a[i].b;
		if (nes + cnt > M) {
			nes = M - cnt;
		}
		cost += nes*a[i].a;
		cnt += nes;
		if (cnt >= M) {
			break;
		}
	}
	std::cout << cost;
	return 0;
}


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

B=[0]*N

for i in range(N):
    B[i]=A[i]-(i+1)

B.sort()

b=[]
if N%2==1:
    b.append(B[(N+1)//2-1])
elif N%2==0:
    b.append(B[N//2-1])
    b.append(B[N//2])

ans=[]
for i in b:
    sum=0
    for j in range(N):
        sum+=abs(B[j]-i)
    ans.append(sum)

print(min(ans))

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

int main()
{
	string s;
	long long int k;
	cin >> s >> k;
	auto ans = vector<char>(101);
	for(auto i = 1; i <= s.size(); ++i){
		ans[i] = (ans[i - 1] > '1' ? ans[i - 1] : s[i - 1]);
	}
	cout << (k > s.size() ? ans[s.size()] : ans[k]) << endl;
	return 0;
}

Measured memory_bytes: 256
def solve(L,R):
    n=R.bit_length()
    dp=[[0 for i in range(8)] for i in range(n)]
    if R&1==1 and L&1==1:
        dp[0][0]=1
        dp[0][1]=1
        dp[0][2]=2
        dp[0][3]=3
        dp[0][4]=1
        dp[0][5]=1
        dp[0][6]=2
        dp[0][7]=3
    elif R&1==1 and L&1==0:
        dp[0][0]=2
        dp[0][1]=3
        dp[0][2]=2
        dp[0][3]=3
        dp[0][4]=2
        dp[0][5]=3
        dp[0][6]=2
        dp[0][7]=3
    elif R&1==0 and L&1==1:
        dp[0][0]=0
        dp[0][1]=0
        dp[0][2]=1
        dp[0][3]=1
        dp[0][4]=1
        dp[0][5]=1
        dp[0][6]=2
        dp[0][7]=3
    else:
        dp[0][0]=1
        dp[0][1]=1
        dp[0][2]=1
        dp[0][3]=1
        dp[0][4]=2
        dp[0][5]=3
        dp[0][6]=2
        dp[0][7]=3
    for i in range(1,n):
        for j in range(8):
            if j==0:
                if R>>i &1==1 and L>>i &1==1:
                    dp[i][j]=dp[i-1][1]
                elif R>>i &1==1 and L>>i &1==0:
                    dp[i][j]=dp[i-1][4]+dp[i-1][3]
                elif R>>i&1 ==0 and L>>i&1 ==0:
                    dp[i][j]=dp[i-1][0]
            elif j==1:
                if R>>i &1==1 and L>>i &1==1:
                    dp[i][j]=dp[i-1][1]
                elif R>>i &1==1 and L>>i &1==0:
                    dp[i][j]=dp[i-1][5]+dp[i-1][3]+dp[i-1][1]
                elif R>>i&1==0 and L>>i&1==0:
                    dp[i][j]=dp[i-1][1]
            elif j==2:
                if R>>i&1==1:
                    dp[i][j]=dp[i-1][6]+dp[i-1][3]
                else:
                    dp[i][j]=dp[i-1][2]
            elif j==3:
                if R>>i&1==1:
                    dp[i][j]=dp[i-1][7]+2*dp[i-1][3]
                else:
                    dp[i][j]=dp[i-1][3]
            elif j==4:
                if L>>i&1==1:
                    dp[i][j]=dp[i-1][5]
                else:
                    dp[i][j]=dp[i-1][7]+dp[i-1][4]
            elif j==5:
                if L>>i&1==1:
                    dp[i][j]=dp[i-1][5]
                else:
                    dp[i][j]=2*dp[i-1][5]+dp[i-1][7]
            elif j==6:
                dp[i][j]=dp[i-1][6]+dp[i-1][7]
            else:
                dp[i][j]=3*dp[i-1][7]

    return dp[-1][0]

mod=10**9+7
L,R=map(int,input().split())
print(solve(L,R)%mod)

Measured memory_bytes: 62928
n = int(input())
num_list = [ int(v) for v in input().split() ]
dp_list = [ 0 for i in range(n) ]
for i, v in enumerate(num_list):
    if i == 0:
        if v % 2 == 0:
            dp_list[i] = 1
        else:
            dp_list[i] = 2
    else:
        if v % 2 == 0:
            dp_list[i] += 2 * dp_list[i-1] + 3**i 
        else:
            dp_list[i] += dp_list[i-1] + 2 * 3**i 
print(dp_list[-1])
        

Measured memory_bytes: 38384
from itertools import permutations
from math import factorial

n = int(input())
p = permutations(tuple(map(int, input().split())) for _ in range(n))
s=sum(((x1-x2)**2+(y1-y2)**2)**0.5 for a in p for(x1,y1),(x2,y2)in zip(a,a[1:]))
print(s / factorial(n))


Measured memory_bytes: 3060
from collections import deque
n,q=map(int, input().split( ))
Q=[]
for i in range(n):
    D=deque()
    Q.append(D)
for i in range(q):
    c,*a=map(int,input().split( ))
    if c==0:
        Q[a[0]].append(a[1])
    elif c==1:
        if len(Q[a[0]])>0:
            print(Q[a[0]][0])
        else:
            pass
    elif c==2:
        if len(Q[a[0]])>0:
            Q[a[0]].popleft()
        else:
            pass



Measured memory_bytes: 14536
INF = 1.0 / 0.0

def used_edges(sink, pre_node)
  ans = []
  p = pre_node[sink]
  while p != nil
    v, i = p
    ans << $node[v][i]
    p = pre_node[v]
  end
  return ans
end

def min_cost_flow(source, sink, required_flow)
  res = 0
  loop do
    dist = Array.new($n){INF}
    dist[source] = 0
    pre_node = Array.new($n){nil}

    loop do
      updated = false
      $n.times{|v|
        next if dist[v] == INF
        $node[v].each_with_index{|edge, i|
          capacity, target, cost = edge[0..2]
          new_dist = dist[v] + cost
          if capacity > 0 &&  dist[target] > new_dist
            dist[target] = new_dist
            pre_node[target] = [v, i]
            updated = true
          end
        }
      }
      break if not updated
    end
    return res if dist[sink] == INF

    path = used_edges(sink, pre_node)

    aug = 1
    res += aug
    path.each{|e|
      target,idx = e[1], e[3]
      e[0] -= aug
      $node[target][idx][0] += aug
    }
  end
end

x, y, e = gets.split.map(&:to_i)

$n = x+y+2
$node = Array.new($n){[]}

x.times{|i|
  s = 0
  t = i+1
  ls = $node[s].size
  lt = $node[t].size
  $node[s] << [1, t, 0, lt]
  $node[t] << [0, s, 0, ls]
}

y.times{|i|
  s = i+x+1
  t = x+y+1
  ls = $node[s].size
  lt = $node[t].size
  $node[s] << [1, t, 0, lt]
  $node[t] << [0, s, 0, ls]
}


e.times{
  xi, yi = gets.split.map(&:to_i)
  s = xi + 1
  t = yi + x + 1
  ls = $node[s].size
  lt = $node[t].size
  $node[s] << [1, t, 1, lt]
  $node[t] << [0, s,-1, ls]
}

puts min_cost_flow(0, $n-1, e)

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

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<map>
#include<stack>
#include<queue>
#include<math.h>


using namespace std;




int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	long long int a, b, c;
	cin >> a >> b >> c;
	long long int temp = 1;
	long long int ans = 0;
	while (temp * c <= b && c != 0)
	{
		if (temp * c >= a)
		{
			ans++;
		}
		temp++;

	}
	cout << ans << endl;



	return 0;


}


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

#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) <<"#" <<endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 998244353;
const ll MAX = 3e3+23;
const ll inf = 1e18+7;

ll binpow(ll a, ll b, ll m){
    ll res = 1;
    while(b>0){
        if(b%2==1){
            res = (res*a)%m;
        }
    a = (a*a)%m;
    b/=2;
}   
    return res;
}
ll combi(ll a){
    return a*(a-1)/2;
}
ll cnt[10030];
int main(){
  fastio;
  ll n,p;
  cin>>n>>p;
  string s;
  cin>>s;
  if(p==5 || p==2){
    ll ans=0;
    f(i,0,n){
        if((s[i]-'0')%p==0)ans+=i+1;
    }
    cout<<ans<<"\n";
    return 0;
  }
  cnt[0]=1;
  ll aux =0,ans=0;
  f(i,0,n){
    aux*=10;
    aux+=s[i]-'0';
    aux%=p;
    ans = binpow(10,n-1-i,p)*aux;
    ans%=p;
    cnt[ans]++;
  }
  ans =0;
  f(i,0,p) ans+=combi(cnt[i]);
  cout<<ans<<"\n";
  return 0; 
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define ll long long
#define MAX 1e9
#define MOD 1e9+7
using namespace std;
void file()
{
//#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //	freopen("output.txt", "w", stdout);
//#endif  !ONLINEJUDGE
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int n;
vector<int>v;
int dp[100005];
int solve(int idx){
    if(idx>=n)return 2e9;
    if(idx==n-2)return abs(v[idx]-v[n-1]);
    if(idx==n-3)return abs(v[idx]-v[n-1]);
    int &ret=dp[idx];
    if(ret!=2e9)return ret;
    ret=min(ret,solve(idx+1)+abs(v[idx]-v[idx+1]));
    ret=min(ret,solve(idx+2)+abs(v[idx]-v[idx+2]));
    return ret;
}
int main()
{
    cin>>n;
    v.resize(n+1);
    fill(dp,dp+n+1,2e9);
    for(int i=0;i<n;++i)cin>>v[i];
    cout<<solve(0)<<endl;
    return 0;
}


Measured memory_bytes: 4096
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;

int main(void){
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = 0; i < k; i++) {
		if (i % 2 == 0) {
			if (a % 2 != 0) {
				a--;
			}
			b += a / 2;
			a /= 2;
		}
		else {
			if (b % 2 != 0) {
				b--;
			}
			a += b / 2;
			b /= 2;
		}
	}
	cout << a << endl << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

#include <iomanip>
int main() {
    cout << fixed << setprecision(12);
    int n, m, d; cin >> n >> m >> d;
    if (d == 0) {
        cout << 1.0 * (m - 1) * n / n / n << endl;
    } else {
        cout << 1.0 * (m - 1) * 2 * (n - d) / n / n << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define YOI 1
#define YOKUNAI 0

int main(){
    int N,M,d[101],h[100000],tenbodai[100000],A,B,yoi_tenbodai=0;

    scanf("%d %d", &N, &M);
    for(auto i=1; i<=N; i++){
        scanf("%d", &h[i]);
        tenbodai[i] = YOI;
    }
    for(auto i=1; i<=M; i++){
        scanf("%d %d", &A, &B);

        if(h[A] > h[B]){
            tenbodai[B] = YOKUNAI;
        }else if(h[A] < h[B]){
            tenbodai[A] = YOKUNAI;
        }else{
            tenbodai[A] = YOKUNAI;
            tenbodai[B] = YOKUNAI;
        }
    }


    for(auto i=1; i<=N; i++){
        if(tenbodai[i] == YOI){
            yoi_tenbodai++;
        }
    }

    printf("%d", yoi_tenbodai);

}

Measured memory_bytes: 2512
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
unsigned int randxor()
{
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
int d=365;
vector<int> ans(d);
vector<int> ans1(d);
vector<int> c(26);
vector<vector<int> > s(d);
int score;
int keisan(){
  int cost=0,i,j;
  vector<int> x(26,-1);
  for(i=0;i<d;i++){
    cost+=s[i][ans1[i]];
    x[ans1[i]]=i;
    for(j=0;j<26;j++){
      cost=cost-c[j]*(i-x[j]);
    }
  }
  return cost;
}
void solve(){
  int i;
  for(i=0;i<d;i++){
    ans1[i]=randxor()%26;
  }
  if(score<keisan()){
    for(i=0;i<d;i++){
      ans[i]=ans1[i];
    }
  }
}
int main(){
  int i,j;
  int ti=clock();
  cin >> d;
  for(i=0;i<26;i++){
    scanf("%d",&c[i]);
  }
  for(i=0;i<d;i++){
    for(j=0;j<26;j++){
      int a;
      scanf("%d",&a);
      s[i].push_back(a);
    }
  }
  for(i=0;i<d;i++){
    ans1[i]=randxor()%26;
    ans[i]=ans1[i];
  }
  score=keisan();
  while(clock()-ti<195.4*CLOCKS_PER_SEC/100){
    solve();
  }
  for(i=0;i<d;i++){
    printf("%d\n",ans[i]+1);
  }
  return 0;
}

Measured memory_bytes: 3892
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int x,k,d;
int32_t main() 
{
    IOS;
    cin>>x>>k>>d;
    x=abs(x);
    int movesneed=x/d;
    if(movesneed>k)
        print(abs(x-k*d));
    else
    {
        k-=movesneed;
        x-=movesneed*d;
        if(k%2==0)
            print(x);
        else
            print(min(abs(x+d),abs(x-d)));
    }
}

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

const int INF = 1e9 + 5;  

void min_self ( int& a, int b  ) {
	a = min (a, b);
}

void max_self ( int& a, int b  ) {
	a = max (a, b);
}

signed
main () {
	
	string first, second;
	std::cin >> first >>second;
	int size1 = first.size();
	int size2 = second.size();
	std::vector< std::vector< pair<int, pair<int, int> > > > dp( size1 + 1, std::vector< std::pair<int, pair<int, int> > >( size2 + 1, make_pair(0, make_pair(0, 0) ) ) );
	//std::vector< std::vector< int > > dp( size1 + 1, std::vector<int>( size2 + 1, 0 ) );
	for ( int i = 0; i < size1; ++i ) {
		for ( int j = 0; j < size2; ++j ) {
			if ( first[i] == second[j] ) {
				dp[i+1][j+1] = std::make_pair(dp[i][j].first + 1, make_pair(i, j));
				continue;
			}
			 
			if ( dp[i+1][j+1].first <= dp[i+1][j].first ) {
				dp[i+1][j+1] = make_pair( dp[i+1][j].first, make_pair( i+1, j ) );
			}
			if ( dp[i+1][j+1].first <= dp[i][j+1].first ) {
				dp[i+1][j+1] = make_pair( dp[i][j+1].first, make_pair( i, j+1 ) );
			}
			dp[i+1][j+1].first = max( dp[i+1][j].first, dp[i][j+1].first );
		}
	}
	string answer = "";
	int currentRow = size1;
	int currentCol = size2;
	
	while ( currentRow != 0 and currentCol != 0 ) {
		
		if ( (dp[currentRow][currentCol].second.first + 1 == (currentRow)) and ( dp[currentRow][currentCol].second.second + 1 == (currentCol) ) ) {
			answer = answer + first[currentRow-1];
		}
		
		int tempR = dp[currentRow][currentCol].second.first;
		int tempC = dp[currentRow][currentCol].second.second;
		currentRow = tempR;
		currentCol = tempC;
	} 
	std::reverse(answer.begin(), answer.end());
	std::cout << answer << '\n'; 
	return 0;
}


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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[],int n){
    for(int i=0;i<n;i++){
    cout<<a[i]<<" ";
    }
    cout<<endl;
}

int main() {
    int i,n,m,c=0,k,sum=0;
    c_p_c();
    cin>>n>>k;
    int a[n];
    fo(i,n) cin>>a[i];
    sort(a,a+n);
    reverse(a,a+n);
    for (int i = 0; i < k; ++i)
    {
    	/* code */
    	sum+=a[i];
    }
 
 cout<<sum<<endl;
  	
 	return 0;

   }

Measured memory_bytes: 3644
from math import ceil

N = int(input())
A = list(map(int,input().split()))


layer=[]#(nodes leaf)
node=1
for i,leaf in enumerate(A):
    if node>leaf:#どうにかなる
        r = node-leaf
        node=r*2
        layer.append([i,leaf,r])
    elif node==leaf:#最後ならどうにかなる
        if i==N:
            node-=leaf
            layer.append([i,leaf,node])
            break
        else:
            print(-1)
            exit()
    else:
        print(-1)
        exit()

ans=1

cur_node=0
for dep,leaf,node in reversed(layer[1:]):
    ans+=leaf+cur_node
    upper_layer_node = layer[dep-1][2]
    #次のレイヤーのノードの数
    cur_node = min(upper_layer_node,leaf+cur_node)

print(ans)


Measured memory_bytes: 682560
#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
#define pb push_back

int main(){
    int P, Q, R;
    cin >> P >> Q >> R;

    cout << (P + Q + R - max( max(P, Q), R)) << endl;

    return 0;
}

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

int dig_sum(int num) {
	int dig, sum = 0;
	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}
	return sum;
}

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

	if (n % dig_sum(n) == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long i=1;i<=n;i++)
using ll = long long;
int main(){
ll n,ans;
  cin>>n;
  ans=n;
  rep(i,sqrt(n)){
    if(n%i == 0){
      ans=min(i+n/i-2,ans);
    }
  }
  cout<<ans<<endl;
}


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

#define fastI ios_base::sync_with_stdio(false); cin.tie(NULL)
#define endl '\n'

using namespace std;

int main() {
    fastI;
    int n, p;
    cin >> n >> p;
    cout << n - p + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define mod (1e9 + 7)
#define pb push_back
#define ll long long int
using namespace std;
typedef pair<int,int> pii;

vector<vector<int> > tugi(2222);
int res[2222];

int main(){
  int n,x,y;
  cin>>n>>x>>y;

  for(int i=1;i<n;i++){
    tugi[i].pb(i+1);
    tugi[i+1].pb(i);
  }
  tugi[x].pb(y);
  tugi[y].pb(x);

  for(int i=1;i<n;i++){
    int vis[n+1];
    fill(vis,vis+n+1,0);
    priority_queue<int, vector<pii>, greater<pii> >q;

    q.push(pii(0,i));
    while(!q.empty()){
      pii p=q.top();q.pop();
      int ima,cost;
      cost=p.first;
      ima=p.second;
      if(vis[ima]==1) continue;
      vis[ima]=1;
      if(ima>=i) res[cost]++;
      //printf("%d : %d %d\n",cost,i,ima);
      for(int j=0;j<tugi[ima].size();j++){
        q.push(pii(cost+1,tugi[ima][j]));
      }
    }
  }
  for(int i=1;i<n;i++){
    cout<<res[i]<<endl;
  }
  return 0;
}


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

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define test() ll t;cin>>t;for(ll test = 1;test<=t;test++)
#define f first
#define s second
#define pb push_back
#define ins insert
#define nl cout<<"\n"
#define P 1000000007
#define N 100005
#define MOD(x) ((x%P)+P)%P
#define show(x) cout<<x<<" "
#define vec(v) loop(i,0,v.size()) show(v[i]); nl

int main()
{
	fastio();

	int n;
	cin>>n;

	int arr[3][n];
	loop(i,0,n)
	{
		int a,b,c;
		cin>>arr[0][i]>>arr[1][i]>>arr[2][i];
		if(i)
		{
			arr[0][i] += max(arr[1][i-1], arr[2][i-1]);
			arr[2][i] += max(arr[0][i-1], arr[1][i-1]);
			arr[1][i] += max(arr[0][i-1], arr[2][i-1]);
		}
	}

	cout<<max(max(arr[0][n-1],arr[1][n-1]),arr[2][n-1]),nl;

	//cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
	return 0;
}

Measured memory_bytes: 1408
N, M = map(int, input().split())

a_list = list(map(int, input().split()))
w_a_list = sorted(a_list, reverse=True)

a_max = sum(a_list)
a_judge = a_max / (4*M)

disp_enable = True
for i in range(M):
	if(w_a_list[i] < a_judge):
		disp_enable = False

if(disp_enable):
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	int n;
	cin >> n;
	//すべて10の倍数だった場合にも対応
	int sub=0;
	int a;
	int mi=101;
	bool flag = 0;
	rep(i,n){
		cin >> a;
		sub += a;
		if (a%10) {
			flag = 1;
			mi = min(mi,a);
		}
	}
	if (sub%10) {
		cout << sub << endl;
	}
	else if (!flag) {
		cout << "0" << endl;
	}
	else {
		cout << sub - mi << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main()
{
	int n=0,s=0,e=0,w=0;
	string S;
	cin>>S;
	rep(i,S.size()){
		if(S[i]=='N') n++;
		if(S[i]=='E') e++;
		if(S[i]=='S') s++;
		if(S[i]=='W') w++;
	}
	if(n==0 && s>0) cout<<"No"<<endl;
	else if(s==0 && n>0) cout<<"No"<<endl;
	else if(e==0 && w>0) cout<<"No"<<endl;
	else if(w==0 && e>0) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;

fn main() {
    let n: usize = read();
    let m: usize = read();
    let p: i64 = read();

    let mut ab: Vec<Vec<(usize, i64)>> = vec![vec![]; n];
    let mut ba: Vec<Vec<usize>> = vec![vec![]; n];
    for _ in 0..m {
        let a: usize = read();
        let b: usize = read();
        let c: i64 = read();
        ab[a-1].push((b-1, p-c));
        ba[b-1].push(a-1);
    }

    let mut que = VecDeque::new();
    let mut used = vec![false; n];
    que.push_back(n-1);
    used[n-1] = true;
    while let Some(q) = que.pop_front() {
        for i in &ba[q] {
            if !used[*i] {
                used[*i] = true;
                que.push_back(*i);
            }
        }
    }
    let mut used2 = vec![false; n];
    que.push_back(0);
    used2[0] = true;
    while let Some(q) = que.pop_front() {
        for &(i, _) in &ab[q] {
            if !used2[i] {
                used2[i] = true;
                que.push_back(i);
            }
        }
    }

    let mut d: Vec<i64> = vec![0; n];
    let mut ok = true;
    for k in 0..n {
        for i in 0..n {
            if !used[i] || !used2[i] {
                continue;
            }
            for &(to, cost) in &ab[i] {
                if d[to] > d[i] + cost {
                    d[to] = d[i] + cost;

                    if k == n-1 {
                        ok = false;
                    }
                }
            }
        }
    }
    if !ok {
        println!("-1");
        return;
    }

    let INF = 1_i64 << 60;
    for i in 0..n {
        d[i] = INF;
    }
    d[0] = 0;
    loop {
        let mut update = false;
        for i in 0..n {
            if !used[i] || !used2[i] {
                continue;
            }
            for &(to, cost) in &ab[i] {
                if d[i] != INF && d[to] > d[i] + cost {
                    d[to] = d[i] + cost;
                    update = true;
                }
            }
        }
        if !update {
            break;
        }
    }
    println!("{}", std::cmp::max(0, -d[n-1]));
}

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


Measured memory_bytes: 4352
taka_hp, taka_att, aoki_hp, aoki_att = map(int, input().split())

while 1:
    aoki_hp -= taka_att
    if aoki_hp <= 0:
        print("Yes")
        break
    
    taka_hp -= aoki_att
    if taka_hp <= 0:
        print("No")
        break


Measured memory_bytes: 9092
#include <stdio.h>

int main(void)
{
	int n;

	scanf("%d", &n);

	int a = n / 100;
	int b = n / 10 % 10;
	int c = n % 10;

	if (a == 7 || b == 7 || c == 7)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 1736
N = int(input()) 
H = list(map(int, input().split()))
sub = []
for i in range(N-1):
    sub.append(H[i+1]-H[i])
#print(sub)
ans = 0
tmp = 0
for s in sub:
    if s <= 0:
        tmp += 1
    else:
        ans = max(ans, tmp)
        tmp = 0
ans = max(ans, tmp)


print(ans)
    





Measured memory_bytes: 14252
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <sstream>

using namespace std;

int const INT_MAX = 10000000;

typedef pair<int, string> P;

// ?????????????????????????????§????????£???????????????
vector<string> split(const string &str, char sep)
{
	vector<string> v;
    stringstream ss(str);
    string buffer;
	
    while(getline(ss, buffer, sep)){
        v.push_back(buffer);
    }
	return v;
}

int main(){
	
	while(true){
		
		int n;
		
		cin >> n;
		cin.ignore();
		
		if(n == 0){
			break;
		}
		
		vector<string> v_str;
		
		for(int loop = 0; loop < n; loop++){
			string str;
			getline(cin, str);
			vector<string> v = split(str, ' ');
			for(int i = 0; i < v.size(); i++){
				v_str.push_back(v[i]);
			}
		}
		
		vector<P> v_pair;
		
		for(int i = 0; i < v_str.size(); i++){
			bool flag = true;
			for(int j = 0; j < v_pair.size(); j++){
				if(v_pair[j].second == v_str[i]){
					flag = false;
					v_pair[j].first--;
					break;
				}
			}
			if(flag){
				P p;
				p.first = -1;
				p.second = v_str[i];
				v_pair.push_back(p);
			}
		}
		
		sort(v_pair.begin(), v_pair.end());
		
		int count = 0;
		
		char c;
		
		cin >> c;
		
		for(int i = 0; i < v_pair.size(); i++){
			if(v_pair[i].second[0] == c){
				if(count == 0){
					cout << v_pair[i].second;
				}else{
					cout << " " << v_pair[i].second;
				}
				count++;
				if(count == 5){
					break;
				}
			}
		}
		
		if(count == 0){
			cout << "NA";
		}
		
		cout << endl;
		
	}
	return 0;
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 3010
const int MOD = 1000000007;

int v[maxn];
int dp[maxn][maxn];

void solve() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)cin >> v[i];
    for (int i = n; i >= 1; i--)
        for (int j = i; j <= n; j++) {
            if (i == j)dp[i][j] = v[i];
            else dp[i][j] = max(v[i] - dp[i + 1][j], v[j] - dp[i][j - 1]);
        }
    cout << dp[1][n] << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}



Measured memory_bytes: 49788