akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip> // 文字幅の指定 setw(int), 詰めたい文字の指定 setfill(char)
#include <algorithm> // sort
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define p(x) cout << (x) << endl
#define FOR(i,r,n) for(ll i=(ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n); i>=r; i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) REP(i,0,n)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pb push_back

// 定義する？→左揃えで0埋め
// cout << setfill('0') << left << setw(4) << 12; // "0012"
// http://marycore.jp/prog/cpp/padding-left-right-zero/

const int inf = (int)1e9;
const ll INF = (ll)1e18;

// vectorの中身をcout << vs;で表示
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v)
{
    o << "{";
    for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i];
    o << "}";
    return o;
}

ll gcd (ll a, ll b) {
	while (b > 0) {
		ll t = a % b;
		a = b, b = t;
	}
	return a;
}

ll lcm (ll a, ll b) {
	return (a / gcd (a, b)) * b;
}

bool is_prime (ll n) {
		if (n < 2) return false;
		else if (n == 2) return true;
		else if (n % 2) return false;
		
		double sqrtn = sqrt(n);
		for (ll i = 3; i < sqrtn; i += 2) {
			if (n % i == 0) return false; 
		}
		return true;
}

ll ctoi(char c) {
	return (ll)(c - 48);
}

ll n, k, cnt=0, ans=0;
string s,t;

// ==================== template ============================

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

	int a, b, c, d; cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define mod 1000000007


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }
    
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
    
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};



int gcd(int a, int b){
    while(b){
        int t = a;
        a = b;
        b = t%b;
    }
    return a;
}

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



int main() {
    int D; cin >> D;
    if(D==25) cout << "Christmas" << endl;
    else if(D==24) cout << "Christmas Eve" << endl;
    else if(D==23) cout << "Christmas Eve Eve" << endl;
    else cout << "Christmas Eve Eve Eve" << endl;
    
    return 0;
}


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

int main()
{
    string s;
    cin>>s;
    int f=0;
    for(int i=0;i<s.size();i++)
    {
        int x=count(s.begin(),s.end(),s[i]);
        if(x%2==1)
        {f=1;
        break;}
    }
    if(f==0)
    {
        cout<<"Yes"<<endl;
    }
    else if (f==1)
    {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
N, K = map(int, input().split())
a = [list(map(int, input().split())) for i in range(N)]
a.sort()
ans = a[0][0]
b = a[0][1]
i = 1
while b < K:
  ans = a[i][0]
  b += a[i][1]
  i += 1
print(ans)
  

Measured memory_bytes: 29652
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e5+7,INF = 0x7f7f7f7f;
ll a[N],f[N],s[N];
int main()
{
    int n;scanf("%d",&n);
    for(int i = 1;i <= n;++i)	scanf("%lld",&a[i]);
	s[1] = a[1];
	for(int i = 2;i <= n;++i)
		s[i] = s[i - 2] + a[i];
	f[2] = a[1];
	for(int i = 2;i <= n;++i)
		if(i & 1)	f[i] = max(f[i - 1],f[i - 2] + a[i]);
		else	f[i] = max(f[i - 2] + a[i],s[i - 1]);
    printf("%lld",f[n]);
    return 0;
}


Measured memory_bytes: 7916
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int count1 = 0;
		int count2 = 0;
		char x;
		for (int i = 0; i<S.length(); i++) {
			x = S.charAt(i);
			if (x == '0') {
				if (i % 2 == 0){
					count1++;
				}
				if (i % 2 == 1) {
					count2++;
				}
			}			
			if (x == '1') {
				if (i % 2 == 1){
					count1++;
				}
				if (i % 2 == 0) {
					count2++;
				}
			}
		}
		if (count1 > count2)
			System.out.println(count2);
		else
			System.out.println(count1);
	}
}	


Measured memory_bytes: 24628
line = input()
a, b = [int(n) for n in line.split()]
tempo = b
custo = 1001
tle = True
for n in range(1, a+1):
    line = input()
    c, t = [int(n) for n in line.split()]
    if t<=tempo and c<=custo:
        custo = c
        tle = False

print(custo if tle==False else "TLE")


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

