akhauriyash/Code-Regression huggingface dataset:
n, k = [ int( val ) for val in raw_input( ).split( " " ) ]
w = [ int( raw_input( ) ) for val in range( n ) ]
sumW = sum( w )
maxW = max( w )

minP = 0
if 1 == k:
	minP = sumW
elif n == k:
	minP = maxW
else:
	left = maxW
	right = 100000*10000
	while left <= right:
		middle = ( left+right )//2
		truckCnt = i = loadings = 0
		while i < n:
			loadings += w[i]
			if middle < loadings:
				truckCnt += 1
				if k < truckCnt+1:
					break
				loadings = w[i]
			i += 1

		if truckCnt+1 <= k:
			minP = middle
		
		if k < truckCnt+1:
			left = middle + 1
		else:
			right = middle - 1

print( minP )

Measured memory_bytes: 10476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    ll n;cin>>n;
    vl a(n);rep(i,n)cin>>a[i];
    reverse(all(a));
    rep(i,n){
        if(i>0)cout<<" ";
        cout<<a[i];
    }
    cout<<endl;
}

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



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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)
typedef long long ll;
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;
const int MAX = 510000;

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

int main() {
	COMinit();
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	ll res = 0;
	REP(i, h - a) {
		res += COM(b - 1 + i, b - 1)*COM(w - b - 1 + h - 1 - i, w - b - 1);
		res %= mod;
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 12160
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<=(b);++i)
#define DEC(i,a,b) for(int i=(a);i>=(b);--i)
#define dbg(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
template<typename T,typename U> inline bool smax(T&x,const U&y){return y>x?(x=y,1):0;}
template<typename T,typename U> inline bool smin(T&x,const U&y){return y<x?(x=y,1):0;}
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define X first
#define Y second
inline int read(){
	int w=0,p=0;char c;
	while(!isdigit(c=getchar()))if(c=='-')p=1;
	while(isdigit(c))w=(w<<1)+(w<<3)+(c^'0'),c=getchar();
	return p?-w:w;
}
const int N=2007;
int n,k,q,a[N],b[N],c[N],cnt;
priority_queue<int,vector<int>,greater<int> > qq;
int main(){
	n=read(),k=read(),q=read();
	REP(i,1,n)a[i]=b[i]=read();
	sort(b+1,b+1+n);
	int last=0,ans=0x3f3f3f3f;
	REP(i,1,n-q+1){
		last=cnt=0;
		REP(j,1,n+1){	
			if(a[j]<b[i]){
				if(j-1-last>=k){
					int s=j-1-last;
					while(!qq.empty()){
						int xx=qq.top();qq.pop();
						if(s-->=k)c[++cnt]=xx;
					}
				}
				while(!qq.empty())qq.pop();
				last=j;
			}
			else qq.push(a[j]);	
		}
		if(cnt<q)continue;
		sort(c+1,c+1+cnt);
		smin(ans,c[q]-c[1]);
	}
	cout<<ans;
	return 0;
}


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

int main(){
    string s;
    cin>>s;
    for(int i=0;i<3;i++){
        if(s[i]=='1')s[i]='9';
        else if(s[i]=='9')s[i]='1';
        cout<<s[i];
    }
    cout<<endl;
    return 0;
}

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

int main(){
    //N，Kの入力
    int N,K;
    cin >> N >> K;

    //Dの入力
    vector<int> D(K);
    for(int i=0;i<K;i++){
        cin >> D.at(i);
    }


    bool flag = false;
    int ans=N;
    
    while(!flag){
        flag=true;
        for(int num=ans;num>=1;num/=10){
            for(auto i:D){
                if(num%10==i){
                    flag=false;
                }
            }
        }
        ans++;
    }
    cout << ans-1 << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    string S;
    cin >> S;
    if (S[0] != S[1] && S[0] != S[2] && S[1] != S[2]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int a = input[0];
        int b = input[1];
        int k = input[2];
        if (b - a + 1 <= k * 2)
        {
            for (int i = a; i <= b; i++)
            {
                Console.WriteLine(i);
            }
        }
        else
        {
            for (int i = a; i < a + k; i++)
            {
                Console.WriteLine(i);
            }
            int start;
            if (a + k - 1 >= b - k + 1)
                start = a + k;
            else
                start = b - k + 1;
            for (int i = start; i <= b; i++)
            {
                Console.WriteLine(i);
            }
        }
    }
}

Measured memory_bytes: 13140
#include<stdio.h>
int main(void){
    int N,M;
    int n[1000]={0},m[1000]={0};
    int p[1000]={0};
    int i,j,ans=0;
    scanf("%d %d",&N,&M);
    for(i=0;i<N;i++){
        scanf("%d",&n[i]);
    }
    for(i=0;i<M;i++){
        scanf("%d",&m[i]);
    }
    for(i=0;i<M;i++){
        for(j=0;j<N;j++){
            if(m[i]>=n[j]){
                p[j]++;
                break;
            }
        }
    }
    for(i=0;i<N;i++){
        if(p[ans]<p[i])ans=i;
    }
    printf("%d\n",ans+1);
    return 0;
}

Measured memory_bytes: 608
n,t = map(int,input().split())
cl=[0 for i in range(n)]
tl=[0 for i in range(n)]

for i in range(n):
    cl[i],tl[i]=map(int,input().split())
    
min_cost = 100000
for i in range(n):
    if cl[i] < min_cost and tl[i] <= t:
        min_cost = cl[i]
if min_cost < 100000:
    print(min_cost)
else:
    print("TLE")

Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstdio>
#include<queue>
#include<functional>
#include<tuple>
#include<iomanip>
#include<stack>
#include<cmath>
#define ll long long
using namespace std;
int cnt;
int rec(int n, int k, int s) {
	if (k == 0 && s == 0) return cnt + 1;
	if (n <= 0 || k <= 0 || s <= 0) return cnt;
	for (int i = k; i <= n; ++i) cnt=rec(i - 1, k - 1, s - i);
	return cnt;
}
int main() {
	int n, k, s;
	while (cin >> n >> k >> s && n&&k&&s) {
		cnt = 0;
		cout << rec(n, k, s) << endl;
	}
	return 0;
}


Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
const int nmax=40,abmax=10,inf=1000000;
int a[nmax],b[nmax],c[nmax];
int dp[nmax+1][nmax*abmax+1][nmax*abmax+1];
int main(){
	int n,ma,mb;
	cin>>n>>ma>>mb;
	for(int i=0;i<n;++i){
		cin>>a[i]>>b[i]>>c[i];
	}
	for(int i=0;i<=n;i++){
		for(int ca=0;ca<=nmax*abmax;ca++){
			for(int cb=0;cb<=nmax*abmax;cb++){
				dp[i][ca][cb]=inf;
			}
		}
	}
	dp[0][0][0]=0;
	for(int i=0;i<n;i++){
		for(int ca=0;ca<=nmax*abmax;ca++){
			for(int cb=0;cb<=nmax*abmax;cb++){
				if(dp[i][ca][cb]==inf){
					continue;
				}
				dp[i+1][ca][cb]=min(dp[i+1][ca][cb],dp[i][ca][cb]);
				dp[i+1][ca+a[i]][cb+b[i]]=min(dp[i+1][ca+a[i]][cb+b[i]],dp[i][ca][cb]+c[i]);
			}
		}
	}
	int ans=inf;
	for(int ca=1;ca<=nmax*abmax;ca++){
		for(int cb=1;cb<=nmax*abmax;cb++){
			if(ca*mb==cb*ma){
				ans=min(ans,dp[n][ca][cb]);
			}
		}
	}
	if(ans==inf){
		ans=-1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 25984
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
	#define dbg(x) cout << #x << " : " << x << endl;
#else 
	#define dbg(x)
#endif

#define int long long
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 200010;
const double EPS = 1e-9;


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

int a[MX], b[MX], c[MX];

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

    int n;
    cin >> n;
    fi(0, n) {
    	cin >> a[i];
    	--a[i];
    }
    fi(0, n) cin >> b[i];
    fi(0, n - 1) cin >> c[i];
    int res = 0;
    fi(0, n) {
    	res += b[a[i]];
    	if (i != 0 && a[i - 1] + 1 == a[i])
    		res += c[a[i - 1]];
    }
    cout << res << '\n';
}

Measured memory_bytes: 2304
from heapq import heappop,heappush
import sys
input=sys.stdin.readline

q=int(input())
query=[list(map(int,input().split())) for _ in range(q)]
inf=10**12
left=[inf]
left_sum=0
right=[inf]
right_sum=0

cnt=0
b=0
for i in range(q):
    if query[i][0]==1:
        a=query[i][1]
        b+=query[i][2]
        if cnt==0:
            d=right[0]
            if a>d:
                heappush(left,-heappop(right))
                heappush(right,a)
                right_sum+=a-d
                left_sum-=d
            else:
                heappush(left,-a)
                left_sum-=a
            cnt=1
        else:
            c=-left[0]
            if a<c:
                heappush(right,-heappop(left))
                heappush(left,-a)
                right_sum+=c
                left_sum+=c-a
            else:
                heappush(right,a)
                right_sum+=a
            cnt=0
    else:
        x=-left[0]
        if cnt==0:
            print(x,b+right_sum+left_sum)
        else:
            print(x,b+x+right_sum+left_sum)

Measured memory_bytes: 56696
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N,K,C;cin>>N>>K>>C;
	string s;cin>>s;
    if(C == 0){
        int cnt = 0;
        rep(i,0,N) if(s[i] == 'o') cnt++;
        if(cnt == K){
            rep(i,0,N) if(s[i] == 'o') cout<<i+1<<endl;
        }return 0;
    }
	int L[N+1] = {},R[N+1] = {};
	rep(i,0,N)if(s[i] == 'o'){ L[i+1] = 1; i += C; }
    for(int i = N-1; i >= 0; i--)if(s[i] == 'o'){ R[i] = 1; i -= C; }
    rep(i,0,N){ L[i+1] += L[i]; R[N-i-1] += R[N-i]; }
	int acm[N + C] = {};//print(L,,N+1);print(R,,N+1);
	rep(i,0,N + C){
		if(i - C >= 0) acm[i] += L[i - C];
		if(i <= N) acm[i] += R[i];
        //cout<<acm[i]<<" ";
		if(acm[i] >= K) acm[i] = 1;
		else acm[i] = 0;
	}//cout<<endl;
	int res[N+C+1]; res[0] = 0;
	rep(i,0,N+C) res[i + 1] = res[i] + acm[i];
	rep(i,1,N+1){
		if(s[i-1] == 'o')if(res[i + C] - res[i] == 0) cout<<i<<endl;
	}
}

Measured memory_bytes: 3716
#include<stdio.h>

int main(){
  int n,p[200][2],xmin,xmax,ymin,ymax,d,N;
  p[0][0]=p[0][1]=0;
  while(1){
    scanf("%d",&N);
    if(N==0)
      break;
    xmin=xmax=ymin=ymax=0;
    for(int i=1;i<N;i++){
      scanf("%d %d",&n,&d);
      if(d==0){
        p[i][0]=p[n][0]-1;
        p[i][1]=p[n][1];
      }
      else if(d==1){
        p[i][0]=p[n][0];
        p[i][1]=p[n][1]+1;
      }
      else if(d==2){
        p[i][0]=p[n][0]+1;
        p[i][1]=p[n][1];
      }
      else{
        p[i][0]=p[n][0];
        p[i][1]=p[n][1]-1;
      }
    }
    for(int i=0;i<N;i++){
      if(xmin>p[i][0])
        xmin=p[i][0];
      if(ymin>p[i][1])
        ymin=p[i][1];
      if(xmax<p[i][0])
        xmax=p[i][0];
      if(ymax<p[i][1])
        ymax=p[i][1];
    }
    printf("%d %d\n",xmax-xmin+1,ymax-ymin+1);
  }
}


Measured memory_bytes: 2104
#include <stdio.h>

int main(void){
	int second;
	int time;
	int minute;

	scanf( "%d", &second );

	time = second/3600;
	minute = (second-time*3600)/60;
	second = second%60;

printf("%d:%d:%d\n", time, minute, second);

return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define repd(i, a, b) for (int i = a; i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template <typename H>
bool chmin(H &v1, const H v2)
{
    if (v1 > v2)
    {
        v1 = v2;
        return true;
    }
    return false;
}
template <typename H>
bool chmax(H &v1, const H v2)
{
    if (v1 < v2)
    {
        v1 = v2;
        return true;
    }
    return false;
}
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((b >= 1 && d >= 1) || (a <= -1 && c <= -1))
        cout << max(a * c, b * d);
    else if ((a <= 0 && b >= 0) || (c <= 0 && d >= 0))
        cout << 0 << endl;
    else
        cout << max(max(a * c, a * d), max(b * c, b * d)) << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#define PI 3.141592653589
typedef long long ll;
const int MOD = 1000000007;
const int INF = 2002002002;
const int di[] = { -1, 0, 1, 0 };
const int dj[] = { 0, -1, 0, 1 };
using namespace std;

int main() {
	ll n, m, x;
	cin >> n >> m >> x;
	vector<ll> c(n);
	vector<vector<ll>> a(n, vector<ll>(m));
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		for (int j = 0; j < m; j++)
			cin >> a[i][j];
	}
	vector<ll> sum(m, 0);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			sum[j] += a[i][j];
		}
	}
	bool ok = true;
	for (int i = 0; i < m; i++)
		if (sum[i] < x)
			ok = false;
	if (!ok) {
		cout << -1 << endl;
		return 0;
	}

	// bit

	ll ans = 1000000000000;
	for (int bit = 0; bit < (1 << n); bit++) {
		ll sumvalue = 0;
		vector<ll> algo(m, 0);
		// buy to value and algoup
		for (int i = 0; i < n; i++) {
			if (bit & (1 << i)) {
				sumvalue += c[i];
				for (int j = 0; j < m; j++) {
					algo[j] += a[i][j];
				}
			}
		}
		bool ok = true;
		for (int i = 0; i < m; i++)
			if (algo[i] < x)
				ok = false;
		if (ok) {
			ans = min(ans, sumvalue);
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3640
N, Y = gets.split.map(&:to_i)

(0 .. Y/10000).each do |x|
  (0 .. Y/5000).each do |y|
    if 9*x + 4*y == Y/1000 - N && N >= x + y
      printf "%d %d %d\n", x, y, N - x - y
      exit
    end
  end
end
puts "-1 -1 -1"

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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll>
using namespace std;

const ll maxn=4e5+500;
const ll inf=1e17+7;
const ll mod=998244353;


ll fac[maxn];
ll rfac[maxn];
ll ent(ll n,ll k){
    if(k>n || k<0){
        return 0;
    }
    return (((fac[n]*rfac[k])%mod)*rfac[n-k])%mod;
}
ll poww(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=(b/2);
    }
    return ans;
}
int main()
{
    fac[0]=1;
    rfac[0]=1;
    for(ll i=1;i<maxn;i++){
        fac[i]=(fac[i-1]*i)%mod;
        rfac[i]=poww(fac[i],mod-2);
    }
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,a,b,k;
    cin>>n>>a>>b>>k;
    ll ans=0;
    for(ll i=0;i<=n;i++){
        ll kk=k-a*i;
        if(kk>=0 && kk%b==0){
            ll j=kk/b;
            ans+=(ent(n,i)*ent(n,j))%mod;
            ans%=mod;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 6528
///i am nothing :( :(
#include<bits/stdc++.h>
using namespace std;
long long int tri_sum(long long int n)
{
    int x;
    x=(n*(n+1))/2;
    return x;
}
int main()
{
   long long int n,h,a,b=0,s=0,f;
   // freopen("input.txt","r",stdin);
    long long int t,y;
   cin>>n>>t;
   char a1[t];
   //scanf("%s",&a1);
   for(int i=0;i<t+2;i++)
   {
       printf("#");
   }
    printf("\n");
   for(int j=0;j<n;j++)
   {     printf("#");
       scanf("%s",&a1);
       cout<<a1;
        printf("#");
         printf("\n");
   }
   for(int i=0;i<t+2;i++)
   {
       printf("#");
   }
}


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

int n;
int a[100000];
int b[100000];

int s[100000];
int t[100000];


ll solve(){
  if(n==1 && a[0]!=b[0])return 0;
  
  s[0]=a[0];

  s[n-1]=b[n-1];

  for(int i=1;i<n;i++){
    if(a[i-1]<a[i]){
      if(s[i]!=-1)return 0;
      s[i]=a[i];
    }else if(a[i-1]==a[i]){
      t[i]=min(t[i],a[i]);
    }else{
      return 0;
    }
  }

  for(int i=n-2;i>=0;i--){
    if(b[i]>b[i+1]){
      if(s[i]!=-1&&s[i]!=b[i])return 0;
      s[i]=b[i];
    }else if(b[i]==b[i+1]){
      t[i]=min(t[i],b[i]);
    }else{
      return 0;
    }
  }

  ll ans=1;
  for(int i=0;i<n;i++){
    if(s[i]!=-1&&t[i]<s[i])return 0;
    
    if(s[i]==-1){
      ans=(ans*t[i])%1000000007LL;
    }
  }

  return ans;
}

int main(){
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(int i=0;i<n;i++){
    scanf("%d",&b[i]);
  }
  for(int i=0;i<n;i++){
    s[i]=-1;
    t[i]=1e9;
  }

  printf("%lld\n",solve());
  return 0;
}


Measured memory_bytes: 1792
use std::cmp::max;
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let n = scan!(i64);
    let (mut x, mut y) = (1, 1);
    for _ in 0..n {
        let (a, b) = scan!(i64, i64);
        if x <= a && y <= b {
            x = a;
            y = b;
        } else if x > a && y > b {
            let n = max((x + a - 1) / a, (y + b - 1) / b);
            x = n * a;
            y = n * b;
        } else if y > b {
            let n = (y + b - 1) / b;
            x = n * a;
            y = n * b;
        } else {
            let n = (x + a - 1) / a;
            x = n * a;
            y = n * b;
        }
    }

    println!("{}", x + y)
}


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll h, w;
	cin >>h >>w;
	if(min(h, w) <=1) cout<< "1\n";
	else cout << (h*w+1) / 2 <<"\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
      using namespace std;
      #include <ext/pb_ds/assoc_container.hpp>
      #include <ext/pb_ds/tree_policy.hpp>
      using namespace __gnu_pbds;
      #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
      #define ll long long
      #define int long long
      #define ld long double
      #define pb push_back
      #define f(i,a,b) for(int i=a;i<b;i++)
      #define fd(i,a,b) for(int i=a-1;i>=b;i--)
      #define pf push_front
      #define ppf pop_front
      #define ppb pop_back
      #define fi first
      #define se second
      #define take(a,n) f(i,0,n)cin>>a[i];
      #define show(a,n) f(i,0,n){cout<<a[i]<<" ";}
      #define ashow(a)  for(auto i:a)cout<<i<<" ";
      #define khtm     cout<<endl;
      #define all(s) s.begin(),s.end()
      #define len(a) a.length()
      #define INF 1e18
      #define MAXN 2000009
      #define PMOD 998244353
      const double pi=3.14159265358979323;
      const int mod=1e9+7;
      void btao(int n){
        if(n)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
      }
      bool isPrime(int n) 
  { 
      // Corner cases 
      if (n <= 1) 
          return false; 
      if (n <= 3) 
          return true; 
    
      // This is checked so that we can skip 
      // middle five numbers in below loop 
      if (n % 2 == 0 || n % 3 == 0) 
          return false; 
    
      for (int i = 5; i * i <= n; i = i + 6) 
          if (n % i == 0 || n % (i + 2) == 0) 
              return false; 
    
      return true; 
  } 
  int spf[MAXN];
  void sieve()
        {
            spf[1] = 1;
            for (int i=2; i<MAXN; i++)
                spf[i] = i;
            for (int i=4; i<MAXN; i+=2)
                spf[i] = 2;
            for (int i=3; i*i<MAXN; i++)
            {
                if (spf[i] == i)
                {
                    for (int j=i*i; j<MAXN; j+=i)
                        if (spf[j]==j)
                            spf[j] = i;
                }
            }
        }
 
  int lcm(int a,int b){
      return a*b/__gcd(a,b);
  }
  
  // string s;
       signed main() {

          ios_base::sync_with_stdio(false);
          cin.tie(NULL);  
          cout.tie(0);  
       // -------------------------------------Code starts here--------------------------------------------------------------------- 
      int t=1;
      // cin>>t;
      while(t--)
      {
        

            int x=0,y=0;
          int mx=0,mi=INF,mn=INF;
            int tb,ta,tm=0;
            int n,m;
            // int a,b;
            cin>>n;
            map<string,int>mp;
            string s[n];
           for(int i=0;i<n;i++){
           cin>>s[i];
           mp[s[i]]++;}
          string r="AC";
          cout<<r<<" x "<<mp[r]<<endl;
          r="WA";
          cout<<r<<" x "<<mp[r]<<endl;
          r="TLE";
          cout<<r<<" x "<<mp[r]<<endl;
          r="RE";
          cout<<r<<" x "<<mp[r]<<endl;
            


                    }
   }

Measured memory_bytes: 6788
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<ll>
using namespace std;
using ll = long long;

int main(){
    string o,e;
    cin>>o>>e;
    rep(i,0,e.size()){
        cout<<o[i]<<e[i];
    }
    if(o.size()-e.size()==1) cout<<o.back();
    cout<<"\n";
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public void solve() {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		int count = 15;
		for (int i=0; i<s.length(); i++) {
			if (s.charAt(i) == 'x') {
				count--;
			}
		}
		in.close();
		if (count >= 8) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
	
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}
 
}


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

int main()
{
    int a, b, k;

    cin >> a >> b >> k;

    vector<int> v;

    int n = min(a, b);

    for(int i = 1; i <= n; i++){
        if((a%i) == 0 && (b%i) == 0) v.push_back(i);
    }

    sort(v.begin(), v.end(), greater<int>());

    cout << v[k-1] << "\n";

    return 0;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	int pn = 1;
	if (ci - cn + 16 > cm) {
		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
		A = ct - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
	else {
		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
		A = ct - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
}

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


	int N = getint();
	int A[200000];
	ll goukei = 0;
	rep(i, N) {
		A[i] = getint();
		goukei += A[i];
	}

	ll saishou = 1e18;
	ll kari = 0;
	rep(i, N - 1) {
		kari += A[i];
		saishou = min(saishou, abs(kari + kari - goukei));
	}
	printf("%d", saishou);


	Would you please return 0;
}

Measured memory_bytes: 1024
S = input()
n = len(S)
mod = 10**9+7
dp = [[0]*13 for _ in range(n+1)]
dp[0][0] = 1

for i in range(n):
    if S[i] == '?':
        for num in range(10):
            for j in range(13):
                dp[i+1][(j*10+num)%13] += dp[i][j]
    else:
        num = int(S[i])
        for j in range(13):
            dp[i + 1][(j * 10 + num) % 13] += dp[i][j]

    for j in range(13):
        dp[i + 1][j] %= mod

print(dp[n][5])

Measured memory_bytes: 61788
import fractions


def main():
    A, B = map(int, input().split())
    n = fractions.gcd(A, B)
    print(num_prime_factor(n))

def num_prime_factor(n):
    
    if n == 1: return 1
    
    ret = 1
    cursor = 2
    if n % cursor == 0: ret += 1
    while n % cursor == 0: n = n // cursor
    
    cursor = 3
    while cursor**2 <= n:
        if n == 1: return ret
        if n % cursor == 0: ret += 1
        while n % cursor == 0: n = n // cursor
        cursor += 2

    if n != 1: ret += 1
        
    return ret

if __name__ == "__main__":
    main()

Measured memory_bytes: 64364
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
    return a.first < b.first;
}

int main() { 
    int N, M; cin >> N >> M;
    vector<pair<ll, ll>> D;

    for (int i=0; i<N; i++) {
        ll a, b; cin >> a >> b;
        D.push_back(make_pair(a, b));
    }
    sort(D.begin(), D.end(), sortbysec);
    // for (auto v :D) cout << v.first << "," << v.second << endl;

    ll cost = 0;
    int ct = 0;
    for (auto v: D) {
        ll rest = M - ct;
        ll buy = min(rest, v.second);
        cost += buy * v.first;
        ct += buy;
    }
    cout << cost << endl;
    
    return 0;
}

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

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a >= b + 2)
    {
        printf(":(\n");
    }
    else if (b >= a + 2)
    {
        printf(":(\n");
    }
    else
    {
        printf("Yay!\n");
    }

    return 0;
}

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

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

    vector<int> d(N, 0);
    for(int i=0; i < N; i++){
        cin >> d.at(i);
    }

    int sum=0;
    for(int i=0; i<N; i++){
        for(int j=i; j<N; j++){
            if(i!=j){
                sum += d.at(i) * d.at(j);
            }
        }
    }

    cout << sum << endl;

}


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

int main() {
	string s;
	cin >> s;
	if (regex_match(s, regex("(dream|dreamer|erase|eraser)*")))
		cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 39808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N;
    cin >> N;
    VL A(N+1);
    map<ll, ll> mp1, mp2;
    rep(i, 1, N+1){
        cin >> A[i];
        mp1[A[i] - i]++;
        mp2[-i - A[i]]++;
    }
    ll ans = 0;
    for(auto p : mp1){
        if(mp2.count(p.first) == 0) continue;
        ans += p.second * mp2[p.first];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 27992
#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#define INF 0x3f3f3f3f
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;

inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
ll n,k,a[100005];
int main()
{
    ll i,j,sum=0,ans=0;
    scanf("%lld%lld",&n,&k);
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        if(a[i]>0)
            sum=sum+a[i];
    }

    ll temp1=sum,temp2=sum;
    for(i=1;i<=k;i++)
    {
        if(a[i]<0)
            temp1=temp1+a[i];
        else
            temp2=temp2-a[i];
    }
    ans=max(ans,max(temp1,temp2));

    for(i=2;i<=n-k+1;i++)
    {
        if(a[i-1]<0)
            temp1=temp1-a[i-1];
        else
            temp2=temp2+a[i-1];

        if(a[i+k-1]<0)
            temp1=temp1+a[i+k-1];
        else
            temp2=temp2-a[i+k-1];

        ans=max(ans,max(temp1,temp2));
    }

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

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
  int N, i;
  scanf("%d",&N);
  for(i=0;i<3;i++){
    if(N%10==7) break;
    N/=10;
  }
  if(N%10==7) printf("Yes");
  else printf("No");
  
  return 0;
}

Measured memory_bytes: 1720
def solve():
    N, M = map(int, input().split())
    g = [[False] * N for i in range(N)]
    bridge = []
    for i in range(M):
        a, b = map(lambda x: int(x)-1, input().split())
        bridge.append((a,b))
        g[a][b] = True
        g[b][a] = True
    
    ans = 0
    for a, b in bridge:
        visited = [False] * N
        g[a][b] = False
        g[b][a] = False
        if not dfs(0,g,visited,N):
            ans += 1

        g[a][b] = True
        g[b][a] = True
    
    print(ans)

def dfs(now, g, visited, N):
    visited[now] = True
    if isAllVisited(visited):
        return True
    
    for next in range(N):
        if g[now][next] and not visited[next]:
            if dfs(next, g, visited, N):
                return True
    
    return False

def isAllVisited(visited):
    for v in visited:
        if not v:
            return False
    
    return True

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

using Graph=vector<vector<int64_t>>;

int main()
{
  int n,q;
  cin>>n>>q;
  Graph tree(n);
  for (int i = 0; i < n-1; ++i)
  {
    int64_t a,b;
    cin>>a>>b;
    tree[a-1].emplace_back(b-1);
    tree[b-1].emplace_back(a-1);
  }
  vector<int64_t> ans(n,0LL);
  for (int i = 0; i < q; ++i)
  {
    int64_t p,x;
    cin>>p>>x;
    ans[p-1]+=x;
  }
  vector<bool> seen(n,false);
  seen[0]=true;
  queue<int> que;
  for(auto&& e: tree[0]) {
    que.push(e);
    ans[e]+=ans[0];
  }
  while(!que.empty()){
    int tgt=que.front();
    que.pop();
    seen[tgt]=true;
    for(auto&& e: tree[tgt]) {
      if(seen[e]) continue;
      que.push(e);
      ans[e]+=ans[tgt];
    }
  }
  for(auto&& e: ans) {
    cout<<e<<" ";
  }
}

Measured memory_bytes: 17136
#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++)
typedef long long ll;


int main() {
    ll n; cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i,n){
        cin >> a.at(i);
        b.at(i)=a.at(i);
    }
    sort(a.begin(),a.end());
    ll M=a.at(n-1);
    ll m=a.at(n-2);
    rep(i,n){
        if(b.at(i)==M){
            cout << m;
        }
        else cout << M;

        cout << endl;
    }
}

Measured memory_bytes: 4736
import sys

MAX = 999999
L = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]

