akhauriyash/Code-Regression huggingface dataset:
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int dp[SIZE];
PII p[SIZE];
int main(){
    int N,D,A;
    R(N,D,A);
    REP(i,N)R(p[i].F,p[i].S);
    sort(p,p+N);
    int rr=0;
    LL an=0;
    REP(i,N){
        while(rr+1<N&&p[rr+1].F-p[i].F<=2*D)rr++;
        int need=(p[i].S+A-1)/A;
        if(i)dp[i]+=dp[i-1];
        if(dp[i]<need){
            int v=need-dp[i];
            an+=v;
            dp[i]+=v;
            dp[rr+1]-=v;
        }
    }
    W(an);
    return 0;
}


Measured memory_bytes: 5888
<?php

fscanf(STDIN, "%d", $n);
//1行入力
$single_line_input = trim(fgets(STDIN));
//不要な改行コードを取り除く
$single_line_input = str_replace(array("\r\n","\r","\n"), '', $single_line_input);
//スペースで分解して配列に格納
$A = explode(" ", $single_line_input);
$ng = 0;
    foreach($A as $a){
        if($a%2 == 0){
            if($a%3 == 0 || $a%5 == 0){
            }else{
                $ng++;
            }
        }
    }
    
    if($ng == 0){
        echo("APPROVED");
    }else{
        echo("DENIED");
    }
  
?>

Measured memory_bytes: 4728
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var XA = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var X = XA[0];
            var A = XA[1];

            var output = X < A ? "0" : "10";
            Console.WriteLine(output);
        }

        static int NumberOfDigits(long x)
        {
            if (x < 10) return 1;

            var result = 0;
            while (x > 0)
            {
                result++;
                x /= 10;
            }

            return result;
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;

int main(){
	string s;
	std::cin >> s;
	ll k;
	std::cin >> k;
	bool han=1;
	int a;
	rep(i,(int)min(k,(ll)s.size())){
		if(s[i]!='1'){
			if(han==1){
				han=0;
				a=s[i]-48;
			}
		}
	}
	if(han){
		std::cout << 1 << std::endl;
	}else{
		std::cout << a << std::endl;
	}
}

Measured memory_bytes: 256
min = 40.00
max = 150.00

measure = [min, 48.00, 51.00, 54.00, 57.00, 60.00, 64.00, 69.00, 75.00, 81.00, 91.00, max]
className = ['light fly',
         'fly',
         'bantam',
         'feather',
         'light',
         'light welter',
         'welter',
         'light middle',
         'middle',
         'light heavy',
         'heavy']

while True:
    try:
        weight = float(input())
    except:
        break;
    for i in range(11):
        if(measure[i] < weight and weight <= measure[i + 1]):
            print(className[i])


Measured memory_bytes: 5580
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
INF = float("inf")
import sys
sys.setrecursionlimit(10000)


def solve(A, B, C, X):
    ans = 0
    for i in range(A + 1):
        for j in range(B + 1):
            for k in range(C + 1):
                ans += 500 * i + 100 * j + 50 * k == X
    return ans


def main():
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())
    print(solve(A, B, C, X))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3916
import java.util.*;
public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int one = sc.nextInt();
		int two = sc.nextInt();//B
		int three = sc.nextInt();
		int four = sc.nextInt();

		int min = Math.max(one, three);
		int max = Math.min(two, four);

		if (min < max) {
			System.out.println(max - min);
		} else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 21844
class BIT:
    """
    1-indexed
    """
    def __init__(self, size):
        self.size = size
        self.data = [0] * (size + 1)

    def add(self, index, value=1):
        while index <= self.size:
            self.data[index] += value
            index += index & (-index)

    def sum(self, index):
        """
        右端含める
        """
        ret = 0
        while index:
            ret += self.data[index]
            index -= index & (-index)
        return ret

    def search(self, val):
        """
        x_1 + ... x_i >= val を満たす最小のi
        """
        i = 0
        s = 0
        step = 1 << (self.size.bit_length() - 1)  # 一番上の長さ

        while step:
            if i + step <= self.size and s + self.data[i + step] < val:
                i += step
                s += self.data[i]
            step //= 2
        return i + 1

N, Q = map(int, input().split())
C = [-1] + list(map(int, input().split()))
tree = BIT(N)

query = [[] for _ in range(N + 1)]
for q in range(Q):
    l, r = map(int, input().split())
    query[r].append((q, l))

index = [-1] * (N + 1)
ans = [0] * Q

for r in range(1, N + 1):
    if index[C[r]] > 0:
        tree.add(index[C[r]], -1)
    tree.add(r, 1)
    index[C[r]] = r

    for q, l in query[r]:
        ans[q] = tree.sum(r) - tree.sum(l - 1)

