akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    int x,t;
    cin >> x >> t;
    if(t <= x) cout << x-t << endl;
    else cout << 0 << endl;
    return 0;
}

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

#define INF 0x3f3f3f3f
#define int long long
#define pii pair<int, int>

const int N = 3005;

int dp[N][N], a[N];
int n;

int solve(int beg, int end) {     // maximum difference you get for [beg, end]
    if(beg == end)
        return dp[beg][end] = a[beg];
    if(dp[beg][end] != -1)
        return dp[beg][end];
    dp[beg][end] = max(a[beg] - solve(beg+1, end), a[end] - solve(beg, end-1));
    return dp[beg][end];
}

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

    int i;
    memset(dp, -1, sizeof(dp));

    cin >> n;
    for(i = 1 ; i <= n ; i++)
        cin >> a[i];
    cout << solve(1, n) << endl;
    return 0;
}


Measured memory_bytes: 70912
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
double dp[3000][3000];

double prob(int n,int x,vector<double> &p)
{
    if(x==0)
    {
        return dp[n][x]=1;
    }
    else if(n==0)
    {
        return dp[n][x]=0;
    }
    else
    {
        if(dp[n][x]>-0.9)
        {
            return dp[n][x]; // pehle se calculate kr liya hai....
        }
        return dp[n][x]=p[n]*prob(n-1,x-1,p)+(1-p[n])*prob(n-1,x,p);
    }
}

void solve(int n,vector<double> &p)
{
    memset(dp,-1,sizeof(dp));
    int x;
    x=((n>>1)+1);
    cout<<fixed<<setprecision(10)<<prob(n,x,p);
}

int main()
{
    int n;
    cin>>n;
    vector<double> p(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>p[i];
    }
    solve(n,p);
    return 0;
}

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

#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

string s,t;

int dp[3001][3001];

void givstr(int i,int j)
{
	if(i==0||j==0)
		return;
	if(s[i-1]==t[j-1])
	{
		givstr(i-1,j-1);
		cout<<s[i-1];
	}
	else if(dp[i-1][j]>dp[i][j-1])
		givstr(i-1,j);
	else givstr(i,j-1);
	return;
}


int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("test.txt","r",stdin);
	cin>>s>>t;
	for(int i=1;i<=s.length();i++)
	{
		for(int j=1;j<=t.length();j++)
		{
			if(s[i-1]==t[j-1])
				dp[i][j] = dp[i-1][j-1] + 1;
			else  dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		}
	}
	givstr(s.length(),t.length());
	return 0;
}

Measured memory_bytes: 35840
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ
int main()
{
    int N;
    cin >> N;
    if (N < 3)
        cout << 0;
    else
        cout << (N / 3);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {


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

        long a = scan.nextLong();
        long b = scan.nextLong();
        long c = scan.nextLong();
        long d = scan.nextLong();
        long ans;

        if (a < 0 && c <0) {
            ans = Math.max(a * c, b*d);
        }
        else if (a < 0 && c>=0) {
            ans = Math.max(b * c, b*d);
        }
        else if (a>=0 && c <0) {
            ans = Math.max(a*d, b*d);
        }
        else {
            ans = b*d;
        }
        System.out.println(ans);
    }
}

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

typedef long long ll;
const int N = 100100;

vector<pair<int,int>>adj[N];
int n , q ;
int p[N][20];
int dep[N];
ll s[N];

void dfs(int u,int pr,ll sm){
dep[u]=1+dep[pr];
p[u][0]=pr;
s[u]=sm;

for(auto x:adj[u]){
    int v = x.first;
    int c = x.second;
    if( v == pr )continue;
    dfs(v,u,sm+c);
}

}


int LCA(int u,int v){

if( dep[u]<dep[v] )swap(u,v);
int k = dep[u]-dep[v];

for(int i=0;i<20;i++)
    if( k&(1<<i) )
    u=p[u][i];

if( u == v )return u;

for(int i=19;i>=0;i--)
    if( p[u][i] != p[v][i] )
    u=p[u][i],v=p[v][i];
return p[u][0];
}

ll dis(int u,int v){
int lca=LCA(u,v);
return s[u]-s[lca]+s[v]-s[lca];
}

int main(){

cin>>n;
for(int i=1;i<n;i++){
    int a,b,c;
    cin>>a>>b>>c;
    adj[a].push_back( {b,c} );
    adj[b].push_back( {a,c} );
}

dfs(1,0,0);

for(int j=1;j<20;j++)
for(int i=1;i<=n;i++){
    p[i][j]=p[ p[i][j-1] ][j-1];
}

int k;
cin>>q>>k;

while( q-- ){
    int x,y;
    cin>>x>>y;
    cout<<dis(x,k)+dis(k,y)<<endl;
}

return 0;
}


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

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}
////////////////////////////////////////////////////////////
int keta(int n){
  int c=0;
  while(n>0){
    n/=10;
    c++;
  }
  return c;
}
signed main() {
  int n,k;
  cin>>n>>k;
  int ans=0;
  vector<int>d(k);
  rep(i,k)cin>>d[i];
  for(int i=n;i<=100000;i++){
    int t=i;
    bool b=true;
    while(t>0){
      rep(j,k){
        if(d[j]==t%10){
          b=false;
        }
      }
      t/=10;
    }
    if(b){
      ans=i;
      break;
    }
  }
  cout<<ans;
}


Measured memory_bytes: 3476
n=int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
ini=sum(alist)

