akhauriyash/Code-Regression huggingface dataset:
import networkx as nx

BIT_SHIFT = 9
BIT_MASK = (1 << BIT_SHIFT) - 1


def combine_rc(r, c):
    return (r << BIT_SHIFT) | c


def separate_rc(rc):
    return rc >> BIT_SHIFT, rc & BIT_MASK


def solve(n, m, sss):
    m2 = m + 2
    lefts = set()
    rights = set()

    for r in range(1, n + 1):
        for c in range(1, m + 1):
            if sss[r][c] == '#':
                continue
            rc = combine_rc(r, c)
            if (r ^ c) & 1:
                lefts.add(rc)
            else:
                rights.add(rc)

    edges = []
    MOVE = (-(1 << BIT_SHIFT), -1, 1, 1 << BIT_SHIFT)
    for rc in lefts:
        for d in MOVE:
            nrc = rc + d
            if nrc in rights:
                edges.append((rc, nrc))
    BG = nx.Graph()
    BG.add_nodes_from(lefts, bipartite=0)
    BG.add_nodes_from(rights, bipartite=1)
    BG.add_edges_from(edges)

    ans = 0
    for sub in nx.connected_components(BG):
        matched = nx.bipartite.maximum_matching(BG.subgraph(sub))

        for rc1, rc2 in matched.items():
            r1, c1 = separate_rc(rc1)
            if (r1 ^ c1) & 1:
                continue
            r2, c2 = separate_rc(rc2)
            if r1 == r2:
                if c1 > c2:
                    c1, c2 = c2, c1
                sss[r1][c1] = '>'
                sss[r2][c2] = '<'
            else:
                if r1 > r2:
                    r1, r2 = r2, r1
                sss[r1][c1] = 'v'
                sss[r2][c2] = '^'
            ans += 1

    return ans


n, m = map(int, input().split())
n2, m2 = n + 2, m + 2
sss = [['#'] * m2 for _ in range(n2)]
for i in range(1, n + 1):
    sss[i][1:m + 1] = list(input())

ans = solve(n, m, sss)
print(ans)
for i in range(1, n + 1):
    print(''.join(sss[i][1:m + 1]))


Measured memory_bytes: 68720
#include <bits/stdc++.h>
#define pb emplace_back
#define fi first
#define se second
#define int long long
#define inf 100000000000000
using namespace std;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int l) { uniform_int_distribution<int> uid(0, l - 1); return uid(rang); }

int dp[400005];
int seg[1600005];
int d[400005];
int n, h;
void apply(int i, int val) {
	seg[i] += val;
	if (i < n) d[i] += val;
}

void build(int p) {
	while(p > 1) p >>= 1, seg[p] = max(seg[p << 1], seg[p << 1 | 1]) + d[p];
}

void push(int p) {
	for (int s = h; s > 0; --s) {
		int i = p >> s;
		if (d[i] != 0) {
			apply(i << 1ll, d[i]);
			apply(i << 1ll | 1ll, d[i]);
			d[i] = 0;
		}
	}
}

void inc(int l, int r, int val) {
	r += (n + 1);
	l += n;
	int l0 = l, r0 = r;
	for(; l < r; l >>= 1ll, r >>= 1ll) {
		if(l & 1) apply(l++, val);
		if(r & 1) apply(--r, val);
	}
	build(l0);
	build(r0 - 1);
}

int query(int l, int r) {
	r += n + 1ll; l += n;
	push(l); push(r - 1);
	int y = -inf;
	for(; l < r; l >>= 1, r >>= 1) {
		if(l & 1) y = max(y, seg[l++]);
		if(r & 1) y = max(y, seg[--r]);
	}
	return y;
}


int32_t main() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cin >> n; n++;
	h = sizeof(int) * 8 - __builtin_clz(n);
	int m; cin >> m;
	std::vector<pair<int, int> > l(m);
	std::vector<int> L(m);
	std::vector<int> R(m);
	std::vector<int> a(m);
	std::vector<pair<int, int> > r(m);
	for (int i = 0; i < m; ++i) {
		cin >> l[i].fi >> r[i].fi >> a[i]; r[i].se = l[i].se = i; R[i] = r[i].fi; L[i] = l[i].fi;
	}
	sort(l.begin(), l.end());
	sort(r.begin(), r.end());
	int j = 0;
	int k = 0;
	for (int i = 1; i < n; ++i) {
		while (j < m && l[j].fi == i) {
			inc(0, i - 1, a[l[j].se]);
			j++;
		}
		dp[i] = query(0, i - 1);
		inc(i, i, dp[i]);
		dp[i] = max(dp[i], dp[i - 1]);
		while (k < m && r[k].fi == i) {
			inc(0, L[r[k].se] - 1, -a[r[k].se]);
			k++;
		}
	}
	cout << dp[n - 1];
}

Measured memory_bytes: 23040
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int> alph(26,0);
    string s;
    while(cin >> s){
        for(int i = 0; i < s.length(); i++){
            if(isupper(s[i])) s[i] = tolower(s[i]);
            alph[s[i]-'a']++;
        }
    }
    for(int i = 0; i < 26; i++){
        cout << (char)(i+'a') << " : " << alph[i] << endl;
    }
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define mp make_pair
#define pii pair<int,int>

