akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>

using namespace std;

inline bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
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(); }
template<class T> inline T sqr(T x) { return x*x; }

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

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const int mod = 1000000007;
const int INF = 1e9;

bool inter(int x1,int y1,int r1,int x2,int y2,int r2){
	int dist = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
	if (dist < (r1 + r2) * (r1 + r2)){
		return true;
	}else return false;
}

short dp[(1 << 24) + 1];

int main()
{
	int n;
	int x[100], y[100], r[100], c[100];
	vector<int> f[100];

	while (cin >> n && n){
		memset(f, 0, sizeof f);
		rep(i, n){
			cin >> x[i] >> y[i] >> r[i] >> c[i];
		}
		rep(i, n){
			For(j, i + 1, n){
				if (inter(x[i], y[i], r[i], x[j], y[j], r[j]))
					f[j].push_back(i);
			}
		}
		memset(dp, -1, sizeof dp);
		int ans = 0;
		dp[0] = 0;
		rep(k, 1 << 24){
			if (dp[k] == -1)continue;
			rep(i, n){
				if (1 & k >> i)continue;

				bool If = false;
				rep(l, f[i].size()){
					if (!(1 & k >> f[i][l])){
						If = true;
					}
				}
				if (If)continue;

				For(j,i+1, n){

					if (1 & k >> j)continue;
					if (c[i] != c[j])continue;

					bool Jf = false;
					rep(l, f[j].size()){
						if (!(1 & k >> f[j][l])){
							Jf = true;
						}
					}
					if (Jf)continue;

					int nx = k | (1 << j) | (1 << i);
					dp[nx] = max(int(dp[nx]),dp[k] + 2);
					ans = max(int(dp[nx]), ans);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main()
{
  int n;
  cin >> n;
  vector<string> w(n);

  cin >> w[0];

  for (int i = 1; i < n; i++)
  {
    cin >> w[i];
    if (w[i - 1].substr(w[i - 1].length() - 1, 1) != w[i].substr(0, 1))
    {
      cout << "No" << endl;
      return 0;
    }
    for (int j = 0; j < i; j++)
    {
      if (w[i] == w[j])
      {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3648
// In the name of God

#include <bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(x) cout << #x ": " << x << endl;

int dp[105][(int)1e5+5];
int w[105];
int v[105];

int main() {
	IOS
	int n, W;
	cin >> n >> W;
	int mxv = 0;
	for(int i=0; i<n; i++) {
		cin >> w[i] >> v[i];
		mxv += v[i];
	}
	for(int i=0; i<=n; i++) {
		for(int j=0; j<=mxv; j++) {
			dp[i][j] = W+1;
		}
	}
	for(int i=0; i<=n; i++) dp[i][0] = 0;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=mxv; j++) {
			if(j>=v[i-1]) dp[i][j] = min(dp[i][j], min(dp[i-1][j], dp[i-1][j-v[i-1]]+w[i-1]));
			else dp[i][j] = min(dp[i][j], dp[i-1][j]);
		}
	}
	int ans = 0;
	for(int i=0; i<=mxv; i++) {
		if(dp[n][i]<=W) ans = max(ans, i);
	}
	cout << ans;
 	return 0;
}


Measured memory_bytes: 41216
/*************************************************\
           In the name of almighty ALLAH
                 MD.Faysal Hasan
                Comilla Univesity
\*************************************************/

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

#define     ikarus_101  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef     long long             ll;
typedef     long double           ld;
typedef     unsigned long long    ull;
typedef     vector<ll>            vll;
typedef     pair<ll,ll>           pll;
typedef     vector<pll>           vpl;
typedef     map<ll,ll>            mll;
typedef     multiset<ll>          msl;
typedef     multimap<ll,ll>       Mll;
using pqboro=priority_queue<ll,vll,less<ll>>;
using pqchoto=priority_queue<ll,vll,greater<ll>>;

#define    all(str)       str.begin(),str.end()
#define    sajo(str)      sort(str.begin(),str.end())
#define    rev(str)       reverse(str.begin(),str.end())
#define    usajo(str)     sort(str.rbegin(),str.rend())
#define    vin(a)         for(auto &it : a) cin>>it
#define    vout(a)        for(auto it:a) cout<<it<<' ';cout<<nn
#define    pb             push_back
#define    eb             emplace_back
#define    mkp(x,y)       make_pair(x,y)
#define    F              first
#define    S              second
#define    yes            cout<<"YES"<<nn
#define    no             cout<<"NO"<<nn
#define    nn             "\n" ///endl
#define    rep(i,n)       for (i=0;i<n;++i )
#define    rep1(i,n)      for (i=1;i<=n;++i )

#define    min3(a,b,c)    min(a,min(b,c))
#define    max3(a,b,c)    max(a,max(b,c))
#define    sqr(x)         ((x)*(x))
#define    pi             2*acos(0.0)
#define    gcd(a,b)       __gcd(a,b)
#define    lcm(a,b)       (a/gcd(a,b))*b
#define    mem(a,b)       memset(a,b,sizeof (a))
#define    dec(x)         cout<<fixed<<setprecision(x)
#define    none(n)         __builtin_popcountll(n)

template < typename T > string toString ( T Number ) { stringstream ss ; ss << Number ; return ss.str() ; }
template < typename T > ll toll ( T str ) { stringstream ss ; ss << str ; ll num ; ss >> num ; return num ; }
ll power(ll n , ll k) { if(k == 0) return 1 ; if(k&1) return n*sqr(power(n,k/2)) ; else return sqr(power(n,k/2)); }

const   int  N   =   2e5+7;
const   int  M   =   1e9+7;
const   ll  inf  =   0x7f7f7f7f7f7f7f7f;

ll a[N];

int main() {ikarus_101

    ll n,m,i,j,k,x;

    cin>>n>>k;

    rep(i,n) cin>>a[i];
    ll s=k;
    for(i=1;i<n;i++)
    {
        s += min(k , a[i]-a[i-1]);
    }
    cout << s << nn;










    return 0;
}


Measured memory_bytes: 5088
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

map<int, int> ma;
vector<pair<int,int>> v;
vector<int> A;
signed main() {
	int N, T;
	cin >> N >> T;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		A.push_back(tmp);
	}
	int minValue = 1145141919;
	int minInd = -1;
	int value = -1;
	for (int i = 0; i < N; i++) {
		if (minValue > A[i]) {
			minValue = A[i];
			minInd = i;
		}
		if (value <  A[i] - minValue ) {
			value = A[i] - minValue;
			v.clear();
			v.push_back(make_pair(minInd, i));
		}
		else if (value ==  A[i] - minValue) {
			v.push_back(make_pair(minInd, i));
		}

	}
	//区間の端っこを全部入れる
	for (pair<int, int> p : v) {
		ma[p.first]++;
		ma[p.second]++;
	}
	int ans = 0;
	for (pair<int, int> p : v) {
		//すべての区間について端っこが死んでいないか検査、両方とも死んでいなければ多いほうを潰してans++
		if (ma[p.first] == -1 || ma[p.second] == -1) {
			continue;
		}
		if (ma[p.first] > ma[p.second]) {
			ma[p.first] = -1;
			ans++;
		}
		else {
			ma[p.second] = -1;
			ans++;
		}
	}
	cout <<ans << "\n";

	return 0;
}

Measured memory_bytes: 8052
import heapq
n,m=[int(i) for i in input().split()]
a=[-1*int(i) for i in input().split()]
heapq.heapify(a)
for i in range(m):
    b=heapq.heappop(a)
    b=b/2
    heapq.heappush(a,b)
ans=0
for i in a:
    ans-=int(i)
print(ans)

Measured memory_bytes: 14180
import java.math.BigDecimal
import java.util.*

val mod: Long = (Math.pow(10.0, 9.0) + 7).toLong()

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextLong()
    val aList = mutableListOf<Long>()
    for (i in 0 until n) {
        aList.add(sc.nextLong())
    }
    val isOdd = n % 2 != 0L
    if (isOdd && !aList.contains(0)) {
        println(0)
        return
    }
    if (!isOdd && aList.contains(0)) {
        println(0)
        return
    }

    var bList = mutableListOf<Long>()
    for (i in 1..n / 2) {
        bList.add(n - i * 2 + 1)
    }
    val reversed = bList.reversed().toMutableList()
    if (n % 2 != 0L) {
        reversed.add(0, 0)
    }
    bList = (bList + reversed).toMutableList()

    if (aList.sorted() != bList.sorted()) {
        println(0)
        return
    }
    val bigN = BigDecimal.valueOf(2)
    val ans = bigN.pow( (n / 2).toInt()).remainder(BigDecimal(mod))
    println(ans.toLong())
}


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

int main() {
    ios::sync_with_stdio(false);
    int x=100000, n;
    cin >> n;
    for(int i=0;i<n;i++){
      x *= 1.05;
      if(x%1000 == 0) ;
      else x = (x/1000)*1000 + 1000;
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 1196
#include<stdio.h>
#include<math.h>

int sosu(int);

int main(){
  int A[10000],h,i,cnt=0,result;

  scanf("%d",&h);
  
  for(i = 0 ; i < h ; i++){
    scanf("%d",&A[i]);
    result = sosu(A[i]);
    if(result == 1) cnt++;
  }

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

  return 0;
}

int sosu(int x){
  int i,result = 1;
  double A = sqrt(x);

  for(i = 2 ; i <= A ; i++){
    if(x % i == 0){
      result = 0;
      break;
    }
  }
  return result;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int a[100005],vis[100005];
int main(){
	int n,m,x;
	scanf("%d%d",&n,&m);
	memset(vis,0,sizeof(vis));
	memset(a,0,sizeof(a));
	for(int i=0;i<m;i++){
		scanf("%d",&x);
		vis[x]=1;
	}
	a[0]=1;
	for(int i=0;i<n;i++){
		if(vis[i]){
			continue;
		}
		if(vis[i+1]==0){
			a[i+1]+=a[i];
			a[i+1]%=mod;
		}
		if(vis[i+2]==0){
			a[i+2]+=a[i];
			a[i]%=mod;
		}
	}
	printf("%d\n",a[n]);	
}

Measured memory_bytes: 1024
s = input()
old = ''
flag = 0
sample = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    for i, s1 in enumerate(s[::-1]):
        if i != 0 and s1 < old[-1]:
            for o in sorted(old):
                if o > s1:
                    out = s[:len(s)-i-1] + o
                    print(out)
                    exit()
        old += s1
    if flag == 0:
        out = -1
else:
    out = s + min(set(sample)-set(s))

print(out)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF 9223372036854775807
using namespace std;
long long ans;
long long N;
long long solve(long long arg_N) {
  long retans;
  long long count;
  long long count_8 = 0;
  for(int i = 1; i <= arg_N; i=i+2) {
    count = 0;
    for(int j = 1; j <= arg_N; j=j+2) {
      if(i % j == 0) {
        count++;
      }
    }
    if(count == 8) {
      count_8++;
    }
  }
  retans = count_8;
  return retans;
}

int main(int arg, char* argv[]) {
  scanf("%d", &N);
  ans = solve(N);
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
ll m1=999979,m2=999983;

ll extgcd(ll a,ll b,ll& x,ll& y){
  ll d = a;
  if(b!=0){
    d=extgcd(b, a%b ,y,x);
    y-=(a/b)*x;
  }
  else{
    x=1; y=0;
  }
  return d;
}

ll mod_inverse(ll a,ll m){
  ll x,y;
  extgcd(a,m,x,y);
  return (m+x%m)%m;
}

ll solve(ll x,ll o,ll y){
  ll a=0,b=0;

  if(o==1)a=(x+y)%m1,b=(x+y)%m2;
  else if(o==2)a=(x-y+m1)%m1, b=(x-y+m2)%m2;
  else if(o==3)a=(x*y)%m1, b=(x*y)%m2;
  else if(o==4)a=(x*mod_inverse(y,m1))%m1,b=(x*mod_inverse(y,m2))%m2;
  
  ll p,q;
  extgcd(m1,m2,p,q);

return (b*m1*p+a*m2*q)%(m1*m2);
}

int main(void){

  ll n,o,x=0,y,a=0,b=0;

  cin >> n;

  while(n--){
    cin >> o >> y;
    x=solve(x,o,y);
  }
 
  cout << x << endl;

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
// #include <numeric>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
typedef long long int ll;
#define iceil(a,b) (x+y-1)/y
#define min(x,y)(x<y?x:y)
 
using namespace std;
typedef pair<int, int> P;


int main() {
	FAST;

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

	if (abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d)) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static int n;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = Integer.parseInt(sc.next());
		int[] values = new int[n];
		for (int i = 0; i < n; i++) {
			values[i] = Integer.parseInt(sc.next());
		}
		Arrays.sort(values);

		double middle = values[0];
		for (int i = 1; i < n; i++) {
			middle = (middle + values[i]) / 2.0;
		}

		System.out.println(middle);

	}

}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>H>>W;
    string white = "";
    rep(i,W+2) white.push_back('.');
    vector<string> grid(H+2);
    grid[0] = grid[H+1] = white;
    rep(i,H){
        string ins = ".";
        cin>>S;
        ins.append(S);
        ins.push_back('.');
        grid[i+1] = ins;
    }
    rep(i,H+2){
        rep(j,W+2){
            if(grid[i][j] == '#'){
                if((grid[i-1][j] == '.') && (grid[i][j-1] == '.')
                && (grid[i+1][j] == '.') && (grid[i][j+1] == '.')){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = list(map(int,input().split()))
    tmp_o = [0 for i in range(N+1)]
    tmp_e = [0 for i in range(N+1)]
    count_o = 0
    count_e = 0
    for i in range(N):
        tmp_o[i+1] = tmp_o[i]+A[i]
        if i%2 == 1 and tmp_o[i+1] <= 0:
            count_o += 1-tmp_o[i+1]
            tmp_o[i+1] = 1
        elif i%2 == 0 and tmp_o[i+1] >= 0:
            count_o += tmp_o[i+1]+1
            tmp_o[i+1] = -1
        else:
            continue
    for i in range(N):
        tmp_e[i+1] = tmp_e[i]+A[i]
        if i%2 == 0 and tmp_e[i+1] <= 0:
            count_e += 1-tmp_e[i+1]
            tmp_e[i+1] = 1
        elif i%2 == 1 and tmp_e[i+1] >= 0:
            count_e += tmp_e[i+1]+1
            tmp_e[i+1] = -1
        else:
            continue

    print(min(count_o,count_e))

if __name__ == "__main__":
    main()

Measured memory_bytes: 14332
#include <stdio.h>
#include <math.h>
#define TIME 0.5

int main(void){
  // 自分の得意な言語で
  // Let's チャレンジ！！
  float bisket_t;
  unsigned int biskets;
  float real_time;
  unsigned int total_biskets;
  scanf("%f %d %f", &bisket_t, &biskets, &real_time);
  unsigned int calc_biskets = floor((real_time + TIME ) / bisket_t);
  
  if(calc_biskets == 0) {
    printf("0\n");
  } else if(calc_biskets > 0) {
    printf("%d\n", calc_biskets * biskets);
  }
  return 0;
}

Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	var max int
	if a+b > a-b {
		max = a + b
	} else {
		max = a - b
	}
	if a*b > max {
		max = a * b
	}
	fmt.Println(max)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define MAXN 100100
#define pii pair<int, int>
#define pb push_back
typedef long long ll;

using namespace std;

int n;
ll mod = 1e9 + 7;
string a, b;
vector<bool> v;

ll go(int p, int x, bool vert){
	if(p >= v.size()) return 1;
	if(v[p] == 1){
		return (x * go(p + 1, 2, 1)) % mod;
	} else{
		ll t;
		if(x == 3) return (6 * go(p + 2, 1, 0)) % mod;
		if(vert){
			return (2 * go(p + 2, 1, 0)) % mod;
		} else return (3 * go(p + 2, 1, 0)) % mod;
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n >> a >> b;
    for(int i = 0; i < n; i++){
    	if(a[i] == b[i]){
    		v.pb(1);
    	} 
    	else{
    		v.pb(0);
    	}
    }
    // cout << v.size() << endl;
    // for(auto i : v) cout << i;
    // cout << endl;
    cout << go(0, 3, 1);
}

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

int n;
vector<int> A;

void input() {
    cin >> n;
    A = vector<int>(n);
    rep(i, n) cin >> A[i];
}

int main() {
    input();
    unordered_map<int, int> m;
    m[0] = 3;
    ll ans = 1;
    for (int a : A) {
        ans = (ans * m[a]--) % MOD;
        m[a+1]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4772
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <algorithm>
#include <limits.h>
#include <bits/stdc++.h>
#define fw(x) freopen("x.txt","w",stdout)
#define For(i,a,b,c) for(int i = a;i < b;i+=c)
#define REP(i,n) for(int i = 0;i < n;++i)
#define REP1(i,n) for(int i = 1; i<=n;i++)
#define mem(a,s) memset(a,s,sizeof a)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
#define pf printf
#define sc scanf
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define vii vector<int>
#define vll vector<ll>
#define vss vector<string>
#define debug(x)  cout<<#x"="<<(x)<<endl
#define pb push_back


using namespace std;


// moves

//int dx[]= {0,0,1,-1};/*4 side move*/
//int dy[]= {-1,1,0,0};/*4 side move*/
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/


//big_mod

//ll bigmod(ll a,ll b,ll m)
//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}
//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}
//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}
//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}

const int mod = 1000000007;
int n, m, x, y;
vii gr[100001];
int len[100001];
int ans=0;
int dp(int cur){
  if(len[ cur ] == -1){
    int sz = gr[cur].size();
    if(sz>0){
      int mx = 0;
      for(int j=0; j<sz; j++){
        if(len[ gr[cur][j] ] == -1) {
          len[gr[cur][j]] = dp(gr[cur][j]);
          mx = max(mx, len[gr[cur][j]]);
        }
        else mx = max(mx, len[gr[cur][j]]);
      }
      len[cur] = mx+1;
      return len[cur];
    }
    else return 0;
  }
  else return len[cur];
}
int main()
{
    fast;
    mem(len, -1);
    cin>>n>>m;
    REP1(i, m){
      cin>>x>>y;
      gr[x].pb(y);
    }
    for(int i=1; i<=n; i++){
        int sz=gr[i].size();
        if(sz>0){
          int mx=0;
          for(int j=0; j<sz; j++){
            if(len[ gr[i][j] ] == -1) {
              len[gr[i][j]] = dp(gr[i][j]);
              mx = max(mx, len[gr[i][j]]);
            }
            else mx = max(mx, len[gr[i][j]]);
          }
          len[i] = mx+1;
          ans = max(ans, mx+1);
        }
        else len[i] = 0;
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 12244
#include<stdio.h>
int main()
{
	int N,M;
	scanf("%d %d", &N,&M);
	int P=1,K=1,O=0,L=0;
	for(int i = 1;i<N;i++)
	{
		O = O + P;
		P++;
	}
	for(int j = 1;j<M;j++)
	{
		L = L + K;
		K++;
	}
	
	printf("%d",O+L);
	return 0;
}

Measured memory_bytes: 1720
def dfs(n,a,s):
    global ans
    temp = int(s)
    if temp > n:
        return
    if "7" in s and "5" in s and "3" in s and n>=temp:
        ans += 1
    for i in a:
        dfs(n,a,s+i)
ans = 0
a = ["7","5","3"]
n = int(input())
s = "0"
dfs(n,a,s)
print(ans)

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

using namespace std;

int main(){
    int A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;
    vector<int> v;
    v.push_back(A);
    v.push_back(B);
    v.push_back(C);
    v.push_back(D);
    v.push_back(E);
    int ans = 0;
    
    for(int i = 0; i < 5; i++){
        ans += (v[i] / 10) * 10;
        v[i] %= 10;
    }
    //cout << ans << endl;
    /*for(int i = 0; i < 5; i++){
        cout << v[i] << " ";
    }
    cout << endl;*/
    
    sort(v.begin(), v.end());
    
    int index;
    for(int i = 0; i < 5; i++){
        if(v[i] > 0){
            index = i;
            break;
        }
    }
    //cout << index << endl;
    
    ans += v[index];
    for(int i = index + 1; i < 5; i++){
        ans += 10;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define inf 10000000000000007
#define vsort(vec) sort(vec.begin(),vec.end())
#define vreverse(vec) reverse(vec.begin(),vec.end())
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

string s;

signed main() {
	cin >> s;
	int mu = stoi(s);
	int a = mu / 1000;
	int b = mu / 100 % 10;
	int c = mu / 10 % 10;
	int d = mu % 10;
	rep(i, 2) {
		rep(j, 2) {
			rep(k, 2) {
				int ta = a;
				if (i)ta += b;
				else ta -= b;
				if (j)ta += c;
				else ta -= c;
				if (k)ta += d;
				else ta -= d;
				if (ta == 7) {
					cout << a;
					if (i)cout << '+' << b;
					else cout << '-' << b;
					if (j)cout << '+' << c;
					else cout << '-' << c;
					if (k)cout << '+' << d;
					else cout << '-' << d;
					cout << "=7" << endl;
					ggr
				}
			}
		}
	}
	ggr
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

signed main() {
  int x,a;
  std::cin >> x >> a;
  if(x<a) print(0);
  else print(10);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int h, w, i;
	char a[100][101];

	scanf("%d %d", &h, &w);
	for ( i = 0; i < h; i++ ) {
		scanf("%s", a[i]);
	}

	for ( i = 0; i <= w + 1; i++ ) {
		printf("#");
	}

	printf("\n");
	for ( i = 0; i < h; i++ ) {
		printf("#%s#\n", a[i]);
	}

	for ( i = 0; i <= w + 1; i++ ) {
		printf("#");
	}
	
	printf("\n");

	return 0;
}


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

int main()
{
	long long x, y, i, j, k, flag0=0, flag;
	cin >> x;
	cin >> y;
//	for(i = x; i <= y; i++)
//	{
		j = 2;
		flag = 1;
		k = x;
		while(1)
		{
			if(j*k <= y)
			{
				k = j * k;
				flag++;
//				cout << flag <<endl;
			}
			else
			{
//				cout << flag <<endl;
				break;
			}
		}
		if(flag > flag0)
		{
			flag0 = flag;
		}
//	}
	cout << flag0 <<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define w(t) ll t;cin>>t; while(t--)

int main()
{

 // w(t)
  //{
    
     ll n,x,y,W,i,j,z=0,k=0,c=0,s=0;
    cin>>n;
    ll h[n];ll dp[100005];
   // map<ll,ll>mp;
    for(i=0;i<n;i++)
    {
      cin>>h[i];
     // cout<<h[i];
    }
   dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    //cout<<dp[1];
    for(i=2;i<n;i++)
    {
      dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),
        dp[i-2]+abs(h[i]-h[i-2]));
      
    }
    cout<<dp[n-1];
    
}      
      
 //   
  //  cout<<a[i]<<b[j];
    

/*if(flag==1)
    cout<<"NO"<<endl;
    else
    cout<<"YES"<<endl;*/
    
    
    
  
 

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <tuple>
#include <iomanip>


using namespace std;

typedef long long ll;

const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

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

//-------------------ここから-----------------------------------


int main(void){
	int r;
	cin >> r;

	if (r < 1200){
		cout << "ABC" << endl;
	}
	else if (r < 2800){
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
#define MODSIZE 1000000007
 
bool b[100000];
 
int main()
{
    int n;
    string s;
    cin >> n >> s;
 
    for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++){
        bool fl = 0;
        b[0] = i;
        b[1] = j;
        for (int it = 1; it < n - 1; it++){
            if ((b[it] && s[it] == 'o') || (!b[it] && s[it] == 'x')){
                b[it + 1] = b[it - 1];
            }
            else{
                b[it + 1] = !b[it - 1];
            }
        }
 
        if ((b[n - 1] && s[n - 1] == 'o') || (!b[n - 1] && s[n - 1] == 'x')){
            if (b[0] != b[n - 2])
                fl = 1;
        }
        else{
            if (b[0] == b[n - 2])
                fl = 1;
        }
 
        for (int it = 0; it < n; it++){
            if (b[it] && s[it] == 'o'){
                if (b[(it - 1 + n) % n] != b[(it + 1) % n])
                    fl = 1;
            }
            if (b[it] && s[it] == 'x'){
                if (b[(it - 1 + n) % n] == b[(it + 1) % n])
                    fl = 1;
            }
 
            if (!b[it] && s[it] == 'o'){
                if (b[(it - 1 + n) % n] == b[(it + 1) % n])
                    fl = 1;
            }
            if (!b[it] && s[it] == 'x'){
                if (b[(it - 1 + n) % n] != b[(it + 1) % n])
                    fl = 1;
            }
        }
 
        if (!fl){
            for (int it = 0; it < n; it++)
                cout << (b[it] ? 'S' : 'W');
            return 0;
        }
    }
 
    cout << -1 << '\n';
    return 0;
}

Measured memory_bytes: 640
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto K = readln.chomp.to!long;
    auto k = K;
    int r;
    while (k) {
        ++r;
        foreach (long i; 0..10) {
            if ((k+K*i)%10 == 7) {
                k = (k+K*i)/10;
                goto ok;
            }
        }
        writeln(-1);
        return;
        ok:
    }
    writeln(r);
}

Measured memory_bytes: 2728
#include<iostream>
#include<string>
using namespace std;
int main(){
  int hit,brow;
  string s1,s2;
  while(1){
    int math[4]={0};
    cin >> s1 >> s2;
    if(s1=="0" && s2=="0"){
      break;
    }
    hit=0;
    brow=0;
    for(int i=0;i<4;i++){
      if(s1[i]==s2[i]){
	math[i]++;
	hit++;
      }
    }
    for(int i=0;i<4;i++){
      if(math[i]==0){
	for(int j=0;j<4;j++){
	  //if(math[j]==0){
	    if(s1[i]==s2[j]){
	      math[i]++;
	      brow++;
	    }
	    //}
	}
      }
    }
    cout << hit << " " << brow << endl;
  }
}

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

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

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

    int max1_index = 0;
    for(int i = 0; i < A.size(); i++)
    {
        if(A[max1_index] < A[i])
        {
            max1_index = i;
        }
    }

    int max2_index = -1;
    for(int i = 0; i < A.size(); i++)
    {
        if(max1_index == i)
        {
            continue;
        }

        if(max2_index == -1)
        {
            max2_index = i;
        }

        else if(A[max2_index] < A[i])
        {
            max2_index = i;
        }
    }

    for(int i = 0; i < A.size(); i++)
    {
        if(i == max1_index)
        {
            cout << A[max2_index] << endl;
        }

        else
        {
            cout << A[max1_index] << endl;
        }
    }

    return 0;
}

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

string bt[] = 
{
	" ",
	"',.!?",
	"abcABC",
	"defDEF",
	"ghiGHI",
	"jklJKL",
	"mnoMNO",
	"pqrsPQRS",
	"tuvTUV",
	"wxyzWXYZ"
};

int main()
{
	string str,ans;
	while(cin >> str)
	{
		ans = "";
		str = "0" + str + "X";

		int n=0;
		for(int i=1; i<str.length(); i++)
		{
			if(str[i-1] == str[i])
			{
				if(str[i]=='0')
				{
					ans += " ";
				}
				else
				{
					n++;
				}
			}
			else
			{
				if(str[i-1]!='0')
				{
					ans += bt[str[i-1]-'0'][n%bt[str[i-1]-'0'].length()];
				}
				n=0;
			}
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 0
while True:
    a, op, b= input().split()
    a = int(a)
    b = int(b)

    if op == '?':
        break
    else:
        if op == '+':
            print(a + b)
        elif op == '-':
            print(a - b)
        elif op == '*':
            print(a * b)
        elif op == '/':
            print(a // b)


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

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

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


Measured memory_bytes: 3632
S = raw_input()
T = raw_input()
Slist = []
Tlist = []
for i in range(0, len(S)):
	Slist.append(S[i])
	Tlist.append(T[i])
flag = False
for i in range(0, len(S)):
	if Slist == Tlist:
		flag = True
		break
	x = Slist.pop(0)
	Slist.append(x)
if flag: print 'Yes'
else: print 'No'

Measured memory_bytes: 27372
#include<bits/stdc++.h>
using namespace std;
using pi=pair<int,int>;
#define mp make_pair
main(){
  int h,w,d,q;
  cin>>h>>w>>d;
  map<pi,int> a;
  map<int,pi> b;
  for(int i=0;i<h;++i)for(int j=0;j<w;++j){
    cin>>a[mp(i,j)];
    b[--a[mp(i,j)]]=mp(i,j);
  }
  vector<int> cost(h*w,0);
  for(int i=0;i<d;++i){
    for(pi s=b[i],t=b[i+d];a[t]<h*w&&a[s]<a[t];s=t,t=b[a[t]+d]){
      cost[a[t]] = abs(s.first-t.first)+abs(s.second-t.second) + cost[a[s]];
    }
  }
  cin>>q;
  while(q--){
    int l,r;
    cin>>l>>r;
    cout<<cost[r-1]-cost[l-1]<<"\n";
  }
}

Measured memory_bytes: 17664
import java.io.*;
import java.util.*;

public class Main {
	public static void main ( String[] args ) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> List;
		while ( true ) {
			int remove = 0;
			List = new ArrayList<Integer>();
			int size = sc.nextInt();
			int space = sc.nextInt();
			if ( size == 0 && space == 0 ) break;
			space--;
			for ( int i = 1; i <= size; i++ )
				List.add(i);
			while ( List.size() != 1 ) {
				remove += space;
				while ( remove >= List.size() )
					remove -= List.size();
				List.remove(remove);
			}
			System.out.println(List.get(0));
		}
	}
}

Measured memory_bytes: 12000
import sys

dp = [0] * 31
dp[0] = dp[1] = 1
dp[2] = 2

for i in range(3,31):
	dp[i] = dp[i-1] + dp[i-2] + dp[i-3]

for n in sys.stdin:
	n = int(n)
	if n == 0:
		break
	else:
		print((3649+dp[n])//3650)

Measured memory_bytes: 7496
use std::io::{self, Read};
use std::str::FromStr;

pub struct Scanner<R: Read> {
    reader: R,
}
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let s = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.expect("failed to read char") as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        s.parse::<T>().ok().expect("failed to parse token")
    }
}

fn lcs(x: &String, y: &String) -> u64 {
    // なお、x.len>y.lenであるものとする
    let xlen = x.len();
    let ylen = y.len();
    assert!(xlen >= ylen);

    // 方針: 解説より
    // xi == yi のとき、そのLCSはx[..i]とy[..j]のLCSにxi(=yi)を加えたもの
    // xi != yi のとき、そのLCSはx[..i+1]とy[..j] or x[..i]とy[..j+1]のLCSの長い方となる

    let xc: Vec<char> = x.chars().collect();
    let yc: Vec<char> = y.chars().collect();

    // dp[i][j] をx[0..i+1], y[0..j+1]の最長共通部分列の長さとする
    // X = {x1, x2, ..., xn}, Y = {y1,y2,...,ym}としたとき、
    // dp[i][j]がX[..i+1], Y[..j+1]のLCSの長さとする (つまり添え字0は0埋め)
    let mut dp: Vec<Vec<u64>> = vec![vec![0; ylen+1]; xlen+1];

    for i in 1..xlen+1 {
        for j in 1..ylen+1 {
            if xc[i-1] == yc[j-1] {
                dp[i][j] = dp[i-1][j-1] + 1;
            } else {
                dp[i][j] = if dp[i-1][j] > dp[i][j-1] {
                    dp[i-1][j]
                } else {
                    dp[i][j-1]
                };
            }
        }
    } 

    dp[xlen][ylen]
}

fn main() {
    let sin = io::stdin();
    let sin = sin.lock();
    let mut sc = Scanner::new(sin);

    let n: usize = sc.read();
    for _ in 0..n {
        let x: String = sc.read();
        let y: String = sc.read();
        let res = if x.len() > y.len () {
            lcs(&x, &y) 
        } else {
            lcs(&y, &x)
        };
        println!("{}", res);
    }
}



Measured memory_bytes: 13140
#include <iostream>
using namespace std;
const int maN = 2e5+5;
int parent[maN];
int sz[maN];
int find_set(int v)
{
    if(v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b)
{
    int u = find_set(a);
    int v = find_set(b);
    if(u!=v)
    {
        if(sz[u] < sz[v])
        {
            swap(u, v);
        }
        parent[u] = v;
            sz[v] += sz[u];
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    
    for(int i = 0; i <= n; ++i)
    {
        parent[i] = i;
        sz[i] = 1;
    }
    for(int i = 0; i < m; ++i)
    {
        int a, b;
        cin >> a >> b;
        --a, --b;
        union_sets(a, b);
    }
    
    // for(int i = 0; i < n; ++i)
    // {
    //     cout << parent[i] << " ";
    // }
    int max_set = 1;
    for(int i = 0; i < n; ++i)
    {
        // cout << sz[i] << " ";
        if(max_set < sz[i])
            max_set = sz[i]; 
    }
    
    cout << max_set;

	return 0;
}


Measured memory_bytes: 5160
use std::io::*;
use std::str::FromStr;

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

fn main() {
  let (n, m): (i32, i32) = (read(), read());
  let mut balls: Vec<i32> = Vec::new();
  for _ in 0..n { balls.push(2); }
  for _ in 0..m { balls.push(1); }
  
  let mut c = 0;
  for i in 0..balls.len() {
    for j in 0..balls.len() {
      if i != j && (balls[i] + balls[j]) % 2 == 0 {
        c += 1;
      }
    }
  }
  
  println!("{}", c / 2);
}

Measured memory_bytes: 4352
import java.util.*;

public class Main {
	public static void main(String[] args) {
				
		Scanner sc = new Scanner(System.in);
		LinkedList<Integer> ll = new LinkedList<>();
		
		int n = 999;
		int x = 999;
		int cnt = 0;
		while(n != 0 || x != 0) {
			n = sc.nextInt();
			x = sc.nextInt();
			int ans = 0;
			if(n == 0 && x == 0) {
				break;
			} else {
				cnt++;
				for(int i = 1; i <= n; i++) {
					for(int j = 1; j < i; j++) {
						for(int k = 1; k < j; k++) {
							if(i + k + j == x) {
								ans++;
							}
						}
					}
				}
				ll.add(ans);
			}
		}
		
		for(int i = 0; i < cnt; i++) {
			System.out.println(ll.get(i));
		}
	}
}

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

int main(){
  int N, Y;
  cin >> N >> Y;
  //iが1万円札, jが5千円札, kが千円札とする．
  for(int i=0;i<=N;i++){
    for(int j=0;j<=N;j++){
	  if(i+j>N) break;
	  for(int k=0;k<=N;k++){
		if(i+j+k>N) break;
	    if(i*1000+j*5000+k*10000 > Y) break;
		if(i*1000+j*5000+k*10000==Y){
	      if(i+j+k==N){
		    cout << k << " " << j << " " << i << endl;
	        return 0;
		  }
		}
	  }

	}
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}


Measured memory_bytes: 384
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int Q;
int ans;
int cnt;
int main(){
	cin>>Q;
	for(int i =0 ;i < Q;i++){
		bool flag =true;
		map<int,int> ma;
		ll n;
		cin>>n;
		ma[n] =1;
		cnt = 0;
		while(1){
			if(n==0){
				break;
			}
			int len =log10(n)+1;
			//cout <<len<<endl;
			if(len==1){
				break;
			}
			ans = 0;
			for(int j = 0;j <len-1;j++){
				unsigned int a =n/(1*pow(10.0,j+1));
				unsigned int b =n%((int)(1*pow(10.0,j+1)));
				//cout <<"b = "<<b<<endl;
				ll x =a*b;
				if(x >ans){
					ans = x;
				}
			}
			if(ma[ans]==1){
				flag = false;
				break;
			}
			ma[ans] = 1;
			//cout <<"ans = "<<ans<<endl;
			cnt++;
			n = ans;
		}
		if(flag){
			cout <<cnt<<endl;
		}else{
			cout <<"-1"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define inf 1000000000
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(i) cout<<i<<endl;
const int mod=1e9 +7;
int main(){
IOS;
int n,i;
cin>>n;
int a[n];
for(i=0;i<n;i++){
    cin>>a[i];
}
int count=0;
for(i=1;i<n-1;i++){
    if(a[i]!=max(a[i-1],max(a[i],a[i+1]))&&a[i]!=min(a[i-1],min(a[i],a[i+1])))
        count++;
}
cout<<count<<endl;
}


Measured memory_bytes: 256
import sys
import heapq

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]

    def isOK(mid):
        cnt = 0
        for i in range(N):
            if A[i] > mid:
                cnt += -(-A[i] // mid) - 1
                if cnt > K:
                    return False
        return True

    ok = max(A)
    ng = 0

    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if isOK(mid):
            ok = mid
        else:
            ng = mid

    print(ok)


if __name__ == '__main__':
    main()


Measured memory_bytes: 30996
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define mo 1000000007
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
int power(ll a, int b){
	ll c=1;
	while (b){
		if (b&1) c=c*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return c;
}
int n;
ll d;
ll sqr(ll x) {return x*x;}
int main(){
	n=read(), d=read();
	int ans=0;
	for (int i=1;i<=n;i++){
		ll x=read(), y=read();
		if (sqr(x)+sqr(y)<=sqr(d)) ans++;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];int b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];b[i]=a[i];
    }
    sort(b,b+n); int c=0;
    for(int i=0;i<n;i++)
    {
        if(abs(a[i]-b[i])!=0)
        c++;
    }
    if(c<=2)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;



}

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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
bool sortbysec(const pair<string,ll> &a,
               const pair<string,ll> &b)
{
    return (a.second < b.second);
}
int main()
{
    ll n,i;
    cin>>n;
    map<string,set< pair<ll,ll> > > m;
    vector<string> v;
    for(ll i=0;i<n;i++)
    {
        string s;
        cin>>s;
        ll a;
        cin>>a;
        m[s].insert(mp(a,i+1));
    }
    map<string,set< pair<ll,ll> > >::iterator it;
    set< pair<ll,ll> >::reverse_iterator itr;
    for(it=m.begin();it!=m.end();++it)
    {
        for(itr=(it->second).rbegin();itr!=(it->second).rend();++itr)
        {
            cout<<itr->second<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
taro = 0
hanako = 0
for i in range(n):
    t, h = input().split()

    if t < h:
        hanako += 3
    elif t > h:
        taro += 3
    else:
        hanako += 1
        taro += 1
print(taro,hanako)

Measured memory_bytes: 7648
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (ll i = (ll)(a); i<(ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
void bOUT(bool c, string s, string t) { OUT(c ? s : t); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }

int main(void) {
	int N, I;
	cin >> N >> I;
	cout << N - I + 1 << endl;
	return 0;
}

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

int N;
string str;
map<string, int> m;

int main() {
    
    ios_base::sync_with_stdio(false);
    cin >> N;
    while(N--) {
        cin >> str;
        m[str]++;
    }
    cout << m.size();
}

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

ll GCD(ll a,ll b){
    if(a>b){
        return GCD(b,a);
    }
    else{
    ll r=b%a;
    while(r!=0){
        b=a;
        a=r;
        r=b%a;
    }
    return a;
    }
}

int main(){
    ll N,K;cin>>N>>K;
    ll a[100010],MAX=-1;
    rep(i,0,N){
        cin>>a[i];
        MAX=max(MAX,a[i]);
    }
    if(N==1&&(a[0]==K)){
        cout<<"POSSIBLE"<<endl;
        return 0;
    }
    else if(N==1) {
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
    ll g=GCD(a[0],a[1]);
    rep(i,2,N){
        g=GCD(g,a[i]);
    }
    if((MAX-K)%g||MAX<K)cout<<"IMPOSSIBLE"<<endl;
    else cout<<"POSSIBLE"<<endl;
}







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

int main()
{
    int n, k, x, y;
    cin >> n >> k >> x >> y;
  	int sum = 0;
  	for(int i = 1; i <= n; i++) {
      if(i > k) sum += y;
      else sum += x;
    }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <tuple>
using namespace std;

long long solve(long long p) {
	// [0, p) の xor
	long long V = 0;
	for (int i = 1; i < 60; i++) {
		long long E = p % (2LL << i);
		if (0 <= E && E < (1LL << i)) V += 0;
		else V += ((p % 2LL) << i);
	}
	if (p % 4 == 2 || p % 4 == 3) V += 1;
	return V;
}

int main() {
	long long A, B; cin >> A >> B;
	cout << (solve(B + 1) ^ solve(A)) << endl;
	return 0;
}

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

int main() {
    int n,i;
    i = 1;
    cin >> n;
    int A[n];
    while(i <= n){
        cin >> A[i] ;
        i = i + 1;
    }
    int j;
    j = n;
    while(j > 1){
        cout << A[j]<< " " ;
        j = j-1;
    }
    cout << A[1] << endl;
    
}


Measured memory_bytes: 3108