for i in range(n):
    tmpa=alist[i]
    tmpb=blist[i]
    if tmpb >=tmpa:
        alist[i]=0
        tmpb-=tmpa
        alist[i+1]=max(0,alist[i+1]-tmpb)
    else:
        alist[i]-=tmpb
print(ini-sum(alist))

Measured memory_bytes: 24124
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n); for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
typedef pair<int, int> P;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<""<<endl;
int main(){
ll N,K;cin>>N>>K;vl A(N);
  rep(i,N){
    cin>>A[i];
    A[i]--;
  }
  vl ok(N);
  rep(i,N)ok[i]=1000000000;
  ok[0]=0;
  ll i=0;
  ll cnt=1;
  ll gh=1;
  ll st =0,en=0;
  while(gh<=N+1){
    if(ok[A[i]]!=1000000000){
      st=ok[A[i]];
      en=gh;
      break;      
    }
    ok[A[i]]=gh;
    i=A[i];
    gh++;
  }
  if(K<=st-1){
    rep(i,N){
      if(ok[i]==K)cout<<i+1<<endl;
    }
  }
  else if(st-1<K){
    K=K-st+1;
    K%=(en-st);
    rep(i,N){
      if(K==0)K=en-st;
      if(ok[i]==st-1+K)cout<<i+1<<endl;
    }
  }
    
  
  
}


Measured memory_bytes: 6460
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		// 自分の得意な言語で
		// Let's チャレンジ！！

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		String re = "No";

		Set<Integer> se = new HashSet<>();
		se.add(a);
		se.add(b);
		se.add(c);

		if (se.size() == 2) {
			re = "Yes";
		}

		System.out.println(re);
	}

}

Measured memory_bytes: 25300
#include <iostream>
#include <list>

using namespace std;

int main(void) {
  int n, q, command, s, t, x;
  cin >> n >> q;

  list<int> L[n];
  list<int>::iterator it;

  for(int i = 0; i < q; i++) {
    cin >> command >> t;
    switch(command) {
      case 0:
        cin >> x;
        L[t].push_back(x);
        break;
      case 1:
        for(list<int>::iterator it = L[t].begin(); it != L[t].end(); it++) {
          if(it != L[t].begin()) cout << " ";
          cout << *it;
        }     
        cout << endl;
        break;
      case 2:
        cin >> s;
        L[s].splice(L[s].end(), L[t]);
        L[t].clear();
        break;
    }
  }
}


Measured memory_bytes: 18692
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, int num=0){
  if(num == 0) num = (int)v.size();
  if(is_reverse) for(int i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<" ";}
  else for(int i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<" ";}
  cout << endl;
}

template <typename T>
void print_pairvec(const vector<T> &v, int num=0){
  if(num == 0) num = (int)v.size();
  cout << endl;
  for(int i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
}


template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){
  ll W, H, x, y;
  cin >> W >> H >> x >> y;
  // long double S = W * H /2.0;
  ll S = W * H;
  ll ans = 0;
  if(W == 2*x && H == 2*y) ans = 1;

 cout << fixed;//小数点を確実に10桁で表示するためのもの
 cout << setprecision(10); 

 if(S%2 == 0) cout << S/2 << " " << ans << endl;
 else cout << S/2 << ".5 " << ans << endl;

	return 0;
}



Measured memory_bytes: 3540
from itertools import combinations

N, D = [int(n) for n in input().split()]
X = []
for i in range(N):
    p = [int(n) for n in input().split()]
    X.append(p)
ans = 0
for i,j in combinations(X, 2):
    dd = 0
    for d in range(D):
        dd += (j[d]-i[d])**2
    if (dd**0.5).is_integer():
        ans += 1
print(ans)


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

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

int main() {
  int n;
  cin >> n;
  map<int, int> a;
  rep(i, n-1){
    int tmp;
    cin >> tmp;
    a[tmp]++;
  }

  for(int i = 0; i < n; ++i){
    size_t tmp = a.count(i+1);
    if(tmp > 0){
      cout << a[i+1] << endl;
    }
    else{
      cout << 0 << endl;
    }
  }



  return 0;
}


Measured memory_bytes: 12864
import java.util.*;

class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int d = sc.nextInt();
        int n = sc.nextInt();
        
        if (n == 100) {
            System.out.println( 101 * (int)Math.pow(100, d));
        } else {
            System.out.println( n * (int)Math.pow(100, d));
        }
        
    }
}

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

using namespace std;

int main(){
	int N; cin>>N;
	map<int, int> s;
	int a;
	for(int n=0; n<N; n++){
		cin>>a;
		s[a]++;
	}
	auto x = s.end(); x--;
	long long w=-1, h=-1;
	while(true){
		if(x->second>1){
			x->second-=2;
			if(w==-1){
				w=x->first;
			} else {
				h = x->first;
				break;
			}
		}
		if(x->second>1){
			x->second -=2;
			h=x->first;
			break;
		}
		if(x==s.begin()){
			break;
		}
		x--;
	}
	if(h==-1||w==-1){
		cout << 0 << endl;
	} else {
		cout << (h*w) << endl;
	}
	return 0;
}

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

const int maxn = 1e5 + 5;
vector<int> g[maxn];
int dp[maxn];

int dfs(int x) {
    if (~dp[x]) return dp[x];
    dp[x] = 1;
    for (const int &u : g[x]) {
        dp[x] = max(dp[x], dfs(u) + 1);
    }
    return dp[x];
}