using namespace std;



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

    ll a,b,c,d; cin>>a>>b>>c>>d;
    ll ans = -1e18 - 5;
    if(a <= 0 && b>= 0) ans = 0;
    if(c <= 0 && d >= 0) ans = 0;
    ans = max(ans,b * d);
    ans = max(ans,c * a);
    ans = max(ans,a * d);
    ans = max(ans,c * b);
    cout<<ans;


    return 0;

}



Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;
int main() {



	string s;

	cin >> s;

	int c;
	
	c = s.size();

	cout << s[0] << c - 2 << s[c - 1];

	return 0;
}

Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
 
cnt=0
for i in range(1,n-1):
  if p[i-1]<p[i] and p[i]<p[i+1]:
    cnt+=1
  elif p[i+1]<p[i] and p[i]<p[i-1]:
    cnt+=1
print(cnt)

Measured memory_bytes: 9188
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <climits>
#include <bitset>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple

using namespace std;

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

const int N = 1e5 + 10;

template <class T>
struct SegTree{
	int n;
	vector<T> lazy, Max;

	SegTree(int size){
		n = 1;
		while (n < size) n *= 2;

		lazy = Max = vector<T>(n * 2);
	}

	void add(int i, T val){
		add_range(i, i + 1, val);
	}
	void add_range(int a, int b, T val){
		add_range(a, b, val, 0, 0, n);
	}
	void add_range(int a, int b, T val, int k, int l, int r){
		if (r <= a || b <= l) return;
		if (a <= l && r <= b){
			Max[k] += val;
			lazy[k] += val;
			return;
		}

		add_range(a, b, val, k * 2 + 1, l, (l + r) / 2);
		add_range(a, b, val, k * 2 + 2, (l + r) / 2, r);

		Max[k] = max(Max[k * 2 + 1], Max[k * 2 + 2]) + lazy[k];
	}

	T query_max(int a, int b){
		return query_max(a, b, 0, 0, n);
	}

	T query_max(int a, int b, int k, int l, int r){
		if (r <= a || b <= l) return -1e15;
		if (a <= l && r <= b) return Max[k];
		return max(query_max(a, b, k * 2 + 1, l, (l + r) / 2), query_max(a, b, k * 2 + 2, (l + r) / 2, r)) + lazy[k];
	}
};

ll a[N];

ll n, m, c;
ll check(int R){
	SegTree<ll> rmq(n);

	ll res = 0;
	for (int i = 0; i < min((int)n, R+1); ++i){
		rmq.add(i, a[i] - i*c);
	}
	for (int i = 0; i < n; ++i){
		int l = max(i - R, 0);
		int r = min(i + R + 1, (int)n);

		res += rmq.query_max(l, r);
		//cout << "***" << rmq.query_max(l, r) << endl;
		//for (int j = l; j < r; ++j) cout << rmq.query_max(j, j + 1) << endl;
		//cout << endl;

		rmq.add_range(l, i + 1, -c);
		rmq.add_range(i + 1, r, c);
		if (i + R + 1 < n) rmq.add(i + R + 1, a[i + R + 1] - R*c);
	}

	return res;
}


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

	cin >> n >> m >> c;
	rep(i, n) cin >> a[i];

	int lb = -1, ub = 1e5 + 10;
	while (ub - lb > 1){
		int mid = (ub + lb) / 2;
		if (check(mid) >= m) ub = mid;
		else lb = mid;
	}

	if(ub <= 100000) cout << ub << endl;
	else cout << -1 << endl;


	return 0;
}


Measured memory_bytes: 6032
#include <iostream>
#include <algorithm>
#include <limits>

using namespace std;

const u_int64_t DMAX = numeric_limits<u_int64_t>::max();

u_int64_t dist[200][200];
int r[8];

template <typename F>
void with_perm(int *p, int size, F func)
{
    if (size == 0)
    {
        func();
        return;
    }
    for (int i = 0; i < size; i++)
    {
        swap(p[0], p[i]);
        with_perm(p + 1, size - 1, func);
        swap(p[0], p[i]);
    }
}

