akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

struct Node {
	int key;
	Node* parent, * left, * right;
};

#define MAX 500000

Node* root;

void in(Node* node) {
	if (node == NULL)return;
	in(node->left);
	cout << " " << node->key;
	in(node->right);
}

void pre(Node* node) {
	if (node == NULL)return;
	cout << " " << node->key;
	pre(node->left);
	pre(node->right);
}

void print() {
	in(root);
	cout << endl;
	pre(root);
	cout << endl;
}

void insert(int key) {
	Node* y = NULL;
	Node* x = root;
	Node* z = new Node;
	z->key = key;
	z->parent = z->left = z->right = NULL;

	if (root == NULL) {
		root = z;
		return;
	}

	while (x != NULL) {
		y = x;
		if (key < x->key)x = y->left;
		else if (key > x->key)x = y->right;
	}
	if (key < y->key) {
		y->left = z;
		z->parent = y;
	}
	else {
		y->right = z;
		z->parent = y;
	}
}

int main() {
	int m;
	cin >> m;
	for (int i = 0; i < m; i++) {
		char buf[20];
		cin >> buf;
		if (buf[0] == 'i') {
			int k;
			cin >> k;
			insert(k);
		}
		else {
			print();
		}
	}
	return 0;
}


Measured memory_bytes: 26528
#include <bits/stdc++.h>
using namespace std;
#define int long long
main()
{
	int n,m;
	cin>>n>>m;
	string s[n];
	for (int i=0;i<n;i++) cin>>s[i];
	int dp[n][m];
	if (s[0][0]=='#') dp[0][0]=0;
	else dp[0][0]=1;
	for (int i=1;i<n;i++)
	{
	  
	if (s[i][0]=='#') dp[i][0]=0;
	else dp[i][0]=dp[i-1][0];}
	for (int j=1;j<m;j++)
	{
	if (s[0][j]=='#') dp[0][j]=0;
	else dp[0][j]=dp[0][j-1];}
	for (int i=1;i<n;i++)
	{
		for (int j=1;j<m;j++)
		{
			int a=(s[i-1][j]=='#') ? 0 : dp[i-1][j];
			int b=(s[i][j-1]=='#') ? 0 : dp[i][j-1];
			dp[i][j]=(a+b)%1000000007;
		}
	}
	cout<<dp[n-1][m-1]<<endl;
}

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

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

struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

int main() {
    int N,a,b,c,Q,K,x,y;
    queue<int> q;
    cin >> N;
    Graph G(N+1);
    vector<ll> d(N+1,-1);

    rep(i,N-1) {
        cin >> a >> b >> c;
        G.at(a).push_back(Edge(b,c));
        G.at(b).push_back(Edge(a,c));
    }

    cin >> Q >> K;
    q.push(K);
    d.at(K) = 0;

    while(!q.empty()) {
        int v = q.front();
        q.pop();
        for (auto nv : G.at(v)) {
            if (d.at(nv.to) != -1)
                continue;
            d.at(nv.to) = d.at(v) + nv.weight;
            q.push(nv.to);
        }
    }
    
    rep(i,Q) {
        cin >> x >> y;
        cout << d.at(x)+d.at(y) << endl;
    }
}

Measured memory_bytes: 8820
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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 void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int dp[111][111];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<string> fi(H);
    REP(i,H) cin >> fi[i];

    queue<tuple<int, int, char>> q;
    q.emplace(0, 0, fi[0][0]);
    memset(dp, 10101010, sizeof(dp));
    if(fi[0][0] == '.') dp[0][0] = 0;
    else dp[0][0] = 1;

    while(!q.empty()){
        int h, w;
        char cur;
        tie(h, w, cur) = q.front(); q.pop();
        if(h == H-1 && w == W-1) break;
        REP(i,2){
            int nh = h + dx[i], nw = w + dy[i];
            if(nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if(cur == fi[nh][nw]){
                if(chmin(dp[nh][nw], dp[h][w])){
                    q.emplace(nh, nw, cur);
                }
            }
            else{
                if(cur == '#'){
                    if(chmin(dp[nh][nw], dp[h][w])){
                        q.emplace(nh, nw, fi[nh][nw]);
                    }
                }
                else{
                    if(chmin(dp[nh][nw], dp[h][w] + 1)){
                        q.emplace(nh, nw, fi[nh][nw]);
                    }
                }
            }
        }
    }
    cout << dp[H-1][W-1] << endl;
}


Measured memory_bytes: 384
n=int(input())
cnt=[[0]*n for _ in range(26)]
check='abcdefghijklmnopqrstuvwxyz'
for i in range(n):
  s=input()
  for j in range(26):
    cnt[j][i]=s.count(check[j])
ans=''
for i in range(26):
  ans+=check[i]*min(cnt[i])