int main() {
    int n, m; scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i) {
        int x, y; scanf("%d%d", &x, &y);
        --x, --y;
        g[x].push_back(y);
    }
    memset(dp, -1, sizeof(dp));
    int ans = 0;
    for (int i = 0; i < n; ++i) ans = max(ans, dfs(i));
    printf("%d\n", ans - 1);
    return 0;
}


Measured memory_bytes: 7424
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
typedef long long llong;
static const llong max_n = 200010;
static const llong max_abs_value = 1000000010;
vector<llong> seq(max_n);
vector<llong> diff_seq(max_n);
vector<llong> cum_diff_seq(max_n);
vector<vector<llong>> dp(max_n, vector<llong>(3, 0));
// vector<llong> dp(max_n, 0);
// vector<vector<llong>> dp(max_n, vector<llong>(10, 0));
// static const int max_n = 110;
// static const llong max_cost = 2000000000000000;
// // vector<vector<llong>> matrix(max_n, vector<llong>(max_n, 0));
// // vector<vector<llong>> adj_matrix(max_n, vector<llong>(max_n, max_cost));
// vector<vector<pair<llong, int>>> adj_list(max_n);
// vector<llong> distance_table(max_n, max_cost);
// set<pair<llong, int>> points_sort_x;
// set<pair<llong, int>> points_sort_y;

// int N;
llong N;


int main(){
    // int u, v;
    // bool updated = false;
    llong ans = 0, value;
    scanf("%lld", &N);
    for(llong i=0;i<N;i++){
        scanf("%lld", &seq[i]);
    }

    dp[0][2] = seq[0];
    dp[1][1] = max(seq[0], seq[1]);
    dp[1][2] = max(seq[0], seq[1]);
    for(llong i=2;i<N;i++){
        // printf("--------------\n");
        for(int j=0;j<3;j++){
            // printf("dp[%lld][%d]=%lld\n", i-1, j, dp[i-1][j]);
        }
        if((i+1)%2==1){
            dp[i][0] = max(dp[i-2][0]+seq[i], dp[i-1][0]);
            dp[i][1] = max(dp[i-2][1]+seq[i], dp[i-1][1]);
            dp[i][2] = dp[i-2][2] + seq[i];
        }else{
            dp[i][0] = max(dp[i-2][0]+seq[i], dp[i-1][1]);
            dp[i][1] = max(dp[i-2][1]+seq[i], dp[i-1][2]);
            dp[i][2] = dp[i][1];
        }
    }

    printf("%lld\n", dp[N-1][1]);
    // printf("ok input\n");



    // double limit = 1. / (double)(4 * M);



    return 0;

}

Measured memory_bytes: 18232
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

