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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

ll pow_mod(ll a, ll n, ll p)
{
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res*a%p;
        a = a*a%p;
        n >>= 1;
    }
    return res;
}

ll modinv(ll a, ll MOD)
{
    ll b = MOD, u = 1, v = 0;
    while(b){
        ll t = a/b;
        a -= t*b;   swap(a,b);
        u -= t*v;   swap(u,v);
    }
    u %= MOD;
    if(u < 0) u+= MOD;
    return u;
}

int main()
{
    ll MOD = 1e9+7;
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    unordered_map<ll,ll> mp;
    vector<map<ll,ll>> vmp(n);
    for(i = 0;i < n;++i){
        ll tmp = a.at(i);
        ll sn = sqrt(tmp);
        vector<pair<ll,ll>> insuu;
        ll so = 2;
        ll num = 0;
        while(true){
            if(tmp%so == 0){
                tmp /= so;
                ++num;
            }else{
                if(num != 0){
                    insuu.emplace_back(so,num);
                    num = 0;
                }
                ++so;
            }
            if(tmp == 1){
                insuu.emplace_back(so,num);
                break;
            }
            if(so > sn){
                insuu.emplace_back(tmp,1);
                break;
            }
        }
        for(auto x:insuu){
            vmp.at(i)[x.first] = x.second;
            if(mp.count(x.first)){
                if(mp[x.first] < x.second) mp[x.first] = x.second;
            }else{
                mp[x.first] = x.second;
            }
        }
    }
    ll ans = 0;
    ll lsd = 1;
    for(auto x:mp){
        ll so = x.first;
        ll num = x.second;
        ll tmp = pow_mod(so, num, MOD);
        lsd *= tmp;
        lsd %= MOD;
    }
    map<ll,ll> somap;
    for(i = 0;i < n;++i){
        ll tmp = lsd;
        for(auto x:vmp.at(i)){
            ll so =  x.first;
            ll num = x.second;
            ll tmp2;
            if(somap.count(so)){
                tmp2 = somap[so];
            }else{
                tmp2 = modinv(so, MOD);
                somap[so] = tmp2;
            }
            ll tmp3 = pow_mod(tmp2, num, MOD);
            tmp *= tmp3;
            tmp %= MOD;
        }
        ans += tmp;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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


int main(){
    int N,K;
    cin >> N >> K;
    
    vector<int> p(N);
    for(int i = 0; i<N; i++){
        cin >> p[i];
    }
    
    sort(p.begin(),p.end());
    int ans = 0;
    for(int i = 0; i<K; i++){
        ans += p[i];
    }
    
    cout << ans << endl;
}
    

Measured memory_bytes: 3628
w,h,n=map(int,input().split())
ans=[0]*(w*h)
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        for j in range(h):
            for k in range(x):
                ans[j*w+k]=1
    if a==2:
        for j in range(h):
            for k in range(x,w):
                ans[j*w+k]=1
    if a==3:
        for j in range(y):
            for k in range(w):
                ans[j*w+k]=1
    if a==4:
        for j in range(y,h):
            for k in range(w):
                ans[j*w+k]=1
print(ans.count(0))


Measured memory_bytes: 3188
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)















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

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

int A[105];

int shift[105];

int N;

vector<int> SOLVE(void) {
	vector<int > IMP;
	IMP.push_back(-1);
	vector<int> V;
	for (int i = 1; i <= N; i++) {
		if (shift[i] < 0) { return IMP; }
	}

	for (int i = 1; i <= N; i++) {

		int K = -1;
		for (int j = 1; j <= N - i + 1; j++) {
			if (shift[j] == 0) { K = j; }
		}
		if (K == -1) { return IMP; }
		V.push_back(K);
		for (int h = K; h <= N - i; h++) {
			shift[h] = shift[h + 1] - 1;
		}

	}
	return V;
}

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}

	for (int i = 1; i <= N; i++) {
		shift[i] = i - A[i];
	}

	vector<int> W;
	W = SOLVE();

	int M = W.size();
	for (int i = 0; i < M; i++) {
		if (i != 0) { cout << " "; }
		cout << W[M-i-1];
	}
	cout << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 2e5 + 10;
