akhauriyash/Code-Regression huggingface dataset:
m, k = input().split()
m, k = int(m), int(k)


xx = 0
for i in range(2**m):
    xx = xx ^ i

if k == 0:
    arr = [0] * (2 ** (m+1))
    for i in range(2**m):
        arr[2*i] = i
        arr[2*i+1] = i
    print(" ".join([str(x) for x in arr]))
elif xx != 0 or k >= 2 ** m:
    print(-1)
else:
    arr = [0] * (2 ** (m+1))
    f = (2 ** (m+1))
    arr[0] = k
    arr[f//2] = k
    pt1 = f // 2 - 1
    pt2 = f // 2 + 1
    curr = 0
    for i in range((f - 2) // 2):
        if (curr == k):
            curr += 1
        arr[pt1] = curr
        arr[pt2] = curr
        pt1 -= 1
        pt2 += 1 
        curr += 1
    print(" ".join([str(x) for x in arr]))


Measured memory_bytes: 27544
#!/usr/bin/env pytHon3
# -*- coding: utf-8 -*-

from collections import Counter


def main():
    N = int(input())

    c = Counter(input())

    for _ in range(1, N):
        cx = Counter(input())

        for k, v in c.items():
            c[k] = min(v, cx[k])

    result = []
    for k, v in c.items():
        result += [k] * v

    result.sort()
    print("".join(result))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include<stdio.h>
#include<string.h>
 
int main(){
  char buf[1001];
  int	len = 0;
  
  	memset(buf, 0x00, sizeof(buf));
  
  	scanf("%s", buf);
  
  	len = strlen(buf);
  
  	if (buf[len-1] == 's' ) {
      printf("%ses", buf);
    } else {
      printf("%ss", buf);
    }
  
 	return 0; 
}

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf

#define sf(n) scanf("%d",&n)
#define sff(n1,n2) scanf("%d %d",&n1,&n2)
#define sfff(n1,n2,n3) scanf("%d %d %d",&n1,&n2,&n3)
#define sl(n) scanf("%lld",&n)
#define sll(n1,n2) scanf("%lld %lld",&n1,&n2)
#define slll(n1,n2,n3) scanf("%lld %lld %lld",&n1,&n2,&n3)

#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define sz(x) x.size()

#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))

#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >

#define endl "\n";
#define line puts("-------");
#define dbb(x) cout<<#x<<" : "<<x<<"\n";

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

template<typename T, typename V> void __print(const pair<T, V> &x)
{cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T> void __print(const queue<T> &x)
{queue<T>temp=x;cerr<<"\n-----\n";while(!temp.empty())
{cerr << temp.front() << endl;temp.pop();}cerr<<"-----\n";}
template<typename T> void __print(const stack<T> &x)
{stack<T>temp=x;cerr<<"\n-----\n";while(!temp.empty())
{cerr << temp.top() << endl;temp.pop();}cerr<<"-----\n";}
template<typename T> void __print(const T &x)
{int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V> void _print(T t, V... v)
{__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
    #define db(x...) cerr << "[" << #x << "] = [", _print(x)
#endif
using ll = long long;
const int N = 100005;
const int MOD = 1000000007;

int main()
{
    #ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt","w",stdout);
    #endif
    int i,j,n,x,k;
    unordered_map<int,bool>mp;
    sff(x,n);
    rep0(i,n)
    {
        sf(k);
        mp[k]=true;
    }
    i=x,j=x;
    while(mp[i])
        i--;
    while(mp[j])
        j++;
    if(abs(x-i)>abs(x-j))
        cout<<j;
    else
        cout<<i;

}


Measured memory_bytes: 3708
#include<iostream>
#include<vector>
#include<string>
#define REP(i, j) for(int (i)=0; (i)<(j); ++(i))
using namespace std;

vector<string> strs = {"dream", "dreamer", "erase", "eraser"};

void cutString(string &s){
  for(string str : strs){
    if(s.length() < str.length()) continue;
    if(s.substr(s.length() - str.length()) == str){
      s = s.substr(0, s.length() - str.length());
      return ;
    }
  }
  s = "-1";
}

int main(){
  string s; cin >>s;
  while(s != "" && s != "-1") cutString(s);
  if(s == "") cout <<"YES" <<endl;
  else cout <<"NO" <<endl;
  return 0;
}


Measured memory_bytes: 540
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int X;
int main(void){
    cin >> X;
    if (X <= 599) cout << 8 << endl;
    else if (X <= 799) cout << 7 << endl;
    else if (X <= 999) cout << 6 << endl;
    else if (X <= 1199) cout << 5 << endl;
    else if (X <= 1399) cout << 4 << endl;
    else if (X <= 1599) cout << 3 << endl;
    else if (X <= 1799) cout << 2 << endl;
    else if (X <= 1999) cout << 1 << endl;
    return 0;
}



Measured memory_bytes: 3632
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

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

const int MAXN = 63;

int num[MAXN];

int main(){
	int N =0;
	scanf("%d",&N);
	int tot = 0;
	memset(num,0,sizeof(num));
	if(N!=0){
	while(N!=0){
		if(N%2!=0){
			num[tot++] = 1;
			N = (N-1)/(-2);
		}else{
			num[tot++] = 0;
			N = N/(-2);
		}
		//printf("%d %d\n",N,tot);
	}
	for(int i=tot-1;i>=0;i--){
		printf("%d",num[i]);
	}
	printf("\n");
	}else{
		printf("0\n");
	}	
	return 0;
}


Measured memory_bytes: 256
/*
             much pretests
        ▄              ▄    
        ▌▒█           ▄▀▒▌   wow vectors
        ▌▒▒█        ▄▀▒▒▒▐   
       ▐▄█▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒▐        heckin_TLE
     ▄▄▀▒▒▒▒▒▒▒▒▒▒▒█▒▒▄█▒▐   
   ▄▀▒▒▒░░░▒▒▒░░░▒▒▒▀██▀▒▌   
  ▐▒▒▒▄▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀▄▒▌      beautiful graphs
  ▌░░▌█▀▒▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒▐  
 ▐░░░▒▒▒▒▒▒▒▒▌██▀▒▒░░░▒▒▒▀▄▌ 
 ▌░▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░▒▒▒▒▌  wow cp
▌▒▒▒▄██▄▒▒▒▒▒▒▒▒░░░░░░░░▒▒▒▐ 
▐▒▒▐▄█▄█▌▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▒▒▒▌        much time
▐▒▒▐▀▐▀▒▒▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▒▐ 
 ▌▒▒▀▄▄▄▄▄▄▀▒▒▒▒▒▒▒░▒░▒░▒▒▒▌     very memory
 ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒░▒▒▄▒▒▐  
  ▀▄▒▒▒▒▒▒▒▒▒▒▒▒▒░▒░▒▄▒▒▒▒▌  
    ▀▄▒▒▒▒▒▒▒▒▒▒▄▄▄▀▒▒▒▒▄▀   much loops
      ▀▄▄▄▄▄▄▀▀▀▒▒▒▒▒▄▄▀     
         ▀▀▀▀▀▀▀▀▀▀▀▀     
         bugs do me a bamboozle
*/

#include<bits/stdc++.h>
#define int 			long long
#define fi 				first
#define sc 				second
#define pii 			pair<int,int>
#define vi 				vector<int>
#define mii 			map<int,int>
#define msi 			map<string,int>
#define si 				set<int>
#define mlem			main
#define all(v) 			v.begin(),v.end()
#define sz(v)  			int((v).size())
#define rep(i,a,b)    	for(int i=a;i<b;i++)
#define dep(i,a,b)    	for(int i=a;i>=b;i--)
#define isinarr(i,n) 	((i>=0)?((i<n)?1:0):0)
#define pb 				push_back
#define ppb 			pop_back
#define lb 				lower_bound
#define ub 				upper_bound
#define hell 			1000000007
#define PI 				3.14159265
#define mp 				make_pair
#define inparr(a,n) 	rep(i,0,n)cin>>a[i];
#define strwspaces(s) 	getline(cin,s)
#define give(x,y) 		cout<<x<<" "<<y<<endl;
#define setp(n) 		cout<<fixed<<setprecision(n);
#define endl   			'\n'
#define inp(n) 			int n;cin>>n;
#define inps(s) 		string s;cin>>s;
#define setmem(inde,k) 	memset(inde,k,sizeof(inde))
#define tr(a,m) 		for(auto a=m.begin();a!=m.end();a++)
using namespace std;

int i,j,k,l;

void woof()
{
	inp(n);
	int cnt=0,ans=0;
	rep(i,0,n)
	{
		cin>>j>>k;
		if(j==k)
			cnt++;
		else
			cnt=0;
		ans=max(ans,cnt);
	}
	if(ans>=3)
		cout<<"Yes\n";
	else
		cout<<"No\n";
} 



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

Measured memory_bytes: 3648
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		String S = sc.next();

		//zyunbi
		int temp=0;
		int now=1;
		List<Integer> list = new ArrayList<Integer>();
		for (int i=0;i<N;i++) {
			if (S.charAt(i)-48==0+now) {
				temp++;
			} else {
				list.add(temp);
				now=1-now;
				temp=1;
			}
		}
		if (temp!=0) {
			list.add(temp);
		}
		if (list.size()%2==0) {
			list.add(0);
		}

		//ruiseki
		List<Integer> R = new ArrayList<Integer>();
		int X=0;
		R.add(0);
		for (int i=0;i<list.size();i++) {
			X=list.get(i)+R.get(i);
			R.add(X);
		}

		int add=2*K+1;
		int left;
		int right;
		int temp_A;
		int max=0;
		for (int i=0;i<R.size();i+=2) {
			left=i;
			right=Math.min(left+add,R.size()-1);
			temp_A=R.get(right)-R.get(left);
			max=Math.max(max,temp_A);
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 30092
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main() {
  ll n, t, ans = 0, s1, s2;
  cin >> n >> t;
  cin >> s1;
  for (int i = 0; i < n - 1; i++) {
    cin >> s2;
    if (s2 - s1 > t)
      ans += t;
    else {
      ans += s2 - s1;
    }
    s1 = s2;
  }
  ans += t;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define double long double
#define x first
#define y second
#define long long long
#define int long 



           //       |----|       /\      |    |   -----   |
           //       |   /       /  \     |    |     |     |
           //       |--/       /----\    |----|     |     |
           //       |   \     /      \   |    |     |     |
           //       |    \   /        \  |    |   -----   -------

int n,w;
int arr[102][3];
int cache[102][100005];
int dp(int i,int weight)
{
	if(weight>w)
		return (-(int)pow(10,18));
	if(i==n)
		return 0;
	if(cache[i][weight]!=-1)
		return cache[i][weight];
	return cache[i][weight]=max(arr[i][1]+dp(i+1,weight+arr[i][0]),dp(i+1,weight));
}
int32_t main()
{
    IOS
    cin>>n>>w;
    for(int i=0;i<n;i++)for(int j=0;j<2;j++)cin>>arr[i][j];
    	memset(cache,-1,sizeof(cache));
    cout<<dp(0,0);
}

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

typedef long long int ll;
typedef pair<int,int> pi;
priority_queue<pi, vector<pi>, greater<pi> > pq; //min heap

#define dodebug(i, n, arr)	for(int i=0;i<n;++i)	cout<<arr[i]<<" ("<<i<<")\n";

ll gcd(ll a,ll b){	if(b == 0)	return a;return gcd(b,a%b);}
ll binpow(ll n,ll x){	ll ans = 1;while(x){if(x & 1)	ans *= n;n *= n;x >>= 1;}return ans;}

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

	int n;
	cin>>n;
	vector<int> h(n);
	for(int i=0;i<n;++i)	cin>>h[i];
	vector<int> dp(n+1, 0);

	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for(int i=2;i<n;++i){
		dp[i] = min(dp[i-2] + abs(h[i-2] - h[i]), dp[i-1] + abs(h[i-1] - h[i]));
	}
	// for(auto i:dp)	cout<<i<<" ";
	cout<<dp[n-1]<<"\n";
	
	return 0;
}

Measured memory_bytes: 3852
s = input()
l = []
for i in range(3):
  l += s[i]
for i in range(3):
  if l[i] == '1':
    l[i] = '9'
  elif l[i] == '9':
    l[i] = '1'
print(l[0] + l[1] + l[2])

Measured memory_bytes: 9112
def search(i, bit):
  global ans
  if i<0 or i>=N:
    return;
  else:
    bit |= (1<<i)
  if bit == (1<<N)-1:
    ans += 1
    return
  else:
    for j in A[i]:
      if bit&(1<<j) == 0:
        search(j, bit)
    return
        

N, M = map(int, input().split())
A= [[] for _ in range(N)]
for _ in range(M):
  a, b = map(int, input().split())
  a-=1
  b-=1
  A[a].append(b)
  A[b].append(a)
  
ans = 0

search(0, 0)

print(ans)

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

using namespace std;

int main()
{
	int N;
	long long K;
	cin >> N >> K;
	vector<long long> A(N);

	for (auto &x : A) {
		cin >> x;
	}

	long long X = 0;
	for (int s = 50; s >= 0; --s) {
		int n1 = 0;
		for (int i = 0; i < N; ++i) {
			if (A[i] & (1LL << s)) {
				++n1;
			}
		}

		if (2 * n1 < N) {
			if (X + (1LL << s) <= K) {
				X += 1LL << s;
			}
		}
	}

	long long ans = 0;
	for (int i = 0; i < N; ++i) {
		ans += X ^ A[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
#define chmax(x,y) (x = max(x, y))
void solve(); int main() { solve(); return 0; }

void solve() {
  int a, b, h; cin >> a >> b >> h;
  cout << (a+b)*h/2 << endl;
}


Measured memory_bytes: 3556
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
#include <map>
using namespace std;

typedef long long ll;

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}


int main() {
  ll n, T;
  cin >> n >> T;
  ll bef = -T-1;
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ll t;
    cin >> t;
    if (t-bef <= T) {
      ans += t-bef;
    }
    else {
      ans += T;
    }
    bef = t;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Deque;
import java.util.ArrayDeque;
import java.util.LinkedList;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> a = new ArrayList<>();
        for(int i = 0;i < n;i++){
            a.add(sc.nextInt());
        }
        LinkedList<Integer> b = setList(a,n);
        for(Integer it : b){
            System.out.print(it);
            System.out.print(" ");
        }
        System.out.println();
    }
    public static LinkedList<Integer> setList(List<Integer> a,int n){
        LinkedList<Integer> b = new LinkedList<>();
        int parity = n % 2;
        for(int i = 1;i <= n;i++){
            if(i % 2 == parity){
                b.addFirst(a.get(i-1));
            }
            else if(i % 2 != parity){
                b.addLast(a.get(i-1));
            }
        }
        return b;
    }
}


Measured memory_bytes: 101468
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define GYOU_MAX 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PRINT(str) printf(#str "\n")
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define pi acos(-1.0)
#define v_pri(val) printf("%d\n",val);
#define s_pri(str) printf("%s\n",str);
#define v_sca(x) scanf("%d",&x);
#define s_sca(x) scanf("%s",x);

typedef long long int ll;


/*
puts("コメント");
//*/

int main(void) {

	char a;
	scanf("%c", &a);
	printf("%c", a + 1);

	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<algorithm>
int dp[10000];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%d",dp+i);
		std::sort(dp,dp+a);
		long long int ans=0;
		for(int i=0;i<a;i++){
			ans+=dp[i]*(a-1-i);
		}
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
long long n,ans;
int main()
{
	cin>>n;
	if(n%2==1)
	printf("0");
	else
	{
		ans+=n/10;
		n/=10;
		while(n)
		{
			ans+=n/5;
			n/=5;
		}
		printf("%lld",ans);
	}
	return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize, mut a: u64, mut b: u64, mut c: u64,
        mut q: [String; n],
    }
    q.push(String::from(""));
    let mut ans = vec![];
    for i in 0..n {
        match &q[i][..] {
            "AB" => {
                if a > 1 || (a, b) == (1, 0) {
                    a -= 1;
                    b += 1;
                    ans.push("B");
                } else if b > 1 || (a, b) == (0, 1) {
                    a += 1;
                    b -= 1;
                    ans.push("A");
                } else if (a, b) == (0, 0) {
                    println!("No");
                    return;
                } else {
                    if q[i + 1] == "AC" {
                        a += 1;
                        b -= 1;
                        ans.push("A");
                    } else {
                        a -= 1;
                        b += 1;
                        ans.push("B");
                    }
                }
            }
            "AC" => {
                if a > 1 || (a, c) == (1, 0) {
                    a -= 1;
                    c += 1;
                    ans.push("C");
                } else if c > 1 || (a, c) == (0, 1) {
                    a += 1;
                    c -= 1;
                    ans.push("A");
                } else if (a, c) == (0, 0) {
                    println!("No");
                    return;
                } else {
                    if q[i + 1] == "AB" {
                        a += 1;
                        c -= 1;
                        ans.push("A");
                    } else {
                        a -= 1;
                        c += 1;
                        ans.push("C");
                    }
                }
            }
            "BC" => {
                if b > 1 || (b, c) == (1, 0) {
                    b -= 1;
                    c += 1;
                    ans.push("C");
                } else if c > 1 || (b, c) == (0, 1) {
                    b += 1;
                    c -= 1;
                    ans.push("B");
                } else if (b, c) == (0, 0) {
                    println!("No");
                    return;
                } else {
                    if q[i + 1] == "AB" {
                        b += 1;
                        c -= 1;
                        ans.push("B");
                    } else {
                        b -= 1;
                        c += 1;
                        ans.push("C");
                    }
                }
            }
            _ => (),
        }
    }
    println!("Yes");
    for s in ans.iter() {
        println!("{}", s);
    }
}


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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  
  if (A + B + C > 21){
   cout << "bust" << endl;
  }
  else{
   cout << "win" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 300005
struct node {
    int val,x,id;
};
int n,m;
long long L[maxn];
long long R[maxn];
int cnt[maxn+10];
long long tree[maxn+10];
node p[maxn];
bool cmp(node x,node y) {
    return x.val<y.val;
}
bool cmp2(node x,node y) {
    return x.id<y.id;
}
void cpidx() {
    int i;
    sort(&p[1],&p[3*n+1],cmp);
    for(i=1;i<=3*n;i++) p[i].x = i;
    sort(&p[1],&p[3*n+1],cmp2);
}
void add(int x,int val1,int val2,int type) {
    while(x>0 && x<=maxn)
    {
        cnt[x] += val1;
        tree[x] += val2;
        x += (x&-x)*type;
    }
}
pair<int,long long> sum(int x,int type) {
    int now = 0;
    long long ans = 0;
    while(x>0 && x<=maxn)
    {
        now += cnt[x];
        ans += tree[x];
        x += (x&-x)*type;
    }
    return {now,ans};
}
main()
{
    int i,l,r,mid;
    long long ans;
    scanf("%d",&n);
    for(i=1;i<=3*n;i++) scanf("%d",&p[i].val), p[i].id = i;
    cpidx();
    //Max of Prefix
    memset(cnt,0,sizeof(cnt));
    memset(tree,0,sizeof(tree));
    for(i=1;i<=3*n;i++)
    {
        add(p[i].x,1,p[i].val,-1);
        l = 1; r = 3*n;
        while(l<=r)
        {
            mid = (l+r)/2;
            if(sum(mid,1).first >= n)
            {
                L[i] = sum(mid,1).second;
                l = mid+1;
            }
            else r = mid-1;
        }
    }
    //Min of Suffix
    memset(cnt,0,sizeof(cnt));
    memset(tree,0,sizeof(tree));
    for(i=3*n;i>=1;i--)
    {
        add(p[i].x,1,p[i].val,1);
        l = 1; r = 3*n;
        while(l<=r)
        {
            mid = (l+r)/2;
            if(sum(mid,-1).first >= n)
            {
                R[i] = sum(mid,-1).second;
                r = mid-1;
            }
            else l = mid+1;
        }
    }
    ans = -(long long)1e18;
    for(i=n;i<=2*n;i++) ans = max(ans,L[i]-R[i+1]);
    printf("%lld",ans);
}


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


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()


using namespace std;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
using ll  = long long;

using point = complex<double>;


void err(istream_iterator<string> it) {cerr << endl;}
template<typename T, typename... Args>void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " = " << a << endl;err(++it, args...);}


const double EPS = 1e-8;
const long long mod = 1e9 + 7;

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

const int N = 1e5 + 5;


ll l ,r ;
int m = 2019;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> l >> r;
    int ans = 2018;
    for(int i = l,rep = 0; i <= r && rep < 2019; ++i,++rep){
            int x = i % m,y;
            for(int j = i + 1,rep1 = 0; j <= r && rep1 < 2019; ++j, ++rep1){
                y = j % m;
                ans = min(ans,(x*y)%m);
            }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;
 
 
class Main
{
    public static void main(String[] args)
    {
        int ans = 0;
        int count = 0;
        int s[] = new int[100000000];
        
        Scanner scanner = new Scanner(System.in);
        int d = scanner.nextInt();
        for(int i = 0; i< d; i++){
            s[i] = scanner.nextInt();
        }

        for(int j = 0; j< d ;j++){
            ans = s[j];
            while(ans % 2 ==0){
                count++;
                ans = ans/2;
            }      
        }
        System.out.println(count);
        scanner.close();
    }
}

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

int main()
{
string s;
cin>>s;
if(s[s.size()-1]=='s')
cout<<s<<"es"<<endl;
else
cout<<s<<"s"<<endl;
return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  ll n;
  cin >> n;

  vld p(n + 1);
  REP(i, n + 1) {
    cin >> p[i];
  }

  vvld dp(n + 2, vld(n + 2));
  dp[0][0] = 1;
  REP(i, n + 1) {
    rep(j, i + 1) {
      if (j > 0)
        dp[i][j] += dp[i - 1][j - 1] * p[i];
      dp[i][j] += dp[i - 1][j] * (1 - p[i]);
    }
  }

  ld ans = 0;
  FOR(i, (n + 1) / 2, n + 1) {
    ans += dp[n][i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 141184
/**
 * @author: Jenniekim
 * @date  : 02-21-2019
 **/
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define el '\n'
#define MOD 1000000007

int n;

int arr[100005][3], dp[100005][3];
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
    }

    dp[1][0]=arr[1][0];
    dp[1][1]=arr[1][1];
    dp[1][2]=arr[1][2];

    for(int i=2;i<=n;i++){
        for(int j=0;j<3;j++){
            switch(j){
                case 0:
                    dp[i][j] = arr[i][j]+max(dp[i-1][1], dp[i-1][2]);
                    break;
                case 1:
                    dp[i][j] = arr[i][j]+max(dp[i-1][0], dp[i-1][2]);
                    break;      
                case 2:
                    dp[i][j] = arr[i][j]+max(dp[i-1][1], dp[i-1][0]);
                    break;             
            }
        }
    }

    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << el;
 
    return 0;
}

Measured memory_bytes: 2560
import heapq

N, M = map(int, input().split())
A = list(map(lambda x : int(x)*(-1), input().split()))
heapq.heapify(A)

for _ in range(M):
    t = heapq.heappop(A)
    heapq.heappush(A, (-1)*(-t//2))

print(-sum(A))


Measured memory_bytes: 14380
#include <bits/stdc++.h>
 
using namespace std;
using ll=long long;
 
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cll ll t;cin>>t;while(t--)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pii pair<int,int>
#define vint vector<int>
 
ll mod=1e9+7;
 
int main(){
    faster;
 
    int m,n;
    cin>>m>>n;
 
    if(n==m) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main(){
  int n, q;
  cin >> n >> q;
  ll a[n];
  vector<ll> sum(n+1,0);
  vector<ll> odd(n+1,0);
  vector<ll> even(n+1,0);
  rep(i,n) {
    cin >> a[i];
    sum[i+1] = sum[i] + a[i];
    if(i % 2) {
      odd[i+1] = odd[i];
      even[i+1] = even[i] + a[i];
    } else {
      odd[i+1] = odd[i] + a[i];
      even[i+1] = even[i];
    }
  }
  vector<ll> v((n+1)/2,0);
  for(int i = 1; i <= (n+1)/2; i++) {
    v[i-1] = a[n-i] + a[n-2*i+1]; 
  }
  reverse(v.begin(),v.end());
  vector<ll> ans(q,0);
  rep(i,q) {
    ll x;
    cin >> x;
    int c = lower_bound(v.begin(),v.end(),2*x) - v.begin();
    c = (n+1)/2 - c;
    ans[i] += sum[n] - sum[n-c];
    if(n % 2 && n-2*c >= 0) ans[i] += odd[n-2*c];
    else if(n % 2 == 0) ans[i] += even[n-2*c];
  }
  for(auto k : ans) cout << k << endl;
  return 0;
}

Measured memory_bytes: 6016
#n,m = map(int,input().split())
h = int(input())
w = int(input())
n = int(input())

max_a = max(h,w)
#print(max_a)
ans = 1
for i in range(min(h,w)):
    n = n - max_a
    if n <=0:
        print(ans)
        exit()
    ans += 1
print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
using lli=long long int;
using vi=vector<int>;  using vs=vector<string>; using gi=greater<int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define soao(c) sort((c).begin(),(c).end()) //昇順
#define sodo(c) sort((c).begin(),(c).end(),gi()) //降順
#define rev(c) reverse((c).begin(), (c).end())


int main(){
    string S; cin>>S;
    if(S.at(1)=='B') cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl; 
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

ll g(ll a,ll b){
  if (b) return g(b,a%b);
  return a;
}

int main(){
  ll k;
  ll ans=0;
  string s;
  cin >> k;
  for (ll i=1;i <= k;i++){
    for (ll j=1;j <=k;j++){
      for (ll h=1; h <= k;h++){
        //cout << g(i,g(j,k)) << endl;
        ans+=g(i,g(j,h));
      }
    }
  }
  //cout << g(2,g(2,2)) << endl;
  cout << ans << endl;
  return 0;
}

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

#define SPD 0
#define HP 1
#define ATK 2
#define DEF 3
#define IDX 4

bool cmp(array<long long,2> a,array<long long,2> b){
	return a[0] * b[1] < a[1] * b[0];
}
int main(){
	int N;
	while( cin >> N && N ){
		N = N+1;
		vector< array<long long,5> > v(N);
		for(int i = 0 ; i < N; i++){
			cin >> v[i][HP] >> v[i][ATK] >> v[i][DEF] >> v[i][SPD];
			v[i][IDX] = i;
			v[i][SPD] *= -1;
		}
		long long fstHp = v[0][HP];
		sort(v.begin(),v.end());
		int my = -1;
		rep(i,N) if( v[i][IDX] == 0 ){ my = i;  break; }
		rep(i,my) v[my][HP] -= max(0ll,v[i][ATK]-v[my][DEF]);
		vector< array<long long,2> > kill;
		
		int error = 0;
		rep(i,N) if( i != my ){
			long long d = max(0ll,v[my][ATK]-v[i][DEF]);
			long long w = max(0ll,v[i][ATK]-v[my][DEF]);
			//cout << w << " " << d << endl;
			if( w == 0 ) continue;
			if( d == 0 ){ error = 1; break; }
			kill.push_back(array<long long,2>{w,(v[i][HP]+d-1)/d});
		}
		sort( kill.rbegin(), kill.rend(),cmp );
		//(a+c)b+c(b+d) < (a+c)d+a(b+d)
		//a*b+c*b+c*d < c*d+a*b+a*d
		//cb < ad
		//
		long long tot = 0;
		rep(i,kill.size()) tot += kill[i][0];
		rep(i,kill.size()){
			//cout << kill[i][0] << " " << kill[i][1] << endl;
			if( 1.*v[my][HP]-1.*tot*kill[i][1] <= -1 ){ error = 1; break; }
			v[my][HP] -= tot * kill[i][1] - kill[i][0];
			if( v[my][HP] < 0 ){ error = 1; break; }
			tot -= kill[i][0];
		}
		if(error){ cout << -1 << endl; continue; }
		else cout << fstHp - v[my][HP] << endl;
		
	}
}

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

int N, M;
vector<vector<int> > adj;

int main() {
    scanf("%d %d", &N, &M);
    adj.resize(N);
    for(int i = 0; i < M; i++) {
        int u, v; scanf("%d %d", &u, &v);
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i = 0; i < N; i++) {
        if(adj[i].size() % 2) {
            printf("NO");
            return 0;
        }
    }
    printf("YES");
}


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

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

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

int main(){
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  if(N < K) cout << N*X << endl;
  else cout << K*X + (N-K)*Y << endl;
}


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

using namespace std;

int N;
int r[9];
int a[100];

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> a[i];
    for(int i=0;i<9;i++) r[i] = 0;
    for(int i=0;i<N;i++){
        int b = a[i] / 400;
        if(b >= 9) b = 8;
        r[b]++;
    }
    int count = 0;
    for(int i=0;i<8;i++){
        if(r[i] != 0){
            count++;
        }
    }
    if(count == 0){
        cout << 1 << " " << r[8] << endl;
        return 0;
    }
    cout << count << " " << count+r[8] << endl;
    return 0;
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    string s;
    
    irep(i, 3) {
        string t;
        cin >> t;
        s.push_back(toupper(t.front()));
    }
    cout << s;
    return 0;
}   
/** atcoder **/


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

int main()
{
  string S;
  cin >> S;

  bool bad = false;

  for (int i = 0; i < S.size() - 1; i++)
  {
    if (S.at(i) == S.at(i + 1))
    {
      bad = true;
      break;
    }
  }
  if (bad)
    cout << "Bad" << endl;
  else
    cout << "Good" << endl;
  return 0;
};


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

int main()
{
	int A,B,C,D;
	cin >> A >> B >> C >> D;
	int l = A + B;
	int r = C + D;
	if(l > r) cout << "Left";
	else if(l == r) cout << "Balanced";
	else cout << "Right";
	return 0;
}


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

main(){
    string line;
    while( getline( cin, line) ){
	string str = line;
	for ( int i = 0; i <= line.size()-5; i++ ){
	    if ( line.substr(i, 5) == "apple" ){
		str.replace(i, 5, "peach");
	    }
	    if ( line.substr(i, 5) == "peach" ){
		str.replace(i, 5, "apple");
	    }
	}
	cout << str << endl;
    }
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  string abcd;
  cin >> abcd;
  for (int tmp = (1 << 6) - 1; tmp >= 0; tmp--) {
    bitset<6> s(tmp);
    int sum = 0;
    int last_plus_minus = -1;
    bool if_break = 0;
    for (int i = 0; i < 3; i++) {
      if (s.test(i)) {
        if (s.test(i + 3)) {
          if_break = !if_break;
          break;
        }
        sum += stoi(abcd.substr(3 - i, i - last_plus_minus));
        last_plus_minus = i;
      } else {
        if (s.test(i + 3)) {
          sum -= stoi(abcd.substr(3 - i, i - last_plus_minus));
          last_plus_minus = i;
        }
      }
    }
    if (if_break) {
      continue;
    }
    sum += stoi(abcd.substr(0, 3 - last_plus_minus));
    if (sum == 7) {
      for (int i = 0; i < 3; i++) {
        cout << abcd[i];
        if (s.test(2 - i)) {
          cout << '+';
        } else if (s.test(5 - i)) {
          cout << '-';
        }
      }
      cout << abcd[3] << "=7" << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		while(true) {
			int n = in.nextInt();
			if(n==0) return;
			int sum = 0;
			int[] darr = new int[n];
			for (int i = 0; i < n; i++) {
				darr[i] = in.nextInt();
				sum += darr[i];
			}
			double m = (double)sum / n;
			double bunsan = 0.0;
			for(int i=0;i<n;i++) {
				bunsan += Math.pow(darr[i] - m, 2.0);
			}
			bunsan /= n;
			System.out.println(Math.sqrt(bunsan));
		}
	}
}

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

int main(){
   int a,b;
   cin >> a >> b;
   if(a==1) a=14;
   if(b==1) b=14;
   if(a==b) cout << "Draw" << endl;
   else if(a>b) cout << "Alice" << endl;
   else cout << "Bob" << endl;
   return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

N = INT()
S = [input() for i in range(N)]

C = Counter(S)
print('AC x {0}'.format(C['AC']))
print('WA x {0}'.format(C['WA']))
print('TLE x {0}'.format(C['TLE']))
print('RE x {0}'.format(C['RE']))


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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

signed main() {
	int n, ans = 0;
	cin >> n;
	int a[114514];
	rep(i, n) {
		cin >> a[i];
	}
	bool up = true, down = true;
	for (int i = 1; i < n; i++) {
		if (a[i - 1] < a[i]) {
			if (!up) {
				ans++;
				up = true;
				down = true;
			}
			else {
				down = false;
			}
		}
		else if (a[i - 1] > a[i]) {
			if (!down) {
				ans++;
				up = true, down = true;
			}
			else {
				up = false;
			}
		}
	}
	cout << ans + 1 << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iomanip>
#include <time.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <queue>
#include <vector>
#define mod 1000000007
#define ll long long
#define pi acos(-1)
using namespace std;

int main(){
	ios::sync_with_stdio(0);	
	string s1,s2;
	cin>>s1>>s2;
	for(int i = 0; i < s1.size(); i++){
		if(s1[i]!=s2[i]){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	
    return 0; 
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void)
{
	int n ,ai ,i ,max ,min;
	
	long long int sum = 0;
	
	scanf("%d" ,&n);
	
	for(i=0;i<n;i++){
		
		scanf("%d" ,&ai);
		
		sum += ai;
		
		if(i==0){
			
			max = ai;
                        min = ai;


		}
		
		else if(ai>max){
			
			max = ai;
		
		}
		
		else if(ai<min){
			
			min = ai;
			
		}

          }
		
		printf("%d %d %lld\n" ,min ,max ,sum);
		
		return 0;
		
	}
		
	

Measured memory_bytes: 600
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
    int N;
    cin>>N;
    int ans;
    if(N%2==0)ans=N/2;
    else ans=N/2+1;
    p(ans);


}

Measured memory_bytes: 256
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
string to_string(char c) { return string(1,c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return (string)s; }
string to_string(string s) { return s; }
template<class A> string to_string(complex<A> c) { 
	stringstream ss; ss << c; return ss.str(); }
string to_string(vector<bool> v) { 
	string res = "{"; for(int i = 0; i < (int)v.size(); i++) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> string to_string(bitset<SZ> b) {
	string res = ""; for(size_t i = 0; i < SZ; i++) res += char('0'+b[i]);
	return res; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) { // containers with begin(), end()
	bool fst = 1; string res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += to_string(x);
	}
	res += "}"; return res;
}
template<class A, class B> string to_string(pair<A,B> p) {
	return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define wis(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
#else
#define wis(...) 0
#endif
typedef long long ll;
const int MOD = 1e9 + 7, INF = 1e9 + 5;
const ll LONG_INF = 1e18 + 10;
inline ll powmod(ll a, ll b){ll res=1;for(;b;b>>=1,a=a*a%MOD)if(b&1)res=res*a%MOD;return res;}
inline ll power(ll a, ll b){ll res=1;for(;b;b>>=1,a=a*a)if(b&1)res=res*a;return res;}

const int MAXN = 2e5 + 10;

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, k;
        cin >> n >> k;
        vector <int> c(n), p(n);
        for(int& i : p){
                cin >> i;
                i--;
        }
        for(int& i : c)
                cin >> i;
        ll ans = -LONG_INF;
        for(int i = 0; i < n; i++){
                ll tans = 0;
                int cnt = 0;
                vector <bool> mark(n);
                vector <ll> get;
                int cur = i;
                while(!mark[cur]){
                        tans += c[p[cur]];
                        mark[cur] = 1;
                        cur = p[cur];
                        cnt++;
                        if(k >= cnt)
                                ans = max(ans, tans);
                        get.push_back(tans);
                }
				if(k % cnt == 0){
					ans = max(ans, (k - 1) / cnt * tans + max(-LONG_INF,*max_element(get.begin(), get.end())));
				}
				else{
                	ans = max(ans, k / cnt * tans + (k % cnt == 0 ? 0 : *max_element(get.begin(), get.begin() + (k % cnt))));
				}
        }
        cout << ans << '\n';
}


Measured memory_bytes: 3812
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Ans[2] = {"No", "Yes"};
string ANS[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    cout << n / 3;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int N=110000;
int c[2], p[2][N], s[N], q;
vi adj[N];

void dfs(int x) {
    s[x]=1;
    p[q][c[q]++]=x;
    for(int y:adj[x]) if(!s[y]) {
        dfs(y);
        break;
    }
}

int main() {
    int i, n, m, u, v;
    scanf("%d%d", &n, &m);
    while(m--) {
        scanf("%d%d", &u, &v);
        adj[u].pb(v);
        adj[v].pb(u);
    }
    q=0; dfs(1);
    q=1; dfs(1);
    printf("%d\n", c[0]+c[1]-1);
    for(i=c[1]-1; i>=0; i--)
        printf("%d ", p[1][i]);
    for(i=1; i<c[0]; i++)
        printf(i==c[0]-1? "%d\n":"%d ", p[0][i]);
    return 0;
}

Measured memory_bytes: 7296