print(ans)

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, K;
    cin >> N >> K;
    vector<ll> v(N);
    REP(i, N) cin >> v[i];
    sort(ALL(v));

    ll ans = INF;
    REP(i, N - K + 1) {
        ans = min(ans, v[i+K-1] - v[i]);
    }

    cout << ans << endl;

}


Measured memory_bytes: 1024
#include <iostream>

int main()
{
    long int L, R;
    std::cin >> L >> R;

    long int ceil = L / 2019;
    long int floor = R / 2019 + 1;
    if (floor - ceil > 1) {
        std::cout << 0;
        return 0;
    }

    // 3 * 673が作れる
    long int ceil2 = L / 673;
    long int floor2 = R / 673;
    if (floor2 - ceil2 > 1 && R - L + 1 >= 3) {
        std::cout << 0;
        return 0;
    }

    int min = 2019;
    for (long int i = L; i < R; i++) {
        for (long int j = i + 1; j <= R; j++) {
            int mod = (i * j) % 2019;
            if (mod < min) {
                min = mod;
                if (min == 1) {
                    std::cout << min;
                    return 0;
                }
            }
        }
    }
    std::cout << min;

    return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n;
ll a[201010];
P b[201010];
ll res[201010];

int main(){
  cin>>n;
  rep(i,n){
    cin>>a[i];
    b[i]=P(a[i],i);
  }
  sort(b,b+n);
  ll m=(n+1)/2;
  m--;
  rep(i,n){
    if(i<=m)res[b[i].se]=b[m+1].fi;
    else res[b[i].se]=b[m].fi;
  }
  rep(i,n)cout<<res[i]<<endl;
  return 0;
}


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

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

int main(void){
    int n,ma,mb;
    cin>>n>>ma>>mb;
    vector<P> v(n);
    rep(i,n){
        int a,b,c;
        cin>>a>>b>>c;
        v[i] = {{a,b},c};
    }

    map<pair<int,int>,int> cost;
    cost[{0,0}] = 0;
    rep(i,n){
        for(auto itr = cost.rbegin(); itr!=cost.rend(); ++itr){
            int a = v[i].first.first + itr->first.first;
            int b = v[i].first.second + itr->first.second;
            int c = v[i].second + itr->second;
            if(cost.count({a,b})){
                cost[{a,b}] = min(cost[{a,b}], c);
            }else{
                cost[{a,b}] = c;
            }
        }
    }

    int mn = INF;
    cost.erase(cost.begin());
    for(auto itr : cost){
        if(itr.first.first * mb == itr.first.second * ma){
            mn = min(mn, itr.second);
        }
    }
    cout<<((mn==INF) ? -1 : mn)<<endl;
    return 0;
}


Measured memory_bytes: 1536
class Dice

  def initialize(surfaces)
    @surfaces = surfaces.dup 
  end

  def top
    @surfaces[0]
  end

  def N
    tmp = @surfaces[0]
    @surfaces[0] = @surfaces[1]
    @surfaces[1] = @surfaces[5]
    @surfaces[5] = @surfaces[4]
    @surfaces[4] = tmp
    self
  end

  def E
    tmp = @surfaces[0]
    @surfaces[0] = @surfaces[3]
    @surfaces[3] = @surfaces[5]
    @surfaces[5] = @surfaces[2]
    @surfaces[2] = tmp
    self
  end

  def S
    tmp = @surfaces[0]
    @surfaces[0] = @surfaces[4]
    @surfaces[4] = @surfaces[5]
    @surfaces[5] = @surfaces[1]
    @surfaces[1] = tmp
    self
  end

  def W
    tmp = @surfaces[0]
    @surfaces[0] = @surfaces[2]
    @surfaces[2] = @surfaces[5]
    @surfaces[5] = @surfaces[3]
    @surfaces[3] = tmp
    self
  end
end

n = gets.chomp.split.map(&:to_i)
c = gets.chomp

d = Dice.new(n)
c.each_char{|m| d.send(m) }
puts d.top

Measured memory_bytes: 8704
import sys
input = lambda: sys.stdin.readline().rstrip()

N, M, K = map(int, input().split())

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

a = [0] + A
b = [0] + B

for i in range(len(a)-1):
    a[i+1] += a[i]

for i in range(len(b)-1):
    b[i+1] += b[i]

ans = 0
j = M

for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans) 

Measured memory_bytes: 118168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//UnionFind
//全て添字で扱うこと
struct union_find {
  vll parent;
  vll sizes;

  //初期化
  void init(ll n) {
    for (ll i = 0; i < n; i++) parent.push_back(i);
    for (ll i = 0; i < n; i++) sizes.push_back(1);
    return;
  }

