akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
    int n,r;
    cin >> n >> r;
    if(n >= 10){
        cout << r;
    } else if(n < 10){
        int l = 100 * (10 - n);
        cout << r + l;
    }
    
    return 0;
}

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

int mod = 1000000007;
int n, k;
int a[200000];
vector<int> sei;
vector<int> fu;

signed main() {
  int i;

  cin >> n >> k;
  rep(i, n) {
    cin >> a[i];
    if (a[i] >= 0)
      sei.push_back(a[i]);
    else
      fu.push_back(-a[i]);
  }

  if ((sei.size() == 0 && k % 2 == 1) || (n == k && fu.size() % 2 == 1)) {
    sort(fu.begin(), fu.end());
    int ans = 1;
    rep(i, min((int)fu.size(), k)) {
      ans *= fu[i];
      ans %= mod;
    }
    rep(i, max(0LL, k - (int)fu.size())) {
      ans *= sei[i];
      ans %= mod;
    }
    cout << (mod - ans) % mod << endl;
    return 0;
  }

  sort(sei.begin(), sei.end(), greater<int>());
  sort(fu.begin(), fu.end(), greater<int>());

  int ans = 1;
  if (k % 2 == 1) {
    ans *= sei[0];
  }

  vector<int> vec;
  for (i = k % 2; i + 1 < sei.size(); i += 2) {
    vec.push_back(sei[i] * sei[i + 1]);
  }
  for (i = 0; i + 1 < fu.size(); i += 2) {
    vec.push_back(fu[i] * fu[i + 1]);
  }
  sort(vec.begin(), vec.end(), greater<int>());

  rep(i, k / 2) {
    int res = vec[i] % mod;
    ans *= res;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8116
def isPrime(num)
  return false if num < 2
  return true if num == 2
  n = 2
  while n <= Math.sqrt(num) + 1
    return false if num % n == 0
    n += 1
  end
  return true
end

def compute(init, diff, num)
  found = 0
  n = init
  while true
    found += 1 if isPrime(n)
    if found == num
      puts n
      return
    end
    n += diff
  end
  
end

while line = gets.split(" ")
  a = line[0].to_i
  d = line[1].to_i
  n = line[2].to_i
  break if a == 0 and d == 0 and n == 0

  compute(a, d, n)
end

Measured memory_bytes: 8732
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)

using namespace std;

int N;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> N;
    int n = N;
    int dsum = 0;
    while (N > 0) {
        dsum += (N % 10);
        N /= 10;
    }

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int const N = 100;
struct coord { int x, y; };

int main()
{
  int n;
  while( cin >> n ) {
    if ( n == 0 )
      break;

    bool pre[N][N] = {};
    bool vst[N][N] = {};
    coord table[N][N] = {};

    for( int yy=0; yy<n; ++yy ) {
      for( int xx=0; xx<n; ++xx ) {
	coord p;
	cin >> p.x >> p.y;
	table[xx][yy] = p;
      }
    }

    int loops = 0;
    for( int yy=0; yy<n; ++yy ) {
      for( int xx=0; xx<n; ++xx ) {
	coord p = { xx, yy };
	for(;;) {
	  if ( pre[p.x][p.y] ) {
	    coord pm = p;
	    do {
	      if ( vst[pm.x][pm.y] )
		goto owari;
	      pre[pm.x][pm.y] = false;
	      vst[pm.x][pm.y] = true;
	      pm = table[pm.x][pm.y];
	    } while( !( pm.x == p.x && pm.y == p.y ) );
	    ++loops;
	  owari:
	    break;
	  }
	  pre[p.x][p.y] = true;
	  p = table[p.x][p.y];
	}
      }
    }
    cout << loops << endl;
  }
}

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define reps(i,s,e) for(int i=s; i<(int)e; i++)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Graph = vector<vector<T>>;

const int INT_BIG = ~(1<<28);

void printFixedDouble(double d, int fix) {
    cout << std::fixed;
    cout << std::setprecision(fix) << d << endl;
}

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    reps(i, A, B+1) {
        if (i % K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

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



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

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

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









int main(){
    ull n;
    cin >> n;
    if(n % 2 == 1){
        cout << 0 << endl;
        return 0;
    }
    ull ans = 0, r = 5;
    while(n >= r){
        ans += (n / 2) / r;
        r *= 5;
    }
    cout << ans << endl;
}

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

#define PI 6.28318530717958623200

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

	double R;

	cin >> R;

	cout << fixed;
	cout.precision(16);
	
	cout << R*PI << '\n';
	return 0;
}

Measured memory_bytes: 3804
#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,M;cin>>N>>M;
  vector<int> H(N+1);
  for(int i=1;i<=N;i++) cin>>H[i];
  vector<int> around_max(N+1,0);
  
  int a,b;
  for(int i=1;i<=M;i++){
    cin>>a>>b;
    around_max[a]=max(around_max[a],H[b]);
    around_max[b]=max(around_max[b],H[a]);
  }
  
  int ans=0;
  for(int i=1;i<=N;i++){
    if(H[i]>around_max[i]) ans++;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 4044
// CONTEST

#include <bits/stdc++.h>
using namespace std;

// Utility
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, X, Y) for (int I = (X); I < (Y); I++)
using ll = int64_t;
using ull = uint64_t;
template<typename T> struct is_container {
template<typename C> static char test(typename C::const_iterator*); template<typename> static int test(...);
static bool const value = sizeof(test<T>(nullptr)) == sizeof(char) && !std::is_same<std::string, T>::value;
};
namespace std {
template<class ...Ts>        istream& operator>>(istream& i, tuple<Ts...>& x) { apply([&](auto&&... ys){ ((i >> ys), ...); }, x); return i; }
template<class T1, class T2> istream& operator>>(istream& i, pair<T1, T2>& x) { i >> x.first >> x.second; return i; }
template<class T, enable_if_t<is_container<T>::value, int> = 0>
istream& operator>>(istream& i, T& x) { for (auto& y : x) { i >> y; } return i; }
}

// Debugging
#define DD(X) std::cout << #X ": " << (X) << std::endl << std::flush
#define DD2(X) std::cout << #X ":" << std::endl; for (auto x : (X)) { std::cout << x << std::endl << std::flush; }
namespace std {
template<class ...Ts>        ostream& operator<<(ostream& o, const tuple<Ts...>& x) { o << "("; apply([&](auto&& y, auto&&... ys){ o << y; ((o << ", " << ys), ...); }, x); o << ")"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const pair<T1, T2>& x) { o << tie(x.first, x.second); return o; }
template<class T, enable_if_t<is_container<T>::value, int> = 0>
ostream& operator<<(ostream& o, const T& x) { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
}

// Main
void mainCase() {
  string s;
  cin >> s;

  int x = 0;
  for (auto c : s) {
    x += (c - '0');
    x %= 9;
  }

  bool res = x == 0;
  cout << (res ? "Yes" : "No") << endl;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  // [ Single case ]
  mainCase();
  return 0;
  // [ Multiple cases ]
  // int t;
  // cin >> t;
  // FOR(i, 0, t) { mainCase(); }
  // return 0;
}


Measured memory_bytes: 3784
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <map>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <memory>

using namespace std;

#if 1
#define PRINT(x) { cout << #x << ": " << (x) << endl; }
#define PRINT_CONTAINER(x)  { cout << #x << ": ";                       \
        for (size_t ix = 0; ix < (x).size(); ++ix) cout << (x)[ix] << ", "; \
        cout << endl; }
#else
#define PRINT(x)
#define PRINT_CONTAINER(x)
#endif

typedef pair<int, int> p;

int n;

int main(int argc, char *argv[]) {
    int a, b, x;
    scanf("%d %d %d", &a, &b, &x);
    puts(a <= x && x <= a + b ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N,K;
  cin>>N>>K;
 ll X=N/K;
  N-=K*X;
 ll A=abs(N-K);
  cout<<min(A,N)<<endl;
}
 
  
  

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

const ll M = 3500;

int main(void)
{
    ll N;
    cin >> N;
    Rep(i, 1, M+1){
        Rep(j, 1, M+1){
            ll a = 4*i*j-i*N-j*N;
            if(a <= 0) continue;

            if(((i*j*N) % a) == 0){
                pr(i, j, (i*j*N)/a);
                return 0;
                // ll k = (i*j*N)/a;
                // if(4*i*j*k == (i*j + j*k + k*i)*N){
                //     pr(i, ub, k);
                //     return 0;
                // }
            }
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n , i , j , count;
	char buf1[1000] , buf2[1000];
	int num1[81] = {0} , num2[81] = {0} , ans[81] = {0};
	scanf("%d" , &n);
	for(i=1;i<=n;i++){
		for(j=0;j<81;j++){
			num1[j] = 0;
			num2[j] = 0;
			ans[j] = 0;
		}
		buf1[81] = 'a';
		buf2[81] = 'a';
		scanf("%s" , buf1);
		scanf("%s" , buf2);
		if(buf1[81]!='a'||buf2[81]!='a'){
			printf("overflow\n");
			continue;
		}
		for(j=0;;j++){
			if(buf1[j]=='\0') break;
		}
		count = 0;
		for(;j>0;j--){
			num1[80-count] = buf1[j-1] - 48;
			count++;
		}
		for(j=0;;j++){
			if(buf2[j]=='\0') break;
		}
		count = 0;
		for(;j>0;j--){
			num2[80-count] = buf2[j-1] - 48;
			count++;
		}
		for(j=80;j>0;j--){
			ans[j] += num1[j] + num2[j];
			if(ans[j]>=10){
				ans[j-1]++;
				ans[j] -= 10;
			}
		}
		if(ans[0] == 1){
			printf("overflow\n");
			continue;
		}
		for(j=0;j<=81;j++){
			if(j==81) break;
			if(ans[j] != 0) break;
		}
		if(j==81){
			printf("%d\n" , 0);
			continue;
		}
		for(;j<=80;j++){
			printf("%d" , ans[j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector> 
#include <math.h>

using namespace std;

int main(void){
   
    int N;
    cin >>N;
    int k;
    k=(1+sqrt(1+8*N))/2;
    if(k==(1+sqrt(1+8*N))/2)
    {
    
    vector <vector <int>> ans;
    
    
    int cnt=1;
    ans.resize(k);
    
    
    for(int i=0;i<k;i++)
    {
        for(int j=i+1;j<k;j++)
        {
           ans[i].push_back(cnt);
           ans[j].push_back(cnt);
          
           cnt+=1;
           
           
        }
    }
    
    cout << "Yes"<<endl;
    cout << k<<endl;
    
    for (int i=0;i<k;i++)
    {
        
        cout << k-1 <<" ";
        for (int j=0;j<k-1;j++)
        {
            cout << ans[i][j]<< " ";
        }
        cout << endl;
    }
    }
    else
    {
        cout <<"No"<<endl;
    }
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int n;
    cin >> n;
    P res = {0,0};
    for(int i = 1;i<= n;i++){
        int b = 0;
        int a = i;
        while (1)
        {
            if(a%2 == 0){
                b++;
                a /=2;
            }else{
                break;
            }
        }
        if(res.second <= b){
            res.first = i;
            res.second = b;
        }
    }
    cout << res.first << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k,a;
    cin>>n>>k;
    std::deque<int> deq;
    for (int i=0;i<n;i++) {
        cin>>a;
        deq.emplace_back(a);
    }
    auto itr=find(deq.begin(),deq.end(),1);
    int dist=distance(deq.begin(),itr);
    int count=0,flag=0;
    if (n!=k) {
        //左側
        if (dist%(k-1)==0) {
            count+=dist/(k-1);
        } else {
            count+=dist/(k-1);
            count++;
            flag=1;
        }
        //cout<<count<<endl;
        //右側
        if (flag==1) {
            dist+=k-(dist%(k-1)+1);
            //cout<<dist<<endl;
        }
        if (n-(dist+1)>0) {
            if (n-(dist+1)>=k-1) {
                count+=(n-(dist+1))/(k-1);
                if ( (n-(dist+1))%(k-1)!=0 ) {
                    count++;
                }
            } else {
                count++;
            }
        }
        cout<<count<<endl;
    } else {
        cout<<1<<endl;
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    ll N, time;
    cin >> N >> time;

    vector<ll> t(N);
    for (int i = 0; i < N; i++)
    {
        cin >> t[i];
    }

    reverse(t.begin(), t.end());
    vector<ll> ruiseki(N + 1, 0);
    ll diff;
    ruiseki[0] = time;
    for (int i = 0; i < N; ++i)
    {
        diff = t[i] - t[i + 1];
        ruiseki[i + 1] = ruiseki[i] + min(diff, time);
    }

    // debug
    // for (int i = 0; i < N; i++)
    // {
    //     printf("%lld ", ruiseki[i]);
    // }
    ll ans = ruiseki[N - 1];
    cout << ans << endl;
}

Measured memory_bytes: 6324
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var nextReader func() string

func newScanner() func() string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), int(1e11))
	sc.Split(bufio.ScanWords)
	return func() string {
		sc.Scan()
		return sc.Text()
	}
}

func nextString() string { return nextReader() }

func nextInt() int { n, _ := strconv.Atoi(nextReader()); return n }

func nextInts(size int) []int {
	ns := make([]int, size)
	for i := 0; i < size; i++ {
		ns[i] = nextInt()
	}
	return ns
}

func main() {
	nextReader = newScanner()
	S := nextString()
	T := nextString()
	var balls = make(map[string]int, 0)
	is := nextInts(2)
	balls[S] = is[0]
	balls[T] = is[1]
	if nextString() == S {
		balls[S] -= 1
	} else {
		balls[T]-=1
	}
	fmt.Println(balls[S], balls[T])
}


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

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  for(int i=0;i<n;i++)
    cin >> h.at(i);
  
  string s="Yes";
  
  int k=0;
  for(int i=0;i<n;i++){
    if(k>h.at(i)+1){
      s="No";
      break;
    }
    k=max(k,h.at(i));
  }
  cout << s << endl;
}

Measured memory_bytes: 764
import numpy as np
K=int(input())
s3=0
s2=0
s1=0
s0=0
for a in range(1,K-1):
    for b in range(a+1,K):
        d=np.gcd(a,b)
        for c in range(b+1,K+1):
            s0+=np.gcd(c,d)
for a in range(1,K):
    for c in range(a+1,K+1):
        s1+=np.gcd(a,c)
for a in range(1,K):
    for b in range(a+1,K+1):
        s3+=np.gcd(a,b)
for k in range(K+1):
    s2+=k
print(s0*6+s1*3+s3*3+s2)
        

            

Measured memory_bytes: 27144
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
int inf=1000001000;
ll INF=100000000000000000;
ll MOD=1000000007;
//g++ code.cpp   ./a.out 
 
long long calc(long long A) {
 	if (A <= 0) return 0;
 	A++;
	long long ans = 0;
	//i桁目の偶奇を調べる
	for (int i = 0; i < 50; i++)
	{
		long long loop = (1LL << (i + 1));
		long long cnt = (A / loop) * (loop / 2);
		cnt += max(0LL, (A % loop) - (loop / 2));
		if (cnt % 2 == 1) {
			ans += 1LL << i;
		}
	}
 
	return ans;
}
 
int main() {
	long long A, B;
	cin >> A >> B;
	long long ans = calc(B) ^ calc(A - 1);
	cout << ans << endl;
}

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

int main(void) {
    int N;
    double t, v, d;
    
    while(cin >> v) {
        N = 0;
        t = v / 9.8;
        d = 4.9 * t * t;
        
        while(N * 5 - 5 < d) {
            ++N;
        }
        
        cout << N << endl;
    }
}


Measured memory_bytes: 3052
#include<iostream>
#include<string>

using namespace std;

int main(){

  string s;
  cin >> s;
  
   int res=0;
  for(int i=1;2*i<s.length();i++){
    if(s.substr(0,i)==s.substr(i,i)) res=2*i;
  }
 cout << res << endl;

}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

ll f(ll X){
	if(X==1){
		return 1;
	}else{
		return 2*f(X/2) + 1;
	}
}

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

    ll H;
    cin >> H;
    cout << f(H) << endl;
    return 0;
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

size_t N;
std::string buf[1000];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	for (size_t i = 0; i < N; i++)
	{
		in >> buf[i];
	}
	for (size_t i = 1; i < N; i++)
	{
		if (buf[i-1].back() != buf[i].front()) {
			out << "No" << endl;
			return 0;
		}
	}
	std::sort(buf, buf + N);
	for (size_t i = 1; i < N; i++)
	{
		if (buf[i - 1] == buf[i]) {
			out << "No" << endl;
			return 0;
		}
	}
	out << "Yes" << endl;

	return 0;
}
#endif

#if 0
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <sstream>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t H, W;

int map[500][500];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> H >> W;

	for (int32_t i = 0;i < H; i++)
	{
		for (int32_t j = 0; j < W; j++)
		{
			in >> map[i][j];
		}
	}

	std::vector<std::string> buf;
	int32_t x1=-1, y1=-1;
	for (int32_t i = 0; i < H; i++)
	{
		for (int32_t j = 0; j < W; j++)
		{
			if (map[i][j] % 2 == 1)
			{
				if (x1 == -1) {
					x1 = j; y1 = i;
				}
				else {
					int32_t x2 = j, y2 = i;
					while (x1 < x2) {
						std::stringstream ss;
						ss << y1+1 << ' ' << x1 + 1 << ' ' << y1 + 1 << ' ' << x1 + 1 + 1 << '\n';
						buf.push_back(ss.str());
						++x1;
					}
					while (x2 < x1) {
						std::stringstream ss;
						ss << y1 + 1 << ' ' << x1 + 1 << ' ' << y1 + 1 << ' ' << x1 + 1 - 1 << '\n';
						buf.push_back(ss.str());
						--x1;
					}
					while (y1 < y2) {
						std::stringstream ss;
						ss << y1 + 1 << ' ' << x1 + 1 << ' ' << y1 + 1 + 1 << ' ' << x1 + 1 << '\n';
						buf.push_back(ss.str());
						++y1;
					}
					while (y2 < y1) {
						std::stringstream ss;
						ss << y1 + 1 << ' ' << x1 + 1 << ' ' << y1 + 1 - 1 << ' ' << x1 + 1 << '\n';
						buf.push_back(ss.str());
						--y1;
					}

					x1 = -1, y1 = -1;
				}
			}
		}
	}
	out << buf.size() << endl;
	for (auto& i : buf)
	{
		out << i;
	}

	return 0;
}
#endif


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

#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)

using ll = long long;
#define INF 1e9

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N){
    cin >> a[i];
    a[i]--;
  }
  int ans = 0;
  REP(i, N){
    if(a[a[i]] == i){
      ans++;
    }
  }
  cout << ans / 2 << endl;
  return 0;
}


Measured memory_bytes: 640
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
a,b = LI()
if a%3 == 0 or b%3 == 0 or (a+b)%3 == 0:
    print("Possible")
else:
    print("Impossible")
"""
#B
n,k = LI()
l = LI()
l.sort(reverse = True)
print(sum(l[:k]))
#C
"""
n = I()
a = LI()
b = [None for i in range(n-1)]
for i in range(n-1):
    a[i+1] += a[i]
for i in range(n-1):
    b[i] = abs(2*a[i]-a[n-1])
print(min(b))
"""

#D
"""
n = I()
v = [[] for i in range(n)]
for i in range(n-1):
    a,b = LI()
    a -= 1
    b -= 1
    v[a].append(b)
    v[b].append(a)
d_f = [-1 for i in range(n)]
q = deque()
q.append(0)
d_f[0] = 0
while q:
    x = q.pop()
    for y in v[x]:
        if d_f[y] == -1:
            d_f[y] = d_f[x] + 1
            q.append(y)
d_s = [-1 for i in range(n)]
q.append(n-1)
d_s[n-1] = 0
while q:
    x = q.pop()
    for y in v[x]:
        if d_s[y] == -1:
            d_s[y] = d_s[x] + 1
            q.append(y)
f = 0
s = 0
for i in range(n):
    if d_f[i] <= d_s[i]:
        f += 1
    else:
        s += 1
if f > s:
    print("Fennec")
else:
    print("Snuke")
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 38512
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		long r = solve(n);
		System.out.println(r);
		in.close();
	}

	private static long solve(int n) {
		long r = 0;
		for (int i = 1; i <= n; i++)
			if (i % 3 == 0 || i % 5 == 0)
				continue;
			else
				r += i;
		return r;
	}

}

Measured memory_bytes: 35888
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let s = scan!();
    let rev: String = s.chars().rev().collect();
    let words = vec!["maerd", "remaerd", "esare", "resare"];
    let lens = vec![5, 7, 5, 6];

    let n = rev.chars().count();
    let mut i = 0;
    while i < n {
        let mut found = false;
        for (j, &word) in words.iter().enumerate() {
            if i + lens[j] <= n && word == &rev[i..i + lens[j]] {
                i += lens[j];
                found = true;
                break;
            }
        }
        if !found {
            println!("NO");
            return;
        }
    }
    println!("YES")
}