main(){
  int n;
  while(cin>>n,n){
    stack<PI> go;
    rep(i,n){
      int st;
      cin>>st;
      if(i%2){
	PI tp=go.top();go.pop();
	if(tp.F!=st){
	  tp.S++;
	  go.push(tp);
	}else{
	  if(!go.empty()){
	    PI tp2=go.top();go.pop();
	    tp2.S+=tp.S+1;
	    go.push(tp2);
	  }else{
	    tp.S++;
	    tp.F=!tp.F;
	    go.push(tp);
	  }
	}
      }else{
	if(!go.empty()){
	  PI tp=go.top();go.pop();
	  if(tp.F==!st){
	    tp.S++;
	    go.push(tp);
	  }else{
	    go.push(tp);
	    go.push(mp(!st,1));
	  }
	}else go.push(mp(!st,1));
      }
    }
    int ans=0;
    while(!go.empty()){
      int col=go.top().F,num=go.top().S;
      go.pop();
      if(col)ans+=num;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 908
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	vector<int> pf(n),sf(n);
	for(int i=0;i<n;++i)
		pf[i]=(s[i]=='W')+(i?pf[i-1]:0);
	for(int i=n-1;~i;--i)
		sf[i]=(s[i]=='E')+(i!=n-1?sf[i+1]:0);
	int res=n;
	for(int i=0;i<n;++i){
		int cost=0;
		if(i) cost+=pf[i-1];
		if(i!=n-1) cost+=sf[i+1];
		res=min(res,cost);
	}
	cout<<res<<'\n';
}



Measured memory_bytes: 6116
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

struct edge{
	int64_t to, cost;
	edge(int64_t to, int64_t cost){
		this->to = to;
		this->cost = cost;
	}
};

int main(){
	int n;
	cin >> n;
	vector<vector<edge>> v(n);
	for(int i = 0; i < n - 1; i++){
		int64_t from, to, cost;
		cin >> from >> to >> cost;
		from--;
		to--;
		v[from].emplace_back(edge(to, cost));
		v[to].emplace_back(edge(from, cost));
	}
	int q, k;
	cin >> q >> k;
	k--;
	bool done[n]{};
	int64_t dist[n];
	fill(dist, dist + n, 1ll << 60);
	dist[k] = 0;
	priority_queue<pair<int64_t, int>, vector<pair<int64_t, int>>, greater<pair<int64_t, int>>> pq;
	pq.push({0, k});
	while(!pq.empty()){
		pair<int64_t, int> p = pq.top();
		pq.pop();
		if(done[p.second]) continue;
		done[p.second] = true;
		for(edge &e:v[p.second]) if(!done[e.to] && dist[p.second] + e.cost < dist[e.to]){
			dist[e.to] = dist[p.second] + e.cost;
			pq.push({dist[e.to], e.to});
		}
	}
	while(q--){
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		cout << dist[x] + dist[y] << endl;
	}
}

Measured memory_bytes: 11248
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

long long int INF = 1000000000000000000LL; // 10^18
using namespace std;

typedef pair<long long int, long long int> P;

vector<int> E[110000];

bool visited[110000] = {};

vector<int> v1, v2;

void dfs1(int id){
	v1.push_back(id);
	for(int i = 0; i < E[id].size(); i++){
		if(!visited[E[id][i]]){
			visited[E[id][i]] = true;
			dfs1(E[id][i]);
			return;
		}
	}
}

void dfs2(int id){
	v2.push_back(id);
	for(int i = 0; i < E[id].size(); i++){
		if(!visited[E[id][i]]){
			visited[E[id][i]] = true;
			dfs2(E[id][i]);
			return;
		}
	}
}

int main(){
	
	int N, M;
	cin >> N >> M;
	
	for(int i = 0; i < M; i++){
		int A, B;
		cin >> A >> B;
		A--;
		B--;
		E[A].push_back(B);
		E[B].push_back(A);
	}
	
	visited[0] = true;
	dfs1(0);
	dfs2(0);
	
	cout << v1.size() + v2.size() - 1 << endl;
	
	for(int i = v2.size() - 1; i >= 1; i--){
		cout << v2[i] + 1 << " ";
	}
	
	for(int i = 0; i < v1.size() - 1; i++){
		cout << v1[i] + 1 << " ";
	}
	cout << v1[v1.size() - 1] + 1 << endl;
	
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>x;
	cout<<2*x/__gcd(x,2)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<ll> Vec;
typedef vector<Vec> DVec;
typedef vector<DVec> TVec;
typedef priority_queue<P, vector<P>, greater<P>> PQ;

#define fi                first
#define se                second
#define pb                push_back
#define INF               LLONG_MAX/3
#define MOD               1000000007
#define bcnt              __builtin_popcount
#define all(x)            (x).begin(),(x).end()
#define srt(x)            sort(all(x))
#define rvs(x)            reverse(all(x))
#define uni(x)            x.erase(unique(all(x)),x.end())
#define ub(x,y)           (upper_bound(all(x),y)-x.begin())
#define lb(x,y)           (lower_bound(all(x),y)-x.begin())
#define rep(i,n)          repl(i,0,n-1)
#define mkp(x,y)          make_pair(x,y)
#define mmax(x,y)         (x>y?x:y)
#define mmin(x,y)         (x<y?x:y)
#define maxch(x,y)        x=mmax(x,y)
#define minch(x,y)        x=mmin(x,y)
#define exist(x,y)        (find(all(x),y)!=x.end())
#define each(itr,v)       for(auto itr:v)
#define repl(i,a,b)       for(ll i=(ll)(a);i<=(ll)(b);i++)
#define dvec(n1,n2,i)     DVec(n1,Vec(n2,i))
#define tvec(n1,n2,n3,i)  TVec(n1,dvec(n2,n3,i))


int main(){
  cin.sync_with_stdio(false);
  ll n,m,w,h,r,l;
  ll mv=0,c,suma=0,sumb=0;
  cin >> n >> c;
  Vec v(n+2,0),x(n+2,0),rv(n+2,0),lv(n+2,0),frv(n+2,0),dnum(n+2,0);
  x[n+1]=c;
  repl(i,1,n) cin >> x[i] >> v[i];
  repl(i,1,n){
    suma+=v[i];
    sumb+=v[n+1-i];
    rv[i]=suma-x[i];
    if(rv[i]>frv[i-1]){
      frv[i]=rv[i];
      dnum[i]=i;
    }
    else{
      frv[i]=frv[i-1];
      dnum[i]=dnum[i-1];
    }
    lv[i]=max(lv[i-1],sumb-c+x[n+1-i]);
  }
  rep(i,n+1)mv=mmax(mv,lv[i]+frv[n-i]-mmin(c-x[n+1-i],x[dnum[n-i]]));
  cout << mv << endl;

  return 0;
}


Measured memory_bytes: 4992
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}

	sc.Scan()
	j, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}

	if i < j {
		fmt.Println(0)
	} else {
		fmt.Println(10)
	}

}

Measured memory_bytes: 640
def IsPrime(n):
    '''

    :param n:??£??´??°
    :return: ?´???°?????????True, ????????????????????°?????????False
    ???????????§???????´???°??? 6k-1????????? 6k+1??§??¨?????????????????????k?????£??´??°
    '''
    if n == 2 or n == 3 or n== 5: return True
    if n == 1 or n%2 == 0 or n%3 == 0:return False
    d, l = 5, int(n**(1/2))
    while d <= l:
        if n%d == 0 or n%(d+2) == 0:return False
        d += 6
    return True
c = 0
for i in range(int(input())):
    if IsPrime(int(input())): c += 1
print(c)

Measured memory_bytes: 7700
#include <stdio.h>

