akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;
#define vv vector

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

ll N;
ll X[100];
ll Y[100];
ll P[100];
ll mk[1 << 16];
ll dp[1 << 16][20];
ll i, j, k;

void mnin(ll& a,ll b){
    if(a>b){
        a = b;
    }
}

ll calc(ll i,ll* X,ll* P){
    ll ret = 1e18;
    ll j, k;
    vv<pll> v;
    ll a, c = 0;
    rep(j, 0, N)
    {
        if (i >> j & 1)
        {
            v.push_back({X[j], P[j]});
            c += P[j];
        }
    }
    sort(v.begin(), v.end());
    k = 0;
    rep(j,0,v.size()){
        k += v[j].second;
        if(c<=k*2){
            break;
        }
    }
    if(j>0){
        a = 0;
        rep(k,0,v.size()){
            a += abs(v[k].first - v[j-1].first) * v[k].second;
        }
        ret = min(a, ret);
    }
    a = 0;
    rep(k,0,v.size()){
        a += abs(v[k].first - v[j].first) * v[k].second;
    }
    ret = min(a, ret);
    return ret;
}



int main(){
    scanf("%lld", &N);
    rep(i,0,N){
        ll x, y,p;
        scanf("%lld%lld%lld", &x,&y,&p);
        X[i] = x;
        Y[i] = y;
        P[i] = p;
    }
    rep(i,0,1<<N){
        mk[i] = min(calc(i, X, P), calc(i, Y, P));
        //printf("%lld:%lld\n", i, mk[i]);
    }
    vv<ll> dp(2<<N);
    dp[0] = -1e18;
    rep(k,0,N){
        ll ans = 0;
        rep(i,0,1<<N){
            ll a = dp[i];
            rep(j,0,N){
                if(!(i>>j&1)){
                    a += min(abs(X[j]), abs(Y[j])) * P[j];
                }
            }
            mnin(ans, a);
        }
        printf("%lld\n", ans+(ll)1e18);
        if(k+1==N)
            break;
        vv<ll> odp = dp;
        vv<bool> mk2(2<<N);
        
        rep(i,1,1<<N){
            ll &d = dp[i];
            ll c = __builtin_popcount(i);
            if(c<=k)
                continue;
            for (j = i; j > 0;--j&=i){
                //printf("%lld:%lld\n", i, j);
                ll a = odp[j^i]+ mk[j];
                if(d> a){
                    d = a;
                }
            }
        }
    }
    printf("0\n");
    return 0;
}

Measured memory_bytes: 4696
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, X, M = MAP()
visited = [0]*M
now = X
cnt = 0
l = []

while not visited[now]:
    l.append(now)
    visited[now] = True
    now = (now*now)%M
    cnt += 1
    if cnt == N:
        print(sum(l))
        exit()

idx = l.index(now)
loop = l[idx:]
loop_cnt = len(loop)
loop_sum = sum(loop)

cnt, m = divmod(N-(len(l)-loop_cnt), len(loop))
ans = sum(l[:idx])+loop_sum*cnt+sum(loop[:m])
print(ans)