int main()
{
    int N, M, R;
    cin >> N >> M >> R;

    for (int i = 0; i < R; i++)
    {
        cin >> r[i];
        r[i]--;
    }

    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
        {
            dist[i][j] = i == j ? 0 : DMAX;
        }

    for (int i = 0; i < M; i++)
    {
        int a, b;
        u_int64_t c;

        cin >> a >> b >> c;
        a--;
        b--;

        dist[a][b] = dist[b][a] = c;
    }

    for (int k = 0; k < N; k++)
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
            {
                if (dist[i][k] != DMAX && dist[k][j] != DMAX)
                {
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }

    u_int64_t md = DMAX;
    with_perm(r, R, [&]() {
        u_int64_t d = 0;
        for (int i = 0; i < R - 1; i++)
        {
            int from = r[i];
            int to = r[i + 1];
            d += dist[from][to];
        }

        md = min(md, d);
        return;
    });

    cout << md << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    std::cout<<std::fixed<<std::setprecision(10);
    
    int N; cin >> N;
    bool perf = true;
    int ans = 0;
    int tempa = 1;
    rep(i, N) {
        int a; cin >> a;
        if (a != tempa) {
            // ansと同じaじゃないなら
            perf = false;
            ans += 1;
        } else {
            // ansと同じaなら
            tempa += 1;
        }
    }

    if (ans == N) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  cout << max((a + b), max((a - b), (a * b))) << endl;
  return 0;
}
//templete by private_yusuke

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

#include <iostream>
#include <algorithm>

#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <utility>
#include <array>
#include <complex>
#include <valarray>

#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>


using namespace std;
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod
#define inside(y, x, h, w) (0 <= (y) && (y) < (h) && 0 <= (x) && (x) < (w)) ? true : false

int n, z, w;
int a[2000 + 5], dp[2000 + 5][2];

int dfs(int now, int pl, int card1, int card2) {
    if (now == n) {
        return abs(card1 - card2);
    }
    if (dp[now][pl] != -1 && dp[now][pl] != INF) return dp[now][pl];
    if (pl == 0) {
        rep2(nx, now, n) {
            dp[now][pl] = max(dp[now][pl], dfs(nx + 1, pl^1, a[nx], card2));
        }
    }
    else {
        rep2(nx, now, n) {
            dp[now][pl] = min(dp[now][pl], dfs(nx + 1,  pl^1, card1, a[nx]));
        }
    }
    return dp[now][pl];
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> z >> w;
    rep(i, n) cin >> a[i];
    rep(i, n)rep(j, 2) {
        if (j == 0) {
            dp[i][j] = -1;
        }
        else {
            dp[i][j] =  INF;
        }
    }
    cout << dfs(0, 0, z, w) << endl;
}

Measured memory_bytes: 384
// Aizu 0288: Knocker of the Gigas Cedar
// 2017.9.10 bal4u@uu

#include <stdio.h>
#include <string.h>
#define INF 201

int a[102], e[102], r[102];
unsigned char dp[102][102];

int main()
{
	int d, n, i, j, k, f, ans;

	while (scanf("%d%d", &d, &n) && d > 0) {
		for (f = i = 0; i < n; i++) {
			scanf("%d%d%d", a+i, e+i, r+i);
			if (a[i] > 0) f = 1;
		}
		if (!f) { puts("NA"); continue; } 
	
		memset(dp, INF, sizeof(dp));
		dp[d][0] = 0;
		for (i = d; i >= 0; i--) for (j = 0; j <= 100; j++) {
			for (k = 0; k < n; k++) if (j >= r[k]) {
				int ni, nj;
				if (i > a[k]) ni = i-a[k]; else ni = 0;
				if (j + e[k] < 100) nj = j + e[k]; else nj = 100;
				if (dp[ni][nj] > dp[i][j] + 1) dp[ni][nj] = dp[i][j] + 1;
			}
		}

		for (ans = INF, i = 0; i <= 100; i++) if (dp[0][i] < ans) ans = dp[0][i];
		if (ans == INF) puts("NA");
		else printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1808
#include<bits/stdc++.h>
using namespace std;
int main(){

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

    if((A==5&&B==5&&C==7)||(A==5&&B==7&&C==5)||(A==7&&B==5&&C==5)){
        cout<<"YES"<<endl;
    }
else {
     cout<<"NO"<<endl;
}
return 0;
}


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

typedef long long int lli;
typedef long double lld;
typedef long long ll;
//Datatype
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define vvlli vector<vector<long long int>>
#define ppi pair<int, int>
#define rppi pair<int, pair<int, int>>
#define lppi pair<pair<int, int>, int>
#define vppi vector<pair<int, int>>
#define sppi stack<pair<int int>>
#define qppi queue<pair<int, int>>
//function
#define f first
#define s second
#define pb(x) push_back(x)
#define mkp(i, j) make_pair(i, j)
#define lmkp(i,j,k) make_pair(make_pair(i,j),k)
#define rmkp(i,j,k) make_pair(i,make_pair(j,k))
//loop
#define loop(i,n) for (i = 0; i < n; ++i)
#define loops(i,k,n) for (i = k; i <= n; ++i)
#define looprev(i,k,n) for (i = k; i >= n; --i)
//Const
#define inf (int)1e9
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
//Print
#define prd(n) printf("%d", n)
#define prl(n) printf("%lld", n)
#define prdn(n) printf("%d\n", n)
#define prln(n) printf("%lld\n", n)
#define prf(n) printf("%f", n)
//Scan
#define scd(n) scanf("%d", &n)
#define scd2(a, b) scanf("%d %d", &a, &b)
#define scd3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scl(n) scanf("%lld", &n)
#define scl2(a, b) scanf("%lld %lld", &a, &b)
#define scl3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define scf(n) scanf("%f", &n)

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<fixed;
    cout<<setprecision(10);
    lli i, j, k, N;
    cin>>N;
    vector<lld> A(N);
    loop(i, N){
        cin>>A[i];
    }
    vector<vector<lld>> dp(N+1, vector<lld>(N+1, 0.0));
    dp[0][0] = 1;
    loops(i, 1, N){
        loops(j, 0, i){
            dp[i][j] = j == 0 ? dp[i-1][j]*(1-A[i-1]) : (dp[i-1][j]*(1-A[i-1]) + dp[i-1][j-1]*A[i-1]);
        }
    }
    lld res = 0.0;
    for(i=N; i>N/2; i--){
        res+= dp[N][i];
    }
    cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 144260
#include<bits/stdc++.h>
using namespace std;
#define MAXN	1005
#define MAXLOG	105
#define P	1000000007
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int n, m;
long long k;
char mp[MAXN][MAXN];
long long power(long long x, long long y) {
	if (y == 0) return 1;
	long long tmp = power(x, y / 2);
	if (y % 2 == 0) return tmp * tmp % P;
	else return tmp * tmp % P * x % P;
}
int main() {
	read(n), read(m), read(k);
	if (k <= 1) {
		printf("1\n");
		return 0;
	}
	for (int i = 1; i <= n; i++)
		scanf("%s", mp[i] + 1);
	long long ver = 0, hor = 0;
	for (int i = 1; i <= n; i++)
		hor += mp[i][1] == '#' && mp[i][m] == '#';
	for (int i = 1; i <= m; i++)
		ver += mp[1][i] == '#' && mp[n][i] == '#';
	long long cnt = 0;
	for (int i = 1; i <= n; i++)
	for (int j = 1; j <= m; j++)
		cnt += mp[i][j] == '#';
	if (ver && hor) {
		printf("1\n");
		return 0;
	}
	if (ver == 0 && hor == 0) {
		printf("%lld\n", power(cnt, k - 1));
		return 0;
	}
	if (ver) {
		swap(ver, hor);
		for (int i = 1; i <= max(n, m); i++)
		for (int j = i; j <= max(n, m); j++)
			swap(mp[i][j], mp[j][i]);
		swap(n, m);
	}
	long long cmt = 0;
	for (int i = 1; i <= n; i++)
	for (int j = 2; j <= m; j++)
		cmt += mp[i][j] == '#' && mp[i][j - 1] == '#';
	static long long matrix[MAXLOG][2][2], ans[1][2], tmp[1][2];
	matrix[0][0][0] = cnt;
	matrix[0][0][1] = 0;
	matrix[0][1][0] = P - cmt;
	matrix[0][1][1] = hor;
	ans[0][0] = ans[0][1] = 1;
	long long now = 1, p = 0;
	k -= 1;
	while (k) {
		if (k & now) {
			tmp[0][0] = tmp[0][1] = 0;
			for (int i = 0; i <= 0; i++)
			for (int j = 0; j <= 1; j++)
			for (int l = 0; l <= 1; l++) {
				tmp[i][j] += ans[i][l] * matrix[p][l][j];
				tmp[i][j] %= P;
			}
			ans[0][0] = tmp[0][0];
			ans[0][1] = tmp[0][1];
			k ^= now;
		}
		p++, now <<= 1;
		for (int i = 0; i <= 1; i++)
		for (int j = 0; j <= 1; j++)
		for (int l = 0; l <= 1; l++) {
			matrix[p][i][j] += matrix[p - 1][i][l] * matrix[p - 1][l][j];
			matrix[p][i][j] %= P;
		}
	}
	cout << ans[0][0] << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int multi(double p, double y, double m, double c){
    rep(i,y){
        m+=static_cast<int>(m * p);
        m-=c;
    }
    return m;
}

int single(double p, double y, double m, double c){
    double r = 0;
    rep(i,y){
        r+=static_cast<int>( m * p );
        m-=c;
    }
    return r + m;
}

int main(){
    int m;
    cin >> m;
    rep(i,m){
        double money, year, n;
        int result = 0;
        cin >> money >> year >> n;
        rep(j,n){
            double d, par, charge;
            cin >> d >> par >> charge;
            if(d) result = max(result, multi(par, year, money, charge));
            else result = max(result, single(par, year, money, charge));
        }
        cout << result << endl;
    }
}

Measured memory_bytes: 1232
n,a,b,c,d=map(int,input().split())
s = input()

if c > d:#追い抜きが必要な場合
    x = 0
    for i in range(b-2,d-1):
        if s[i] == "." and s[i+1] == "." and s[i+2] == ".":
            x = 1
    if x == 0:
        print("No")#追い抜きが出来ない
    else:#追い抜き可能な場合
        check = 0#岩が2連続以上だと達成不能
        for i in range(a-1,c-1):
            if s[i] == "#" and s[i+1] == "#":
                check = 1
        if check == 1:
            print("No")
        else:
            print("Yes")
else:#a<b<c<dと並ぶ場合、もしくはacbdと並ぶ場合
    a_check = 0#Aがいけるか
    b_check = 0#Bがいけるか
    for i in range(a-1,c-1):
        if s[i] == "#" and s[i+1] == "#":
            a_check = 1
    for i in range(b-1,d-1):
        if s[i] == "#" and s[i+1] == "#":
            b_check = 1
    if a_check == 0 and b_check == 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 40048
import numpy as np

n, k, q = map(int, input().split())
a = []
for _ in range(q):
    a.append(int(input()))

nn = np.zeros(n)
kk = np.zeros(n) + k
qq = np.zeros(n) + q

for i in a:
    nn[i-1] += 1

_list = (kk-qq+nn).tolist()

for ans in _list:
    if ans > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 22640
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var arr=(Arr.shift()).split(" ").map(Number);
   if(arr[0]==0)break;
   var sum=0;
   arr=arr.filter(function(v){
      if(v>10)v=10;
      sum+=v;
      return v==1;
   });
   var i=arr.length;
   while(i!=0){
      if(sum+10<=21)sum+=10;
      i--;
   }
   console.log((sum>21)?0:sum);
}

Measured memory_bytes: 8628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Atcoderrrrrrr
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]); int K = int.Parse(input[1]);

            List<int> inputH = new List<int>();
            for (int i = 0; i < N; i++)
            {
                inputH.Add(int.Parse(Console.ReadLine()));
            }

            inputH.Sort();

            long dmin = long.MaxValue;
            for (int i = 0;i<inputH.Count -(K - 1); i++)
            {
                long d = inputH[i + K - 1] - inputH[i];
                if (d < dmin)
                {
                    dmin = d;
                }
            }
            

            Console.WriteLine(dmin);
        }
    }
}

