akhauriyash/Code-Regression huggingface dataset:
var a, b, d, g, ans;

function gcd(a, b){
	if(b === 0){
		g = a;
		return [1, 0];
	}
	else{
		var r = a % b;
		var q = (a - r) / b;
		var p = gcd(b, r);
		var x = p[0];
		var y = p[1];
		return [y, x - y * q];
	}
}

function test(x, y, u){
	x = Math.abs(x);
	y = Math.abs(y);
	if(ans === u || (x + y < ans[0] + ans[1]) || (x + y === ans[0] + ans[1] && a * x + b * y < a * ans[0] + b * ans[1])){
		ans = [x, y];
	}
}

function main(u){
	while(1){
		a = scan();
		b = scan();
		d = scan();

		if(a === 0){
			break;
		}

		var p = gcd(a, b);
		var x = p[0];
		var y = p[1];
		
		var s = d / g;
		x *= s;
		y *= s;

		var ap = a / g;
		var bp = b / g;
		var k = -x / bp;
		var l = y / ap;
		test(x + bp * Math.floor(k), y - ap * Math.floor(k));
		test(x + bp * Math.ceil(k), y - ap * Math.ceil(k));
		test(x + bp * Math.floor(l), y - ap * Math.floor(l));
		test(x + bp * Math.ceil(l), y - ap * Math.ceil(l));
		print(ans.join(' '));

		ans = u;
	}
}

function rep(a, b, c, u){
	if(c === u){
		c = b;
		b = a;
		a = 0;
	}
	for(var i = a; i < b; ++i){
		if(c(i) === false){
			break;
		}
	}
}

var input = '';

function scan(){
	return +input.pop();
}
function scan_string(){
	return input.pop();
} 
function print(val){
	console.log(val);
}
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.trim().split(/\s+/).reverse();
	main();
});

Measured memory_bytes: 17284
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vi d(n);
    rep(i, n) cin >> d[i];

    sort(all(d));

    cout << d[n/2] - d[n/2 - 1] << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
    int D, N;
    cin >> D >> N;
    
    int n;
    if(D == 0)  n = 1;
    else if(D == 1) n = 100;
    else if(D == 2) n = 10000;

    if(N != 100){
        cout << n*N << endl;
    }
    
    else if(N == 100){
        cout << n*101 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,k;cin>>n>>k;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
        a[i]--;
    }
    queue<ll> que;
    que.push(0);
    vector<ll> used(n,-1); //最短何回目のワープでここに来れるか
    ll tmp=0;
    ll buf1=-1,buf2=-1;
    while(true){
        ll x=que.front();que.pop();
        if(tmp+1==k){
            cout<<a[x]+1<<endl;
            return 0;
        }
        if(a[x]==x){
            cout<<x+1<<endl;
            return 0;
        }
        if(used[a[x]]!=-1){
            buf1=used[a[x]];
            buf2=tmp-used[a[x]]+1;
            break;
        }
        
        used[x]=tmp;
        tmp++;
        que.push(a[x]);
    }
    
    //cout<<buf1<<" "<<buf2<<endl;
    ll buf=(k-buf1)%buf2;
    buf+=buf1;
    que.push(0);
    ll x=-1;
    rep(i,buf){
        x=que.front();que.pop();
        que.push(a[x]);
    }
    if(x==-1)cout<<1<<endl;
    else cout<<a[x]+1<<endl;
    return 0;
}

Measured memory_bytes: 6376
def insertionSort(A, N):
    for i in range(1, N):
        print " ".join(map(str, A))
        v = A[i]
        j = i-1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v


N = int(raw_input())
A = map(int, raw_input().split())

insertionSort(A, N)

print " ".join(map(str, A))

Measured memory_bytes: 6376
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	std::string s; cin >> s;
	
	std::vector<int> latte(100, 0);
	for(int i = 0; i < s.size(); i++) latte[s[i] - 'A']++;
	
	bool ans = true;
	for(auto v: latte) ans &= (v == 0 or v == 2);
	if(ans) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 764
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	
	drinks := make(map[int]int)
	
	var a, b int
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		fmt.Scan(&b)
		drinks[a] += b
	}
	
	sorta := make([]int,0, len(drinks))
	for k := range drinks {
		sorta = append(sorta,k)
	}
	//fmt.Println(sorta)
  
	sort.Ints(sorta)
	
	ans := 0
	for i := 0; i < n && m > 0; i++ {
		buy := min(drinks[sorta[i]], m)
		ans += buy * sorta[i]
		m -= buy
	}
	fmt.Println(ans)
}

func min(num1, num2 int)int {
	if num1 < num2 {
		return num1
	}
	return num2
}

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

#define pb push_back
#define mp make_pair
#define all(n) (n).begin(),(n).end()
#define fi first
#define se second
#define mset(x,v) memset((x),(v),sizeof(x))

typedef pair<int, int> PII;
typedef long long ll;

const int MOD = 1e9+7;