Measured memory_bytes: 13328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,Q;
  cin >> N >> K >> Q;
  vector<int> v(N);
  for (int i = 0;i<Q;i++) {
    int A;
    cin >> A;
    v.at(A-1)++;
  };
  for (int i = 0;i<N;i++) {
    if (v.at(i)>Q-K) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    };
  };
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
        	int sum = 0;
        	for(int i = 0;i < 10;i++){
        		sum += scan.nextInt();
        	}
        	System.out.println(sum);
        }
    }
}

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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    int n, k; cin >> n >> k;
    vi arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    ll res = 0;
    for (int i = 1; i < n; i++){
        int cur = arr[i-1] + arr[i];
        if (cur <= k) continue;
        res += cur - k;
        arr[i] -= min(arr[i], cur - k);
    }
    cout << res << endl;

}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,w,h) rep(j,h)rep(i,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main() { //ナップサック(main関数なので注意)
  int n,W;
  cin >> n >> W;
  std::vector<int> weight(n),value(n);
  vvector(dp,int,n+1,W+1,0);
  for (int i = 0; i < n; ++i) cin >> value[i] >> weight[i];

  // DP初期条件: dp[0][w] = 0
  for (int w = 0; w <= W; ++w) dp[0][w] = 0;

  // DPループ
  for (int i = 0; i < n; ++i) {
    for (int w = 0; w <= W; ++w) {
      if (w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
      else dp[i+1][w] = dp[i][w];
    }
  }

  cout << dp[n][W] << endl;
}


Measured memory_bytes: 6836
P,Q,R = map(int,input().split())

if P + R <= P + Q and P + R <= R + Q:
   answer = P + R
elif P + Q <= P + R and P + Q <= R + Q:
	answer = P + Q
elif R + Q <= P + R and R + Q <= R + Q:
	answer = R + Q
  
print(answer)

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

int main(){
    int a, b;
    cin >> a >> b;
    if (a > b){
        cout << "a > b" << endl;
    }
    else if (a < b){
        cout << "a < b" << endl;
    }
    else {
        cout << "a == b" << endl;
    }
}


Measured memory_bytes: 3124
import math 
gcd = math.gcd
K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            d = gcd(gcd(i,j),k)
            if i==j==k:
                ans += d
            elif i==j or j== k or k==i:
                ans += 3*d
            else:
                ans += 6*d
print(ans)


Measured memory_bytes: 68172
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define irep(i, n) for(int i = n-1; i >= (int)0; i--)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    string s;
    std::cin >> s;
    int n=s.size();
    ll ans=0ll;
    for (int bit = 0; bit <(1<<n-1) ; bit++) {
        /* code */
        std::vector<string> d(1);
        d[0]+=s[0];
        rep(i,n-1){
             if(bit&(1<<i))d.pb(string(1,s[i+1]));
             else d[d.size()-1]=d[d.size()-1]+s[i+1];
        }
        //rep(i,d.size())std::cout << d[i] << std::endl;
        rep(i,d.size())ans+=stoll(d[i]);
    }
    std::cout << ans << std::endl;
}

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

int main(){
    int n;
    scanf("%d",&n);

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

    int max,half,dist,dist_tmp;

    max = *max_element(a.begin(),a.end());
    dist= abs(max-a[0]-a[0]);
    half= a[0];
    for(int i=0;i<n;i++){
        dist_tmp=abs(max-a[i]-a[i]);
        if(dist_tmp<dist){
            dist=dist_tmp;
            half=a[i];
        }
    }

    if(max==half){
        if(max==a[0]){
            half=a[1];
        }
        else{
            half=a[0];
        }
    }

    printf("%d %d", max,half);

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

const ll MOD = 1e9+7;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> vec(n+1);
    vector<bool> isbloken(n+1);
    
    ll tmp,tmp2;
    
    rep(i,m){
        cin >> tmp;
        isbloken[tmp] = true;
    }
    
    if(!isbloken[1])vec[1] = 1;
    if(!isbloken[2])vec[2] = 1 + vec[1];

    reps(i,3,n+1){
        tmp = tmp2 = 1LL;
        if(isbloken[i-2]) tmp = 0;
        if(isbloken[i-1]) tmp2 = 0; 
        vec[i] = (vec[i-1]*tmp2 + vec[i-2]*tmp) % MOD;
    }
    
    cout << vec[n] << endl;

    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<set>
#include<queue>
#include<map>
#include<ctype.h>
#include<math.h>
#include<time.h>
#include<stdlib.h>
#include<unordered_map>
#include<list>
#include<complex>
#include<unordered_set>
#include<stack>
#include<string>
#include<iostream>
#define _Zero(a) memset(a,0,sizeof(a))
#define _Inf(a) memset(a,0x3f,sizeof(a))
#define _Neg1(a) memset(a,-1,sizeof(a))
#define _NegInf(a) memset(a,0xcf,sizeof(a))
#define _Rep(i,a,b) for(int (i)=a;(i)<=(b);(i)++)
#define _Dep(i,a,b) for(int (i)=a;(i)>=(b);(i)--)
#define Ci(x) scanf("%d",&x)
#define Cl(x) scanf("%lld",&x)
#define Cd(x) scanf("%f",&x)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
typedef double db;
typedef complex<db> cp;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdd;
const int MOD = 998244353;
const db EPS = 1e-8;
const db PI = acos(-1);
int sign(db x) { return x<-EPS ? -1 : x>EPS; }
int dbcmp(db l, db r) { return sign(l - r); }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
const int MAXN = 3e3 + 54;

map<ll,ll>dp;
ll val[3],d;
int xxx[3]={2,3,5};
ll boom(ll x,ll y)
{
	ll ret=0;
	while(y)
	{
		if(y&1)	ret+=x;
		if(ret>LINF)return LINF;
		if(x>LINF) return LINF;
		x=x+x;
		y>>=1;
	}
	return ret;
}
ll dfsdp(ll n)
{
	if(dp.count(n))return dp[n];
	dp[n]=boom(n,d);
	for(int i=0;i<3;i++)
	{
		ll nn=n/xxx[i];ll lef=n%xxx[i];
		dp[n]=min(dp[n],dfsdp(nn)+lef*d+val[i]);
		dp[n]=min(dp[n],dfsdp(nn+1)+(xxx[i]-lef)*d+val[i]);
	}
	return dp[n];
	
}
int main()
{
	int T;scanf("%d",&T);
	while(T--)
	{
		ll n;scanf("%lld%lld%lld%lld%lld",&n,val,val+1,val+2,&d);dp.clear();dp[0]=0;
		printf("%lld\n",dfsdp(n));

	}
}

/*

*/


Measured memory_bytes: 4900
#include <bits/stdc++.h>
#define rc(s) return cout<<s,0
/*\     /  *   ---  -------   --    ---     VICTOR BOSS FOR EVER!!!
   \   /   |  /        |      /  \  |   \
    \ /    |  \        |      \  /  |- -
     -     |   ---     |       --   |    \  VICTOR BOSS FOR EVER!!! */
 
using namespace std;
int main(){
    long long int j,i,n,x=0,y=0,z=0,t=0,v=0,q=0,f=0,ans=0;
    string s;
    cin>>s;
    n=s.size();
if(s.substr(0,6)=="keyenc"&&i<n-6){
    for(j=0;j<n;j++)
    if((s[j]=='e'&&j==i+6)||(s[j]=='e'&&j>i+6&&j+1==n)){
        cout<<"YES";
        return 0;
    }
}else if(s.substr(0,5)=="keyen"&&i<n-5){
for(j=0;j<n;j++)
    if(s.substr(j,j+2)=="ce"&&j+2==n){
        cout<<"YES";
        return 0;
        }
    }else if(s.substr(0,4)=="keye"&&i<n-4){
    for( j=0;j<n;j++)
if(s.substr(j,j+3)=="nce"&&j>=i+4&&j+3==n){
    cout<<"YES";
    return 0;
    }
}else if(s.substr(0,3)=="key"&&i<n-3){
for(j=0;j<n;j++)
        if(s.substr(j,j+4)=="ence"&&j>=i+3&&j+4==n){
        cout<<"YES";
        return 0;
        }
    }else if(s.substr(0,2)=="ke"&&i<n-2){
    for( j=0;j<n;j++)
        if(s.substr(j,j+5)=="yence"&&j>=i+2&&j+5==n){
            cout<<"YES";
            return 0;
        }
    }else if(s[0]=='k'){
    for(int j=0;j<n;j++)
        if(s.substr(j,j+6)=="eyence"&&j>=i&&j+6==n){
            cout<<"YES";
            return 0;
        }
    
}
    cout<<"NO";
    return 0;}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	llint A,B;double b;cin>>A>>b;
	B=b*100+0.5;
	A*=B;A/=100;
	cout<<A<<endl;
	
	return 0;
}


Measured memory_bytes: 3164
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<sstream>
using namespace std;
int inf = 1000000000;

int main(){

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

  n -= k;
  cout << (n+k-2)/(k-1) + 1 << endl;

  return 0;
}



//


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;


int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, A, B;

	cin >> N;
	if(N == 1){
		printf("Hello World\n");
		return 0;
	}
	else if(N == 2){
		cin >> A;
		cin >> B;
		printf("%d\n", A+B);
		return 0;
	}
	return 0;
}