Measured memory_bytes: 16092
#include<stdio.h>

int main(){
    int N,i;
    long long int T,ALL=1,REMAIN1,REMAIN2,REMAIN3;

    scanf("%d",&N);

    for(i=0;i<N;i++){
        scanf("%lld",&T);
        if(i==0){
            ALL=T;
            continue;
        }
        if(T>ALL){
            REMAIN2=ALL;
            REMAIN1=T;
        }else{
            REMAIN2=T;
            REMAIN1=ALL;
        }
        while(1){
            REMAIN3=REMAIN1%REMAIN2;
            if(REMAIN3==0) break;
            REMAIN1=REMAIN2;
            REMAIN2=REMAIN3;            
        }
        ALL=ALL/REMAIN2*T;
    }
    printf("%lld\n",ALL);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	unsigned long j = 0, i, n;
	scanf("%lu", &n);
	int flag = 0;
	
	for (i = 1; i <= n; i++) {
		if (i % 3 != 0 && i % 5 != 0)
			j += i;
	}
	printf("%lu", j);
	return 0;
}

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

namespace ARC070_D___No_Need
{
    class Program
    {
        static int N;
        static int K;
        static int[] ai;
        static void Main(string[] args)
        {
            var NK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            N = NK[0]; K = NK[1];
            ai = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            ai = ai.Where(n => n < K).OrderBy(s => s).ToArray();

            int left = -1;
            int right = ai.Length;
            while (right - left > 1)
            {
                int mid = left + (right - left) / 2;
                if (DP(mid)) right = mid;
                else left = mid;
            }

            Console.WriteLine(right);
        }
        static bool DP(int mid)
        {
            var DP = new bool[ai.Length + 1, 2 * K];
            DP[0, 0] = true;
            for (int i = 1; i < ai.Length + 1; i++)
            {
                var item = i - 1 != mid ? ai[i - 1] : 0;
                for (int k = 0; k < K; k++)
                {
                    if (k < item) DP[i, k] = DP[i - 1, k];
                    else DP[i, k] = DP[i - 1, k] || DP[i - 1, k - item];
                }
            }
            for (int i = K - ai[mid]; i < K; i++) if (DP[ai.Length, i]) return true;
            return false;
        }
    }
}