Measured memory_bytes: 4352
def g_c_d(x, y):
    if y == 0:
        return x
    else:
        return g_c_d(y, x % y)


n = int(input())
a = list(map(int, input().split()))
gcd = 0
for i in range(n):
    gcd = g_c_d(gcd, a[i])
cnt = 0
while True:
    if gcd % 2 == 0:
        cnt += 1
        gcd //= 2
    else:
        print(cnt)
        exit()


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


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

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

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


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

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


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





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


	if (n == n1) {
		return min(val * 2, val + k);
	}
	return min( recu(n + 1, k, 2 * val), recu(n + 1, k, val + k)              );


}
int digit(int n) {

	int temp = 0;
	while (n) {
		// temp += n % 10;
		n = n / 10;
		temp++;
	}



	return temp;
}

bool check(int a[], int n) {
	for (int i = 0; i < n; ++i)
	{
		/* code */
		if (a[i] % 2)
			return false;
	}
	return true;
}
bool ispalin(int n) {


	string  str = to_string(n);
	// cout<<str<<endl;


	for (int i = 0; i < str.size() / 2; ++i)
	{
		/* code */
		// watch2(str[i],str[str.size()-i-1]);
		if (str[i] != str[str.size() - i - 1]) {
			return false;
		}
	}


	return true;


}