Measured memory_bytes: 3736
#include <stdio.h>

int main(){
  int N; scanf("%d", &N);
  int M; scanf("%d", &M);
  int C; scanf("%d", &C);
  int count = 0;
  int value = 0;
  int i, j;
  int B[20] = {};
  int A;
  for(i = 0; i < M; i++){
    scanf("%d", &B[i]);
  }

  for(i = 0; i < N; i++){
    for(j = 0; j < M; j++){
      scanf("%d", &A);
      value += B[j] * A;
    }
    //printf("value[%d] == %d. ", i, value);
    if(value + C > 0) count++;
    value = 0;
  }

  printf("%d", count);

  return 0;
}


Measured memory_bytes: 128
#[allow(unused)]
use proconio::{
    input,
    marker::{Chars, Usize1},
};

fn main() {
    input! {
        input: i32,
    }
    let former = input / 100;
    let latter = input % 100;
    if (former > 12 && latter > 12)
        || (former == 0 && latter == 0)
        || (former == 0 && latter > 12)
        || (former > 12 && latter == 0)
    {
        println!("NA");
    } else if former == 0 {
        println!("YYMM");
    } else if latter == 0 {
        println!("MMYY");
    } else if former <= 12 && latter <= 12 {
        println!("AMBIGUOUS");
    } else if former <= 12 {
        println!("MMYY");
    } else if latter <= 12 {
        println!("YYMM");
    }
}