set<int> a[N];

int main() {
  int n, m, len;
  scanf("%d%d%d", &n, &m, &len);
  set<ii> forbid;
  while (len--) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    forbid.insert({x, y});
    a[y].insert(x);
  }
  int ret = INF;
  int x = 0, y = 0;
  while (true) {
    auto it = a[y].upper_bound(x);
    int nxt = (it == a[y].end() ? n : *it);
    ret = min(ret, nxt);
    // trace(x, y, ret);
    for (++x; x != nxt; ++x) {
      if (!forbid.count({x, y + 1})) {
        y += 1;
        break;
      }
    }
    if (x == nxt) break;
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 28416
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) cout << ", "; else first = false; cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) {}
#define debug_array(a) {}
#endif
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) {
  v = vector<T>(n, x);
}
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i];
}
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n;
vector<lli> a[3];
vector<lli> s[3];
int main() {
  cin >> n;
  for (lli i=0; i<3; ++i) init_n(a[i], n, 0);
  for (lli i=0; i<n; ++i) cin >> a[0][i] >> a[1][i] >> a[2][i];
  for (lli i=0; i<3; ++i) init_n(s[i], n+1, 0);
  for (lli i=1; i<=n; ++i) {
    for (lli j=0; j<3; ++j) {
      s[j][i] = max(s[(j+1)%3][i-1], s[(j+2)%3][i-1]) + a[j][i-1];
    }
  }
  lli ans=0;
  for (lli i=0; i<3; ++i) ans = max(ans, s[i][n]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>

int main(void)
{
	int N, X, T;
	int sum;
	scanf("%d %d %d", &N, &X, &T);
	sum = 0;
	sum = sum + ((N / X) * T);
	if (N % X != 0)
	{
		sum = sum + T;
	}
	printf("%d\n", sum);
}


Measured memory_bytes: 1680
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		
		int[] dic=new int[6];
		
		
		for(int i=0;i<6;i++){
			dic[i]=scan.nextInt();
		}
		int n=scan.nextInt();
		
		int q1,q2,A=-1,tmp;
		
		for(int i=0;i<n;i++){
			q1=scan.nextInt();
			q2=scan.nextInt();
			
			A=dic[2];
			
			if(q1==dic[1]){
				tmp=dic[0];
				dic[0]=dic[1];
				dic[1]=dic[5];
				dic[5]=dic[4];
				dic[4]=tmp;
			}else if(q1==dic[2]){
				tmp=dic[0];
				dic[0]=dic[2];
				dic[2]=dic[5];
				dic[5]=dic[3];
				dic[3]=tmp;
			}else if(q1==dic[3]){
				tmp=dic[0];
				dic[0]=dic[3];
				dic[3]=dic[5];
				dic[5]=dic[2];
				dic[2]=tmp;
			}else if(q1==dic[4]){
				tmp=dic[0];
				dic[0]=dic[4];
				dic[4]=dic[5];
				dic[5]=dic[1];
				dic[1]=tmp;
			}else if(q1==dic[5]){
				tmp=dic[0];
				dic[0]=dic[5];
				dic[5]=tmp;
				tmp=dic[4];
				dic[4]=dic[1];
				dic[1]=tmp;
			}
			
			if(q2==dic[1]){
				A=dic[2];
			}else if(q2==dic[2]){
				A=dic[4];
			}else if(q2==dic[3]){
				A=dic[1];
			}else if(q2==dic[4]){
				A=dic[3];
			}
			System.out.println(A);
		}
		
		
		scan.close();
	}
}

Measured memory_bytes: 17180
N = int(input())
nums = [int(input()) for i in range(N)]
sorted_nums = sorted(nums)

max_num = sorted_nums[-1]
second_max_num = sorted_nums[-2]

for num in nums:
    if num != max_num:
        print(max_num)
    else:
        print(second_max_num)