def is_prime(n):
  if n == 2:return True
  if n % 2 == 0:return False
  for i in range(3,int(n**0.5)+1,2):
    if n % i == 0:return False
  return True

def is_prime_2(n):
  a = int(n ** 0.5)
  for i in L:
    if i > a:return True
    if n % i == 0:return False
  return True

def prime_count(n):
  result = 0
  if n >= 2:result+=1
  for i in range(3,n+1,2):
    if is_prime_2(i):result+=1
  return result

def prime_list(n):
  result = []
  if n >= 2:result.append(2)
  for i in range(3,n+1,2):
    if is_prime(i):result.append(i)
  return result

L2 = prime_list(MAX)

def prime_count_2(n):
  for i,v in enumerate(L2):
    if v > n:return i
  return len(L2)

for n in sys.stdin:
  print(prime_count_2(int(n)))

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

int n, k, w[100010];

bool ok(int P){
	int l = 0,p, count = 0;
	for (;;){
		p = P;
		while (p - w[l] > 0){
			if (l == n - 1)return true;
			p = p - w[l];
			l++;
		}
		count++;
		if (count == k)return false;
	}
}

int main(){
	cin >> n >> k;
	for (int i = 0; i < n; i++)cin >> w[i];
	int l = 0, h = 1e9;
	while (l + 1 < h){
		int mid = (l + h) / 2;
		if (ok(mid))h = mid;
		if (!ok(mid))l = mid;
	}
	cout << l << endl;
}

