akhauriyash/Code-Regression huggingface dataset:
#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++)
#define repi(i,a,b) for(int i = (a); i < (b); 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 main(){
	int n;
	int N=4;
	cin>>n;
	rep(i, n){
		ll s;
		cin>>s;
		int cnt = 0;
		cout <<"Case "<<i+1<<":"<<endl;
		while(true){
			cnt++;
			s *=s;
			stringstream ss;
			ss <<s;
			string tmp =ss.str();
			while(tmp.length()!=8){
				tmp ="0"+tmp;
			}
			//cout <<"tmp1 = "<<tmp<<endl;

			tmp =tmp.substr(2,4);
			s =0;
			//cout <<"tmp = "<<tmp<<endl;
			for(int i =0;i < 4;i++){
				s +=(tmp[i]-'0')*(pow(10.0,3-i));
			}
			cout <<s<<endl;
			if(cnt==10){
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
#define int long long int  //comment for large arrays
#define pll pair<int,int>
#define dbl long double
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define eps 0.00000001
#define INF 10000000000000001
#define all(x) (x).begin(),(x).end()
#define LB(v,x) (lower_bound(all(v),x) - v.begin()) 
#define UB(v,x) (upper_bound(all(v),x) - v.begin())
#define size(x) (int)(x).size()
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define popb() pop_back()
#define popf() pop_front()
#define mp(x,y) make_pair((x),(y))
#define vec(dt) vector<dt>
#define vv(dt) vector<vector<dt>>
#define fastio(x) ios_base::sync_with_stdio(x); cin.tie(NULL)
#define init(v,s) memset(v,s,sizeof(v)) 
#define bug(x) cerr<<"LINE: "<<__LINE__<<" || click to see test details "<<#x<<" = "<<x<<endl
#define loop(i,s,n) for(int i=s;i<n;i++)
#define print(v) for(auto it:v) cout<<it<<" "; cout<<endl 
using namespace std;

int n,m,in[100001],out[100001],excludent[100001];
vec(int) adj[100001],v[100001];

void dfs_in(int node,int par)
{
	in[node] = 1;
	for(auto it:adj[node])
		if(it!=par)
		{
			dfs_in(it,node);
			in[node] = (in[node] * (in[it] + 1))%m;
			v[node].pb(it);
		}
	if(size(v[node])==0) return;
	vec(int) pre(size(v[node]),1),suf(size(v[node]),1);
	pre[0] = in[v[node][0]]+1;
	suf[size(suf)-1] = in[v[node][size(v[node])-1]]+1;
	loop(i,1,size(pre)) pre[i] = (pre[i-1] * (in[v[node][i]]+1))%m;
	for(int i=size(suf)-2;i>=0;i--) suf[i] = (suf[i+1] * (in[v[node][i]]+1))%m;
	loop(i,0,size(v[node]))
	{
		excludent[v[node][i]] = 1;
		if(i>0) excludent[v[node][i]] = (excludent[v[node][i]] * pre[i-1])%m;
		if(i<size(v[node])-1) excludent[v[node][i]] = (excludent[v[node][i]] * suf[i+1])%m;
	}	
}

void dfs_out(int node,int par)
{
	out[node] = (excludent[node] * (out[par]+1))%m;
	for(auto it:adj[node])
		if(it!=par)
			dfs_out(it,node);
}

signed main()
{
	fastio(0);
	cin>>n>>m;
	loop(i,1,n)
	{
		int x,y;
		cin>>x>>y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	dfs_in(1,0);
	for(auto it:adj[1]) dfs_out(it,1);
	loop(i,1,n+1) cout<< (in[i] * (out[i]+1))%m <<endl;	
	return 0;		
}


Measured memory_bytes: 18688
#include <iostream>
using namespace std;
int main(){
	int n,t=0;
	cin>>n;
	int l[n+1],r[n+1];
	for(int i=1;i<=n;i++){
		cin>>l[i]>>r[i];
		t+=r[i]-l[i]+1;
	}
	cout<<t<<endl;
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

import Data.List (splitAt, unfoldr)
import qualified Data.ByteString.Char8 as BS

divide :: Int -> Int -> [Int] -> (Int, Int, [Int])
divide !size !count !xs
    | length xs < 2 = (size, count, xs)
    | otherwise     = conq (divide size count xl) (divide size count xr)
  where
    (xl, xr) = splitAt (length xs `div` 2) xs


conq :: (Int, Int, [Int]) -> (Int, Int, [Int]) -> (Int, Int, [Int])
conq (!s1, !c1, []) (!s2, !c2, ys) = (s1 + s2, c1 + c2, ys)
conq (!s1, !c1, xs) (!s2, !c2, []) = (s1 + s2, c1 + c2, xs)
conq (!s1, !c1, (x:xs)) (!s2, !c2, (y:ys))
    | y < x          = f x $ conq (s1 - 1, c1 + s2, xs) (s2, c2, (y:ys))
    | otherwise      = f y $ conq (s1, c1, (x:xs)) (s2 - 1, c2, ys)
  where
    f a (!b, !c, d) = (b + 1, c, (a:d))


main :: IO ()
main = do
    getLine
    xs <- fmap (unfoldr (BS.readInt . BS.dropWhile (' ' ==))) BS.getLine :: IO ([Int])
    let (_, a, _) = divide 1 0 xs
    print a



Measured memory_bytes: 40668
# -*- coding: utf-8 -*-

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

S = input()
Q = int(input())

preffix = ""
suffix = ""
revcnt = 0
for i in range(Q):
    query = input()
    if query[0] == "1":
        wk = preffix
        preffix = suffix
        suffix = wk
        revcnt += 1
    elif query[2] == "1":
        if revcnt %2 ==0:
            preffix = (query[4]+preffix)
        else:
            preffix += query[4]
    else:
        if revcnt %2 ==1:
            suffix = (query[4]+suffix)
        else:
            suffix += query[4]

if revcnt%2 == 1:
    S = S[::-1]
    suffix = suffix[::-1]
    preffix = preffix[::-1]


print(preffix+S+suffix)


Measured memory_bytes: 4532
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define pb push_back
#define all(v) v.begin(),v.end()
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int n, a, b;
vector<int> x[3];

int main(){
    fio;
    cin >> n >> a >> b;
    for(int i = 0, p; i < n; i++){
        cin >> p;
        if(p <= a) x[0].push_back(p);
        else if(p <= b) x[1].push_back(p);
        else x[2].push_back(p);
    }
    cout << min({x[0].size(),x[1].size(),x[2].size()}) << '\n';
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] c = str.toCharArray();
        int k = c[0] - 'a';
        if (0 <= k && k <= 26) {
            System.out.println("a");
        } else {
            System.out.println("A");
        }
    }
}


Measured memory_bytes: 35788
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T> void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U> void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl

struct edge { int to, cost; };

const LL LINF = 1LL<<60;
const int IINF = 1LL<<30;
const LL MOD = 1e9+7;

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

   s = "0" + s;

   vector<int> zeros, ones;

   char prev = '$'; int cnt = 0;
   for (int i = 0; i < s.size(); ++i) {
      if (prev == s[i]) {
         ++cnt;
      } else {
         if (prev == '0') {
            zeros.push_back(cnt);
         } else if (prev == '1') {
            ones.push_back(cnt);
         }
         prev = s[i];
         cnt = 1;
      }
   }
   if (prev == '0') {
      zeros.push_back(cnt);
   } else if (prev == '1') {
      ones.push_back(cnt);
   }


   ones.insert(ones.begin(), 0);
   int sz = ones.size();

   // DUMP(ones);
   // DUMP(zeros);

   auto dp = make_v<int>(4, sz);

   for (int i = 1; i < sz; ++i) {
      chmax(dp[0][i], dp[0][i-1]);
      chmax(dp[0][i], dp[1][i-1]);
      chmax(dp[0][i], dp[2][i-1]);
      chmax(dp[0][i], dp[3][i-1]);

      if (zeros[i-1] == 1) {
         if (ones[i-1] >= 1) chmax(dp[1][i], dp[0][i-1] + ones[i-1]);
         if (ones[i-1] >= 2) chmax(dp[1][i], dp[1][i-1] + ones[i-1] - 1);
         if (ones[i-1] >= 1) chmax(dp[1][i], dp[2][i-1] + 1);

         if (ones[i-1] >= 1) chmax(dp[2][i], dp[0][i-1] + ones[i] - 1);
         if (ones[i-1] >= 2) chmax(dp[2][i], dp[1][i-1] + ones[i] - 1);
         if (ones[i-1] >= 1) chmax(dp[2][i], dp[2][i-1] + ones[i] - 1);

         if (ones[i-1] >= 1) chmax(dp[3][i], dp[0][i-1] + ones[i]);
         if (ones[i-1] >= 2) chmax(dp[3][i], dp[1][i-1] + ones[i]);
         if (ones[i-1] >= 1) chmax(dp[3][i], dp[2][i-1] + ones[i]);
      }

      // DUMP(dp[0][i]);
      // DUMP(dp[1][i]);
      // DUMP(dp[2][i]);
      // cerr << endl;
   }

   int ans = max({ dp[0][sz-1], dp[1][sz-1], dp[2][sz-1], dp[3][sz-1] });
   cout << ans << endl;


   return 0;
}


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

int n, a0;
long long int k, k0, ans;
multiset<int> a;

int main()
{
	cin >> n >> k;
	k0 = k * (k - 1) / 2 % 1000000007;
	ans = 0;
	for (size_t i = 0; i < n; i++)
	{
		cin >> a0;
		long long int r = 0, s = 0;
		for (auto itr = a.begin(); itr != a.lower_bound(a0); itr++)
		{
			s++;
		}
		for (auto itr = a.upper_bound(a0); itr != a.end(); itr++)
		{
			r++;
		}
		a.insert(a0);
		ans += k * r + (s + r)*k0 % 1000000007;
		ans %= 1000000007;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n
# 
# s = input()

N, K = list(map(int, input().split()))
dp = [1]*(N+1)
dp[0] = 0
for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    for e in A:
        dp[e] = 0

ans = sum(dp)
print(ans)


Measured memory_bytes: 9148
#include<stdio.h>
#include<iostream>
using namespace std;
typedef long long LL;

LL A[305][305];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin>>A[i][j];
        }
    }
    LL ans=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<i+1;j++){
            bool flag=1;
            for(int k=0;k<N;k++){
                if(A[i][j]>A[i][k]+A[k][j]){
                    cout<<-1<<endl;
                    return 0;
                }else if(i!=k&&j!=k&&A[i][j]==A[i][k]+A[k][j]) flag=0;
            }
            if(flag){
                ans+=A[i][j];
            }//else cout<<i<<" "<<j<<endl;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(void)
{
    int K,X;
    cin >> K >> X;
    vector<int> ans;
    for (int i = X-K+1; i < X+K; i++) {
        if(-1000000 <= i && i <= 1000000) cout << i << " ";
    }
    cout << endl;
}

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

typedef vector<int> vi;

int H, W;
vector<string> S;
vector<vi> U, D, L, R;

void input_init(void) {
	cin >> H >> W;
	S.resize(H);
	for (int j = 0; j < H; ++j)
		cin >> S[j];
	U.resize(H, vi(W, 0));
	D.resize(H, vi(W, 0));
	L.resize(H, vi(W, 0));
	R.resize(H, vi(W, 0));
}

void calcu(void) {
	for (int i = 0; i < W; ++i) {
		if (S[0][i] == '.')
			U[0][i] = 1;
		if (S[H - 1][i] == '.')
			D[H - 1][i] = 1;
	}
	for (int i = 0; i < W; ++i) {
		for (int j = 1; j < H; ++j) {
			if (S[j][i] == '.')
				U[j][i] = U[j - 1][i] + 1;
			if (S[H - j - 1][i] == '.')
				D[H - j - 1][i] = D[H - j][i] + 1;
		}
	}
	for (int j = 0; j < H; ++j) {
		if (S[j][0] == '.')
			L[j][0] = 1;
		if (S[j][W - 1] == '.')
			R[j][W - 1] = 1;
	}
	for (int j = 0; j < H; ++j) {
		for (int i = 1; i < W; ++i) {
			if (S[j][i] == '.')
				L[j][i] = L[j][i - 1] + 1;
			if (S[j][W - i - 1] == '.')
				R[j][W - i - 1] = R[j][W - i] + 1;
		}
	}
}

int solve(void) {
	int max_cnt = 0;
	for (int j = 0; j < H; ++j) {
		for (int i = 0; i < W; ++i) {
			if (S[j][i] == '#')
				continue;
			int cnt = U[j][i] + D[j][i] + L[j][i] + R[j][i] - 3;
			max_cnt = max(cnt, max_cnt);
		}
	}
	return max_cnt;
}

int main(void) {
	input_init();
	calcu();
	int ans = solve();

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 67200
# ABC107B - Grid Compression
h, w = list(map(int, input().rstrip().split()))
data = [input().rstrip() for _ in range(h)]
row = [False] * h
col = [False] * w

for i in range(h):
    for j in range(w):
        if data[i][j] == "#":
            row[i] = True
            col[j] = True

for i in range(h):
    if row[i] == True:
        for j in range(w):
            if col[j] == True:
                print(data[i][j], end="")
        print()

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const int MAX_N = 1e+5;

int main() {
  int N;
  ll H[MAX_N];
  std::cin >> N;
  rep(i, N) std::cin >> H[i];

  int dp[MAX_N];
  dp[0] = 0;
  for(int i = 1; i < N; ++i) {
    if(H[i] <= H[i - 1]) {
      dp[i] = dp[i - 1] + 1;
    } else {
      dp[i] = 0;
    }
  }

  int ans = 0;
  rep(i, N) {
    ans = std::max(ans, dp[i]);
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 1408
s=list(input())
for i in range(int(input())):
    q=input().split()
    a,b=int(q[1]),int(q[2])
    
    if q[0]=="replace":
        s[a:b+1]=q[3]

    elif q[0]=="reverse":
        s[a:b+1]=reversed(s[a:b+1])
        
    else:print(*s[a:b+1],sep="")



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

const int N = 100100;

int n, a[N], ans;

int main() {
	cin >> n;
	set<int> st;
	map<int, int> mp;
	int cur = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		st.insert(a[i]);
	}
	for (int i: st) mp[i] = ++cur;
	for (int i = 1; i <= n; i++)
		ans += (i + mp[a[i]]) % 2;
	assert(ans % 2 == 0);
	cout << ans / 2;
}


Measured memory_bytes: 13344
#include <stdio.h>

int main(){
    long long int a, b, x;

    scanf("%lld %lld %lld", &a, &b, &x);

    if(a>0)
        printf("%lld\n", b/x-(a-1)/x);
    else
        printf("%lld\n", b/x+1);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

long long d[300][300];
int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            cin >> d[i][j];
        }
    }

    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            for(int k = 0; k < N; k++){
                if(i == j || j == k || i == k){
                    continue;
                }
                if(d[j][i] + d[i][k] < d[j][k]){
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }

    long long ans = 0;
    for(int i = 0; i < N - 1; i++){
        for(int j = i + 1; j < N; j++){
            bool exists_mid_point = false;
            for(int k = 0; k < N; k++){
                if(i == k || j == k){
                    continue;
                }
                if(d[i][k] + d[k][j] == d[i][j]){
                    exists_mid_point = true;
                    break;
                }
            }
            if(!exists_mid_point){
                ans += d[i][j];
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    string S;cin>>S;
    ll N=atoi(S.c_str());
    int sn=0;
    for(int i=0;i<S.size();i++){
        sn+=S[i]-'0';
    }
    cout<<((N%sn)?"No":"Yes")<<endl;
}

Measured memory_bytes: 3604
def is_prime(x)
  return true if x === 2 || x === 3
  2.upto(Math.sqrt(x) + 1) do |i|
    return false if x % i === 0
  end
  true
end

def solve(items)
  items.select {|x| is_prime(x) }.count
end
puts solve(Array.new(gets.to_i) { gets.to_i })



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



int main() {
    string s;
    int q;
    cin >> s >> q;
    
    deque<char> d;
    rep(i,s.size()) {
        d.push_back(s[i]);
    }
    
    bool to = true;
    
    rep(i,q) {
        int t;
        cin >> t;
        if(t == 1) {
            to = !to;
        }
        else {
            int f;
            char c;
            cin >> f >> c;
            
            if(f == 1) {
                if(to)
                    d.push_front(c);
                else
                    d.push_back(c);
            }
            else {
                if(to)
                    d.push_back(c);
                else
                    d.push_front(c);
            }
        }
    }
    
    if(to) {
        for(int i = 0; i < d.size(); i++) {
            cout << d[i];
        }
    }
    else {
        for(int i = (int)d.size() - 1; i >= 0; i--) {
            cout << d[i];
        }
    }
    
    cout << endl;
    
    
    return 0;
}




Measured memory_bytes: 4000
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for i in range(m)]
r=any([r[j:j+m] for r in a[i:i+m]]==b for i in range(n-m+1) for j in range(n-m+1))
print("Yes" if r else "No")

Measured memory_bytes: 3188
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

const double cos60=0.500000000000000;
const double sin60=0.866025403784439;

void koch_snowflake(size_t n, pair<double, double> p1, pair<double, double> p2) {
    if (!n) return;

    pair<double, double> s, t, u;
    s.first = (2*p1.first + p2.first) / 3.0;
    s.second = (2*p1.second + p2.second) / 3.0;
    t.first = (p1.first + 2*p2.first) / 3.0;
    t.second = (p1.second + 2*p2.second) / 3.0;
    u.first = (t.first-s.first)*cos60 - (t.second-s.second)*sin60 + s.first;
    u.second = (t.first-s.first)*sin60 + (t.second-s.second)*cos60 + s.second;

    koch_snowflake(n-1, p1, s);
    printf("%.12f %.12f\n", s.first, s.second);
    koch_snowflake(n-1, s, u);
    printf("%.12f %.12f\n", u.first, u.second);
    koch_snowflake(n-1, u, t);
    printf("%.12f %.12f\n", t.first, t.second);
    koch_snowflake(n-1, t, p2);
}

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

    pair<double, double> p1(0.0, 0.0), p2(100.0, 0.0);

    printf("%.12f %.12f\n", 0.0, 0.0);
    koch_snowflake(n, p1, p2);
    printf("%.12f %.12f\n", 100.0, 0.0);

    return 0;
}

Measured memory_bytes: 2748
n = int(input())
p = list(map(int, input().split()))
o = [i for i in range(1,n+1)]
k = 0
for i in range(n):
    if p[i] != o[i]:
        k += 1

if k == 0 or k == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
H,W = map(int,input().split())
C = []
A = []
for i in range(10) :
    C.append(list(map(int,input().split())))
for j in range(H) :
    A.append(list(map(int,input().split())))
for k in range(10) :
    for l in range(10) :
        for m in range(10) :
            C[l][m] = min(C[l][m],C[l][k]+C[k][m])
ans = 0
for row in A :
    for n in row :
        if n == -1 :
            continue
        else :
            ans += C[n][1]
print(ans)


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

typedef int64_t ll;

using namespace std;

const ll mod = 1e9 + 7;
ll n, k, a[200005], l, r, tot, ans, lb, rb;

void calcmin() {
    l = lb, r = rb;
    while (tot < k) {
        ll lv = mod, rv = mod;
        if (l >= 1) lv = -a[l];
        if (r <= n) rv = a[r];
        if (rv < lv) {
            ans = ans * rv % mod;
            r++;
        }
        else {
            ans = ans * (-lv) % mod;
            l--;
        }
        tot++;
    }
}

void calcmax() {
    if (k % 2 == 1) {
        ans *= a[n];
        r = n - 1;
        tot = 1;
    }
    while (tot < k && (l < lb || r > rb)) {
        ll lv = 0, rv = 0;
        if (l < lb) lv = a[l] * a[l + 1];
        if (r > rb) rv = a[r] * a[r - 1];
        if (rv > lv) {
            rv %= mod;
            ans = ans * rv % mod;
            r -= 2;
        }
        else {
            lv %= mod;
            ans = ans * lv % mod;
            l += 2;
        }
        tot += 2;
    }
    if (tot == k - 1) {
        if (r == rb) {
            ans = ans * a[rb] % mod;
        }
        else if (l == lb) {
            ans = ans * a[lb] % mod;
        }
    }
}

int main() {
    cin >> n >> k;
    for (ll i = 1; i <= n; i++) cin >> a[i];
    sort(a + 1, a + n + 1);
    l = 1, r = n, tot = 0, ans = 1, lb = 0, rb = n + 1;
    for (ll i = 1; i <= n; i++) {
        if (a[i] < 0) {
            lb = max(lb, i);
        } 
        if (a[i] > 0) {
            rb = min(rb, i);
        }
    }
    if ((n - rb + 1 + lb == k && lb % 2 == 1) || 
    n - rb + 1 + lb < k || (rb == n + 1 && k % 2 == 1)) {
        if (rb - lb > 1) {
            cout << 0 << endl;
            return 0;
        }
        else {
            calcmin();
        }
    }
    else {
        calcmax();
    }
    
    cout << (ans + mod) % mod << endl;
    return 0;
}

Measured memory_bytes: 5196
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <list>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long
#define eps 1e-6
using namespace std;
const double pi = 3.1415926535;
/*
https://codeforces.com/contest/1106/problems
https://codeforces.com/contest/1106/submit
*/

int main(){
	char s[100000];
	for(int i  = 0; i < 3; i ++){
		scanf("%s",&s);
		pc(s[0]);
	}

	pn

    return 0;

}



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

int main() {
    int N;
    string W[110], used_w[110];

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

    for (int i=1; i<N; i++) {
        for (int j=0; j<i; j++) { 
            if (used_w[j] == W[i-1]) { cout << "No" << endl; return 0; }
        }
        if (W[i-1].back() == W[i].front()) { used_w[i-1] = W[i-1]; }
        else { cout << "No" << endl; return 0; }
    }
    for (int i=0; i<N-1; i++) {
        if (used_w[i] == W[N-1]) { cout << "No" << endl; return 0; }
    }
    cout << "Yes" << endl;
}

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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;
}

typedef tuple<pii,int32,int32,int32> tup4;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 h,w,k;
  cin >> h >> w >> k;
  int32 x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  --x1,--y1,--x2,--y2;
  vector<string> c(h);
  REP(i,h)cin >> c[i];
  priority_queue<tup4,vector<tup4>,greater<tup4>> que;
  vector<vector<vector<pii>>> dist(h,vector<vector<pii>>(w,vector<pii>(4,pii(inf,0))));
  REP(i,4){
    dist[x1][y1][i] = pii(0,0);
    que.emplace(pii(0,0),x1,y1,i);
  }
  while(!que.empty()){
    auto [d,cx,cy,dir] = que.top();
    que.pop();
    if(dist[cx][cy][dir] < d)continue;
    REP(i,4){
      if(i != dir){
        auto nd = d;
        if(nd.se > 0){
          nd.fi++;
          nd.se = 0;
        }
        if(chmin(dist[cx][cy][i],nd)){
          que.emplace(nd,cx,cy,i);
        }
      }else{
        int32 nx = cx + dx[i];
        int32 ny = cy + dy[i];
        if(nx < 0 || h <= nx)continue;
        if(ny < 0 || w <= ny)continue;
        if(c[nx][ny] == '@')continue;
        pii nd = d;
        nd.se++;
        while(nd.se >= k){
          nd.fi++;
          nd.se-=k;
        }
        if(chmin(dist[nx][ny][dir], nd))
          que.emplace(nd,nx,ny,dir);
      }
    }
  }
  int32 ans = inf;
  REP(i,4){
    if(dist[x2][y2][i].se > 0){
      dist[x2][y2][i].fi++;

    }
    chmin(ans, dist[x2][y2][i].fi);
  }
  if(ans == inf)ans = -1;
  ANS(ans);
  return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];

    sort(a.begin(), a.end(), greater<ll>());

    ll w = -1, h = -1;

    for (int i = 0; i < n - 1; i++) {
        if (w < 0) {
            if (a[i] == a[i + 1]) {
                w = a[i];
                i++;
            }

        } else {
            if (a[i] == a[i + 1]) {
                h = a[i];
                break;
            }
        }
    }

    if (h > 0 && w > 0) {
        cout << w * h << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 1024
s=input()
q=int(input())

rev=1

sf=""
sb=s

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf+=n[2]
    else:
      sb+=n[2]

s=sf[::-1]+sb

if rev==1:
  print(s)
else:
  print(s[::-1])


Measured memory_bytes: 4596
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g){
	for (int i=g; i<n; i++){
		int v = A[i];
		int j = i - g;
		while (j >=0 && A[j] > v){
			A[j+g] = A[j];
			j -= g;
			cnt++;
		}
		A[j+g] = v;
	}
}

void shellSort(int A[], int n){
	for (int h = 1; ; ){
		if (h > n) break;
		G.push_back(h);
		h = 3*h + 1;
	}

	for (int i = G.size()-1; i >= 0; i--){
		insertionSort(A, n, G[i]);
	}
}

int main(){
	cin >> n;
	for (int i=0; i<n; i++) scanf("%d", &A[i]);
	cnt = 0;

	shellSort(A, n);

	cout << G.size() << endl;
	for (int i=G.size() - 1; i>=0; i--){
		printf("%d", G[i]);
		if (i) printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	for (int i=0; i<n; i++) printf("%d\n", A[i]);

	return 0;

}

Measured memory_bytes: 5196
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 1000000007;

//bool operator< (pint a, pint b) {
	//return a.second < b.second;

//}



ll gcd(ll a, ll b) {

	if (b == 0)
		return a;

	return gcd(b, a % b);


}

ll max(ll a, ll b) {
	if (a < b) {
		return b;
	}
	else
		return a;

}

ll min(ll a, ll b) {
	if (a < b)
		return a;

	return b;
}




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

vector<pint> list;










void floyd(int N, ll** d) {

	rep(k, N+1){
		rep(i, N+1) {
			if (d[i+1][k+1] == inf) continue;
			rep(j, N+1) {
				if (d[j+1][k+1] == inf) continue;

				d[i+1][j+1] = min(d[i+1][j+1], d[i+1][k+1] + d[j+1][k+1]);

			}

		}
	}




}


ll vis[100005];
ll d[100005];
vector<ll> M[100005];
vector<ll> anslist;


stack<int> to_1;

ll col[100005];

void dfs(ll K, ll dist) {

	
	d[K] = dist;
	vis[K] = 1;

		
	for (int i = 0; i < M[K].size(); i++) {
		if (vis[M[K][i]] == 0) {
			
			dfs(M[K][i], dist + 1);
			
		}
	}

}



vector<unsigned long long> v;





ll A[100005];
ll cho[100005];

int main() {
	ll N, M;
	ll a, b;
	cin >> N;

	ll sum_c = 0;
	rep(i, N) {
		cin >> A[i];
		cho[A[i]] += 1;

		if (cho[A[i]] > 1) {
			sum_c += 1;

		}

	}


	
	if (sum_c % 2 == 0)
		cout << N - sum_c << endl;
	else
		cout << N - sum_c - 1 << endl;


	
	return 0;
}

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

int main(){
	string st;
	cin >> st;
    int f = 0;
    if(st.size()%2 == 1){
      cout << "No" << endl;
    }else{
      int su = st.size()/2;
      for(int i=0; i<su; i++){
        if(!(st.at(i*2) == 'h' && st.at(i*2+1) == 'i')) f = 1;
      }
      if(f == 0){
        cout << "Yes" << endl;
      }else{
        cout << "No" << endl;
      }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

unsigned int randInt() {
	static unsigned int tx = 123456789, ty = 362436069, tz = 521288629, tw = 88675123;
	unsigned int tt = (tx ^ (tx << 11));
	tx = ty; ty = tz; tz = tw;
	return (tw = (tw ^ (tw >> 19)) ^ (tt ^ (tt >> 8)));
}
double randDouble() {
    return (double)(randInt())/UINT_MAX;
}
const int64_t CYCLES_PER_SEC=3000000000;
#define TIMES 1.0
double timeLimit=1.95*TIMES;
struct Timer {
	int64_t start;
	Timer() { reset(); }
	void reset() { start = getCycle(); }
	inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; }
	inline int64_t getCycle() {
		uint32_t low, high;
		__asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
		return ((int64_t)low) | ((int64_t)high << 32);
	}
} timer;
bool move(int prev_score, int next_score, double temperature) {
    if (prev_score <= next_score) return true;
    long long int diff = next_score - prev_score;
	//cerr << diff << " "<< pow(1.001, diff/temperature) << endl;
    //std::cerr << pow(1.0001, diff/temperature) << " " << randDouble() << std::endl;
    return pow(1.03, diff/temperature) >= randDouble();
}
int D; 
int s[365][26];
int contest[365];
int c[26];

int score() {
	int S = 0;
	int last[26] = {};
	rep(i, 26) last[i] = -1;
	rep(i, D) {
		S += s[i][contest[i]];
		last[contest[i]] = i;
		rep(j, 26) {
			S -= c[j] * (i - last[j]);
		}
	}
	return S;
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	// std::ifstream in("in1.txt");
    // std::cin.rdbuf(in.rdbuf());
	cin >> D;
	rep(i, 26) cin >> c[i];
	rep(i, 365) {
		rep(j, 26)  {
			cin >> s[i][j];
		}
	}
	rep(i, 365) {
		contest[i] = i % 26;
	}
	int now_score = score();
	double temperature = 100.0;
	while(true) {
		double t=timer.get();
        if(t >= timeLimit) break;
		int a = randInt() % 365;
		int b = randInt() % 26;
		while(b == contest[a]) {
			b = randInt() % 26;
		}
		int prev = contest[a];
		contest[a] = b;
		int next_score = score();
		if(move(now_score, next_score, temperature)) {
			now_score = next_score;
		} else {
			contest[a] = prev;
		}
		temperature *= 0.99997;
		//if(randInt() % 100 == 0) cout << score() << " " << temperature << endl;
	}
	//cout << now_score + 1000000 << endl;
	rep(i, D) {
		cout << contest[i] + 1 << endl;
	}
	
    return 0;
}


Measured memory_bytes: 4376
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    ans = 0
    for i in range(1, N):
        if A[i] == A[i-1]:
            A[i] = 0
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>
int main()
{
  const int BASE = 100000;
  int n, debt = BASE;
  std::cin >> n;
  while (n--) {
    debt = (debt * 1.05 + 999) / 1000;
    debt *= 1000;
  }
  std::cout << debt << std::endl;
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#define size(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
int main(void){
    int a,b,c,d,e;
    cin >> a;

    b = a/1000;
    c = (a/100) % 10;
    d = (a/10) % 10;
    e = a % 10;
  if(c == d){
    if(b == c){
      cout << "Yes";
    }else if(e == c){
      cout << "Yes";
    }else{
      cout << "No";
    }
  }else{
      cout << "No";
  }
}

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

using namespace std;

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

    vector<int> a(n);
    iota(a.begin(), a.end(), 1);

    auto itr = a.begin();
    do {
      for (itr = a.begin(); itr!=a.end(); ++itr) {
        if (itr!=--a.end()){
          printf("%d ",*itr);
        }else{
          printf("%d\n",*itr);
        }
      }
    } while(next_permutation(a.begin(),a.end()));

    return 0;
}



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

int main () {
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  int N = 5;
  
  vector<int> Time = {a, b, c, d, e};
  vector<int> nextTime(N);
  for (int i = 0; i < N; i++) {
    nextTime[i] = (Time[i] + 9) / 10 * 10;
  }
  
  int BestTime = 9999999999;
  
  for (int i = 0; i < N; i++) {
    int SumTime = 0;
    for (int j = 0; j < N; j++){
      if (i == j) {
        SumTime += Time[j];
      }else {
        SumTime += nextTime[j];
      }
    }
    BestTime = min(BestTime, SumTime);
  }
  cout << BestTime << endl;
}

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

using ll = long long;

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

    ll n;
    cin >> n;
    string s = "";
    while (n > 0)
    {
        --n;
        int b = n % 26;
        char c = 'a' + (char)(b);
        s += c;
        n /= 26;
    }
    reverse(ALL(s));
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#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 FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_que<int> pque;//これは大きい順
//typedef priority_que<int, vector<int>, greater<int>> pque;//これは小さい順


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

  return 0;
}


Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

sa = [A[0]]
for a in A[1:]:
    sa.append(sa[-1] + a)

cnt = Counter(sa)
ans = 0
for i, j in cnt.items():
    if i == 0:
        ans += j
    ans += j * (j - 1) // 2
print(ans)

Measured memory_bytes: 41620
#include<stdio.h>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
int main(){
  int n;
  scanf("%d",&n);
  int p[n];
  int i,k,l,c;
  for(i=0;i<n;i++)
    scanf("%d",&p[i]);

  c=0;
  for(i=1;i<n-1;i++){
    k=max(p[i+1],max(p[i],p[i-1]));
    l=min(p[i+1],min(p[i],p[i-1]));
    if(p[i]!=k&&p[i]!=l)
      c++;
  }
  printf("%d\n",c);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pii pair<int,int>
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%lld",&t)
#define p(t) printf("%lld\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<int,vector<int>,greater<int> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define spitr set<pii>:: iterator
#define mitr map<int,int>:: iterator

int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}


typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


int32_t main()
{
    fast;
    int n, d, a; cin >> n >> d >> a;
    vip v;
    for (int i = 0; i < n; i++)
    {
        int x, y; cin >> x >> y;
        v.pb(mp(x, y));
    }

    vip bombs;
    bombs.pb(mp(-1e18, 0));
    sort(all(v));

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        int drops = 0;
        int id = upper_bound(all(bombs), mp(v[i].ff + d, LLONG_MAX)) - bombs.begin();
        id--;
        int tmp = lower_bound(all(bombs), mp(v[i].ff - d, -1ll)) - bombs.begin();
        tmp--;

        if (id >= 0)
            drops += bombs[id].ss;
        if (tmp >= 0)
            drops -= bombs[tmp].ss;

        //trace2(i,drops);


        drops *= a;
        if (v[i].ss <= drops)
            continue;

        int left = v[i].ss - drops;
        int tobe = left / a + bool(left % a);
        ans += tobe;

        bombs.pb(mp(v[i].ff + d, tobe + bombs.back().ss));
    }

    cout << ans;
}

Measured memory_bytes: 10860
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,1,-1,1,-1,-1,0};
int dy[]={0,1,1,-1,-1,1,0,-1};

const int M_N=1000000;
bool prime[M_N+1];
 
void Sieve(){
    prime[1]=false;
    for(int i=2;i*i<=M_N;i++){
        if(prime[i]==true){
            for(int j=2;i*j<=M_N;j++){
                prime[i*j]=false;
            }
        }
    }
}

int main(){
    int x;cin >> x;
    memset(prime,true,sizeof(prime));
    Sieve();
    for (int i = x; i < 1000000; i++) {
        if(prime[i]){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int H, W;
    cin >> H >> W;
    char s;
    int cnt = 0;
    for (int i = 0; i < H*W; i++) {
        cin >> s;
        if(s == '#'){
            cnt++;
        }
    }
    if(cnt == H + W - 1){
        printf("Possible\n");
    }
    else{
        printf("Impossible\n");
    }
}

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

int main(){
    double r;
    cin >> r;
    r = r*2.0;
    r = r*3.141592653;
    printf("%.6f",r);
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i) 
#define REP(i,k,n) for (int i = k; i <= n; ++i) 
#define REPR(i,k,n) for (int i = k; i >= n; --i)  
 
#define MP make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
void test();
 
int main()
{
//freopen("input.in","r",stdin);freopen("output.in","w",stdout);
int t=1;
//   cin>>t;
for(int i=1;i<=t;i++)
{    
//	cout<<"Case #"<<i<<": ";
	test();
cout<<endl;
}
return 0;
}
void test() 
{
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int t;
        cin>>t;
        if(t%2==1 && i%2==1)ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>
#define INF 1000000001
#define MAX_N 500000

int cnt = 0;

void merge(int A[], int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;

  int *L = malloc(sizeof(int)*(n1+1));
  int *R = malloc(sizeof(int)*(n2+1));
  for (i = 0; i < n1; i++) {
    L[i] = A[left+i];
  }
  for (i = 0; i < n2; i++) {
    R[i] = A[mid+i];
  }
  L[n1] = INF;
  R[n2] = INF;

  i = 0;
  j = 0;
  for (k = left; k < right; k++) {
    cnt++;
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
    }
  }

  free(L);
  free(R);
}

void merge_sort(int A[], int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right)/2;
    merge_sort(A, left, mid);
    merge_sort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main(void) {
  int i, n;
  int ary[MAX_N];
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &ary[i]);
  }

  merge_sort(ary, 0, n);
  for (i = 0; i < n-1; i++) {
    printf("%d ", ary[i]);
  }
  printf("%d\n", ary[n-1]);
  printf("%d\n", cnt);
  
  return 0;
}

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

int main (){
    int x, a, b;
    cin >> x >> a >> b;
    if(b <= a){
        cout << "delicious" << endl;
    }else if(b <= (a+x)){
        cout << "safe" << endl;
    }else {
        cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 384