int main() {
	int i,  n, m,c=0, k, sum = 0;
	c_p_c();
	string s;
	cin>>s;
	n = s.size();


	for (int i = 0; i < n/2; ++i)
	{
		/* code */
		// debug(s[i],s[n-1-i]);
		if(s[i]!=s[n-1-i])
			c++;
	}
	cout<<c<<endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s;
    cin >> s;
    if (s.length() == 6 && (s[2] == s[3] && s[4] == s[5]))
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=2e3+10,MAXM=1e6+5;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}int n,p1,p2,p3,p4;ll ans,dis[MAXN];
struct Edge{int to,next,w,c;}edges[MAXM];
int cnt=1,head[MAXN],cur[MAXN],S,T,vis[MAXN],pre[MAXN],pre_num[MAXN];
inline void add(int x,int y,int w,int c){
	edges[++cnt]=(Edge){y,head[x],w,c},head[x]=cnt;
	edges[++cnt]=(Edge){x,head[y],0,-c},head[y]=cnt;
}

int spfa()
{
	queue<int>q;
    memset(dis,-0x3f,sizeof(dis));
    q.push(S);dis[S]=0;vis[S]=1;
    while(q.size())
    {
        int now=q.front();q.pop();vis[now]=0;
        for(int i=head[now];i;i=edges[i].next)
        {
            if(dis[edges[i].to]<dis[now]+edges[i].c&&edges[i].w)
            {
                dis[edges[i].to]=dis[now]+edges[i].c;
                pre[edges[i].to]=now;
                pre_num[edges[i].to]=i;
                if(!vis[edges[i].to])  q.push(edges[i].to),vis[edges[i].to]=1;
            }
        }
    }
    if(dis[T]==-1e16)  return 0;
    int di=1e9;
    for(int i=T;i!=S;i=pre[i])  di=min(di,edges[pre_num[i]].w);
    for(int i=T;i!=S;i=pre[i])  edges[pre_num[i]].w-=di,edges[pre_num[i]^1].w+=di;
    ans+=dis[T]*di;
    return di;
}
//inline bool bfs(){
//	queue<int>q;q.push(S),memset(dis,-0x3f,sizeof(dis)),memset(vis,0,sizeof(vis)),memcpy(cur,head,sizeof(head)),dis[S]=0;
//	for(int x;!q.empty();q.pop()){
//		x=q.front(),vis[x]=0;
//		for(int i=head[x],y;i;i=edges[i].next)if(edges[i].w&&dis[y=edges[i].to]<dis[x]+edges[i].c)
//			dis[y]=dis[x]+edges[i].c,!vis[y]?q.push(y),0:0;
//	}return dis[T]>=-1e9;
//}
//int dfs(int x,int dist){
//	if(x==T||!dist)return dist;vis[x]=1;int z=0;
//	for(int&i=cur[x],y,k;i;i=edges[i].next)if(edges[i].w&&dis[y=edges[i].to]==dis[x]+edges[i].c&&!vis[y]){
//		k=dfs(y,min(edges[i].w,dist)),z+=k,dist-=k,edges[i].w-=k,edges[i^1].w+=k;
//		if(!dist)break;
//	}return vis[x]=0,z;
//}inline void Solve(){while(bfs())ans+=1ll*dis[T]*dfs(S,1e9);}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),S=MAXN-2,T=MAXN-1,p1=MAXN-3,p2=MAXN-4,p3=MAXN-5,p4=MAXN-6;
	Rep(i,1,n){
		int x=read(),y=read(),w=read();
		add(S,i,w,0),add(i,p1,1e9,x+y),add(i,p2,1e9,x-y),add(i,p3,1e9,-x+y),add(i,p4,1e9,-x-y);
	}Rep(i,1,n){
		int x=read(),y=read(),w=read();
		add(i+n,T,w,0),add(p1,i+n,1e9,-x-y),add(p2,i+n,1e9,-x+y),add(p3,i+n,1e9,x-y),add(p4,i+n,1e9,x+y);
	}while(spfa());cout<<ans<<'\n';
	return 0;
}