Measured memory_bytes: 1552
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef long double ld;
using namespace std;

const int MOD = 1e9 + 7;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, i;
  cin >> n >> i;
  cout << n - i + 1;

  return 0;
}


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

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

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

int s[100000];
int t[100000];
int c[100000];
int merge[200000];
int time[200000] = {0};

int main(void){
    int N, C;
    int i, j;
    int max = 0;
    scanf("%d %d", &N, &C);

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

    for (i = 1; i <= C; i++){
        for (j = 0; j < 200000; j++){
            merge[j] = 0;
        }
        for (j = 0; j < N; j++){
            if (c[j] == i){
                merge[s[j]*2-1] = 1;
                merge[t[j]*2] = -1;
            }
        }
        for (j = 1; j < 200000; j++){
            merge[j] += merge[j-1];
        }
        for (j = 0; j < 200000; j++){
            if (merge[j] > 0){
                time[j]++;
            }
        }
    }

    for (i = 0; i < 200000; i++){
        max = time[i]>max?time[i]:max;
    }

    printf("%d\n", max);


    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    string s,t,ans="";
    cin >> s >> t;
    vector<vector<int> > dp(s.size()+1,vector<int>(t.size()+1,0));
    for(int i=1;i<=s.size();i++){
        for(int j=1;j<=t.size();j++){
            if(s[i-1]==t[j-1])
                dp[i][j] = dp[i-1][j-1]+1;
            else
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int i=s.size(),j=t.size();
    while(i&&j){
        if(s[i-1]==t[j-1]){
            ans += s[i-1];
            i--,j--;
        } else if(dp[i][j]==dp[i-1][j])
            i--;
        else
            j--;
    }
    reverse(ans.begin(),ans.end());
    cout << ans;
    return 0;
}

Measured memory_bytes: 38560
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;
using Graph = vector<string>;

#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 revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    string S; cin >> S;
    vector<int> res;
    rep (i, 0, S.size()-2) res.push_back(stoi(S.substr(i, 3)));
    int ans = INF;
    rrep (i, 0, res.size()) ans = min(abs(753-res[i]), ans);
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
p = tuple(map(int, input().split( )))
q = tuple(map(int, input().split( )))

l = (i+1 for i in range(n))
import itertools
L =[]
for perm in itertools.permutations(l,n):
    L.append(perm)
import bisect

pi = bisect.bisect_left(L,p)
qi = bisect.bisect_left(L,q)

print(abs(qi-pi))

Measured memory_bytes: 8052
#include <stdio.h>

int signal[10][7] = {
	{0, 1, 1, 1, 1, 1, 1},
	{0, 0, 0, 0, 1, 1, 0},
	{1, 0, 1, 1, 0, 1, 1},
	{1, 0, 0, 1, 1, 1, 1},
	{1, 1, 0, 0, 1, 1, 0},
	{1, 1, 0, 1, 1, 0, 1},
	{1, 1, 1, 1, 1, 0, 1},
	{0, 1, 0, 0, 1, 1, 1},
	{1, 1, 1, 1, 1, 1, 1},
	{1, 1, 0, 1, 1, 1, 1},
};

int main(void)
{
	int n;
	
	while (scanf("%d", &n) + n != 0){
		int i, j;
		int num;
		int *before;
		
		scanf("%d", &num);
		for (i = 0; i < 7; i++){
			printf("%d", signal[num][i]);
		}
		puts("");
		for (i = 1; i < n; i++){
			before = signal[num];
			scanf("%d", &num);
			for (j = 0; j < 7; j++){
				printf("%d", signal[num][j] ^ before[j]);
			}
			puts("");
		}
	}
	
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);++i)
#define gep(i,n) for(int i = 1;i<(n);++i)
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    ll num = 1;
    rep(i,N){
        cin >> P.at(i);
    }
    vector<int> m(N);
    m.at(0) = P.at(0);//min
    gep(i,N){
        m.at(i) = min(m.at(i - 1),P.at(i));
//        cout << m.at(i) <<" ";
    }
/*    cout << endl; */
/*    rep(i,N){
        cout << m.at(i) <<" ";
    }
/////////////////////////////////////////////////    cuo*/
//    cout << endl;
//    bool a = true;
    gep(i,N){
        if(P.at(i) < m.at(i - 1)){
            num++;
        }
    }
    cout << num << endl;
	return 0;
}