print(*ans, sep='\n')


Measured memory_bytes: 208468
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

#define MAX_H 2001
#define MAX_W 2001
using namespace std;
typedef long long ll;

ll H, W;
char grid[MAX_H][MAX_W];
ll dh[MAX_H][MAX_W];
ll dw[MAX_H][MAX_W];

ll dfs_h(ll i, ll j, ll d) {
  if (i + 1 == H) {
    dh[i][j] = d;
    return d;
  }
  else if (grid[i + 1][j] == '#') {
    dh[i][j] = d;    
    return d;
  }
  
  ll depth = dfs_h(i + 1, j, ++d);
  dh[i][j] = depth;
  return depth;
}

ll dfs_w(ll i, ll j, ll d) {
  if (j + 1 == W) {
    dw[i][j] = d;
    return d;
  }
  else if (grid[i][j + 1] == '#') {
    dw[i][j] = d;    
    return d;
  }
  ll depth = dfs_w(i, j + 1, ++d);
  dw[i][j] = depth;
  return depth;
}


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

    cin >> H >> W;
    for (ll i = 0; i < H; i++) {
      for (ll j = 0; j < W; j++) {
	cin >> grid[i][j];
	dh[i][j] = -1;
	dw[i][j] = -1;
      }
    }

    for (ll i = 0; i < H; i++) {
      for (ll j = 0; j < W; j++) {
	if (grid[i][j] != '#' && dh[i][j] == -1) dfs_h(i, j, 1);
	if (grid[i][j] != '#' && dw[i][j] == -1) dfs_w(i, j, 1);
      }
    } 

    ll ans = 0;
    for (ll i = 0; i < H; i++) {
      for (ll j = 0; j < W; j++) {
	ans = max(ans, dh[i][j] + dw[i][j]);
      }
    }

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


Measured memory_bytes: 69596
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


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, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/



//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}

/*最小公倍数*/
template<typename T>
T lcm(T x, T y) {
	T tmp = gcd(x, y);
	return x * y / tmp;
}


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);


	string s;
	cin >> s;
	int ans = 0;
	for (int i = 1; i < s.size(); i++)
	{
		if (s[i] == s[i - 1]) {
			ans++;
			if (s[i] == '0') {
				s[i] = '1';
			}
			else
			{
				s[i] = '0';
			}
		}
	}
	cout << ans << endl;





	return 0;
}


Measured memory_bytes: 512
S=input()
A=int(S[0])
B=int(S[1])
C=int(S[2])
D=int(S[3])
ans=""
for x in [1,-1]:
  for y in [1,-1]:
    for z in [1,-1]:
      if A+B*x+C*y+D*z==7:
        if x==1:
          sx="+"
        else:
          sx="-"
        if y==1:
          sy="+"
        else:
          sy="-"
        if z==1:
          sz="+"
        else:
          sz="-"
        ans=str(A)+sx+str(B)+sy+str(C)+sz+str(D)+"=7"
print(ans)

Measured memory_bytes: 9160
#include <bits/stdc++.h>
#include <unordered_map>
#define mem(ara, a) memset(ara, a, sizeof(ara))
#define fo freopen("output.txt", "w", stdout)
#define fi freopen("bruh.txt", "r", stdin)
#define int long long
#define sp " "
#define pb push_back
#define ff first
#define sz(x) x.size();
#define len(x) x.length();
#define ss second
#define vi vector<int>
#define double long double
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define pii pair<int, int>


long long inf = 2e18;
long long minf = -inf;
int ans = 0;
using namespace std;

signed main() {
 int k ,a , b;
 cin >> k >> a >> b;
 if(a%k==0){
    cout<<"OK"<<endl;
    exit(0);
 }
int f=((a/k)+1)*k;
if(f>=a and f<=b)cout<<"OK";
else cout<<"NG";

}


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