Measured memory_bytes: 60408
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

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

/* do your best */

int main() {
  
  vector<int> a(4);
  for (int i = 0; i < 4; i++) {
    cin >> a[i];
  }

  int ans = 1010101010;
  for (int i = 0; i < 4; i++) {
    for (int j = i + 1; j < 4; j++) {
      int s = 0;
      int t = 0;
      for (int k = 0; k < 4; k++) {
        if (k == i or k == j) s += a[k];
        else t += a[k];
      }

      ans = min(ans, (int)abs(s - t));
    }
  }
  cout << ans << endl;
  return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<bool> isred(N, false);
  for (int i = 0; i < N; i++) {
    char c;
    cin >> c;
    if (c == 'R') isred[i] = true;
  }

  int l = 0;
  int r = N - 1;
  int ans = 0;
  while (l < r) {
    if (isred[l]) {
      l++;
      continue;
    }
    if (!isred[r]) {
      r--;
      continue;
    }
    isred[l] = true;
    isred[r] = false;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
using namespace std;
string S;
int main() {
  cin >> S;
  string T; bool ok = false;
  for(int i = 0; i < 5; ++i) {
    T += "hi";
    if(S == T) ok = true;
  }
  cout << (ok?"Yes":"No") << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
    FOR(i,2,p) {
      if (p%i==0) return false;
    }
  return true;
}

int main(){
  int a,b,c;
  cin >> a >> b;
  c=0;
  FOR(i,a,b+1){
    if (i/10000==i%10&&(i/1000)%10==(i/10)%10) c++;
  }
  cout << c;
  return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  int ans = 0;
  for (int i=a;i<=b;i++){
    string str;
    str = to_string(i);
    if(str[0]==str[4]&&str[1]==str[3]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
// JAI SHREE RAM
/*
	Author: gourav_raj
*/
#pragma GCC optimize("O3")
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max3(a,max(b,c),d)
#define max5(a,b,c,d,e) max4(a,max(b,c),d,e)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min3(a,min(b,c),d)
#define min5(a,b,c,d,e) min4(a,min(b,c),d,e)
#define M_PI           3.14159265358979323846  /* pi */
#define sec second
#define fir first
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repe(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define entire(a) (a).begin(),(a).end()
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
void solve()
{
	int n;
	cin>>n;
	if(n<=1000)
		cout<<1000-n<<endl;
	else 
	{
		int res=0;
		for(int i=1;;i++)
		{
			if(i*1000>=n)
			{
				res=i*1000;
			cout<<res-n<<endl;
				break;
			}
		}
	}
}

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast
	int T = 1;
	// cin >> T;
	while (T--)
	{
		solve();
	}
	return 0;
}

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

#define N 200
#define R 8
#define INF 0x3f3f3f3f

int min(int a, int b) { return a < b ? a : b; }

int main() {
	static int ii[R], dd[N][N], dp[1 << R][R];
	int n, m, r, h, i, j, k, b, ans;

	scanf("%d%d%d", &n, &m, &r);
	for (h = 0; h < r; h++) {
		scanf("%d", &i), i--;
		ii[h] = i;
	}
	memset(dd, 0x3f, sizeof dd);
	for (i = 0; i < n; i++)
		dd[i][i] = 0;
	while (m--) {
		int d;

		scanf("%d%d%d", &i, &j, &d), i--, j--;
		dd[i][j] = dd[j][i] = d;
	}
	for (k = 0; k < n; k++)
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				dd[i][j] = min(dd[i][j], dd[i][k] + dd[k][j]);
	memset(dp, 0x3f, sizeof dp);
	for (h = 0; h < r; h++)
		dp[1 << h][h] = 0;
	for (b = 0; b < 1 << r; b++)
		for (h = 0; h < r; h++) {
			int x = dp[b][h], x_, b_, h_;

			if (x == INF)
				continue;
			i = ii[h];
			for (h_ = 0; h_ < r; h_++)
				if ((b & 1 << h_) == 0) {
					b_ = b | 1 << h_;
					j = ii[h_];
					x_ = x + dd[i][j];
					dp[b_][h_] = min(dp[b_][h_], x_);
				}
		}
	ans = INF;
	b = (1 << r) - 1;
	for (h = 0; h < r; h++)
		ans = min(ans, dp[b][h]);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 384
fun main(args: Array<String>) {
    val (h, w, m) = readIntList()

    val hc = MutableList(h) { 0 }
    val wc = MutableList(w) { 0 }

    val tar = mutableSetOf<Pair<Int, Int>>()
    repeat(m) {
        val (hh, ww) = readIntList().map { it - 1 }
        tar.add(hh to ww)
        hc[hh]++
        wc[ww]++
    }

    val hMax = hc.max()!!
    val wMax = wc.max()!!

    val lsH = hc.withIndex().filter { it.value == hMax }.map { it.index }
    val lsW = wc.withIndex().filter { it.value == wMax }.map { it.index }

    val ans = hMax + wMax
    lsH.forEach { i ->
        lsW.forEach { j ->
            if (!tar.contains(i to j)) {
                println(ans)
                return
            }
        }
    }
    println(ans - 1)
}

// read
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 116036
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int Q = sc.nextInt();
    int H = sc.nextInt();
    int S = sc.nextInt();
    int D = sc.nextInt();
    int N = sc.nextInt();
    int Sl = Math.min(Math.min(4*Q, 2*H), S);
    if (2*Sl > D) {
      System.out.println((long)N/2*D + (N%2 == 1 ? Sl : 0));
    } else {
      System.out.println((long)N*Sl);
    }
  }
}

Measured memory_bytes: 23892
#include <stdio.h>

int main() {

	int a, b;
	scanf("%d %d", &a, &b);
	char s[a+b+2];
	scanf("%s", s);
	
	for(int i=0; i<a; i++){
		if(s[i]<48 || s[i]>57){
			printf("No\n");
			return 0;
		}
	}
	
	if (s[a]!=45){
		printf("No\n");
			return 0;
	}
	
	for(int i=a+1; i<=(a+b); i++){
		if(s[i]<48 || s[i]>57){
			printf("No\n");
			return 0;
		}
	}

	printf("Yes\n");

    return 0;
}

Measured memory_bytes: 3160
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        var sc = new Scanner(System.in);
    
        int n = Integer.parseInt(sc.next());
        var a = new long[n];
        for(int i = 0; i < n; i++){
            a[i] = Long.parseLong(sc.next());
        }
        
        long ans = 0;
        long x = 0;
        final long MOD = 1000000007;
        for(int i = 1; i < n; i++){
            x += a[i-1];
            x %= MOD;
            ans += a[i] * x;
            ans %= MOD;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 62344
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin >> a >> b;
    if(a<b){
        cout << 2*b-1 << endl;
    }
    if(a>b){
        cout << 2*a-1 << endl;
    }
    if(a==b){
        cout << 2*a << endl;
    }
    return 0;
}


Measured memory_bytes: 256
use std::io::Read;
use std::cmp;

fn main() {
    let mut buf = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf);

    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();

    // aの読み込み
    let a: usize = iter.next().unwrap().parse().unwrap();
    // bの読み込み
    let b: usize = iter.next().unwrap().parse().unwrap();

    if (a + b) % 2 != 0 {
        println!("IMPOSSIBLE");
    } else {
        let ans: usize = (a + b) / 2;
        println!("{}", ans);
    }
}

Measured memory_bytes: 4352
# https://atcoder.jp/contests/agc036/tasks/agc036_a

s = int(input())

x1, y1 = 0, 0
x2 = 10 ** 9
y2 = 1

y3 = (s + x2 -1) // x2
x3 = x2 * y3 - s
print(x1, y1, x2, y2, x3, y3)

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

const int MAXN = 3e3 + 10;

int n, cntA, cntB;
int posA[MAXN], posB[MAXN], nxt[MAXN << 1], id[MAXN << 1];
char s[MAXN << 1];
std::string dp[MAXN];

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("now.out", "w", stdout);
	scanf("%d %s", &n, s + 1);
	for (int i = 1; i <= n << 1; ++i) s[i] == 'a' ? posA[id[i] = ++cntA] = i: posB[id[i] = ++cntB] = i;
	id[posA[n + 1] = posB[n + 1] = n * 2 + 1] = n + 1;
	for (int i = 1, j = 0; i <= n + 1; ++i) while (j < posA[i] && j < posB[i]) nxt[++j] = i;
	for (int i = n; i; --i) {
		if (posA[i] > posB[i]) {
			int j = posB[i];
			while (posB[id[j]] < posA[id[j]] && (id[j] <= i || posB[id[j]] < posA[id[j] - 1])) { if (id[j] >= i) dp[i] += s[j]; ++j; }
			dp[i] += dp[id[j]];
		} else dp[i] = "ab" + dp[nxt[posB[i] + 1]];
		dp[i] = std::max(dp[i], dp[i + 1]);
	}
	std::cout << dp[1] << '\n';
	return 0;
}

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

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

    int A, B, K;
    cin >> A >> B >> K;

    for (int i=100; i>=1; --i) {
        if (A % i == 0 && B % i == 0) {
            K --;
            if (K == 0) {
                cout << i << endl;
                break;
            }
        }
    }

    return 0;
}

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

using namespace std;
int g[100005],px[100005],py[100005];
pair<int,int>sx[100005],sy[100005];
int FIND(int x){
	if(g[x]==x)return x;
	else return g[x]=FIND(g[x]);
}
int value(int x,int y){
	x=FIND(x);
	y=FIND(y);
	if(x==y)return 0;
	g[x]=y;
return 1;
}
int op(int x,int y){
	return min(abs(px[x]-px[y]),abs(py[x]-py[y]));
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>px[i]>>py[i];
		g[i]=i;
		sx[i]=make_pair(px[i],i);
		sy[i]=make_pair(py[i],i);
	}	
	sort(sx,sx+n);
	sort(sy,sy+n);
	set<pair<int,pair<int,int> > >s;
	for(int i=0;i<n-1;i++){
		s.insert(make_pair(op(sx[i].second,sx[i+1].second),make_pair(sx[i].second,sx[i+1].second)));
		s.insert(make_pair(op(sy[i].second,sy[i+1].second),make_pair(sy[i].second,sy[i+1].second)));
	}
	long long res=0;
	while((int)s.size()){
		pair<int,pair<int,int> > p=*s.begin();
		s.erase(s.begin());
		int x=p.second.first,y=p.second.second;
		res+=(long long)value(x,y)*op(x,y);
	}
	cout<<res;
	return 0;
} 