int main() {

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

	int n,cnt=0;
	cin >> n;
	bool ok = false;
	for (int i=0;i<n;i++) {
		int a,b;
		cin >> a >> b;
		if (a==b) cnt++;
		else cnt=0;
		if (cnt==3) ok = true;
	}
	if (ok) cout << "Yes\n";
	else cout << "No\n";
}

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

int main(){
	string s;
	cin >> s;
	int a= 0;
	int b = 0;
	rep(i,s.size()){
		if(s[i] == '1') a++;
		if(s[i] == '0') b++;
	}
	cout << 2 * min(a, b) << endl;
	
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
    char c;
    scanf("%c", &c);
    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
        printf("vowel\n");
    } else {
        printf("consonant\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int dp[100000][26];//s[i]からスタートしていくつたどればchar'j'にたどりつけるか
int main()
{
	string s,t;
	ll ans=0;
	cin>>s>>t;
	string tmp=s+s;
	fill(dp[0],dp[100000],1e8-1);
	//最後の文字を調べる
	for(int i=s.size();i<tmp.size();i++)
		dp[s.size()-1][tmp[i]-'a']=min(dp[s.size()-1][tmp[i]-'a'],i-(int)s.size()+1);
	//最後から2文字目以降は直後の文字を除いてすべて次の文字+1
	for(int i=s.size()-2;i>-1;i--)
	{
		for(int j=0;j<26;j++)
		{
			if(dp[i+1][j]!=1e8-1)
				dp[i][j]=dp[i+1][j]+1;
		}
		dp[i][tmp[i+1]-'a']=1;
	}
	int ind=0;
	if(t[ind]==s[0])
		ind++;
	for(;ind<t.size();ind++)
	{
		//cerr<<dp[ans%s.size()][t[ind]-'a']<<endl;
		if(dp[ans%s.size()][t[ind]-'a']==1e8-1)
		{
			cout<<-1<<endl;
			return 0;
		}
		ans+=dp[ans%s.size()][t[ind]-'a'];
	}
	cout<<ans+1<<endl;
	return 0;
}

Measured memory_bytes: 10880
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int  a, b;
	cin >> a >> b;
	int ma,mi;
	ma = max(a, b), mi = min(a, b);
	for (int i = 0;i <ma;i++) cout << mi ;
	cout << endl;
	return 0;
}

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, n) for (int i = 1; i <= (n); i++)
using ll = long long;
using Grid = vector<vector<char>>;

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    Grid grid(H, vector<char>(W));
    rep(i,H) rep(j,W) {
        cin >> grid[i][j];
    }
    int ans = 0;

    for (int bh = 0; bh < (1 << H); bh++) {
        for (int bw = 0; bw < (1 << W); bw++) {
            int sum = 0;
            for (int i = 0; i < H; i++) {
                if (bh & (1 << i))
                    continue;
                for (int j = 0; j < W; j++) {
                    if (bw & (1 << j))
                        continue;
                    if (grid[i][j] == '#')
                        sum++;
                }
            }
            if (sum == K)
                ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
import collections
n=int(input())
#a,b=map(int,input().split())
#a=list(map(int,input().split()))
#n=int(input())
#s=input()
mod=10**9+7
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
d=[0]*1000

for i in range(n,1,-1):
  for j in prime_factorize(i):
    d[j]+=1
ans=1

for i in d:
  ans*=(i+1)
  ans%=mod
print(ans%mod)
  
  

Measured memory_bytes: 3316
# D
N = int(input())
As = list(map(int, input().split()))

items = {}
for a in As:
    items[a] = items[a]+1 if a in items.keys() else 1

sum_items = 0
for k in items.keys():
    if items[k] >= 2:
        sum_items += (items[k]*(items[k]-1))/2
sum_items = int(sum_items)
res = [0] * len(As)
for i,k in enumerate(As):
    res[i] = sum_items 
    if items[k] >= 2:
        res[i] -= (items[k]-1)

print(*res, sep="\n")

Measured memory_bytes: 28304
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    int N, R, T; cin >> N >> R >> T;
    vector<int> bot(R), add(R), pos(N), p(N);
    for(int i=0; i<N; i++) cin >> p[i];

    int ans = 0;
    for(int t=0; t<T; t++) {
        for(int i=0; i<N; i++) {
            int dst = (pos[i] + p[i]) % R;
            if(bot[dst] == 0) ans++;
            else bot[dst]--;
            if(t) add[dst]++;
            pos[i] = dst;
        }

        for(int i=0; i<R; i++) bot[i] += add[i];
        fill(add.begin(), add.end(), 0);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3084
#include <iostream>
using namespace std;
int main(void){
    int d, n;
    cin >> d >> n;
    int j = 1;
    if(d > 0){
        for(int i = 0; i < d; i++){
        j *= 100;
    }}else{
        j = 1;}
    if(n != 100){
    j *= n;
    }else{
        j*= 101;
    }
    
    cout << j;
    
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;
#define debug(x) cerr << #x << ": " << (x) << "\n";

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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;
};

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

  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
};


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

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

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

const int N = 2e5+23;

pair<long long, long long> a[N];
int n;

int closest(int x, int y) {
  long long d = 2e9;
  int ret = -1;
  for (int i = 0; i < n; ++i) {
    long long nd = abs(x-a[i].first)+abs(y-a[i].second);
    if (nd < d) {
      d = nd;
      ret = i;
    }
  }
  return ret;
}

void solve() {
  scanf("%d", &n);
  long long maX = -1e9, maY = -1e9, miX = 1e9, miY = 1e9;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a[i].first, &a[i].second);
    maX = max(maX, a[i].first);
    miX = min(miX, a[i].first);
    maY = max(maY, a[i].second);
    miY = min(maY, a[i].second);
  }
  int corners[8] = {closest(miX, maY), closest(maX, maY),
		    closest(miX, miY), closest(maX, miY),
                    closest(0  , maY), closest(0  , miY),
		    closest(maX, 0  ), closest(miX, 0  )};
  long long ans = 0;
  for (int i = 0; i < 7; ++i) {
    for (int j = i+1; j < 8; ++j) {
      if (corners[i] == corners[j]) continue;
      long long nd = abs(a[corners[j]].first-a[corners[i]].first)+
	             abs(a[corners[j]].second-a[corners[i]].second);
      ans = max(nd, ans);
    }
  }
  printf("%lld", ans);
}

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