Measured memory_bytes: 3976
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

#define int long long

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, m, v, p;
    cin >> n >> m >> v >> p;
    vector<int> a(n);
    for (auto &t : a) {
    	cin >> t;
    }
    sort(a.rbegin(), a.rend());
    auto can = [&](int x) {
    	if (v == 0) {
    		return x == 1;
    	}
    	//b[x - 1]
    	int skip = 0;
    	int val = a[x - 1] + m;
    	// cerr << val << endl;
    	int tot = m * (v - 1);
    	// cerr << tot << endl;
    	vector<int> na = a;
    	na.erase(na.begin() + x - 1);
    	int eq = 0;
    	vector<int> tuks;
    	for (auto t : na) {
    		if (t > val) {
    			skip++;
    			tot -= m;
    			continue;
    		}
    		int tk = min(m, val - t);
    		t += tk;
    		tot -= tk;
    		if (t == val) {
    			eq++;
    			tuks.push_back(m - tk);
    			continue;
    		}
    	}
    	if (skip >= p) {
    		return false;
    	}
    	int can = min(p - 1 - skip, eq);
    	sort(tuks.rbegin(), tuks.rend());
    	for (int i = 0; i < can; i++) {
    		tot -= tuks[i];
    	}
    	return tot <= 0 && skip <= p - 1;
    };
    int l = 1;
    int r = (int)a.size() + 1;
    while (r - l > 1) {
    	int mm = (r + l) >> 1;
    	if (can(mm)) {
    		l = mm;
    	} else {
    		r = mm;
    	}
    }
    cout << l << endl;
    // for (auto t : a) {
    // 	cerr << t << ' ';
    // }
    // cerr << endl;
    // cout << can(8) << endl;
}