int main(void) {
  int a[11][11], n, i, j;

  while (1) {
    for (i = 0; i < 11; i++)
      for (j = 0; j < 11; j++)
	a[i][j] = 0;
    
    scanf("%d", &n);
    if (n == 0) break;

    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++)
	scanf("%d", &a[i][j]);

    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++)
	a[i][n] += a[i][j];

    for (j = 0; j < n; j++)
      for (i = 0; i < n; i++)
	a[n][j] += a[i][j];

    for (i = 0; i < n; i++)
      a[n][n] += a[i][n];

    for (i = 0; i < n + 1; i++) {
      for (j = 0; j < n + 1; j++)
	printf("%5d", a[i][j]);
      putchar('\n');
    }
  }
  return 0;
}

Measured memory_bytes: 616
using System;

public class Program
{
  public static void Main()
  {
    int price = int.Parse(Console.ReadLine());
    double notax = price / 1.08;
    
    if(Math.Floor((int)(notax) * 1.08) == price)
    {
      Console.WriteLine((int)notax);
      return;
    }
    if(Math.Floor((int)(notax + 1) * 1.08) == price)
    {
      Console.WriteLine((int)notax + 1);
      return;
    }
    
    Console.WriteLine(":(");
  }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
	using namespace std;
	typedef long long int ll;
	#define PRINT(x,y) cout<<"Case #"<<(int)x<<": "<<(int)(y)<<endl;
	ll exp(ll x, ll y) {
		if(y==0) return 1;
		if(y==1) return x;
		if(y%2==0) return exp(x,y/2)*exp(x,y/2);
		else return x*exp(x,y/2)*exp(x,y/2);
	}
	ll gcd(ll a , ll b) {
		if(b==0) return a;
		return gcd(b , a%b);
	}
	ll lcm(ll a , ll b) {
		return (a*b)/gcd(a,b);
	}
	#define MOD (1e9+7);
	#define sq(a) (a)*(a);
	#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int l;
	ll fact(ll x) {
		if(x==1) return 1;
		else return x*fact(x-1);
	}
	bool isPrime(int x) {
		int ans  = 0;
		for(int i=2;i<=sqrt(x);++i) {
			if(x%i==0) {
				ans = 1; i=x;
			}  
		}
		if(ans==0) return true;
		else return false;
	}
	void solve() {
		int d,t,s; cin>>d>>t>>s;
		if(s*t>=d) cout<<"Yes";
		else cout<<"No";
	}

	int main() {
		io
	   solve();
	    
	}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cMOD 1000000007ULL
#define cINF ((1ull<<62)-1)
#define cINFINT ((1<<30)-1)


class Graph
{
public:
	explicit Graph( int nodeSize )
		: mNodeSize( nodeSize )
		, mEdgeSize( 0 )
		, mEdge( nodeSize )
		, mUsed( nodeSize )
		, mMark( nodeSize )
		, mMark2( 0 )
		{}
	
	// Edge定義
	struct Edge
	{
		bool operator<( const Edge& other )
		{ return this->cost != other.cost ?
			this->cost < other.cost : this->to < other.to;  }
		int to; int cost; int rev;
	};
	
	// Edge情報を読み取る
	void readEdge_Undirect_NoCost( int m ) { readEdge_( m, false, false ); }
	void readEdge_Direct_NoCost( int m ) { readEdge_( m, true, false ); }
	void readEdge_Undirect_Cost( int m ) { readEdge_( m, false, true ); }
	void readEdge_Direct_Cost( int m ) { readEdge_( m, true, true ); }
	void readEdge_Direct_Flow( int m ) { readEdge_Flow_( m ); }
	
private:
	void readEdge_( int m, bool isDirected, bool isCost )
	{
		REP( i, m )
		{
			int a, b, c = 1, r = -1;
			cin >> a >> b;
			if( isCost ) cin >> c;
			mEdge[a-1].push_back( { b-1, c, -1 } );
			if( !isDirected ) mEdge[b-1].push_back( { a-1, c, r } );
			++mEdgeSize;
		}
	}
	void readEdge_Flow_( int m )
	{
		REP( i, m )
		{
			int a, b, c;
			cin >> a >> b >> c;
			mEdge[a-1].push_back( { b-1, c, int(mEdge[b-1].size()) } );
			mEdge[b-1].push_back( { a-1, 0, int(mEdge[a-1].size() - 1) } );
			++mEdgeSize;
		}
	}
	
public:
	// 必要なときだけメモリ確保するように
	void assignMark2()
	{
		vector<int> tmp( mNodeSize, cINFINT );
		mMark2.assign( mNodeSize, tmp );
	}
	void setupMark2ForCost()
	{
		REP( i, mNodeSize )
		{
			mMark2[i][i] = 0;
			for( const auto& e : mEdge[i] ) mMark2[i][e.to] = e.cost;
		}
	}

public:
	int mNodeSize; // VertexSize
	int mEdgeSize; // EdgeSize
	vector< vector< Edge > > mEdge; // 隣接リスト
	