  //頂点nの根
  ll root(ll n) {
    if (parent[n] == n) return n;
    return parent[n] = root(parent[n]);
  }

  //頂点nと間接的に繋がっている頂点の数(自身含む)
  ll size(ll n) {
    return sizes[root(n)];
  }

  //頂点a, bが間接的に繋がっているか判定
  bool is_united(ll a, ll b) {
    return (root(a) == root(b));
  }

  //頂点aを含むグラフに頂点bを含むグラフを結合
  void unite(ll a, ll b) {
    if (is_united(a, b)) return;
    sizes[root(a)] += size(b);
    parent[root(b)] = root(a);
    return;
  }
};

int main() {
  ll n, m;
  cin >> n >> m;

  vector<vll> xyz(m, vll(3));
  for (ll i = 0; i < m; i++) cin >> xyz[i][0] >> xyz[i][1] >> xyz[i][2];

  union_find uf;
  uf.init(n);

  ll ans = n;
  for (ll i = 0; i < m; i++) {
    if (!(uf.is_united(xyz[i][0] - 1, xyz[i][1] - 1))) {
      ans--;
      uf.unite(xyz[i][0] - 1, xyz[i][1] - 1);
    }
  }

  cout << ans << endl;
}

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

const int N = 205;

int n, color[N], d[N][N];
bool e[N][N];

void dfs(int u) {
	for (int v = 0; v < n; v++) {
		if (!e[u][v]) continue;
		if (color[v]) {
			if (color[v] == color[u]) {
				printf("-1\n");
				exit(0);
			}
		}
		else {
			color[v] = 3 ^ color[u];
			dfs(v);
		}
	}
}