int main()
{
  int d, g;
  int p[20];
  int c[20];
  cin >> d >> g;

  for (int i = 0; i < d; ++i)
  {
    cin >> p[i] >> c[i];
  }

  int minCount = 100000000;
  for (int f = 0; f < (1 << d); ++f)
  {
    int total = 0;
    int count = 0;
    int restMax_i = 0;
    for (int i = 0; i < d; ++i)
    {
      if (f & (1 << i))
      {
        total += p[i] * 100 * (i + 1) + c[i];
        count += p[i];
      }
      else
      {
        restMax_i = i;
      }
    }
    if (total >= g)
    {
      // トータルが条件を満たしていたら、最小かどうかチェックして次へ
      if (count < minCount)
      {
        minCount = count;
      }
      continue;
    }

    // 目標より低い場合、説いてない問題で一番点数の高いもので調べる
    for (int i = 1; i < p[restMax_i]; ++i)
    {
      total += (restMax_i + 1) * 100;
      count++;
      // total が超えたらbreak;
      if (total >= g)
      {
        break;
      }
    }
    if (total >= g)
    {
      if (count < minCount)
      {
        minCount = count;
      }
    }
  }

  cout << minCount << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL

const int N = 100005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif


signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int a, b, c; cin>>a>>b>>c;
    swap(a, b); swap(a, c);
    cout<<a<<" "<<b<<" "<<c;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const long long INF = 9223372036854775807;

struct datum {
  long long min, max;

  datum &update(long long x) {
    if (x < min) min = x;
    if (x > max) max = x;
    return *this;
  }

  long long diff() const { return max - min; }
};

datum operator^(const datum &a, const datum &b) {
  return a.diff() <= b.diff() ? a : b;
}

datum dfs(long long h, long long w, int n) {
  if (n == 1) {
    long long S = h * w;
    return {S, S};
  }

  return dfs(h - h / n, w, n - 1).update(h / n * w) ^
         dfs(h - (h / n + 1), w, n - 1).update((h / n + 1) * w) ^
         dfs(h, w - w / n, n - 1).update(h * (w / n)) ^
         dfs(h, w - (w / n + 1), n - 1).update(h * (w / n + 1));
}

int main() {
  int H, W;
  cin >> H >> W;

  cout << dfs(H, W, 3).diff() << endl;
}


Measured memory_bytes: 3556
def get_ac(n, q, s, lrli):

    ans = []
    nli = [0]*(n+1)

    for i in range(1, n):
        if s[i] == "C" and s[i-1] == "A":
            nli[i+1] = nli[i] + 1
        else:
            nli[i+1] = nli[i]

    for i in lrli:
        ans.append(nli[i[1]]-nli[i[0]])

    return ans

def main():
    n, q = map(int, input().split())
    s = list(str(input()))
    lrli = [list(map(int, input().split()))for i in range(q)]
    ans = get_ac(n, q, s, lrli)
    for i in ans:
        print(i)

if __name__ == '__main__':
    main()

Measured memory_bytes: 34516
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define debug_array(a,n) for (ll bccc=(0); bccc<(n); bccc++) cout<<a[bccc]<<" "
#define debug_vector(a) for(ll bccc=(0); bccc<(a.size());bccc++) cout<<a[bccc]<<" "
#define F           first
#define S           second
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll i;
    for(i=0;i<b;i++)
        c*=a;
    return c;
}
ll hell=1000000007;
//ll hell=998244353 ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
// mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());  after namespace std
// srand(chrono::high_resolution_clock::now().time_since_epoch().count()); after ios:base
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ll dp[102][2605];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,i,j;
    cin>>n;
    int a[n+1];
    for(i=1;i<=n;i++)
        cin>>a[i];
    ll b[n+1]={0};
    for(i=n;i>=1;i--)
    {
        ll c=0;
        for(j=i;j<=n;j+=i)
            c+=b[j];
        c%=2;
        if(c!=a[i])
            b[i]=1;
    }
    vector<ll> v;
    for(i=1;i<=n;i++)
        if(b[i])
            v.pb(i);
    cout<<v.size()<<"\n";
    for(i=0;i<v.size();i++)
        cout<<v[i]<<" ";
    return 0;
}


Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define INF (1e18)

struct UnionFind {
private:
    ll N;
    vector<ll> parent;
    vector<ll> num;
    vector<ll> diff_weight;
    vector<ll> rank;

public:
    UnionFind(ll n){
        N = n;
        rep(i,0,N) parent.push_back(i);
        rep(i,0,N) num.push_back(1);
        rep(i,0,N) diff_weight.push_back(0);
        rep(i,0,N) rank.push_back(0);
    }
    ll root(ll x){
        if(x == parent[x]){
            return x;
        }else{
            ll r = root(parent[x]);
            diff_weight[x] += diff_weight[parent[x]];
            return parent[x] = r;
        }
    }
    void unite(ll a, ll b, ll w = 0){
        w += weight(a); w -= weight(b);
        a = root(a); b = root(b);
        if(a == b) return;
        parent[b] = a;
        ll sum = num[a] + num[b];
        num[a] = sum;
        num[b] = sum;
        diff_weight[b] = w;
    }

    bool same(ll a, ll b){ return root(a) == root(b);}
    ll sz(ll x){ return num[x];}

    ll weight(ll x){
        root(x);
        return diff_weight[x];
    }