Measured memory_bytes: 6956
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
int n;
int bit[100010];
void add(int v, int x) {

	while (v <= n)
	{
		bit[v] += x;
		v += v & -v;
	}
}

ll sum(int v) {
	ll r = 0;
	while (v > 0)
	{
		r += bit[v];
		v -= v & -v;
	}
	return r;
}

void solv() {
	int q;
	cin >> n >> q;
	int com[100010], x[100010], y[100010];
	for (size_t i = 0; i < q; i++)
	{
		cin >> com[i] >> x[i] >> y[i];
	}

	for (size_t i = 0; i < q; i++)
	{
		int c = com[i], x1 = x[i], y1 = y[i];
		if (c == 0) {
			add(x1, y1);
		}
		else {
			ll r = sum(y1) - sum(x1 - 1);
			cout << r << endl;
		}
	}
}


int main() {
	//	COMinit();
	solv();

	return 0;
}



Measured memory_bytes: 4660
leftB = []
rightA = []
both = []
ans = 0

N = gets.to_i
N.times do
  s = gets.chomp
  ans += s.scan(/AB/).length
  if s[0] == "B" and s[s.length - 1] == "A"
    both << s
  elsif s[0] == "B"
    leftB << s
  elsif s[s.length - 1] == "A"
    rightA << s
  end
end

if both.length > 0
  ans += both.length - 1
  if leftB.length > 0
    leftB.pop
    ans += 1
  end
  if rightA.length > 0
    rightA.pop
    ans += 1
  end
end

while leftB.length > 0 and rightA.length > 0
  leftB.pop
  rightA.pop
  ans += 1
end

puts ans

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

