akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

ll H, W;
char mp[22][22];

ll di(ll sy, ll sx, ll gy, ll gx){
  ll dist[H][W];
  rep(i, H)rep(j, W) dist[i][j] = INFL;
  dist[sy][sx] = 0;
  queue<pair<ll, ll>> que;
  que.push({sy, sx});
  while(!que.empty()){
    pair<ll, ll> now = que.front();
    que.pop();
    rep(i, 4){
      ll ny = now.f + dy[i];
      ll nx = now.s + dx[i];
      if(ny < 0 || ny >= H || nx < 0 || nx >= W || mp[ny][nx] == '#') continue;
      if(dist[ny][nx] > dist[now.f][now.s] + 1){
        dist[ny][nx] = dist[now.f][now.s] + 1;
        que.push({ny, nx});
      }
    }
  }
  return dist[gy][gx];
}

void solve(){
  cin >> H >> W;
  rep(i, H)rep(j, W) cin >> mp[i][j];
  ll ans = 0;
  rep(sy, H)rep(sx, W)rep(gy, H)rep(gx, W){
    if(mp[sy][sx] == '#' || mp[gy][gx] == '#') continue;
    ans = max(ans, di(sy, sx, gy, gx));
  }
  cout << ans << endl;
}


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


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
int a[10];
for(int i=0;i<10;i++){scanf("%d",&a[i]);}
sort(a,a+10,greater<int>());
printf("%d\n%d\n%d\n",a[0],a[1],a[2]);
}

Measured memory_bytes: 0
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int K, X;
	cin >> K >> X;
	if (500 * K >= X) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}


Measured memory_bytes: 256
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


if __name__ == "__main__":
    all_primes = primes(60000)
    while True:
        try:
            n = int(input())
            ps = primes(n)
            x = ps[-1] if ps[-1] != n else ps[-2]
            y = all_primes[len(ps)]
            print("{} {}".format(x, y))
        except:
            break



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

namespace 課題1
{
    class Program
    {
        static void Main(string[] args)
		{
			
			string str = Console.ReadLine();

			string[] strArray = str.Split(" ");
			int[] intArray = Array.ConvertAll(strArray, int.Parse);

			if(intArray[0]<=intArray[1]*intArray[2])
			{
				Console.WriteLine("Yes");
			}
            else
            {
				Console.WriteLine("No");
			}

			
		}




	}

	
}


Measured memory_bytes: 27536
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

using lint = long long;
using ldouble = long double;

inline int sq(int a) { return a * a; }

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        int M, N;
        cin >> M >> N;
        int sqmn = sq(M) + sq(N);

        int num = 0;
        for (int p = -150; p <= 150; ++p) {
            for (int q = -150; q <= 150; ++q) {
                int sqpq = sq(p) + sq(q);
                if (sqpq == 0 || sqmn % sqpq != 0) continue;

                if ((M * p + N * q) % sqpq == 0 &&
                    (N * p - M * q) % sqpq == 0) {
                    ++num;
                }
            }
        }
        cout << (num == 8 ? 'P' : 'C') << endl;
    }
    return 0;
}



Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main() {
	int A, B, T;
	cin >> A >> B >> T;
	int i = 1;
	int ans = 0;
	while (i < T + 0.5) {
		if (i % A == 0) {
			ans+=B;
		}
		i++;
	}
	cout << ans;
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	//
	
	int n;
	vector<int> a;
	cin >> n;
	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		a.push_back(t);
	}

	long long mi = INF;
	for(int i=-200; i<=200; i++){
		long long sum = 0;
		for(int j=0; j<a.size(); j++){
			sum += (i - a[j])*(i - a[j]);
		}
		if(sum < mi){
			mi = sum;
		}
	}

	cout << mi << endl;
	

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
using ll = long long;
using ull = unsigned long long;

vector<int> v;

int main() {
    FAST;

    int n, a, b;
    string s;
    cin >> n >> a >> b >> s;

    int ab = a + b;

    int now = 0, bcnt = 0;
    rep(i, size(s)){
        if(s[i] == 'a'){
            if(now < ab){
                println("Yes");
                now++;
            }else{
                println("No");
            }
        }
        else if(s[i] == 'b'){
            if(now < ab && bcnt < b){
                now++;
                bcnt++;
                println("Yes");
            }else{
                println("No");
            }
        }
        else{
            println("No");
        }
    }
}

Measured memory_bytes: 848
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <utility>
using namespace std;
 
using P = pair<int, int>;   // (頂点, 路線) または (コスト, 頂点)
 
struct Edge {
    int to, cost;
};
 
const int MAXN = 100010;
const int MAXM = 200010;
 
const int INF = (1 << 28);
 
