akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define Rep(i,a) for(int i = 0; i < (a); i++)
#define rep(i,a,b) for(int i = (a); i <= (b); i++)//(a)!
#define dep(i,a,b) for(int i = (a); i >= (b); i--)
#define ab(a) ((a) > 0 ? (a) : -(a))
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
const int N = 100010, M = 400010;
char s[M], t[M];
int L[N], R[N], l0 = 0;

struct node { int ch[26], s; }T[M * 26]; int rt = 0, tl = 0;

#define oc T[o].ch[s[i] - 'a']
#define os T[o].s
void add(char *s, int l) {
	int o = rt;
	rep(i,1,l) { if (!oc) oc = ++tl; o = oc, os++; }
}

int S[N][26][26], p[N], s0[N];

int main() {
	int n; scanf("%d",&n);
	rep(i,1,n) {
		scanf("%s",t + 1); int l = strlen(t + 1);
		L[i] = l0 + 1; rep(j,1,l) s[++l0] = t[j]; R[i] = l0;
		add(t, l);
	}
	rep(t,1,n) {
		int o = 0;
		rep(i,L[t],R[t]) {
			s0[t] += (o ? T[o].s : n) - T[oc].s;
			rep(j,0,25) if (T[o].ch[j] != oc) s0[t] -= T[ T[o].ch[j] ].s, S[t][j][s[i] - 'a'] += T[ T[o].ch[j] ].s ;
			o = oc;
		}
	}
	int Q; scanf("%d",&Q);
	rep(i,1,Q) {
		int k1; scanf("%d",&k1);
		scanf("%s",t);
		rep(j,0,25) p[t[j] - 'a'] = j;
		int ans = 1 + s0[k1];
		rep(j,0,25) rep(k,0,25) if (p[j] < p[k]) ans += S[k1][j][k];
		printf("%d\n",ans);
	}
	return 0;
}

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

int main(){
  int N,sum=0;
  cin >> N;
  rep(i,N){
    int l,r;
    cin >> l >> r;
	sum += r-l+1;
  }
  cout << sum << endl;
}
    


Measured memory_bytes: 256
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        1e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
    freopen("gout.txt", "w", stdout);
   
    #endif
}

void solve()
{
  int n,k;
  cin >> n >> k;
  int a[n];

  forf(i,0,n) cin >> a[i];

  sort(a,a+n);
  int an = 0;

  forf(i,0,k) an += a[i];

  cout<<an;

}