Measured memory_bytes: 15488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N,T;
    cin >> N >> T;
    vector<int> A(N);
    int maxd = 0,mini = INF;
    for(int i = 0;i < N;i++){
        cin >> A[i];
        mini = min(mini,A[i]);
        maxd = max(maxd,A[i] - mini);
    }
    int cnt = 0;
    mini = INF;
    for(int i = 0;i < N;i++){
        mini = min(mini,A[i]);
        if(A[i] - mini == maxd)cnt++;
    }
    cout << cnt << endl;
}   

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

ll g[3002][3002]{};
ll a[3002][3002][4]{};


int main() {
    int R, C, K;
    cin >> R >> C >> K;
    int r, c, v;
    for (int i = 0; i < K; i++) {
        cin >> r >> c >> v;
        g[r][c] = v;
    }

    for (int i = 0; i <= R; i++) {
        for (int j = 0; j <= C; j++) {
            for (int k = 0; k <= 3; k++) {
                a[i + 1][j][0] = max(a[i + 1][j][0], a[i][j][k]);
                a[i][j + 1][k] = max(a[i][j + 1][k], a[i][j][k]);
                if (k == 3) {
                    a[i + 1][j][1] = max(a[i + 1][j][1], a[i][j][k] + g[i + 1][j]);
                } else {
                    a[i + 1][j][1] = max(a[i + 1][j][1], a[i][j][k] + g[i + 1][j]);
                    a[i][j + 1][k + 1] = max(a[i][j + 1][k + 1], a[i][j][k] + g[i][j + 1]);
                }
            }
        }
    }
    ll best = 0;
    for (int i = 0; i <= 3; i++) {
        best = max(best, a[R][C][i]);
    }
    cout << best << "\n";
    return 0;
}