vector<Edge> graph[MAXN + 2 * MAXM];
int cost[MAXN + 2 * MAXM];
 
void dijkstra() {
 
    for (int i = 0; i < MAXN + 2 * MAXM; i++) cost[i] = INF;
 
    priority_queue<P, vector<P>, greater<P>> que;
    cost[0] = 0;
    que.push(make_pair(cost[0], 0));
    while (!que.empty()) {
        auto q = que.top(); que.pop();
 
        int c = q.first,
            v = q.second;
        
        if (c > cost[v]) continue;
 
        for (Edge& e : graph[v]) {
            if (cost[e.to] > c + e.cost) {
                cost[e.to] = c + e.cost;
                que.push(make_pair(cost[e.to], e.to));
            }
        }
    }
}
 
int main() {
    int N, M;
    cin >> N >> M;
 
    int id = N;
    map<P, int> p2id;
    // グラフの構築
    for (int i = 0; i < M; i++) {
        int p, q, c;
        cin >> p >> q >> c;
 
        p--; q--;
 
        P pc = make_pair(p, c),
          qc = make_pair(q, c);
 
        if (p2id.count(pc) == 0) {
            graph[p].push_back({id, 1});
            graph[id].push_back({p, 0});
 
            p2id[pc] = id++;
        }
 
        if (p2id.count(qc) == 0) {
            graph[q].push_back({id, 1});
            graph[id].push_back({q, 0});
 
            p2id[qc] = id++;
        }
 
        int idp = p2id[pc],
            idq = p2id[qc];
        graph[idp].push_back({idq, 0});
        graph[idq].push_back({idp, 0});
    }
 
    dijkstra();
 
    if (cost[N - 1] >= INF) cout << -1 << endl;
    else cout << cost[N - 1] << endl;
 
    return 0;
}