int main()
{
	auto p = vector<bool>(1000000);
	auto pl = vector<int>();
	p[0] = p[1] = true;
	for(int i = 2; i < 1000000; ++i){
		if(p[i]) continue;
		pl.push_back(i);
		for(int j = i + i; j < 1000000; j += i){
			p[j] = true;
		}
	}
	long long int n;
	cin >> n;
	int ans = 0;
	for(int i = 0; i < (int)pl.size(); ++i){
		if(n == 1) break;
		int cnt = 0;
		while(n % pl[i] == 0){
			++cnt;
			n /= pl[i];
		}
		for(int j = 1;; ++j){
			cnt -= j;
			if(cnt < 0) break;
			++ans;
		}
	}
	if(n > 1) ++ans;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> A(n);
  for (auto &a: A) cin >> a;
  sort(A.begin(), A.end());
  cout << A[n-1]-A[0] << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=3005,INF=1<<30;

ll inv[MAX],fac[MAX],finv[MAX];

void make(){
    
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    
    for(int i=2;i<MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll)i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
    
}

ll comb(ll a,ll b){
    if(b<0) return 0;
    if(a<b) return 0;
    return fac[a]*(finv[b]*finv[a-b]%mod)%mod;
}

ll dp[MAX][MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    make();
    
    int N,q;cin>>N>>q;
    string S;cin>>S;
    vector<pair<int,int>> Q;
    while(q--){
        int s,t;cin>>s>>t;
        if(Q.size()==0) Q.push_back({s,t});
        else if(Q.back().first==s) chmax(Q.back().second,t);
        else if(Q.back().second<t) Q.push_back({s,t});
    }
    Q.push_back({N+1,N+2});
    
    vector<int> T(N+1);
    int M=int(Q.size());
    
    for(int i=1;i<=N;i++){
        if(S[i-1]=='1') T[i]=T[i-1]+1;
        else T[i]=T[i-1];
    }
    
    ll ans=1;
    
    int left=Q[0].first-1;
    dp[0][T[left]]=1;
    
    for(int i=1;i<M;i++){
        if(Q[i-1].second<Q[i].first){
            ll sum=0;
            for(int j=0;j<=T[Q[i-1].second];j++){
                sum+=dp[i-1][j]*comb(Q[i-1].second-left,T[Q[i-1].second]-j);
                sum%=mod;
            }
            ans*=sum;
            ans%=mod;
            left=Q[i].first-1;
            dp[i][T[Q[i].first-1]]=1;
        }else{
            for(int j=0;j<=T[Q[i-1].second];j++){
                for(int d=0;d<=Q[i].first-1-left;d++){
                    if(j-d<0) continue;
                    if(T[Q[i-1].second]-j>Q[i-1].second-(Q[i].first-1)) continue;
                    
                    dp[i][j]+=dp[i-1][j-d]*comb(Q[i].first-1-left,d);
                    dp[i][j]%=mod;
                }
            }
            left=Q[i].first-1;
        }
    }
    
    /*for(int i=1;i<=M;i++){
        for(int j=0;j<=N;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    
    cout<<ans<<endl;
}



Measured memory_bytes: 29440
import collections

N = int(input().strip())
words = []
for i in range(N):
  word = input().strip()
  words.append(word)
  
c = collections.Counter(words)
num = c.most_common()[0][1]
#print(num)

ans = []
for name, freq in c.most_common():
  if freq == num:
    ans.append(name)
  else:
    break
    
for i in sorted(ans):
  print(i)
      
    

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

int main(){
    int a,li[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    cin >> a;

    cout << li[ a - 1 ] << "\n";
}

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

int main() {
  short input_k, input_a, input_b;
  char output[3];

  scanf("%hd %hd %hd", &input_k, &input_a, &input_b);

  // A または B が K の倍数だった場合は問答無用で OK
  if (input_a % input_k == 0 || input_b % input_k == 0) {
    strcpy(output, "OK");
  } else if (input_a /* e.g. 11 */ - (input_a % input_k) /* e.g. 3 */ + input_k /* e.g. 4 */ <= input_b /* e.g. 15 */) {
    strcpy(output, "OK");
  } else {
    strcpy(output, "NG");
  }

  printf("%s", output);
  printf("%c", '\n');

  return 0;
}