Measured memory_bytes: 2116
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int n;
int x;
int main()
{
  while(cin>>n,n){
    int ans;
    double sum = 0;
    vector<int> V;
    for(int i = 0; i< n;i++){
      cin>>x;
      V.push_back(x);
    }
    sort(V.begin(),V.end());
    
    for(int i = 1;i <V.size()-1;i++){
      sum+=V[i];
    }
    ans =sum/(V.size()-2);
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>

using namespace std;
void func()
{
	string S,T;
	cin >> S;
	cin >> T;

	int ans = INT_MAX;
	for (int i = 0; i < S.size() - T.size()+1; ++i)
	{
		int tmp(0);
		for (int j = 0; j < T.size(); ++j)
		{
			if (S[i + j] != T[j])
				++tmp;
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}

int main() {
//	while(1)
	func();
	return 0;
}


Measured memory_bytes: 3172
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <iostream>

using namespace std;


int MAXN = 2e5 + 1;
vector<long long> st;


void update_tree( int leaf, long long value, int root_id, int left, int right) {
  // cout << ">>>" << leaf << " " << left << " " << right << endl;
  if (left > right) return;
  if (left == right && left == leaf) {
    st[root_id] = value;
  } else {
      int mid = (left + right) / 2;
      
      if (leaf <= mid) update_tree(leaf, value, root_id*2, left, mid);
      if (leaf > mid) update_tree(leaf, value, root_id*2+1, mid+1, right);
      
      if (st[root_id] < value) st[root_id] = value;
  }
}

long long query( int queryleft, int queryright, int left, int right, int root_id) {
    if ( left >= queryleft && right <= queryright) return st[root_id];

    if (  left > queryright ) return -1;
    if ( right < queryleft) return -1;
    
    int mid = (left + right)/2;
    // (left, mid)   and (mid+1, right) // vs. (ql, qr)
    long long qlres = query(queryleft, queryright, left, mid, root_id*2);
    long long qrres = query(queryleft, queryright, mid+1, right, root_id*2+1);
    
    return max(qlres, qrres);
}


// https://atcoder.jp/contests/dp/tasks/dp_q
int main() {
  int N;
  cin >> N;

  vector<int> H(N+1);
  vector<int> A(N+1);

  st.assign(N*4 + 10, -1);

  // input H
  for(auto i=1; i<=N; i++) cin >> H.at(i);
  // input A
  for(auto i=1; i<=N; i++) cin >> A.at(i);
    
  vector<long long> F(N+1, 0);


  long long myres = -1;
  for (auto i = 1; i <= N; i++) {

      // cout << H.at(i) - 1 << endl;
      long long res = query(1, H.at(i)-1, 1, N, 1);

      // cout << res << endl;
      
      F.at(i) = (  (res==-1)?(0):(res) ) + A.at(i);
      myres = max(myres, F.at(i));
      
      update_tree(  H.at(i), F.at(i), 1, 1, N);
  }

  cout << myres << endl;

  return 0;
}

Measured memory_bytes: 9600
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		int work;
		int result[] = new int[3];
		Scanner sc = new Scanner(System.in);
		
		result[0] = sc.nextInt();
		result[1] = sc.nextInt();
		result[2] = sc.nextInt();
		
		
		if (result[0] > result[1]) {
			work = result[0];
			result[0] = result[1];
			result[1] = work;
		}

		if (result[1] > result[2]) {
			work = result[1];
			result[1] = result[2];
			result[2] = work;
		}
		//一番大きいのが一番右へ

		if (result[0] > result[1]) {
			work = result[0];
			result[0] = result[1];
			result[1] = work;
		}

		
		System.out.println(result[0] + " " + result[1] + " " + result[2]);
		
	}
}


Measured memory_bytes: 26200
#include<stdio.h>
#include<stdlib.h>
void bubbleSort(int *A,int N);
int main(){
  int *A,i,N;
  scanf("%d\n",&N);
  A=(int *)malloc(N*sizeof(int));
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  bubbleSort(A,N);
  return 0;
}
void bubbleSort(int *A,int N){
  int flag=1,i,count=0,j,v;
  while(flag){
    flag=0;
    for(j=N-1;j>=1;j--){
      if(A[j]<A[j-1]){
	count++;
	v=A[j];
	A[j]=A[j-1];
	A[j-1]=v;
	flag=1;
      }
    }
  }

  for(i=0;i<N-1;i++){
    printf("%d",A[i]);
    printf(" ");
  }
  printf("%d\n",A[N-1]);
  printf("%d\n",count);
}





Measured memory_bytes: 2120
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

typedef long long ll;

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

// const int C ;
// const int M = 1000000007;

typedef pair<int, int> point;

int N;
int K[2];
vector<int> V[2][200010];
bool visited[2][200010];
int group[2][200010];
map<point, int> M;
int ans[200010];

int main () {
  cin >> N >> K[0] >> K[1];
  fill(&visited[0][0], &visited[0][0]+200010*2, false);
  for (auto k = 0; k < 2; k++) {
    for (auto i = 0; i < K[k]; i++) {
      int p, q;
      cin >> p >> q;
      p--; q--;
      V[k][p].push_back(q);
      V[k][q].push_back(p);
    }
    for (auto i = 0; i < N; i++) {
      if (visited[k][i]) continue;
      stack<int> St;
      St.push(i);
      while (!St.empty()) {
        int src = St.top();
        St.pop();
        if (!visited[k][src]) {
          visited[k][src] = true;
          group[k][src] = i;
          for (auto dst : V[k][src]) {
            if (!visited[k][dst]) {
              St.push(dst);
            }
          }
        }
      }
    }
  }
  for (auto i = 0; i < N; i++) {
    point p = make_pair(group[0][i], group[1][i]);
    //cerr << "i = " << i << ", (" << group[0][i] << ", " << group[1][i]
    //     << ")" << endl;
    if (M.find(p) == M.end()) {
      M[p] = 1;
    } else {
      M[p]++;
    }
  }
  for (auto i = 0; i < N; i++) {
    point p = make_pair(group[0][i], group[1][i]);
    ans[i] = M[p];
  }
  for (auto i = 0; i < N; i++) {
    cout << ans[i];
    if (i < N-1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
}


Measured memory_bytes: 29052
#include <stdio.h>

int main(void){
    long long int n;
    int f[100001] = {};
    long long int x, xx;
    int m;
    int cnt;
    int tmp;
    long long int i;
    long long int ans = 0;
    long long int tmpans;

    scanf("%lld%lld%d", &n, &xx, &m);
    x = xx;
    i = 0;
    while (!f[x])
    {
        f[x] = 1;
        x = (x * x) % m;
    }
    tmp = x;
    cnt = 1;
    tmpans = tmp;
    x = (x * x) % m;
    while (x != tmp)
    {
        cnt++;
        tmpans += x;
        x = (x * x) % m;
    }
    x = xx;
    ans = 0;
    i = 0;
    while (x != tmp)
    {
        ans += x;
        i++;
        if (i == n)
        {
            printf("%lld", ans);
            return (0);
        }
        x = (x * x) % m;
    }
        ans += (n - i) / cnt * tmpans;
    i += (n - i) / cnt * cnt;
    while (i < n)
    {
        ans += x;
        i++;
        x = (x * x) % m;
    }
    printf("%lld", ans);
}


Measured memory_bytes: 2120
<?php
$n = trim(fgets(STDIN));
$c = trim(fgets(STDIN));

$cntr = 0;
for ($i = 0; $i < $n;++$i) {
    if ($c[$i] === 'R') ++$cntr;
}
$cnt = 0;
for ($i = 0; $i < $cntr; ++$i) {
    if ($c[$i] === 'W') ++$cnt;
}
echo $cnt.PHP_EOL;

Measured memory_bytes: 16472
/*
    Author : zzugzx
    Lang : C++
    Blog : blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define SZ(x) (int)x.size()
#define mem(a, b) memset(a, b, sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int mod = 1e9 + 7;
//const int mod = 998244353;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int maxn = 2e6 + 10;
const int N = 2e4 + 5;
const ll inf = 0x3f3f3f3f;
const int dir[][2]={{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
    int x;
    cin >> x;
    if (x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

typedef long long ll;

ll gcd( ll x, ll y );
ll lcm( ll x, ll y );

int main()
{
    int cnt;
    int n;
    int l[4], s[4];
    int l_num, s_num;

    while ( true ) {
        cnt = 0;
        scanf("%d", &n );
        if ( n == 0 ) break;
        if ( n % 1111 == 0 ) {
            printf("NA\n");
        } else {
            while( n != 6174 ) {
                l_num = s_num = 0;

                for ( int i = 3; i >= 0; --i ) {
                    s[i] = n % 10;
                    n /= 10;
                }

                sort( s, s + 4 );

                s_num += s[0] * 1000;
                s_num += s[1] * 100;
                s_num += s[2] * 10;
                s_num += s[3];

                l_num += s[3] * 1000;
                l_num += s[2] * 100;
                l_num += s[1] * 10;
                l_num += s[0];

                n = l_num - s_num;
                cnt++;
            }
            printf("%d\n", cnt );
        }
    }

    return 0;
}

ll gcd( ll x, ll y )
{
    if ( y == 0 ) return x;
    return gcd( y, x % y );
}

ll lcm( ll x, ll y )
{
    return x / gcd( x, y ) * y;
}



Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1LL << 60;

int n;
ll h[100010];

ll dp[100010];

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

    rep(i, 100010) dp[i] = INF;

    dp[0] = 0;

    for (int i = 1; i < n; i++) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if(i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[n - 1] << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1000000007;
#define Sort(a) sort(a.begin(), a.end())
 
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int count = 0;
  count = k - a;
  if (count < 0) {
    cout << k << '\n';
    return 0;
  }
  else {
    count -= b;
    if (count < 0) {
      cout << a << '\n';
      return 0;
    }
    else {
      cout << a-count << '\n';
      return 0;
    }
  }
}

Measured memory_bytes: 3648
fun main(arg: Array<String>) {

    val n = readLine()!!.toInt()

    val p = Array(n) { i ->
        readLine()!!.split(" ").map { it.toInt() }.let { intArrayOf(i, it[0], it[1]) }
    }

    val edge = ArrayList<IntArray>()

    p.sortBy { it[1] }
    for (i in 0..n - 2) {
        val d = Math.abs(p[i][1] - p[i + 1][1])
        edge.add(intArrayOf(p[i][0], p[i + 1][0], d))
    }

    p.sortBy { it[2] }
    for (i in 0..n - 2) {
        val d = Math.abs(p[i][2] - p[i + 1][2])
        edge.add(intArrayOf(p[i][0], p[i + 1][0], d))
    }

    edge.sortBy { it[2] }
    val from = IntArray(edge.size)
    val to = IntArray(edge.size)
    val w = IntArray(edge.size)
    for (i in 0..edge.size - 1) {
        from[i] = edge[i][0]
        to[i] = edge[i][1]
        w[i] = edge[i][2]
    }

    println(kruskal(from, to, w))
}

fun kruskal(from: IntArray, to: IntArray, w: IntArray): Long {
    val n = from.size
    val uf = UnionFind(n)
    var ret = 0L
    for (i in 0..n - 1) {
        if (!uf.same(from[i], to[i])) {
            uf.union(from[i], to[i])
            ret += w[i]
        }
    }
    return ret
}

class UnionFind(size: Int) {
    val par = IntArray(size) { -1 }

    fun same(x: Int, y: Int) = root(x) == root(y)

    fun union(x: Int, y: Int) {
        val rx = root(x)
        val ry = root(y)
        if (rx == ry) return
        par[rx] += par[ry]
        par[ry] = x
    }

    fun root(x: Int): Int {
        if (par[x] < 0) return x
        par[x] = root(par[x])
        return par[x]
    }
}


Measured memory_bytes: 77436
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
 int K,N;
 int a[100];
 cin>>K>>N;
 for(int i=0;i<K;i++)
 cin>>a[i];
 sort(a,a+K,cmp);
 int count=0;
 
 for(int i=0;i<N;i++)
 count+=a[i];
 cout<<count<<endl;
}

Measured memory_bytes: 256
import java.io.PrintWriter
val pw = PrintWriter(System.out)
fun main(args: Array<String>) {
    func()
    pw.flush()
}
fun print(value: Any) { pw.print(value) }
fun println(value: Any) { pw.println(value) }

fun func() {
    val N = nextInt()
    val A = listOfInt().toIntArray().sortedDescending().toMutableList()
    val output = StringBuilder()
    if (A.all { it >= 0 }) {
        for (i in 1..(N - 2)) {
            output.append("${A[N - 1]} ${A[i]}\n")
            A[N - 1] = A[N - 1] - A[i]
        }
        output.append("${A[0]} ${A[N - 1]}\n")
        A[0] = A[0] - A[N - 1]
        println(A[0])
        print(output)
    } else if (A.all { it < 0 }) {
        for (i in 1..(N - 1)) {
            output.append("${A[0]} ${A[i]}\n")
            A[0] = A[0] - A[i]
        }
        println(A[0])
        print(output)
    } else {
        val fni = A.indexOfFirst { it < 0 }
        for (i in 1 until fni) {
            output.append("${A[N - 1]} ${A[i]}\n")
            A[N - 1] = A[N - 1] - A[i]
        }
        for (i in fni until N) {
            output.append("${A[0]} ${A[i]}\n")
            A[0] = A[0] - A[i]
        }
        println(A[0])
        print(output)
    }
}

fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 67688
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
using namespace std;
using ll=long long;

using Graph=vector<vector<int>>;

vector<pair<int,int>> res;

Graph g;
vector<int> depth;

int dfs(int v){
    int pre=-1;
    vector<int> tos;
    for(auto to:g[v]){
        if(depth[to]==-100){
            depth[to]=depth[v]+1;
            if(dfs(to)){
                tos.push_back(to);
            }
        }
        else if(depth[to]==depth[v]-1) pre=to;
        else if(depth[to]<depth[v]) tos.push_back(to);
    }
    for(auto to:tos){
        res.push_back({v,to});
    }
    if(tos.size()%2==1){
        res.push_back({v,pre});
        return 0;    
    }
    else return 1;
}
int main(){
    int n,m;
    cin>>n>>m;
    g.resize(n);
    depth.assign(n,-100);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    if(m%2==1){
        cout<<-1<<endl;
        return 0;
    }
    depth[0]=0;
    int ret=dfs(0);
    cerr<<res.size()<<endl;
    for(int i=0;i<m;i++){
        cout<<res[i].first+1<<" "<<res[i].second+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 17524
#include <bits/stdc++.h>
using namespace std;
const int mn=(1e5)+10;
int n,a[mn],b[mn],ans1,ans2;
int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	ans1=0;
	for (int i=1;i<n;i++) {
		if (a[i]==i) {
			ans1++;
			swap(a[i],a[i+1]);
		}
	}
	if (a[n]==n) ans1++;
	ans2=0;
	for (int i=n;i>=2;i--) {
		if (b[i]==i) {
			ans2++;
			swap(b[i],b[i-1]);
		}
	}
	if (b[1]==1) ans2++;
	printf("%d\n",min(ans1,ans2));
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    string s,t;
    cin >> s >> t;
    int cnt = 0;
    rep(i,3){
        if(s[i] == t[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
 
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
void pv(vector<int>&v){
	for(int i = 0;i<v.size();i++){
		if(i)cout<<' ';
		cout<<v[i];
	}
	cout<<endl;
}



signed main()
{
	//IOS();
	int N;
	cin>>N;
	int A,B,C,D;
	cin>>A>>B>>C>>D;
	A--;B--;C--;D--;
	string s;
	cin>>s;
	if(C<D){
		int now = A;
		while(now<C){
			if(s[now+1]=='.')now++;
			else if(s[now+2]=='.')now+=2;
			else break;
		}
		if(now!=C){
			cout<<"No"<<endl;
			return 0;
		}
		now = B;
		while (now<D)
		{
			if(s[now+1]=='.')now++;
			else if(s[now+2]=='.')now+=2;
			else break;
		}
		if(now!=D){
			cout<<"No"<<endl;
		}else{
			cout<<"Yes"<<endl;
		}
		return 0;
	}
	int l = A;
	int r = B;
	while(l!=C||r!=D){
		if(r-l==1&&s[l+2]=='.')l+=2;
		else if(s[l+1]=='.'&&l+1!=r)l++;
		else if(s[l+2]=='.'&&l+2!=r)l+=2;
		else if(s[r+1]=='.'&&r+1!=l)r++;
		else if(s[r+2]=='.'&&r+2!=l)r+=2;
		else{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 640
n = int(input())
a = [int(i) for i in input().split()]

tmp = abs(a[0])

for i in range(1,n):
  tmp += abs(a[i] - a[i-1])
  
tmp += abs(a[-1])
a = [0] + a + [0]

for i in range(1,n+1):
  print(tmp - (abs(a[i] - a[i - 1])) - (abs(a[i] - a[i+1])) + abs(a[i-1] - a[i+1]))
    


Measured memory_bytes: 64876
# E
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
f=list(map(int,input().split()))
f.sort(reverse=True)
x=1
i=0
while i>=0:
    cnt=0
    for j in range(n):
        cnt+=max(0,a[j]-x//f[j])
    if cnt>k:
        i+=1
        x=2**i
    else:
        break
while i>0:
    cnt=0
    for j in range(n):
        cnt+=max(0,a[j]-x//f[j])
    if cnt>k:
        i-=1
        x+=2**i
    else:
        i-=1
        x-=2**i
y=x-1
cnt=0
for j in range(n):
    cnt+=max(0,a[j]-y//f[j])
if cnt<=k:
    print(y)
else:
    cnt=0
    for j in range(n):
        cnt+=max(0,a[j]-x//f[j])
    if cnt<=k:
        print(x)
    else:
        print(x+1)

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

//  a^b % m
long long powmod(long long a, long long b, long long m)
{
    long long r = 1;
    for (; b>0; b>>=1, a=a*a%m)
        if (b&1)
            r = r*a%m;
    return r;
}


int main()
{
    int p;
    cin>>p;
    vector<int> a(p);
    for (int &t: a)
        cin>>t;

    vector<int> b(p);
    b[0] = a[0];
    for (int i=0; i<p; i++)
    if (a[i]!=0)
    {
        //  Π[0<=j<p, j!=i](x-j) = (x^p-1)/(x-i)
        vector<int> bt(p);
        bt[p-1] = 1;
        for (int j=p-2; j>=1; j--)
        {
            bt[j] = i*bt[j+1];
            bt[j] %= p;
        }

        //  Π[0<=j<p, j!=i](i-j)
        int v = 1;
        for (int j=0; j<p; j++)
            if (j!=i)
            {
                v *= (i-j+p)%p;
                v %= p;
            }

        int c = powmod(a[i], p-2, p) * powmod(v, p-2, p) % p;
        for (int j=1; j<p; j++)
        {
            b[j] += c*bt[j];
            b[j] %= p;
        }
    }
    for (int i=0; i<p; i++)
        cout<<(i>0 ? " " : "")<<b[i];
    cout<<endl;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
 
class Program
{
  static void Main(string[] args){
    int n = int.Parse(Console.ReadLine());
    List<int> h = Console.ReadLine().Split().Select(int.Parse).ToList();
    Console.WriteLine(solve(h,n));
  }
  static int solve(List<int> h, int n) {
    h.Insert(0, 0);
    int count = 0;
    for (int i = 1; i < h.Count; i++) {
      if (h[i] > h[i - 1]) {
        count += h[i] - h[i - 1];}
        }
    return count;
  }
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define modqq (ll)1e9+7
#define pll pair<long,long>

int main()
{
  ll a;
  cin>>a;
  ll b=1;
  while(a)
  {
    if(a%10==7)
    {
      b=0;
    }
      a/=10;
  }
  if(b==1)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        while (i+1 < N && A[i] == A[i+1]) i++;
        if (i+1 < N && A[i] < A[i+1]) {
            while (i+1 < N && A[i] <= A[i+1]) i++;
        }
        else if (i+1 < N && A[i] > A[i+1]) {
            while (i+1 < N && A[i] >= A[i+1]) i++;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<20;

int N,M;
int a[9];
int t[9]={2,5,5,4,5,6,3,7,6};
int c[9];
int x[9];
int ans[9];

int mini=10;
vector<int> v;
int k;

bool check(){
    int ab=0,ac=0;
    for (int i = 0; i < 9; i++) {
        ab+=ans[i];
        ac+=x[i];
    }
    if(ab<ac){
        return true;
    }
    else if(ac==ab){
        for (int i = 8; i >= 0; i--) {
            if(ans[i]>x[i]) return false; 
            else if(ans[i]<x[i]) return true;
        }
        return false;
    }
    else return false;
}

void dfs(int z){
    if(z==-1){
        int p=0;
        for (int i = 0; i < 9; i++) {
            p+=t[i]*x[i];
        }
        if(p>N) return;
        if((N-p)%mini!=0) return;
        x[k]=(N-p)/mini;
        if(check()){
            for (int i = 0; i < 9; i++) {
                ans[i]=x[i];
            }
        }
        x[k]=0;
        return ;
    }
    for (int i = 0; i < 10; i++) {
        x[v[z]]=i;
        dfs(z-1);
        x[v[z]]=0;
    }
}

int main(){
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> a[i];
        a[i]--;
        c[a[i]]=1;
    }
    if(c[8]){
        t[5]=0;
        c[5]=0;
    }
    if(c[4]){
        t[2]=0;
        t[1]=0;
        c[2]=0;
        c[1]=0;
    }
    else if(c[2]){
        t[1]=0;
        c[1]=0;
    }
    for (int i = 0; i < M; i++) {
        if(t[a[i]]<=mini&&c[a[i]]){
            mini=t[a[i]];
            k=a[i];
        }
    }
    c[k]=0;
    for (int i = 0; i <9; i++) {
        if(c[i]) v.pb(i);
    }
    dfs(v.size()-1);
    for (int i = 8; i >= 0; i--) {
        for (int j = 0; j < ans[i]; j++) {
            cout << i+1;
        }
    }
    cout << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
        #include<iostream>
        #include<cstdio>
        #include<vector>
        #include<queue>
        #include<map>
        #include<cstring>
        #include<string>
        #include <math.h>
        #include<algorithm>
    //    #include <boost/multiprecision/cpp_int.hpp>
        #include<functional>
      #define int long long
        #define inf  1000000007
        #define pa pair<int,int>
#define ll long long
        #define pal pair<ll,ll>
        #define ppa pair<int,pa>
        #define  mp make_pair
        #define EPS (1e-10)
        #define equals(a,b) (fabs((a)-(b))<EPS)

        using namespace std;

        class Point{
        	public:
        	double x,y;
        	Point(double x=0,double y=0):x(x),y(y) {}
        	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
        	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
        	Point operator * (double a) {return Point(x*a,y*a);}
        	Point operator / (double a) {return Point(x/a,y/a);}
        	double absv() {return sqrt(norm());}
        	double norm() {return x*x+y*y;}
        	bool operator < (const Point &p) const{
        		return x != p.x ? x<p.x: y<p.y;
        	}
        	bool operator == (const Point &p) const{
        		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
        	}
        };
        typedef Point Vector;

        struct Segment{
        Point p1,p2;
        };

    double hen(Vector a){
    if(fabs(a.x)<EPS && a.y>0) return acos(0);
    else if(fabs(a.x)<EPS && a.y<0) return 3*acos(0);
    else if(fabs(a.y)<EPS && a.x<0) return 2*acos(0);
    else if(fabs(a.y)<EPS && a.x>0) return 0.0;
    else if(a.y>0) return acos(a.x/a.absv());
    else return 2*acos(0)+acos(-a.x/a.absv());

    }

        double dot(Vector a,Vector b){
        	return a.x*b.x+a.y*b.y;
        }
        double cross(Vector a,Vector b){
        	return a.x*b.y-a.y*b.x;
        }
        int dx[4] = {1, 0, -1, 0};
        int dy[4] = {0, 1, 0, -1};
        //----------------kokomade temple------------

int t[100022],a[100022],ma[100022],mi[100022],ke[100022]={0};
signed main(){
string s;
int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>t[i];
	for(int i=1;i<=n;i++) cin>>a[i];
	ke[1]=1;
	ma[1]=t[1];
	for(int i=2;i<=n;i++) {
		if(t[i]==t[i-1]) ma[i]=t[i];
		else ma[i]=t[i],ke[i]=1;
		
	}
	
	mi[n]=a[n];
	if(ke[n]==1 && a[n]!=t[n]){
		cout<<0<<endl;
		return 0;
	}
	ke[n]=1;
	for(int i=n-1;i>=1;i--){
		if(a[i]==a[i+1]){
			ma[i]=min(ma[i],a[i]);
		}
		else{
			if(ma[i]<a[i]){
				cout<<0<<endl;
		return 0;
			}
			else{
				ke[i]=1;
			}
		}
		
	}
	int ans=1;
	for(int i=1;i<=n;i++){
		if(ke[i]==1) continue;
		
		ans*= ma[i];
		ans %=inf;
		
	}
	/*
	for(int i=1;i<=n;i++){
		cout<<ke[i]<<" "<<ma[i]<<endl;
		
	}
	*/
	cout<<ans<<endl;
	
//	cout<<ans<<endl;
	return 0;
}

//printf("%.10f\n",ans);


Measured memory_bytes: 3328
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
# A.sort(reverse=True)
sm = sum(A)

cnt = 0
for ai in A:
    if 4 * M * ai >= sm:
        cnt += 1

if cnt >= M:
    print('Yes')
else:
    print('No')

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

int main(){
    
    int n,m;
    cin>>n>>m;
    int matrix[100][100]={{0}};
    int vector[100]={0};
    for(int i=0; i<n; i++){
        for(int j=0;j<m;j++){
            cin>>matrix[i][j];
        }
    }
    for (int j = 0; j < m; j++)
    {
        cin>>vector[j];
    }
    for (int i = 0; i < n; i++)
    {
        int result = 0;
        for (int j = 0; j < m; j++)
        {
            result += matrix[i][j]*vector[j];
        }
        cout<<result<<endl;
    
    }
    
    
    return 0;
}




Measured memory_bytes: 3144
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=2000100,mod=1e8;
inline int read(){
    int x=0,c=getchar(),f=0;
    for(;c>'9'||c<'0';f=c=='-',c=getchar());
    for(;c>='0'&&c<='9';c=getchar())
    x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
void write(ll x){
    if(x>9)write(x/10);
    putchar(x%10+'0');
}char s[N];
int i,a,b,ans,n,x;
int main(){
	scanf("%d%s",&n,s+1);
	for(i=1;i<=n;i++){
		if(s[i]=='I')x++;
		if(s[i]=='D')x--;
		if(x>ans)ans=x;
	}printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

a, b, c, x, y = na()

ans = 0
while x or y:
    if x and y:
        if a + b > c * 2:
            z = min(x, y)
            x -= z
            y -= z
            ans += c * 2 * z
        else:
            z = min(x, y)
            x -= z
            y -= z
            ans += (a + b) * z
    else:
        q = c * 2 * (x + y)
        if q <= a * x + b * y:
            ans += c * 2 * (x + y)
            x = 0
            y = 0
        if x:
            ans += a * x
            x = 0
        if y:
            ans += b * y
            y = 0

print(ans)

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

Measured memory_bytes: 3592