Measured memory_bytes: 59128
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<cmath>
#include <string>
#include<map> 
#include<deque>  
#include<vector>
#include<bitset>
#include<string>  
#include<cstring> 
#include<stack>  
#include<set>
#include<functional>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<long long,long long> pll;
char ch[9];
int ans;
int main()
{
	scanf("%s",ch);
	int a=ch[0]-'0',b=ch[1]-'0',c=ch[2]-'0',d=ch[3]-'0';
	for(int i=0;i<2;i++){
		if(i)ans=a+b;
		else ans=a-b;
		for(int j=0;j<2;j++){
			if(j)ans+=c;
			else ans-=c;
			for(int k=0;k<2;k++){
				if(k)ans+=d;
				else ans-=d;
				if(ans==7){printf("%d%c%d%c%d%c%d=7\n",a,i?'+':'-',b,j?'+':'-',c,k?'+':'-',d);return 0;
				}
				if(k)ans-=d;
				else ans+=d;
			}
			if(j)ans-=c;
			else ans+=c;
		}
		if(i)ans=a-b;
		else ans=a+b;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
vector<int> res;
void divisor(int n) {
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			res.push_back(i);
			if (i != n / i) res.push_back(n / i);
		}
	}
	if (n != 1) { res.push_back(n); }
}
int test[12345678];
signed main() {
	int n, k, cnt = 0, ans = 1; cin >> n >> k;
	vector<int>kari;
	for (int h = 0; h < n; h++) {
		cin >> test[h]; cnt += test[h];
	}
	divisor(cnt);
	for (int h = 0; h < res.size(); h++) {
		for (int i = 0; i < n; i++) {
			if (test[i] % res[h] != 0) {
				kari.push_back(test[i] % res[h]);
			}
		}
		sort(kari.begin(), kari.end()); 
		int a = 0, b = 0, ok = 0;
		for (int i = 0; i < kari.size(); i++) {
			a += res[h] - kari[i];
		}
		for (int i = 0; i < kari.size(); i++) {
			a -= res[h] - kari[i]; b += kari[i];
			if (a == b) { ok = a; }
		}
		if (ok <= k) { ans = max(ans, res[h]); }
		kari.clear();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
s=input()
n=len(s)
count=0
a=(n-1)//2
b=(n+3)//2
for i in range(n//2):
  if s[i]!=s[-abs(i+1)]:
    count+=1
    
for i in range(a//2):
  c=ord(s[i])
  d=ord(s[(a-1-i)])
  if c!=d:
    count+=1

for i in range((n-b+1)//2):
  c=ord(s[-(i+1)])
  d=ord(s[b-1+i])
  if c!=d:
    count+=1

if count!=0:
  print('No')
else:
  print('Yes')

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

int main() {
  int n;
  cin >> n;
  int sum = 0, ans1 = 0, ans2 = 0;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
    sum += a[i];
  }
  int avg1 = sum / n;
  int avg2 = avg1 + 1;
  rep(i,n){
    ans1 += pow(abs(a[i] - avg1), 2);
    ans2 += pow(abs(a[i] - avg2), 2);
  }
  cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,h;
  cin >> n >> h;
  vector<int> a(n), b(n);
  REP(i,n) cin >> a[i] >> b[i];
  sort(ALL(a), greater<int>());
  sort(ALL(b), greater<int>());
  int cnt = 0;
  REP(i,n){
    if(b[i]>= a[0]){
      h -= b[i];
      cnt++;
    }
    if(h<=0) break;
  }
  if(h>0) cnt += h/a[0] + (h%a[0]==0 ? 0 : 1);
  cout << cnt << endl;
  return 0;
}


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


int main(){
    int n;
    cin>>n;
    vector<int> b;
    rep(i,n){
        int bb;
        cin>>bb;
        b.push_back(bb);
    }

    vector<int> ans;
    vector<int> c;
    rep(i,n){
        int id=-1;
        for(int j=b.size()-1;j>=0;j--){
            if(j+1==b[j]){
                id=j;
                ans.push_back(b[j]);
                break;
            }
        }
        if(id==-1){
            cout<<-1<<endl;
            return 0;
        }
        c.clear();
        rep(j,b.size()){
            if(j==id) continue;
            c.push_back(b[j]);
        }
        b.clear();
        rep(j,c.size()){
            b.push_back(c[j]);
        }
    }

    reverse(all(ans));
    rep(i,n) cout<<ans[i]<<endl;
}


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        string S = cin.next();
        int black=0;
        int white=0;
        for(int i=0;i<N;i++)
        {
          if(S[i]=='.')white++;
        }
        int min=white;
        for(int i=0;i<N;i++)
        {
          if(S[i]=='#')black++;
          else white--;
          if(black+white<min)min=black+white;
        }
      
        if(black==N)min=0;
        Console.WriteLine(min);
    }


}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }
    
    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13216
S=input()
A=[int(s) for s in S]
for i in range(2):
    for j in range(2):
        for k in range(2):
            if A[0]+A[1]*(-1)**i+A[2]*(-1)**j+A[3]*(-1)**k==7:
                temp=[i,j,k]
                break
ans=S[0]
for l in range(3):
    if temp[l]==0:
        ans+="+"
    else:
        ans+="-"
    ans+=S[l+1]
print(ans+"=7")

Measured memory_bytes: 3064
# https://atcoder.jp/contests/abc079/tasks/abc079_c

num = list(input())

for i in range(2 ** 3):
    t = int(num[0])
    op = []
    for j in range(3):
        if (i >> j) & 1:
            t += int(num[j + 1])
            op.append('+')
        else:
            t -= int(num[j + 1])
            op.append('-')
    op.append('=')
    if t == 7:
        ans = []
        for i, j in zip(num, op):
            ans.append(i)
            ans.append(j)
        print(''.join(ans) + '7')
        break

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000009
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

vector<ll> par(100000);
vector<ll> rnk(100000);

void init(ll n){
  rep(i, n){
    par.at(i) = i;
    rnk.at(i) = 0;
  }
}

ll root(ll x){
  if(par.at(x) == x){
    return x;
  }
  else{
    par.at(x) = root(par.at(x));
    return par.at(x);
  }
}

bool same(ll x, ll y){
  if(root(x) == root(y)){
    return true;
  }
  else{
    return false;
  }
}

void unite(ll x, ll y){
  x = root(x);
  y = root(y);
  if(x == y){
    return;
  }
  if(rnk.at(x) < rnk.at(y)){
    par.at(x) = y;
  }
  else{
    par.at(y) = x;
    if(rnk.at(x) == rnk.at(y)){
      rnk.at(x)++;
    }
  }
}

int main(){
  ll N, M;
  cin >> N >> M;
  init(N);
  vector<ll> p(N);
  rep(i, N){
    cin >> p.at(i);
    p.at(i)--;
  }
  vector<ll> x(M), y(M);
  rep(i, M){
    cin >> x.at(i) >> y.at(i);
    x.at(i)--;
    y.at(i)--;
    unite(x.at(i), y.at(i));
  }
  ll ans = 0;
  rep(i, N){
    if(same(i, p.at(i))){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4224
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int r[22][100001]={};//r[0][i]は番兵
int main(){
	int N,Q;
	ll L,x[100001];
	scan(N);
	rep(i,N) scan(x[i]);
	scan(L>>Q);
	rep(i,N){
		r[1][i]=upper_bound(x,x+N,x[i]+L)-x-1;
	}
	rep1(k,20){
		rep(i,N){
			r[k+1][i]=r[k][r[k][i]];
		}
	}
	rep(i,Q){
		int a,b;
		scan(a>>b);
		a--; b--;
		if(a>b) swap(a,b);
		int nowans=0;
		while(1){
			int daymin=0,daymax=20;
			while(daymin+1<daymax){
				int daymid=(daymin+daymax)/2+(daymin+daymax)%2;
				//printf("a:%d b:%d min:%d max:%d mid:%d r:%d\n",a,b,daymin,daymax,daymid,r[daymid][a]);
				if(r[daymid][a]<b) daymin=daymid;
				else daymax=daymid;

			}
			//kaigyo;
			if(daymin==0) break;
			else{
				nowans+=(1<<(daymin-1));
				a=r[daymin][a];
			}
		}
		prin(nowans+1);
	}
	return 0;
}


Measured memory_bytes: 9856
#include<iostream>
using namespace std;
int main(){
	double a,b;cin>>a>>b;
	if(a<=5) cout<<"0"<<endl;//<<"Takahashi is "<<a<<" years old, and he can ride the Ferris wheel for free.";
	else if(a>5&&a<=12) cout<<b/2<<endl;//<<"Takahashi is "<<a<<" years old, and the cost of the Ferris wheel is the half of "<<b<<" yen, that is, "<<b/2<<" yen.";
	else cout<<b<<endl;//<<"Takahashi is "<<a<<" years old now, and the cost of the Ferris wheel is "<<b<<" yen.";
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define SORT(x) sort((x).begin(),(x).end(),greater<int>())
using LL=long long;
using ULL=unsigned long long;
using PII=pair<int,int>;
const int INF = numeric_limits<int>::max();
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    int N;
    cin >> N;
    vector<int> vc( N + 1 );
    REP2( i, 1, N + 1 )
    {
        cin >> vc[ i ];
    }
    int cnt{};
    REP2( i, 1, N + 1 )
    {
        if( i == vc[ i ] )
        {
            swap( vc[ i ], vc[ i + 1 ] );
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll N,M,L,K,A,H;
vector<vector<ll>> dp;
vector<bool> r;

void wf(){
    rep(k,N){
        rep(i,N){
            rep(j,N)dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j]);
        }
    }
}

struct edge{
    int to,cost;
    edge(int _to,int _cost):to(_to),cost(_cost){}
};

vector<edge> G[100];
vector<ll> mincost;

void solve(){
    typedef pair<P,ll> PP;
    queue<PP> que;
    que.push(PP(P(0,A),M));
    mincost[A] = 0;
    while(que.size()){
        PP p = que.front();
        que.pop();
        ll v = p.first.second;
        ll cost = p.first.first;
        ll hp = p.second;
        // cout << "!!" << v << " " << cost << " " << hp << endl;
        if(mincost[v] < cost)continue;
        if(v == H)continue;
        rep(i,G[v].size()){
            edge e = G[v][i];
            ll t = e.cost;
            ll to = e.to;
            ll ncost = cost + t;
            ll nhp = hp;
            if(t > M)continue;
            if(hp < t){
                ncost += (t-hp);
                nhp = 0;
            }
            else nhp -= t;
            if(ncost < mincost[to]){
                que.push(PP(P(ncost,to),nhp));
                mincost[to] = ncost;
            }
        }
    }
}

int main(){
    while(cin >> N >> M >> L >> K >> A >> H && N){
        dp.clear();
        r.clear();
        dp.resize(100);
        rep(i,100)dp[i].resize(100,INF);
        rep(i,100)dp[i][i] = 0;
        rep(i,100)G[i].clear();
        mincost.clear();
        mincost.resize(N,INF);
        r.resize(100,false);
        rep(i,L){
            ll num;
            cin >> num;
            r[num] = 1;
        }
        rep(i,K){
            ll x,y,c;
            cin >> x >> y >> c;
            dp[x][y] = c;
            dp[y][x] = c;
        }
        wf();
        r[A] = 1;
        r[H] = 1;
        rep(i,100){
            FOR(j,i+1,100){
                if(r[i] && r[j]){
                    if(dp[i][j] == INF)continue;
                    // cout << "!" << i << " " << j << " " << dp[i][j] << endl;
                    G[i].push_back(edge(j,dp[i][j]));
                    G[j].push_back(edge(i,dp[i][j]));
                }
            }
        }
        r[A] = 0;
        r[H] = 0;
        solve();
        if(mincost[H] == INF)cout << "Help!" << endl;
        else cout << mincost[H] << endl;
    }
}


Measured memory_bytes: 3124
import java.util.*;
import java.io.*;
public class Main {
	Scanner sc;
	PrintWriter pw;
	public static void main(String... args) {
		Main m = new Main();
		m.solve();
		m.close();
	}
	public Main() {
		sc = new Scanner(System.in);
		pw = new PrintWriter(System.out);
	}
	private void close() {
		pw.flush();
		pw.close();
	}
	private void solve() {
		int n = sc.nextInt();
		int m = 100000;
		for(int i = 0; i < n; i++) {
			m*=1.05f;
			int x = m%1000;
			m = x != 0 ? 1000-x+m : m;
		}
		pw.println(m);
	}
}

Measured memory_bytes: 11000
import sys
n,y = map(lambda x:int(x),input().split())

for i in range(n+1) :
    for j in range(n+1) :
        if n - (i + j) < 0 :
            continue
        nokori = y - i*10000 - j*5000
        if nokori % 1000 == 0:
            k = int(nokori / 1000)
            if n == i + j + k :
                print(i,j,k)
                sys.exit()
print(-1,-1,-1)


Measured memory_bytes: 3188
import java.util.Scanner;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int a,b;
        while(true){
            a=sc.nextInt();
            b=sc.nextInt();
            if(a==0&&b==0){break;}
            System.out.printf("%d %d\n",Math.min(a,b),Math.max(a,b));
        }
    }
}


Measured memory_bytes: 40432
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,a,b) for(ll i=(a);i<(b);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

//verified POJ3680
#define MAX_V (400)
struct edge { int to, cap, cost,rev; };

vector<edge> G[MAX_V];

// from??????to??????????????????cap????????????cost????????????????????????????????????
void add_edge(int from, int to, int cap, int cost) {
    G[from].push_back((edge){to, cap, cost, (int)G[to].size()});
    G[to].push_back((edge){from, 0, -cost, (int)G[from].size() - 1});
}

//?????????????????????????????????????????´????????????
void shortest_path(int s,vector<int> &d){
    int v = d.size();
    rep(i,d.size())d[i]=INF;
    d[s]=0;
    rep(loop,v){
        rep(i,v){
            for(auto e:G[i]){
                if(e.cap && d[i]!=INF && d[e.to] > d[i]+e.cost)
                    d[e.to] = d[i]+e.cost;
            }
        }
    }
}


// s??????t????????????f???????°??????¨???????±???????
// ??????????????´??????-1?????????
int min_cost_flow(int s, int t, int f) {
    vector<int> h(MAX_V);	//??????????????£???
    vector<int> dist(MAX_V);// ???????????¢
    int prevv[MAX_V], preve[MAX_V];// ??´??????????????¨???
    
    int res = 0;
    shortest_path(s, h);
    
    while (f > 0) {
        // ?????????????????????????????¨??????h?????´??°??????
        priority_queue<pii, vector<pii>, greater<pii> > que;
        rep(i,dist.size())dist[i]=INF;
        dist[s] = 0;
        que.push(pii(0, s));
        while (!que.empty()) {
            pii p = que.top(); que.pop();
            int v = p.second;
            if (dist[v] < p.first) continue;
            for (int i = 0; i < G[v].size(); i++) {
                edge &e = G[v][i];
                if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
                    dist[e.to] = dist[v] + e.cost + h[v] - h[e.to]; prevv[e.to] = v;
                    preve[e.to] = i;
                    que.push(pii(dist[e.to], e.to));
                }
            }
        }
        if (dist[t] == INF) return -INF;	//????????\???????????????
        
        for (int v = 0; v < h.size(); v++) h[v] += dist[v];
        
        
        // s-t????????????????????£??????????????????
        int d = f;
        for (int v = t; v != s; v = prevv[v]) {
            d = min(d, G[prevv[v]][preve[v]].cap);
        }
        f -= d;
        res += d * h[t];
        for (int v = t; v != s; v = prevv[v]) {
            edge &e = G[prevv[v]][preve[v]]; e.cap -= d;
            G[v][e.rev].cap += d;
        }
    }
    return res;
}


int main(){
    int n;
    while(cin>>n&&n){
        rep(i,MAX_V)G[i].clear();
        rep(i,n){
            int s,t,c;
            cin>>s>>t>>c;
            s--,t;
            add_edge(s, t, 1, -c);
        }
        int S = 366;
        int T = S+1;
        add_edge(S, 0, INF, 0);
        add_edge(365, T, INF, 0);
        rep(i,365)add_edge(i, i+1, INF, 0);
        
        cout<<-1*min_cost_flow(S, T, 2)<<endl;
    }
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int main() {
	int K, X;
	cin >> K >> X;

	int L = X - (K - 1);
	int R = X + (K - 1);

	for (int i = L; i <= R; i++) {
		if (i!=L) cout << ' ';
		cout << i;
	}
	cout << endl;
}

Measured memory_bytes: 3632
N, M = map(int, input().split())

ans = 0
if N >= 3 and M >= 3:
    ans = max(N - 2, 1) * max(M - 2, 1)
elif N == 1 and M >= 3:
    ans = M - 2
elif N >= 3 and M == 1:
    ans = N - 2
elif N == 1 and M == 1:
    ans = 1
else:
    ans = 0

print(ans)


Measured memory_bytes: 3060
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long n, std::vector<long long> a){
    int cnt = 1;
    for(auto& x : a){
        if(x == cnt)
            ++cnt;
    }
    if(cnt == 1){
        cout << -1 << endl;
        return ;
    }
    cout << n - cnt + 1 << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
 
#define MAX_LEN (80)
 
char num1[1000000];
char num2[1000000];
 
void zerofill(char *str, int size)
{
    char buf[83];
    memset(buf, '0', sizeof(buf));
    buf[82] = 0;
    strcpy(buf + (MAX_LEN - size + 1), str);
    strcpy(str, buf);
}
 
int main(void)
{
    int n, carry;
    int i, j, len;
     
    scanf("%d", &n);
     
    for (i = 0; i < n; i++){
        memset(num1, 0, sizeof(num1));
        memset(num2, 0, sizeof(num2));
         
        scanf("%81s %81s", num1, num2);
        if (strlen(num1) > MAX_LEN || strlen(num2) > MAX_LEN){
            printf("overflow\n");
            continue;
        }
         
        zerofill(num1, strlen(num1));
        zerofill(num2, strlen(num2));
         
        carry = 0;
        for (j = MAX_LEN; j >= 0; j--){
            int sum = (num1[j] - '0') + (num2[j] - '0') + carry;
            num1[j] = (sum % 10) + '0';
            carry = sum / 10;
        }
         
        for (j = 0; j < MAX_LEN; j++){
            if (num1[j] != '0'){
                break;
            }
        }
        if (j == 0){
            printf("overflow\n");
        }
        else {
            printf("%s\n", num1 + j);
        }
    }
     
    return (0);
}

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

int main() {
	int a, b;
	cin >> a >> b;
	int ans;
	if (a + b < 10) {
		ans = a + b;
	} else {
		cout << "error" << endl;
		return 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int main()
{
   int n;
   cin>>n;
  int ans = 0;
  vector<ll>a(n),b(n),c(n+1);
      for(int i=0;i<n;i++)cin>>a[i];
      for(int i=0;i<n;i++){cin>>b[i];ans+=b[i];}
      for(int i=1;i<=n-1;i++)cin>>c[i];
      for(int i=0;i<n-1;i++)
      {
        if(a[i+1]-a[i] == 1)ans+=c[a[i]];
      }
  cout<<ans;
  
}

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

int cmp(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}
int main(void)
{
    int i;
    int n, m;
    int *xs;
    int sum = 0;
    
    scanf("%d %d", &n, &m);
    
    xs = malloc(m * sizeof(int));
    
    for(i = 0; i < m; ++i){
        scanf("%d", &xs[i]);
    }
  
    qsort(xs, m, sizeof(int), cmp);
    
    for(i = m-1; i > 0; --i){
        xs[i] -= xs[i-1];  //1..m-1: distances
    }
    
    qsort(&xs[1], m-1, sizeof(int), cmp);
  
    for(i = 1; i <= m-n; ++i)
        sum += xs[i]; 
  
    printf("%d", sum);
  
    return 0;
}

Measured memory_bytes: 924
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,i,q;
    cin>>n;
    double a[n],s=0;
    for(i=0;i<n;i++)
        cin>>a[i];
   sort(a,a+n);
   for(i=1;i<n;i++){
       a[i]=(a[i]+a[i-1])/2;
   }cout.precision(9);
   cout<<fixed<<a[n-1];
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;

lol N,W,w[105],v[105];
lol dp[105][100005];

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

    cin>>N>>W;
    reps(i,N){
	cin>>w[i]>>v[i];
    }

    memset(dp,LINF,sizeof(dp));
    dp[0][0]=0;
    reps(i,N){
	rep(j,100001){
	    if(j>=v[i]){
		dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
	    }
	    else{
		dp[i][j]=dp[i-1][j];
	    }
	}
    }
    
    int ans=0;
    for(int j=100000;j>=0;j--){
	if(dp[N][j]<=W){
	    ans=j;
	    break;
	}
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 82304
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    a = f()
    a = sorted(a)
    print(a[n-1] - a[0])
    

solve()


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

struct Trie{
	int num;
	bool flag;
	Trie *next[26];
	Trie(){
		num = 0;
		flag = false;
		fill(next,next + 26,(Trie*)0);
	}
};

void add(string s,Trie *t){
	for(int i = 0;i < s.length();i++){
		int c = s[i] - 'a';
		if(!t->next[c]) t->next[c] = new Trie;
		t = t->next[c];
		t->num++;
	}
	t->flag = true;
}

int cnt[26][26][100000],ad[100000];

void calc(string s,int ind,int c,Trie *t){
	for(int i = 0;i < s.length();i++){
		int d = s[i] - 'a';
		if(t->next[c]) cnt[c][d][ind] += t->next[c]->num;
		if(!c && t->flag) ad[ind]++;
		t = t->next[d];
	}
}

signed main(){
	ios::sync_with_stdio(false);
	int n,q;
	string s[100000];
	Trie *trie = new Trie;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> s[i];
		add(s[i],trie);
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < 26;j++) calc(s[i],i,j,trie);
	}
	cin >> q;
	for(int i = 0;i < q;i++){
		int a,ans = 1;
		string pr;
		cin >> a >> pr; a--;
		for(int j = 0;j < 26;j++){
			for(int k = j + 1;k < 26;k++) ans += cnt[pr[j] - 'a'][pr[k] - 'a'][a];
		}
		cout << ans + ad[a] << endl;
	}
	return 0;
}

Measured memory_bytes: 351488
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n;cin>>n;
  	vector<int> p(n);
  	for (int i=0;i<n;i++){
    	cin>>p.at(i);
    }
  	sort(p.begin(),p.end());
    int ans=0;
    for(int i=0;i<n-1;i++){
    	ans+=p.at(i);
    }
         ans+=p.at(n-1)/2;
         cout<<ans<<endl;
}


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

  long ans = 1e8;
  for (int i=-100; i<=100; i++) {
    long cost = 0;
    for (int j=0; j<n; j++) {
      cost += (a[j] - i) * (a[j] - i);
    }
    ans = min(cost, ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
mi = n
while mi >= n and mi > 0:
    if n < mi:
        mi = n
    # n = abs(n - k)
    # print(mi)
    if int(mi/k) > 1:
        mi = abs(mi - (k*int((mi/k))))
        n = mi
        continue
    n = abs(n - k)

print(mi)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    int n,m;
    cin >> n >> m;
    string a[n],b[m];
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];

    if(n == m){
        bool ans = true;
        for(int i = 0; i < n; i++){
            if(a[i] != b[i]) ans = false;
        }
        if(ans){
            cout << "Yes" << endl;
            return 0;
        }
    }

    for(int i = 0; i < n-m; i++){
        for(int j = 0; j < n-m; j++){
            bool same = true;
            for(int k = 0; k < m; k++){
                bool end = false;
                for(int l = 0; l < m; l++){
                    if(a[k+i][l+j] != b[k][l]){
                        end = true;
                        same = false;
                        break;
                    }
                }
                if(end) break;
            }
            if(same){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    deque<int> Q;
    int t;cin>>t;
    while(t--){
        int op;
        cin>>op;
        if(op==0){
            int d,x;
            cin>>d>>x;
            !d?Q.push_front(x):Q.push_back(x);
        }else{
            if(op==1){
                int p;
                cin>>p;
                cout<<Q[p]<<endl;
            }else{
                int d;
                cin>>d;
                !d?Q.pop_front():Q.pop_back();
            }
        }
    }
    
}
/* 
- push(dd, xx): Add element xx at the begining of AA, if d=0d=0. Add element xx at the end of AA, if d=1d=1.
- randomAccess(pp): Print element apap.
- pop(dd): Delete the first element of AA, if d=0d=0. Delete the last element of AA, if d=1d=1.
 */


Measured memory_bytes: 4628
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;


vector<LL> fact;
vector<LL> inver(200001);
 
LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}
 
 
LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}
 
void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=200000;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[200000]=fpow(fact[200000],mod-2);
    for(int i=199999;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}
 


int main(){
    set_combi();
    int H,W,N;cin >> H >> W >> N;
    H--,W--;
    vector<P> v;
    for (int i = 0; i < N; i++) {
        int x,y;cin >> x >> y;
        x--,y--;
        v.pb(P(x,y));
    }
    v.pb(P(0,0));
    v.pb(P(H,W));
    sort(ALL(v));
    vector<vector<LL>> dp(N+2,vector<LL> (2,0));
    dp[0][0] = 1;
    for (int i = 0; i < N+2; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = i+1; k < N+2; k++) {
                int dx = v[k].fs - v[i].fs;
                int dy = v[k].sc - v[i].sc;
                dp[k][j^1] = (dp[k][j^1] + dp[i][j]*combi(dx+dy,dx))%mod;
            }
        }
    }
    cout <<  (dp[N+1][1] - dp[N+1][0] + mod)%mod << endl;
    return 0;
}


Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <algorithm>

struct element
{
  int i;
  std::string s;
  int p;
};

element work[100];

int main()
{
  int N;
  std::cin >> N;
  
  std::vector<element *> resutoran;
  resutoran.reserve(N);
  
  for(int i=0; i<N;i++)
  {
    auto l = work + i;
    l->i = i + 1;
    std::cin >> l->s >> l->p;
    resutoran.push_back(l);
  }
  
  std::sort(resutoran.begin(), resutoran.end(), []
            (const element * a, const element *  b) {
              return a->p > b->p;
            });
  
  std::stable_sort(resutoran.begin(), resutoran.end(), []
            (const element * a, const element *  b) {
              return a->s < b->s;
            });
  
  for(auto it=resutoran.begin(); it!=resutoran.end(); it++)
    std::cout << (*it)->i << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int N;
  int A[100];
  int i,j,k,v;

  scanf("%d",&N);
  for(i=0;i<N;i++)
  {
    scanf("%d",&A[i]);
  }

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

  for(i=1;i<N;i++)
  {
    v = A[i];
    j = i-1;
    while(j>=0 && A[j]>v)
    {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    for(k=0;k<N-1;k++)
    {
      printf("%d ",A[k]);
    }
    printf("%d\n",A[N-1]);
  }

  return 0;

}

Measured memory_bytes: 596
#include<stdio.h>
#include<stdlib.h>
 
#define NIL -1
#define MAX 500001
 
typedef struct{
  int right;
  int left;
  int key;
} Node;
 
void Insert(Node*,int,int);
void PreOrder(Node*,int);
void InOrder(Node*,int);
 
int main(void){
  int i, n, k, count=0;
  char state[8];
  Node T[MAX];
 
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%s", state);
 
    if(state[0] == 'i'){
 
      scanf("%d",&k);
      Insert(T, count, k);
      count++;
 
    } else if(state[0] == 'p'){
 
      if(count > 0){
        InOrder(T,0);
        printf("\n");
        PreOrder(T,0);
        printf("\n");
      }
 
    }
  }
  return 0;
}
 
void Insert(Node *T,int count, int k){
  int x, y;
 
  T[count].key = k;
  T[count].left = NIL;
  T[count].right = NIL;
 
  if(count == 0) return;
 
  x = 0;
  while(x!=NIL){
    y = x;
 
    if(k < T[x].key) x = T[x].left;
    else x = T[x].right;
 
  }
 
  if(k < T[y].key) T[y].left = count;
  else T[y].right = count;
 
  return;
}
 
void PreOrder(Node *T, int u){
 
  if(u == NIL) return;
 
  printf(" %d", T[u].key);
  PreOrder(T, T[u].left);
  PreOrder(T, T[u].right);
 
  return;
}
 
void InOrder(Node *T, int u){
 
  if(u == NIL) return;
 
  InOrder(T, T[u].left);
  printf(" %d", T[u].key);
  InOrder(T, T[u].right);
 
  return;
}

Measured memory_bytes: 6464
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;cin >> h >> w;
    char c[h][w];
    REP(i,h){
        REP(j,w){
            cin >> c[i][j];
        }
    }
    REP(i,h){
        REP(j,w){
            if(c[i][j]=='.'){
                continue;
            }
            bool f=false;
            REP(k,4){
                int x=i+dx[k],y=j+dy[k];
                if(x>=0&&x<h&&y>=0&&y<w){
                    if(c[x][y]=='#'){
                        f=true;
                    }
                }
            }
            if(!f){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3696
#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 ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int main() {
	ll N, M;
	cin >> N >> M;
	if (N > M) swap(N, M);
	
	ll ans = 0;
	if (N >= 3 && M >= 3) ans = (N - 2) * (M - 2);
	else if (N == 1) {
		if (M == 1) ans = 1;
		else ans = M - 2;
	}
	else ans = 0;
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    n, m, k = map(int, input().split())
    uf = UnionFind(n)
    ans = [0] * n
    for _ in range(m):
        A, B = map(int, input().split())
        A, B = A - 1, B - 1
        uf.union(A, B)
        ans[A] -= 1
        ans[B] -= 1

    for i in range(n):
        ans[i] = ans[i] + uf.size(i) - 1

    for _ in range(k):
        C, D = map(int, input().split())
        C, D = C - 1, D - 1
        if uf.same(C, D):
            ans[C] -= 1
            ans[D] -= 1
    
    print(*ans)
    
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

if __name__ == '__main__':
    main()

Measured memory_bytes: 13392