Measured memory_bytes: 355596
#[allow(unused_imports)]
use std::cmp;
use std::collections::BTreeMap;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let a = sc.read_vec::<usize>(n);
    let q: usize = sc.read();
    let bc = sc.read_pairs::<usize>(q);

    let mut sum = a.iter().sum::<usize>();
    let mut bmap = BTreeMap::new();
    for a in a.into_iter() {
        bmap.entry(a).and_modify(|x| *x += 1).or_insert(1);
    }

    for (b, c) in bc.into_iter() {
        if bmap.contains_key(&b) {
            let v = *bmap.get(&b).unwrap();
            bmap.entry(b).and_modify(|x| *x = 0);
            bmap.entry(c).and_modify(|x| *x += v).or_insert(v);
            sum -= b * v;
            sum += c * v;
        }
        println!("{}", sum);
    }
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 5468
N = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(1,N-1):
  if (p[i]<p[i+1])and(p[i]>p[i-1]):
    ans += 1
  elif(p[i]>p[i+1])and(p[i]<p[i-1]):
    ans += 1
  else:
    None
print(ans)

Measured memory_bytes: 3064
/*input
7 2 3 1 3
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N 1005
// const int INF = 1e18;
const int mod = 1e9 + 7;

int n, a, b, c, d;
int dp[N][N];
int fac[N];
int infac[N];

#define pow binPow
long long binPow(long long a, long long q) {
	long long ret = 1;
	for (int i = 0; (1LL << i) <= q; i++) {
		if (q & (1LL << i)) ret = (ret * a) % mod;
		a = (a * a) % mod;
	}
	return ret;
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> a >> b >> c >> d;
	fac[1] = 1; infac[1] = 1;
	for (int i = 2; i <= 1000; i++) fac[i] = (fac[i - 1] * i) % mod, infac[i] = binPow(fac[i], mod - 2);
	for (int i = a; i <= b; i++) dp[0][i] = 1;
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = a; j <= b; j++) {
			if (j == a) {
				dp[i][j] = dp[i][0];
				for (int k = c; i - k * j >= 0 && k <= d; k++) {
					int t = ((dp[i - k * j][0] * binPow(binPow(fac[j], k), mod - 2)) % mod * infac[k]) % mod;
					dp[i][j] = (dp[i][j] + t) % mod;
				}
			}
			else {
				dp[i][j] = dp[i][j - 1];
				for (int k = c; i - k * j >= 0 && k <= d; k++) {
					int t = ((dp[i - k * j][j - 1] * binPow(binPow(fac[j], k), mod - 2)) % mod * infac[k]) % mod;
					dp[i][j] = (dp[i][j] + t) % mod;
				}
			}
		}
	}
	cout << dp[n][b]*fac[n] % mod << endl;
}

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

int w, h;
int vx[4] = { 1, 0, -1, 0 };
int vy[4] = { 0, 1, 0, -1 };
bool used[25][25];
char c[25][25];

int dfs(int x, int y){
    int ret = 1;
    for (int i = 0; i < 4; i++){
        int nextx = x + vx[i];
        int nexty = y + vy[i];

        if (0 < nextx && nextx < w + 1 && 0 < nexty && nexty < h + 1 && c[nextx][nexty] == '.' && !used[nextx][nexty]){
            used[nextx][nexty] = true;
            ret += dfs(nextx, nexty);
        }
    }

    return ret;
    
}

int main(void){

    while (true){

        cin >> w >> h;

        if (w == 0 && h == 0)break;

        for (int i = 0; i <= 20; i++){
            for (int j = 0; j <= 20; j++){
                used[i][j] = false;
            }
        }

        int sx, sy;

        for (int i = 1; i <= h; i++){
            for (int j = 1; j <= w; j++){
                cin >> c[j][i];
                if (c[j][i] == '@'){
                    sx = j; sy = i;
                }
            }
        }

        cout << dfs(sx, sy) << endl;
    }
 

}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 1e5 + 7, mod = 1e9 + 7;
int n;
int sa[N], sb[N];
LL val[N], sf[N], g[N], sg[N], f[N], ans, A, B;
void add(LL &a, LL b) { a += b; if(a >= mod) a -= mod;}
int main() {
#ifdef fwat
#endif
	scanf("%d%lld%lld", &n, &A, &B);
	if(A > B) swap(A, B);
	rep(i, 1, n) scanf("%lld", &val[i]);
	rep(i, 3, n) if(val[i] - val[i - 2] < A) return puts("0"), 0;
	rep(i, 1, n) {
		sa[i] = sa[i - 1] + (val[i] - val[i - 1] >= A);
		sb[i] = sb[i - 1] + (val[i] - val[i - 1] >= B);
	}
	sf[0] = sg[0] = f[0] = g[0] = 1;
	int L = 0, R = 0;
	rep(i, 1, n) {
		while(R < i && val[i] - val[R + 1] >= B) ++R;
		if(L <= R) f[i] = (sf[R] - (L == 0 ? 0 : sf[L - 1]) + mod) % mod;
		sf[i] = (sf[i - 1] + f[i]) % mod;
		if(i != 1 && val[i] - val[i - 1] < A) L = i - 1;
	}
	for(int i = n; i >= 0; --i) {
		add(ans, f[i]);
		if(i != n && val[i + 1] - val[i] < A) break;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3712
use std::collections::HashSet;
use std::io::prelude::*;
use std::string::String;

fn main() {
    let mut s = String::new();
    let stdin = std::io::stdin();
    let mut stdin = stdin.lock();
    stdin.read_line(&mut s).expect("line");
    let _: u32 = s.trim().parse().expect("parsing N");
    let a_s: Vec<u32> = stdin
        .lines()
        .map(|l| l.unwrap().trim().parse().expect("error reading line"))
        .collect();
    println!("{}", solve(&a_s).map(|i| i as i32).unwrap_or(-1));
}

fn solve(a_s: &[u32]) -> Option<usize> {
    let mut current = 0;
    let mut history: HashSet<u32> = HashSet::new();
    while history.insert(current) {
        current = a_s[current as usize] - 1;
        if current == 1 {
            return Some(history.len());
        }
    }
    None
}


Measured memory_bytes: 8444
from heapq import heapify, heappop, heappush, heappushpop
import sys
input = sys.stdin.readline
x,y,a,b,c=map(int, input().split())
p=list(map(int, input().split()))
q=list(map(int, input().split()))
r=list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort()
p=p[:x]
q=q[:y]
heapify(p)
heapify(q)
mp = heappop(p)
mq = heappop(q)
for ri in r:
  if mp<mq:
    if mp<ri:
      heappush(p, ri)
      mp=heappop(p)
  else:
    if mq<ri:
      heappush(q, ri)
      mq=heappop(q)

print(sum(p)+sum(q)+mp+mq)

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

int main() {

	int n;
	cin >> n;


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

	int max = 0;
	int min = 10E09;
	int dif;

	for (int i = 0; i < n; ++i) {
		if (max < a[i])
			max = a[i];

		if (min > a[i])
			min = a[i];

	}

	dif = max - min;

	cout << dif << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1e9
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define FOR(i,k,n) for(int i=k;i<n+k;i++)
#define ALL(x) x.begin(),x.end()

int main(){
	int n,m;cin>>n>>m;
	if(n<m){
		for(int i=0;i<m;i++) cout<<n;
		cout<<endl;
	}else{
		for(int i=0;i<n;i++) cout<<m;
		cout<<endl;
	}
}

Measured memory_bytes: 256