int main(){
  string s;
  cin >> s;
  cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
 
 
def ruizyou(x, n, S=1):
    
    S = 1
    for _ in range(n):
        S = (S*x)%(1e9+7)
    
    return S
    
a = int( ruizyou(10, N) + ruizyou(8, N) - ruizyou(9, N)*2 )
 
print(int(a%(1e9+7)))

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

#define db(x) cerr << #x ": " << (x) << '\n';

#define int long long

using namespace std;

typedef long long ll;

typedef long double ld;

const int oo = 1e18;

string cad;

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

    cin >> cad;

    if(cad[0] == cad[1] && cad[1] == cad[2])cout << "No" << '\n';
    else cout << "Yes" << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> v(n);
    int sum = 0;
    for(int i = 0;i < n;++i)
    {
        cin >> v.at(i);
        sum += v[i];
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    int dlimit;
    if(sum % (4 * m) == 0)
        dlimit = sum / (4 * m);
    else
        dlimit = sum / (4 * m) + 1;
    
    
    if(v[m - 1] >= dlimit)
    {
        cout << "Yes\n";
    } 
    else
    {
        cout << "No\n";
    }
}

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

const int MAX = 1e7;
ll fac[MAX], finv[MAX], inv[MAX];

//前処理
void COMinit (){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; 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 COM(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int main(){
    int n,k;
    cin >> n >> k;
    COMinit();
    ll ans = 0;
    for(int i = 0; i <= min(n-1,k); i++){
        ans += COM(n,i)*COM(n-1,i);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 234752
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

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

    if (a > b) {
      tmp = a;
      a = b;
      b = tmp;
    }
    if (b > c) {
      tmp = b;
      b = c;
      c = tmp;
    }
    if (a > b) {
      tmp = a;
      a = b;
      b = tmp;
    }

    System.out.println(a +" " +  b + " " + c);
    sc.close();
  }
}


Measured memory_bytes: 26248
#include <iostream>
#include <cassert>
#include <vector>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
#include <sstream>
#include <iterator>
#include <map>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <limits>
#include <typeinfo>
#include <numeric>
 
#include <stdio.h>
#include <string.h>
 
using namespace std;
  
int main(int argc, char* argv[])
{
 
	int r,g,b;

	cin >> r >> g >> b;

	cout << ((r*100+g*10+b) % 4 ==0 ? "YES" : "NO") << endl;
 
	return 0;
 
}

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

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

using namespace std;
using lint=long long;

const long long INF=1LL<<61;

class starry_sky_tree{
	int n;
	vector<lint> dat1,dat2;

	void add(int l,int r,int a,int b,int u,lint val){
		if(b<=l || r<=a) return;
		if(l<=a && b<=r){ dat1[u]+=val; return; }

		add(l,r,a,(a+b)/2,2*u+1,val);
		add(l,r,(a+b)/2,b,2*u+2,val);

		dat2[u]=max(dat2[2*u+1]+dat1[2*u+1],dat2[2*u+2]+dat1[2*u+2]);
	}

	lint query_max(int l,int r,int a,int b,int u){
		if(b<=l || r<=a) return -INF;
		if(l<=a && b<=r) return dat1[u]+dat2[u];

		lint res1=query_max(l,r,a,(a+b)/2,2*u+1);
		lint res2=query_max(l,r,(a+b)/2,b,2*u+2);
		return max(res1,res2)+dat1[u];
	}

public:
	starry_sky_tree(int N){
		for(n=1;n<N;n*=2);
		dat1.assign(2*n,0);
		dat2.assign(2*n,0);
	}

	void add(int l,int r,lint val){ add(l,r,0,n,0,val); }
	void update_max(int x,lint val){
		lint tmp=query_max(x,x+1);
		if(tmp<val) add(x,x+1,val-tmp);
	}

	lint query_max(int l,int r){ return query_max(l,r,0,n,0); }
};

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<int> l(m),r(m),val(m);
	rep(i,m) scanf("%d%d%d",&l[i],&r[i],&val[i]), l[i]--;

	vector<vector<int>> L(n),R(n+1);
	rep(i,m){
		L[l[i]].emplace_back(i);
		R[r[i]].emplace_back(i);
	}

	starry_sky_tree SS(n);
	SS.add(0,n,-(1LL<<61));

	lint ans=0;
	lint score=0;
	rep(x,n){
		for(int idx:R[x]){
			SS.add(0,l[idx],-val[idx]);
			score-=val[idx];
		}
		for(int idx:L[x]){
			SS.add(0,l[idx],val[idx]);
			score+=val[idx];
		}

		SS.update_max(x,max(score,SS.query_max(0,x)));
		ans=max(ans,SS.query_max(x,x+1));
	}

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

	return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

using cost_t=int;

struct Edge {
  int from, to;
  cost_t cost;
  Edge(int from, int to, cost_t cost) : from(from), to(to), cost(cost) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

const cost_t INF=1e9;
bool bellman_ford(int s,Graph& g,vector<cost_t>& d){
  int n = g.size();
  d.assign(n,INF);
  d[s] = 0;
  bool update=true;
  for(int i=0;update;i++){
    if(i==n){
      return false;
    }
    update=false;
    for(int i=0;i<n;i++){
      if(d[i]==INF) continue;
      for(auto &e:g[i]){
        cost_t tmp = d[i] + e.cost;
        if(tmp<d[e.to]){
          d[e.to]=tmp;
          update=true;
        }
      }
    }
  }
  return true;
}

void dijkstra(int s,Graph& g,vector<cost_t>& d){
  int n=g.size();
  d.assign(n,INF);
  d[s]=0;
  using Item=pair<cost_t,int>;
  priority_queue<Item,vector<Item>,greater<Item>> que;
  que.push(Item(0,s));
  while(!que.empty()){
    auto tmp=que.top(); que.pop();
    int v=tmp.second;
    if(d[v]<tmp.first) continue;
    for(auto &e:g[v]){
      if(d[v]+e.cost<d[e.to]){
        d[e.to]=d[v]+e.cost;
        que.push(Item(d[e.to],e.to));
      }
    }
  }
}

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

  int n, m, p; cin >> n >> m >> p;
  Graph g(n), tmp(n), tmprev(n);
  REP(i, m) {
    int a, b, c; cin >> a >> b >> c;
    a--; b--; c -= p;
    g[a].push_back(Edge(a, b, -c));
    tmp[a].push_back(Edge(a, b, 1));
    tmprev[b].push_back(Edge(b, a, 1));
  }

  vi d1(n), d2(n);
  dijkstra(0, tmp, d1);
  dijkstra(n-1, tmprev, d2);

  vector<bool> use(n, false);
  REP(i, n) {
    use[i] = d1[i] + d2[i] < INF;
  }

  Graph newg(n);
  REP(i, n) {
    REP(j, SZ(g[i])) {
      auto e = g[i][j];
      if(use[e.from] && use[e.to]) {
        newg[e.from].push_back(Edge(e.from, e.to, e.cost));
      }
    }
  }

  vector<cost_t> d(n);
  bool ok = bellman_ford(0, newg, d);

  cout << (ok ? max(0, -d[n-1]) : -1) << endl;


}
























Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(),i.end()
#define debug(i) std::cout << i << "\n"



const int INF = 100000000;
const ll MOD = 1000000007;

ll pow_mod(ll x, ll y, ll mod)
{
	if (y == 0)
		return 1;
    if(y%2){
        return (x*pow_mod(x,y-1,mod))%mod;
    }else{
        return pow_mod(x*x,y/2,mod);
    }
}

int main()
{
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!

  ll a,b,c;
  std::cin>>a>>b>>c;
  if(a>=b+c){
    std::cout<<0;
  }else{
    std::cout<<b+c-a;
  }
	return 0;
}

Measured memory_bytes: 256
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n;
  rd(n);
  if (n == 1) {
    writeln("Hello World");
  } else {
    int a, b;
    rd(a);
    rd(b);
    writeln(a + b);
  }
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


Measured memory_bytes: 256
using System;

namespace Atcoder
{
    class ABC162_A
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            if(str[0] == '7' || str[1] == '7' || str[2] == '7')
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 25892
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {

	int A, B, C, D;
	int H, K;

	cin >> A;
	cin >> B;
	cin >> C;
	cin >> D;

	H = A / D;
	if (A % D > 0) {
		H++;
	}
	K = C / B;
	if (C % B > 0) {
		K++;
	}
	if (H >= K) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;

}

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

int main () {
    int N;
    cin >> N;
    vector <int> vec(N);
    for (int i=0; i<N; i++) {
        cin >> vec.at(i);
    }
    
    int sum=0;
    
    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            sum+=vec.at(i)*vec.at(j);
        }
    }
    for (int i=0; i<N; i++) {
        sum-=vec.at(i)*vec.at(i);
    }
    cout << sum/2 << endl;
}
            
    


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    int H, N;
    cin >> H >> N;
    vector<ll> A(N), B(N);
    for(int i=0; i<N; i++) cin >> A[i] >> B[i];

    ll M = 20010;
    Vvec<ll> dp(N+1, vector<ll>(M+4, 1e+18));
    for(int i=0; i<=N; i++) dp[i][0] = 0;
    for(int i=1; i<=N; i++){
        for(int j=1; j<=M; j++){
            dp[i][j] = dp[i-1][j];
            if(j-A[i-1]>=0) dp[i][j] = min(dp[i-1][j], dp[i][j-A[i-1]] + B[i-1]);
        }
    }

    ll ans = 1e+18;
    for(int j=H; j<=M; j++){
        ans = min(ans, dp[N][j]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 160640
#include<bits/stdc++.h>
using namespace std;
#define int long long

int cnt[10010];

int32_t main(){
    int n, p; cin >> n >> p;
    string s; cin >> s;
    if(p == 2 || p == 5){
        int ans=0;
        for(int i=0; i<n; ++i) if((s[i]-'0')%p == 0) ans+= i+1;
        cout << ans << endl;
        exit(0); 
    }
    int ans = 0;
    int pre = 0; cnt[0]=1;
    int pow10=1;
    for(int i=n-1; i>=0; --i){
        pre=(pre+(s[i]-'0')*pow10)%p, pow10=(pow10*10)%p;
        ans+=cnt[pre];
        ++cnt[pre];
    }
    cout << ans << endl;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000007
#define maxn 1000000009b
int main()
{
    int H, W;
    cin >> H >> W;
    string S[H];
    ll L[H][W], R[H][W], D[H][W], U[H][W];
    for (int i = 0; i < H; i++)
    {
        cin >> S[i];
    }
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (S[i][j] == '#')
            {
                L[i][j] = 0;
            }
            else if (j == 0)
            {
                L[i][j] = 1;
            }
            else
            {
                L[i][j] = L[i][j - 1] + 1;
            }
            if (S[i][j] == '#')
            {
                U[i][j] = 0;
            }
            else if (i == 0)
            {
                U[i][j] = 1;
            }
            else
            {
                U[i][j] = U[i - 1][j] + 1;
            }
        }
    }
    for (int i = H - 1; i >= 0; i--)
    {
        for (int j = W - 1; j >= 0; j--)
        {
            if (S[i][j] == '#')
            {
                R[i][j] = 0;
            }
            else if (j == W - 1)
            {
                R[i][j] = 1;
            }
            else
            {
                R[i][j] = R[i][j + 1] + 1;
            }
            if (S[i][j] == '#')
            {
                D[i][j] = 0;
            }
            else if (i == H - 1)
            {
                D[i][j] = 1;
            }
            else
            {
                D[i][j] = D[i + 1][j] + 1;
            }
        }
    }
    ll count = 0;
    ll ans = 0;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            count = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3;
            ans = max(ans, count);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 129408
import sys
readline = sys.stdin.readline

A = [list(map(int, readline().split())) for _ in range(3)]

G = [[0, 0, 0] for _ in range(3)]
N = int(readline())
B = [int(readline()) for _ in range(N)]
for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                G[i][j] = 1

ans = 'No'

if G[0][0] and G[1][1] and G[2][2]:
    ans = 'Yes'
if G[0][2] and G[1][1] and G[2][0]:
    ans = 'Yes'

for i in range(3):
    if G[i][0] and G[i][1] and G[i][2]:
        ans = 'Yes'
    if G[0][i] and G[1][i] and G[2][i]:
        ans = 'Yes'

print(ans)
    

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

string s;

int count_joi() {
    int count = 0;
    for (string::iterator i = s.begin(); i != s.end(); i++) {
        if (*i == 'J') {
            if (*(i+1) == 'O' && *(i+2) == 'I') count++;
        }
    }
    return count;
}

int count_ioi() {
    int count = 0;
    for (string::iterator i = s.begin(); i != s.end(); i++) {
        if (*i == 'I' && *(i+1) == 'O' && *(i+2) == 'I') count++;
    }
    return count;
}

int main() {
    while (cin >> s) {
        cout << count_joi() << endl;
        cout << count_ioi() << endl;
    }
    return 0;
}

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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<'\n';exit(0);}

void solve() {
  int n, w; cin >> n >> w;
  vector<long long> weight(n), value(n);
  for(int i=0; i<n; ++i) cin >> weight[i] >> value[i];
  
  vector<vector<long long>> dp(n+1,vector<long long>(w+1));
  for(int i=0; i<n; ++i) {
    for(int j=0; j<=w; ++j) {
      if(j >= weight.at(i)) dp.at(i+1).at(j) = max(dp.at(i).at(j), dp.at(i).at(j-weight.at(i))+value.at(i));
      else dp.at(i+1).at(j) = dp.at(i).at(j);
    }
  }
  cout << dp.at(n).at(w) << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 83192
/*
░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░▐▐▐▐▐▐░░░░░░░
░░░░░░░░░░▐▐▌▌▌▌▌▌▐▐░░░░░
░░░░░░░░░▐▌▌▌▌▌▌▌▌▌▌▐░░░░
░░░░░░░░▐░░▌◐░▌▌▌◐░░░▐░░░
░░░░░░░░▐░░░░░░░░░░░░▐░░░  
░░░░░░░░▐░░░░░▐░░░░░░▐░░░
░░░░░░░░░▐░░░▐▐▐░░░░░▐░░░
░░░░░░░░░▐░░░░░░░░░░▐░░░░
░░░░░░░░░░▐░░████░░▐░░░░░
запускаем░░▐░░░░░░░▐░░░░░
░░░░Влада░░▐░░░░░░▐░░░░░░
░░░Макеева░░▐░░░░▐░░░░░░░
░░░░░░░░░░░░░▐▐▐▐░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define zhfs main
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define re return
#define forn(i, n) for (int i = 1; i <= n; i++)
int zhfs()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 1; ; i++)
	{
		sum += i;
		if (sum >= n)
		{
			cout << i << endl;
			return 0;
		}
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int main(int qtd, char* nome[])
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int a[3][3];
	for(int i=0; i<3; i++)
		for(int j=0; j<3; j++)
			cin >> a[i][j];
	bool check[3][3];
	memset(check, false, sizeof check);
	int n;
	cin >> n;
	string ans = "No\n";
	while(n--){
		int x;
		cin >> x;
		for(int i=0; i<3; i++)
			for(int j=0; j<3; j++)
				if(a[i][j] == x)
					check[i][j] = true;
	}
	for(int i=0; i<3; i++)
		if(check[i][0] && check[i][0] == check[i][1] && check[i][1] == check[i][2])
			ans = "Yes\n";
		else if(check[0][i] && check[0][i] == check[1][i] && check[1][i] == check[2][i])
			ans = "Yes\n";
	if(check[0][0] && check[0][0] == check[1][1] && check[1][1] == check[2][2])
		ans = "Yes\n";
	if(check[0][2] && check[0][2] == check[1][1] && check[1][1] == check[2][0])
		ans = "Yes\n";
	cout << ans;
	
	return 0;
}

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

ac = [False] * n
wa = [0] * n

for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s == 'AC':
        ac[p] = True
    else:
        if not ac[p]:
            wa[p] += 1

a = 0
b = 0

for i in range(n):
    if ac[i]:
        a += 1
        b += wa[i]

print(*[a, b])
       

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

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

    int n;
    cin >> n;
    vector<ll> arr(n);
    for(int i=0; i<n; ++i){
        cin >> arr[i];
    }
    int ans = 0;
    sort(arr.begin(), arr.end());

    for(int i=0; i<n-2; ++i){
        for(int j=i+1; j<n-1; ++j){
            for(int k=j+1; k<n; ++k){
                if( arr[i] + arr[j] > arr[k] ){
                    if( arr[i] != arr[j] and arr[j] != arr[k]) 
                        ++ans;
                }
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3660
#include<cmath>
using namespace std;
int main(){
	int n,mi,id;
	while(cin>>n,n){
		double mx=1000000,h,w;
		for(int i=0;i<n;i++){
			cin>>id>>h>>w; h/=100;
			if(abs(mx-22)>abs(1.*w/h/h-22))mx=1.*w/h/h,mi=id;
		}
		cout<<mi<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main()
{
    int a,b,i,j,k,c=0,s;
    scanf("%d %d",&a,&b);
    while(a!=0 || b!=0)
    {
    for(i=1;i<=a;i++)
    {
        for(j=1;j<=a;j++)
        {
            for(k=1;k<=a;k++)
            {
                s=i+j+k;
                if(s==b && i!=j && j!=k && i!=k && i<j && j<k && i<k)
                {
                    c++;
                }
            }
        }
    }
    printf("%d\n",c);
    c=0;
    scanf("%d %d",&a,&b);
    }
    return 0;
}


Measured memory_bytes: 2036
h,w = map(int,input().split())
grid = []
grid_num1 = []
grid_num2 = []
for i in range(h):
    lst = list(input())
    lst.append("#")
    grid.append(lst)
    grid_num1.append([0]*w)
grid.append(["#"]*(w+1))
for j in range(w):
    grid_num2.append([0]*h)

grid_t = [list(x) for x in zip(*grid)]

for i in range(h):
    sw = []
    tar_row = grid[i]
    for j in range(w+1):
        if j == 0 and tar_row[j] == ".":
            sw.append(j)
        elif tar_row[j] == "." and tar_row[j-1] == "#":
            sw.append(j)
        elif tar_row[j] == "#" and tar_row[j-1] == ".":
            sw.append(j)
    for j in range(0,len(sw),2):
        l = sw[j]
        r = sw[j+1]
        for k in range(l, r):
            grid_num1[i][k] += r-l

for i in range(w):
    sw = []
    tar_row = grid_t[i]
    for j in range(h+1):
        if j == 0 and tar_row[j] == ".":
            sw.append(j)
        elif tar_row[j] == "." and tar_row[j-1] == "#":
            sw.append(j)
        elif tar_row[j] == "#" and tar_row[j-1] == ".":
            sw.append(j)
    for j in range(0,len(sw),2):
        l = sw[j]
        r = sw[j+1]
        for k in range(l, r):
            grid_num2[i][k] += r-l
grid_num2 = [list(x) for x in zip(*grid_num2)]

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, grid_num1[i][j] + grid_num2[i][j]-1)
print(ans)



Measured memory_bytes: 320008
<?php

fscanf(STDIN, "%d", $n);

$str = trim(fgets(STDIN));

$array = str_split($str);
$len = strlen($str);
$max = 0;
for($i=0;$i<$len;$i++){

    if($len - $i - ($max * 2) <=0){
        break;
    }
    $substr = substr($str,$i,$max);
    for($j=$i+$max;$j<(intdiv($len - $i , 2)+1+$i);$j++){
        $substr = $substr . $array[$j];

        if(substr_count($str, $substr)>1){
            $max = max($max, $j - $i + 1);

        }else{
            break;
        }
    }
}
echo $max;

Measured memory_bytes: 4856
#include <algorithm>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N, K;
  while (cin >> N >> K) {
    vector<int> mod(K, 0);
    for (int i = 1; i <= N; i++) {
      ++mod[i % K];
    }
    ll res = 0;
    for (int a = 0; a < K; a++) {
      int b = (K - a) % K;
      int c = (K - a) % K;
      if ((b + c) % K == 0) {
        res += 1ll * mod[a] * mod[b] * mod[c];
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
	long long int a,b,ans;
	scanf("%lld%lld",&a,&b);
	ans = a+b;
	if(ans%2==1){
		printf("IMPOSSIBLE");
		return 0;
	}
	else
		printf("%d",ans/2);
	return 0;
}


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

int main(){
    char c;
    cin >> c;
    if(c == 'A')    cout << 'T' << endl;
    if(c == 'T')    cout << 'A' << endl;
    if(c == 'C')    cout << 'G' << endl;
    if(c == 'G')    cout << 'C' << endl;
    return 0;
}

Measured memory_bytes: 764
#include <stdio.h>

int main(){

	long N, M;
	long x;
	long ans;

	scanf("%ld %ld", &N, &M);

	if(2 * N > M){
		ans = M / 2;
	} else {
		x = (M - 2*N) / 4;
		ans = N + x;
	}
	
	printf("%ld\n", ans);	
	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

int main(void)
{
    int n; cin >> n;
    cout << (n +1)/2 << endl;
    return 0;
}



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


int main() {
	int N = 0;
	cin >> N;

	vector< int > rabbits;
	rabbits.resize(N);
	for (int i = 0; i < N; ++i) {
		cin >> rabbits[i];
		--rabbits[i];
	}

	int num = 0;
	for (int i = 0; i < N; ++i) {
		//if (rabbits[i] > i) {
			if (rabbits[rabbits[i]] == i) {
				++num;
			}
		//}
	}

	cout << (int)num/2;

	return 0;
}


Measured memory_bytes: 768
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

struct unionfind{
  vector<int> par;
  vector<int> rank;
  unionfind(int n=1){
    init(n);
  }
  void init(int n=1){
      par.resize(n); rank.resize(n);
      for(int i=0;i<n;++i) par[i]=i,rank[i]=0;
  }
  int root(int x){
    if(par[x]==x){
      return x;
    }
    else{
      int r=root(par[x]);
      return par[x]=r;
    }
  }
  bool issame(int x,int y){
    return root(x)==root(y);
  }
  bool merge(int x,int y){
    x=root(x); y=root(y);
    if(x==y) return false;
    if(rank[x]<rank[y]) swap(x,y);
    if(rank[x]==rank[y]) ++rank[x];
    par[y]=x;
    return true;
  }
};

int main(){
  int n,m; cin >> n >> m;
  unionfind uf(n+m);
  rep(i,n){
    int k; cin >> k;
    rep(j,k){
      int l; cin >> l;
      uf.merge(i,n-1+l);
    }
  }
  bool f=1;
  rep(i,n){
    if(!(uf.issame(0,i))) f=0;
  }
  if(f){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 1792
from collections import defaultdict
n, m = map(int, input().split())
left = []
right = []
for i in range(m):
    l, r = map(int, input().split())
    left.append(l)
    right.append(r)

if min(right) >= max(left):
    print(min(right) - max(left) + 1)
else:
    print(0)


Measured memory_bytes: 11376
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_DISABLE_PERFCRIT_LOCKS
#define POPCNTI(a) __builtin_popcount(a)
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>


#include <bits/stdc++.h>
using namespace  __gnu_pbds; 
using namespace std;

 
// #ifndef _LOCAL_DEFINE
// inline int getchar_unlocked(){return _getchar_nolock();}
// inline void putchar_unlocked(char c) {_putchar_nolock(c);}
// #endif
 
typedef long long ll;  
typedef pair<int,int> pr; 
 
const ll OOl = LLONG_MAX;
const int N = 1e6+1, M = 1e6+1, OO = INT_MAX,OOmem = 0x4f4f4f4f, MOD = 1e9 + 7;

inline void WRITE_CHAR(char c)  {putchar_unlocked(c);}
 
template<typename T> 
inline bool READn (T &result) {
  int minus = 1;
  char ch;
  result=0;
  ch = (char) getchar_unlocked();
  if(ch!='-') while (!isdigit(ch) && ch!=EOF) ch= (char) getchar_unlocked(), minus = (ch == '-'? -1 : minus);
 
  if(ch==EOF) return false;
  while (isdigit(ch))  result = result*10 + (int) (ch - '0'),ch = (char) getchar_unlocked();
  
  result *= minus;
  return ch != '\n';
}
template<typename T>
inline void WRITEn(T x) {
  if (x < 0) {putchar_unlocked('-'); x = -x; }
  char writeBuffer[20], *writePtr = writeBuffer;
  do {
    *writePtr++ = (char)('0' + x % 10);
    x /= 10;
  }
  while (x);
  do  { putchar_unlocked(*--writePtr); }
  while (writePtr > writeBuffer);
}
inline bool Read_CHAR(char &c)
{
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  c = READ_CHARACTER;
  return true;
} 
inline bool READ_CHAR_ARRAY(char (&x)[N]) {
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  char *ptr = &x[0];
  while ((READ_CHARACTER != '\n' && READ_CHARACTER != '\t' && READ_CHARACTER != ' ' && READ_CHARACTER != EOF)) *ptr++ = READ_CHARACTER, READ_CHARACTER = (char)getchar_unlocked();
  *ptr = '\0';
  return true;
}
inline void WRITE_CHAR_ARRAY(const char *x) {
  while(*x != '\0')
    putchar_unlocked(*x++);
}
int n,k,arr[101];
int memo[N][2];
int solve(int pile=k,bool flag = 0)
{
  int &ret = memo[pile][flag];
  if(~ret) return !ret;

  ret = 0;
  for(int i=0;i<n;++i)
    if((pile-arr[i])>=0) ret = max(ret,solve(pile-arr[i],!flag)); 
    
  
  return !ret;
}
int main()
{
  
  memset(memo,-1,sizeof memo);
  READn(n),READn(k);
  for(int i=0;i<n;++i) READn(arr[i]);
  if(!solve()) WRITE_CHAR_ARRAY("First");
  else WRITE_CHAR_ARRAY("Second");

  
  return 0;
}




Measured memory_bytes: 11392
#include<stdio.h>
#include<string.h>
int main(){
    char s[100];
    int k;
    scanf("%d",&k);
    scanf("%s",&s);
    if(k>=strlen(s)){
        printf("%s",s);
    }else{
        for(int i=0;i<k;i++){
            printf("%c",s[i]);
        }
        printf("...\n");
    }
    return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int main(void)
{
    int N;
    cin >> N;
    auto B = vc(int, N-1);
    fa(i, B) cin >> i;
    int ans = B[0] + B[N-2];
    lpsb(i, 2, N) ans += min(B[i-2], B[i-1]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256