akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>

using namespace std;

int h[1000000];
int dp[1000000];

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

    for(int i=1;i<=n;i++)
        cin>>h[i];
    dp[1] = 0;
    dp[2] = abs(h[2]-h[1]);

    for(int i=3;i<=n;i++)
    {
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n];
}

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

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll res;
  if ((B-A) % 2 == 0) res = (B-A)/2;
  else res = min(A-1, N-B) + 1 + (B-A-1)/2;
  cout << res;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> E;
typedef long long LL;
string code[128];
int obj[128];
int m, n;
int memo[2048][2048];
int solve(int q, int a) {
	if (memo[q][a] != -1) return memo[q][a];
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if ((obj[i] & q) == a)cnt++;
	}
	if (cnt < 2) return memo[q][a] = 0;
	int ret = m;
	for (int i = 0; i < m; i++) {
		int nq = q | (1 << i);
		if (nq == q) continue;
		ret = min(ret, max(solve(nq, a | (1 << i)), solve(nq, a)) + 1);
	}
	return memo[q][a] = ret;
}
int main() {
	while (cin >> m >> n, m) {
		for (int i = 0; i < n; i++) cin >> code[i];
		memset(obj, 0, sizeof(obj));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (code[i][j] == '1') obj[i] |= (1 << j);
			}
		}
		memset(memo, -1, sizeof(memo));
		cout << solve(0, 0) << endl;
	}
}


Measured memory_bytes: 19452
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

