akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
 
using namespace std;
 
int main() {
        int i,j;
    int N, A[100];
    int s_c=0; //swap_count
    
    cin >> N;
    for(i=0;i<N;i++) cin >> A[i];
    
    for(i=0;i<N;i++){
        for(j=N-1;j>i;j--){
            if(A[j]<A[j-1]){
                swap(A[j],A[j-1]);
                s_c++;
            }
        }
    }
    
    for(i=0;i<N;i++){
        cout << A[i];
        if(i!=N-1) cout << ' ';
        else cout << endl;
    }
    cout << s_c++ << endl;
    
        return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>

static const int N = 100;

int min(int a,int b){
  if(a>b)return b;
  else return a;
}

int main(){
  int i,j,k,l,n,p[N + 1],m[N+1][N+1];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }
  for(i=1;i<=n;i++)m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i+l-1;
      m[i][j]=(1<<21);
      for(k=i;k<=j-1;k++){
	m[i][j] = min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  printf("%d\n",m[1][n]);

  return 0;
}

  



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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }


template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

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

    int n, k;
    cin >> n; k = 2;
    V<ll> dp(n, TEN(18)); dp[0] = 0;
    V<ll> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        for (int j = 1; j <= k; j++) {
            if (i - j < 0) break;
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }
    cout << dp.back() << endl;
    return 0;
}


Measured memory_bytes: 1792
for i in range(5):

    num = 0
    num2 = 0

    s = input()
    S = list(s)

    for i in range(len(S)-2):

        if S[i] == "J" and S[i+1] == "O" and S[i+2] == "I":
            num += 1
        if S[i] == "I" and S[i+1] == "O" and S[i+2] == "I":
            num2 += 1

    print (num)
    print (num2)



Measured memory_bytes: 5592
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int SIZE = 50100;