int32_t main()
{
  //pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
   // cout << "Time taken by function: "
   //       << duration.count() << " microseconds" << endl; 

 }
      
      

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
int gcd(int p,int q,int r)
{ int i;
	int minu=min(p,min(q,r));
	for( i=minu;i>=1;i--)
	{
		if(p%i==0&&q%i==0&&r%i==0)
		break;
	}
	return i;
}
int main()
{
	int k;
	cin>>k;
	long long int s=0;
	for(int i=1;i<=k;i++)
	{
		for(int j=1;j<=k;j++)
	    {
	    	for(int l=1;l<=k;l++)
	    	s=s+gcd(i,j,l);
		}
	}
	cout<<s<<endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
    int a, b;
    string op;
    while (1)
    {
        cin >> a >> op >> b;
        if (op == "+"){
            cout << a + b << endl;
        } else if (op == "-"){
            cout << a - b << endl;
        } else if (op == "*"){
            cout << a * b << endl;
        } else if (op == "/"){
            cout << a / b << endl;
        } else if (op == "?"){
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3148
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
LL bucket[10];
pair<int,int> node[N];
map<pair<int,int>,int> mp;
int main(){
    LL h,w,n;
    scanf("%lld%lld%lld",&h,&w,&n);
    for(int i=1;i<=n;i++){
        int x,y;
        scanf("%d%d",&node[i].first,&node[i].second);
        mp[node[i]]++;
    }

    for(int i=1;i<=n;i++){
        for(int j=0;j<8;j++){
            int nx=node[i].first+dx[j];
            int ny=node[i].second+dy[j];
            if(nx>=1&&nx<=h&&ny>=1&ny<=w){
                pair<int,int> temp(nx,ny);
                mp[temp]++;
            }
        }
    }

    LL sum=0;
    LL tot=(h-2)*(w-2);
    map<pair<int,int>,int>::iterator it;
    for(it=mp.begin();it!=mp.end();it++){
        int x=it->first.first;
        int y=it->first.second;
        int val=it->second;
        if(x>=2&&x<=h-1&&y>=2&y<=w-1){
            bucket[val]++;
            sum++;
        }
    }
    bucket[0]=tot-sum;

    for(int i=0;i<=9;i++)
        printf("%lld\n",bucket[i]);

    return 0;
}


Measured memory_bytes: 57344
#include <stdio.h>

void DICE(char x, int *dice1, int *dice2, int *dice3, int *dice4, int *dice5, int *dice6){
    int tmp1, tmp2, tmp3, tmp4;
    if(x=='S'){
        tmp1=*dice1;
        tmp2=*dice2;
        tmp3=*dice5;
        tmp4=*dice6;
        *dice1=tmp3;
        *dice2=tmp1;
        *dice5=tmp4;
        *dice6=tmp2;
    }
        else if(x=='W'){
        tmp1=*dice1;
        tmp2=*dice3;
        tmp3=*dice4;
        tmp4=*dice6;
        *dice1=tmp2;
        *dice3=tmp4;
        *dice4=tmp1;
        *dice6=tmp3;
    }
    else if(x=='N'){
        tmp1=*dice1;
        tmp2=*dice2;
        tmp3=*dice5;
        tmp4=*dice6;
        *dice1=tmp2;
        *dice2=tmp4;
        *dice5=tmp1;
        *dice6=tmp3;
    }
    else if(x=='E'){
        tmp1=*dice1;
        tmp2=*dice3;
        tmp3=*dice4;
        tmp4=*dice6;
        *dice1=tmp3;
        *dice3=tmp1;
        *dice4=tmp4;
        *dice6=tmp2;
    }
}


int main(void){
    
    int dice1, dice2, dice3, dice4, dice5, dice6, i;
    int d1, d2, d3, d4, d5, d6;
    
    scanf("%d %d %d %d %d %d\n%d %d %d %d %d %d", &dice1, &dice2, &dice3, &dice4, &dice5, &dice6, &d1, &d2, &d3, &d4, &d5, &d6);
    
    if(d2!=dice2){
        for(i=1; i<=6; i++){
                DICE('N', &dice1, &dice2, &dice3, &dice4, &dice5, &dice6);
                if(d2==dice2) break;
        }
        if(d2!=dice2){
            DICE('E', &dice1, &dice2, &dice3, &dice4, &dice5, &dice6);
            for(i=1; i<=6; i++){
                DICE('N', &dice1, &dice2, &dice3, &dice4, &dice5, &dice6);
                if(d2==dice2) break;
            }
        }
    }
        
    if(d1!=dice1){
        for(i=1; i<=6; i++){
            DICE('E', &dice1, &dice2, &dice3, &dice4, &dice5, &dice6);
            if(d1==dice1) break;
        }
    }
        
    if(d3==dice3 && d4==dice4 && d5==dice5 && d6==dice6) printf("Yes\n");
    else printf("No\n");
}


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

int main(){
  int x;cin>>x;
  double ans=0;
  for(int i=1;i*i<=x;i++){
    for(int j=2;j<=10;j++){
      if(pow(i,j)<=x){
        ans=max(ans,pow(i,j));
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640
K,N = map(int,input().split())
A = list(map(int,input().split()))
kyori=[0]*(N)
kyori[N-1]=(K-A[N-1])+A[0]
for i in range(N-1):
    kyori[i]=A[i+1]-A[i]
print(sum(kyori)-max(kyori))

Measured memory_bytes: 32212
import java.util.Scanner;

public class Main {
    //Ordinary Number
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < n; i++) A[i] = sc.nextInt();
        System.out.println(sln(A));
        sc.close();
    }

    static int sln(int[] A) {
        int n = A.length, res = 0;
        for (int i = 1; i < n - 1; i++) {
            if ((A[i] <= A[i - 1] && A[i] <= A[i + 1]) || (A[i] >= A[i - 1] && A[i] >= A[i + 1])) continue;
            res++;
        }
        return res;
    }
}


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

const ll mod = 1000000007;
const int INF = 1001001001;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	string s; cin >> s;
	int tmp = 0;
	for(int i = 0; i < s.size(); i++){
		tmp += s[i] - '0';
		tmp %= 9;
	}
	if(!tmp) cout << "Yes" << endl;
	else cout << "No" << endl;
} 

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

using namespace std;


int main()
{
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	if (s == "ABC") {
		cout << "ARC" << endl;
	}
	else {
		cout << "ABC" << endl;
	}

	return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int dp[N];
signed main()
{
    dp[0]=2, dp[1]=1;
    int n=read();
    for(ri int i=2;i<=n;i++) dp[i]=dp[i-1]+dp[i-2];
    printf("%lld\n",dp[n]);
    return 0;
}

Measured memory_bytes: 3744
#include <iostream>
#include <iomanip> //setprecision
#include <cstdlib>
#include <vector>
#include <cmath>

int main(void) {
    double number;
    std::vector<double> v(1000);
    std::cin >> number;
    double sum;
    double average;
    double dispersion;
    while(number != 0) {
        sum = 0;
        dispersion = 0.0;
        for (double i = 0; i < number; i++) {
            std::cin >> v[i];
            sum += v[i];
        }
        average = sum / number;
        for (int i = 0; i < number; i++) {
            dispersion += (average - v[i]) * (average - v[i]);
        }
        dispersion /= number;
        std::cout << std::fixed << std::setprecision(12);
        std::cout << sqrt(dispersion) << std::endl;
    std::cin >> number;
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 3292
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCorder
{
    class Program
    {
        static Dictionary<string, int> Prices { get; } = new Dictionary<string, int>
        {
            ["L"] = 500,
            ["M"] = 100,
            ["S"] = 50,
        };

        static void Main(string[] args)
        {
            var a = int.Parse(Console.ReadLine());
            var b = int.Parse(Console.ReadLine());
            var c = int.Parse(Console.ReadLine());
            var x = int.Parse(Console.ReadLine());
            var count = 0;

            for (var i = 0; i <= a; i++)
            {
                for (var j = 0; j <= b; j++)
                {
                    for (var k = 0; k <= c; k++)
                    {
                        var total = Prices["L"] * i + Prices["M"] * j + Prices["S"] * k;
                        if (total == x)
                        {
                            count++;
                        }
                    }
                }
            }
            Console.WriteLine(count);
        }
    }
}


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

int main(){

    std::string s, t;
    std::cin >> s >> t;

    size_t cnt = 0;
    for(size_t i = 0; i < s.size(); i++){
        if(s[i] != t[i]) cnt++;
    }

    std::cout << cnt << std::endl;

    return 0;
}


Measured memory_bytes: 3856
import bisect
import sys
input = sys.stdin.readline


n, q = map(int, input().split())
events = [list(map(int, input().split())) for _ in range(n)]
events.sort(key=lambda x: x[2])

departures = [int(input()) for _ in range(q)]


ans = ['-1'] * q
skip = [-1] * q

for start, end, pos in events:
    left = bisect.bisect_left(departures, start-pos)
    right = bisect.bisect_left(departures, end-pos)

    while left < right:
        if skip[left] == -1:
            ans[left] = str(pos)
            skip[left] = right
            left += 1

        else:
            left = skip[left]

print('\n'.join(ans))

Measured memory_bytes: 87212
def main():
    n,q = [int(i) for i in input().split()]
    #自分自身が親
    par = [ i for i in range(n)]
    #ランク
    rank = [ 0 for i in range(n)]
    #親を返す関数
    def find(x):
        if par[x] == x:
            return x
        else:
            par[x] = find(par[x])
            return par[x]

    #木を結合する
    def unite(x,y):
        x = find(x)
        y = find(y)
        if x == y:
            return
        if rank[x]<rank[y]:
            par[x] = y
            return
        elif rank[y]<rank[x]:
            par[y] = x
            return
        else:
            par[x] = y
            rank[y] +=1
            return

    def same(x,y):
        return find(x) == find(y)

    for i in range(q):
        com,x,y = [int(j) for j in input().split()]
        #unite
        if com == 0:
            unite(x,y)
        #same
        else:
            if same(x,y):
                print(1)
            else:
                print(0)

if __name__ == '__main__':
    main()


Measured memory_bytes: 6040
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string s, t; cin >> s >> t;
    int n_s = s.size();
    int n_t = t.size();
    queue<char> q;
    rep(i,n_t) q.push(t[i]);
    vvint data(26);
    rep(i,2*n_s) {
        data[s[i%n_s]-'a'].push_back(i);
    }
    rep(i,n_t) {
        if (data[t[i]-'a'].size() == 0) {cout << -1 << endl; return 0;}
    }
    ll ans = 0;
    int now = -1;
    while (!q.empty()) {
        now = *lower_bound(all(data[q.front()-'a']),now+1);
        if (now >= n_s) {
            ans += n_s; 
            now %= n_s;
        }
        q.pop();
    }
    cout << ans + now + 1 << endl;
}

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

int main()
{
	int N = 0;
	string s;
	cin >> N;
	cin >> s;
	if (N == 1)
		cout << 1 << endl;
	else
	{
		int i = 1;
		int ct = 1;
		char last = s[0];
		while (i < N)
		{
			if (s[i] == last)
				++i;
			else
			{
				last = s[i];
				ct++;
				++i;
			}
		}
		cout << ct << endl;
	}

	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
	int N, M, X;
	cin >> N >> M >> X;

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

	int sum = 0;
	for (int i = X; i > 0; i--) sum += A[i-1];

	int sum2 = 0;
	for (int i = X; i < N - 1; i++) sum2 += A[i+1];

	cout << min(sum, sum2) << endl;

	return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	bool first = false;
	bool up = false;
	bool down = false;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (!first) first = true;
		else {
			if (up == false && down == false) {
				if (a.at(i) == a.at(i - 1)) {}
				else if (a.at(i) > a.at(i - 1)) up = true;
				else down = true;
			}
			else if (up == true) {
				if (a.at(i) < a.at(i - 1)) {
					ans++;
					up = false;
					down = false;
				}
			}
			else {
				if (a.at(i) > a.at(i - 1)) {
					ans++;
					up = false;
					down = false;
				}
			}
		}
	}
	ans++;
	cout << ans << endl;
}

Measured memory_bytes: 640
import sys
def input():
	return sys.stdin.readline().strip()

A, B = list(map(int, input().split()))

keta = 0
B2 = B
while B2 > 0:
	B2 = B2 // 2
	keta += 1

total = 0
for bit in range(keta):
	if bit == 0:
		A_mod = A % 4
		B_mod = B % 4
		B_mod += 4
		num = 0
		for i in range(A_mod, B_mod + 1):
			num += i%2
		#print(num, A_mod, B_mod, total)
		total += num%2
		#print(total)
		continue

	A_mod = A % (2**(bit+1))
	B_mod = B % (2**(bit+1))
	if B_mod <= A_mod:
		B_mod += 2**(bit+1)

	#print("mod",A_mod, B_mod, 2**(bit+1))

	if A_mod < 2**bit and B_mod < 2**bit:
		num = 0
		#print(1,num)
	elif A_mod < 2**bit and B_mod < 2**(bit+1):
		num = B_mod - 2**bit + 1
		#print(2,num)
	elif A_mod < 2**bit:
		num = 2**bit
		#print(3,num)
	elif A_mod < 2**(bit+1) and B_mod < 2**(bit+1):
		num = B_mod - A_mod + 1
		#print(4,num)
	elif A_mod < 2**(bit+1) and B_mod < 3*(2**bit):
		num = 2**(bit+1) - A_mod
		#print(5,num)
	else:
		num = B_mod - A_mod - 2**bit + 1
		#print(6,num)

	num = num % 2
	total += num*(2**bit)
	#print(total)
print(total)



Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=1000005,INF=1<<30;

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

int cnt[MAX];

vector<int> prime;//i番目の素数
bool is_prime[MAX+1];

void sieve(int n){
    for(int i=0;i<=n;i++){
        is_prime[i]=true;
    }
    
    is_prime[0]=is_prime[1]=false;
    
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            prime.push_back(i);
            for(int j=2*i;j<=n;j+=i){
                cnt[i]+=cnt[j];
                is_prime[j] = false;
            }
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
        cnt[A[i]]++;
    }
    
    sieve(MAX-2);
    
    bool check=true;
    
    for(int i=2;i<MAX;i++) if(cnt[i]>=2) check=false;
    
    if(check){
        cout<<"pairwise coprime"<<endl;
    }else{
        int g=0;
        for(int i=0;i<N;i++){
            g=gcd(g,A[i]);
        }
        
        if(g==1) cout<<"setwise coprime"<<endl;
        else cout<<"not coprime"<<endl;
    }
}





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

int main(void){
    int N,K;
    cin >> N >> K;
    vector<char> cant(K);
    string str;
    for(int i=0; i<K; i++) cin >> cant[i];

    //N~10Nまでの数に対して
    for (int n=N; n<10*N+1; n++){
        str = to_string(n);

        bool flag=true;
        for (int i=0; i<str.size(); i++){
            //str[i]がcant[]にあるかどうか
            bool breakflag=false;
            for(int j=0; j<K; j++){
                if(str[i]==cant[j]){
                    breakflag=true;
                    flag=false;
                    break;
                }
            }

            if(breakflag) break;

        }

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

    return 0;
}

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

using namespace std;

int main() {
	int n;
	while (cin >> n, n) {
		long long l = -1e10, r = 1e10;
		vector<string> a(n);
		for (auto& e : a) cin >> e;
		string prev;
		for (int i = 0; i < n; ++i) {
			if (a[i] == "x") {
				if (prev == "x") {
					l = 1e18;
					break;
				}
				if (i & 1) {
					if (i - 1 >= 0 && a[i - 1] != "x") l = max(l, stoll(a[i - 1]) + 1);
					if (i + 1 < n && a[i + 1] != "x") l = max(l, stoll(a[i + 1]) + 1);
				} else {
					if (i - 1 >= 0 && a[i - 1] != "x") r = min(r, stoll(a[i - 1]) - 1);
					if (i + 1 < n && a[i + 1] != "x") r = min(r, stoll(a[i + 1]) - 1);
				}
			} else {
				if (i & 1) {
					if (i - 1 >= 0 && a[i - 1] != "x") {
						if (stoi(a[i - 1]) >= stoi(a[i])) {
							l = 1e18;
							break;
						}
					}
				} else {
					if (i - 1 >= 0 && a[i - 1] != "x") {
						if (stoi(a[i - 1]) <= stoi(a[i])) {
							l = 1e18;
							break;
						}
					}
				}
			}
			prev = a[i];
		}
		if (l == r) cout << l << endl;
		else if (l < r) cout << "ambiguous" << endl;
		else cout << "none" << endl;
	}

	return 0;
}


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

int main(){

    ll n;

    cin >> n;

    vector<ll> a(1e+5,0);
    ll t;

    rep(i,n){
        cin >> t;
        a[t]++;
    }

    ll ma=0;

    for(int i=1;i<a.size()-1;i++){
        ll te=a[i]+a[i-1]+a[i+1];
        ma=max(te,ma);
    }

    cout << ma << endl;

    return 0;
}

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

int main(void){
  int n, now;
  cin >> n;
  now = n;
  int sum = 0;
  while(n > 0){
    sum += n%10;
    n /= 10;
  }
  if(now%sum==0) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>

using namespace std;

const int MAXN = 100005;

int n, root, sol;
vector <int> v[MAXN];

int dfs (int x, int par) {
	if (v[x].size()==1) return 1;
	int res=0, cnt=0;
	for (int i=0; i<v[x].size(); i++) {
		int sus=v[x] [i];
		if (sus==par) continue;
		int t=dfs(sus, x);
		if (t==1) cnt++;
		res+=t;
	}
	if (cnt>0) sol+=cnt-1;
	return res;
}

int main () {
	cin >> n;
	for (int i=0; i<n-1; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a++; b++;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for (int i=1; i<=n; i++) {
		if (v[i].size()>2) {
			root=i;
			break;
		}
	}
	if (root==0) {
		cout << 1;
		return 0;
	}
	dfs(root, 0);
	cout << sol;
	return 0;
}

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

int main(void){

    int A,B,C;
    cin>>A>>B>>C;

    int ans;

    ans = C-(A-B);
    if(ans<0){
        cout<<0<<endl;
    }else{
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int x1,x2,x3,tot1;
	cin>>x1>>x2>>x3>>tot1;
	int tot2=0;
	for(int i=0;i<=x1;i++)
	{
		for(int j=0;j<=x2;j++)
		{
			for(int z=0;z<=x3;z++)
			{
				if((i*500+j*100+z*50)==tot1)
				{
					tot2++;
				}
				if((i*500+j*100+z*50)>tot1)
				{
					break;
				}
			}
		}
	}
	cout<<tot2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

constexpr ll MAX = 10000000;
constexpr ll MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void init(ll n)
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < n; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll comb(ll n, ll k)
{
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}

void solve(void)
{
  ll X, Y; cin >> X >> Y;
  ll Z = Y - X;
  ll a{}, b{};
  if (Z > 0) {
    ll c = 2*Z + X;
    if (c % 3 != 0) {
      cout << 0 << CRLF;
      return;
    }
    a = c / 3;
    b = a - Z;
  } else if (Z < 0) {
    Z = -Z;
    ll c = Z + X;
    if (c % 3 != 0) {
      cout << 0 << CRLF;
      return;
    }
    b = c / 3;
    a = b - Z;
  } else {
    if (X % 3 != 0) {
      cout << 0 << CRLF;
      return;
    }
    ll c = 2*Y - X;
    if (c % 3 != 0) {
      cout << 0 << CRLF;
      return;
    }
    b = c / 3;
    a = b - Z;
  }

  init(a + b + 1);
  auto ans = comb(a + b, a);

  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 18688
#include<stdio.h>
#include<string.h>
#include<math.h>
int a,s,d[10000000],f,g,h;
int main(void)
{
	int i,j,k;
	for(i=2;i<=10000000;i++) d[i]=1;
	d[1]=0;
	d[2]=1;
	for(i=2;i*i<=10000000;i++){
		if(d[i]==1){
			for(j=2;j<=5000000;j++){
				if(i*j>10000000) break;
				d[i*j]=0;
			}
		}
	}
	//for(i=0;i<10000000;i++) if(d[i]==1) printf("%d  ",i);
	while(1){
		g=0;
		scanf("%d",&a);
		if(a==0) break;
		for(i=a;i>12;i--){
			if(d[i]==1&&d[i-2]==1&&d[i-6]==1&&d[i-8]==1){
				g=i;
				break;
			}
		}
		printf("%d\n",g);
	}
	return 0;
}

Measured memory_bytes: 41668
import sys

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

N = INT()
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = MAP()

A.sort()
B.sort()
if N % 2 == 0:
    mn = (A[N//2-1]+A[N//2]) / 2
    mx = (B[N//2-1]+B[N//2]) / 2
    ans = int((mx-mn)*2) + 1
else:
    mn = A[N//2]
    mx = B[N//2]
    ans = (mx-mn) + 1
print(ans)


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

// --------------------------------------------------------------------------------
#define fastio	ios_base::sync_with_stio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long 
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define deb(name,value) cout <<"->>  "<<name<< "= " <<value<<" "
#define frepi(a,b,k) for(int i=a;i<=b;i+=k)
#define frepj(a,b,k) for(int j=a;j<=b;j+=k)
// --------------------------------------------------------------------------------


void solve_main()
{
   	int k,x;cin>>k>>x;
   	if(k*500>=x)cout<<"Yes";
   	else cout<<"No";
}

int main()
{
	// #ifndef ONLINE_JUDGE
 //    	freopen("/home/suryakant/input.txt","r",stdin);
 //        freopen("/home/suryakant/output.txt","w",stdout);
 //    #endif
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve_main();
    }
    
}

Measured memory_bytes: 3616
// A - Rainy Season
#include <bits/stdc++.h>
using namespace std;

int main(){
	string s; cin>>s;
	int ans = 1;
	if(s == "RRR") ans = 3;
	else if(s == "SSS") ans = 0;
	else if(s[0] == 'R' && s[1] == 'R') ans = 2;
	else if(s[1] == 'R' && s[2] == 'R') ans = 2;
	cout<< ans <<endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
	}
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const{
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        uint64_t x = hash1 ^ hash2;
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x;
    while (y > 0) {
        if (y & 1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}
bool equals(pair<pair<string, lli>, lli> v1, pair<pair<string, lli>, lli> v2){
	if(v1.fi.fi == v2.fi.fi && v1.fi.se == v2.fi.se)
		return true;
	return false;
}
lli solve(){
	lli n;
	cin>>n;
	vector<pair<pair<string, lli>, lli> > S(n), A;
	loop(i, 0, n){
		string temp;
		lli tp;
		cin>>temp>>tp;
		S[i] = {{temp, tp}, i+1};
	}
	A = S;
	sort(S.begin(), S.end(), [](const pair<pair<string, lli>, lli>& v1, const pair<pair<string, lli>, lli>& v2){
		if(v1.fi.fi == v2.fi.fi)
			return v1.fi.se > v2.fi.se;
		else
			return v1.fi < v2.fi;
	});
	loop(i, 0, n){
		cout<<S[i].se<<"\n";
		// loop(j, 0, n){
		// 	if(equals(A[i], S[j]))
		// 		cout<<j+1<<"\n";
		// }
	}
	return 0;
}
int main(){
	fastio;
	lli t;
	// cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int N, X; cin >> N >> X;
  vector<int> m(N); cin >> m;
  sort(m.begin(),m.end());
  int sum = 0;
  for (int i = 0; i < N; ++i) {
    sum += m[i];
    if (sum > X) {
      cout << i - 1  << endl;
      return 0;
    }
  }
  cout << N + (X - sum) / m[0] << endl;
}


Measured memory_bytes: 3588
import numpy as np

N, M = list(map(int, input().split(" ")))
A_list = np.sort(np.asarray(list(map(int, input().split(" ")))))[::-1]
B_list = np.sort(np.asarray(list(map(int, input().split(" ")))))[::-1]

out = 1
a_next_i = 0
b_next_i = 0
for x in range(N*M, 1, -1):
    cond1 = a_next_i < N and x == A_list[a_next_i]
    cond2 = b_next_i < M and x == B_list[b_next_i]
    if cond1 and cond2:
        kosuu = 1
        a_next_i += 1
        b_next_i += 1
    elif cond1:
        kosuu = b_next_i
        a_next_i += 1
    elif cond2:
        kosuu = a_next_i
        b_next_i += 1
    else:
        kosuu = a_next_i * b_next_i - (N * M - x)
    out *= kosuu
    out = out % 1000000007
   
print(out)

Measured memory_bytes: 14436
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

ll n;
map<pair<int,pair<ll,int> > ,ll> memo;

ll dfs(int h, ll rest, ll tt, int mode){

  ll ret = 0;
  
  if(h == 61){
    debug(rest);
    debug(mode);
    return 1;
  }
  
  if(memo.find({h,{rest,mode}}) != memo.end()) return memo[{h,{rest,mode}}];
  
  if(rest > 0) ret = (ret + dfs(h+1, (rest-1)/2, tt/2,0))%mod; //01
  
  ret = (ret + dfs(h+1, rest/2, tt/2,1))%mod; //00
  
  if(rest/2 > 0) ret = (ret + dfs(h+1, rest/2-1, tt/2,1))%mod; //11

  memo[{h,{rest,mode}}] = ret;
  return ret;
}

int main(){
  vector<ll> vec;
  
  cin >> n;

  ll ans = dfs(0,n,n,0);

  printf("%lld\n",ans);

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
#define INF 0xfffffff
int dis[200][200];
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
            {
                if(i==j) 
				dis[i][j]=0;
                else dis[i][j]=INF;
            }
		for(int i=0;i<n;i++)
		{
			int a,b,c;
			scanf("%d",&a);
			int t;
			scanf("%d",&t);
			for(int j=0;j<t;j++)
			{
				scanf("%d %d",&b,&c);
				dis[a][b]=min(c,dis[a][b]);
			}
		}
		for(int k = 0; k < n; k++)  //枚举中间点（必须放最外层）
		  for(int i = 0; i < n; i++)  //枚举端点i
		    if(i != k)
		      for(int j = 0; j < n; j++)  //枚举端点j
		        if(i != j && j != k && dis[i][j] > dis[i][k] + dis[k][j])
		          dis[i][j] = dis[i][k] + dis[k][j];
		int f,g;
		f=0;g=0;
		dis[0][0]=0;
		for(g=0;g<n;g++)
		{
			printf ("%d %d\n",g,dis[f][g]);
		}
	}
}


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

//#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pl;

#define FST first
#define SND second

const int MAX_N = 100000;                  // 10^5
// const int MAX_N = 100000;                  // 10^5
// const int MAX_N = 1000000000;              // 10^9
// const ll  MAX_N = 1000000000000000000;     // 10^18
// const int BASE  = 1000000000 + 7;          // 10^9 + 7
// const int INFI  = 1000000000 + 7;          // 10^9 + 7
const ll INFL  = 1000000000000000000 + 7; // 10^18 + 7

typedef struct{int to; ll cost;} edge;

int N, K, Q;
ll DEPTH[MAX_N];
vector<edge> G[MAX_N];

void calc_depth(int root) {
  for (int i = 0; i < N; i++) DEPTH[i] = INFL;
  DEPTH[root] = 0;
  queue<int> q;
  q.push(root);
  while (!q.empty()) {
    int u = q.front(); q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i].to;
      ll c = G[u][i].cost;
      if (DEPTH[u] + c < DEPTH[v]) {
        DEPTH[v] = DEPTH[u] + c;
        q.push(v);
      }
    }
  }
#ifdef DEBUG
for (int i = 0; i < N; i++) cout << i << " " << DEPTH[i] << endl;
#endif
}

ll solve(int x, int y) {
  return DEPTH[x] + DEPTH[y];
}

int main() {
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    edge e, f;
    e.to = b; e.cost = c;
    f.to = a; f.cost = c;
    G[a].push_back(e);
    G[b].push_back(f);
  }

  cin >> Q >> K;
  K--;

  calc_depth(K);

  for (int i = 0; i < Q; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    cout << solve(x, y) << endl;
  }

  return 0;
}


Measured memory_bytes: 9984
#include<stdio.h>

#define MAX  200
#define IN (1<<21)
#define WHITE  0
#define GRAY  1
#define BLACK  2

int pr(void);

int n;
int MM[MAX][MAX];

int main(){
  int i,j,e;
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      MM[i][j]=(e==-1) ? IN : e;
    }
  }

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

  return 0;
}

int pr(){

  int i,r,mi,dd[MAX],pp[MAX],color[MAX],u;

  for(i=0;i<n;i++){
    dd[i]=IN;
    pp[i]=-1;
    color[i]=WHITE;
  }

  dd[0]=0;

  while(1){
    mi=IN;
    u=-1;

    for(i=0;i<n;i++){
      if(mi>dd[i] && color[i] != BLACK){
        u=i;
        mi=dd[i];
      }
    }
    if(u==-1) break;

    color[u]=BLACK;

    for(r=0;r<n;r++){
      if(color[r] != BLACK && MM[u][r] != IN){
        if(dd[r]>MM[u][r]){
          dd[r]=MM[u][r];
          pp[r]=u;
          color[r]=GRAY;
        }
      }
    }
  }
  
  int sum = 0;
  
  for(i=0;i<n;i++){
    if(pp[i] != -1){
      sum+=MM[i][pp[i]];
    }
  }

  return sum;
}



Measured memory_bytes: 2112
n,m = map(int,input().split())
a=[]
b=[]

for i in range(n):
    a.append(input().split())

for j in range(m):
    b.append(input())

s=0

for i in range(n):
    for j in range(m):
        s+=int(a[i][j])*int(b[j])
    print (s)
    s=0



Measured memory_bytes: 6248
#include  <iostream>

using namespace std;

int main()
{
	int n;
	int a[20];

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

	int ans = 0;
	for (int i = 2; i < n; i++) {
		if (a[i - 2] < a[i - 1] && a[i - 1] < a[i])  ans++;
		else if (a[i - 2] == a[i] && a[i - 2] < a[i - 1])  ans++;
		else if (a[i] < a[i - 1] && a[i - 1] < a[i - 2])  ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 384
import sys

input = sys.stdin.readline


def main():
    S = input().strip()
    K = int(input())

    dic = []
    dic_set = set()
    for i in range(len(S)):
        j = 0
        tmp = ""
        while i + j < len(S) and j < 5:
            tmp += S[i + j]
            if tmp not in dic_set:
                dic.append(tmp)
                dic_set.add(tmp)
            j += 1

    dic.sort()
    print(dic[K - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 4592
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define inf 0x3f3f3f3f
using namespace std;

const int maxn = 100050;

int A[maxn];

int main(){
    int n;cin>>n;
    FOR(i,1,n)scanf("%d",&A[i]);
    int ans=0;
    FOR(i,2,n-1){
        if(A[i-1]<A[i]&&A[i]<A[i+1])ans++;
        if(A[i-1]>A[i]&&A[i]>A[i+1])ans++;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL n;
  cin >> n;
  vector<LL> a(n);
  REP(i,n) cin >> a[i];
  vector<LL> l(n),r(n);
  FOR(i,1,n) l[i] = max(a[i-1],l[i-1]);
  for(int i = n-2;i>=0;--i) r[i] = max(a[i+1],r[i+1]);
  REP(i,n) cout << max(l[i],r[i]) << endl;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N, D, X;
  cin >> N >> D >> X;
  int count = X, A, num;
  for (int i = 0; i < N; i++) {
    cin >> A;
    num = 1;
    while(1 + A * (num - 1) <= D) {
      num++;
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

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

using namespace std;

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

	string line;
	getline(cin,line);
	int n = stoi(line);
	getline(cin, line);
	unsigned occurrences_found = 0;
	for(auto it = line.begin(); it != line.end(); it++) {
		if(*it == 'A' && *(it + 1) == 'B' && *(it + 2) == 'C') {
			occurrences_found++;
		}
	}
	cout << occurrences_found;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=s;i<t;i++)
#define MAXNUM 222222
int tree[MAXNUM],allx[MAXNUM],tsize;
void add(int a,int num)
{
    for(int i=a;i<=tsize;i+=i&(-i))tree[i]+=num;
}
const int mod=998244353;
void add1(int &a,int b)
{
    a+=b;
    if(a>=mod)a-=mod;
}
void sub(int &a,int b)
{
    a-=b;
    if(a<0)a+=mod;
}
int query(int a)
{
    int num=0;
    for(int i=a;i;i-=i&(-i))num+=tree[i];
    return num;
}
struct node{
    int x,y,id;
    bool operator<(const node &a)const
    {
        return x<a.x;
    }
};
node num[MAXNUM];
int lef[MAXNUM],lefdown[MAXNUM],down[MAXNUM],p[MAXNUM];
int main()
{
    int n;scanf("%d",&n);
    p[0]=1;
    rep(i,1,n+1)p[i]=p[i-1],add1(p[i],p[i]);
    rep(i,1,n+1)scanf("%d%d",&num[i].x,&num[i].y),allx[++tsize]=num[i].y,num[i].id=i;
    sort(allx+1,allx+tsize+1);
    rep(i,1,n+1)num[i].y=lower_bound(allx+1,allx+tsize+1,num[i].y)-allx;
    sort(num+1,num+n+1);
    rep(i,1,n+1)lef[num[i].id]=i-1,lefdown[num[i].id]=query(num[i].y),add(num[i].y,1);
    rep(i,1,n+1)down[num[i].id]=query(num[i].y)-1;
    int res=0;
    rep(i,1,n+1)
    {
        int now=p[n];
        sub(now,p[lef[i]]),sub(now,p[n-1-lef[i]]);
        sub(now,p[down[i]]),sub(now,p[n-1-down[i]]);
        add1(now,p[lefdown[i]]),add1(now,p[lef[i]-lefdown[i]]);
        add1(now,p[down[i]-lefdown[i]]),add1(now,p[(n-1-down[i])-lef[i]+lefdown[i]]);
        add1(res,now);sub(res,1);
    }
    printf("%d\n",res);
}

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

int main()
{
   int k,x; //x is black //k is total
   scanf("%d %d",&k,&x);
   int i;
   int count=1;
       for(i=x-k+1;count<k*2;i++)
       {
           printf("%d ",i);
           count++;
       }

}


Measured memory_bytes: 1696
class Node():
    "node of the tree structure"
    def __init__(self, parent = -1, left = -1, right = -1):
        self.parent = parent
        self.left = left
        self.right = right

def setHeight(u):
    h1 = 0
    h2 = 0
    if node_list[u].right != -1:
        h1 = setHeight(node_list[u].right) + 1
    if node_list[u].left != -1:
        h2 = setHeight(node_list[u].left) + 1
    return max(h1,h2)

def getSibling(u):
    if node_list[u].parent == -1:
        return -1
    if node_list[node_list[u].parent].left != -1 and node_list[node_list[u].parent].left != u:
        return node_list[node_list[u].parent].left
    if node_list[node_list[u].parent].right != -1 and node_list[node_list[u].parent].right != u:
        return node_list[node_list[u].parent].right
    return -1

def getDegree(u):
    count = 0
    if node_list[u].left != -1:
        count += 1
    if node_list[u].right != -1:
        count += 1
    return count

def getDepth(u):
    count = 0
    while node_list[u].parent != -1:
        count += 1
        u = node_list[u].parent
    return count

def getType(u):
    if node_list[u].parent == -1:
        return "root"
    if node_list[u].left == -1 and node_list[u].right == -1:
        return "leaf"
    return "internal node"

n = int(input())
node_list = []
for i in range(n):
    node = Node()
    node_list.append(node)

for i in range(n):
    a,b,c = map(int, input().split())
    node_list[a].left = b
    node_list[a].right = c
    if b != -1:
        node_list[b].parent = a
    if c != -1:
        node_list[c].parent = a
height_list = [-1]*n

for i in range(n):
    print("node", str(i)+":", "parent =", str(node_list[i].parent) + ",", "sibling =", str(getSibling(i)) + ",", "degree =", str(getDegree(i)) + ",", "depth =", str(getDepth(i)) + ",", "height =", str(setHeight(i)) + ",", getType(i))



Measured memory_bytes: 5656
import sys
import math
from collections import defaultdict, deque
from copy import deepcopy
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
def end_of_loop():raise StopIteration
    
    
def main():
    N = I()
    A = [0]*N
    B = [0]*N
    if N == 0:
        sys.exit()
    for i in range(N):
        a, b = MI()
        A[i] = a
        B[i] = b

    D = Init(N, N, 0)
    #tableの初期化
    for num1 in range(N-1):
        num2 = num1+1
        a,b,c = A[num1], B[num1], B[num2]
        D[num1][num2] = a*b*c
        D[num2][num1] = a*b*c

    for length in range(2, N):
        for num1 in range(N-length):
            num2 = num1+length
            #num1からnum2-1までの組み合わせで最小値を求める
            a = A[num1]
            c = B[num2]
            result = float('inf')
            for num3 in range(num1, num2):
                result = min(result, a*B[num3]*c + D[num1][num3] + D[num3+1][num2])
            D[num1][num2] = result
            D[num2][num1] = result
    print(D[0][N-1])
            
if __name__ == "__main__":
    main()


Measured memory_bytes: 6432
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;

int main(){
  int i,j,cnt=0;
  string s;
  cin>>s;
  int n=s.size();
  int c[n];
  for(i=0;i<n;i++)c[i]=1;
  for(i=1;i<n;i++){
    if(s[i]==s[i-1])c[cnt]++;
    else cnt++;
  }
  int m=cnt+1;cnt=0;
  int d[n];
  for(i=0;i<n;i++)d[i]=0;
  for(i=0;i<n;i++){
    if(s[i]=='R' && s[i+1]=='L')d[i]=1;
    if(s[i]=='L' && s[i-1]=='R')d[i]=1;
  }
  for(i=0;2*i+1<m;i++){
    j=c[2*i]+c[2*i+1];
    if(c[2*i]%2==1){     
      c[2*i]=(j+1)/2;
      c[2*i+1]=j/2;
    }else{
      c[2*i]=j/2;
      c[2*i+1]=(j+1)/2;
    }
  }
  for(i=0;i<n;i++){
    if(d[i]==0)cout<<0<<" ";
    else cout<<c[cnt++]<<" ";
  }
}

Measured memory_bytes: 1408
import java.util.Scanner;

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

		int A = sc.nextInt();
		int B = sc.nextInt();

		String u = sc.next();

		if (u.equals(s)) {
			System.out.println((A - 1) + " " + B);
		} else {
			System.out.println(A + " " + (B - 1));
		}

		sc.close();
	}

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main()
{
    ll N; cin >> N;
    ll a = 1;

    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) a = i;
    }

    cout << a + N / a - 2 << endl;
}

Measured memory_bytes: 764
#include "iostream"
#include "vector"

using namespace std;

int main() {
  int m, n;
  cin >> m >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  if (m == 2) {
    int res1 = 0;
    int res2 = 0;
    for (int i = 0; i < n; ++i) {
      if (i % 2 == 0 && a[i] != 1) ++res1;
      if (i % 2 == 1 && a[i] != 2) ++res1;
      if (i % 2 == 0 && a[i] != 2) ++res2;
      if (i % 2 == 1 && a[i] != 1) ++res2;
    }
    cout << min(res1, res2) << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i + 1 < n; ++i) {
    if (a[i] == a[i + 1]) {
      ++ans;
      ++i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3116