const int mod=1000000007;
int a[100001];
map<int,int> tb;
int main(){
    int n;
    cin>>n;
    rep(i,n){
        cin>>a[i];
        ++tb[a[i]];
    }
    bool flag=false;
    if(n%2==1) flag=true;
    for(auto it:tb){
        if(it.second==1&&it.first==0&&flag) flag=false;
        else if(it.second!=2){
            cout<<0<<endl;return 0;
        }
    }
    ll ans=1;
    rep(i,n/2) ans=(ans*2)%mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define rep(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[2] = {1, 0};
int dy[2] = {0, 1};
char maze[17][17];
struct Data{
	int x, y, cost;
	Data(int xx, int yy, int cc){
		cost = cc;
		x = xx;
		y = yy;
	}
	Data(){}
};
int main(void){
	int w, h, n;
	while(cin >> w >> h, w){
		cin >> n;
		rep(i, 17)rep(j,17)maze[i][j] = '.';
		rep(i, n){
			int x, y;
			cin >> x >> y;
			maze[y-1][x-1] = '#';
		}
		queue<Data> que;
		que.push(Data(0, 0, 0));
		int ans = 0;
		while(!que.empty()){
			Data data = que.front();que.pop();
			int x = data.x;
			int y = data.y;
			if(x == w-1 && y == h-1){
				ans++;
				continue;
			}
			int cost = data.cost;
			rep(i, 2){
				int nx = x + dx[i];
				int ny = y + dy[i];
				if(nx < 0 || ny < 0 || nx >= w || ny >= h || maze[ny][nx] == '#')continue;
				que.push(Data(nx, ny, cost+1));
			}
		}
		FIN(ans);

	}

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 10352
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  ll ans = 0;
  for(int i=1; i<=N; ++i)
  {
    if(i%3 !=0 && i%5 !=0) {
      ans += i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3656
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 9/1/2018
 
 5:51-6:17 submit
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
//const int MAX_N=1e5+1;
int N,K;
//LL A[MAX_N];
LL f(int x) {
  return N/K+(x<=(N%K));
}
void solve() {
  LL res=f(K)*f(K)*f(K);
  dump(res);
  FOR(a,1,K) if(2*a%K==0) {
    LL fa=f(a),fb=f(K-a);
    dump4(a,K-a,fa,fb);
    res+=fa*fa*fb;
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N>>K;
//  REP(i,N) cin>>A[i];
  solve();
  return 0;
}


Measured memory_bytes: 256
n = int(input())
d = list(map(int, input().split()))

dd = sorted(d)
c = []
j = 0
for i in range(max(d)+1):
	tmp = 0
	while dd[j] == i:
		tmp += 1
		j += 1
		if j == n:
			break
	c.append(tmp)

ans = 1
if d[0] == 0 and d.count(0) == 1 and c.count(0) == 0:
	for i in range(1, max(d)):
		ans = ans * (c[i]**c[i+1])
else:
	ans = 0

print(ans%998244353)

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

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int,null_type, less<int>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e6+10, mod=1e9+7;
vector<int> g[N];
int res[N];

void dfs(int u,int p){
	for(auto v:g[u]){
		if(v==p) continue;
		res[v]+=res[u];
		dfs(v,u);
	}
}

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int n,q; 
	cin>>n>>q;
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	
	memset(res,0,sizeof res);
	
	while(q--){
		int a,b;
		cin>>a>>b;
		res[a]+=b;
	}
	
	dfs(1,0);
	for(int i=1;i<=n;i++)cout<<res[i]<<" ";
}
// check for any potential overflow before submitting



Measured memory_bytes: 45440
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;

int main()
{
    int N;
    cin >> N;
    vector<int> v(N + 2);
    int sum = 0;
    rep2(i, 1, N + 1) cin >> v[i];

    rep2(i, 1, N + 2)
    {
        sum += abs(v[i] - v[i - 1]);
    }
    rep2(i, 1, N + 1)
    {
        int before = abs(v[i] - v[i - 1]);
        int after = abs(v[i + 1] - v[i]);
        int skip = abs(v[i + 1] - v[i - 1]);
        int ans = sum - before - after + skip;
        cout << ans << endl;
    }
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
/* Uncomment only if you are not using GNU compiler->
*/
#include <map>
#include <algorithm> 
#include <vector> 
#include <string.h> 
#include <math.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <chrono> 
#include <thread> 
#include <iomanip>
#include <typeinfo>
/**/ 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()

//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

ll power(ll x, ll n)
{
    ll res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

void solve()
{
    int n, m;
    ll k;
    cin>>n>>m>>k;
    vll a(n), b(m);
    rep(i,n)
    cin>>a[i];
    rep(i,m)
        cin>>b[i];
    vll dp1(n+1,0), dp2(m+1,0);
    rep(i,n)
    {
        dp1[i+1]=dp1[i]+a[i];
    }
    rep(i,m)
    {
        dp2[i+1]=dp2[i]+b[i];
    }
    int cnt=0;
    int x=-1, y=-1;
    rep(i,m+1)
    {
        if(dp2[i]>k)
        {
            y=i-1;
            break;
        }
    }
    if(y==-1)
        y=m;
    cnt=y;
    repu(i,1,n)
    {
        if(dp1[i]>k)
            break;
        while(y>=0 && dp1[i]+dp2[y]>k)
            y--;
        cnt=max(cnt,i+y);
    }
    cout<<cnt<<endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


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

N = int(input())
S = list(map(str, input().split()))
s=list(S[0])
c=[]

for i in range(1,N):
    a_and_b = list(set(s[0:i]) & set(s[i:N]))
    c.append(int(len(a_and_b)))

print(max(c))

Measured memory_bytes: 3064
N,L = map(int,input().split())
ls = []
for i in range(L,L+N):
    ls.append(i)
    
if ls[0] > 0:
    del ls[0]
    print(sum(ls))
elif ls[0] < 0 and ls[-1] < 0:
    del ls[-1]
    print(sum(ls))
else:
    print(sum(ls))

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

using namespace std;

#define INF 1000000
#define MAX_N 101
long long N, W, item[MAX_N][2];
long long dp[MAX_N][INF];

long long dpCalc(long long i, long long w)
{
    long long res = 0;
    if (dp[i][w] >= 0)
    {
        return dp[i][w];
    }

    if (i == N)
        res = 0;
    else if (w < item[i][0])
    {
        res = dpCalc(i + 1, w);
    }
    else
    {
        res = max(dpCalc(i + 1, w), dpCalc(i + 1, w - item[i][0]) + item[i][1]);
    }
    return dp[i][w] = res;
}

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

    for (int i = 0; i < MAX_N; i++)
    {
        for (int j = 0; j < INF; j++)
        {
            dp[i][j] = -1;
        }
    }

    for (int i = 0; i < N; i++)
        cin >> item[i][0] >> item[i][1];

    cout << dpCalc(0, W) << endl;

    return 0;
}

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

const int64_t MOD= 1000000007;
/* 剰余環 Z/nZ */
struct mint{ // Z/nZ に関する演算(n:素数の場合は除算も)をサポートする構造体
  int64_t rep; // 出力すべき代表元 rep \in {0,1,..,MOD- 1}
  mint(int64_t x=0): rep(((x%MOD)+ MOD)% MOD){}
  mint operator-() const { return mint(-rep);}
  mint& operator+=(const mint& x){
    rep+= x.rep; 
    if(rep>= MOD) rep-= MOD;
    return *this;
  }
  mint& operator-=(const mint& x){
    rep-= x.rep;
    if(rep< 0) rep+= MOD;
    return *this;
  }
  mint& operator*=(const mint& x){
    rep*= x.rep; rep%= MOD;
    return *this;
  }
  mint operator+(const mint x) const {
    mint ans(*this);
    ans+= x;
    return ans;
  }
  mint operator-(const mint x) const {
    mint ans(*this);
    ans-= x;
    return ans;
  }
  mint operator*(const mint x) const {
    mint ans(*this);
    ans*= x;
    return ans;
  }
  bool operator==(const mint x) const {
    return rep==x.rep;
  }
  bool operator!=(const mint x) const {
    return rep!=x.rep;
  }

  mint pow(int64_t d) const{ // d \geq 0
    if(d==0) return 1;
    else{
      mint ans= pow(d>>1);
      ans*= ans;
      if(d&1){ ans*= *this; }

      return ans;
    }
  }

  friend istream& operator >> (istream &is, mint& x) noexcept{
    int64_t a;
    is >> a;
    x= a;
    return is;
  }
  friend ostream& operator << (ostream &os, const mint& x) noexcept{
      return os << x.rep;
  }
  // MOD が素数(<=> Z/nZ が体)のとき
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint& x){
    *this *= x.inv();
    return *this;
  }
  mint operator/(const mint x) const {
    mint ans(*this);
    ans/= x;
    return ans;
  }
};
// ^^^ テンプレここまで ^^^

int main(){
  int N; int64_t K;
  cin >> N >> K;
  
  mint ans= 0;
  vector<mint> pattern(K+1);
  for(int64_t k=K; k>0; k--){
    mint offset= 0;
    for(int64_t k2=2*k; k2<=K; k2+=k){
      offset+= pattern.at(k2);
    }
    mint p= K/k;
    mint g= k;
    pattern.at(k)= p.pow(N)- offset;
    ans+= g* pattern.at(k);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4052
from fractions import gcd 

N = int(input())
A = [int(i) for i in input().split()]

# Lを埋める
L = [0 for _ in range(N+1)]
for i in range(1, N+1):
    if not L[i-1]:
        L[i] = A[i-1]
    else: 
        L[i] = gcd(L[i-1], A[i-1])

# Rを埋める
R = [0 for _ in range(N+1)]
for i in range(1, N+1)[::-1]:
    if not R[i]:
        R[i-1] = A[i-1] 
    else:
        R[i-1] = gcd(R[i], A[i-1])

# Mを埋める
M = [0 for _ in range(N)]
for i in range(N):
    if not L[i]:
        M[i] = R[i+1]
    elif not R[i]:
        M[i] = L[i]
    else: 
        M[i] = gcd(L[i], R[i+1])

print(max(M))

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

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX_N = 100000;
ll N, C;
ll x[MAX_N+1], v[MAX_N+1];
ll migi[MAX_N+1], hidari[MAX_N+1];
ll migi2[MAX_N+1], hidari2[MAX_N+1];

int main() {
  cin >> N >> C;
  for (int i = 1; i <= N; ++i) cin >> x[i] >> v[i];

  hidari[0] = 0;
  ll sumv = 0;
  for (int i = 1; i <= N; ++i) {
    sumv += v[i];
    hidari[i] = max(hidari[i-1], sumv-x[i]);
  }

  migi[0] = 0;
  sumv = 0;
  for (int i = 1; i <= N; ++i) {
    sumv += v[N-i+1];
    migi[i] = max(migi[i-1], sumv-(C-x[N-i+1]));
  }

  hidari2[0] = 0;
  sumv = 0;
  for (int i = 1; i <= N; ++i) {
    sumv += v[i];
    hidari2[i] = max(hidari2[i-1], sumv-2*x[i]);
  }

  migi2[0] = 0;
  sumv = 0;
  for (int i = 1; i <= N; ++i) {
    sumv += v[N-i+1];
    migi2[i] = max(migi2[i-1], sumv-2*(C-x[N-i+1]));
  }

  ll ans = 0;
  for (int i = 1; i <= N; ++i) {
    ans = max(ans, hidari[i] + migi2[N-i]);
  }

  for (int i = 1; i <= N; ++i) {
    ans = max(ans, migi[i] + hidari2[N-i]);
  }

  cout << ans << endl;

  return 0;
}



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

long long N, A[100000];
long long x[100000];

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

    long long double_x0 = 0, sign = 1;
    for(int i = 0; i < N; i++){
        double_x0 += sign * 2 * A[i];
        sign *= -1;
    }

    x[0] = double_x0 / 2;
    for(int i = 0; i < N - 1; i++){
        x[i + 1] = 2 * A[i] - x[i];
    }

    for(int i = 0; i < N; i++){
        if(i){
            cout << " ";
        }
        cout << x[i];
    }
    cout << endl;
}


Measured memory_bytes: 2816
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

//https://blog.foresta.me/posts/enumerate_all_pattern/
//https://hacknote.jp/archives/20862/

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

int make_kaijo(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

int main() {

    int N; 
    cin >> N;
    
    int p[N]; 
    int q[N]; 

    int a_num = 0;
    int b_num = 0;

    vector<int> nums;

    vector<string> for_sort;

    string p_str;
    for (int i = 0; i < N ; i++) {
        cin >> p[i];
        p_str += to_string(p[i]);

        nums.push_back(i+1);

    }

    string q_str;
    for (int i = 0; i < N ; i++) {
        cin >> q[i];
        q_str += to_string(q[i]);

    }

    

    // vector順列ループ
    do {

        string num_str = "";
        for (int i = 0; i < nums.size() ; i++) {

            //cout << "nums.at(i) "<< nums.at(i) << endl;

            num_str =  num_str + to_string(nums.at(i));
        }
        //cout << "-------- num_str "<< num_str << endl;
        for_sort.push_back(num_str);
   

        //printVector(nums);
    } while (next_permutation(nums.begin(), nums.end()));


    sort(for_sort.begin(), for_sort.end());

    //cout << "p_str: "<< p_str << endl;
    //cout << "q_str: "<< q_str << endl;

    for (int i = 0; i < for_sort.size() ; i++) {

        //cout << for_sort.at(i) << endl;

        if (p_str == for_sort.at(i)){
            a_num = i;
        }

        if (q_str == for_sort.at(i)){
             b_num = i;
        }
    }

    cout << abs(a_num - b_num)<< endl;


    return 0;

}

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

int main(){
    int H, W, Ch, Cw, Dh, Dw;
    std::cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
    std::vector< std::string > S(H);
    for(int i=0; i<H; i++){
        std::cin >> S[i];
    }
    
    std::vector< std::vector< int > > warp_min(H, std::vector< int >(W, 1e9));
    
    std::deque< int > H_pos;
    std::deque< int > W_pos;
    std::deque< int > warp_cnt;
    
    H_pos.push_back(Ch - 1);
    W_pos.push_back(Cw - 1);
    warp_cnt.push_back(0);
    
    while(!H_pos.empty()){
        int cur_H = H_pos[0];
        int cur_W = W_pos[0];
        int cur_warp = warp_cnt[0];
        H_pos.pop_front();
        W_pos.pop_front();
        warp_cnt.pop_front();
        
        if(cur_H < 0 || cur_H >= H){
            continue;
        }
        if(cur_W < 0 || cur_W >= W){
            continue;
        }
        if(warp_min[cur_H][cur_W] <= cur_warp){
            continue;
        }
        if(S[cur_H][cur_W] == '#'){
            continue;
        }
        
        warp_min[cur_H][cur_W] = cur_warp;
        
        for(int i=-2; i<=2; i++){
            for(int j=-2; j<=2; j++){
                int dist = abs(i) + abs(j);
                if(dist == 0){
                    continue;
                }else if(dist == 1){
                    H_pos.push_front(cur_H + i);
                    W_pos.push_front(cur_W + j);
                    warp_cnt.push_front(cur_warp);
                }else{
                    H_pos.push_back(cur_H + i);
                    W_pos.push_back(cur_W + j);
                    warp_cnt.push_back(cur_warp + 1);
                }
            }
        }
    }
    
    //for(int i=0; i<H; i++){
    //    for(int j=0; j<W; j++){
    //        std::cout << warp_min[i][j] << " ";
    //    }
    //    std::cout << std::endl;
    //}
    
    if(warp_min[Dh - 1][Dw - 1] == 1e9){
        std::cout << -1 << std::endl;
    }else{
        std::cout << warp_min[Dh - 1][Dw - 1] << std::endl;
    }
    
    
    return 0;
    
}


Measured memory_bytes: 11916
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
//------------------------------>> coding space <<------------------------------//



int main() {
	int N;
	cin >> N;
	
	Vec< int > p(N);
	for_(i,0,N) cin >> p[i];
	
	int ans = 0;
	for_(i,0,N) {
		if (p[i] == i+1) {
			++ans;
			swap(p[i], p[(i+1)%N]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#define DOT(v1, v2) (v1.x * v2.x + v1.y * v2.y)
#define CROSS(v1, v2) (v1.x * v2.y - v1.y * v2.x)
#define NORM(v) (v.x * v.x + v.y * v.y)
#define ABS(v) (sqrt(NORM(v)))

typedef struct { double x, y; } point_t;
typedef point_t vector_t;
typedef struct { point_t p0, p1; } segment_t;
typedef segment_t line_t;
typedef struct { point_t p; double r; } circle_t;

static vector_t plus(vector_t v1, vector_t v2) {
  vector_t ret = { v1.x + v2.x, v1.y + v2.y };
  return ret;
}

static vector_t minus(vector_t v1, vector_t v2) {
  vector_t ret = { v1.x - v2.x, v1.y - v2.y };
  return ret;
}

static vector_t multiple(vector_t v, double s) {
  vector_t ret = { v.x * s, v.y * s };
  return ret;
}

static vector_t divide(vector_t v, double s) {
  vector_t ret = { v.x / s, v.y / s };
  return ret;
}

static point_t projection(line_t l, point_t p) {
  vector_t base = minus(l.p1, l.p0);
  double r = DOT(minus(p, l.p0), base) / NORM(base);
  return plus(l.p0, multiple(base, r));
}

static segment_t cross_points(circle_t c, line_t l) {
  segment_t s;
  vector_t e, v, x, tmp;
  double base;

  x = projection(l, c.p);
  v = minus(l.p1, l.p0);
  e = divide(v, ABS(v));
  base = sqrt(c.r * c.r - NORM(minus(c.p, x)));
  v = multiple(e, base);
  s.p0 = plus(x, v);
  s.p1 = minus(x, v);
  if (s.p0.x > s.p1.x || (s.p0.x == s.p1.x && s.p0.y > s.p1.y)) {
    tmp = s.p0;
    s.p0 = s.p1;
    s.p1 = tmp;
  }
  return s;
}

int main(int argc, char **argv) {
  circle_t c;
  line_t l;
  segment_t s;
  int q, i;

  scanf("%lf %lf %lf %d", &c.p.x, &c.p.y, &c.r, &q);
  for (i = 0; i < q; ++i) {
    scanf("%lf %lf %lf %lf", &l.p0.x, &l.p0.y, &l.p1.x, &l.p1.y);
    s = cross_points(c, l);
    printf("%.8lf %.8lf %.8lf %.8lf\n", s.p0.x, s.p0.y, s.p1.x, s.p1.y);
  }
}


Measured memory_bytes: 2112
n, k = map(int, input().split())
li = []
for i in range(k):
    d = int(input())
    li.append([d, list(map(int, input().split()))])
c = 0
for i in range(1, n+1):
    for j in li:
        if i in j[1]:
            break
    else:
        c += 1
print(c)
    

Measured memory_bytes: 9124
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let x = stdin.lock().lines().next().unwrap().unwrap();
    let x = x.parse::<i32>().unwrap();

    for i in x.. {
        if (2..).take_while(|d| d * d <= i).all(|d| i % d != 0) {
            println!("{}", i);
            return;
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define eps 1e-6
typedef long long ll;
int n,d;
bool isInt(long double p) {
	return fabs(p-floor(p)) <= eps;
}
long double dist(vector<long double>&a, vector<long double>&b) {
	long double di = 0;
	for (int i=0; i<d; i++) {
		di += (fabs(a[i]-b[i]))*(fabs(a[i]-b[i]));
	}
	return sqrtf(di);
}
int main() {
	cin >> n >> d;
	vector< vector< long double > > a(n, vector<long double>(d));
	for (int i=0; i<n; i++) {
		for (int j=0; j<d; j++) {
			cin >> a[i][j];
		}
	}
	int ans = 0;
	for (int i=0; i<n; i++) {
		for (int j=i+1; j<n; j++) {
			long double di = dist(a[i],a[j]);
			// cout << i << ' ' << j << ' ' << di << '\n';
			if (isInt(di)) {
				ans++;
			}
		}
	}
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 3796
import math
from functools import reduce

n = int(input())
a_list = list(map(int, input().split()))
max = 10 ** 6 + 1
memo = [0] * max

for a in a_list:
    memo[a] += 1

for i in range(2, max):
    if sum(memo[i::i]) > 1:
        if reduce(math.gcd, a_list) == 1:
            print("setwise coprime")
            exit()
        else:
            print("not coprime")
            exit()

print("pairwise coprime")


Measured memory_bytes: 127612
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
//#include <intrin.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 300005
#define inf 2000000000
#define EPS 1e-6
#define MOD 998244353ll
#define __builtin_popcount(x) __popcnt(x)

using namespace std;

typedef long long ll;

inline void solve()
{
	int n, m, k;
	cin >> n >> m >> k;
	vector<vector<char>> mx(n, vector<char>(m));
	fore(i, 0, n)
		fore(j, 0, m)
		cin >> mx[i][j];

	int otv = inf;

	fore(q, 0, (1 << (n - 1)))
	{
		vector<int> cnt(n, 0);
		int o = 0;

		fore(j, 0, m)
		{
			fore(i, 0, n)
			{
				if (mx[i][j] == '1')
					cnt[i]++;
			}

			int cur = 0;
			bool is = 0;

			fore(i, 0, n)
			{
				cur += cnt[i];

				if (cur > k)
				{
					is = 1;
					o++;
					break;
				}

				if (i != n - 1)
				{
					if (((q >> i) & 1) == 1)
						cur = 0;
				}
			}

			if (is)
			{
				fore(i, 0, n)
				{
					if (mx[i][j] == '1')
						cnt[i] = 1;
					else
						cnt[i] = 0;
				}
			}

			cur = 0;

			fore(i, 0, n)
			{
				cur += cnt[i];

				if (cur > k)
					goto next;

				if (i != n - 1)
				{
					if (((q >> i) & 1) == 1)
						cur = 0;
				}
			}

		}

		fore(i, 0, n - 1)
			if (((q >> i) & 1) == 1)
				o++;

		otv = min(otv, o);

	next:
		continue;
	}

	cout << otv;
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	while (q--)
	{
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 256
n,k = map(int,input().split())
p = list(map(int,input().split()))
for i in range(n):
    p[i] -= 1
c = list(map(int,input().split()))

reach = [False]*n
x = []
for i in range(n):
    if reach[i]:continue
    buf = []
    cur = i
    while not reach[cur]:
        buf.append(c[cur])
        reach[cur] = True
        cur = p[cur]
    x.append(buf)

ans = max(c)
import itertools
for i in x:
    n = k//len(i)
    ind = k%len(i)
    if n>0:
        n -= 1
        ind += len(i)
    else:
        ind = min(k,len(i)*2)
    ii = i+i+i
    r = list(itertools.accumulate(ii))
    a = max(0,r[len(i)-1]*n)
    for j in range(len(i)):
        for z in range(1,ind+1):
            s = r[j+z]-r[j]
            ans = max(ans,a+s)
print(ans)


Measured memory_bytes: 68988
N, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
B = A.map{|a| a / 2 }
m = B.inject(&:lcm)
s2 = A.map{|a| (0 .. 100).find{|i| a[i] > 0} }

if s2.uniq.size > 1
  puts 0
else
  puts (M / m + 1) / 2
end

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

int main(void){
  char ans[32]="", *q;
  char s[32];
  
  cin >> s;
  q = ans;
  for (char *p=s; *p; p++){
    if (*p == '0') *q++='0';
    if (*p == '1') *q++='1';
    if (*p == 'B' && q>ans) *--q='\0';
//  cout << ans << endl;
    
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
long long int arr[500005];
long long int size1[500005];
long long int m = 1000000007;
bool vis[200005] = {0};
vector<pair<ll, ll>> vec[300005];
ll count1 = 0;
vector<pair<ll, pair<ll, ll>>> vec1;
ll count2 = 0;
long long int fin(long long int node)
{
    if (node == arr[node])
        return node;
    node = arr[arr[node]];
}

void union1(long long int x, long long int y)

{
    long long int node1 = fin(x);
    long long int node2 = fin(y);

    if (size1[node1] > size1[node2])
    {
        size1[node1] += size1[node2];
        arr[node2] = node1;
    }
    else
    {
        size1[node2] += size1[node1];
        arr[node1] = node2;
    }
}
long long int fastexpo(long long int a, long long int b)
{
    long long int ans = 1;
    while (b)
    {
        if (b & 1)
            ans = (ans * a) % m;
        b = b / 2;
        a = (a * a) % m;
    }
    return ans;
}
void dfs(ll node)
{
    vis[node] = 1;
    //  vec1.push_back({count1, {node1, node}});

    size1[node] = count1;
    count1++;
    for (int i = 0; i < vec[node].size(); i++)
    {

        // arr[vec[node][i]] = count1;
        if (!vis[vec[node][i].first])
        {
            dfs(vec[node][i].first);
            arr[node] += arr[vec[node][i].first];
        }
    }
    count1--;
}
void dijkstra(ll s, vector<pair<ll, ll>> vec2[], ll dis5[])
{
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
    pq.push(make_pair(0, s));
    dis5[s] = 0;
    while (!pq.empty())
    {
        ll u = pq.top().second;
        //  vis[u] = 1;
        pq.pop();
        for (ll i = 0; i < (ll)vec2[u].size(); i++)
        {

            ll q = vec2[u][i].second;
            ll w = vec2[u][i].first;

            if (dis5[u] + w < dis5[q])
            {
                dis5[q] = dis5[u] + w;
                pq.push(make_pair(dis5[q], q));
            }
        }
    }
}
int main()
{
    long double t;
    cin >> t;
    cout << 2 * 3.141592* t;

    return 0;
}

Measured memory_bytes: 10856
import sys

def solveA(S):
    N = len(S)
    count = 0
    for i in range(N-1):
        if S[i] == S[i+1]:
            S[i+1] = "_"
            count += 1
    return count

def solve(S, K):
    S0 = S[:]
    N = len(S)
    if N == 1:
        return (K-(K%2))//2
    if K < 10:
        return solveA(S*K)
    #actual=(solveA(S*K))
    S1 = S0*1
    S2 = S0*2
    c1 = solveA(S1)
    c2 = solveA(S2)
    if c1 * 2 == c2:
        return c1 * K
    if S2[0] != S2[-1]:
        return c2 * (K//2) + (K%2) * c1
    else:
        a =  c2 * (K//2) + (K%2)*c1 + (K//2)-(1-K%2)
            #if a != solveA(S0*K):
            #print(c1, c2, S2[0]!=S2[-1])
            #print("c2 * (K//2) +(K%2)*c1=", c2 * (K//2)+(K%2)*c1)
        return a


def main():
    S = list(input().rstrip()) # len(S) <= 100
    K = int(input())    # K <= 10**9

    print(solve(S, K))
def test():
    import random

    for i in range(2000):
        n = random.randint(1,100)
        S = random.choices("aaaaaabcedbdddddklkjlkjdsfaak", k=n)
        S0 = S[:]
        K = random.randint(2, 30)
        SK = S*K
        a, a0 = solve(S, K), solveA(SK)
        if a != a0:
            print("".join(S0))
            print(K)
            print("actual=",a, ",expected=",a0)
            print("BAD\n")
            return
#test()
main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    string sa, sb, sc;
    cin >> sa >> sb >> sc;
    int a = 0, b = 0, c = 0;
    char x = sa[0];
    char ans;
    a++;
    while(true) {
        if(x == 'a') {
            if(a == sa.size()) {
                ans = 'A';
                break;
            }
            x = sa[a];
            a++;
        } else if(x == 'b') {
            if(b == sb.size()) {
                ans = 'B';
                break;
            }
            x = sb[b];
            b++;
        } else {
            if(c == sc.size()) {
                ans = 'C';
                break;
            }
            x = sc[c];
            c++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  if (N <= 999) {
    cout << "ABC" << endl;
  }else {
    cout << "ABD" << endl;
  }

  return 0;
}



Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    int a = 0;
    int b = 1001;
    for(int i = 0; i < n; i++){
        int c;
        cin >> c;
        a = max(a, c);
        b = min(b, c);
    }
    cout << a - b << endl;
    return 0;
}


Measured memory_bytes: 256
S=input()
T=input()

LS=len(S)
LT=len(T)
ans=[]

for i in range(LS-LT+1):
    for j in range(LT):
        if not (T[j]==S[i+j] or S[i+j]=="?"):
            break
        if j==LT-1:
            ans.append(list(S[0:i]+T+S[i+LT:]))

Lans=len(ans)

if Lans==0:
    print("UNRESTORABLE")
    exit()


for i in range(Lans):
    for j in range(LS):
        if ans[i][j]=="?":
            ans[i][j]="a"
    ans[i]="".join(ans[i])

ans.sort()

print(ans[0])




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

int main(){
  int n;
  cin >> n;
  vector<long long> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  sort(a.begin(), a.end());
  long long height = 0, width = 0;
  long long k = 0;
  for(int i = n-1; i >= 0; i--){
    if(k == a.at(i)){
      if(height == 0) height = k;
      else width = k;
      k = 0;
      continue;
    }
    
    if(width) break;
    k = a.at(i);
  }
  
  cout << height * width << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,chk[100010],check[100010],ac,pen;
int a[100010];
char b[100010][5];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
    {
        scanf("%d %s",&a[i],b[i]);
        if(strcmp(b[i],"AC")==0&&chk[a[i]]==0)
        {
            ac++;
            chk[a[i]]=1;
        }
    }
    for(int i=0;i<m;i++)
    {
        if(chk[a[i]]==1&&check[a[i]]==0&&strcmp(b[i],"WA")==0)
        {
            pen++;
        }
        if(check[a[i]]==0&&strcmp(b[i],"AC")==0)
        {
            check[a[i]]=1;
        }
    }
    printf("%d %d",ac,pen);
}

Measured memory_bytes: 1920
N, K = map(int, input().split())
h = list(map(int, input().split()))

INF = 10 ** 10
dp = [INF] * N
dp[0] = 0
dp[1] = min(dp[1], dp[0] + abs(h[0] - h[1]))

for i in range(2, N):
    if i >= K:
        for j in range(1, K + 1):
            dp[i] = min(dp[i], dp[i - j] + abs(h[i - j] - h[i]))
    else:
        for j in range(1, i + 1):
            dp[i] = min(dp[i], dp[i - j] + abs(h[i - j] - h[i]))

print(dp[N - 1])


Measured memory_bytes: 84688
from itertools import accumulate

N, K = map(int, input().split())
As = list(map(int, input().split()))

accAs = [0] + list(accumulate(As))

Bs = []
for L in range(N):
    for R in range(L, N):
        Bs.append(accAs[R + 1] - accAs[L])

ans = 0
for d in reversed(range(40)):
    num = sum([(B >> d) & 1 for B in Bs])
    if num >= K:
        ans += 1 << d
        Bs = [B for B in Bs if (B >> d) & 1]

print(ans)


Measured memory_bytes: 28800
#include<stdio.h>
#include<string.h>
#include <ctype.h> 
main(){
  char pan[1001];
  int i,a;
  fgets(pan,sizeof(pan),stdin);
  a=strlen(pan);
  pan[a-1]='\0';
  for(i=0;i<a;i++)
    pan[i]=toupper(pan[i]);

  printf("%s\n",pan);
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		String str = scn.nextLine();
		StringBuilder sb = new StringBuilder(str);
		final String REPLACE = "replace";
		final String REVERSE = "reverse";
		final String PRINT = "print";
		int orderCount = Integer.parseInt(scn.nextLine());

		for (int i = 0; i < orderCount; i++) {
			String order = scn.nextLine();
			String[] aaa = order.split(" ");
			int a = Integer.parseInt(aaa[1]);
			int b = Integer.parseInt(aaa[2])+1;
			if (aaa[0].equals(PRINT)) {
				System.out.println(sb.substring(a, b).toString());
			} else if (aaa[0].equals(REVERSE)) {
				StringBuilder sbs = new StringBuilder(sb.substring(a, b));
				String bbb= sbs.reverse().toString();
				sb.replace(a, b, bbb);
			} else if (aaa[0].equals(REPLACE)) {
				sb.replace(a, b, aaa[3]);
			}
		}
	}
}



Measured memory_bytes: 28240
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, k;
    cin >> n >> k;
    akari<double> ps(n);
    for (auto &p : ps)
    {
        cin >> p;
    }
    double sum = 0, cur = 0;
    for (int i = 0; i < n; i++)
    {
        cur += ps[i];
        if (i < k - 1)
        {
            continue;
        }
        if (i - k >= 0)
        {
            cur -= ps[i - k];
        }
        sum = max(sum, cur);
    }
    double ans = (sum + k) / 2.;
    cout << fixed << setprecision(9) << ans << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 1792
from itertools import accumulate
 
n = int(input())
acc = [0] + list(accumulate(map(int, input().split())))
dp = [[0] * (n + 1) for _ in range(n)]
for w in range(2, n + 1):
    for l in range(n - w + 1):
        r = l + w
        dp[l][r] = min(dp[l][m] + dp[m][r] for m in range(l + 1, r)) + acc[r] - acc[l]
print(dp[0][n])

Measured memory_bytes: 45276
#include<bits/stdc++.h>
using namespace std;
int n,s[100000],q,t,c,l,m,r,i,j;
main(){
  cin.sync_with_stdio(false);
  for(cin>>n;i<n;cin>>s[i++]);
  for(cin>>q;j++<q;){
    l=0,r=n,cin>>t;
    while(m=(l+r)/2,l<r){
      t-s[m]||(l=r,c++);
      t<s[m]&&(r=m);
      t>s[m]&&(l=m+1);
    }
  }
  cout<<c<<endl;
}

Measured memory_bytes: 3408
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
vector<pair<int,int> >g[N];
int ans[N],tot,vis[N];
void dfs(int x,int pre){
	vis[x]=1;
//	if(x==1)tot=max(tot,(int)g[x].size());
//	 else tot=max(tot,(int)g[x].size());
	int cur=0;
	for(auto& u:g[x]){
		int v=u.first,id=u.second;
		if(vis[v])continue;
		++cur;
		if(cur==pre)cur++;
		ans[id]=cur;
		dfs(v,cur);
	}
}
int main(){
	int n;
//	ios::sync_with_stdio(false);cin.tie(0);
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int x,y;
	//	cin>>x>>y;
	    scanf("%d%d",&x,&y);
	//	g[x].push_back({y,i});
	//	g[y].push_back({x,i});	
		g[x].push_back(make_pair(y,i));
		g[y].push_back(make_pair(x,i));
	}
	for(int i=1;i<=n;i++)tot=max(tot,(int)g[i].size());
	dfs(1,0);
	printf("%d\n",tot);
	for(int i=1;i<n;i++)printf("%d\n",ans[i]);
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int K = l[0], T = l[1];
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var pq = new PriorityQueue<int>();            
            foreach (var val in a)
                pq.Enqueue(val);
            
            var old = pq.Dequeue();
            old--;
            
            while (pq.Count > 0) {
               var cur = pq.Dequeue();
               cur--;
               if (old > 0) pq.Enqueue(old);
               old = cur;
            }
            
            Console.WriteLine(old);
        }
    }

class PriorityQueue<T> : IEnumerable<T>
{
    private readonly List<T> _data = new List<T>();
    private readonly IComparer<T> _comparer;
    private readonly bool _isDescending;

    public PriorityQueue(IComparer<T> comparer, bool isDescending = true)
    {
        _comparer = comparer;
        _isDescending = isDescending;
    }

    public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
        : this(Comparer<T>.Create(comparison), isDescending)
    {
    }

    public PriorityQueue(bool isDescending = true)
        : this(Comparer<T>.Default, isDescending)
    {
    }

    public void Enqueue(T item)
    {
        _data.Add(item);
        var childIndex = _data.Count - 1;
        while (childIndex > 0)
        {
            var parentIndex = (childIndex - 1) / 2;
            if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
                break;
            Swap(childIndex, parentIndex);
            childIndex = parentIndex;
        }
    }

    public T Dequeue()
    {
        var lastIndex = _data.Count - 1;
        var firstItem = _data[0];
        _data[0] = _data[lastIndex];
        _data.RemoveAt(lastIndex--);
        var parentIndex = 0;
        while (true)
        {
            var childIndex = parentIndex * 2 + 1;
            if (childIndex > lastIndex)
                break;
            var rightChild = childIndex + 1;
            if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0)
                childIndex = rightChild;
            if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
                break;
            Swap(parentIndex, childIndex);
            parentIndex = childIndex;
        }
        return firstItem;
    }

    public T Peek()
    {
        return _data[0];
    }

    private void Swap(int a, int b)
    {
        var tmp = _data[a];
        _data[a] = _data[b];
        _data[b] = tmp;
    }

    private int Compare(T a, T b)
    {
        return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
    }

    public int Count => _data.Count;

    public IEnumerator<T> GetEnumerator()
    {
        return _data.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,K;
    cin >> N >> K;
    ll low = K - N + 1,high = N + K - 1;
    for(ll i = low;i <= high;i++){
        cout << i;
        cout << (i != high ? " ":"\n");
    }
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(long long i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const double EPS = 1e-9;
const ll powll = 1LL<<1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int main(void){
    int n; cin >> n;
    int a[n]; rep(i,0,n) cin >> a[i];

    int ans = MOD;
    rep(i,0,2001){
        int sum = 0;
        rep(j,0,n){
            sum = max(sum, abs((int)i-a[j]));
        }
        if(sum < ans) ans = sum;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

int main() {
    int n;
    double v[101];
    cin>>n;
    REP(i, 0, n) cin>>v[i];

    sort(v, v+n);

    double avr=v[0];
    REP(i, 1, n){
        avr=(avr+v[i])/2.0;
    }
    printf("%.7lf\n", avr);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <utility>

using namespace std;

const int INF = 1000000007;
const double PI = acos(-1.0);
typedef long long llong;

int n, t, r;

int id(int _r, int _t) { return _t * 5 + _r; }

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> r >> t;
		bool OnT = t % 30 == 0 ? true : false;
		bool OnR = r % 100 == 0 ? true : false;
		r  = r / 100;
		t = t / 30;
		if (OnT && OnR)
			cout << id(r, t) << endl;
		else if (OnR)
			cout << id(r, t) << " " << id(r, t + 1) << endl;
		else if (OnT)
			cout << id(r, t) << " " << id(r + 1, t) << endl;
		else
			cout << id(r, t) << " " << id(r + 1, t) << " " << id(r, t + 1) << " " << id(r + 1, t + 1) << endl;;
	}

	return 0;
}

Measured memory_bytes: 3080