	// 作業用変数
	vector<bool> mUsed;
	vector<int> mMark;
	// 必要なときだけメモリ確保するように
	vector< vector<int> > mMark2;
};

int dfs_tree_( Graph& g, const vector<ll>& c, ll& idx, int v )
{
	for( const auto& e : g.mEdge[v] )
	{
		if( g.mUsed[e.to] ) continue;
		g.mUsed[e.to] = true;
		g.mMark[e.to] = c[idx++];
		auto u = dfs_tree_( g, c, idx, e.to );
	}
}
void
dfs_tree( Graph& g, const vector<ll>& c, ll& idx, int startNode )
{
	fill( ALL( g.mUsed ), 0 ); fill( ALL( g.mMark ), -1 );
	g.mUsed[startNode] = true;
	g.mMark[startNode] = c[idx++];
	dfs_tree_( g, c, idx, startNode );
}

int main()
{
	int n, m;
	cin >> n; m = n - 1;
	Graph g( n );
	g.readEdge_Undirect_NoCost( m );
	vector<ll> c(n);
	REP( i, c.size() ) cin >> c[i];
	sort( ALL(c), greater<ll>() );

	vector<pair<ll,ll>> nodeP( n );
	REP(i,n) nodeP[i] = { g.mEdge[i].size(), i };
	sort( ALL( nodeP ) );
	ll idx = 0;
	dfs_tree( g, c, idx, nodeP[0].second );
	
	ll ans = accumulate( ALL(c), 0ll ) - *c.begin();
	cout << ans << endl;
	REP( i, g.mMark.size() ) cout << g.mMark[i] << " "; cout << endl;
	
	return 0;
}

Measured memory_bytes: 1792
import Queue
INF = 1 << 29
class Edge:
    def __init__(self, _v, _cost):
        self.v = _v
        self.cost = _cost
def parse(s, m, n):
    if(s[0]=="C"): return int(s.translate(None, "C")) - 1
    elif(s[0]=="L"): return int(s.translate(None, "L")) - 1 + m
    elif(s[0]=="H"): return m + n 
    else: return m + n + 1
while True:
    m, n, k, d = map(int, raw_input().split())
    if m==0 and n==0 and k==0 and d==0: break
    cake = map(int, raw_input().split())
    G = [[] for i in range((m + n + 2))]
    for i in range(d):
        dist = raw_input().split()
        u = parse(dist[0], m, n)
        v = parse(dist[1], m ,n)
        G[v].append(Edge(u, int(dist[2])))
        G[u].append(Edge(v, int(dist[2])))
    D = [[0  for col in range(1<<6)]  for row in range(108)]
    for i in range(m + n + 2):
        for j in range(1 << m):
            D[i][j] = INF
    D[m + n][0] = 0

    ans = INF
    que = Queue.PriorityQueue()
    que.put([0, [m + n, 0]])
    while not que.empty():
        item = que.get()
        d_now = item[0]
        u = item[1][0]
        s = item[1][1]
        if D[u][s] < d_now: continue
        if u == m + n + 1: ans = min(ans, d_now)
        for i in range(len(G[u])):
            v = G[u][i].v
            if v < m:
                if s & 1 << v != 0: continue
                s2 = s | 1 << v
                d2 = d_now + k * G[u][i].cost - cake[v]
            else:
                s2 = s
                d2 = d_now + k * G[u][i].cost
            if d2 < D[v][s2]:
                D[v][s2] = d2
                que.put([d2, [v, s2]])
    print ans

Measured memory_bytes: 5576
#include<bits/stdc++.h>
#define INF 1234567890
using namespace std;
int partition(int *A,char *B,int p,int r){
  int x=A[r];
  int i=p-1;
  for(int j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      swap(A[i],A[j]);
      swap(B[i],B[j]);
    }
  }
  swap(A[i+1],A[r]);
  swap(B[i+1],B[r]);
  return i+1;
}
void quicksort(int *A,char *B,int p,int r){
  if(p<r){
    int q=partition(A,B,p,r);
    quicksort(A,B,p,q-1);
    quicksort(A,B,q+1,r);
  }
}
void merge(int *a,char *b,int l,int m,int r){
  int n1 = m - l;
  int n2 = r - m;
  vector<int> L(n1+1);
  vector<int> R(n2+1);
  vector<int> Lb(n1+1);
  vector<int> Rb(n2+1);
  for(int i=0;i<n1;i++){
    L[i]=a[l+i];
    Lb[i]=b[l+i];
  }
  for(int i=0;i<n2;i++){
    R[i]=a[m+i];
    Rb[i]=b[m+i];
  }
  L[n1]=INF;
  R[n2]=INF;
  int i=0;
  int j=0;
  for(int k=l;k<r;k++){
    if(L[i]<=R[j]){
      a[k]=L[i];
      b[k]=Lb[i];
      i++;
    }
    else{
      a[k]=R[j];
      b[k]=Rb[j];
      j++;
    }
    //  cou++;
  }
}
 
void mergesort(int *a,char *b,int l,int r){
  if(l+1<r){
    int m=(l+r)/2;
    mergesort(a,b,l,m);
    mergesort(a,b,m,r);
    merge(a,b,l,m,r);
  }
}
 