Measured memory_bytes: 1720
#include <iostream>
using namespace std;
using ll = long long;
int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  if(A > B) {
    cout << 0 << endl;
    return 0;
  }
  if(N == 1) {
    if(A == B) {
      cout << 1 << endl;
      return 0;
    }
    else {
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = (B - A) * (N - 2) + 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
 
using namespace std;
typedef long long ll;
 
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
int T;
const int maxN = 1e6+8;
const int maxM = 1e3+6;
const ll INF = 1e15+7;
const int MOD = 1e9+7;
int n;
int k;
int a[maxM][maxM];
char s[maxN];
void calc(int L,int R,int tot)
{
	if(L == R)
	{
		return; 
	}
	int mid = (L+R)/2;
	for(int i=L;i<=mid;i++)
	{
		for(int j=mid+1;j<=R;j++)
		{
			a[i][j] = tot;
		}
	}
	calc(L,mid,tot+1);
	calc(mid+1,R,tot+1);
}

int main() {
	int n,k;
	scanf("%d",&n);
	calc(1,n,1);
	for(int i=1;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			printf("%d ",a[i][j]);
		}
		printf("%d\n",a[i][n]);
	}
	 
    return 0;
}

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

//UnionFind
//全て添字で扱うこと
struct union_find {
  std::vector<long long> parent;
  std::vector<long long> sizes;

  //コンストラクタ
  union_find(long long n) {
    for (long long i = 0; i < n; i++) {
      parent.push_back(i);
      sizes.push_back(1);
    }
  }

  //頂点nの根
  long long root_of(long long n) {
    if (parent[n] == n) return n;
    return parent[n] = root_of(parent[n]); //パス圧縮
  }

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

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

  //頂点aを含むグラフに頂点bを含むグラフを結合
  void unite(long long a, long long b) {
    if (is_united(a, b)) return;
    if (size_of(a) < size_of(b)) std::swap(a, b); //マージテク
    sizes[root_of(a)] += size_of(b);
    parent[root_of(b)] = root_of(a);
  }
};

int main() {
  long long n, m, k;
  std::cin >> n >> m >> k;

  union_find uf(n);

  std::vector<std::vector<long long>> nx(n, std::vector<long long>(0));
  for (long long i = 0; i < m; i++) {
    long long a, b;
    std::cin >> a >> b;
    nx[a - 1].push_back(b - 1);
    nx[b - 1].push_back(a - 1);
    uf.unite(a - 1, b - 1);
  }

  std::vector<long long> bl(n, 0);
  for (long long i = 0; i < k; i++) {
    long long c, d;
    std::cin >> c >> d;
    if (uf.is_united(c - 1, d - 1)) {
      bl[c - 1]++;
      bl[d - 1]++;
    }
  }

  for (long long i = 0; i < n - 1; i++) std::cout << uf.size_of(i) - 1 - nx[i].size() - bl[i] << " ";
  std::cout << uf.size_of(n - 1) - 1 - nx[n - 1].size() - bl[n - 1] << std::endl;
}

Measured memory_bytes: 9452
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    int n;
    cin>>n;
    map<string,int> m;
    vector<string> v={"AC","WA","TLE","RE"};
    while(n--)
    {
        cin>>a;
        m[a]++;
    }
    for(auto j:v)
    {
        cout<<j<<" "<<"x"<<" "<<m[j]<<'\n';
    }
}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
struct multi {
  ll first;
  ll second;
  ll third;
  multi(ll first, ll second, ll third)
      : first(first), second(second), third(third) {}
};
bool multicomp(const multi &a, const multi &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  vl A;
  cin >> S;
  if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3])
    cout << "Bad" << endl;
  else
    cout << "Good" << endl;

  return 0;
}


Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        long N = cin.nextint;
        long M = cin.nextint;

        long max = 1;
        if (N * M <= M)
        {
            chmax(ref max, M);
        }
        for (int i = 2 ; i * i <= M; i++)
        {
            if(M % i != 0)
            {
                continue;
            }

            if (N * i <= M)
            {
                chmax(ref max, i);
            }
            var g = M / i;
            if (N * g <= M)
            {
                chmax(ref max, g);
            }
        }
        WriteLine(max);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#include <numeric> 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define int long long int
