akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
 
#define loop(x) for(int i = 0; i < x; i++)
#define deb(x) cout<< #x << x << " "
#define ll long long
#define LINF 1e18L + 5 
#define INF 1e9 + 7
using namespace std;

const int max_size = 1e5 + 5;
int totalMax = 0;
int maxAmount = -400;

vector<int> visited(max_size, 0);
vector<int> maxLength(max_size, 0);
vector<int> incom(max_size, 0);


bool f(string s1) {
   
}

void dfs(vector<vector<int>> arr, int i) {
    if(visited[i]) {
        return;
    }
    visited[i] = true;
    for(int j = 0; j < arr[i].size(); j++) {
        incom[arr[i][j]]--;
        maxLength[arr[i][j]] = max(maxLength[arr[i][j]], maxLength[i] + 1);
        if(incom[arr[i][j]] == 0) {
            dfs(arr, arr[i][j]);
        }
    }
}

int main() {
 
    int t = 1;
    //cin>>t;
    while(t--) {
        // FOR ARRAY
        // int n;
        // cin>>n;
        // vector<int> arr;
        // for(int i = 0; i < n; i++) {
        //     int x;
        //     cin>>x;
        //     arr.push_back(x);
        // }
        // f(arr);
 
        // FOR MATRIX
        // int row, col;
        // cin>>row;
        // cin>>col;
        // vector<vector<int>> arr(row, vector<int>(col, 0));
        // for(int i = 0; i < row; i++) {
        //     for(int j = 0; j < col; j++) {
        //         cin>>arr[i][j];
        //     }
        // }
        int n;
        cin>>n;
        vector<double> p(n, 0);
        for(int i = 0; i < n; i++) {
            cin>>p[i];
        }
        vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
        for(int i = 0; i <= n / 2 + 1; i++) {
            for(int j = 0; j <= n; j++) {
                if(i == 0 && j == 0) {
                    dp[i][j] = 1;
                } else if(j == 0) {
                    dp[i][j] = 0;
                } else if(i == 0) {
                    dp[i][j] = 1;
                } else {
                    dp[i][j] = (double)p[j - 1] * dp[i - 1][j - 1] + (double)((double)1 - p[j - 1]) * dp[i][j - 1];
                }
                //cout<<dp[i][j]<<" ";
                
            }
            //cout<<endl;
        }
        cout<<setprecision(10)<<dp[n / 2 + 1][n]<<endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if((i+1)%2!=0 && arr[i]%2!=0) cnt++;
    }
    cout<<cnt<<endl;


    return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n,d;
  cin >> n >> d;
  vector<vector<int>> x(n,vector<int>(d));
  rep(i,n)rep(j,d) cin >> x[i][j];

  set<int> sqr;
  for(int i=1; i*i<=2500*d; ++i) sqr.emplace(i*i);

  int ans = 0;
  rep(i,n)for(int j = i + 1; j < n; ++j){
    int dist = 0;
    rep(di,d) {
      int diff = x[i][di]-x[j][di];
      dist += diff*diff;
    }
    if(sqr.count(dist)>0) ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
int main(int argc, char const *argv[])
{
	int a, b, c;
//	char s[101];

	scanf("%d", &a);
	scanf("%d", &b);
//	scanf("%d", &c);
//	scanf("%s", &s);

//	printf("%d ", a+b+c);
//	printf("%s\n", s);

	c = a + b;
	if ((a%2 == 1)&&(b%2 == 1))
	{
		printf("Odd\n");
	}else{
		printf("Even\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;

bool ans = true;
int main()
{
	int n, m;
	cin >> n >> m;
	string s = string(n, 'a');
	for (int i = 0; i < m; i++) {
		int pos, c;
		cin >> pos >> c;
		if (s[pos - 1] == 'a')s[pos - 1] = c + '0';
		else if (c + '0' != s[pos - 1])ans = false;
	}
	
	for (int i = 1; i < n; i++)
		if (s[i] == 'a')s[i] = '0';
	if (s[0] == '0' && n > 1)ans = false;
	else if (s[0] == 'a') {
		if (n > 1)s[0] = '1';
		else s[0] = '0';
	}
	if (ans) {
		cout << s << endl;
	}
	else cout << -1 << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LINF = (LLONG_MAX/2);
const double eps = 1e-14;
const double PI = M_PI;  
#define DEB cout<<"!"<<endl
#define SHOW(a,b) cout<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cout<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
  
#define DIV 1000000007

vector<ll> v(100000);

int main(){
  ll n,k; cin >> n >> k;
  ll m = 0;
  rep(i,n){
    cin >> v[i];
    m = max(m,v[i]);
    if(i!=0)
      v[i] = __gcd(v[i],v[i-1]);
  }
  if(k % v[n-1] == 0 && k <= m)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

int N, M;
vector<P> G[200100];
int dist[200100];

std::priority_queue<P, std::vector<P>, std::greater<P>> pq;
template <typename T, typename U, int N>
void dijkstra(int s, std::vector<T> (&graph)[N], U (&dist)[N]){
    std::fill(dist, dist+N, std::numeric_limits<U>::max() / 2);
    dist[s] = 0;
    pq.emplace(dist[s], s);

    while(!pq.empty()){
        int u;
        U d;
        std::tie(d, u) = pq.top();
        pq.pop();

        if(dist[u] < d){continue;}

        for(const auto& p : graph[u]){
            int v;
            U c;
            std::tie(v, c) = p;
            if(dist[v] > d + c){
                dist[v] = d + c;
                pq.emplace(dist[v], v);
            }
        }
    }
}

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

    std::cin >> N >> M;

    for(int i=0;i<M;++i){
        int a, b;
        std::cin >> a >> b;

        G[a].emplace_back(b, 1);
        G[b].emplace_back(a, 1);        
    }

    dijkstra(1, G, dist);
    if(dist[N] == 2){
        std::cout << "POSSIBLE" << std::endl;
    }else{
        std::cout << "IMPOSSIBLE" << std::endl;
    }
}


Measured memory_bytes: 15080
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvll vector<vll>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define pii pair<int, int>
#define vpli vector<pair<long long, int>>
#define deb(x) cout << "deb " << #x << " " << x << endl;
#define all(x) x.begin(), x.end()
#define endl "\n"
const ll BIG = 1e18;
const int MOD =  998244353;

void swap(ll &a, ll &b)
{
    ll t = a;
    a = b;
    b = t;
}

ll Min(ll a, ll b, ll c)
{
    return min(a, min(b, c));
}

void printvec(vi &vec)
{
    for (int x : vec)
    {
        cout << x << " ";
    }
    cout << endl;
}

int sum(int a)
{
    int ans = 0;
    while (a)
    {
        ans += (a % 10);
        a = a / 10;
    }
    return ans;
}
void print(vi &mp)
{
    for (auto x : mp)
    {
        cout << x;
    }
    cout << endl;
}
/*
void mulmod(ll &a,ll b )
{
    a += MOD;
    b += MOD;
    return (a*b)%MOD;
}
*/
void solve()
{
    int n, s;
    cin >> n >> s;
    vi a(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    vvll dp(n + 1, vll(s + 1));
    ll mul = 1;
    for (int i = 0; i <= s; i++)
    {
        dp[0][i] = 0;
    }
    for (int i = 0; i <= n; i++)
    {
        dp[i][0] = mul;
        mul = (mul*2)%MOD;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j = 1;j<=s;j++)
        {
            dp[i][j] = (2*dp[i-1][j])%MOD;
            if(j-a[i]>=0)
            {
                dp[i][j] = (dp[i][j] +  dp[i-1][j-a[i]])%MOD;
                if(dp[i][j]<0) dp[i][j] += MOD;
            }
        }
    }
    cout<<dp[n][s];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 73692
use std::io::*;
use std::str::FromStr;
use  std::collections::BTreeMap;
use std::cmp::min;

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

fn main(){
    let s: String = read();
    let t: String = read();
    let a: u8 = read();
    let b: u8 = read();
    let u: String = read();
    if s == u {
        println!("{} {}", a - 1, b);
    } else {
        println!("{} {}", a, b - 1);
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
static const int MAX = 200000;
int main(){
	int R[MAX], n;
	cin >> n;
	int j;
	for (int i = 0; i < n; i++)
		cin >> R[i];
	int key;
	for (int i = 0; i < n; i++){
                key=R[i];
		j = i - 1;
		while (j >= 0 && R[j] > key){
			R[j + 1] = R[j];
			j--;
		}
		R[j + 1] = key;
		for (int i = 0; i < n; i++){
                        if(i>0)
                          printf(" ");
			printf("%d", R[i]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 3172
def slove():
    import sys
    input = sys.stdin.readline
    a, b, c, x, y = list(map(int, input().rstrip('\n').split()))
    t = a * x + b * y
    t = min(t, max(x, y) * 2 * c)
    m = min(x, y)
    x -= m
    y -= m
    m = min(t, a * x + b * y + c * 2 * m)
    print(m)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main(){
	char s[18];
	for(int i=0;i<19;i++){
		cin>>s[i];
		if(s[i]==',')s[i]=' ';
	}
	for(int j=0;j<19;j++)cout<<s[j];
	cout<< endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,a[105],sum=0;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    cin>>m;
    for(int i=1;i<=m;i++)
    {
        int p,q;
        cin>>p>>q;
        cout<<sum-a[p]+q<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}


int get_str(char *str, int size)
{
    char format[100];
    if (size == 0)
        return 0;
    snprintf(format, sizeof(format), "%%%ds", size);
    scanf(format, str);
    return 0;
}

#define NUM_MAX 200000
#define BUF_SIZE (NUM_MAX+50)
#define PRIME_MAX 10000

int main(void) {
    int num, divisor;
    get_int2(&num, &divisor);

    static char str[BUF_SIZE];
    static int mod_map[PRIME_MAX];
    get_str(str, BUF_SIZE);
    int i;

    int64_t ans = 0;
    if(divisor == 2 || divisor == 5) {
        for(i = num-1; i >= 0; i--) {
            int d = str[i] - '0';
            if(!(d%divisor)) {
                ans += (i+1);
            }
        }
        goto finish;
    }
    
    // divisor has nothing to do with 10**n.
    int sum = 0;
    int power10 = 1;
    for(i = num-1; i >= 0; i--) {
        int d = str[i] - '0';
        sum = (d*power10+sum)%divisor;
        power10 = (power10*10)%divisor;
        mod_map[sum]++;
    }
    int offset = 0;
    ans += mod_map[offset];
#ifdef DEBUG
    printf("ans: %lld\n", ans);
#endif
    power10 = 1;
    for(i = num-1; i >= 0; i--) {
        int d = str[i] - '0';
        offset = (d*power10+offset)%divisor;
        power10 = (power10*10)%divisor;
        mod_map[offset]--;
        ans += mod_map[offset];
#ifdef DEBUG
        printf("ans: %d\n", mod_map[offset]);
#endif
    }
finish:
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=200005;
int X,Y,n;
struct info{
	int w,c;
	inline void init(){read(c);read(w);}
}a[maxn];
inline bool operator < (const info &a,const info &b){
	return a.c<b.c||(a.c==b.c&&a.w<b.w);
}
priority_queue<pin,vector<pin>,greater<pin> > heap;
int fac[maxn],v[maxn],id2,lv1,lv2;
int facinv[maxn];
const int mod=1e9+7;
inline int powmod(int a,int b){
	int res=1;for(;b;b>>=1){
		if(b&1)res=1ll*res*a%mod;
		a=1ll*a*a%mod;
	}return res;
}
inline void prprpr(){
	fac[0]=1;
	rep(i,1,200000)fac[i]=1ll*fac[i-1]*i%mod;
	facinv[200000]=powmod(fac[200000],mod-2);
	per(i,200000-1,0)facinv[i]=1ll*facinv[i+1]*(i+1)%mod;
}
int mini[maxn],m1,m2,t,sz[maxn],sum[maxn];
int main(){
    prprpr();
    read(n);read(X);read(Y);
    rep(i,1,n)a[i].init();
    sort(a+1,a+1+n);
    memset(mini,60,sizeof(mini));
 	rep(i,1,n)mini[a[i].c]=min(mini[a[i].c],a[i].w);m1=m2=1e9;
 	rep(i,1,n)if(a[i].w<m1)m1=a[i].w,t=a[i].c;
 	rep(i,1,n)if(a[i].c!=t)m2=min(m2,a[i].w);
 	rep(i,1,n)if(a[i].w+mini[a[i].c]<=X)sz[a[i].c]++;
 	rep(i,1,n)if(a[i].w+m1<=Y&&a[i].c!=t||a[i].w+m2<=Y)sum[a[i].c]++;int res=1,tot=0;
 	rep(i,1,n)if(sum[i]||i==t){
 		tot+=max(sum[i],sz[i]);
 		res=1ll*res*facinv[max(sum[i],sz[i])]%mod;
 	}
 	res=1ll*res*fac[tot]%mod;
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 6528
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String s = sc.next();

        int a = Integer.parseInt(s.substring(0,2));
        int b = Integer.parseInt(s.substring(2,4));

        if ( (a>=1) && (a<=12) && (b>=1) && (b<=12) )
            System.out.println("AMBIGUOUS");
        else if ( (a>=1) && (a<=12) && ( (b==0) || (b>12) ) )
            System.out.println("MMYY");
        else if ( (b>=1) && (b<=12) && ( (a==0) || (a>12) ) )
            System.out.println("YYMM");
        else
            System.out.println("NA");
    }
}

Measured memory_bytes: 35584
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define REP(i, a, b) for(i = a; i < b; i++)
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int cnt[10];

signed main() {
	int a;
	for (int i = 0; i < 4; i++) {
		cin >> a;
		cnt[a]++;
	}
	if (cnt[1] && cnt[9] && cnt[7] && cnt[4]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <cassert>
#include <list>

struct Proc{
	std::string name;
	int time;
};

typedef std::list<Proc> PList;
void output(const PList& vec);
PList calc(PList vec, int q);

///-------------------------------------------------
int main()
{
	PList ivec;
	int n;
	std::cin >> n;
	int q;
	std::cin >> q;
	for(int i = 0; i < n; i++){
		Proc proc;
		std::cin >> proc.name;
		std::cin >> proc.time;
		ivec.push_back(proc);
	}
	PList ovec = calc(ivec,q);
	for(PList::const_iterator itr = ovec.begin(); itr != ovec.end(); itr++){
		std::cout << itr->name << " " << itr->time << std::endl;
	}
	return 0;
}
///--------------------------------------------
///-------------------------------------------------
PList calc(PList queue, int q)
{
	PList vec;
	int  time = 0;
	while(!queue.empty()){
		if(queue.front().time > q){
			time += q;
			queue.front().time -= q;
			queue.push_back(queue.front());
		}else{
			time += queue.front().time;
			queue.front().time = time;
			vec.push_back(queue.front());
		}
		queue.pop_front();
	}
	return vec;
}
///-------------------------------------------------

Measured memory_bytes: 10060
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	int n=s.length();
	bool flag=false;
	for(int i=0;i<n;i++){
		if(s==t){
			flag=true;
			break;
		}
		reverse(s.begin(),s.begin()+n-1);
		reverse(s.begin(),s.begin()+n);
	}
	if(flag) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


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


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/


int main() {

	ll n, q;
	cin >> n >> q;

	vector<ll> s(n), t(n), x(n), d(q);

	for (int i = 0; i < n; i++)
	{
		cin >> s[i] >> t[i] >> x[i];
	}
	for (int i = 0; i < q; i++)
	{
		cin >> d[i];
	}

	vector<pair<pll, ll> > events;//(時刻，座標，フラグ)
	set<ll> cannot_use;

	for (int i = 0; i < n; i++)
	{
		events.push_back(make_pair(make_pair(s[i] - x[i], x[i]), 1));
		events.push_back(make_pair(make_pair(t[i] - x[i], x[i]), 0));
	}

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

	int idx = 0;
	int siz = events.size();

	for (int i = 0; i < q; i++)
	{
		while (idx < siz && events[idx].first.first <= d[i]) {

			if (events[idx].second == 1) {
				//工事の開始
				cannot_use.insert(events[idx].first.second);
			}
			else
			{
				//工事の終了
				cannot_use.erase(events[idx].first.second);
			}
			idx++;
		}
		if (cannot_use.empty()) {
			cout << "-1" << endl;
		}
		else
		{
			cout << *cannot_use.begin() << endl;
		}
	}
	

	return 0;
}


Measured memory_bytes: 26600
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
 
#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<char> Sa(N);
  int P = (N-1)/2;
  int Q = (N+3)/2;
  rep(i, N){
    Sa.at(i) = S.at(i);
  }
vector<char> rSa(N);
  rSa = Sa;
  reverse(rSa.begin(),rSa.end());
  if(rSa != Sa) {
    cout << "No" << endl;
  }
  else{
    vector<char> Sb(P);
    rep(j, P) {
      Sb.at(j) = Sa.at(j);
    }

    vector<char> rSb(P);
    rSb = Sb;
  reverse(rSb.begin(),rSb.end());
    if(rSb != Sb) {
 cout << "No" << endl;
    }
    else{
      cout << "Yes" << endl;
      }
    }
  }



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

using namespace std;

int main(){
  int N,M; cin >> N >> M;
  vector<int> switches(N,0);
  for(int i = 0; i < M; i++){
    int k ; cin >> k;
      for(int j = 0; j < k; j++){
        int s; cin >> s;  s--;
        switches[s] |= 1 << i;}}
  
  int cnt = 0; int p = 0;
  
  for(int i = 0; i < M; i++){ int q; cin >> q;
    p |= q << i;}
  
  for(int i = 0; i < ( 1 << N); i++){
    int t = 0;
    for(int j = 0; j < N; j++){ 
      if( i >> j & 1){t ^= switches[j];}}
    if( t == p){ cnt++;}            }
  
  cout << cnt << endl;
  return 0;}
      
        

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define assign(x,val) memset(x,val,sizeof(x))
#define motherfucker  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define for0(i,n) for(ll i=0;i<n;++i)
#define for1(i,n) for(ll i=1;i<=n;++i)
#define ford(i,n) for(ll i=n;i>=1;--i)
#define forg(i,a,b) for(ll i=a;i<b;++i)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpl;
long long mod = 1000000007;
const long double PI = (long double)(3.1415926535897932384626433832795);
 
 
void solve(){
	int n;cin>>n;
	vpi arr(n);
	for0(i,n){
		cin>>arr[i].ff;
		arr[i].ss = i;
	}
	sort(all(arr));
	int cnt = 0;
	for0(i,n){
		if(arr[i].ss%2!=i%2){
			cnt++;
		}
	}
	cout<<cnt/2<<endl;
}
 
int main(){
	motherfucker
	ll t = 1;
	//cin>>t;
	for0(i, t){
		solve();
	}
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        sc.nextLine();

        char[][] s = new char[h][w];
        for(int i=0; i<h; i++) {
            s[i] = sc.nextLine().toCharArray();
        }
        sc.close();

        // down, right, up, left
        int[] x = {1, 1, 0, -1, -1, -1, 0, 1}; //height
        int[] y = {0, 1, 1, 1, 0, -1, -1, -1}; //width
        char[][] ans = new char[h][w];

        for(int i=0; i<h; i++) {
            for(int j=0; j<w; j++) {
                int cnt = 0;
                for(int k=0; k<8; k++) {
                    int nx = i+x[k];
                    int ny = j+y[k];
                    if(nx >= 0 && nx < h && ny >= 0 && ny < w) {
                        if(s[nx][ny] == '#') {
                            cnt++;
                        }
                    }
                }
                if(s[i][j] == '#') {
                    ans[i][j] = '#';
                } else {
                    ans[i][j] = (char)(cnt+'0');
                }
            }
        }

        for(int i=0; i<h; i++) {
            System.out.println(ans[i]);
        }
    }
}


Measured memory_bytes: 23892
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public int countTriangles(int[] lengths) {
        if (lengths.length < 3) return 0;

        Map<Integer, Integer> uniqueMap = new HashMap<>();
        for (int length : lengths) {
            uniqueMap.put(length, uniqueMap.getOrDefault(length, 0) + 1);
        }

        int count = 0;
        Integer[] uniqueLengths = uniqueMap.keySet().toArray(new Integer[0]);
        for (int i = 0; i < uniqueLengths.length; i++) {
            for (int j = i + 1; j < uniqueLengths.length; j++) {
                for (int k = j + 1; k < uniqueLengths.length; k++) {
                    if (!canFormTriangle(uniqueLengths[i], uniqueLengths[j], uniqueLengths[k])) {
                        continue;
                    }
                    count += uniqueMap.get(uniqueLengths[i]) * uniqueMap.get(uniqueLengths[j]) * uniqueMap.get(uniqueLengths[k]);
                }
            }
        }

        return count;
    }
    private boolean canFormTriangle(int a, int b, int c) {
        return a < b + c && b < a + c && c < a + b;
    }

    public static void main(String[] args) throws Exception {
        Main solution = new Main();

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] lengths = new int[n];

        for (int i = 0; i < n; i++) {
            lengths[i] = scanner.nextInt();
        }

        int answer = solution.countTriangles(lengths);
        System.out.println(answer);
    }
}

Measured memory_bytes: 38056
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if((a*b)%2==0)
	{
		printf("Even");
	}
	if((a*b)%2!=0)
	{
		printf("Odd");
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAX 100100
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,L,T,t;
int pos[MAX];
int main()
{
	n=read();L=read();T=read();
	for(int i=0;i<n;++i)
	{
		int x=read(),w=(read()==2)?-1:1;
		pos[i]=((x+w*T)%L+L)%L;
		if(~w)t=(t+(x+T)/L)%n;
		else t=(t+(x-T)/L-(((x-T)%L<0)?1:0)+n)%n;
	}
	sort(&pos[0],&pos[n]);
	for(int i=t;i<n;++i)printf("%d\n",pos[i]);
	for(int i=0;i<t;++i)printf("%d\n",pos[i]);
	return 0;
}


Measured memory_bytes: 1536
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

S, C = gets_i_list

if S >= C * 2
  puts [S, C/2].min
elsif S >= C / 2
  puts C / 2
else
  diff = C - S * 2
  puts S + diff / 4
end




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

int f(int x) {
	if(x % 2 == 0) return 0;
	int cnt = 0;
	for(int i = 1; i <= x; ++i) if(x % i == 0) cnt++;
	if(cnt == 8) return 1;
	return 0;
}

int main() {
	int n; cin >> n;
	int sum = 0;
	for(int i = 1; i <= n; ++i) sum += f(i);
	cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N; cin >> N;
    vec<lint> A_list(N);
    range(i, 0, N) cin >> A_list.at(i);
    unordered_map<lint, lint> count;
    for (const auto& A : A_list) count[A] += 1;
    // cout << count << "\n";
    lint num_comb_all = 0;
    for (const auto& p : count) {
        num_comb_all += p.second * (p.second - 1) / 2;
    }
    // cout << num_comb_all << "\n";
    for (const auto& A : A_list) {
        lint c = count.at(A);
        cout << num_comb_all - (c - 1) << "\n";
    }
}

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

int64_t mod = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector<int> list(N);
    for (int i = 0; i < N; i++)
        cin >> list[i];

    sort(list.begin(), list.end());
    double ans = list[0];
    for (int i = 1; i < N; i++)
        ans = (ans + list[i]) / 2;
    cout << fixed << setprecision(15) << ans;
}

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

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

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

ll f(ll x, ll c, ll d) {
	ll res = x;
	res -= x / c;
	res -= x / d;
	res += x / lcm(c, d);
	return res;
}

int main() {

	ll a,b,c,d;
	cin >> a>> b >> c >> d;

	ll ans = 0;
	ans = f(b, c,d) - f(a - 1, c,d);

	cout << ans << endl;
}


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

std::map<char, int> mp;
int H, W;

bool ans = true;

void solve1(int a, int b){
	bool check;
	for(int i = 0; i < a; i += 2){
		check = false;
		if(a - i >= 2){
			if(b >= 2){
				for(char i = 'a'; i <= 'z'; i++){
					if(mp[i] >= 4) {
						std::cerr << i << ":" << mp[i] << "->";
						mp[i] -= 4;	
						std::cerr << mp[i] << std::endl;
						check = true;
						break;
					}
				}
			}else{
				for(char i = 'a'; i <= 'z'; i++){
					if(mp[i] >= 2) {
						std::cerr << i << ":" << mp[i] << "->";
						mp[i] -= 2;	
						std::cerr << mp[i] << std::endl;
						check = true;
						break;
					}
				}
			}
		}else{
			if(b >= 2){
				for(char i = 'a'; i <= 'z'; i++){
					if(mp[i] >= 2) {
						std::cerr << i << ":" << mp[i] << "->";
						mp[i] -= 2;	
						std::cerr << mp[i] << std::endl;
						check = true;
						break;
					}
				}
			}else{
				for(char i = 'a'; i <= 'z'; i++){
					if(mp[i] >= 1) {
						std::cerr << i << ":" << mp[i] << "->";
						mp[i] -= 1;	
						std::cerr << mp[i] << std::endl;
						check = true;
						break;
					}
				}
			}

		}
		if(!check)ans = false;
	}

}
void solve(int H, int W){
	if(H <= 0 || W <= 0)return;
	std::cerr << "-----remaining-------" << std::endl;
	for(char i = 'a'; i <= 'z'; i++){
		if(mp[i] > 0)std::cerr << i << " " << mp[i] << std::endl;
	}
	std::cerr << "------------------------" << std::endl;

	std::cerr << "H=" << H << std::endl;
	solve1(H, W);

	if(W >= 2)W -= 2;
	else W = 0;

	std::cerr << "W=" << W << std::endl;
	solve1(W, H);

	if(H >= 2)H -= 2;
	else H = 0;

	solve(H, W);
}

int main(){
	std::cin >> H >> W;
	char a;

	for(char i = 'a'; i <= 'z'; i++){
		mp[i] = 0;
	}

	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			std::cin >> a;
			mp[a]++;
		}
	}

	solve(H, W);

	std::cout << (ans ? "Yes" : "No") << std::endl;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <chrono>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdarg.h>
#include <utility>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unisgned long long
#define ld long double
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define pii pair<int, int>
#define tii triple<int, int, int>
#define e 1e-7
#define PI acos(-1)
#define sz(a) (int)(a.size())
#define inf 1e17
#define vi vector<int>
#define F first
#define S second
#define rng(x) for(int _ = 0; _ < (x); _++)
#define rngi(i, x) for(int i = 0; i < (x); i++)
#define rngsi(s, i, x) for(int i = (s); i <(x); i++)
#define int long long
#define problem ""

template<typename A, typename B, typename C>
struct triple{
    A X;
    B Y;
    C Z;
    triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
};
template<typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0){
    return triple<A, B, C>(a, b, c);
}
template<typename A, typename B, typename C>
bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b){
    if (a.X != b.X)
        return a.X < b.X;
    if (a.Y != b.Y)
        return a.Y < b.Y;
    return a.Z < b.Z;
}
template<typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p){
    ofs << "( " << p.F << " , " << p.S << " )";
    return ofs;
}
template<typename T>
void print(T a){
    for (auto i : a)
        cout << i << ' ';
    cout << '\n';
}
template<typename T>
T max(T a, T b, T c){
    return max(a, max(b, c));
}
template<typename T>
T min(T a, T b, T c){
    return min(a, min(b, c));
}
template<typename T, typename D>
D min(T a){
    return *min_element(all(a));
}
template<typename T, typename D>
D max(T a){
    return *max_element(all(a));
}
struct custom_hash{
    static uint64_t splitmix64(uint64_t x){
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const{
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void solve(){
    int n; cin >> n;
    vi a(n); rngi(i, n) cin >> a[i];
    SORT(a);
    int ans = 0;
    rngi(k, n - 1) ans += a[n - 1 - (k + 1)/2];
    cout << ans << '\n';
    
};
signed main()
{
    if(0){
        freopen(problem".in", "r", stdin);
        freopen(problem".out", "w", stdout);
    }
    srand(time(NULL));
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    int t = 1; //cin >> t;
    rng(t) solve();
}


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

int main() {
	int N;
	cin >> N;
	vector<int> h(N);
	rep(i, N) cin >> h[i];

	vector<int> dp(N, 0);
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for(int i = 2; i < N; i++) {
		dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
	}

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

	return 0;
}

Measured memory_bytes: 4048
def tria(n):
  return n * (n+1) // 2

X = int(input())

l = 0
r = int(1e9)

while l+1<r:
  mid = (l+r)//2
  if tria(mid) < X:
    l = mid
  else:
    r = mid
    
print(r)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define rep(i, j, k) for (auto i = j; i < k; i++)
#define rrep(i, j, k) for (auto i = j; i > k; i--)
using namespace std;

void solve(int &n) {
  int a[30];
  char ch[101];
  fill(a, a + 30, 0);
  rep(i, 0, n) {
    char b; cin >> b;
    a[b - 'A']++;
    ch[i] = b;
  }
  char winner = 'a';
  int cnt = -1;
  rep(i, 0, 26) {
    if (cnt < a[i]) {
      cnt = a[i];
      winner = (char)('A' + i);
    } else if (cnt == a[i]) winner = 'a';
  }
  if (winner == 'a') {
    cout << "TIE" << endl;
    return;
  }
  int nokori = n - 1;
  int wincnt[30];
  fill(wincnt, wincnt + 30, 0);
  rep(i, 0, n) {
    wincnt[ch[i] - 'A']++;
    int nowmax = -1;
    rep(j, 0, 26) {
      if (j == (int)(winner - 'A')) continue;
      if (nowmax < wincnt[j]) nowmax = wincnt[j];
    }
    if (nowmax + nokori < wincnt[winner - 'A']) {
      cout << winner << " " << i + 1 << endl;
      return;
    }
    nokori--;
  }
}

int main() {
  int n;
  while (cin >> n, n) solve(n);
}



Measured memory_bytes: 3060
#template
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
lis = ['0']*N
time = [0]*N
for i in range(N):
    lis[i],time[i] = input().split()
sing = input()
index = -1
for i in range(N):
    if lis[i] == sing:
        index = i
        break
ans = 0
for i in range(index+1,N):
    ans += int(time[i])
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h> 
using namespace std ; 
#define ll long long int 
#define pb push_back
#define ff first 
#define dobara(i,a,b) for(int (i) = (a); (i) < (b); (i)++)
#define ss second 
#define S(x) scanf("%d",&x) 
#define SL(x) scanf("%lld",&x)
#define M 1000000007
#define sz(x) (int)x.size()
#define all(a) (a).begin(),(a).end()
#define N 2005 

ll dp[N][N] , n , k ;


int main(){
	ll ans = 0 ; 

	cin>>n>>k ; 
    //memset(dp , -1 , sizeof(dp)) ; 
    
    dp[1][0] = 1 , dp[1][1] = 1 ; 
    dp[0][0] = 1  ;
    for(int i=2;i<=n;i++){
    	dp[i][0] = 1 ;
    	for(int j=1;j<=i;j++){
    		dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1])%M ; 
    	}
    }

	for(int i=1;i<=k;i++){
		ll p = n - k + 1 ; 
		ans = dp[p][i] ; 
		ans = (ans*dp[k - 1][i - 1])%M ; 
		cout<<ans<<"\n" ;
	}
}

Measured memory_bytes: 30080
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N],b[N],c[N<<2],nex[N<<2];
int main() {
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int i=0;i<n;i++) scanf("%d",&b[i]);
	for(int i=0;i<n;i++) {
		c[i]=a[i]^a[(i+1)%n];
		c[i+n]=c[i+2*n]=b[i]^b[(i+1)%n];
	}
	nex[0]=c[n]=-1;
	int j=-1;
	for(int i=0;i<3*n;i++) {
		while(j>=0&&c[i]!=c[j]) j=nex[j];
		nex[i+1]=++j;
	}
	for(int i=0;i<n;i++) {
		if(nex[3*n-i]==n) {
			printf("%d %d\n",i,a[i]^b[0]);
		}
	}
	return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int a,b,c;
int main()
{
    cin>>a>>b>>c;
    cout<<max(a,max(b,c))-min(a,min(b,c));
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		String s[] = new String[H];
		for (int i=0;i<H;i++) {
			s[i] = sc.next();
		}
		for (int i=0;i<W+2;i++) {
			System.out.print("#");
		}
		System.out.println();
		for (int i=0;i<H;i++) {
			System.out.print("#");
			System.out.print(s[i]);
			System.out.println("#");
		}
		for (int i=0;i<W+2;i++) {
			System.out.print("#");
		}
	}
}

Measured memory_bytes: 37640
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  int n; cin >> n;
  vector<int> v(n);
  for(int i=0;i<n;++i)cin >> v[i];
  vector<int> vd;
  int prev=v[0];
  vd.push_back(v[0]);
  for(int i=1;i<n;++i){
    if(v[i]!=prev){
      vd.push_back(v[i]);
      prev = v[i];
    }
  }
  int cnt = 1;
  int grad = 0;
  for(int j=1;j<vd.size(); ++j){
    if(grad==0){
      if((vd[j] - vd[j-1]) > 0) grad =1;
      if((vd[j] - vd[j-1]) < 0) grad =-1;
    }
    if(grad*(vd[j] - vd[j-1]) < 0) {
      ++cnt;
      grad=0;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1276
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    string s;
    cin >> s;
    int cnt = 1;
    char tmp = s[0];
    for (int i = 1; i < s.size(); i++){
        if (s[i] == tmp) continue;
        else{
            tmp = s[i];
            cnt += 1;
        }
    }
    cout << cnt - 1 << endl;
    return 0;
}

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

int main(){
	string s;
  	cin >> s;
  	int n = s.size();
  	int k = 0;
  	char last = '0';
  	for(int i = 0; i < n; i++){
    	if(s[i] == last){
        	i++;
          	last = '0';
        }else{
            last = s[i];
            if(i == n-2 && s[i] == s[i+1])i++;
        }
        k++;
    }
    cout << k;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define cs(ans); cout<<setprecision(20)<<fixed<<ans<<endl;
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds; 
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw;pw = pw*pw;ex>>=1;}return ans;}
ll pwm(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
template<typename T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//st.order_of_key(num)->number of elements < num
//st.find_by_order(i)->iterator of ith element in sorted order starting from zero
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mkp make_pair
//#define int long long int
//Binary_Search->dp->greedy
//auto check = [&](ll x){};
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int X[]={2,1,-1,-2,-2,-1,1,2}; 
int Y[]={1,2,2,1,-1,-2,-2,-1}; 
struct comp{
	bool operator()(const pair<int,int>&a,const pair<int,int>&b) const {
		if(a.first>b.first) return true;
		if(a.first<b.first) return false; 
		if(a.second<b.second) return true;
		return false;
	}
};	
void solve(){
	
	int s,w;
	cin>>s>>w;
	if(s<=w) cout<<"unsafe"<<endl;
	else cout<<"safe"<<endl;
	
		
}
int32_t main(){
int t=1;
//scanf("%d",&t);
while(t--){
	solve();
}
return 0;
}    


Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 *
 * @author Milo
 */
class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt() {
            return Integer.parseInt(next());
        }
 
        long nextLong() {
            return Long.parseLong(next());
        }
 
        double nextDouble() {
            return Double.parseDouble(next());
        }
 
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    static FastReader in = new FastReader();
    public static void main(String[] args) {
        int t = 1; //in.nextInt();
        while (t-- > 0)
            solve();
    }
 
    public static void solve() {
        
        int N = in.nextInt();
        int M = in.nextInt();
        int t;
        long sum = 0;
        
        for(int i = 0; i < M; ++i){
            t = in.nextInt();
            sum += t;
        }
        if(sum > N){
            System.out.println("-1");
        }else{
            System.out.println((N-sum));
        }
    }
 
    public static int max(int a, int b) {
        return a > b ? a : b;
    }
 
    public static int min(int a, int b) {
        return a < b ? a : b;
    }
 
    public static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, (a % b));
    }
}


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

vector<int> l, r, balls;
int lp, rp;

bool search(int n){
	bool isl = false, isr = false;
	if( n==10 ) return true;
	if( balls[n] > l[lp] ){
		l[++lp] = balls[n];
		isl = search(n+1);
		lp--;
	}
	if( balls[n] > r[rp] && !isl ){
		r[++rp] = balls[n];
		isr = search(n+1);
		rp--;
	}
	return isl || isr;
}

int main(){
	int n;
	cin >> n;
	l.resize(10); r.resize(10);
	balls.resize(10);
	for( int i=0; i<n; i++ ){
		lp = rp = 0;
		for( int j=0; j<10; j++ ){
			int b;
			cin >> b;
			balls[j] = b;
		}
		cout << (search(0)?"YES":"NO") << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265359
int main(){
    string S;cin>>S;
    if(S=="MON"){
        cout<<6;
        return 0;
    }
    else if(S=="TUE"){
        cout<<5;return 0;
    }
    else if(S=="WED"){
        cout<<4;return 0;
    }
    else if(S=="THU"){
        cout<<3;return 0;
    }
    else if(S=="FRI"){
        cout<<2;return 0;
    }
    else if(S=="SAT"){
        cout<<1;return 0;
    }
    else{
        cout<<7;return 0;
    }
    return 0;
}

Measured memory_bytes: 256