int main(int argc, char *argv[]) {
	// make sieve
	vector<bool> sieve(SIZE, true);
	vector<int> prime;
	for (int i = 2; i < SIZE; i++) {
		if (sieve[i]) {
			prime.push_back(i);
			//printf("%d\n", i);
			for (int j = i+i; j < SIZE; j+=i) {
				sieve[j] = false;
			}
		}
	}
	sort(prime.begin(), prime.end());
	// load data
	int rcv;
	const int prime_size = static_cast<int>(prime.size());
	while (EOF != fscanf(stdin, "%d", &rcv)) {
		for (int i = 0; i < prime_size; i++) {
			if (prime[i] > rcv) {
				if (prime[i-1] != rcv)
					printf("%d %d\n", prime[i-1], prime[i]);
				else
					printf("%d %d\n", prime[i-2], prime[i]);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <string>
#include <chrono>
#include <random>

using namespace std;

#define sqr(x) x * x
#define all(x) x.begin(), x.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;
typedef long long ll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int& e : a) cin >> e;
	double res = 0;
	for (int i = 0; i < n; ++i)
		res += (double)1 / (double)a[i];
	cout << 1 / res;
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int par[100010];
int depth[100010];
void init(int n){
  for(int i=0;i<=n;i++){
      par[i]=i;
      depth[i]=0;
  }
}
int root(int x){
  return par[x]==x?x:par[x]=root(par[x]);
}
bool same(int x,int y){
  return root(x)==root(y);
}
void unite(int x,int y){
  x=root(x);
  y=root(y);
  if(x==y)return;
  if(depth[x]<depth[y]){
      par[x]=y;
  }else{
      par[y]=x;
      if(depth[x]==depth[y])depth[x]++;
  }
}
int main(){
    ll n;cin>>n;
    vector<pair<ll,pll> >es(0);
    vector<pair<pll,ll> >p(n);
    rep(i,n){
        ll x,y;cin>>x>>y;
        p[i]=(make_pair(make_pair(x,y),i));
    }
    sort(all(p));
    rep(i,n-1){
        es.pb(mp(p[i+1].first.first-p[i].first.first,mp(p[i].second,p[i+1].second)));
    }
    rep(i,n){
        swap(p[i].first.first,p[i].first.second);
    }
    sort(all(p));
    rep(i,n-1){
        es.pb(mp(p[i+1].first.first-p[i].first.first,mp(p[i].second,p[i+1].second)));
    }
    init(n-1);
    sort(all(es));
    ll cnt=0;
    rep(i,es.size()){
        if(!same(es[i].second.first,es[i].second.second)){
            unite(es[i].second.first,es[i].second.second);
            cnt+=es[i].first;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 10864
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  ll a,b,c;cin>>a>>b>>c;
  if(a%2==0||b%2==0||c%2==0){
    cout<<0<<endl;
    return 0;
  }
  cout<<min({a*b,b*c,c*a})<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
#include <cctype>
#include <ctype.h>
#define ll long long
using namespace std;
int main()
{

    int n;
    string s;
    cin >>n>>s;
    int cou = 0;
  if(n==3)
  {
    if(s[0]=='A'&&s[1]=='B'&&s[2]=='C')
    {
      cout <<1<<endl;
    }
    else{
      cout <<0 <<endl;
    }
    return 0;
  }
  
    for (int i = 0; i < s.size()-2 ; i++)
    {
     
      
    
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
        {
            cou++;
        }
    }
    cout << cou << endl;
    return 0;
}


Measured memory_bytes: 256
def max(a,b) a>b ? a:b end

def distance(x1, y1, x2, y2)
  dx, dy = x1 - x2, y1 - y2
  Math.sqrt(dx**2 + dy**2)
end

# 時間t, 熱源位置(x,y)で焼ける肉の個数を返す
# t + 0.0000000001 の 0.0000000001 はtan,cosの計算による誤差をカバー(だと思う)
def yaketa_niku(t, x, y)
  res = 0
  N.times do |i|
    if t + 0.0000000001 >= C[i] * distance(x, y, X[i], Y[i])
      res += 1
    end
  end
  res
end

# [二円の交点] http://godfoot.world.coocan.jp/circle-circle.htm
def circle_cross_point(t, xyc1, xyc2)
  x1, y1, x2, y2 = xyc1[0], xyc1[1], xyc2[0], xyc2[1]
  d = distance(x1, y1, x2, y2)
  r1, r2 = t/xyc1[2], t/xyc2[2]

  return if d > r1 + r2 || d < (r1 - r2).abs
  
  sita = Math.atan2(y2-y1, x2-x1)
  alf = Math.acos((r1**2 + d**2 - r2**2)/(2*r1*d))

  nx1 = x1 + r1 * Math.cos(sita + alf)
  ny1 = y1 + r1 * Math.sin(sita + alf)
  nx2 = x1 + r1 * Math.cos(sita - alf)
  ny2 = y1 + r1 * Math.sin(sita - alf)
  [[nx1,ny1], [nx2,ny2]].uniq
end

# ci*(熱源からの距離) <= t
# (熱源からの距離) <= t/ci
# 時間tの時、肉が焼ける円(中心は肉の座標、半径はt/ci)があり、
# 2つの円を選んだ時の交点の座標を熱源の候補位置を計算する
# 計算した熱源の位置を使って肉が時間内に焼けた個数の最大値を計算し返す
def f(t)
  heater_pos = XY
  XYC_comb.each do |xyc1, xyc2|
    tmp = circle_cross_point(t, xyc1, xyc2)
    heater_pos += tmp if tmp
  end
  res = 0
  heater_pos.each do |x, y|
    res = max(res, yaketa_niku(t, x, y))
  end
  res
end

#時間で二分探索
def main()
  l = 0.0
  r = 400000.0
  100.times do
    m = (l+r)/2.0
    if f(m) < K
      l = m
    else
      r = m
    end
    break if r-l < 10**(-7)
  end
  puts sprintf("%.10f", l)
end

N, K = gets.split.map(&:to_i)
XYC = N.times.map{gets.split.map(&:to_f)}

=begin
N=60
K=30
aaa=Array.new(N)
N.times do |i|
  aaa[i] = [-1000 + 30*i, -1000 + 30*i, rand(1..100)].map(&:to_f)
end
XYC=aaa
=end

X, Y, C = XYC.transpose
XY = [X, Y].transpose
XYC_comb = XYC.combination(2).to_a

main


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

int main()
{
	int n,x,t;
	scanf("%d %d %d",&n,&x,&t);
	int ans = 0;
	int time = 0;
	while(ans < n)
	{
		ans += x;
		time += t;
	}
	printf("%d",time);
	return 0;
}

Measured memory_bytes: 3812
#include<iostream>
#include<vector>
#include<list>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
bool r[200000];
int main() {
	int n, m, q;
	cin >> n >> m >> q;
	list<int>a;
	fill(r, r + n, true);
	a.push_back(-1);
	for (int i = 0; i < n; i++) a.push_back(i);
	list<int>::iterator it=a.begin(), it2;
	it++;
	for (int z = 0; z < m; z++) {
		int s;
		cin >> s;
		if (s % 2 == 0) {
			for (int i = 0; i < s; i++) {
				it++;
				if (it == a.end()) {
					it = a.begin();
					it++;
				}
			}
		}
		else {
			for (int i = 0; i < s; i++) {
				it--;
				if (it == a.begin()) {
					it = a.end();
					it--;
				}
			}
		}
		it2 = it;
		r[(*it)] = false;
		it2++;
		a.erase(it);
		it = it2;
		if (it == a.end()) {
			it = a.begin();
			it++;
		}
	}
	for (int z = 0; z < q; z++) {
		int q;
		cin >> q;
		if(r[q])
		cout << 1 << endl;
		else cout << 0 << endl;
	}
}

Measured memory_bytes: 9528
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){cin >> a[i];}
    sort(a.begin(), a.end());
    int ans = 0;
    for (int c = 0; c < n; ++c ) {
    	int r = c + 1;
    	for(int l = 0; l < c; ++l){    	    
            while ( r  < n && a[l] + a[c]  > a[r]) {
                ++r;
                ans += (c-l);               
            }        
        }      
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def doIt(t, c):
	c = c.split()
	t = list(t)
	if c[0] == 'replace':
		j = 0
		temp = [x for x in c[3]]
		for i in range(int(c[1]), int(c[2]) + 1):
			t[i] = temp[j]
			j += 1
	elif c[0] == 'reverse':
		temp = t[int(c[1]):int(c[2]) + 1]
		j = len(temp) - 1
		for i in range(int(c[1]), int(c[2]) + 1):
			t[i] = temp[j]
			j -= 1
	else:
		print(''.join(t[int(c[1]):int(c[2])+1]))
	return ''.join(t)

text = input()
n = int(input())
while n > 0:
	text = doIt(text, input())
	n -= 1


Measured memory_bytes: 5636
n = int(input())
p = list(map(int, input().split()))
cnt = 0

for i in range(1, n - 1):
    max_p = max(p[i - 1], p[i], p[i + 1])
    min_p = min(p[i - 1], p[i], p[i + 1])
    if max_p != p[i] and min_p != p[i]:
        cnt += 1

print(cnt)


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10**8)

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]

t = dict()
for i in range(1, n+1):
    t[i] = set()
for a, b in ab:
    t[a].add(b)
    t[b].add(a)

cnt = [0] * n
s = set()
for p, x in px:
    cnt[p-1] += x

def solve(p):
    s.add(p)
    for c in t[p]:
        if c not in s:
            cnt[c-1] += cnt[p-1]
            solve(c)
solve(1)
print(*cnt, sep=' ')


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

using ll=long long;

#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(e,E) for(const auto &e:E)

using namespace std;

int N,M,P;
ll from[2500],to[2500];

vector<pair<int,int>> E[3030];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>P;
	FOR(i,M) {
		cin>>x>>y>>r;
		E[x-1].push_back({y-1,r});
	}
	
	FOR(i,N) from[i]=-(1LL<<60);
	from[0]=0;
	ll ma=-1LL<<60;
	FOR(i,10000) {
		FOR(j,N) to[j]=from[j];
		FOR(x,N) if(from[x]>-(1LL<<60)) FORR(e,E[x]) {
			to[e.first]=max(to[e.first],from[x]+e.second-P);
			if(i>=5100&&to[e.first]>from[e.first]) to[e.first]=1LL<<60;
		}
		
		ma=max(ma,to[N-1]);
		swap(from,to);
	}
	ma=max(ma,0LL);
	if(ma>=1LL<<59) ma=-1;
	cout<<ma<<endl;
	
	
}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

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

typedef long long lint;
typedef long double ldouble;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = 1e18;
const lint MOD = 1e9 + 7;
const lint inv = 1e9 + 5;

lint power(lint x, lint n){
    lint t = 1;
    while(n > 0){
        if(n & 1){
            t *= x;
            t %= MOD;
        }
        x *= x;
        x %= MOD;
        n >>= 1;
    }
    return t;
}

lint nCr(lint n, lint r){
    r = min(r, n-r);
    lint multiple = 1, divide = 1;
    rep(i, r){
        multiple *= (n - i);
        multiple %= MOD;
        divide *= (i + 1);
        divide %= MOD;
    }
    lint ans = multiple * power(divide, inv);
    ans %= MOD;
    return ans;
}

lint nHr(lint n, lint r){
    return nCr(n + r - 1, r);
}

int main(){
    lint n, m;
    cin >> n >> m;
    lint ans = 1;
    for(lint i = 2 ; i * i <= m ; i++){
        lint cnt = 0;
        while(m % i == 0){
            m /= i;
            cnt++;
        }
        ans *= nHr(n, cnt);
        ans %= MOD;
    }
    if(m != 1){
        ans *= nHr(n, 1);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define bitrep(X,N) for(ll X = 0; X < (1 << (N)); X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 


using namespace std;


int main(){

    int n;
    cin >> n;

    vector<int> a;
    vector<int> b;
    vector<int> c;
  
    int ans = 0;

    rep(i,n){
        int tmp;
        cin >> tmp;
        a.pback(tmp);
    }

    rep(i,n){
        int tmp;
        cin >> tmp;
        b.pback(tmp);
      	ans += tmp;
    }

    rep(i,n - 1){
        int tmp;
        cin >> tmp;
        c.pback(tmp);
    }


    rep(i, n - 1){
        int eat = a[i];

        if(a[i + 1] == eat + 1) ans += c[eat - 1];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

long A, B;
long solve(long a);
long odd_solve(long a);

// 解法
// 0からBまで排他的論理和, 0からAまでの排他的論理和を求める
// それぞれ b, a とおいたとき
// a xor x = b となるxを求める
// x = a xor b
int main() {
  cin >> A >> B;
  // 引き算。引くも足すも同じビット演算子
  long ans = solve(B) ^ solve(A - 1);
  cout << ans << endl;
}

// 偶奇性と周期性に注目する
long solve(long a) {
  if (a % 2 == 1) {
    return odd_solve(a);
  } else {
    // A[a+1]のときから(a+1)を引く。引くも足すも同じビット演算子
    return odd_solve(a + 1) ^ (a + 1);
  }
}

// 奇数のときは1と0を繰り返している
long odd_solve(long a) {
  return (a + 1) / 2 % 2;
}


Measured memory_bytes: 256
from itertools import combinations_with_replacement


N, M, Q = map(int, input().split())
con = [tuple(map(int, input().split())) for _ in range(Q)]

# ans = 0
# for i in range(1 << M):
#     num = [x + 1 for x in range(M + 1) if (i >> x) & 1]
#     K = len(num)
# if K <= N:
num = [x + 1 for x in range(M)]
ans = 0
for var in combinations_with_replacement(num, N):
    cnt = 0
    for a, b, c, d in con:
        a -= 1; b -= 1
        if var[b] - var[a] == c:
            cnt += d
    ans = max(cnt, ans)

print(ans)


Measured memory_bytes: 80264
import itertools
import bisect
S=input()
T = []
M = int(S)
for i in S:
    T.append(int(i))
    T.append(0)
T.pop()
s = len(S)
for i in range(1,s):
    a = itertools.combinations(list(range(1,2*s-1,2)),i)
    for j in a:
        U = ""
        for k in range(2*s-1):
            if k in j:
                U += "+"
            else:
                U += str(T[k])
        U = U.replace("0","")
        M += eval(U)
print(M)

Measured memory_bytes: 9144
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	std::string A, B;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

	
#if INPUT_FROM_FILE
	std::getline(ifs, A);
	std::getline(ifs, A);
#else
	std::getline(std::cin, A);
	std::getline(std::cin, A);
#endif
#if INPUT_FROM_FILE
	std::getline(ifs, B);
	std::getline(ifs, B);
#else
	std::getline(std::cin, B);
	std::getline(std::cin, B);
#endif

	if(A < B){
		std::cout << "1" << std::endl;
	}
	else{
		std::cout << "0" << std::endl;
	}
	return 0;
}



Measured memory_bytes: 3204
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n;cin>>n,n;){
		vi a(n),b(n);
		rep(i,n)
			cin>>a[i];
		for(int i=0;;i++,a=b){
			map<int,int> c;
			rep(j,n)
				c[a[j]]++;
			rep(j,n)
				b[j]=c[a[j]];
			if(a==b){
				cout<<i<<endl;
				rep(j,n)
					cout<<b[j]<<(j==n-1?'\n':' ');
				break;
			}
		}
	}
	
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int A, B, K;
	cin >> A >> B >> K;

	int result = 0;
	int cnt = 0;

	for( int i = min( A, B ); i > 0; --i ) {
		if( A%i == 0 && B%i == 0 ) {
			cnt += 1;
		}

		if( cnt == K ) {
			result = i;
			break;
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;
int par[MAX],ok[MAX],ng[MAX];
ll cost[MAX];

void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        ok[i]=0;
        ng[i]=0;
    }
}

int root(int a){
    if(par[a]==a) return a;
    else return par[a]=root(par[a]);
}

void unite(int a,int b){
    if(root(a)!=root(b)){
        cost[root(a)]+=cost[root(b)];
        ok[root(a)]+=ok[root(b)];
        ng[root(a)]+=ng[root(b)];
        par[root(b)]=root(a);
    }
}

bool check(int a,int b){
    return root(a)==root(b);
}

struct edge{
    int from;
    int to;
    ll cost;
};

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;cin>>N>>M;
    init(N);
    for(int i=0;i<N;i++) cin>>cost[i];
    
    vector<edge> G(M);
    for(int i=0;i<M;i++){
        int a,b,c;cin>>a>>b>>c;
        a--;b--;
        G[i]={a,b,c};
    }
    
    sort(all(G),[](edge a,edge b){
        return a.cost<b.cost;
    });
    
    for(int i=0;i<M;i++){
        int a=G[i].from,b=G[i].to,c=G[i].cost;
        unite(a,b);
        
        if(cost[root(a)]>=c){
            ok[root(a)]++;
            ok[root(a)]+=ng[root(a)];
            ng[root(a)]=0;
        }else{
            ng[root(a)]++;
        }
    }
    
    set<pair<int,int>> SE;
    
    for(int i=0;i<N;i++){
        SE.insert({root(i),ng[root(i)]});
    }
    
    int ans=0;
    
    for(auto it=SE.begin();it!=SE.end();it++){
        ans+=(*it).second;
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 4224
#include<bits/stdc++.h>
#include<algorithm>
#include<functional>
//#include<boost/multiprecision/cpp_int.hpp>
#define f(n) for(long long int i=0;i<n;i++)
#define g(n) for(long long int j=0;j<n;j++)
#define ff(a,n) for(long long int i=a;i<n;i++)
#define gg(a,n) for(long long int j=a;j<n;j++)
#define t(a) long long int a;cin>>a
#define test(te) t(te); while(te--)
#define end "\n"
#define pri(a,n) f(n){cout<<a[i]<<" ";}cout<<end
#define pb push_back
#define mp make_pair
#define mod 1000000007  
#define ll long long 
#define lli long long int
#define op std::ios_base::sync_with_stdio(false);cin.tie(NULL)
//using namespace boost::multiprecision;
using namespace std;

int main(int argc, char const *argv[])
{
    op;
    t(a);
    cout<<a/2+a%2;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int n;
    cin>>n;
    int arr[2*n];
    for(int i=0;i<2*n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+2*n);
    int ans=0;
    for(int i=0;i<2*n;i+=2){
        if(arr[i]<arr[i+1]){
            ans+=arr[i];
        }
        else if(arr[i+1]<arr[i]){
            ans+=arr[i+1];
        }
        else if(arr[i]==arr[i+1]){
            ans+=arr[i];
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
c,n,m,s,d;
F[101][101],C[11][101],D[11][101];
u,a,b,f;
main(){
	for(;scanf("%d%d%d%d%d",&c,&n,&m,&s,&d),n;){
		memset(F,1,sizeof(F));
		memset(C,1,sizeof(C));
		memset(D,0,sizeof(D));
		for(;m--;){
			scanf("%d%d%d",&a,&b,&f);
			F[a][b]=F[b][a]=f;
		}
		C[u=c][s]=0;
		for(;s;){
			D[u][s]=1;
			for(a=1;a<=n;a++){
				f=C[u][s]+F[s][a];
				if(f<C[u][a])
					C[u][a]=f;
				f=C[u][s]+F[s][a]/2;
				if(u>0&&f<C[u-1][a])
					C[u-1][a]=f;
			}
			s=0;
			for(f=0;f<=c;f++){
				for(a=1;a<=n;a++){
					if(!D[f][a]&&C[f][a]<C[u][s])
						u=f,s=a;
				}
			}
		}
		f=1<<30;
		for(u=0;u<=c;u++){
			if(C[u][d]<f)
				f=C[u][d];
		}
		printf("%d\n",f);
	}
	for(n=1e7;n--;);
	exit(0);
}

Measured memory_bytes: 460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fastio() ios::sync_with_stdio(0);cin.tie(0);
#define nl "\n"
#define print(x) for(auto it:x) cout << it << " "; cout << "\n";
#define wi(x) cerr << #x << " is " << x << nl
const double eps = 1e-6;
const int mod = 1e9 + 7;

ll rec_power(ll a, ll b){ // assuming a != 0
	if(b == 0) return 1;
	ll tmp = rec_power(a,b/2);
	ll res = tmp * tmp;
	if(b&1) res *= a;
	return res;
}

ll power(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b&1) res = (res * a)%mod;
		a = (a*a)%mod;
		b/=2;
	}
	return res;
}

void solve(){
	int n; cin >> n;
	vi v(n);
	rep(i,0,n-1) cin >> v[i];
	ll ans = 0;
	rep(i,1,n-1){
		if(v[i] >= v[i-1]) continue;
		else{
			ans += v[i-1] - v[i];
			v[i] = v[i-1];
		}
	}
	cout << ans;
}

int main(){
	fastio()
	
	int T=1;
	//int T; cin>>T;
	while(T--) solve();
	
	return 0;
}


Measured memory_bytes: 3984
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}



int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,X;
  cin>>N>>X;
  VEC(L,N);
  rep(i,N){
    cin>>L[i];
  }
  int cnt=1;
  int length=0;
  rep(i,N){
    if(length+L[i]<=X){
      length+=L[i];
      cnt++;
    }
    else{
      cout<<cnt<<endl;
      return 0;
    }
  }
  cout<<cnt<<endl;
  
  
  
  
}
    
  
  


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

signed main() {
  int N,M;cin>>N>>M;
  std::vector<int> go[N],from[N];
  std::vector<int> size(N,0),num(N);
  for(int i=0;i<N+M-1;i++){
    int a,b;cin>>a>>b;
    a--;b--;
    go[a].push_back(b);
    from[b].push_back(a);
    size[b]++;
  }
  queue<int> que;
  for(int i=0;i<N;i++)if(size[i]==0)que.push(i);
  int number=0;
  while(que.size()){
    int q=que.front();que.pop();
    num[q]=number++;
    for(int i=0;i<go[q].size();i++){
      size[go[q][i]]--;
      if(size[go[q][i]]==0)que.push(go[q][i]);
    }
  }
  for(int i=0;i<N;i++){
    if(from[i].size()==0)cout<<0<<endl;
    else{
      int m=-1,parent;
      for(int j=0;j<from[i].size();j++){
        if(m<num[from[i][j]]){
          m=num[from[i][j]];
          parent=from[i][j];
        }
      }
      cout<<parent+1<<endl;
    }
  }
}


Measured memory_bytes: 13312
belong=list()
group=list()

def init(X):
  global belong
  global group
  belong=list(range(X))
  group=[[i] for i in range(X)]

def unite(x,y):
  if len(group[belong[x]])<len(group[belong[y]]):
    x,y=y,x
  if belong[x]==belong[y]:
    return True
  z=belong[y]
  for i in range(len(group[z])):
    belong[group[z][-1]]=belong[x]
    group[belong[x]].append(group[z][-1])
    del group[z][-1]
  return False

N,M=map(int,input().split())
init(N)
a,b=0,0
for i in range(M):
  a,b=map(int,input().split())
  unite(a-1,b-1)
P=0
for i in range(N):
  P=max(P,len(group[i]))
print(P)


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

using namespace std;

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

#define X first
#define Y second

const int N=2e5+10;
const ll inf=1e16;

struct segtree{
    ll b[N<<2];
    void build(){
        fill(b,b+(N<<2),inf);
    }
    ll get(int node,int L,int R,int l,int r){
        if (L>r||R<l) return inf;
        if (l<=L&&R<=r) return b[node];
        return min(get(node*2,L,(L+R)/2,l,r),get(node*2+1,(L+R)/2+1,R,l,r));
    }
    void update(int node,int L,int R,int pos,ll val){
        if (L>pos||R<pos) return;
        if (L==R){
            b[node]=min(b[node],val);
            return;
        }
        update(node*2,L,(L+R)/2,pos,val);
        update(node*2+1,(L+R)/2+1,R,pos,val);
        b[node]=min(b[node*2],b[node*2+1]);
    }
}msegL,msegR;




ll ssum[N];
int n,m,st[2];
int qu[N];


void prepare(){
    scanf("%d%d%d%d",&n,&m,st,st+1);
    ///stone 0 and stone 1
    for(int i=1;i<=m;i++) scanf("%d",qu+i);
    ///ssum[i]== time needed to go from qu[i]->qu[i+1]->...->qu[m]
    for(int i=m-1;i>=1;i--) ssum[i]=ssum[i+1]+abs(qu[i]-qu[i+1]);
}
ll solve(){
    ///special case
    if (m==1) return min(abs(st[0]-qu[1]),abs(st[1]-qu[1]));
    msegL.build();
    msegR.build();

    ll scale=0;
    for(int i=2;i<=m;i++){
//            cout<<i<<'\n';
        ///first move of stone 1 is to x[i]
        ll cost=ssum[1]-ssum[i-1]+abs(qu[1]-st[0])+abs(qu[i]-st[1]);
        ///first move of stone 0 is to x[i]
        cost=min(cost,ssum[1]-ssum[i-1]+abs(qu[1]-st[1])+abs(qu[i]-st[0]));
        ///other case
        ll bestL=msegL.get(1,1,n,1,qu[i])+qu[i]+scale;
        ll bestR=msegR.get(1,1,n,qu[i],n)+(n-qu[i])+scale;
        ///cost == a stone at x[i] and a stone at pos x[i-1]
        cost=min(cost,min(bestL,bestR));
//        cout<<cost<<'\n';
        ///scaling other position as a stone move from x[i-1] to x[i]
        ///note that in this case , both stone have moved at least once
        scale+=abs(qu[i]-qu[i-1]);
        ///update two side
        msegL.update(1,1,n,qu[i-1],cost-qu[i-1]-scale);
        msegR.update(1,1,n,qu[i-1],cost-(n-qu[i-1])-scale);
    }
    ///initial ans is when stone 1 didn't move
    ll ans=ssum[1]+abs(st[0]-qu[1]);
//    cout<<ans<<'\n';
    for(int i=1;i<=n;i++) ans=min(ans,msegL.get(1,1,n,i,i)+i);
    return ans+scale;
}
int main(){
    prepare();
    cout<<solve();
}


Measured memory_bytes: 15104
#include <iostream>
#include <vector>
using namespace std;
const int INF = 1e9+5;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	vector<int> h(n);
	for(int &x: h)
		cin >> x;
	vector<int> dp(n,INF);
	dp[0]=0;
	for(int i=0; i<n; ++i) {
		for(int j: {i+1, i+2}) {
			if(j<n) {
				dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
			}
		}
	}
	cout << dp[n-1] << "\n";
	return 0;
}


Measured memory_bytes: 1024
H = int(input())

n = 1

def calc(h,n):
    a = h//2
    if a==1:
        n += 2
    else:
        n += 2*calc(a,n)
    return n


if H == 1:
    print(1)
else:
    ans = calc(H,n)
    print(ans)

Measured memory_bytes: 3060
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 

	public static void main(String[] args) {   //This is literally segment tree without updates 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int A = I.nextInt();
		int B = I.nextInt();
		int ans = -1;
		for (int chk = 1; chk<=10000; chk++) {
			double pr = (double)(chk);
			double a = pr*0.08;
			double b = pr*0.1;
			a=(int)(a);
			b=(int)(b);
			if (a==A&&b==B) {
				ans=chk;
				break;
			}
		}
		O.pln(ans);
	}
	public static int Check(int L, int R, int ltr, int[][] pref, String S) {
		if (L==R) {
			int cur = S.charAt(L-1)-'a';
			return cur==ltr?0:1;
		}
		int mid = (L+R)/2;
		int range = R-L+1;
		range/=2; //Only ever analyze one half of current [L,R] range
		int left = pref[mid][ltr]-pref[L-1][ltr]; //All letters in left half not desired letter need to
		//be switched
		left=range-left;
		left+=Check(mid+1,R,ltr+1,pref,S); //Checking right child
		
		int right = pref[R][ltr]-pref[mid][ltr]; 
		//Number of desired letters between mid+1 and R
		right=range-right; //Have to swap bads not goods
		right+=Check(L,mid,ltr+1,pref,S); //Checking left child recursion
		return Math.min(left,right);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 25652
#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 <functional>
#include <stack>
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<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
using Graph =vector<vector<int>>;
//xor ^
int main(){
  int N,M;cin>>N>>M;
  int ans1=0;
  int ans2=0;
  ans1=M*(M-1)/2;
  ans2=N*(N-1)/2;
  if(M==0){
    ans1=0;
  }
  if(N==0){
    ans2=0;
  }
  cout<<ans1+ans2<<endl;
}


Measured memory_bytes: 256
def f(N):
    C = [[0] * 51 for _ in range(51)]
    for i in range(N + 1):
        for j in range(i + 1):
            if j == 0 or i == j:
                C[i][j] = 1
            else:
                C[i][j] = C[i - 1][j - 1] + C[i - 1][j]
    return C


def main():
    N, A, B = map(int, input().split())
    V = sorted(list(map(int, input().split())), reverse=True)
    avg = sum(V[:A]) / A
    n = V.count(V[A - 1])
    p = V[:A].count(V[A - 1])
    C = f(N)
    ans = 0
    if p == A:
        for i in range(A, B + 1):
            ans += C[n][i]
    else:
        ans += C[n][p]
    print(avg)
    print(ans)


main()


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	string o, e; cin >> o >> e;
	REP(i, o.length() + e.length()) {
		cout << (i % 2 == 0 ? o : e)[i / 2];
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int K;
    cin >> K;
    vector<vector<P>> graph(K);
    for(int i = 0; i + 1 < K; ++i){
        graph[i].emplace_back(i + 1, 1);
        int v = i * 10 % K;
        graph[i].emplace_back(v, 0);
    }
    graph[K - 1].emplace_back(0, 1);
    graph[K - 1].emplace_back((K - 1) * 10 % K, 0);
    vector<int> dist(K, INF);
    dist[1] = 1;
    deque<int> deq;
    deq.push_back(1);
    while(!deq.empty()){
        int from = deq.front();
        deq.pop_front();
        for(auto e : graph[from]){
            int to = e.first, cost = e.second;
            if(!cost){
                if(chmin(dist[to], dist[from])) deq.push_front(to);
            }
            else{
                if(chmin(dist[to], dist[from] + 1)) deq.push_back(to);
            }
        }
    }
    cout << dist[0] << endl;
}

Measured memory_bytes: 9476
// 解説動画
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n; long long k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<int> s;
    vector<int> ord(n+1, -1);
    int c = 1, l = 0;  // 周期
    {
        int v = 1;
        while(ord[v] == -1){
            ord[v] = s.size();
            s.push_back(v);
            v = a[v-1];
        }
        c = s.size() - ord[v];
        l = ord[v];
    }
    if(k < l) { cout << s[k] << endl; }
    else {
        k -= l;
        k %= c;
        cout << s[l + k] << endl;
    }
    return 0;
}

Measured memory_bytes: 5824
#include <bits/stdc++.h>
using namespace std;
long long int a1[200000];
long long int a2[200000];
int main(){
    long long int n,m,k;
    cin>>n>>m>>k;
    for(long long int i=0;i<n;i++){
        cin>>a1[i];
    }
    for(long long int i=0;i<m;i++){
        cin>>a2[i];
    }
    long long int p1[n+1];
    long long int p2[m+1];
    p1[0]=0;
    p2[0]=0;
    for(long long int i=1;i<=n;i++){
        p1[i]=p1[i-1]+a1[i-1];
    }
    for(long long int i=1;i<=m;i++){
        p2[i]=p2[i-1]+a2[i-1];
    }
    long long int res=0;
    for(int i=0;i<=n;i++){
        long long int temp=k-p1[i];
        if(temp<0){
            break;
        }
        long long int in=lower_bound(p2,p2+m+1,temp)-p2;
        if(in==m+1 || p2[in]>temp){
            in--;
        }
        res=max(res,i+in);
    }
    cout<<res;

    return 0;
}


Measured memory_bytes: 9848
s = list( input( ) )
n = int( input( ) )
for i in range( n ):
	cmd = input( ).split( " " )
	a = int( cmd[1] )
	b = int( cmd[2] ) + 1
	if "print" == cmd[0]:
		print( "".join( s[ a:b ] ) )
	elif "reverse" == cmd[0]:
		for i in reversed( s[ a:b ] ):
			s[ a ] = i
			a += 1
	elif "replace" == cmd[0]:
		for i in cmd[3]:
			s[ a ] = i
			a += 1

Measured memory_bytes: 6724
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007


int main()
{
	int n;
	cin >> n;
	vector<pair<int, int> > v;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		v.push_back(make_pair(a, i + 1));
	}
	sort(v.begin(), v.end());
	for(int i = 0; i < n; i++){
		cout << v[i].second << " ";
	}
	cout << endl;
}

Measured memory_bytes: 1780
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

class EQ{
public:
  double a,b;
  double xs,xe;
};

double compute(double a,double b,double c,double x){
  return a*x*x*x+b*x*x+c*x;
}

double integ(double ai,double bi,double aj,double bj,double xs,double xe){
  double ta=compute((ai*aj)/3,(ai*bj+aj*bi)/2,bi*bj,xs);
  double tb=compute((ai*aj)/3,(ai*bj+aj*bi)/2,bi*bj,xe);
  return tb-ta;
}

bool have_common(double xs1,double xe1,double xs2,double xe2){
  if ((xs2 <= xs1 && xs1 <= xe2)||
      (xs2 <= xe1 && xe1 <= xe2)||
      (xs1 <= xs2 && xs2 <= xe1)||
      (xs1 <= xe2 && xe2 <= xe1))return true;
  else return false;
}

double solve(vector<EQ> &in,double r){
  int n = in.size();
  double ans = 0;
  rep(i,n){
    double xs=in[i].xs+r,xe=in[i].xe+r;
    rep(j,n){
      //cout << xs <<" " << xe << endl;
      if (have_common(xs,xe,in[j].xs,in[j].xe)){
        double cxs=max(xs,in[j].xs),cxe=min(xe,in[j].xe);
        //      cout <<"test :" <<  cxs-r <<" " << cxe-r <<
        //        " " << integ(in[i].a,in[i].b,in[j].a,in[j].b+r*in[j].a,cxs-r,cxe-r) <<" test end " <<  endl;

        ans+=    integ(in[i].a,in[i].b,in[j].a,in[j].b+r*in[j].a,cxs-r,cxe-r);
        if (xe < in[j].xe)break;
        else xs=in[j].xe;
      }
    }
  }
  return ans;
}


main(){
  int n;
  double r;
  while(cin>>n>>r && n){
    vector<double> x,y;
    vector<EQ>in;
    rep(i,n){
      double tx,ty;
      cin>>tx>>ty;
      x.push_back(tx);
      y.push_back(ty);
    }

    EQ ins;
    rep(i,n-1){
      ins.xs=x[i];ins.xe=x[i+1];
      ins.a=(y[i+1]-y[i])/(x[i+1]-x[i]);
      ins.b=-ins.a*x[i]+y[i];
      in.push_back(ins);
    }

    printf("%.10lf\n",solve(in,r));
  }
  return false;
}

Measured memory_bytes: 996
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <numeric>

int main(){
  long int N;
  std::cin>>N;
  std::vector<int> B(N);
  std::copy_n(std::istream_iterator<int>(std::cin),N,B.begin());
  std::vector<int> Index(N);
  std::iota(Index.begin(), Index.end(), 0);
  for(int i = 0 ; i < N ; i++){
    if( Index[i] + 1 < B[i] ){
      std::cout<<-1<<std::endl;
      return 0;
    }
  }

  int max=0;
  std::vector<int> result;
  for(int i = 0 ; i < N ; i++ ){
    for(int k = 0 ; k < N - i ; k++ ){
      if(Index[k] + 1 == B[k]) max = Index[k];
    }
    result.push_back(B[max]);
    B.erase(B.begin() + max );
    Index.erase(Index.begin() + max );
    for(int k = max ; k < N - i - 1 ; k++ ){
      Index[k] -= 1;
    }
    max = 0;
  }
  for(int i = N - 1 ; i >= 0 ; i-- ){
    std::cout<<result[i]<<std::endl;
  } 
  return 0;
}


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

typedef long long ll;
#define int ll

typedef queue<pair<int,int>> Q;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
inline int in() {int x; cin >> x; return x;}
const int INF = 1e+9;

int h, w;
vs s;
int dirh[] = {0,-1,0,+1}, dirw[] = {-1,0,+1,0};
int ans = 0;

void bfs(int h1, int w1) {
  vvi dist(h, vi(w, INF));
  dist[h1][w1] = 0;
  Q q;
  q.push({h1,w1});
  while(!q.empty()) {
    int h2, w2; tie(h2,w2) = q.front(); q.pop();
    FOR (d,0,4) {
      int h3 = h2 + dirh[d];
      int w3 = w2 + dirw[d];
      if (!(0<=h3 && h3<h && 0<=w3 && w3<w)) continue;
      if (s[h3][w3]=='#') continue;
      if (dist[h3][w3]!=INF) continue;

      dist[h3][w3] = dist[h2][w2] + 1;
      q.push({h3,w3});
    }
  }

  FOR (i,0,h)
    FOR (j,0,w)
      if (dist[i][j]!=INF && ans<dist[i][j])
        ans = dist[i][j];
}

void solve() {
  h = in(), w = in();
  s.resize(h);
  FOR (i,0,h) cin >> s[i];

  FOR (i,0,h)
    FOR (j,0,w)
      if (s[i][j]!='#')
        bfs(i,j);

  cout << ans << endl;
}

#undef int
int main() {
  solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string a,b;
	cin>>a>>b;
	b.pop_back();
	cout<<(a==b?"Yes":"No");
	return 0;
}


Measured memory_bytes: 3648
N = int(input())
h = list(map(int, input().split()))

S = sum(h)
ans = 0
while S > 0:
  for l in range(N):
    if h[l] > 0:
      break
  for r in range(l, N):
    if h[r] == 0:
      break
  if r == N - 1 and h[r] > 0:
    r += 1
  for i in range(l, r):
    h[i] -= 1
  ans += 1
  S -= r - l
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double t,n,j;
    cin>>t>>n;
    if(int(n)%2!=0)cout<<"No"<<endl;
    else if(t>=ceil(n/4) and t<=ceil(n/2) and int(n)%2==0)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;



int main(){
	llong N;
	string S;
	cin >> N >> S;
	vector<llong> beki(N+1,1);

	int many[26] = {};
	llong ans = 0;
	for(auto x : S){
		llong res = 1;
		for(int i = 0; i < 26; i++)
			if((int)(x - 'a') == i)
				continue;
			else
				(res *= many[i]+1) %= mod;
		// cerr << res << endl;
		ans += res;
		ans %= mod;
		many[(int)(x-'a')]++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;
const int LOGN = 18;

int n, m, k;

void solve(int test)
{
  cin >> n;
  vector<int> x(n), y(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
  }
  int ans = n;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int64 p = x[j] - x[i];
      int64 q = y[j] - y[i];
      int cur = n;
      for (int c = 0; c < n; ++c) {
        if (c != i)
        for (int d = c - 1; d >= 0; --d) {
          if (x[c] - x[d] == p && y[c] - y[d] == q) {
            --cur;
          }
          if (x[d] - x[c] == p && y[d] - y[c] == q) {
            --cur;
          }
        }
      }
      ans = min(ans, cur);
    }
  }
  cout << ans << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main()
{
    int n;

    while (true) {
        cin >> n;                       // 学生数
        if (n == 0) break;              // 終了
        if (n < 0 && n > 100) continue;

        try {
            int *s;

            s = new int[n];

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

            int total;
            double ave;
            double a2;

            total = 0;
            for (int i = 0; i < n; i++) {
                total += s[i]; 
            }
            ave = (double)total / n;    // 平均値

            a2 = 0;
            for (int i = 0; i < n; i++) {
                double tmp = ((double)s[i] - ave);
                a2 += tmp * tmp;
            }
        
            delete [] s;

            a2 /= n;

            long double a = sqrt(a2);   // 標準偏差

            cout << setprecision(16) << a << endl;
        }
        catch (...) {
            continue;
        }
    }

    return 0;
}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 4e5 + 5;

int dr[] = {1, -1, -1, 1};
int dc[] = {1, 1, -1, -1};

int dr2[] = {1, 0, -1, 0};
int dc2[] = {0, -1, 0, 1};

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int x1, y1, x2, y2, x3, y3, x4, y4;
    cin >> x1 >> y1 >> x2 >> y2;
    int difx = x2 - x1;
    int dify = y2 - y1;
    cout << x2 - dify << " " << y2 + difx << " " << x1 - dify << " " << y1 + difx;




    return 0;
}


Measured memory_bytes: 256