#define mod 1000000007
#define INT_BITS 16
#define inf 1000000099
#define watch(x) cout<<(#x)<<"="<<(x)<<"\n" 
//__builtin_popcount()


// int loop(int i)
// {
//     if(visited[i]==1)
//       return i;
//     for(auto x:g[i])
//     {
//         visited[x]=1;
//         loop(x);
//     }
 
// }
 
// int looplength(int i)
// {
//     int count=1;
//     int x=g[i];
//     while(x!=i)
//     {
//       x=g[x];
//       count++;
//     }
//     return count;
// }
int32_t main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    int visited[n];
    memset(visited,0,sizeof(visited));
    for (int i = 0; i <n ; ++i)
    {
        cin>>a[i];
        a[i]--;
        //g[i].push_back(a[i]);
      
    }
    int i=0;
    while(visited[i]!=1 && k>0)
    {
        visited[i]=1;
        i=a[i];
        k--;
    }
    if(k==0)
    {
      cout<<i+1<<endl;
      return 0;
    }
    //watch(i);
    int count=1;
    int x=a[i];
    while(x!=i)
    {
        x=a[x];
        count++;
    }
    // watch(count);
    // watch(k);
    k%=count;
    x=i;
 
    while(k>0)
    {
        x=a[x];
        k--;
    }
    cout<<x+1<<endl;
    // int x=loop(1);
    // memset(visited,0,sizeof(visited));
    // int length=looplength(x);
    // watch(x);
    // watch(length);
    return 0;
}

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