    ll diff(ll a, ll b){
        return weight(b) - weight(a);
    }
};
int main(){   
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin >> N >> M;
    ll A[100010], B[100010];
    rep(i,0,M){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }
    UnionFind uf(100010);
    ll v = N*(N-1)/2;
    vector<ll> ans;
    ans.push_back(v);
    rrep(i,M-1,0){
        if(uf.same(A[i], B[i])){
            ans.push_back(v);
        }else{
            v -= uf.sz(uf.root(A[i])) * uf.sz(uf.root(B[i]));
            uf.unite(A[i], B[i]);
            ans.push_back(v);
        }
    }
    rrep(i,M-1,0){
        print(ans[i]);
    }
}


Measured memory_bytes: 6900
inf = 10**12


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

    class Bit:
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x):
            while i <= self.size:
                self.tree[i] += x
                i += i & -i

        def lower_bound(self, w):
            if w <= 0:
                return 0
            x = 0
            k = 1 << (self.size.bit_length() - 1)
            while k:
                if x + k <= self.size and self.tree[x + k] < w:
                    w -= self.tree[x + k]
                    x += k
                k >>= 1
            return x + 1

    D = int(input())
    C = list(map(int, input().split()))
    S = [[]]
    for _ in range(D):
        S.append(list(map(int, input().split())))
    ans = 0
    last = [0] * 26
    days = [Bit(D+1) for _ in range(26)]
    for i in range(26):
        days[i].add(D+1, 1)
    T = [-1]
    # greedy
    for d in range(1, D+1):
        plus = -inf
        t = -1
        for tt in range(26):
            plus_new = S[d][tt] + C[tt] * (d - last[tt])
            if plus_new > plus:
                t = tt
                plus = plus_new
        T.append(t)
        ans += S[d][t]
        last[t] = d
        days[t].add(d, 1)
        for i in range(26):
            ans -= C[i] * (d - last[i])

    def calc(d_list, q_list, cur):
        for d, q in zip(d_list, q_list):
            t = T[d]
            cur += S[d][q]
            cur -= S[d][t]
            k = days[q].sum(d)
            i = days[q].lower_bound(k)
            j = days[q].lower_bound(k+1)
            cur += C[q] * (d - i) * (j - d)
            k = days[t].sum(d)
            i = days[t].lower_bound(k-1)
            j = days[t].lower_bound(k+1)
            cur -= C[t] * (d - i) * (j - d)

            T[d] = q
            days[q].add(d, 1)
            days[t].add(d, -1)
        return cur


    # climb
    size = 5
    try_num = 200
    loop_num = 10
    for _ in range(loop_num):
        for x in range(D // size):
            d_list = list(range(x*size+1, (x+1)*size+1))
            for _ in range(try_num):
                t_new = [randint(0, 25) for _ in range(size)]
                for i, d in enumerate(d_list):
                    if t_new[i] == T[d]:
                        t_new[i] = (t_new[i] + 1)%26
                t_ori = []
                for d in d_list:
                    t_ori.append(T[d])
                ans_new = calc(d_list, t_new, ans)
                if ans_new < ans:
                    for i in range(size-1, -1, -1):
                        d = d_list[i]
                        T[d] = t_ori[i]
                        days[t_ori[i]].add(d, 1)
                        days[t_new[i]].add(d, -1)
                else:
                    ans = ans_new
    # print(ans)
    for t in T[1:]:
        print(t+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 92592
#include<bits/stdc++.h>
typedef long long ll;
#define moot 1000000007
 
using namespace std;
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
    int N;
    cin>>N;
    int one = N % 10;
    if(one == 2 || one == 4 || one == 5 || one == 7 || one == 9)
      cout<<"hon";
    else if(one == 0 || one == 1 || one == 6 || one == 8)
      cout<<"pon";
    else
      cout<<"bon";
    
  return 0;  
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define INF 1e7

using namespace std;
typedef long long int ll;

int main()
{
    int N; cin >> N;
    vector<pair<int,int>>v;
    for(int i = 0; i < N; i++)
    {
        int x,l; cin >> x >> l;
        v.push_back(pair(x+l,x-l));
    }
    sort(v.begin(),v.end());
    int ans = 1;
    int r = v[0].first;
    for(int i = 0; i < N-1; i++)
    {
        if(v[i+1].second < r) continue;
        ans++;
        r = v[i+1].first;
    }
    cout << ans << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<pair<double, double>> p(N);
  vector<int> a(N);
  double b = 1.0;
  
  for(int i = 0; i < N; i++) {
    cin >> p.at(i).first >> p.at(i).second;
    a.at(i) = i;
    b *= (double) (i + 1);
  }
  
  double ans = 0.0, tmp;
  
  do {
    for (int i = 0; i < N - 1; i++) {
      tmp = (p.at(a.at(i)).first - p.at(a.at(i + 1)).first) * (p.at(a.at(i)).first - p.at(a.at(i + 1)).first) + (p.at(a.at(i)).second - p.at(a.at(i + 1)).second) * (p.at(a.at(i)).second - p.at(a.at(i + 1)).second);
      ans += pow(tmp, 0.5);
    }
  } while (next_permutation(a.begin(), a.end()));
  
  std::cout << std::setprecision(15);
  cout << ans / b;
  
  return 0;
}



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

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int ans = 0;

void process(vi x) {
    /*for (int i: x) cout << i << " ";
    cout << "\n";*/
    ans += sz(x)/2;    
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vi a;
    F0R(i,n) {
        int x; cin >> x;
        if (sz(a) && a.back() == x) a.pb(x);
        else {
            process(a);
            a.clear();
            a.pb(x);
        }
    }
    process(a);
    cout << ans;
}

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
*/

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

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

int main() {
    //cout.precision(10);
    int N;
    cin >> N;
    int ans;
    cin >> ans;
    for(int i = 2; i <= N; i++) {
        int a;
        cin >> a;
        ans = gcd(ans, a);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
function main(){
  var i = 0;
  while(true){
    var fieldInfo = input[i].split(' ');
    var width = fieldInfo[0] - 0;//toInt
    var height = fieldInfo[1] - 0;//toInt

    // 0 0が入力された
    if(!width && !height){
      break;
    }

    var start;
    var goal;
    var elem = [[],[],[],[],[]];
    for(var ei = 0;ei < 5; ei++){
      elem[ei].length = 0;
    }
    
    for(var y = 0; y < height; y++){
      i++;//1行進める
      for(var x = 0; x < width; x++){
        var c = input[i][x];

        switch(c){
        case 'S':
          start = new Pos(x, y);
          break;
        case 'G':
          goal = new Pos(x, y);
          break;
        case '.':
          break;
        default : // 入力値が正しいので、絶対に属性
          elem[c-1][elem[c-1].length] = new Pos(x, y);
          break;
        }
      }
    }

    
    var bestElement = -1;
    var distance = Infinity;
    
    // 属性ごとにループ
    for (var startElem = 0; startElem < 5; startElem++) {
      // DPの初期化 DP[属性][同じ属性内の連番]
      var dp = [[],[],[],[],[]];
      for(var h = 0; h < 5; h++){
        var hLength = elem[h].length;
        dp[h].length = hLength;
        for(var hidx = 0; hidx < hLength; hidx++){
          dp[h][hidx] = Infinity;
        }
      }
      
      // 最初に選んだパチモンから次に捕まえられる属性番号
      var first = (startElem + 1) % 5;

      for (var j = 0, firstLength = elem[first].length; j < firstLength; j++) {
        // s→e1を計算
        dp[first][j] = dist(start, elem[first][j]);
      }
      
      // s->1->2->3->4->g
      // なので、ループは間の-> * 3分まわす
      for (var e = 0; e < 3; e++) {
        // ex->e(x+1)
        var now = (first + e) % 5;
        var next = (now + 1) % 5;

        for (var j = 0, nowLength = elem[now].length; j < nowLength; j++) {
          for (var k = 0, nextLength = elem[next].length; k < nextLength; k++) {
            dp[next][k] = min(
              dp[next][k],
              dp[now][j] + 
                  dist(elem[now][j], elem[next][k]));
          }
        }
      }
      
      var last = (first + 3) % 5;
      var lastLength = elem[last].length;
      for (var j = 0; j < lastLength; j++) {
        // e4->g
        var d = dp[last][j] + 
                    dist(elem[last][j], goal);
        
        if (d < distance) {
          distance = d;
          bestElement = startElem + 1;
        }
        
      }
      
    }
    
    if (distance == Infinity) {
      console.log("NA");
    } else {
      console.log(bestElement + " " + distance);
    }

    i++;
  }
  

}

function dist(from, to){
  return Math.abs(from.x - to.x) + Math.abs(from.y - to.y)
}

function min(a1, a2){
  return a1 < a2 ? a1 : a2;
}

function Pos(a, b){
  this.x = a;
  this.y = b;
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 63488
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define inf INT_MAX;
int n, d, m, t;
map<int, int> mp;
int main() {
	cin >> n;
	rep(i, n) {
		cin >> d;
		mp[d]++;
	}
	cin >> m;
	rep(i, m) {
		cin >> t;
		if (mp[t] > 0)mp[t]--;
		else {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){
	int a,b,ans=0;cin>>a>>b;
	for(int i=a;i<=b;i++){
		string s,s2("     ");s=to_string(i);
		reverse_copy(s.begin(),s.end(),s2.begin());
		//cout<<s<<" "<<s2.size()<<"\n";
		ans += (s==s2);
	}
	cout<<ans;
}


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

int m, n;
int w[100];

bool check(int mid){
    int tmpm = 1, nowp = 0;
    for(int i = 0; i < n; i++){
        if(mid < w[i])  return false;

        if(nowp + w[i] <= mid){
            nowp += w[i];
        }else{
            nowp = w[i];
            tmpm++;
        }
    }
    return tmpm <= m;
}

int main(){
    while(1){
        cin >> m >> n;

        if(m + n == 0)  break;

        int minp = 1000001;
        for(int i = 0; i < n; i++){
            cin >> w[i];
            minp = min(minp, w[i]); 
        }

        int l = 1, r = 1500000;

        while(r-l > 1){
            int mid = (r+l) / 2;
            if(check(mid))  r = mid;
            else            l = mid;
        }

        cout << (check(l) ? l : r) << endl;
    }

    return 0;
}


Measured memory_bytes: 3092
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int 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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<pair<ll, ll>> v;
    rep(i,n){
        ll a, b;
        cin >> a >> b;
        v.emplace_back(a, b);
    }
    sort(v.begin(), v.end());
    rep(i,n){
        if(k <= v[i].second){
            cout << v[i].first << endl;
            return 0;
        }
        k -= v[i].second;
    }
    return 0;
}

Measured memory_bytes: 2420
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1000000007
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65
//おまじない



int main() {

	int n;
	cin >> n;
	unsigned long long int ans = 1;

	roop(i, 1, n+1) {
		ans = (ans * i)%INF;
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
eval(%w'dx=[-
                      1,0,1        ,-1,1,-1,0,  1];d
                  y=[-1,-1,-1,    0,0, 1,1,1];   m=[[]
                 ];de       fine_ met   hod(:r)   {|t,u
                ,v,     g   |m[t]  [u]   =0;8.ti   mes{|
          i|if(t+dx.at (     i)>=0&&t+d   x.at(i   )<v&&
       u+dy.  at(i)>     =0   &&u+dy.at   (i)<g&&   m[t+
     dx.at(    i)][u+dy    .a  t(  i)]==1);r(t+     dx.
    at(i),u+        dy   .      a    t (i),        v,g
   );end}};          lo     op{         w     ,h=gets
  .c   h         o    mp.spl  i      t   .map(&:to
  _i    )    ;    i    f(w==   0  &   &   h==0);b
  rea    k   ;e   nd   ;m=Arr      a      y.new(w
  ).ma   p    {A        rray.n   ew(h   ,0)};h.ti
   mes{      |y|    s=gets.chomp.spli   t.map(&:
    to_i);w.times   {|x|m[x][y]=s[x]} };c=0;h.ti
     mes{|y|w.ti     mes{|x| if(m[x][y]==1);c+
       =1;r(x,y,   w,h);e        nd}};puts
          (c)}'.join)


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    int n;
    string s;
    int k;
    cin>>n>>s>>k;
    k--;
    for (int i=0; i<n; i++) {
	if (s[i]!=s[k]) s[i]='*';
    }
    out(s);
    
    
    return 0;
}


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

def solve():
    N = int(input())
    S = input()

    pre_color = S[0]
    ans = 1
    for i in range(1, N):
        color = S[i]

        if pre_color == color:
            continue
        else:
            ans += 1
            pre_color = color

    print(ans)

if __name__ == "__main__":
    solve()


Measured memory_bytes: 3316
/* SANDEEP YADAV*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define lld long double
#define umap unordered_map<>
#define sz(x) ((ll)((x).size()))
#define all(x) (x).begin(),(x).end()
#define vi vector<int>
#define pi pair<int, int>
#define setp cout<<fixed<<setprecision(6)
#define loop(i,a,b)  for(int i=a;i<b;i++)
#define rloop(i,b,a) for(int i=b-1;i>=a;i--)
#define vl vector<ll>
#define pl pair<ll, ll>
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll gcd(ll a,ll b){ if(a<b) { a=a+b; b=a-b; a=a-b;}while(b!=0){ll r=a%b; a=b; b=r;} return a;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long power(long long a, long long b, long long m) {a %= m;long long res = 1;while (b > 0) {if (b & 1)res = res * a % m;a = a * a % m;b >>= 1;}return res;}
const int N=1000005;
void judge()
{
      #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
    #endif
}
struct myhash
{
    static uint64_t fxn(uint64_t x)
    {
        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 fxn(x + FIXED_RANDOM);
    }
};
lld dp[3000][3000];

void solve(int tc)
{
    ll n;
    cin>>n;

    lld a[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    dp[0][0]=1;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            if((i==0&&j==0)||i+j>n)
                continue;
            else if(j==0)
                dp[i][j]=dp[i-1][j]*(a[i]);
            else if(i==0)
                dp[i][j]=dp[i][j-1]*(1-a[j]);
            else
                dp[i][j]=dp[i][j-1]*(1-a[i+j])+dp[i-1][j]*(a[i+j]);
        }
    }
    
    lld ans=0.0;
    for(int i=0;i<=n;i++)
    {
        if(i>=n-i)
            break;
        ans+=dp[n-i][i];
    }
     cout<<fixed<<setprecision(10)<<ans;
    



    return;
}
int main()
{
    fastio;
  //  judge();

    int T=1;
    // cin>>T;
    for(int tc=1;tc<=T;tc++)
    {
        solve(tc);
    }
    return 0;
}

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

int main() {
  int n; cin >> n;
  int x; cin >> x;
  int cnt = 1;
  for (int i = 0; i < n; ++i) {
    int l; cin >> l;
    x -= l;
    if (x >= 0) ++cnt;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int box[] = new int[N];
		int box_red[] = new int[N];

		int x;
		int y;

		int ans = 0;

		for (int i = 0; i < N; i++){
			if (i==0)box_red[i] = 1;
			else box_red[i] = 0;

			box[i] = 1;
		}

		for (int i = 0; i < M; i++) {
			x = sc.nextInt();
			y = sc.nextInt();

			if(box_red[x-1]> 0){
			//	box_red[y-1] = box_red[y-1] + 1;
				box_red[y-1] = 1;
				if(box[x-1] == 1){
				//	box_red[x-1] = box_red[x-1] - 1;
					box_red[x-1] = 0;
				}
			}

			if(box[x-1]>0){
			box[y-1] ++;
			box[x-1] --;
			}
		}

		for (int i = 0; i < N; i++){
			if(box_red[i]>0) ans++;
		}

		System.out.println(ans);
		sc.close();

	}
}



Measured memory_bytes: 23936
//be naame khodaa

#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <cstdio>
#include <algorithm>
#include <set>
#include <cassert>
#include <iomanip>
#include <cstring>
#include <sstream>
#define fi first
#define se second
#define rep(i, x, n) for (int i = x; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> VI;

int main()
{
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	for (int i = 0; i+1 < s.length(); i++)
		if (s[i] == 'A' && s[i+1] == 'C')
			return (cout << "Yes\n"), 0;
	cout << "No\n";
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> isPair;
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
#define Pll pair<ll,ll>
#define vpll vector<pll>
#define sll set<ll>
#define mll map<ll,ll>

const ll oo=1e18;
const ll maxs = 3e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
#define mp make_pair
#define I insert
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define LB lower_bound
#define UB upper_bound
#define line() cout<<endl;
#define fr(i,a,b) for(int i=a;i<=b;++i)
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mst(x,a) memset(x,a,sizeof(x))

ll fact[maxs];
ll ifact[maxs];

ll mul(ll a,ll b)
{
    return (a*b)%mod;
}

ll fast(ll x,ll y)
{
    ll res = 1;
    while(y)
    {
        if(y&1)
            res  = (res*x)%mod;
            
        y>>=1;
        x = (x*x)%mod;
    }
    return res;
}

ll inv(ll n)
{
    return fast(n,mod-2);
}

ll ncr(ll n,ll r)
{
    return mul(fact[n] , mul(ifact[n-r] , ifact[r]));
}

int main() 
{
    fastio();
    fact[0] = 1;
    ifact[0] = 1;
    for(ll i=1;i<maxs;i++){
        fact[i] = (fact[i-1]*i)%mod;
        ifact[i] = (inv(fact[i]));
    }    
	ll t=1;
    //cin>>t;
    while(t--){
        ll n,k;
        cin>>n>>k;
        ll ANS=0;
        for(ll i=0;i<=min(n-1,k);i++){
            ll z = i;
            ll rem = n-i;
            ll val = mul( ncr(n,z) , ncr(z + rem-1 , rem-1) );
            //cout << i << " " << val << endl; 
            ANS += val;
            if(ANS > mod)
                ANS %= mod;
        }
        cout << ANS << endl;
    }  
    return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.HashSet;
import java.util.List;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //Library lib = new Library();
        int n = sc.nextInt();
        ArrayList<Integer> p = new ArrayList<>();
        for (int i=0;i<n;i++){
            p.add(sc.nextInt());
        }
        int ans = 0;
        for (int i=1;i<n-1;i++){
            if (p.get(i-1)<p.get(i) && p.get(i)<p.get(i+1)){
                ans++;
            } else if(p.get(i+1)<p.get(i) && p.get(i)<p.get(i-1)){
                ans++;
            }
        }
        System.out.println(ans);
    }
}

/*class Library{
    static long a;
    static long b;

    public static long gcd(long a,long b){
        Library lib = new Library();
        if (a<b){
            lib.swap(a,b);
        }
        if (b==0){
            return a;
        } else {
            return gcd(b,a%b);
        }
    }

    public static void swap(long a,long b){
        long x = a;
        a = b;
        b = x;
        return;
    }
}*/

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> C(M);
    rep(i, M) cin >> C[i];
    vector<ll> dp(N + 1, INF);
    dp[0] = 0;
    rep(i, N + 1) {
        rep(j, M) {
            ll c = C[j];
            if (i - c >= 0) {
                dp[i] = min(dp[i], dp[i - c] + 1);
            }
        }
    }
    cout << dp[N] << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}



Measured memory_bytes: 3340
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<ll, ll>;

const int MAXN = 1e2 + 2;
const int MAXW = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}

int N, W;
ll dp[MAXN][MAXW], w[MAXN], v[MAXN];

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

	cin >> N >> W;

	for (int i = 1 ; i <= N ; ++i) {
		cin >> w[i] >> v[i];
	}

	dp[0][0] = 0;


	for (int i = 1 ; i <= N; ++i) {
		for (ll j = 0; j <= W; ++j) {
			if (j - w[i] >= 0) dp[i][j] = max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]);
			dp[i][j] = max(dp[i - 1][j], dp[i][j]);
		}
	}

	cout << dp[N][W] << endl;

	return 0;
}

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

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


int n;
int a[300000];

int main(){
	cin >> n;
	for(int i = 0; i < 3*n; i++){
		cin >> a[i];
	}
	
	sort(a,a+(3*n));
	
	ll c = 0;
	for(int i = n; i < n*3; i+=2){
		c += a[i];
	}
	
	cout << c << endl;
	
	return 0;
}

Measured memory_bytes: 1536
/*    Don’t Quit
    
    When things go wrong as they sometimes will;
        When the road you’re trudging seems all uphill;
            When the funds are low, and the debts are high;
                And you want to smile, but you have to sigh;
                    When care is pressing you down a bit
                        Rest if you must, but don’t you quit.
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=3e5+10;
int a[N];
int32_t main()
{
    int n;
    cin>>n;
    map<char,int>mp;
    string s;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        mp[s[0]]++;
    }
    int k=mp['M']*mp['A']*mp['R'];
    k+=mp['M']*mp['A']*mp['C'];
    k+=mp['M']*mp['A']*mp['H'];
    k+=mp['M']*mp['R']*mp['C'];
    k+=mp['M']*mp['R']*mp['H'];
    k+=mp['M']*mp['C']*mp['H'];
    k+=mp['A']*mp['R']*mp['C'];
    k+=mp['A']*mp['R']*mp['H'];
    k+=mp['A']*mp['C']*mp['H'];
    k+=mp['R']*mp['C']*mp['H'];
    cout<<k<<endl;








}

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

int lcs(string X, string Y) {
  int m = X.size();
  int n = Y.size();
  int c[m+1][n+1];
  X = ' ' + X;
  Y = ' ' + Y;
  for (int i=0; i<m+1; i++) {
    c[i][0] = 0;
  }
  for (int j=0; j<n+1; j++) {
    c[0][j] = 0;
  }

  int max_lcs = 0;
  for (int i=1; i<m+1; i++) {
    for (int j=1; j<n+1; j++) {
      if (X[i]==Y[j]) {
        c[i][j] = c[i-1][j-1] + 1;
      } else {
        c[i][j] = max(c[i-1][j], c[i][j-1]);
      }
      max_lcs = max(max_lcs, c[i][j]);
    }
  }

  return max_lcs;
}


int main() {
  int N;
  string X, Y;
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> X >> Y;
    cout << lcs(X, Y) << endl;
  }
  return 0;
}



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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll>h(n);
  rep(i,n) cin >> h[i];
  sort(h.begin(), h.end());
  ll ans = 100100100100;
  ll cost = (ll)0;
  for (ll i = 0; i < (n-k+1); ++i){
    cost = h[i+k-1]-h[i];
    ans = min(cost, ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024