Measured memory_bytes: 3700
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

void insert(int);
void inorder(Node);
void preorder(Node);

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key){
    x = x->left;
    }
    else {
      x = x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else {if(z->key < y->key){
      y->left = z;
    }else {y->right = z;
    }
  }
}

void inorder(Node u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
 inorder(u->right);
  
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, a;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &a);
      insert(a);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }

  return 0;
}



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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n;

	cin >> n;

	vector<ll> v(n);

	REP(i, n) {
		cin >> v[i];
	}

	ll ans = 0;

	REP(i, n - 2) {
		if (v[i + 1] >= v[i] && v[i + 2] >= v[i + 1]) {
			ans++;
		}
		else if (v[i + 1] <= v[i] && v[i + 2] <= v[i + 1]) {
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);



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

ll modinv(ll x){
    return modpow(x,mod-2);
}

ll comb(ll n, ll k){
    ll ans1 = 1;
    ll ans2 = 1;
    rep(i,0,k) ans1 = ans1 * (n-i) % mod;
    rep(i,0,k) ans2 = ans2 * (i+1) % mod;
    return ans1*modinv(ans2) % mod;
}

int main(){
    ll n,a,b; cin >> n >> a >> b;
    ll ans = modpow(2,n)-1-comb(n,a)-comb(n,b);
    while (ans < 0) ans += mod;
    cout << ans << endl;
}


Measured memory_bytes: 888
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <iostream>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N_ = 100500;
int N, A[N_];
ll suma;

int main() {
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) {
		scanf("%d", &A[i]);
		suma += A[i];
	}
	A[0] = A[N];

	ll sumn = (ll)N * (N+1) / 2;
	if(suma % sumn != 0) return 0 & puts("NO");
	suma /= sumn;

	for(int i = 1; i <= N; i++) {
		int x = suma - (A[i] - A[i-1]);
		if(x < 0 || x % N != 0) return 0 & puts("NO");
	}

	puts("YES");
	return 0;
}


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


