akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
	vector<pair<int,int> > a;
	vector<pair<int,int> > b;
	vector<pair<int, pair<int, int> > > c;
	int p[100001];
	int k;
	int n, m;
	int s, t;
	int y, z;
	long long ans;
	int h1, h2;
int par(int x,int v){
	if (p[x] == x)return x;
	else{
		if (v == 0)h1++;
		else h2++;
		 p[x] = par(p[x],v);
		 return p[x];
	}
}
int main(void){


	int x;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d %d", &x, &y);
		a.push_back(make_pair(x, i));
		b.push_back(make_pair(y, i));
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	for (int i = 1; i < n; i++){
		c.push_back(make_pair(a[i].first - a[i - 1].first, make_pair(a[i - 1].second, a[i].second)));
		c.push_back(make_pair(b[i].first - b[i - 1].first, make_pair(b[i - 1].second, b[i].second)));
	}
	sort(c.begin(), c.end());
	for (int i = 0; i < n; i++)p[i] = i;
	x = 0;
	ans = 0;
	for (int i=0; x < n - 1;i++){
		h1 = 0;
		h2 = 0;
		y = par(c[i].second.first,0);
		z = par(c[i].second.second,1);
		if (y != z){
			if(h1<h2)p[y] = z;
			else p[z] = y;
			ans = ans + c[i].first;
			x++;
		}
	}


	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 7144
import math
a, b, x = map(int, input().split())
if x>=pow(a,2)*b/2:
    print(math.degrees(math.atan(2*(pow(a,2)*b-x)/pow(a,3))))
else:
    print(math.degrees(math.atan(a*pow(b,2)/(2*x))))

Measured memory_bytes: 9312
num_list = map(int,input().split())

seven_num = 0
five_num = 0

for number in num_list:
  if number == 7:
    seven_num += 1
  elif number == 5:
    five_num += 1
    
if seven_num ==1 and five_num == 2:
  print("YES")
else:
  print("NO")


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int N;
	cin >> N;
	string S,T;
	cin >> S >> T;
	int cnt = 0;
	for(int i = N;i > 0;i--) {
		string s = S.substr(N - i);
		string t = T.substr(0,i);
		if(s == t) {
			cnt = i;
          	break;
		}
	}
	cout << N * 2 - cnt << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)

const ll linf = 1e18 + 7;

struct segment_tree {
	static const int maxn = 1 << 18;
	pair <ll, int> mn[maxn << 1];
	void init() {
		for (int i = 1; i < (maxn << 1); ++ i)
			mn[i] = mp(linf, -1);
	}
	void upd(int x, ll v) {
		mn[x + maxn] = mp(v, x);
		for (x += maxn; x >>= 1; )
			mn[x] = min(mn[x << 1], mn[x << 1 | 1]);
	}
	pair <ll, int> qry(int l, int r) {
		pair <ll, int> ans = mp(linf, -1);
		for (l += maxn, r += maxn; l < r; l >>= 1, r >>= 1) {
			if (l & 1) ans = min(ans, mn[l ++]);
			if (r & 1) ans = min(ans, mn[-- r]);
		}
		return ans;
	}
} seg0, seg1;