int main() {

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			char x; scanf(" %c", &x);
			e[i][j] = x == '1';
		}
	}

	color[0] = 1;
	dfs(0);

	memset(d, 60, sizeof(d));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (e[i][j]) d[i][j] = 1;
		}
	}

	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i == j) continue;
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}

	int mx = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			// printf("distance %d->%d = %d\n", i, j, d[i][j]);
			if (d[i][j] < 1e9) mx = max(mx, d[i][j]);
		}
	}

	cout << mx + 1 << endl;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define MOD 100000007
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main(){
    ll N, ans = 0;
    cin >> N;
    VL V(N), C(N);
    FOR(i, 0, N) cin >> V[i];
    FOR(i, 0, N) cin >> C[i];

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

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/*
  Contest 065
  C - Reconciled?
  Rakesh Kumar --> 01/09/2020
 */

#include <bits/stdc++.h>

using ll = long long int;
const ll M = (1e9 + 7);

ll f (ll n) {
    ll r = 1;
    for (ll i = 2; i <= n; ++i)
        r = (r * i) % M;
    return r;
}

/*
  combinations maths questions.
  for example
  D --> dog, M --> Monkey
  if abs(D - M) == 0
  let's D = M = 2
  can be 2 combinations where DMDM or MDMD therefore (D! * M!) * 2
  if abs(D - M) = 1
  DMD, MDM so D! * M!
  else abs(D - M) > 1
  0, because dog and monkey can't stand each other
 */

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

    ll n = 0, m = 0;
    std::cin >> n >> m;
    if (std::abs(n - m) <= 1) {
        ll result = f(n);
        result = (result * f(m)) % M;
        if (n == m)
            result = (result << 1) % M;
        std::cout << result << std::endl;
    } else {
        std::cout << 0 << std::endl;
    }


    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
struct st{int a,b,c;};
bool operator <(st x,st y) {return x.c>y.c;}
map<int,vi> E[100000];
vi G[100000];
map<int,int> d[100000];
int main(){
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	rep(i,m){
		int x,y,z;cin>>x>>y>>z;--x,--y;
		E[x][z].pb(y);E[y][z].pb(x);
		G[x].pb(z);G[y].pb(z);
	}
	priority_queue<st> pq;
	d[0][0]=0;pq.push({0,0,0});
	while(!pq.empty()){
		st p=pq.top();pq.pop();
		if (p.c>d[p.a][p.b]) continue;
		if (d[p.a].find(0)==d[p.a].end()||d[p.a][0]>p.c){
			d[p.a][0]=p.c;pq.push({p.a,0,p.c});
		}
		if (p.b==0){
			for (int v:G[p.a]){
				if (d[p.a].find(v)==d[p.a].end()||d[p.a][v]>p.c+1){
					d[p.a][v]=p.c+1;pq.push({p.a,v,p.c+1});
				}
			}
			continue;
		}
		for (int v:E[p.a][p.b]){
			if (d[v].find(p.b)==d[v].end()||d[v][p.b]>p.c){
				d[v][p.b]=p.c;pq.push({v,p.b,p.c});
			}
		}
	}
	int ans=INF;
	for (auto i:d[n-1]) ans=min(ans,i.second);
	cout<<(ans==INF? -1:ans);
	return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    int a[m], b[m],x[n];
    rep(i, n) x[i] = 0;
    rep(i,m){
        cin >> a[i] >> b[i];
        x[a[i]-1]++;
        x[b[i]-1]++;
    }
    rep(i, n) cout << x[i] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if (s == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    else if (s == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    else
    {
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
s = gets.chomp
hash = {}
for i in 0...4 do
  if hash.include?(s[i])
    hash[s[i]] += 1
  else
    hash[s[i]] = 1
  end
end
flag = true
count = 0
hash.each { |k, v|
  flag = false if v != 2
  count += 1
}
puts (count == 2 && flag) ? "Yes" : "No"


Measured memory_bytes: 1788
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <math.h>
#include <iomanip>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    double a,b,h,m;
    cin >> a >>b>>h>>m;
    double theta_h = (60*h+m)*2*M_PI/720.0;
    double theta_m = 2*M_PI*m/60.0;

    double ans=sqrt(a*a + b*b-2*a*b*cos(theta_h-theta_m));

    cout << std::setprecision(15)<<ans <<endl;


    return 0;
}


Measured memory_bytes: 4196
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
for i in range(N):
    A[i] -= (i+1)
A = sorted(A)
k = N // 2 
b = A[k]
ans = 0
for i in range(N):
    ans += abs(A[i]-b)
print(ans)

Measured memory_bytes: 29272
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

// #include <unordered_set>
// #include <unordered_map>

#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

#define pb push_back
#define mp make_pair

int gcd(int a, int b) {
    int c;
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}

int lcm(int a, int b) {
    int c = gcd(a, b);
    a /= c;
    return a * b;
}

typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI = acos(-1.0);


// #define int long long

using namespace std;


int main() {


    ios::sync_with_stdio(false);
    cin.tie(0);

//    int n, h, w;
//    cin >> n >> h >> w;
//
//    cout << (n-h+1) * (n-w+1) << endl;

    int n, a, b;
    int tmp;
    int count_1 = 0;
    int count_2 = 0;
    int count_3 = 0;
    cin >> n >> a >> b;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        v.push_back(tmp);
        if (tmp <= a) count_1++;
        else if (a + 1 <= tmp && tmp <= b) count_2++;
        else if (b + 1 <= tmp) count_3++;
    }

//    cout << count_1 << count_2 << count_3 << endl;
    cout << min(count_1, min(count_2, count_3));

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  string sa, sb, sc;
  cin >> sa >> sb >> sc;
  int cnt_a = 0, cnt_b = 0, cnt_c = 0;
  char mode = 'a';
  while (!((cnt_a == sa.length() && mode == 'a') ||
           (cnt_b == sb.length() && mode == 'b') ||
           (cnt_c == sc.length() && mode == 'c'))) {
    switch (mode) {
    case 'a':
      mode = sa[cnt_a];
      cnt_a++;
      break;
    case 'b':
      mode = sb[cnt_b];
      cnt_b++;
      break;
    case 'c':
      mode = sc[cnt_c];
      cnt_c++;
      break;
    }
  }
  switch (mode) {
  case 'a':
    cout << "A" << endl;
    break;
  case 'b':
    cout << "B" << endl;
    break;
  case 'c':
    cout << "C" << endl;
    break;
  }
  return 0;
}

Measured memory_bytes: 256
<?php

list($h1,$m1,$h2,$m2,$k) = explode(" ", trim(fgets(STDIN)));

$hun = 0;
if($m2 < $m1){
    $h2 = $h2 - 1;
    $hun = ($m2+60)-$m1;    
}else{
    $hun = $m2 - $m1;
}

$zikan = (($h2 - $h1)*60);
echo ($zikan + $hun) - $k;

Measured memory_bytes: 16112
// ConsoleApplication1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	priority_queue<int64_t> q;
	for (int i = 0; i < n; i++) {
		int64_t t;
		cin >> t;
		q.push(t);
	}
	for (int i = 0; i < m; i++) {
		auto t = q.top();
		q.pop();
		q.push(t / 2);
	}
	int64_t sum = 0;
	while (!q.empty()) {
		auto t = q.top();
		q.pop();
		sum += t;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
if(s=="MON")cout<<"6"<<endl;
if(s=="TUE")cout<<"5"<<endl;
if(s=="WED")cout<<"4"<<endl;
if(s=="THU")cout<<"3"<<endl;
if(s=="FRI")cout<<"2"<<endl;
if(s=="SAT")cout<<"1"<<endl;
if(s=="SUN")cout<<"7"<<endl;
return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <stack>
#include <set>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;

void solve() {
	ll n, m, k; cin >> n >> m >> k;
	vector<ll> a(n), b(m);
	for (ll &i : a)cin >> i;
	for (ll &i : b)cin >> i;
	for (int i = 1; i < n; i++)a[i] += a[i - 1];
	for (int i = 1; i < m; i++)b[i] += b[i - 1];
	ll ans = 0;
	int j = m - 1;
	for (int i = 0; i < n; i++) {
		ll cur = k - a[i];
		if (cur < 0)break;
		while (j >= 0 && b[j] > cur)j--;
		ans = max(ans, 1ll * i + j + 2);

	}
	ll ans1 = 0, ans2 = 0;
	ans1 = upper_bound(b.begin(), b.end(), k) - b.begin();
	ans2 = upper_bound(a.begin(), a.end(), k) - a.begin();
	cout << max(ans, max(ans1, ans2));
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// int t; cin >> t;
	// while (t--)
	solve();

}

Measured memory_bytes: 6380
import sys
input = sys.stdin.buffer.readline

def main():
    N,Z,W = map(int,input().split())
    A = list(map(int,input().split()))
    
    if len(A) != 1:
        a = abs(A[-1]-W)
        b = abs(A[-2]-A[-1])
        print(max(a,b))
    else:
        print(abs(A[0]-W))
    
if __name__ == "__main__":
    main()

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    string t;
    cin>>t;
    int cnt=0;
    for (int i=0;i<s.size();i++)
        if(s[i]!=t[i])
            cnt++;
    cout<<cnt<<"\n";        
	return 0;
}

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

int main(){
    int64_t a, b, c, d; cin >> a >> b >> c >> d;
    int64_t ans = b - a + 1; int64_t l = lcm(c, d);
    ans -= (b / c - a / c + (a % c == 0));
    ans -= (b / d - a / d + (a % d == 0));
    ans += (b / l - a / l + (a % l == 0));
    cout << ans << endl;
    return 0;
}

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

int main() {
  ll w,h; cin >> w >> h;
  ll x,y; cin >> x >> y;

  cout << w*h/2.0 << endl;

  if(x*2 == w && y*2 == h) cout << 1 <<" ";
  else cout << 0 << endl;

}


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

int main(){
    int n, m, x;
    cin >> n >> m >> x;

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

    int cou_0 = 0;
    int cou_n = 0;

    for(int i = 0; i < m; i++){
        if(a[i] < x){
            cou_0++;
        }else{
            cou_n++;
        }
    }

    if(cou_0 >= cou_n){
        cout << cou_n << endl;
    }else{
        cout << cou_0 << endl;
    }
}

Measured memory_bytes: 256
def main():
    n = int(input())
    A = list(map(int,input().split()))
    m = {}
    for x in A:
        i = min(3200 // 400,x // 400)
        m[i] = m.get(i,0) + 1
    mi = 0
    ma = 0
    for x in range(3200 // 400):
        if m.get(x,0) > 0:
            mi = mi + 1
    if mi == 0:
        mi = 1
        ma = -1
    ma += mi
    ma += m.get(3200 // 400,0)

    print("{} {}".format(mi,ma))
if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include<cstdio>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

typedef long long LL;

const int maxn=55;

int n,p,a[maxn];

LL f[maxn][2];
int main()
{
	scanf("%d %d",&n,&p);
	fo(i,1,n) scanf("%d",&a[i]), a[i]%=2;
	
	f[0][0]=1;
	fo(i,1,n)
		fo(x,0,1) f[i][x]=(f[i-1][x]+f[i-1][x^a[i]]);
	
	printf("%lld\n",f[n][p]);
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  while(cin >>s){
    bool f = false;
    int x = 0;
    for(int i=0; i<s.size(); i++){
      if(s[i] == '@'){f = true;}
      else if(f && x == 0){x = s[i]-'0';}
      else if(f){
	for(int j=0; j<x; j++){cout <<s[i];}
	f = false;
	x = 0;
      }
      else cout <<s[i];
    }
    cout <<endl;
  }
  return 0;
}

Measured memory_bytes: 1172
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var abc="abcdefghijklmnopqrstuvwxyz".split("");
Arr.forEach(function(v){
   for(var i=0;i<26;i++){
      var str=v.replace(/[a-z]/g,function(s){
         return abc[(abc.indexOf(s)+i)%26];
      });
      if(str.match(/the|this|that/))break;
   }
   console.log(str);
});

Measured memory_bytes: 8752
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int a;
    cin >> a;
    cout << "Christmas" << endl;
    rep(i,0,25-a)cout << " Eve";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		String abc = "" + a + b + c;

		String ans = "NO";

		if (a + b + c == 17) {
			if (abc.contains("7") && abc.contains("5")) {
				ans = "YES";
			}
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long i, j, k;
    long long N, K;
    cin >> N >> K;
    vector<long long> as(N), bs(N);
    for(i=0; i<N; i++) cin >> as[i] >> bs[i];
    long long ans = 0;
    for(i=-1; i<=30; i++){
        if(i>=0 && ((K>>i) & 1) == 0) continue;
        long long sum = 0;
        for(j=0; j<N; j++){
            if(i>=0 && ((as[j]>>i) & 1) == 1) continue;
            bool result = true;
            for(k=i+1; k<=30; k++){
                if(((as[j]>>k) & 1) > ((K>>k) & 1)){
                    result = false;
                    break;
                }
            }
            if(result) sum += bs[j];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#define NAME "a"

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <cctype>
#include <cassert>
#include <memory>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#include <iterator>

#define pb push_back
#define mp make_pair
#define frs first
#define snd second

using namespace std;

#ifdef WIN32
    #define lld "%I64d"
#else
    #define lld "%lld"
#endif

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 7;
const ll INFLONG = (ll) 1e18 + 7;
const double EPS = 1e-9;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<string> vs;

typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;

template <typename T>
T sqr(T a) {
    return a * a;
}

void solve() {
    int n;
    scanf("%d", &n);
    vi a(n);

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

    vi pref(n + 1, 0);
    vi suff(n + 1, 0);

    for (int i = 0; i < n; i++) {
        pref[i + 1] = pref[i] ^ a[i];
    }

    suff[0] = pref[n];

    for (int i = 0; i < n; i++) {
        suff[i + 1] = suff[i] ^ a[i];
    }

    vi ans;

    for (int i = 0; i < n; i++) {
        ans.pb(pref[i] ^ suff[i + 1]);
    }

    for (int i = 0; i < n; i++) {
        printf("%d%c", ans[i], " \n"[i == n - 1]);
    }
}

int main() {
    srand(time(0));

//    freopen(NAME".in", "r", stdin);
  //  freopen(NAME".out", "w", stdout);

    int T = 1;

    while (T--) {
        solve();
    }

//    printf("%.3lf\n", (double) clock() / CLOCKS_PER_SEC);
    return 0;
}


Measured memory_bytes: 6664
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int[] N = new int[5];
		boolean t = true;
		
		
		for(int i = 0;i<5;i++) {
			N[i] = sc.nextInt();
		}
		
		int k = sc.nextInt();
		
		for(int j = 0;j<4;j++) {
			if(Math.abs(N[0]-N[j+1])>k) {
				t = false;
			}
		}
		for(int j = 0;j<3;j++) {
			if(Math.abs(N[1]-N[j+2])>k) {
				t = false;
		}
		}
		for(int j = 0;j<2;j++) {
			if(Math.abs(N[2]-N[j+3])>k) {
				t = false;
		}
		}
			if(Math.abs(N[3]-N[4])>k) t = false; 
			
			if(t ==true) {
				System.out.println("Yay!");
			}else {
				System.out.println(":(");
			}
	}
}

Measured memory_bytes: 21588
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int[] i = new int[3];
		
		for(int j = 0; j < 3; j++){
			i[j] = sc.nextInt();
		}
		
		Arrays.sort(i);

		System.out.println(i[0] + " " + i[1] + " " + i[2]);
	}
}

Measured memory_bytes: 26060
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    string s;
    cin >> s;
    ll n=s.size();
    ll ans=1000,mx,t;
    ll i,j;
    for(i=0;i<n;i++){
        j=0;
        mx=0;
        t=0;
        while(j<n){
            if(s[i]!=s[j])t++;else {mx=max(t,mx);t=0;}
            j++;
        }
        mx=max(t,mx);
        ans=min(mx,ans);
    }
    cout << ans;
    return 0;
}


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

#define MAX 50
char tile[MAX][MAX];

int Solve(int,int);

int h,w;

int main(){
	cin>>h>>w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>tile[i][j];
		}
	}


	int flag=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(tile[i][j]=='#'){
				flag+=Solve(i,j);

			}
		}
	}
	if(flag)cout<<"No";
	else cout<<"Yes";

	cout<<endl;

	return 0;
}