int main(void){
	int n, m, c[16], x, y, p[2][256], ans, i, j, k;
	while(1){
		scanf("%d%d",&n,&m);
		if(n == 0 && m == 0) return 0;
		for(i = 0;i < m;i++)
			scanf("%d",&c[i]);
		memset(p,-1,sizeof(p));
		p[0][128] = 0;
		for(i = 0;i < n;i++){
			scanf("%d",&x);
			for(j = 0;j < 256;j++) p[(i + 1) % 2][j] = -1;
			for(j = 0;j < 256;j++){
				if(p[i % 2][j] != -1){
					for(k = 0;k < m;k++){
						y = j + c[k];
						if(y > 255) y = 255;
						else if(y < 0) y = 0;
						if(p[(i + 1) % 2][y] == -1 || p[(i + 1) % 2][y] > p[i % 2][j] + (y - x) * (y - x))
							p[(i + 1) % 2][y] = p[i % 2][j] + (y - x) * (y - x);
					}
				}
			}
		}
		ans = -1;
		for(j = 0;j < 256;j++)
			if(p[i % 2][j] != -1 && (ans == -1 || ans > p[i % 2][j])) ans = p[i % 2][j];
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1028
#include<iostream>

using namespace std;

int func(int n)
{ int sum = 0;
  while( n > 0 )
  { sum += n % 10;
   n /= 10;
  }
 return sum;
}
//桁和を表す

int main()
{int N, A, B;
 cin >> N >> A >> B;
 int cnt = 0;
 for(int i = 1; i <= N ; i++)
 { int c = func(i);
  if(c >= A && c <= B){cnt += i;}}
 
 cout << cnt << endl;
return 0;
}
 


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

ans = 0
for i in range(N):
    # 勇者に余力がある場合
    if B[i] >= A[i]:
        ans += A[i]
        B[i] -= A[i]
        if B[i] >= A[i+1]:
            ans += A[i+1]
            A[i+1] = 0
        else:
            ans += B[i]
            A[i+1] -= B[i]
    # 勇者に余力がない場合
    else:
        ans += B[i]
print(ans)


Measured memory_bytes: 19116
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int  N,k; cin >> N>>k;
    string S; cin >> S;
    if(S[k-1]  == 'A') S[k-1] = 'a';
    else if(S[k-1] == 'B') S[k-1] = 'b';
    else S[k-1] = 'c';
    cout << S << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define fastio  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD=1000000007;
#define PI acos(-1)
using namespace std;
int main(){
	int n; cin >> n ;
	int a[n];
	for(int i=0 ; i < n ; i++) cin >> a[i];
	sort(a,a+n);
	int count =0;
	for(int i=0 ; i < n ; i++){
		for(int j = i+1 ; j < n ; j++){
			int x= a[i],y=a[j];
			int z= x+y; // search for the third such that a+b > c 
			int idx = lower_bound(a+j+1, a+n,z)-a;
			idx--;
			if(idx>j)
			count+=(idx-j);
		}
	}
	cout << count << endl;
}

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

char s[500][501];
int n, g = 0;

void bad(){
	f(i, 0, n)f(j, 0, n)if (s[i][j] == '#')return;
	printf("-1\n");
	exit(0);
}

int main(){
	scanf("%d", &n);
	f(i, 0, n)scanf("%s", s[i]);
	bad();
	f(j, 0, n){
		bool ok = true;
		f(i, 0, n)if (s[i][j] == '.') { ok = false; break; }
		if (ok)++g;
	}
	int an = 1e9;
	f(i, 0, n){
		int r = 0;
		bool ok = false;
		f(j, 0, n)if (s[j][i] == '#') { ok = true; break; }
		if (!ok)++r;
		f(j, 0, n)if (s[i][j] == '.')++r;
		r += n - g;
		an = min(an, r);
	}
	printf("%d\n", an);
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
    #define ll long long
    #define rep(i,a,b) for(i=a;i<b;i++)
    #define pb push_back
    #define all(v) v.begin(),v.end()
    #define F first
    #define S second
    #define hell 1000000007
    using namespace std;

    void solve()
    {
     ll a,b,c,p,q,r;
      ll v,w,T;
      cin>>a>>v>>b>>w>>T;
      if(a==b) {cout<<"YES"; return;}
      if(v<=w) {cout<<"NO"; return;}
      ll dis=abs(a-b);
      ll vel=abs(v-w);
      if(dis<=vel*T) cout<<"YES";
      else cout<<"NO";

}

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


Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<utility>
#include<iterator>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
//#define t ll t;cin>>t;while(t--)
#define nn cout<<endl;
#define ff(a,n) for(ll i=a;i<n;i++)
#define fr(x, a) for(auto &x:a)
#define cY cout<<"YES\n"
#define cN cout<<"NO\n"
#define cy cout<<"Yes\n"
#define cn cout<<"No\n"
#define sc second
#define fs first
#define c(a) cout<<a<<endl

void solve()
{
	ll x; cin>>x;
	cout<<abs(x-1);
}

int main()
{
	solve();
}
/*




*/


Measured memory_bytes: 3600