int main(){
  int n;
  cin >> n;
  int ai[100005],bi[100005];
  char ac[100005],bc[100005];
  for(int i=0;i<n;i++){
    cin >> ac[i]>> ai[i];
    bc[i]=ac[i];
    bi[i]=ai[i];
  }
  mergesort(ai,ac,0,n);
  quicksort(bi,bc,0,n-1);
  int f=0;
  for(int i=0;i<n;i++){
    if(ac[i]!=bc[i]){
      f=1;
      break;
    }
  }
  if(!f)cout << "Stable" << endl;
  else cout << "Not stable" << endl;
  for(int i=0;i<n;i++){
    cout << bc[i] << " " << bi[i] << endl;
  }
  return 0;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

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

#define MP make_pair
#define MT make_tuple
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

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

	int N;
	cin >> N;
	vector<PII> X(N), Y(N);
	int preX = -1, preY = -1;
	REP(i, N){
		int x, y;
		cin >> x >> y;
		X[i] = MP(x, i);
		Y[i] = MP(y, i);
	}

	SORT(X);
	SORT(Y);

	vector<pair<int, PII>> dX(N - 1), dY(N - 1);
	REP(i, N - 1){
		dX[i] = MP(X[i + 1].first - X[i].first, MP(X[i + 1].second, X[i].second));
		dY[i] = MP(Y[i + 1].first - Y[i].first, MP(Y[i + 1].second, Y[i].second));
	}

	SORT(dX);
	SORT(dY);

	UnionFind uf(N);
	LL ret = 0;

	int ix = 0, iy = 0;
	while(ix < N - 1 || iy < N - 1){
		int dx = 1e9 * 2, dy = 1e9 * 2;
		if(ix < N - 1) dx = dX[ix].first;
		if(iy < N - 1) dy = dY[iy].first;
//		cout << dx << " " << dy << endl;
		int d, a, b;
		if(dx < dy){
			d = dx;
			a = dX[ix].second.first;
			b = dX[ix].second.second;
			ix++;
		}
		else{
			d = dy;
			a = dY[iy].second.first;
			b = dY[iy].second.second;
			iy++;
		}
		if(uf.findSet(a, b)) continue;
		ret += d;
		uf.unionSet(a, b);
	}

	cout << ret << endl;


	return 0;
}


Measured memory_bytes: 4608
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, parser) => {
        $next
    };

    ($next:expr, $t:ty) => {
        $next(&is_whitespace).parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        s: chars,
    }

    let mut c = 0;
    for i in 0..3 {
        if s[i] == 'A' {
            c += 1;
        }
    }
    if c == 0 || c == 3 {
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 4352
#include<stdio.h>

int main(){
  int R = 0;
  int G = 0;
  int B = 0;
  int N = 0;
  int r = 0;
  int g = 0;
  int b = 0;
  int cnt = 0;
  int hoge = 0;
  scanf("%d",&R);
  scanf("%d",&G);
  scanf("%d",&B);
  scanf("%d",&N);
  for(r = 0;r <= N/R;r++){
    for(g = 0;g <= N/G;g++){
      hoge = N-(r*R+g*G);
      if(hoge >= 0 && hoge % B == 0){
        cnt++;
      }
    }
  }
  printf("%d",cnt);
  return 0;
}
          

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>	
#include <cmath>
#include <string>
#include<math.h>
#include<sstream>//���炵���̂Œ���
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;


int main()
{
	cin >> n;
	vector<int> p(n); rep(i, n)cin >> p[i];
	int cnt = 0;
	for (int i = 1; i < n-1; i++) {
		if ((p[i - 1] - p[i]) * (p[i + 1] - p[i])<0)cnt++;
	}
	cout << cnt << endl;

	return 0;
}


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

const int INF = 1<<30;

int main(){
    int n;
    cin >> n;

    if(n == 1){
        cout << 0 << endl;
        return 0;
    }

    vector<pair<int,int>> v[n];
    int s, t, w;

    for(int i = 0; i < n-1; i++){
        cin >> s >> t >> w;
        v[s].push_back({t,w});
        v[t].push_back({s,w});
    }

    vector<int> dist(n, INF);
    priority_queue<pair<int,int>> pq;
    pq.push({-0, 0});
    while(!pq.empty()){
        pair<int,int> p = pq.top(); pq.pop();
        int cost = -p.first, pos = p.second;
        if(dist[pos] <= cost)   continue;
        dist[pos] = cost;
        for(pair<int,int> next : v[pos]){
            if(cost + next.second < dist[next.first]){
                pq.push({-(cost + next.second), next.first});
            }
        }
    }

    int a = -1, score = -1;
    for(int i = 0; i < n; i++){
        if(dist[i] > score){
            score = dist[i];
            a = i;
        }
    }
    dist.clear();
    dist.resize(n, INF);

    pq.push({-0, a});
    while(!pq.empty()){
        pair<int,int> p = pq.top(); pq.pop();
        int cost = -p.first, pos = p.second;
        if(dist[pos] <= cost)   continue;
        dist[pos] = cost;
        for(pair<int,int> next : v[pos]){
            if(cost + next.second < dist[next.first]){
                pq.push({-(cost + next.second), next.first});
            }
        }
    }
    
    cout << *max_element(dist.begin(), dist.end()) << endl;

    return 0;
}


Measured memory_bytes: 9660
a = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
bingo = [[0] * 3 for _ in range(3)]
ans = "No"

for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            bingo[i][j] = 1

if bingo[0][0] == bingo[1][1] == bingo[2][2] ==1 or bingo[0][2] == bingo[1][1] == bingo[2][0] == 1:
    ans = "Yes"
else:
    for k in range(3):
        if 0 not in bingo[k]:
            ans = "Yes"
        elif bingo[0][k] == bingo[1][k] == bingo[2][k] == 1:
            ans = "Yes"

print(ans)


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

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

  std::vector<int> a(n);
  for (auto& ai: a) scanf("%d", &ai);

  for (int j = 0; j < 30; ++j) {
    bool valid = true;
    for (auto ai: a)
      if (ai >> j & 1) valid = !valid;
    if (!valid) return puts("No"), 0;
  }
  puts("Yes");
}


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