int main(){
    string s, ans="Yes";
    int a, b, i;

    cin >> a >> b;
    cin >> s;

    if (s.size() != a + b + 1) {
        ans = "No";
    } else {
        for (i=0; i<a; i++) {
            if ((s[i] < '0') || (s[i] > '9')) {
                ans = "No";
                break;
            }
        }
        if (s[a] != '-') {
            ans = "No";
        }
        for (i=a+1; i<a+b+1; i++) {
            if ((s[i] < '0') || (s[i] > '9')) {
                ans = "No";
                break;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef vector<ll> vl;
typedef vector<vector<long long>> vvl;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const int INF = 1e9;


int main() {
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	int x;
	cin >> x;
	for (int cx = x;; cx++)
	{
		bool ok = true;
		for (int i = 2; i * i < cx; i++)
		{
			if (cx % i == 0)
			{
				ok = false;
				break;
			}
		}
		if (ok)
		{
			cout << cx;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
#include<bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
using namespace std;
using ll = long long;

int main(){
     cin.tie(0);
        ios::sync_with_stdio(false);
        ll n; cin >> n;
        ll m=sqrtl(n+1); ll ans=0;
  for(ll i=1;i<=m;i++){
    if(n%i==0 && n/i>=2+i){
      ans+=(n/i)-1;
    }
  }
  cout << ans << endl;
}       

Measured memory_bytes: 256
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define pb     push_back
#define inf     2e18
#define low     -2e18
#define PI        acos(-1.0)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
const int sz = 1e5+9;

int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    cin>>n>>k>>m;
    x = abs(n/m);
    if(x>k)
    {
        if(n<0)
        {
            cout<<abs(n+m*k)<<endl;
        }
        else cout<<abs(n-m*k)<<endl;
        return 0;
    }
    k-= x;
    if(n<0)
    {
        n = n+x*m;
        if(k%2==0)
        {
            cout<<abs(n)<<endl;
        }
        else cout<<abs(n+m)<<endl;
    }
    else
    {
        n = n-x*m;
        if(k%2==0)
        {
            cout<<abs(n)<<endl;
        }
        else cout<<abs(n-m)<<endl;
    }

    return 0;
}



Measured memory_bytes: 3632
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
#import random


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()

def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)

YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


show_flg = False
# show_flg = True

def main():
    N, M = MI()
    cities = [None] * M
    identifiers = [1] * (N + 1)
    output = [None] * M

    for i in range(M):
        P, Y = MI()
        cities[i] = (Y, P, i)

    cities.sort()
    show(cities)

    for i in range(M):
        Y, P, idx = cities[i]
        output[idx] = str(P).zfill(6) + str(identifiers[P]).zfill(6)
        identifiers[P] += 1

    for i in range(M):
        print(output[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 68696
n = int(input())
a = input()
cr = 0
cl = 0
ans = a
for i in range(n):
  if a[i] == "(":
    cl += 1
  elif a[i] == ")":
    cr += 1
  if cl == 0 and cr != 0:
    ans = "(" + ans
    cr -= 1
  if cl != 0 and cr != 0:
    if cr >= cl:
      cl, cr = 0,cr-cl
    else:
      cl, cr = cl-cr,0
if cl != 0:
  for i in range(cl):
    ans = ans+")"
print(ans)


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

struct edge { int64_t to, cap, rev;};

void add_edge(int from, int to, int64_t cap, vector<edge> G[]){
    G[from].push_back((edge){to, cap, G[to].size()});
    G[to].push_back((edge){from, 0, G[from].size()-1});
}

int64_t dfs_flow(int v, int t, int64_t f, vector<bool> &used, vector<edge> G[]){
    if(v==t) return f;
    used[v] = true;
    for(int i=0; i<G[v].size(); i++){
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0){
            int64_t d = dfs_flow(e.to, t, min(f, e.cap), used, G);
            if(d>0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int64_t max_flow(int N, int s, int t, vector<edge> G[]){
    int64_t flow = 0;
    const int64_t INF = 1e18;
    vector<bool> used(N);
    while(true){
        fill(used.begin(), used.end(), false);
        int64_t f = dfs_flow(s, t, INF, used, G);
        if(f==0) return flow;
        flow += f;
    }
}

void fin(bool ok){
    cout << (ok ? "Yes" : "No") << endl;
    exit(0);
}

vector<int> edges[100000];
vector<edge> edges2[100000];

int main(){
    int N, M;
    cin >> N >> M;
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
        add_edge(a, b, 1, edges2);
        add_edge(b, a, 1, edges2);
    }

    vector<int> d6;
    vector<int> d4;
    for(int i=0; i<N; i++){
        int sz = edges[i].size();
        if(sz%2) fin(false);
        if(sz >= 6) d6.push_back(i);
        if(sz == 4) d4.push_back(i);
    }
    if(d6.size()) fin(true);
    if(d4.size() >= 3) fin(true);
    if(d4.size() <= 1) fin(false);

    int path = max_flow(N, d4[0], d4[1], edges2);
    fin(path==2);
    return 0;
}


Measured memory_bytes: 21760
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;


int main(){
    int w,h;
    cin>>w>>h;
    char c;
    cin>>c;
    rep(i,0,h){
        rep(j,0,w){
            if(i==h/2&&j==w/2)cout<<c;
            else if(i==0&&j==0)cout<<"+";
            else if((i==h-1&&j==w-1))cout<<"+";
            else if(i==0 && j==w-1)cout<<"+";
            else if(i==h-1 && j==0)cout<<"+";
            else if(j==0||j==w-1)cout<<"|";
            else if(i==0||i==h-1)cout<<"-";
            else cout<<'.';
        }
        cout<<endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 3096
#include "bits/stdc++.h"
using namespace std;

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


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

    int          N;
    double       max = 0;
    vector <int> value(0);

    cin >> N;
    rep(i, N) {
        int buf;
        cin >> buf;
        value.push_back(buf);
    }
    sort(value.begin(), value.end());
    max = (value.at(0) + value.at(1)) / 2.0;
    rep(i, N - 2) {
        max = (max + value.at(i + 2)) / 2.0;
    }
    cout << max << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

int main() {
  int n;
  int f[101][10], p[101][11];

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

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

  int ans = -int(1e9);

  int m = (1 << 10), c[101];

  for (int i = 1; i < m; ++i) {
    std::fill(c, c + n, 0);
    for (int j = 0; j < 10; ++j) {
      if ((i >> j) & 1) {
	for (int k = 0; k < n; ++k) {
	  c[k] += f[k][j];
	}
      }
    }

    int tmp = 0;
    
    for (int i = 0; i < n; ++i) {
      tmp += p[i][c[i]];
    }

    ans = std::max(tmp, ans);
  }

  cout << ans << endl;
  
  return 0;
}


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

int main(void){
   int n, q;
   long long a[200010]={0},dp[200010]={0};
   long long sum=0;
   scanf("%d",&n);
   for(int i=0;i<n;i++){
     scanf("%lld",&a[i]);
     sum += a[i];
     dp[a[i]]++;
   }
   scanf("%d",&q);
   for(int i=0;i<q;i++){
     long long b,c;
     scanf("%d %d",&b,&c);
     
     sum += c*dp[b];
     sum -= b*dp[b];
     dp[c] += dp[b];
     dp[b] = 0;
     printf("%lld\n",sum);
   }
  return 0;
}

Measured memory_bytes: 4856
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll x[123];
signed main() {
    ll n, res = LONG_LONG_MAX >> 1;
    scanf ("%lld", &n);
    for (int i = 1; i <= n; ++i) scanf ("%lld", x + i);
    for (int i = 1; i <= 100; ++i) {
        long long tmp = 0;
        for (int j = 1; j <= n; ++j) tmp += (x[j] - i) * (x[j] - i);
        res = min (res, tmp);
    } return printf ("%lld\n", res), 0;
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef array<int, 2> duo;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}




void _main() {
        ll a, b, c, d; cin >> a >> b >> c >> d;
        auto solve = [&](ll k) -> ll {
                return k - (k / c) - (k / d) + k / (c * d / __gcd(c, d));
        };

        cout << solve(b) - solve(a - 1);
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3636
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int A = sc.nextInt();
      int B = sc.nextInt();
      int C = sc.nextInt();
      int K = sc.nextInt();
      
      // 計算
      int sum = 0;
      if(K <= A){
        sum = K;
      }else if(K <= A+B){
        sum = A;
      }else{
        sum = A - (K-A-B);
      }
      
      // 出力
      System.out.println(sum);
    }
    
}

Measured memory_bytes: 35712
in1=gets.chomp.split(" ").map(&:to_i)
n=in1[0]
m=in1[1]
step=[]
breaker=[]

for i in 0..n do
 step[i]=0
 breaker[i]=true
end
for i in 0...m do
 a=gets.to_i
 breaker[a]=false
end

step[0]=1

for i in 0...n do
 for j in 1..2 do
  if i+j<=n&&breaker[i]
   step[i+j]=step[i+j]+step[i]
  end
 end
end
puts step[n]%1000000007

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


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n; cin >> n;
    vector<int>l(n,0);
    for(int i = 0; i<n; i++){
        cin >> l[i];
    }
    int ns = 0;
    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++){
                    
                        int a = l[i], b = l[j], c = l[k];
                        if(a!=b and a!=c and b!=c){
                            if(a+b > c && a+c > b && b+c > a){
                                ns++;
                            }
                        }
                    
                }
            
        }
    }
    cout << ns;
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    X--; Y--;

    vector< vector<int> > edges(N, vector<int>());
    REP(i, N-1) {
        edges[i].push_back(i+1);
        edges[i+1].push_back(i);
    }
    
    edges[X].push_back(Y);
    edges[Y].push_back(X);

    vector<vector<int> > dist(N, vector<int>(N, -1));
    vector<int> num(N);
    REP(i, N) {
        queue<int> que;
        dist[i][i] = 0;
        que.push(i);
        while (!que.empty()) {
            int v = que.front(); // キューから先頭頂点を取り出す
            que.pop();

            // v から辿れる頂点をすべて調べる
            for (int nv : edges[v]) {
                if (dist[i][nv] != -1) continue; // すでに発見済みの頂点は探索しない

                // 新たな白色頂点 nv について距離情報を更新してキューに追加する
                dist[i][nv] = dist[i][v] + 1;
                if(i < nv)
                    num[dist[i][nv]]++;
                que.push(nv);
            }
        }
    }

    // cerr << "debug" << endl;
    // REP(i, N) cerr << dist[3][i] << endl;

    FOR(i, 1, N-1) cout << num[i] << endl;

    return 0;
}

Measured memory_bytes: 16128
N, M, Q = [int(x) for x in input().split()]
L = [0] * M
R = [0] * M
p = [0] * Q
q = [0] * Q
for i in range(M):
    L[i], R[i] = [int(x) for x in input().split()]
for j in range(Q):
    p[j], q[j] = [int(x) for x in input().split()]

train = [[0 for i in range(N + 1)] for _ in range(N + 1)]
seg = [[0 for i in range(N + 1)] for _ in range(N + 2)]

for i in range(M): # すべての列車について
    train[L[i]][R[i]] += 1

for col in range(1, N + 1):
    for row in range(col, 0, -1):
        seg[row][col] = train[row][col] + seg[row][col - 1] + seg[row + 1][col] - seg[row + 1][col - 1]

for j in range(Q):
    print(seg[p[j]][q[j]])


Measured memory_bytes: 25872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;
int a[1000];
int main()
{
    cin>>n;
    for(int i=0;i<=25;i++)
        for(int j=0;j<15;j++)
    {
        a[i*4+j*7]=1;
    }
    if(a[n])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys, math, bisect, random, itertools
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    print(n*n*3)
    return

#B
def B():
    n, d = LI()
    print((n-1)//(2*d+1)+1)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    B()


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

using namespace std;
#define ll long long

int main (void) {
    int n;

    scanf("%d", &n);

    ll sum = 0;
    for (int i = 1; i <= n; i++)
    {
        if((i%3==0 || i%5==0)==0){
            sum += i;
        }
    }
    printf("%lld\n", sum);

    return 0;
}

Measured memory_bytes: 3800
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;

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

template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;

int main() {
	int n;
	cin >> n;
	V<int> a(n, 0);
	rep(i, n) {
		cin >> a[i];
	}
	ll sum = 0;
	for (int i = 1; i < n; ++i) {
		int d = a[i] - a[i - 1];
		if (d < 0) {
			sum += -d;
			a[i] += -d;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 4040
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
struct node{
	int l,r;
}a[100000+20];
bool cmp(node a,node b)
{
	if(a.r==b.r)
		return a.l<b.l;
	return a.r<b.r;
}
int main ()
{
	int n,m,i;
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++)
		scanf("%d %d",&a[i].l,&a[i].r);
	int mn=a[0].r;
	for(i=0;i<m;i++)
		mn=min(a[i].r,mn);
		
	sort(a,a+m,cmp);
int now=mn,ans=1;
	for(i=1;i<m;i++)
	{
		if(a[i].l>=now)
		{
			now=a[i].r;
			ans++;
		}

	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,m;
    cin >> n >> m;
    if(abs(n-m) > 1) {
        cout << 0 << endl;
        return 0;
    }
    const int mod = 1e9+7;
    ll ans = 1;
    rep(i,n) ans = ans*(i+1)%mod;
    rep(i,m) ans = ans*(i+1)%mod;
    if(n == m) ans = ans*2%mod;
    cout << ans << endl;
}


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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

int64_t M = 1e9+7;

vector<int64_t> inv_tbl(2000000);
vector<int64_t> fact_inv_tbl(2000000);
vector<int64_t> fact_tbl(2000000);

int64_t modpow(int64_t n, int64_t m) {
    if (m == 0) return 1;
    else if (m % 2 == 0) { 
        int64_t r = modpow(n, m / 2);
        return (r * r) % M;
    } else {
        int64_t r = modpow(n, m / 2);
        return ((n * r) % M * r) % M;
    }
}

int64_t inv(int n) {
    return inv_tbl[n];
}

void compute_inv() {
    for (size_t i = 0; i < inv_tbl.size(); ++i) {
        inv_tbl[i] = modpow(i, M - 2);
    }
    int64_t n = 1;
    fact_inv_tbl[0] = 1;
    fact_tbl[0] = 1;
    for (size_t i = 1; i < inv_tbl.size(); ++i) {
        fact_tbl[i] = (i * fact_tbl[i - 1]) % M;
        fact_inv_tbl[i] = (inv_tbl[i] * fact_inv_tbl[i - 1]) % M;
    }
}

int64_t comb(int n, int k) {
    return ((fact_tbl[n] * fact_inv_tbl[n - k]) % M * fact_inv_tbl[k]) % M;
}

int64_t f(int r, int c) {
    int64_t x = comb(r - 1 + c - 1, c - 1);
    return x;
}

int main() {
    compute_inv();
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    int64_t res = f(H, W);
    for (int i = 0; i < B; ++i) {
        res = (res - (f(H - A, i + 1) * f(A, W - i)) % M + 5 * M) % M;
    }
    cout << res << endl;
}

Measured memory_bytes: 47232
use std::io::*;
use std::str::FromStr;
use std::cmp;

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char) 
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
    
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let (k, x): (i32, i32) = (read(), read());
  println!("{}",
    if 500 * k >= x { "Yes" }
    else { "No" }
  );
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

using namespace std;
int n, m, s, t;
vector<long> dist1(100005);
vector<long> dist2(100005);
vector<long> u(100005);
vector<long> v(100005);
vector<long> a(100005);
vector<long> b(100005);
vector<vector<pair<long, long>>> graph(100005);

void dijkstra1(long s) {
  priority_queue<pair<long,long>, vector<pair<long, long>>, greater<>> queue;
  queue.push(make_pair(0, s));
  while (!queue.empty()) {
    pair<long, long> p = queue.top();
    queue.pop();
    long start = p.second;
    long d = p.first;
    if (d > dist1.at(start)) {
      continue;
    }
    for (auto e : graph.at(start)) {
      long end = e.first;
      long train = e.second;
      long cost = a.at(train);
      if (dist1.at(end) > d + cost) {
        dist1.at(end) = d + cost;
        // cout << "yen: pos: " << end << " cost: " << dist1.at(end) << endl;
        queue.push(make_pair(dist1.at(end), end));
      }
    }
  }
}

void dijkstra2(long t) {
  priority_queue<pair<long,long>, vector<pair<long, long>>, greater<>> queue;
  queue.push(make_pair(0, t));
  while (!queue.empty()) {
    pair<long, long> p = queue.top();
    queue.pop();
    long start = p.second;
    long d = p.first;
    if (d > dist2.at(start)) {
      continue;
    }
    for (auto e : graph.at(start)) {
      long end = e.first;
      long train = e.second;
      long cost = b.at(train);
      if (dist2.at(end) > d + cost) {
        dist2.at(end) = d + cost;
        // cout << "snuke: pos: " << end << " cost: " << dist2.at(end) << endl;
        queue.push(make_pair(dist2.at(end), end));
      }
    }
  }
}

int main() {
  cin >> n >> m >> s >> t;
  for (int i=1; i<=m; i++) {
    cin >> u.at(i) >> v.at(i) >> a.at(i) >> b.at(i);
  }

  for (int i=1; i<=m; i++) {
    graph.at(u.at(i)).push_back(make_pair(v.at(i), i));
    graph.at(v.at(i)).push_back(make_pair(u.at(i), i));
  }

  for (int i=1; i<=n; i++) {
    dist1.at(i) = LONG_MAX;
    dist2.at(i) = LONG_MAX;
  }
  dist1.at(s) = 0;
  dist2.at(t) = 0;

  dijkstra1(s);
  dijkstra2(t);

  vector<long> dvec(n+1);
  for (int i=1; i<=n; i++) {
    dvec.at(i) = dist1.at(i) + dist2.at(i);
  }
  for (int i=n-1; i>=1; i--) {
    dvec.at(i) = min(dvec.at(i), dvec.at(i+1));
  }
  long init = 1;
  for (int i=1; i<=15; i++) {
    init *= 10;
  }
  for (int i=1; i<=n; i++) {
    cout << init-dvec.at(i) << endl;
  }
}


Measured memory_bytes: 14848
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const int maxn = 100100;
int n;
int h[maxn];
int dp[maxn];

int dfs(const int i)
{
    if (i == 0)
        return 0;
    int& ans = dp[i];
    if (-1 == ans) {
        ans = inf;
        FOR(d,1,3) if (i-d >= 0) {
            int j = i-d;
            int result = dfs(j) + abs(h[i]-h[j]);
            ans = min(ans,result);
        }
    }
    return ans;
}
    
int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);
    while (cin >> n) {
        memset(dp,-1,sizeof(dp));
        FOR(i,0,n) {
            cin >> h[i];
        }
        cout << dfs(n-1) << endl;
    }
    
}


Measured memory_bytes: 4224
#include<iostream>
#include<string>

using namespace std;

int main() {
	string a, b;
	cin >> a >> b;
	//今日は頑張って全館するぞーーーーーーーーーーー！
	int cnt = 0;
	for (int i = 0; i < 3; i++)if (a[i] == b[i])cnt++;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256