int Solve(int y, int x){
	int dy[]={-1,1,0,0};
	int dx[]={0,0,-1,1};
	for(int i=0;i<4;i++){
		if(x+dx[i]<0 || x+dx[i]>=w || y+dy[i]<0 || y+dy[i]>=h)continue;

		if(tile[ y+dy[i] ][ x+dx[i] ]=='#' )return 0;
	}

	return 1;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdio.h>
int main()
{
    char S[10];
    int N,K;
    scanf("%d%s%d",&N,S,&K);
    char ch;
    ch = S[K-1];
    int i;
    for(i=0; i<N; i++)
    {
        if(S[i] == ch)
        {
            printf("%c",S[i]);
        }
        else
        {
            printf("*");
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vint A(N);
    rep(i, N) cin >> A[i];
    int search = 1;
    int ans = 0;
    rep(i, N) {
        if (search == A[i]) {
            search++;
        }
        else {
            ans++;
        }
    }
    if (ans == N) {
        cout << -1 << endl;
    }
    else {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int H = sc.nextInt();
        int W = sc.nextInt();
        char[][] c = new char[H][W];
        String[] s = new String[H];
        for(int i = 0; i < H; i++){
            s[i] = sc.next();
            c[i] = s[i].toCharArray();
        }
        sc.close();

        for(int i = 0; i < 2*H; i++){
            for(int j = 0; j < W; j++){
                System.out.print(c[i/2][j]);
            }
            System.out.println();
        }
   }
}

Measured memory_bytes: 27536
#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;

map<int,int> t;
const int INF=1000100010;
int main(){
    int n,c,k,ti;
    cin>>n>>c>>k;
    rep(i,n){
        cin>>ti;
        ++t[ti];
    }
    int cnt=0,wp=0,wt=INF;
    for(auto it:t){
        if(it.first>wt+k){
            wp=0;++cnt;wt=INF;
        }
        wp+=it.second;
        if(wt==INF) wt=it.first;
        while(wp>=c){
            ++cnt,wp-=c;
            if(wp==0) wt=INF;
        } 
    }
    if(wp>0)++cnt;
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 4992
n = int(input())



a = list(map(int,input().split()))

ans = float("inf")

now = 0
summ = 0
for i in range(n):

    summ += a[i]

    if i % 2 == 0 and summ <= 0:
        now += 1 - summ
        summ = 1

    elif i % 2 == 1 and summ >= 0:
        now += summ + 1
        summ = -1

ans = min(ans,now)

now = 0
summ = 0

for i in range(n):

    summ += a[i]

    if i % 2 == 1 and summ <= 0:
        now += 1 - summ
        summ = 1

    elif i % 2 == 0 and summ >= 0:
        now += summ + 1
        summ = -1

ans = min(ans,now)

print (ans)


Measured memory_bytes: 14468
import java.io.*;
import java.util.*;

public class Main {
  private static int solve(int n, int t, int[] ts) {
    int sum = t;
    for (int i = 1; i < n; i++) {
      sum += Math.min(ts[i] - ts[i - 1], t);
    }
    return sum;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    int t = reader.nextInt();
    int[] ts = reader.nextInt(n);
    out.println(solve(n, t, ts));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 46316
import sys
N=int(input())
l=[int(x) for x in input().split()]
l1=[sys.maxsize]*(N)
l1[0]=0
for i in range(N):
    for j in range(i+1,i+3):
        if j<N:
            l1[j]=min(l1[j],l1[i]+abs(l[j]-l[i]))
print(l1[N-1])
        


Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main()
{
  ll x, y;
  cin >> x >> y;
  ll cnt = 0;
  if (x == 0 || y == 0)
  {
    cnt += abs(abs(x) - abs(y));
    if (0 < x || y < 0)
      cnt++;
    cout << cnt << endl;
    return 0;
  }
  int _x = x / abs(x), _y = y / abs(y);
  if (_x == -1 && _y == -1)
  {
    if (x < y)
    {
      cout << abs(abs(x) - abs(y)) << endl;
    }
    else
    {
      cout << abs(abs(x) - abs(y)) + 2 << endl;
    }
  }
  else if (_x == -1 && _y == 1)
  {
    cout << abs(abs(x) - abs(y)) + 1 << endl;
  }
  else if (_x == 1 && _y == -1)
  {
    if (abs(y) < abs(x))
    {
      cout << abs(abs(x) - abs(y)) + 1 << endl;
    }
    else
    {
      cout << abs(abs(x) - abs(y)) + 1 << endl;
    }
  }
  else
  {
    if (x < y)
    {
      cout << y - x << endl;
    }
    else
    {
      cout << x - y + 2 << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1e9+7;
template<class T> bool chmin(T&a,T b){if(a>=b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
ll N=1;
vi segsum;
void init(vi v){
    while(N<v.size())N*=2;
    segsum=vi(N*2-1);
    rep(i,N){
        if(i<v.size())segsum[i+N-1]=v[i];
        else segsum[i+N-1]=0;
    }
    for(int i=N-2;i>=0;i--)segsum[i]=segsum[i*2+1]+segsum[i*2+2];
}
void update(int i,ll x){
    i+=N-1;
    //segsum[i]=x;
    segsum[i]+=x;
    while(i>0){
        i=(i-1)/2;
        segsum[i]=segsum[i*2+1]+segsum[i*2+2];
    }
}
ll getsum(int a,int b,int k,int l,int r){
    if(a<=l&&r<=b)return segsum[k];
    if(r<=a||b<=l)return 0;
    ll c1=getsum(a,b,k*2+1,l,(l+r)/2);
    ll c2=getsum(a,b,k*2+2,(l+r)/2,r);
    return c1+c2;
}
int main(){
    ll n,q;cin>>n>>q;
    vi v(n);
    init(v);
    rep(i,q){
        ll c,x,y;cin>>c>>x>>y;
        if(c)out(getsum(x-1,y,0,0,N));
        else update(x-1,y);
    }
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main(){
	map<char,string>mp;
	string s;
	cin>>s;
	reverse(s.begin(),s.end());
	mp.insert(make_pair('a',s));
	cin>>s;
	reverse(s.begin(),s.end());
	mp.insert(make_pair('b',s));
	cin>>s;
	reverse(s.begin(),s.end());
	mp.insert(make_pair('c',s));
	char ch='a';
	while(mp[ch].size()>0){
		char ch1=mp[ch][mp[ch].size()-1];
		mp[ch].pop_back();
		ch=ch1;
	}
	cout<<char(ch-'a'+'A');
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! p {
    ($x:expr $(, $tail:expr)*) => {
        let mut s = String::new();
        s.push_str(format!("{:?}", $x).as_str());
        $(
            s.push_str(format!(", {:?}", $tail).as_str());
        )*
        println!("{}", s);
    };
}

#[allow(unused_macros)]
macro_rules! pl {
    ($($x:expr), *) => {
        $(println!("{:?}", $x);)*
    };
}

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    println!("{}", solve(stdin!()));
}

fn solve(src: String) -> String {
    input! {
        source = src,
        n: usize,
        s: chars,
    }
    let mut white = 0;
    for i in 0..n {
        if s[i] == '.' {
            white += 1;
        }
    }
    let mut left_black = 0;
    let mut right_white = white;
    let mut ans = right_white;
    for i in 0..n {
        if s[i] == '#' {
            left_black += 1;
        } else if s[i] == '.' {
            right_white -= 1;
        }
        ans = std::cmp::min(ans, left_black + right_white);
    }
    ans.to_string()
}

// Test Code

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input.to_string()), $output);
            )*
        }
    };
}

test! {
r"
3
#.#
" => "1",

r"
5
#.##.
" => "2",

r"
9
.........
" => "0",

r"
9
##...#.#.
" => "4",
}


Measured memory_bytes: 4352
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
#include <deque>
#include <queue>
#include <tuple>
using namespace std;

#define prec(i) cout << fixed << setprecision(i)

void outPut_YN(bool isYes) {
	if (isYes)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

const long long MOD = 1000000007;

long long fact(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum *= i;

	return sum;
}

long long fact_mod(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum = (sum * i) % MOD;

	return sum;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}

long long pow_mod(int a, int b) {
	long long ans = 1;
	for (int i = 0; i < b; i++)
		ans = (ans * a) % MOD;

	return ans;
}

long long powll(long long a, long long  b) {
	long long ans = 1;
	for (long long i = 0; i < b; i++)
		ans = ans * a;

	return ans;
}

long long modinv(long long a) {

	long long b = MOD, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= MOD;
	if (u < 0) u += MOD;

	return u;
}

long long _gcd(long long a, long long b)
{
	if (a < b)
		swap(a, b);

	if (a % b == 0)
		return b;
	else
		return _gcd(b, a % b);
}

long long _lcm(long long a, long long b)
{
	return (((a * b) % MOD) * modinv(_gcd(a, b))) % MOD;
}

long long ncr(long long n, long long r) {
	long long sum = 1;
	for (long long i = r + 1; i <= n; i++)
		sum *= i;

	return sum;
}



int main()
{

	string s;
	int ans = 0, max = 0;

	cin >> s;


	for (int i = 0; i < 3; i++) {
		if (s[i] == 'R') {
			ans++;
			if (max < ans)
				max = ans;
		}
		else
			ans = 0;
	}

	cout << max << endl;

	return 0;
}

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

using namespace std;

long dp[100005][13];
const long mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
  string s;
   cin >> s;
  
  rep(i,13) dp[0][i]=0;
  dp[0][0]=1;
  
  rep(i,s.length()){
    int c;
    if(s[i]=='?') c=-1;
    else c=s[i]-'0';
    
    rep(j,10){
     if(c!=-1&&c!=j) continue;
      rep(k,13) {
        dp[i+1][(k*10+j)%13]+=dp[i][k];
        dp[i+1][(k*10+j)%13]%=mod;
      }
      }
  
  
  }
  
 cout << dp[s.length()][5] << endl;
}

Measured memory_bytes: 10624