Measured memory_bytes: 14112
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int k = saori.saori_hayami();
		Integer[] l = new Integer[n];
		for(int i = 0;i < n;i++){
			l[i] = saori.saori_hayami();
		}
		Arrays.sort(l, Collections.reverseOrder());
		
		int ans = 0;
		for(int i = 0;i < k;i++){
			ans += l[i];
		}
		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

using namespace std;

vector<vector<int>> point;
int node;
int a[100000*2+10];
bool visit[100000*2+10];
int s[100000*2+10];
int h,t;

int main()
{
   // memset(point,0,sizeof(point));
    vector<int> tt={0,0};
    point.push_back(tt);
    memset(a,0,sizeof(a));
    node=0;
    int n,m;
    cin>>n>>m;
    for (int i=1;i<=n;i++)
    {
     int temp;
     cin>>temp;
     for (int j=1;j<=temp;j++)
     {
      int k;
      cin>>k;
      int pp=a[i];
      node++;
      vector<int> tt={k+100001,pp};
      point.push_back(tt);
      a[i]=node;

      node++;
      pp=a[k+100001];
      tt={i,pp};
      point.push_back(tt);
      a[k+100001]=node;
     }
    }
     memset(visit,true,sizeof(visit));
     h=0;t=1;
     s[1]=1;
     while (h!=t)
     {
      h++;
      int pp=a[s[h]];
      while (pp)
      {
       if (visit[point[pp][0]])
       {
        visit[point[pp][0]]=false;
        t++;
        s[t]=point[pp][0];
       }
       pp=point[pp][1];
      }
     }
     bool flag=false;
     for (int i=1;i<=n;i++)
     {
      if (visit[i])
      {
       flag=true;
       break;
      }
     }
     if (flag) cout<<"NO"<<endl;
     else cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 13356
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define vl vector<ll>
const int INF = 1001001001;

int main() {

    ll N;
    cin >> N;

    if (N%2 == 1) {
        cout << 0 << endl;
        return 0;
    }

    ll k = 10;
    ll ans = 0;
    while(k <= N) {
        ans += (N/k);
        k *= 5;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  string s;cin>>s;
  deque<char> l(0),r(0);

  int cnt=0;

  int q;cin>>q;
  rep(i,0,q){
    int f;cin>>f;
    if(f==1){
      cnt^=1;
    }else{
      int x;
      char c;cin>>x>>c;
      x--;
      if((x^cnt)==0){
        l.push_front(c);
      }else{  
        r.push_back(c);
      }
    }
  }

  if(cnt==0){
    rep(i,0,siz(l))cout<<l[i];
    rep(i,0,siz(s))cout<<s[i];
    rep(i,0,siz(r))cout<<r[i];
  }else{
    repr(i,0,siz(r))cout<<r[i];
    repr(i,0,siz(s))cout<<s[i];
    repr(i,0,siz(l))cout<<l[i];
  }
  cout<<ENDL;

}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 848
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  map<char,ll>cnt;
  while(n--){
    string s;cin>>s;
    cnt[s[0]]++;
  }
  ll ans = 0;
  string s = "MARCH";
  for(int i=0;i<5;i++){
    for(int j=i+1;j<5;j++){
      for(int k=j+1;k<5;k++){
	ans += cnt[s[i]]*cnt[s[j]]*cnt[s[k]];
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

def main():
	n=gete(int)
	dp=[[0]*3 for _ in range(n+1)]
	
	
	for i in range(n):
		a,b,c=geta(int)
		dp[i+1][0] = max(dp[i][1], dp[i][2]) + a
		dp[i+1][1] = max(dp[i][2], dp[i][0]) + b
		dp[i+1][2] = max(dp[i][0], dp[i][1]) + c
		
	print(max(dp[n][0],dp[n][1],dp[n][2]))
	
	
	
if __name__ == "__main__":
	main()

Measured memory_bytes: 60236
#include<time.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

template<typename ...Ts>
void show(Ts... ts){
  cout<<"#:";
  auto print=[](auto v){cout<<v<<" ";};
  initializer_list<int>{(void(print(ts)),0)...};
  cout<<endl;
}

int main(void){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    s[k-1]-='A'-'a';
    string ans=s;
    cout<<ans;
}






Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
bool mirror(const char &a,const char &b);
int main()
{
    char s[100000];
    scanf("%s",&s);
        int i ;
        int l = strlen(s);
        int mk = 0 ;
    for(i = 0 ;i < l/2 ;i++)
    {
        bool k  = mirror(s[i],s[l-i-1]);
        if(!k||l%2!=0)
        {
            cout << "No\n";
            mk = 1;
            break;
        }
    }


    if(i == l/2)
    {
        cout << "Yes\n";
    }
    else
    {
        if(mk == 0)
        {
            cout << "No\n";
        }

    }
    return 0;
}

bool mirror(const char &a,const char &b)
{
    if((a == 'b' && b == 'd') ||(a == 'd' && b == 'b')
       || (a == 'p' && b == 'q') ||(a == 'q' && b == 'p'))
    {
        return true;
    }
    else
    {
        return false;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  if (A <= 5) {
    cout << 0 << endl;
  }
  else if (A < 13) {
    cout << B / 2 << endl;
  }
  else {
    cout << B << endl;
  }
}



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

using namespace std;

inline int min(int a, int b) { return a > b ? b : a; }

int main()
{
	int n, ans = 0;
	cin >> n;

	int ol = 1000000, ne;
	for (int i = 1; i < n; i++)
	{
		cin >> ne;
		ans += min(ol, ne);
		ol = ne;
	}
	ans += ol;

	cout << ans;
	system("pause");
	return 0;
}

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

int main(){
  int n, h[101] = {0};
  cin >> n;
  
  for(int i = 0; i < n; i++ ){
    cin >> h[i];
  }
  
  int ans = 0;
  int start = 0, end = 0;
  
  for(start = 0; start < n; start ++){
    if(h[start] == 0) continue;
    while(h[start] > 0){
      for(end = start; end < n; end++){
        if(h[end] == 0){
          for(int i = start; i < end; i++){
            h[i]--;
          }
          ans ++;
          break;
        }else if(end == n-1){
          for(int i = start; i <n; i++){
            h[i]--;
          }
          ans++;
          break;
        }
      }
      
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
K, T = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort(reverse=True)
if T > 1:
    n = a[0]-a[1]
else:
    print(a[0]-1)
    exit()
for i in range(2, T):
    n = abs(n-a[i])
print(max(0, n-1))


Measured memory_bytes: 38256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
int f[3][1010];
int main(){
    int n,i,j,x;
    scanf("%d",&n);
    for(i=1;i<=2;i++)
        for(j=1;j<=n;j++){
            scanf("%d",&x);
            f[i][j]=x+max(f[i-1][j],f[i][j-1]);
        }
    printf("%d",f[2][n]);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
 
#define pb push_back
#define mp make_pair
constexpr int INF = 1 << 29;
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
 
constexpr int dx[4] = {1, 0, -1, 0};
constexpr int dy[4] = {0, 1, 0, -1};
 
int main() {
	int N, C;
	cin >> N >> C;
	vector<vector<ll>> D(C, vector<ll>(C));
	vector<vector<ll>> color_cnt(3, vector<ll>(C));
	vector<vector<ll>> color(N, vector<ll>(N));


	for (int i = 0; i < C; i++) {
		for (int j = 0; j < C; j++) {
			cin >> D[i][j];
		}
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> color[i][j];
			color[i][j]--;
			color_cnt[(i + j) % 3][color[i][j]]++;
		}
	}
	
	ll ans = 1LL << 62;

	for(int ci = 0; ci < C; ci++) {
		for(int cj = ci + 1; cj < C; cj++) {
			for(int ck = cj + 1; ck < C; ck++) {
				vector<int> perm = {ci, cj, ck};
				do {
					ll sum = 0;
					for (int k = 0; k < 3; k++) {
						for (int c = 0; c < C; c++) {
							sum += color_cnt[k][c] * D[c][perm[k]];
						}
					}
					ans = min(ans, sum);
				} while(next_permutation(perm.begin(), perm.end()));

			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>
#include <iostream>

#include <algorithm>
#include <cmath>

#include <vector>
#include <list>
#include <string>

using namespace std;


int main() {
  int N;

  scanf("%d", &N);

  int ans = 0;

  for(int i = 1; i <= N; i += 2){
    int count = 0;

    for(int j = 1; j <=i; j++){
      if(i % j == 0){
        count++;
      }
    }

    if(count == 8){
      ans++;
    }
  }


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

  return 0;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll a=0;
    int k;cin >>k;
    ll ans=-1;
    for (int i = 0; i < k+10; ++i) {
        a+=7;a%=k;
        if(a==0){
            ans=i+1;
            break;
        }
        a*=10;
        a%=k;
    }
    cout <<ans <<endl;
}


Measured memory_bytes: 3632
//#define _GLIBCXX_DEB // Iterator safety; out-of-bounds access for Containers, etc.
//#pragma GCC optimize "trapv" // abort() on (signed) integer overflow.
#include <bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

#define ll long long int
#define mod 1000000007
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.1415926535897932384626
#define INF 1000000000
#define bits(n) __builtin_popcount(n)

void solve()
{
    int n,k;
    cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    vector<int> v(n,INF);
    v[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=i+k;j++)
        {
            if(j<n)
            v[j]=min(v[j],v[i]+abs(h[i]-h[j]));
        }
    }
    cout<<v[n-1];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 4032
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

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

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  char ss[s.size()], tt[t.size()];
  s.copy(ss, s.size());
  t.copy(tt, t.size());
  sort(ss, ss + s.size());
  sort(tt, tt + t.size()); reverse(tt, tt + t.size());
  string sss(ss, s.size()), ttt(tt, t.size());
  if (sss < ttt) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    string s;
    cin>>s;

    rep(i,s.length()){
        s[i]='x';
    }
    cout<<s<<"\n";

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}

signed main(){
    int n; ll k, tmp, m, g;
    cin >> n >> k;
    vector<ll> a;
    rep(n){
        cin >> tmp;
        a.pb(tmp);
    }
    m = *max_element(all(a));
    if(m < k){
        cout << "IMPOSSIBLE";
        return 0;
    }

    g = a[0];
    reppp(i, 1, n-1){
        g = gcd(g, a[i]);
    }
    
    if(k % g == 0){
        cout << "POSSIBLE";
    }else{
        cout << "IMPOSSIBLE";
    }

    return 0;
}


Measured memory_bytes: 1400
h, w = map(int,input().split())
masu = []
for _ in range(h):
    masu.append(list(input()))

# 行から見る
row = []
column = []
for i in range(h):
    if not masu[i] == ['.'] * w:
        row.append(i)

column = []
for i in range(w):
    flg = 0
    for j in range(h):
        if masu[j][i] == '#':
            flg = 1
    if flg == 1:
        column.append(i)

for i in row:
    for j in column:
        print(masu[i][j],end='')
    print()

Measured memory_bytes: 9220
using System;
using System.Linq;
using System.Collections.Generic;
    
class Program
{
    static void Main(string[] args)
    {
        string[] ND = Console.ReadLine().Split(' ');
        int N = int.Parse(ND[0]);
        int D = int.Parse(ND[1]);

        int count = 0;

        string[] XY;
        int X; int Y;

        for(int i=0; i<N; i++){
            XY = Console.ReadLine().Split(' ');
            X = int.Parse(XY[0]);
            Y = int.Parse(XY[1]);

            if(Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2)) <= D){
                count += 1;
            }
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 40508
N, Q = map(int, input().split())
S = input()
SC = [0] * N

for i in range(N - 1):
    if S[i:i + 2] == "AC":
        SC[i + 1] = SC[i] + 1
    else:
        SC[i + 1] = SC[i]

for i in range(Q):
    l, r = map(int, input().split())
    print(SC[r - 1] - SC[l - 1])


Measured memory_bytes: 6188
#include<stdio.h>

void swap(int *a, int *b){
	int temp = *a;
	*a = *b;
	*b = temp;
}

int bubbleSort(int A[],int N){
	int i,j;
	int sw = 0;
	unsigned short flag = 1;
	for(i=0;flag;i++){
		flag = 0;
		for(j=N-1;j>=i+1;j--){
			if(A[j]<A[j-1]){
				swap(&A[j],&A[j-1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;

}
int main(void){
	int i,A[100],N,sw;
	scanf("%d",&N);
	for(i=0;i<N;i++) scanf("%d",&A[i]);
	
	sw = bubbleSort(A,N);
	
	for(i=0;i<N;i++){
		if (i) printf(" ");
		printf("%d",A[i]);
	}
	printf("\n%d\n",sw);
	
	return 0;
}


Measured memory_bytes: 2000
#include<stdio.h>
int main()
{
	int i,w,n,a,b,c;
	int v[31]={0};

	scanf("%d",&w);
	for(i=1;i<=w;i++)
	{
		v[i]=i;
	}
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d,%d",&a,&b);
		c=v[b];
		v[b]=v[a];
		v[a]=c;
	}
	for(i=1;i<=w;i++)
	{
		printf("%d\n",v[i]);
	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c; cin>>a>>b>>c;
    if (b-a==c-b){
        cout<<"YES\n";
    }else{
        cout<<"NO\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

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

int main(void) {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  rep(i, m) cin >> b[i];
  vector<vector<int> > a(n);
  rep(i, n) {
    a[i].resize(m);
    rep(j, m) {
      cin >> a[i][j];
    }
  }

  int cnt = 0;
  rep(i, n) {
    int score = 0;
    rep(j, m) {
      score += a[i][j] * b[j];
    }
    if (score + c > 0) cnt++;
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int mINF = 1e9;
const int MOD = 1e9+7;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(){
    int dx[4] = {0,1,0,-1};
    int dy[4] = {1,0,-1,0};
    int h,w;cin >> h >> w;
    vector<vector<char>> G(h,vector<char>(w));
    rep(i,h){
        rep(j,w){
            cin >> G[i][j];
        }
    }

    queue<pair<int,int>> que;
    vector<vector<int>> dist(h,vector<int>(w,-1));
    dist[0][0] = 0;
    que.push(make_pair(0,0));
    while(!que.empty()){
        int x,y;
        tie(y,x) = que.front();
        que.pop();

        for(int i=0;i<4;i++){
            int ndx = x + dx[i];
            int ndy = y + dy[i];
            if(ndx<0||ndx>=w||ndy<0||ndy>=h||G[ndy][ndx]=='#'||dist[ndy][ndx]!=-1)continue;
            dist[ndy][ndx] = dist[y][x] + 1;
            que.push(make_pair(ndy,ndx));
        }
    }
    int black = 0;
    rep(i,h){
        rep(j,w){
            if(G[i][j]=='#')black++;
        }
    }
    if(dist[h-1][w-1]!=-1)cout << h*w - (black+2) - (dist[h-1][w-1]-1) << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
count = 0
if (H == 1) or (W == 1):
  print(1)
else:
  if H % 2 == 0:
    print(W * (H // 2))
  else:
    if W % 2 == 0:
      print(W * (H // 2) + (W // 2))
    else:
      print(W * (H // 2) + (W // 2) + 1)


Measured memory_bytes: 38256
def main():
    n, m = map(int, input().split())
    num_list = []
    for _ in range(n):
        num_list.append(list(map(int,input().split())))

    ans = 0

    num_list = sorted(num_list, key=lambda x: x[0])

    for i in range(n):
        if m <= 0:
            break
        if m >= num_list[i][1]:
            ans += num_list[i][0] * num_list[i][1]
            m -= num_list[i][1]
        else:
            ans += num_list[i][0] * m
            break

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 65368
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector <int> vi;

int str2int(string text){
    stringstream ss;
    ss<<text;
    int tmp;
    ss>>tmp;
    return tmp;
}

int main(void){
    int w=0, n;
	cin>>w;
	vi x(w);
	for (int i=0; i<w; i++)
		x[i] = i+1;

	cin>>n;
	for (int i=0; i<n; i++){
		string text;
		cin>>text;
		string::size_type index = text.find( "," );

		int a, b;
		a = str2int(text.substr(0, index));
		b = str2int(text.substr(index+1));
		swap(x[a-1], x[b-1]);
	}

	for (int i=0; i<w; i++)
		cout<<x[i]<<endl;
    return 0;
}

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

using namespace std;
  int main() {int A,B;
  cin>>A>>B;
  if(A==1&&B==2)
    cout<<3;
  if(A==1&&B==3)
    cout<<2;
  if(A==2&&B==3)
    cout<<1;
  
  if(B==1&&A==2)
    cout<<3;
  if(B==1&&A==3)
    cout<<2;
  if(B==2&&A==3)
    cout<<1;
              return 0;
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long x,y,o,p=0;
	string s;
	cin>>s;
	x=s.size();
	for(int i=0;i<x;i++)
	{
		if(s[i]=='C')
		{
			o=i;
			break;
		}
	}
	for(int i=o+1;i<x;i++)
	{
		if(s[i]=='F')
	{p++;
		break;
	}	
	}
	if(p==0)cout<<"No";
	else cout<<"Yes";
}

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

pair<long, long> MakePairValue(string s) {
    // a : 最終値
    // b : 制約
    long a = 0, b = 10000000; // S <= 1000000 なので余裕持って
    for (auto c : s) {
        if (c == '(') {
            a++;
        } else {
            a--;
            if (b > a && a < 0)
                b = a;
        }
    }
    return pair<long, long>(b, a);
}

// first で降順、second で降順ソート
bool compF(pair<long, long>a, pair<long, long>b) {
    if (a.first > b.first) {
        return true;
    } else if (a.first == b.first) {
        return a.second > b.second;
    } else {
        return false;
    }
}

// second - first で降順、second で降順ソート
bool compFMinus(pair<long, long>a, pair<long, long>b) {
    long ta = a.second - a.first;
    long tb = b.second - b.first;
    if (ta > tb) {
        return true;
    } else if (ta == tb) {
        return a.second > b.second;
    } else {
        return false;
    }
}

// first 降順
bool compFAdd(pair<long, long>a, pair<long, long>b) {
    if (a.first > b.first)
        return true;
    return false;
}

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

    vector<pair<long, long>> pv;
    vector<pair<long, long>> pvMinus, pvAdd;
    pv.reserve(N);
    pvMinus.reserve(N);
    pvAdd.reserve(N);
    

    for (size_t i = 0; i < N; i++) {
        string s;
        cin >> s;
        auto a = MakePairValue(s);
        if (a.first < 0) {
            if (a.second > 0)
                pvAdd.push_back(a);
            else
                pvMinus.push_back(a);
        } else {
            pv.push_back(a);
        }
    }

    sort(pv.begin(), pv.end(), compF);
    sort(pvMinus.begin(), pvMinus.end(), compFMinus);
    sort(pvAdd.begin(), pvAdd.end(), compFAdd);

    // 前のほうが制約が緩く、最終値が大きい

    long long sum = 0;
    bool b = true;
    for (auto e : pv) {
        sum += e.second;
    }
    for (auto e : pvAdd) {
        if (sum < -e.first) {
            b = false;
            break;
        }
        sum += e.second;
    }
    if (b) {
        for (auto e : pvMinus) {
            if (sum < -e.first) {
                b = false;
                break;
            }
            sum += e.second;
        }
    }
    if (b && sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 18528
from bisect import bisect_left

n = int( input() )
a = []
for i in range(n):
    a.append(int(input()))

min_stack = [a[-1]]

for i in range(2,n+1):
    if min_stack[-1] <= a[-i]:
        min_stack.append(a[-i])
    else:
        tmp = min_stack[bisect_left(min_stack, a[-i])]
        if tmp == a[-i]:
            min_stack[bisect_left(min_stack, a[-i]+1)] = a[-i]
        else:
            min_stack[bisect_left(min_stack, a[-i])] = a[-i]

print(len(min_stack))

Measured memory_bytes: 56408
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f(i,a,b) for(int i=a;i<=b;i++)
#define mm make_pair
#define pi 2*acos(0.0)
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout.precision(i);cout<<fixed<<ans<<endl;
#define Y {cout<<"YES"<<endl;return 0;}
#define pb(x) push_back(x)
#define lowbit(x) (x)&(-x)
#define out(x) {cout<<x<<endl;return 0;} 
#define all(v) v.begin(),v.end() 
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int inf=0x3f3f3f,maxn=2e5+100;
ll gcd(ll x,ll y){if(y==0) return x;else return gcd(y,x%y);} 
ll ksm(ll a,ll b){ll r=1;while(b){if(b&1) r=(r*a)%mod;a=a*a%mod;b>>=1;}return r;} 
int n,m,a[maxn]; 
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	int sum=0;
	for(int i=2;i<=n-1;i++)
	{
		if(a[i]>min(a[i-1],a[i+1])&&a[i]<=max(a[i-1],a[i+1]))
		sum++;
	}
	cout<<sum<<endl;
} 

Measured memory_bytes: 256
#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;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#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';

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll n, k;
  cin >> n >> k;
  
  vl plus, zero, minus;
  ll num;
  rep(i, n) {
    cin >> num;
    if(num>0) plus.push_back(num);
    if(num==0) zero.push_back(num);
    if(num<0) minus.push_back(num);
  }
  
  sort(all(plus));
  sort(all(minus), greater<ll>());
  
  if(k > plus.size() + minus.size()) {cout << 0 << newl; return 0;}
  
  ll ans = 1;
  if(plus.size() > 0) {
    if(k%2==1) {(ans *= plus[plus.size()-1] )%= MOD; plus.pop_back(); k--;}
    while(k) {
      ll num1 = (plus.size()>=2 ? plus[plus.size()-2]*plus[plus.size()-1] : 0LL);
      ll num2 = (minus.size()>=2 ? minus[minus.size()-2]*minus[minus.size()-1] : 0LL);
      if(num1==0 and num2==0) break;
      if(num1>=num2) {
        (ans *= (num1 %= MOD)) %= MOD; plus.pop_back(); plus.pop_back();
      }else {
        (ans *= (num2 %= MOD)) %= MOD; minus.pop_back(); minus.pop_back();
      }
      k--; k--;
    }
    if(k and zero.size()) ans=0;
    else if(k) {(((((ans *= plus[0]) %= MOD ) *= minus[0] ) %= MOD) += MOD) %= MOD;}
    cout << ans << newl;
    return 0;
  }
  
  if(plus.size() == 0) {
    if(k%2==0) rep(_, k) {(ans *= minus.back()) %= MOD; minus.pop_back();}
    else if(k%2==1 and zero.size()) ans = 0;
    else rep(i, k) (ans *= minus[i]) %= MOD;
    (ans += MOD) %= MOD;
    cout << ans << newl;
    return 0;
  }
}

Measured memory_bytes: 5528
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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; }

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */
int main(){
    int a, b;
    cin >> a >> b;
    int ans = 0;
    rep(i, 2) {
        if (a > b) {
            ans += a;
            a--;
        }else{
            ans += b;
            b--;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
//#include"functions.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define INF 0x7fffffff
#define LLINF 0x7fffffffffffffff
#define EPS 1e-5
#define LDEPS 1e-9
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define FOR(a,b) for(int a=0;a<b;a++)
#define FORN(a,m,n) for(int a=m;a<n;a++)
#define REP(a,m,n) for(int a=0;a<m;a+=n)
#define REPN(a,m,n,p) for(int a=m;a<n;a+=p)
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdfopen(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define ifopen(a) freopen(a,"r",stdin);
#define ofopen(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
	int n;
	cin>>n;
	int ans=0;
	if(n<=9){
		cout<<n<<endl;
		return 0;
	}
	if(n<=99){
		cout<<9<<endl;
		return 0;
	}
	if(n<=999){
		cout<<9+(n-100+1)<<endl;
		return 0;
	}
	if(n<=9999){
		cout<<909<<endl;
		return 0;
	}
	if(n<=99999){
		cout<<909+(n-10000+1)<<endl;
		return 0;
	}
	cout<<90909<<endl;
	return 0;
}

Measured memory_bytes: 256