struct union_find {
	static const int maxn = 2e5 + 5;
	int fa[maxn];
	vector <int> v[maxn];
	void init() {
		for (int i = 0; i < maxn; ++ i)
			fa[i] = i, v[i].pb(i);
	}
	int find(int x) {
		return fa[x] == x ? x : fa[x] = find(fa[x]);
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	void merge(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return ;
		if (v[x].size() < v[y].size()) swap(x, y);
		for (int i = 0; i < v[y].size(); ++ i) v[x].pb(v[y][i]);
		fa[y] = x;
	}
} dsu;

const int maxn = 2e5 + 5;
int n, d, a[maxn];

int main() {
	scanf("%d %d", &n, &d);
	for (int i = 0; i < n; ++ i)
		scanf("%d", &a[i]);
	dsu.init();
	seg0.init(); seg1.init();
	for (int i = 0; i < n; ++ i) {
		seg0.upd(i, a[i] - 1LL * d * i);
		seg1.upd(i, a[i] + 1LL * d * i);
	}
	ll ans = 0;
	while (dsu.v[dsu.find(0)].size() != n) {
		vector <pair <ll, pair <int, int> > > e;
		for (int i = 0; i < n; ++ i) {
			if (dsu.find(i) == i) {
//				eprintf("%d\n", i);
				for (int j = 0; j < dsu.v[i].size(); ++ j) {
					int x = dsu.v[i][j];
//					eprintf("%d ", x);
					seg0.upd(x, linf);
					seg1.upd(x, linf);
				}
//				eprintf("\n");
				pair <ll, pair <int, int> > mn = mp(linf, mp(-1, -1));
				for (int j = 0; j < dsu.v[i].size(); ++ j) {
					int x = dsu.v[i][j];
					pair <ll, int> to = seg0.qry(0, x);
					to.first += a[x] + 1LL * d * x;
					mn = min(mn, mp(to.first, mp(x, to.second)));
				}
				for (int j = 0; j < dsu.v[i].size(); ++ j) {
					int x = dsu.v[i][j];
					pair <ll, int> to = seg1.qry(x + 1, n);
					to.first += a[x] - 1LL * d * x;
					mn = min(mn, mp(to.first, mp(x, to.second)));
				}
				e.pb(mn);
				for (int j = 0; j < dsu.v[i].size(); ++ j) {
					int x = dsu.v[i][j];
					seg0.upd(x, a[x] - 1LL * d * x);
					seg1.upd(x, a[x] + 1LL * d * x);
				}
			}
		}
		for (int i = 0; i < e.size(); ++ i) {
			int u = e[i].second.first;
			int v = e[i].second.second;
			ll cost = e[i].first;
			if (!dsu.same(u, v)) {
				dsu.merge(u, v);
				ans += cost;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main(int argc, char const* argv[]) {
  string S, current;
  cin >> S;
  reverse(S.begin(), S.end());

  set<string> candidates{"maerd", "remaerd", "esare", "resare"};
  while (S.size() > 0) {
    if (S.size() >= 5 && candidates.find(S.substr(0, 5)) != candidates.end()) {
      S = S.substr(5);
      continue;
    }
    if (S.size() >= 6 && candidates.find(S.substr(0, 6)) != candidates.end()) {
      S = S.substr(6);
      continue;
    }
    if (S.size() >= 7 && candidates.find(S.substr(0, 7)) != candidates.end()) {
      S = S.substr(7);
      continue;
    }
    cout << "NO" << endl;
    return 0;
  }
  if (S.size() == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 512
// May this submission get accepted
#pragma GCC optimize ("O3")
#pragma GCC target("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    ll n = inp1;
    ll r = inp1;
    if (n >= 10) {
        cout << r << endl;
    } else {
        cout << r + 100*(10-n) << endl;
    }
    
}

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

int main() {
  
  int N,P;
  string S;
  cin >> N >> P >> S;

  map<int,int> mp;
  mp[0]++;
  long long ans = 0;

  if(P == 2 || P == 5) {
    for(int i = 0;i < N;i++) {
      int o = S.at(N-i-1)-'0';
      if(o%P == 0) ans += N-i;
    }
    cout << ans << endl;
  }else {
    long long fac = 1;
    long long num = 0;
    for(int i = 0;i < N;i++) {
      num = (num+fac*(S.at(N-i-1)-'0')) % P;
      fac = fac*10%P;
      mp[num]++;
    }

    for(auto itr = mp.begin();itr != mp.end();itr++) {
      long long v = itr->second;
      ans += v*(v-1)/2;
    }
    cout << ans << endl;
    
  }

}


Measured memory_bytes: 900
$<.each do |s|
  s.chomp!
  puts 10.times.find {|x|
    ns = s.tr('X', x.to_s).scan(/\d+/)
    next false if ns.any? {|n| n.size >= 2 && n[0] == ?0 }
    a, b, c = ns.map(&:to_i)
    a + b == c
  } || 'NA'
end

Measured memory_bytes: 8848
N = list(input())

A = int(N[0] + N[1])
B = int(N[2] + N[3])

if 0 < A and A <= 12 and 0 < B and B <= 12:
    print("AMBIGUOUS")
elif 0 < A and A <= 12:
    print("MMYY")
elif 0 < B and B <= 12:
    print("YYMM")
else:
    print("NA")


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

using namespace std;

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

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

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

    int compare = 0;

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

    compare -= longest;

    if(longest < compare) {
        cout << "Yes";
    }else{
        cout << "No";
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,k=0;
	cin>>n;
	int p[n],q[n];
	for(int i=0;i<n;i++){
		cin>>p[i];
		q[i]=p[i];
	}
	sort(q,q+n);
	for(int i=0;i<n;i++){
		if(p[i]!=q[i])k++;
	}
	if(k>2)cout<<"NO";
	else cout<<"YES";
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void)
{
    int A,B,C,D,P;
    cin>>A>>B>>C>>D>>P;
    if(C>=P)
    {
        if(A*P<B)
        {
            cout<<A*P<<endl;
        }
        if(A*P>B)
        {
            cout<<B<<endl;
        }
    }
    else
    {
        if(A*P<B+(P-C)*D)
        {
            cout<<A*P<<endl;
        }
        if(A*P>B+(P-C)*D)
        {
            cout<<B+(P-C)*D<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n; cin>>n;
  vector<int> d(n);
  for(auto& i:d) cin>>i;
  int res=0;
  for(int i=0; i<n; ++i) for(int j=i+1; j<n; ++j)
    res+=d[i]*d[j];
  cout<<res;
  return 0;
}

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

int main(){
    int N;
    scanf("%d", &N);
    int L[N];
    for(int i = 0; i < N; i++){
        scanf("%d", &L[i]);
    }
    sort(L, L+N);
    int cnt;
    for(int i = 0; i < N-2; i++){
        for(int j = i+1; j < N-1;j++){
            for(int k = j+1; k < N; k++){
                if(L[k] < L[i]+L[j]){
                    cnt++;
                } else {
                    break;
                }
            }
        }
    }
    printf("%d", cnt);
    return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> roads(N, 0);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        roads.at(a-1)++;
        roads.at(b-1)++;
    }
    for (int i = 0; i < N; i++) {
        cout << roads.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

template<typename T>
class UndoableArray {
	int N;
	vector<int> pos, pre, data;
public:
	UndoableArray(int N) : N(N), data(N) {}
	UndoableArray(int N, T val) : N(N), data(N, val) {}
	UndoableArray(const vector<T>& v) : N(v.size()), data(v) {}
	UndoableArray(vector<T>&& v) : N(v.size()), data(move(v)) {}
	T change(int k, T val) {
		pos.push_back(k);
		pre.push_back(data[k]);
		return data[k] = val;
	}
	void undo() {
		data[pos.back()] = pre.back();
		pos.pop_back(), pre.pop_back();
	}
	T operator[](int k) const {
		return data[k];
	}
	int getversion() const {
		return pos.size();
	}
};

class UndoableUnionFind {
	UndoableArray<int> data;
	vector<int> pre;
	int find(int a) const {
		return data[a] < 0 ? a : find(data[a]);
	}
public:
	UndoableUnionFind(int n) : data(n, -1) {}
	bool same(int a, int b) const {
		return find(a) == find(b);
	}
	void unite(int a, int b) {
		pre.push_back(data.getversion());
		a = find(a);
		b = find(b);
		if (a == b) return;
		if (data[a] < data[b]) swap(a, b);
		data.change(b, data[a] + data[b]);
		data.change(a, b);
	}
	void undo() {
		int cnt = data.getversion() - pre.back();
		while (cnt--) data.undo();
		pre.pop_back();
	}
	int size(int a) const {
		return -data[find(a)];
	}
	int getversion() const {
		return pre.size();
	}
};

class DynamicConnectivity {
	const int v, n;
	vector<vector<pii>> data;
	vector<pii> q;
	int size(int x) const {
		int res = 1;
		while (res < x) res <<= 1;
		return res;
	}
	void sub(int node, vector<int>& res, UndoableUnionFind& uuf) const {
		for (auto p : data[node]) uuf.unite(p.first, p.second);
		if (node < n) {
			sub(node * 2, res, uuf);
			sub(node * 2 + 1, res, uuf);
		}
		else if (q[node - n] != pii(-1, -1)) {
			res.push_back(uuf.same(q[node - n].first, q[node - n].second));
		}
		for (int i = 0; i < (int)data[node].size(); i++) uuf.undo();
	}
public:
	DynamicConnectivity(int v_, int n_) : v(v_), n(size(n_)), data(n * 2), q(n, pii(-1, -1)) {}
	void add_edge(int l, int r, int u, int v) {
		l += n, r += n;
		while (l < r) {
			if (l & 1) data[l++].emplace_back(u, v);
			if (r & 1) data[--r].emplace_back(u, v);
			l >>= 1, r >>= 1;
		}
	}
	void add_query(int p, int u, int v) {
		q[p].first = u;
		q[p].second = v;
	}
	vector<int> calc() const {
		vector<int> res;
		UndoableUnionFind uuf(v);
		sub(1, res, uuf);
		return res;
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> t(k), u(k), v(k);
	for (int i = 0; i < k; i++) {
		cin >> t[i] >> u[i] >> v[i];
	}
	map<pii, int> last;
	DynamicConnectivity dc(n, k);
	for (int i = 0; i < k; i++) {
		if (t[i] == 1) {
			last[pii(u[i], v[i])] = i;
		}
		else if (t[i] == 2) {
			dc.add_edge(last[pii(u[i], v[i])], i, u[i], v[i]);
			last.erase(pii(u[i], v[i]));
		}
		else {
			dc.add_query(i, u[i], v[i]);
		}
	}
	for (auto pp : last) {
		dc.add_edge(pp.second, k, pp.first.first, pp.first.second);
	}
	for (auto ans : dc.calc()) {
		puts(ans ? "YES" : "NO");
	}
	return 0;
}

Measured memory_bytes: 13536
#include<bits/stdc++.h>
#define ll long long
#define mod7 1000000007
using namespace std;

void myfunc() {
    long n;
    cin >> n;
    ll count =0;
    for(ll a=1,b=0;a<=n;a++)
    {
		//b=(n/a);
		if(n%a)
		count+=n/a;
		else
		count+=n/a-1;
	}
	cout << count << endl;
}

int main() {
    long t;
    t=1;
    //cin >> t;
    while(t--)
    myfunc();
    return 0;
}


Measured memory_bytes: 3636
def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

N, X = cin()
a = [0 for _ in range(N)] # 全体の枚数
p = [0 for _ in range(N)] # パティの枚数
a[0] = 1
p[0] = 1

for i in range(1, N):
    a[i] = 2 * a[i - 1] + 3
    p[i] = 2 * p[i - 1] + 1
    
def f(N, X):
    if N == 0:  
        if X <= 0: return 0
        else:  return 1
    if X <= 1 + a[N - 1]:  return f(N - 1, X - 1)
    return 1 + p[N - 1] + f(N - 1, X - 2 - a[N - 1])

ans = f(N, X)
print(ans)

Measured memory_bytes: 61912
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define display(v) for (auto x : v) cout << x << ", "
#define dbg(x) cout << (#x) << " = " << (x) << "\n"
#define dbgp(x) cout << (#x) << " = {" << (x.first) << ", " << (x.second) << "}\n";
#define print(x) cout << (#x) << " = [ ";display(x); cout << "]\n"
#define pb push_back
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;


int main()
{
	fastio;

	int n;
	cin >> n;
	int arr[n], ans[n];
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	int f = arr[0];
	for (int i = 1; i < n; i++)
	{
		f = arr[i] - f;
	}
	ans[0] = f;
	for (int i = 1; i < n; i++)
	{
		ans[i] = (2 * (arr[i - 1])) - ans[i - 1];
	}
	for (auto x : ans)
		cout << x << " ";
	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;

void solve(){

}

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

    int t; cin>>t;


    while(t--){
        lint N; cin>>N;
        lint a, b, c, d; cin>>a>>b>>c>>d;

        unordered_map<lint, lint> vst;

        set<pll> bfs;
        lint ans = -1;
        auto push = [&](lint n, lint cost){

            if (vst.count(n) == 0 || vst[n] > cost){
                if (vst.count(n)) bfs.erase(bfs.find({vst[n], n}));
                vst[n] = cost;
                bfs.insert({cost, n});
            }
        };

        push(N, 0);
        while(!bfs.empty()){
            pll cur = *bfs.begin(); bfs.erase(bfs.begin());
            if (cur.second == 0){
                ans = cur.first;
                break;
            }
//            if (cur.second < N+ 100) push(cur.second + 1, cur.first+d);
//            if (cur.second >1) push(cur.second - 1, cur.first+d);
            lint n = cur.second;
            vl p(6);
            p[2]=a;
            p[3]=b;
            p[5]=c;
            for (lint mod : {2LL, 3LL, 5LL}){
                lint res = n % mod;

                if (res) push(n/mod + 1, cur.first+p[mod] + (mod-res)*d);

                lint minc = p[mod];
                lint dd = (n/mod*mod - n/mod);
                if (dd == 0) minc = 0LL;
                else if (d < p[mod]/dd + 9)    minc = min(minc, dd*d);
                push(n/mod, cur.first+minc + res*d);

            }


//            if (cur.second % 2 == 0) push(cur.second/2, cur.first+a);
//            if (cur.second % 3 == 0) push(cur.second/3, cur.first+b);
//            if (cur.second % 5 == 0) push(cur.second/5, cur.first+c);
//            if (cur.second < 3*N) push(cur.second + 1, cur.first+d);
//            if (cur.second >1) push(cur.second - 1, cur.first+d);
        }
        cout<<ans<<"\n";


    }


}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;


int main(){
    int h,w;cin >>h>>w;
    vector<string>s(h);
    for (int i = 0; i < h; ++i) {
        cin >>s[i];
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            int cnt=0;
            if(s[i][j]=='.'){
                auto add=[&](int a,int b){
                    if(a<0||a>=h)return;
                    if(b<0||b>=w)return;
                    if(s[a][b]=='#')cnt++;
                };
                add(i,j+1);
                add(i,j-1);
                add(i+1,j+1);
                add(i+1,j-1);
                add(i-1,j+1);
                add(i-1,j-1);
                add(i+1,j);
                add(i-1,j);
                s[i][j]=(char)('0'+cnt);
            }
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cout <<s[i][j];
        }
        cout <<endl;
    }
    return 0;
}

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

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for (int i = 1; i <= N; ++i) {
    int sum = findSumOfDigits(i); // i の各桁の和
    if (sum >= A && sum <= B) { //  i の各桁の和が A 以上 B 以下かどうか
      total += i;
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"

using namespace std;

void solve()
{
	int A, B, Q;
	cin >> A >> B >> Q;
	vector<long> as(A), bs(B);
	for (int i = 0; i < A; i++)
	{
		cin >> as[i];
	}
	for (int i = 0; i < B; i++)
	{
		cin >> bs[i];
	}
	as.push_back(-1e12);
	as.push_back(1e12);
	bs.push_back(-1e12);
	bs.push_back(1e12);
	sort(as.begin(), as.end());
	sort(bs.begin(), bs.end());
	while (Q--)
	{
		long x, ans = 1e12;
		cin >> x;
		auto yui = lower_bound(as.begin(), as.end(), x);
		auto inori = lower_bound(bs.begin(), bs.end(), x);
		//cout << *yui << ' ' << *(yui - 1) << ' ' << *inori << ' ' << *(inori - 1) << endl;
		ans = min(ans, max(*yui, *inori) - x);
		ans = min(ans, *inori - *(yui - 1) + min(x - *(yui - 1), *inori - x));
		ans = min(ans, x - min(*(yui-1), *(inori-1)));
		ans = min(ans, *yui - *(inori-1) + min(x-*(inori-1), *yui-x));
		cout << ans << endl;
	}
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 2912
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      String S = sc.next();
      
      // ニックネーム命名
      String nickname = S.substring(0,3);
      
      // 出力
      System.out.println(nickname);
    }

}

Measured memory_bytes: 35672
#include <iostream>
#include <sstream>
#include <string>


using namespace std;
int main()
{
	string str;
	getline(cin, str);
	istringstream iss(str);
	iss >> str;
	int N = stoi(str);
	iss >> str;
	int i = stoi(str);
	cout << (N + 1 - i) << endl;
	return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
grid = [input() for _ in range(H)]
blacks = [[0]*W for _ in range(H)]

grid_to_num = {"#":1, ".":0}

blacks[0][0] = grid_to_num[grid[0][0]]
for j in range(1, W):
    blacks[0][j] = blacks[0][j-1] + grid_to_num[grid[0][j]] * (1-grid_to_num[grid[0][j-1]])
for i in range(1, H):
    blacks[i][0] = blacks[i-1][0] + grid_to_num[grid[i][0]] * (1-grid_to_num[grid[i-1][0]])
    for j in range(1, W):
        blacks[i][j] = blacks[i][j-1] + grid_to_num[grid[i][j]] * (1-grid_to_num[grid[i][j-1]])
        blacks[i][j] = min(blacks[i-1][j] + grid_to_num[grid[i][j]] * (1-grid_to_num[grid[i-1][j]]), blacks[i][j])

print(blacks[H-1][W-1])

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solveA();
		// new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numH = 0;
		int numW = 0;
		int h = 0;
		int w = 0;

		try {
			scanner = new Scanner(System.in);
			numH = scanner.nextInt();
			numW = scanner.nextInt();
			h = scanner.nextInt();
			w = scanner.nextInt();

			int total = numH * numW;
			int col = h * numW;
			int row = w * (numH - h);
			System.out.println(total - col - row);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

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

int cnt=0;
bool dfs(int p,int q,vector<vector<int>> &v,vector<bool> &used){
    used[p] = 1;
    if(p==q) return true;
    bool ret = false;
    for(auto i:v[p]){
        if(!used[i]){
            ret |= dfs(i,q,v,used);
        }
    }
    return ret;
}
bool can(int p,int q,vector<vector<int>> &v){
    vector<bool> used(55);
    return dfs(p,q,v,used);
    
}




signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
 
    ll n;
    cin>>n;
    ll a[n],b[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }

    ll bit = (1LL<<51) - 1;
    bit -= 1;
    ll INF = bit;
    
    for(int i=55;i>=0;i--){
        if(!(bit & (1LL<<i))) continue;
        vector<ll> u;
        for(int j=55;j>=1;j--){
            if(i==j) continue;
            if(bit & (1LL<<j)) u.push_back(j);
        }
        vector<vector<int>> v(51);
        for(int j=0;j<=50;j++){
            for(auto k:u){
                v[j].push_back(j%k);
            }
        }
        bool pos = true;
        for(int j=0;j<n;j++){
            if(!can(a[j],b[j],v)) pos = false;
        }
        if(pos) bit -= (1LL<<i);
    }
    if(bit >= INF) bit = -1;
    cout << bit << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-2;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dp[366][365];
int dp2[366];
int x[1000], y[1000], c[1000];
void init() {
	rep(i, 366) {
		dp2[i] = 0;
		rep(j, 365) {
			dp[i][j] = 0;
		}
	}
}
int main() {
	int n;
	while (cin >> n, n) {
		init();
		vector<P> v[365];
		rep(i, n) {
			cin >> x[i] >> y[i] >> c[i];
			x[i]--; y[i]--;
			v[x[i]].push_back({ y[i],c[i] });
		}
		rep(i, 365) {
			dp2[i + 1] = max(dp2[i + 1], dp2[i]);
			rep(j, v[i].size()) {
				if (i == v[i][j].first)dp2[i + 1] = max(dp2[i + 1], dp2[i] + v[i][j].second);
				dp[i+1][v[i][j].first] = max(dp[i+1][v[i][j].first] , dp2[i] + v[i][j].second);
			}
			rep(j, v[i].size()) {
				Rep(k,j+1, v[i].size()) {
					int sum = dp2[i]+v[i][j].second + v[i][k].second;
					int to = min(v[i][j].first + 1, v[i][k].first + 1), las = max(v[i][j].first, v[i][k].first);

					if (to > las)dp2[to] = max(dp2[to], sum);
					dp[to][las] = max(dp[to][las], sum);
				}
			}
			Rep(j, i, 365) {
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
				rep(k, v[i].size()) {
					int to = min(j+1, v[i][k].first+1), las = max(j, v[i][k].first);
					if (to > las) {
						dp2[to] = max(dp2[to], dp[i][j] + v[i][k].second);
					}
					dp[to][las] = max(dp[to][las], dp[i][j] + v[i][k].second);
				}
			}
			dp2[i + 1] = max(dp2[i + 1], dp[i][i]);
		}
		cout << dp2[365] << endl;
	}
	//stop
	return 0;
}



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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

void solve() {
  long long n; scanf("%lld", &n);
  long long ans = 0;
  for (long long i = 1; i*i <= n; ++i) {
    if (n%i) continue;
    if (i>1 && n%(i-1) == n/(i-1)) ans += i-1;
    if (n/i>1 && n%(n/i-1) == n/(n/i-1)) ans += n/i-1;
  }
  printf("%lld", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


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

void solve(){

	int n ;
	cin>>n ;

	vector<int> v(n) ;

	rep(i,n){
		cin>>v[i] ;
	}

	map<int,int> mp1 ;

	for(int i=0;i<n;i=i+2) 
	{
		mp1[v[i]]++ ;
	}

	map<int,int> mp2 ;

	for(int i=1;i<n;i=i+2){
		mp2[v[i]]++ ;

	}

	pair<int,int> p1 ={0,0},p2={0,0} ;
	pair<int,int> p3 ={0,0},p4={0,0} ;


	for(auto x:mp1){
		if(x.second>p1.second){
			p1.second=x.second ;
			p1.first=x.first ;
		}
	}

	for(auto x:mp1){
		if(x.second>p2.second && p1.first!=x.first){
			p2.second=x.second ;
			p2.first=x.first ;
		}
	}

	for(auto x:mp2){
		if(x.second>p3.second){
			p3.second=x.second ;
			p3.first=x.first ;
		}
	}

	for(auto x:mp2){
		if(x.second>p4.second && p3.first!=x.first){
			p4.second=x.second ;
			p4.first=x.first ;
		}
	}

	if(p1==p2){
		p2={0,0} ;
	}

	if(p3==p4){
		p4={0,0} ;
	}
	int ans=0 ;
	/*
	cout<<p1.first<<" "<<p1.second<<"\n" ; 
	cout<<p2.first<<" "<<p2.second<<"\n" ; 
	cout<<p3.first<<" "<<p3.second<<"\n" ; 
	cout<<p4.first<<" "<<p4.second<<"\n" ; 
	*/

	if(p1.first!=p3.first){
		cout<<n-p1.second-p3.second ;
	}
	else{
		cout<<n-max(p1.second+p4.second,p2.second+p3.second) ;
	}

}


int main(){

		int y ;

		y=1 ;
		//cin>>y ;

		while(y--){
 
			solve() ;

		}

}

Measured memory_bytes: 8212
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define ll  long long
  #define ld long double
  #define pb push_back
  #define mp3 make_pair
  #define rep1(i,a,b) for(ll i=a;i<=b;i++)
  #define rep2(i,a,b) for(ll i=a;i<b;i++)
  const ll  mod=998244353;
  const ll INF=1e18;
  template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
  template<typename T> T add(T a,T b,ll m){a+=b;while(a>=0)a-=m;while(a<0)a+=m; return a;}
  template<typename T> T mul(T a,T b,ll m){return (a*1ll*b)%m;}
  int main(){
    IOS;
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll x=a*c;
    ll y=b*c;
    ll z=a*d;
    ll w=b*d;
    cout<<max(x,max(y,max(z,w)));
  }

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdio.h>
#include <set>
using namespace std;

int main(){
    int n, l;
    cin>>n>>l;
    string k[n];
    int i;
    for(i=0; i<n; i++){
        cin>>k[i];
    }

    sort(k, k+n);
    for(i=0; i<n; i++){
        cout<<k[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = Integer.parseInt(sc.next());
	int K = Integer.parseInt(sc.next());
	String str = sc.next();
	Color[] col = new Color[str.length()+3];
	int locnt = 0;
	int collen = 0;
	char prec = str.charAt(0);
	if(N == 1) {
	    if(str.equals("1"))
		System.out.println(1);
	    else {
		if(K>=1) System.out.println(1);
		else System.out.println(0);
	    }
	    return;
	}
	for(int i = 0; i<str.length(); i++) {
	    char c = str.charAt(i);
	    if(c != '0' && i == 0) {
		col[collen] = new Color('0', 0);
		collen++;
	    }
	    if(c == prec) locnt++;
	    else {
		col[collen] = new Color(prec, locnt);
		locnt = 1;
		collen++;
		//System.out.println(col[collen-1].col + " " + col[collen-1].cnt);
	    }
	    if(i == str.length()-1) {
		col[collen] = new Color(c, locnt);
		collen++;
		//System.out.println(col[collen-1].col + " " + col[collen-1].cnt);
	    }
	    prec = c;
	}

	int bcnt = 0;
	int[] ans = new int[collen+1];
	int[] b = new int[collen+1];
	locnt = 0;
	int anscnt = 1;
	for(int i = 0; i<collen; i++) {
	    locnt += col[i].cnt;
	    if(col[i].col == '1') {
		b[anscnt] = col[i].cnt;
		ans[anscnt] = locnt;
		if(anscnt>=1) ans[anscnt] += ans[anscnt-1];
		anscnt++;
		locnt = 0;
		//System.out.println("b " + b[anscnt-1] + " ans " + ans[anscnt-1]);

	    }
	    else if(i==collen-1) {
		ans[anscnt] = locnt;
		if(anscnt>=1) ans[anscnt] += ans[anscnt-1];
		anscnt++;
		//System.out.println("b " + b[anscnt-1] + " ans " + ans[anscnt-1]);
	    }
	}

	int max = 0;
	for(int l = 1; l<=K; l++) {
	for(int i = l; i<anscnt; i++) {
	    max = Math.max(ans[i]-ans[i-l] + b[i-l], max);
        }
	}
	System.out.println(max);

    }
}
class Color {
    char col;
    int cnt;
    Color(char col, int cnt) {
	this.col = col;
	this.cnt = cnt;
    }
}

Measured memory_bytes: 29356
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a[1005]={},ans=1,x,now;
  cin >> n;
  for(int i=2; i<=n; i++) {
    x=i,now=2;
    while(now<=i) {
      while(x%now==0) {
        a[now]++,x/=now;
      }
      now++;
    }
  }
  for(int i=2; i<=n; i++) {
    ans*=a[i]+1;
    ans%=MOD;
  }
  cout << ans << endl;
}

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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(),(c).end())

// repetition
// -----------------------------------------------------------------------------
#define FOR(i, a, b) for(ll i= (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
// -----------------------------------------------------------------------------
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    string S, T; cin >> S >> T;
    ll ans = 0;
    REP(i, S.length()) {
        if(S[i] != T[i]) {
            ans++;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  cin >> N;
  long long num1 = 1, num2 = 1;
  rep(i, N)
  {
    int A;
    cin >> A;
    num1 *= 3;
    if (A % 2 == 1)
      num2 *= 1;
    else
      num2 *= 2;
  }

  long long ans = num1 - num2;
  cout << ans << endl;
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    int ans = 0;
    rep(i,n) {
        int now = 0;
        for (int j = i+1; j < n; ++j) now += d[j];
        ans += now * d[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int a,b; cin>>a>>b;
  int ans=0;
  int out = 1;
  while(out<b) {
    out--;
    out += a;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

deque<int> dq;

void solve() {
    string s;
    cin >> s;
    if (s == "insert") {
        int x;
        cin >> x;
        dq.push_front(x);
    } else if (s == "delete") {
        int x;
        cin >> x;
        rep(i, sz(dq)) {
            if (dq[i] == x) {
                dq.erase(dq.begin()+i);
                break;
            }
        }
    } else if (s == "deleteFirst") {
        dq.pop_front();
    } else {
        dq.pop_back();
    }
}

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

    int n;
    cin >> n;
    while (n--) solve();
    rep(i, sz(dq)) cout << dq[i] << (i == sz(dq)-1 ? '\n' : ' ');
}



Measured memory_bytes: 7040
S = input()
K = int(input())
val = ''
A = set()
for i,s in enumerate(S):
    val = ''
    for j in range(i,min(i+5,len(S))):
        val += (S[j])
        A.add(val)
A_sort = sorted(list(A))
print(A_sort[K-1])

Measured memory_bytes: 70152
#include<iostream>

using namespace std;

typedef long long ll;

namespace comb {
	ll fact[500001];
	ll fact_inv[500001];
	const ll MOD = 1000000007;

	ll modpow(ll a, ll b) {
		ll base = 1, kakeru = a;
		while (b > 0) {
			if (b & 1)base *= kakeru, base %= MOD;
			kakeru *= kakeru, kakeru %= MOD;
			b >>= 1;
		}
		return base;
	}

	void setup() {
		fact[0] = 1, fact[1] = 1;
		for (int i = 2; i <= 500000; i++) {
			fact[i] = (fact[i - 1] * i) % MOD;
		}

		fact_inv[500000] = modpow(fact[500000], MOD - 2);

		for (int i = 499999; i >= 0; i--) {
			fact_inv[i] = fact_inv[i + 1] * (i + 1);
			fact_inv[i] %= MOD;
		}

	}

	ll combination(int a, int b) {
		if (a - b < 0)return 0;
		ll ret = fact[a];
		ret *= fact_inv[b], ret %= MOD;
		ret *= fact_inv[a - b], ret %= MOD;
		return ret;
	}

	ll permutation(int a, int b) {
		if (a - b < 0)return 0;
		ll ret = fact[a];
		ret *= fact_inv[a - b], ret %= MOD;
		return ret;
	}

	ll homogeneous(int a, int b) {
		return combination(a + b - 1, b);
	}

}

int main() {
	ll H, W, A, B;
	cin >> H >> W >> A >> B;
	ll ans = 0;
	comb::setup();
	for (ll i = 1; i <= H - A; i++) {
		ans += (comb::combination(B - 1 + i - 1, i - 1) * comb::combination(W - B - 1 + H - i, H - i) % comb::MOD);
		ans %= comb::MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    int N,X;
    int L;
    cin>>N>>X;
    int d=0,num=1;
    rep(i,N){
        cin>>L;
        d+=L;
        if(X<d){
            cout<<num<<endl;
            return 0;
        }
        num++;
    }
    cout<<num<<endl;
    return 0;
}

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

#define debug(n) cerr << #n << ':' << n << endl;
#define rep(i,n) for(int i = 0; i < (n); ++i)

using namespace std;

using  ll = long long;

template<class T,class U>
using umap = unordered_map<T,U>;

template<class T>
using uset = unordered_set<T>;

template<class T>
inline bool change_max(T&a, const T&b){
  if(b > a){
    a = b;
    return true;
  }
  return false;
}

template<class T>
inline bool change_min(T&a, const T&b){
  if(a > b){
    a = b;
    return true;
  }
  return false;
}


int main(){
  int n; cin >> n;
  vector<deque<int>> a(n);
  for(auto&dq:a){
    rep(i,n-1){
      int x; cin >> x; x--;
      dq.push_back(x);
    }
  }

  vector<pair<int, int>> q;
  auto check = [&](int i){		 
		 if(a[i].empty())return;
		 int j = a[i].front();
		 if(a[j].front() != i)return;
		 if(i > j)swap(i, j);
		 q.push_back({i,j});
	       };

  rep(i, n){
    check(i);
  }
  int ans = 0;
  bitset<1000> fin;
  while(!q.empty()){
    ans++;
    sort(q.begin(), q.end());
    q.erase(unique(q.begin(), q.end()), q.end());
    for(auto p:q){
      int i,j;tie(i,j) = p;
      a[i].pop_front(); a[j].pop_front();
      if(a[i].empty())fin[i] = 1;
      if(a[j].empty())fin[j] = 1;
    }
    q.clear();
    rep(i, n)check(i);
  }
  if(fin.count() < n) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6784
def readinput():
    n=int(input())
    return n

def main(n):
    if 1<=n and n<=9:
        return n
    elif 10<=n and n<=99:
        return 9
    elif 100<=n and n<=999:
        return 9+(n-99)
    elif 1000<=n and n<=9999:
        return 9+900
    elif 10000<=n and n<=99999:
        return 9+900+(n-9999)
    elif 100000==n:
        return 9+900+90000
    return 0

if __name__=='__main__':
    n=readinput()
    ans=main(n)
    print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>

int compare_int(const void *a, const void *b) {
  return *(int*)a - *(int*)b;
}

int main() {
  int n, k;
  int a[100010];
  int i;
  int flag = 1;
  scanf("%d %d", &n, &k);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == k) {
      flag += 100;
    }
  }
  qsort(a, n, sizeof(int), compare_int);
  int min = 1000000010;
  for (i = 0; i < n-1; i++) {
    if (min >= a[i+1] - a[i] && a[i+1] != a[i]) {
      min = a[i+1] - a[i];
    }
  }
  int min_a = a[0];
  /*printf("%d\n", min_a);*/
  int max_a = a[n-1];
  /*printf("%d\n", max_a);*/
  if (max_a < k) {
    flag -= 100;
  }
  if ((k - min_a) % min == 0) {
    flag += 10;
  } else {
    flag -= 10;
  }
  if (flag > 0) {
    printf("POSSIBLE\n");
  } else {
    printf("IMPOSSIBLE\n");
  }
  return 0;
}


Measured memory_bytes: 892
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;
    vector<int> vec(N);
    for(int i=0; i<N; i++) {
        cin >> vec[i];
    }

    map<int, int> pre, suf;
    vector<int> ans;
    for(int i=0; i<N; i++) {
        int lidx = i, ridx = N - 1 - i;
        pre[ vec[lidx] ]++;
        suf[ vec[ridx] ]++;
        if(pre == suf) {
            ans.push_back(i+1);
        }
    }

    for(size_t i=0; i<ans.size(); i++) {
        printf("%lld%c", ans[i], (i+1==ans.size() ? '\n' : ' '));
    }
    return 0;
}


Measured memory_bytes: 10028
///                         .
///                     /   ))     |\         )               ).
///               c++. (\  ( `.    / )  (\   ( `.     ).     ( (
///               | |   ))  ) )   ( (   `.`.  ) )    ( (      ) )
///               | |  ( ( / _..----.._  ) | ( ( _..----.._  ( (
/// ,-.           | |---) V.'-------.. `-. )-/.-' ..------ `--) \._
/// | /===========| |  (   |      ) ( ``-.`\/'.-''           (   ) ``-._
/// | | / / / / / | |--------------------->  <-------------------------_>=-
/// | \===========| |                 ..-'./\.`-..                _,,-'
/// `-'           | |-------._------''_.-'----`-._``------_.-----'
///               | |         ``----''            ``----''
///               | |
///               c++`

///██╗ ██████╗ ██╗    ██████╗  ██████╗  ██████╗   ██████╗
///██║██╔═══██╗██║    ╚════██╗██╔═████╗ ╚════██╗ ██╔═████╗
///██║██║   ██║██║     █████╔╝██║██╔██║  █████╔╝ ██║██╔██║
///██║██║   ██║██║    ██╔═══╝ ████╔╝██║ ██╔═══╝  ████╔╝██║
///██║╚██████╔╝██║    ███████╗╚██████╔╝ ███████╗ ╚██████╔╝
///╚═╝ ╚═════╝ ╚═╝    ╚══════╝ ╚═════╝  ╚══════╝  ╚═════╝

#include<bits/stdc++.h>
#include<fstream>
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define mlojins cout.tie(NULL);
#define bzbz cin.tie(NULL);
#define CODER ios_base::sync_with_stdio(0)  ;
#define p_b pop_back
#define p_f pop_front
#define Qulukh
#define quluq return 0;
#define Zohiri_dzd
#define Mekh
#define Black_star
using namespace std ;

const ll N = 1e6 + 1;

map <ll , ll> mp , pm ;
map <char , ll> hs ;
deque <ll> v , vc , ve ,vv , vd ;
deque <char> p , pe ;
deque <string> ts , ss , st ;
deque <double> sd , ds ;
ll a , b , c , d , e , f , cnt , ans , r , n , l , x , y ;
ld q , t , cnt1 , cnt2 ;
string g , h , w , o , m , s ;
char z , u ;
bool re , rt ;
vector<pair < ll , string > > pr , rp , pp ;
map < pair < char , char > , ll > aw , wa ;

int main ()
{
    bzbz
    mlojins
    Qulukh
    Mekh
    CODER
    Zohiri_dzd
    Black_star
    ///freopen("input.txt" , "r" , stdin );
    ///freopen("output.txt", "w" , stdout );
    ///Author of the greatest code :: Murtazoev Alijon
    cin >> g ;
    if (g[2] == g[3] and g[4] == g[5])
        cout << "Yes" << endl ;
    else
        cout << "No" << endl ;
}
///Mmavl studios
///Eco students


Measured memory_bytes: 256