int main() {
  int num,th;
  cin >> num >> th;
  
  if(num == 0){
   if(th!=100){
     cout << th; 
    }else{
     cout << 101; 
    }
  }else if(num == 1){
    if(th!=100){
     cout << 100 * th; 
    }else{
     cout << 101 * th; 
    }
  }else{
    if(th!=100){
     cout << 100 * 100 * th; 
    }else{
     cout << 101 * 100 * th; 
    }
  }
}


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

int bin_search(int x[],int size,int key)
{
	int low = 0,high = size-1;
	int count=0;
	while(low <= high){
		count++;
		int mid = (low+high)/2;
		if(x[mid] == key)
			return count;
		else if(x[mid] > key)
			high = mid-1;
		else
			low = mid+1;
	}
	return count;
}
int main()
{
	int size;
	int key;
	int x[101];
	while(cin >> size){
		if(size == 0)
			break;
		for(int i=0;i<size;i++){
			cin >> x[i];
		}
		cin >> key;
		cout << bin_search(x,size,key) << endl;
	}
	return 0;
}

/*
#include <iostream>
using namespace std;

static int count = 0;

int binary_search(int data[], int n, int x)
{
	int low = 0;
	int high = n-1;
	while(low<=high){
		count++;
		int middle = (high+low)/2;
		if(x==data[middle])
			return middle;
		else if(x<data[middle])
			high = middle-1;
		else
			low = middle+1;
	}
	return -1;
}

int main()
{
	const int n = 100000;
	int data[n];
	for(int i=0;i<n;i++){data[i] = i;}

	for(int i=0;i<n;i++){
		binary_search(data, n, data[i]);
	}

	cout << static_cast<double>(count)/n << endl;
	return 0;
}
*/

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000 , mod = 1000000007;
#define PI 3.14159265
int main()
{
    fastio;
    int n;
    cin>>n;
    int a[n+1];
    map<int,int>mp;
    ll ans = 0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i!=1)
        {
            int val =  i - a[i];
            if(mp.count(val))
                ans+=mp[val];
        }
        mp[a[i]+i]++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int64_t A,B,n;
  cin >> A >> B;
  for(int i=0;i<B;i++){
    if(A*(i+1)%B==0){
      n=i+1;
      break;
    }
  }
  cout << A*n << endl;
}


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

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

  set<int> st;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    if (st.count(A) == 1) st.erase(A);
    else st.insert(A);
  }

  cout << st.size() << endl;
}

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

using namespace std;

struct Dice
{
	int top;
	int bottom;
	int north;
	int east;
	int west;
	int south;
};

void init(Dice& dice)
{
	dice.top = 1;
	dice.bottom = 6;
	dice.north = 5;
	dice.east = 3;
	dice.west = 4;
	dice.south = 2;
}

int North(Dice& dice)
{
	int temp = dice.top;
	dice.top = dice.south;
	dice.south = dice.bottom;
	dice.bottom = dice.north;
	dice.north = temp;
	return(dice.top);
}

int East(Dice& dice)
{
	int temp = dice.top;
	dice.top = dice.west;
	dice.west = dice.bottom;
	dice.bottom = dice.east;
	dice.east = temp;
	return(dice.top);
}

int West(Dice& dice)
{
	int temp = dice.top;
	dice.top = dice.east;
	dice.east = dice.bottom;
	dice.bottom = dice.west;
	dice.west = temp;
	return(dice.top);
}

int South(Dice& dice)
{
	int temp = dice.top;
	dice.top = dice.north;
	dice.north = dice.bottom;
	dice.bottom = dice.south;
	dice.south = temp;
	return(dice.top);
}

int Right(Dice& dice)
{
	int temp = dice.north;
	dice.north = dice.west;
	dice.west = dice.south;
	dice.south = dice.east;
	dice.east = temp;
	return(dice.top);
}

int Left(Dice& dice)
{
	int temp = dice.north;
	dice.north = dice.east;
	dice.east = dice.south;
	dice.south = dice.west;
	dice.west = temp;
	return(dice.top);
}

void solve()
{
	int n;
	while (cin >> n, n)
	{
		int ans = 1;
		Dice dice;
		init(dice);
		for (int i = 0; i < n; ++i)
		{
			string command;
			cin >> command;
			if (command == "North")
			{
				ans += North(dice);
			}
			else if (command == "East")
			{
				ans += East(dice);
			}
			else if (command == "West")
			{
				ans += West(dice);
			}
			else if (command == "South")
			{
				ans += South(dice);
			}
			else if (command == "Right")
			{
				ans += Right(dice);
			}
			else if (command == "Left")
			{
				ans += Left(dice);
			}
		}
		cout << ans << endl;
	}
}

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

Measured memory_bytes: 1216
H,W,D=map(int,input().split())
A=[]
for i in range(H):
  temp=list(map(int,input().split()))
  for j in range(W):
    A.append([temp[j],i+1,j+1])
Q=int(input())
B=[]
for i in range(Q):
  B.append(list(map(int,input().split())))
A.sort()
#print(A)

C=[0]*(H*W)
for i in range(H*W-1,-1,-1):
  if i+D<=H*W-1:
    C[i]=C[i+D]+abs(A[i][1]-A[i+D][1])+abs(A[i][2]-A[i+D][2])
#print(C)

for i in range(Q):
  print(C[B[i][0]-1]-C[B[i][1]-1])

Measured memory_bytes: 44696
fun main(args: Array<String>) {
    a51(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

fun a51(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    print(args[0].replace(",", " "))
}

Measured memory_bytes: 38036