Measured memory_bytes: 1792
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let s: i32 = read_as_vec()[0];

    let number1 = s/100;
    let number2 = (s/10)%100;
    let number3 = s%100;
    
    if number1%11 == 0 || number2%11 == 0 || number3%11 == 0{
        println!("Bad");
    }else{
        println!("Good");        
    }

    
}
    


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

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

int main (){
    ll n,k;
    cin >> k >> n;
    vector<ll>a(n);
    for(ll i=0;i<n;i++){
        cin >> a[i];
    }
    ll ans=a[n-1]-a[0];
    for(ll i=0;i<n;i++){
        ans=min(ans,a[n-1-i-1]+k-a[n-1-i]);
    }
    
   cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,m;
   cin >> n >> m;
   map<int,int> inc;
   map<int,int> done;
   int a;
   string b;
   int a1 = 0,a2 = 0;
   f(i,0,m){
      cin >> a >> b;
      if(done[a]){
         continue;
      }
      if(b == "AC"){
         a1 += 1;
         done[a] = 1;
         a2 += inc[a];
      }else{
         inc[a]++;
      }
   }
   cout << a1 << ' ' << a2 << '\n';
   return 0;
} 


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+10;
#define fi first
#define se second
#define pb push_back
int n;
int main() {
    ios::sync_with_stdio(false);
    cin>>n;
    cout<<(n-1)/2<<endl;
    return 0;
}

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

int main() {
	string a,b,c;
  	cin >> a >> b >> c;
  	if(a.back() == b.at(0)){
      if(b.back() == c.at(0)){
      cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
 	}else{
      cout << "NO" << endl;
    }
}

Measured memory_bytes: 256