akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  int x,y,z;
  cin>>x>>y>>z;
  int sum = 0;
  int count = 0;
  while(sum+y+z<=x-z){
    sum+=y+z;
    count++;
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 256
def differenceone(a , b , c):

    ans = 0
    if a == b:
        ans = c
    elif b == c:
        ans = a
    else:
        ans = b

    return ans

def main():
    a , b , c = map(int , input().split())
    print(differenceone(a , b , c))

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include <iostream>

using namespace std;

int main()
{
    int n, m;
    int l[100100], r[100100];

    cin >> n >> m;
    int cl = 1, cr = n;
    for (int i = 0;i < m;i++)
    {
        cin >> l[i] >> r[i];
        cl = max(cl, l[i]);
        cr = min(cr, r[i]);
    }
    cout << max(0, cr - cl + 1) << endl;
}

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

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

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
  int n;
    cin >> n;
    
    int a[n];
    f(i,n) cin >> a[i];
    
    int res = 0;
    int sum = 0;
    
    f(i,n)
    {
        res+=(sum*a[i])%MOD;
        res%=MOD;
        sum = (sum + a[i])%MOD;
    }
    
    cout << res;
    
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 5180
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  ll n;
  cin>>n;
  vector<vector<pair<ll,ll> > > vv(n,vector<pair<ll,ll> >());
  rep(i,0,n){
    ll a;
    cin>>a;
    rep(j,0,a){
      ll b,c;
      cin>>b>>c;
      b--;
      vv[i].pb(mp(b,c));
    }
  }
  ll mx = 0;
  rep(i,0,1<<n){
    ll flag = 1;
    rep(j,0,n){
      rep(k,0,vv[j].sz){
        ll a = (i>>j)&1;
        ll b = (i>>vv[j][k].fi)&1;
        ll c = vv[j][k].se;
        if(a==1){
          if(b!=c)flag = 0;
        }
      }
    }
    if(flag == 1){
      ll a = 0;
      rep(j,0,n){
        a += (i>>j)&1;
      }
      mx = max(mx,a);
    }
  }
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector> 
using namespace std;
#define oo 0x3f3f3f3f
#define ll long long
int a,b,c;
ll k;
int main(){
	scanf("%d%d%d%lld",&a,&b,&c,&k);
	if (k&1)printf("%d",b-a);
	else printf("%d",a-b);
} 

Measured memory_bytes: 128
N , K = map(int, input().split())
li = list(map(int, input().split()))
if K < N:
    town = 0
    for i in range(K):
        town = li[town]-1
    print(town+1)
else:
    li2 = [0for i in range(N)]
    count = 1
    town = 0
    while(1):
        if li2[town] != 0:
            num = count - li2[town]
            num2 = li2[town]
            break
        li2[town] = count
        town = li[town]-1
        count += 1

    K = K - (num2 - 1)
    mod = K % num
    #print(mod)
    #print(li2, num, num2)
    for i in range(mod):
        town = li[town] -1
    print(town+1)

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

int main() {
  ll m,D=0,S=0,d,c;
  cin >> m;
  rep(i,m){
  	cin >> d >> c;
    D+=c;
    S+=d*c;
  }
  	cout << D-1+(S-1)/9 << endl;
}


Measured memory_bytes: 256
#pragma G++ optimize(2)
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define LL long long
#define O4 __inline__ __attribute__((always_inline))
#define inf 0x7fffffff
#define UL unsigned LL
#define LD long double
#ifdef ONLINE_JUDGE
#define getchar nc
#endif
//#define int LL
namespace FastIO{
	O4 char nc(){
		static char buf[100000],*p1=buf,*p2=buf;
		return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
	}
	O4 int read(){
		char t;int u=0,k=1;t=getchar();
		while(t<'0'||t>'9'){if(t=='-')k=-1;t=getchar();}
		while(t>='0'&&t<='9'){u=u*10+t-'0';t=getchar();}
		return u*k;
	}
	template <typename T>
	O4 void read(T &u){
		char t;T k=1;u=0;t=getchar();
		while(t<'0'||t>'9'){if(t=='-')k=-1;t=getchar();}
		while(t>='0'&&t<='9'){u=u*10+t-'0';t=getchar();}
		if(t=='.'){
			T mass=0.1;t=getchar();
			while(t>='0'&&t<='9'){u+=mass*(t-'0');mass/=10;t=getchar();}
		}u*=k;
	}
	O4 int read(char asd[]){
		char t=getchar();int u=0;
		while(t==' '||t=='\n'||t=='\r')t=getchar();
		if(t==EOF)return -1;
		while(t!=' '&&t!='\n'&&t!=EOF&&t!='\r')asd[u++]=t,t=getchar();
		asd[u]='\0';return u;
	}
	char sr[1<<23],z[23];int C=-1,Z;
	O4 void wer(int x,char T){
		int y=0;if(x<0)y=1,x=-x;
		while(z[++Z]=x%10+'0',x/=10);if(y)z[++Z]='-';
		while(sr[++C]=z[Z],--Z);sr[++C]=T;
	}
	O4 void wer(char T[],char QWQ){
		for(int i=0;T[i]!='\0';i++)sr[++C]=T[i];
		sr[++C]=QWQ;
	}
	O4 void wer(char T){sr[++C]=T;}
	O4 void out(){fwrite(sr,1,C+1,stdout);C=-1;}
}
using namespace std;
using namespace FastIO;
const int N=305,MOD=1e9+7;
int n,m;
int F[N*2][N][N];
int flag[N*2],Free;
int sta[N*2],top;
void Add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
signed main(){
	n=read();
	for(int i=1;i<=n*2;i+=2){
		int a=read(),b=read();
		if(a!=-1&&b!=-1)flag[a]=2,flag[b]=2;
		else if(a!=-1)flag[a]=1;
		else if(b!=-1)flag[b]=1;
		else Free++;
	}
	for(int i=1;i<=n*2;i++){
		if(flag[i]==1)sta[++top]=1;
		if(flag[i]==0)sta[++top]=0;
	}
	F[top][0][0]=1;
	for(int i=top;i;i--)
		for(int j=0;j<=min(top,n);j++)
			for(int k=0;k<=min(top,n);k++){
				if(sta[i]==0){
					Add(F[i-1][j+1][k],F[i][j][k]);
					if(j!=0)Add(F[i-1][j-1][k],F[i][j][k]);
					if(k!=0)Add(F[i-1][j][k-1],1ll*F[i][j][k]*k%MOD);
				}
				else{
					Add(F[i-1][j][k+1],F[i][j][k]);
					if(j!=0)Add(F[i-1][j-1][k],F[i][j][k]);
				}
			}
	int Ans=F[0][0][0];
	for(int i=1;i<=Free;i++)Ans=1ll*Ans*i%MOD;
	cout<<Ans;
	return 0;
}

Measured memory_bytes: 221624
import sys
read = sys.stdin.read

N, *A = map(int, read().split())
mod = 10 ** 9 + 7

hats = [0] * 3
answer = 1

for i in range(N):
    answer *= hats.count(A[i])
    answer %= mod
    for j in range(3):
        if hats[j] == A[i]:
            hats[j] += 1
            break

print(answer)

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

int main(){
    long long i,j,k,K,ans;
    cin>>K;
    ans=0;
    for(i=1;i<=K;i++){
        for(j=1;j<=K;j++){
            for(k=1;k<=K;k++){
                ans+=gcd(i,gcd(j,k));
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
int main(){
  int n,i,j,k,v,A[1000];

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

Measured memory_bytes: 608
/*
Author : N_o_o_B
Created : April 22 2020 22:18:02 
*/
#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 TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#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 ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    int n,m;
    cin >> n >> m;
    vi ans(n);
    fori(i,m){
        int u,v;
        cin >> u >> v;
        u--;v--;
        ans[u]++;
        ans[v]++;
    }
    fori(i,n){
        cout << ans[i] << endl;
    }



    time_taken();
    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
sc=[list(map(int,input().split()))for _ in [0]*M]

ans=['1']+['0']*(N-1)
count=[0]*N
for s,c in sc:
    if count[s-1]==1 and ans[s-1]!=str(c):
        ans='-1'
        break
    else:
        ans[s-1]=str(c)
        count[s-1]=1

if N>=2 and ans[0]=='0':
    ans='-1'

if M==0 and N==1:
    ans='0'

print(''.join(ans))

Measured memory_bytes: 3064
#include<iostream>
#include<cstdlib>
#include<complex>
#define EPS 1e-10
using namespace std;

typedef complex<double> Po;
Po p[3],o;

double dot(Po x, Po y){return x.real()*y.real()+x.imag()*y.imag();}

double cross(Po x, Po y){return x.real()*y.imag() - x.imag()*y.real();}

double area(Po a, Po b, Po c){return abs(cross(b-a,c-a))/2;}

bool inter(Po a, Po b, Po c, Po x){
  return (fabs(area(a,b,x)+area(b,c,x)+area(c,a,x)-area(a,b,c)) < EPS);
}

double seg_dis(Po a, Po b, Po c){
  if(dot(b-a,c-a)<EPS)return abs(c-a);
  if(dot(a-b,c-b)<EPS)return abs(c-b);
  return abs(cross(b-a,c-a))/abs(b-a);
}

int main(){
  double x[4],y[4],r;
  int i;

  for(;;){
    cin >> x[0] >> y[0];
    if(!x[0] && !y[0])break;

    for(i=1;i<4;i++)cin >> x[i] >> y[i];
    cin >> r;

    for(i=0;i<3;i++)p[i] = Po(x[i],y[i]);
    o = Po(x[3],y[3]);


    bool f = true;;
    for(i=0;i<3;i++)f &= !(abs(o-p[i])>r);
    if(f)cout << "b\n";
    else if(inter(p[0],p[1],p[2],o)){
      f = true;
      for(i=0;i<3;i++)f &= !(seg_dis(p[i],p[(i+1)%3],o)<r);
      if(f)cout << "a\n";
      else cout << "c\n";
    }else{
      for(i=0;i<3;i++)f |= !(seg_dis(p[i],p[(i+1)%3],o)>r);
      if(f)cout << "c\n";
      else cout << "d\n";
    }
  }
}

Measured memory_bytes: 0
n = int(input())
t, a = map(int, input().split())
r = 10000
p = 0
li = list(map(int, input().split()))
for i in range(len(li)):
    if abs(t - li[i] * 0.006 - a) <= r:
        r = abs(t - li[i] * 0.006 - a)
        p = i + 1
print(p)


Measured memory_bytes: 3060
#include <stdio.h>

int main() {
	const long long int mod = 7 + 1e9;
	int n;
	long long int ans = 0, n9 = 1, n8 = 1, n10 = 1;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		n9 *= 9;
		n9 = n9 % mod;
		n8 *= 8;
		n8 = n8 % mod;
		n10 *= 10;
		n10 = n10 % mod;
	}
	ans = n10 - 2 * n9 + n8;
	for (int i = 0;; i++) {
		if (ans < 0)ans += mod;
		if (mod <= ans)ans -= mod;
		if (0 <= ans && ans < mod)break;
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 1000002
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d ", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007
#define mod 998244353
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

void solve()
{
    ll n, l;
    cin>>n>>l;
    vector<ll>a(n);
    for(int i = 0; i < n; i++)
        cin>>a[i];
    int pos = -1;
    for(int i = 0; i < n-1; i++)
    {
        if(a[i]+a[i+1]>=l)
        {
            pos = i + 1;
            break;
        }
    }
    if(pos==-1)
    {
        cout<<"Impossible"<<endl;
    }
    else
    {
        cout<<"Possible"<<endl;
        for(int i = 1; i < pos; i++)
            cout<<i<<endl;
        for(int i = n-1; i > pos; i--)
            cout<<i<<endl;
        cout<<pos<<endl;
    }
}

int main()
{
    FASTIO;
    solve();

    return 0;
}


Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
#define clr(a, x) memset(a, x, sizeof(a))
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define X first
#define Y second
#define fastin                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;

void solve(ll N)
{
    for (ll x = 1; x <= 3500; x++)
        for (ll y = 1; y <= 3500; y++)
        {
            ll t1 = 4 * x * y - N * y - N * x;
            if (t1 <= 0) continue;
            ll t2 = N * x * y;
            // cout << t1 << " " << t2 << endl;
            if (t2 % t1 == 0)
            {
                cout << x << " " << y << " " << t2 / t1 << endl;
                return;
            }
        }
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.in", "r", stdin);
// freopen("1.out", "w", stdout);
#endif
    ll N;
    while (cin >> N)
        solve(N);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;
/// khodaya komak kon
/// ya navid navid
/// ye tec khaphan ke yadam bemone : age jayi didi soale masir hamiltoni mikhad rasasho bokon yal oilery;
/// age ye ja mikhasti to dp az ozv i k ta entekhab koni bejash ye log bezan (nominal) hamoon 2**k va o 1 ent kon

///\\\///\\\///\\\\\\\\\\\\\\\\\///\\\///\\\///

const int N=410,mod=1e9+7;
ll a[N];
int32_t main(){
    sync;
    ll n;
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> a[i];
    }
    ll mi=(ll)1e15;
    for (int i=-200;i<200;i++){
        ll ans=0;
        for (int j=0;j<n;j++){
            ans+=(a[j]-i)*(a[j]-i);
        }
        mi=min(mi,ans);
    }
    cout << mi;

}


















Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define _USE_MATH_DEFINES
#define mp       make_pair
#define pb       push_back
#define fst      first
#define snd      second
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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


int main()
{
    int H, W; cin >> H >> W;
    string A[1000];
    rep(i, H) cin >> A[i];

    int n[1000][1000];
    queue<pii> Q_yx;
    rep(y,H) rep(x,W) {
        if(A[y][x] == '#') {
            n[y][x] = 0;
            Q_yx.push(mp(y,x));
        } else {
            n[y][x] = -1;
        }
    }

    while(!Q_yx.empty()) {
        pii yx = Q_yx.front(); Q_yx.pop();
        int y = yx.fst, x = yx.snd;
        rep(i, 4) {
            int ny = y + dy[i], nx = x + dx[i];
            if(ny >= 0 && ny < H && nx >= 0 && nx < W && n[ny][nx] == -1) {
                n[ny][nx] = n[y][x] + 1;
                Q_yx.push(mp(ny,nx));
            }
        }
    }

    int ans = -1;
    rep(y,H) rep(x,W)
        ans = max(n[y][x], ans);

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


Measured memory_bytes: 13456
h, w = map(int, input().split())
s = [input() for i in range(h)]

memo = [[0]*w for i in range(h)]

from collections import deque
q = deque()
q.append((0, 0))

while len(q) > 0:
    y, x = q.popleft()
    if y == h-1 and x == w-1:
        break
    if x > 0:
        if s[y][x-1] == "." and memo[y][x-1] == 0:
            q.append((y, x-1))
            memo[y][x-1] = memo[y][x] + 1
    if x < w-1:
        if s[y][x+1] == "." and memo[y][x+1] == 0:
            q.append((y, x+1))
            memo[y][x+1] = memo[y][x] + 1
    if y > 0:
        if s[y-1][x] == "." and memo[y-1][x] == 0:
            q.append((y-1, x))
            memo[y-1][x] = memo[y][x] + 1
    if y < h-1:
        if s[y+1][x] == "." and memo[y+1][x] == 0:
            q.append((y+1, x))
            memo[y+1][x] = memo[y][x] + 1

count = 0

for H in range(h):
    for W in range(w):
        if s[H][W] == "#":
            count += 1

if memo[h-1][w-1] == 0:
    print(-1)
else:
    print(w*h - memo[h-1][w-1]-1 - count)

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define MAX (ll)(1e9)

int main(){
	ll s;
	cin >> s;
	ll x=(s+MAX-1)/MAX, y=MAX*x-s;
	printf("%lld %lld %lld %lld %lld %lld\n", 0ll, 0ll, 1ll, MAX, x, y);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 2e3 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, k;
ll fact[maxn * maxn], invfact[maxn * maxn], dp[maxn][maxn];

ll powmod(ll a, ll b)
{
	if (b == 1)
		return a;
	ll tmp = powmod(a, b / 2);
	tmp = tmp * tmp % mod;
	if (b & 1)
		tmp = tmp * a % mod;
	return tmp;
}

ll comb(int n, int r)
{
	return (fact[n] * (invfact[r] * invfact[n - r] % mod) % mod);
}

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

	fact[0] = invfact[0] = 1;
	for (int i = 1; i < maxn * maxn; i++)
	{
		fact[i] = fact[i - 1] * i % mod;
		invfact[i] = powmod(fact[i], mod - 2);
	}

	cin >> n >> k;
	if (k == 1)
	{
		cout << 1 << endl;
		return 0;
	}
	dp[1][0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= i; j++)
		{
			if (i < n)
				dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod;
			if (j < i)
				dp[i][j + 1] = (dp[i][j + 1] + dp[i][j] * comb(n * k - i - j * (k - 1) - 1, k - 2)) % mod;
		}
	cout << dp[n][n] * fact[n] % mod << endl;
}



Measured memory_bytes: 102144
N=int(input())
A=list(map(int,input().split()))
l=[]
def abs(x):
    if x >=0:
        return x
    else:
        return x*(-1)
for j in range(N):
    for k in range(j+1,N):
        l.append(abs(A[k]-A[j]))
max=l[0]
for m in range(len(l)):
    if max<l[m]:
        max=l[m]
print(max)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007


int main(){
  int n;
  string s;
  cin >> n >> s;
  string t;
  rep(i,s.size()){
    int tmp = s.at(i) - 'A';
    tmp = (tmp + n)%26;
    t.push_back('A'+tmp);
  }
  cout << t << endl;
}


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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main()
{
  ll A, B, K;
  cin >> A >> B >> K;
  rep(i, A, B+1){
    if (i <= A + K - 1 || i >= B - K + 1)
    {
      cout << i << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
from queue import Queue

S = input()

ans = [0] * len(S)

R = Queue()
for i in range(len(S)):
    if S[i] == 'R':
        R.put(i)
    else:
        while not R.empty():
            r = R.get()
            l = i

            if abs(l - r) % 2 == 0:
                ans[i] += 1
            else:
                ans[i-1] += 1

L = Queue()
for i in range(len(S)-1, -1, -1):
    if S[i] == 'L':
        L.put(i)
    else:
        while not L.empty():
            l = L.get()
            r = i

            if abs(l - r) % 2 == 0:
                ans[i] += 1
            else:
                ans[i+1] += 1

print(' '.join(map(str, ans)))

Measured memory_bytes: 11888
#include <iostream>
using namespace std;
int a, b, c;

int main() {
	cin >> a >> b >> c;

	if (a == b && b == c)
	{
		cout << 1 << endl;
	} else if (a==b || b==c || c==a)
	{
		cout << 2 << endl;
	} else {
		cout << 3 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,f[N],fff[N],ggg[N],g[N],t[2][N<<2],pre[N],bk[N];
struct node
{
    int x,id;
    bool operator<(const node&o)const
    {
        return x<o.x;
    }
}a[N],b[N],s[N];
void build(int l,int r,int k)
{
    if(l==r)
    {
        t[0][k]=pre[l];
        t[1][k]=bk[l];
        return;
    }
    int m=l+r>>1;
    build(l,m,k<<1);
    build(m+1,r,k<<1|1);
    t[0][k]=t[0][k<<1]&t[0][k<<1|1];
    t[1][k]=t[1][k<<1]&t[1][k<<1|1];
}
int query(int l,int r,int k,int x,int y,int p)
{
    if(l>y||r<x) return 1;
    if(l>=x&&r<=y) return t[p][k];
    int m=l+r>>1;
    return query(l,m,k<<1,x,y,p)&query(m+1,r,k<<1|1,x,y,p);
}
bool vis[N];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i].x),a[i].id=i;
    for(int i=1;i<=n;i++) scanf("%d",&b[i].x),b[i].id=i;
    for(int i=1;i<=n;i++)
        s[i].x=b[i].x,s[i].id=a[i].x;
    sort(s+1,s+1+n);
    for(int i=1;i<=n;i++)
        s[i].x=s[i].id;
    for(int i=1;i<=n;i++)
        s[i].id=i;
    sort(s+1,s+1+n);
    sort(a+1,a+1+n);
    sort(b+1,b+1+n);
    bool flag=true;
    for(int i=1;i<=n;i++)
        if(a[i].x>b[i].x) flag=false;
    for(int i=2;i<=n;i++)
        if(a[i-1].x<=b[i].x) pre[i]=1;
    for(int i=1;i<n;i++)
        if(a[i+1].x<=b[i].x) bk[i]=1;
    build(1,n,1);
    for(int i=1;i<=n;i++)
    {
        f[a[i].id]=i;fff[a[i].id]=a[i].x;
        g[b[i].id]=i;ggg[b[i].id]=b[i].x;
    }
    bool ff=false;
    for(int i=1;i<=n;i++)
    {
        if(fff[i]>ggg[i]) continue;
        int x=f[i],y=g[i];
        if(x==y||b[x].x==ggg[i]||a[y].x==fff[i]||fff[i]==ggg[i]) {ff=true;break;}
        if(x<y)
        {
            if(query(1,n,1,x,y-1,1)) ff=true;
        }
        else
        {
            if(query(1,n,1,y+1,x,0)) ff=true;
        }
    }
    int now=1;
    while(!vis[now])
    {
        vis[now]=true;
        now=s[now].id;
    }
    for(int i=1;i<=n;i++)if(!vis[i])ff=true;
    if(!ff) flag=false;
    printf(flag?"Yes\n":"No\n");
}


Measured memory_bytes: 31872
l=list(map(int, input().split()))
l.sort()
cnt=0
while l[0]!=l[1] or l[0]!=l[2] or l[1]!=l[2]:
    l.sort()
    #print(l)
    if l[1] == l[2]:
        l[0] += 2
    else:
        l[0] += 1
        l[1] += 1
    cnt+=1

print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n, k;
  string s;
  cin >> n >> s >> k;
  for (ll i = 0; i < n; i++) {
    if (s[i] != s[k - 1]) s[i] = '*';
  }
  cout << s << endl;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

typedef pair<int,int> P;

const int MAX_N=800,INF=1E8;

int n;
int p[MAX_N];
int d[MAX_N];

vector<P> G[MAX_N];

int dist[MAX_N];
int pre[MAX_N];
bool used[MAX_N];

void bfs(int s){
	fill(dist,dist+n,INF);
	fill(pre,pre+n,-1);
	dist[s]=0;
	queue<int> q;
	q.push(s);
	while(!q.empty()){
		int v=q.front();
		q.pop();
		REP(i,G[v].size()){
			P p=G[v][i];
			if (dist[p.first]==INF && G[p.first].size()!=1){
				dist[p.first]=dist[v]+p.second;
				pre[p.first]=v;
				q.push(p.first);
			}
		}
	}
}

int main(){
	do{
		scanf("%d",&n);
		if (n){
			fill(used,used+n,false);
			REP(i,n){
				G[i].clear();
			}
			REP(i,n-1){
				scanf("%d",&p[i+1]);
				p[i+1]--;
			}
			REP(i,n-1){
				scanf("%d",&d[i+1]);
			}
			FOR(i,1,n){
				G[i].push_back(P(p[i],d[i]));
				G[p[i]].push_back(P(i,d[i]));
			}
			bfs(0);
			int s=0;
			REP(i,n){
				if (dist[i]!=INF){
					if (dist[i]>dist[s]){
						s=i;
					}
				}
			}
			bfs(s);
			int g=s;
			REP(i,n){
				if (dist[i]!=INF){
					if (dist[i]>dist[g]){
						g=i;
					}
				}
			}
			for(int i=g;i!=-1;i=pre[i]){
				used[i]=true;
			}
			int ans=0;
			FOR(i,1,n){
				if (G[i].size()==1 || G[p[i]].size()==1){
					ans+=d[i];
				}
				else if (used[i] && used[p[i]]){
					ans+=d[i]*2;
				}
				else{
					ans+=d[i]*3;
				}
			}
			printf("%d\n",ans);
		}
	}while(n);
	return 0;
}

Measured memory_bytes: 1312
#include<bits/stdc++.h>
#define int			long long
#define ll 			long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define INF			LLONG_MAX
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define dep(i,a,b)	for(int i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  17

ll n;
ll a[N][N];
ll pre[(1ll<<N)];
ll dp[1LL<<N];


ll calc(ll mask){
	if(mask==0)return 0;
	if(dp[mask]!=-1LL)return dp[mask];
	dp[mask]=-INF;
	for(ll i=mask;i>0;i=(i-1)&mask){
		ll remask = mask^i;
		dp[mask]=max(dp[mask],calc(remask)+pre[i]);
	}
	// cerr<<"mask:"<<mask<<" val:"<<dp[mask]<<endl;
	return dp[mask];
}


void solve()
{
	cin>>n;
	rep(i,0,n){
		rep(j,0,n){
			cin>>a[i][j];
		}
	}
	for(ll i=0;i<(1ll<<n);i++){
		for(ll j=0;j<n;j++){
			for(ll k=j+1;k<n;k++){
				if(i&(1LL<<j) && i&(1LL<<k))
					pre[i]=pre[i]+	a[j][k];	
			}
		}
		// cerr<<"i: "<<i<<" pre:"<<pre[i]<<endl;
	}
	memset(dp,-1LL,sizeof(dp));
	cout<<calc((1LL<<n)-1)<<endl;

}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 5196
#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;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n, k;
    cin>>n>>k;
    if((n - 1)/2 + 1 >= k){
        cout<<"YES";
    }
    else cout<<"NO";
    return 0;
}

Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			List<Product> points = new ArrayList<>();
			for(int i=0;i<n;i++) {
				points.add(new Product(sc.nextInt(), sc.nextInt(), sc.next().charAt(0), sc.nextLong(), sc.next()));
			}
			points.sort((p1, p2) -> {
				int compare = p1.value - p2.value;
				if(compare == 0) {
					compare = p1.weight - p2.weight;
					if(compare == 0) {
						compare = p1.type - p2.type;
						if(compare == 0) {
							compare = (int)(p1.date - p2.date);
							if(compare == 0) {
								compare = p1.name.compareTo(p2.name);
							}
						}
					}
				}
				return compare;
			});
			points.forEach(product -> System.out.println(
						product.value + " " + product.weight + " " + product.type + " " + product.date + " " + product.name
					));
		}
	}
	static class Product{
		public int value;
		public int weight;
		public char type;
		public long date;
		public String name;
		public Product(int value, int weight, char type, long date, String name) {
			this.value = value;
			this.weight = weight;
			this.type = type;
			this.date = date;
			this.name = name;
		}
	}
}


Measured memory_bytes: 176116
#include <iostream>
#include <vector>
using namespace std;
typedef long long int lli;
const lli mod = 1e9+7;

void search(vector<int> &in, vector<lli> &out, int c, int st){
	if(in[0]!=-1 && in[1]!=-1 && in[2]!=-1){
		if(in[0]+in[1]+c == in[2]) out[0]++;
		if(in[0]+in[1]+c == in[2]+10) out[1]++;
		return;
	}
	for(int i=0; i<3; i++){
		if(in[i] == -1){
			for(int d=st; d<=9; d++){
				in[i] = d;
				search(in, out, c, st);
				in[i] = -1;
			}
			return;
		}
	}
}

int main(){
	while(1){
		string str[3];
		cin >> str[0];
		if(str[0]=="0") break;
		cin >> str[1] >> str[2];
		int n=str[0].length();
		
		vector<vector<lli> > pos_c(n, vector<lli>(2, 0));
		vector<vector<lli> > pos_nc(n, vector<lli>(2, 0));
		for(int i=0; i<n; i++){
			vector<int> in(3);
			for(int j=0; j<3; j++){
				in[j] = (str[j][n-i-1] == '?')? -1: str[j][n-i-1]-'0';
			}
			search(in, pos_nc[i], 0, (i==n-1)?1: 0);
			search(in, pos_c[i],  1, (i==n-1)?1: 0);
		}
		
		vector<vector<lli> > dp = pos_nc;
		for(int i=0; i<n-1; i++){
			dp[i+1][0] = (dp[i][0]*pos_nc[i+1][0] +dp[i][1]*pos_c[i+1][0])%mod;
			dp[i+1][1] = (dp[i][0]*pos_nc[i+1][1] +dp[i][1]*pos_c[i+1][1])%mod;
		}
		cout << dp[n-1][0] << endl;
	}
	return 0;
}

Measured memory_bytes: 3024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
	}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	int a,b,k;
    cin >> a >> b >> k;
    if(((b-a)/2+1)<=k){
        for(int i=a;i<=b;i++) cout << i << endl;
    }
    else{
        for(int i=a;i<=a+k-1;i++) cout << i << endl;
        for(int i=b-k+1;i<=b;i++) cout << i << endl;
    }
	return 0;
}


Measured memory_bytes: 256
def resolve():
    N = int(input())
    S = input()
    ans = 0

    for i in range(10):
        idx1 = S.find(str(i))
        if idx1 < 0:
            continue
        for j in range(0, 10):
            idx2 = S.find(str(j), idx1+1)
            if idx2 < 0:
                continue
            for k in range(0, 10):
                idx3 = S.find(str(k), idx2+1)
                if idx3 < 0:
                    continue
                ans += 1
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> opset;
#define SZ(X) ((int)X.size())
#define ALL(I) I.begin(), I.end()
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define eps 1e-12
#define INF 1000000007
#define MXN 200005
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

int n, b[MXN], ans[MXN];

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++) scanf("%d", &b[i]);
	for(int i = 1; i <= n; i ++){
		int pos = -1;
		for(int j = 1, cnt = 1; j <= n; j ++, cnt ++){
			if(b[j] == -1){
				cnt --;
				continue;
			}
			if(b[j] == cnt) pos = j;
		}
		if(pos == -1){
			puts("-1");
			return 0;
		}
		ans[i] = b[pos];
		b[pos] = -1;
	}
	for(int i = n; i; i --) printf("%d\n", ans[i]);
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    double v[n],w;
    for(int i=0; i<n; i++)
        scanf("%lf",&v[i]);
    for(int i=0; i<n; i++){
        for(int j=n-1; j>i; j--){
            if(v[j-1]<v[j]){
                w=v[j];
                v[j]=v[j-1];
                v[j-1]=w;
            }
        }
    }
    for(int i=n-1; i>0; i--){
        v[i-1]=(v[i-1]+v[i])/2;
    }
    printf("%f",v[0]);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
const double PI = 3.14159265359;
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define INF 1000000000000
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST
int n,m,k;
ll h=0,c=0;
cin>>n>>m>>k;
ll a[n],b[m],x=0, y=0,x1=0,y1=0,ans=0;
vector<ll> p,q;
FOR(i,n)
{
	cin>>a[i];
	if(i==0)
	{
		p.pb(a[i]);
	}
	else
	{ 
		p.pb(p[i-1]+a[i]);
	}
}
FOR(i,m)
{
	cin>>b[i];
		if(i==0)
	{
		q.pb(b[i]);
	}
	else
	{
		q.pb(q[i-1]+b[i]);
	}
}
FOR(i,n)
{  if(k-p[i]>0)
   {     x=upper_bound(q.begin(),q.begin()+m,k-p[i])-q.begin();
	     ans=max(ans,x+i+1);
   }
   else if(k-p[i]==0)
   {
   	x=i+1;
   	ans=max(ans,x);
   	 	break;
   }
   else
   {
   	x=i;
   	ans=max(ans,x);
   	break;
   }

}
FOR(i,m)
{
   if(k-q[i]>0)
   {     x=upper_bound(p.begin(),p.begin()+n,k-q[i])-p.begin();
	     ans=max(ans,x+i+1);
   }
   else if(k-q[i]==0)
   {
   	x=i+1;
   	ans=max(ans,x);
   	 	break;
   }
   else
   {
   	x=i;
   	ans=max(ans,x);
   	 	break;
   }
}
cout<<ans<<endl;
return  0;
}






Measured memory_bytes: 10552
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a==1)
    a=14;
  if(b==1)
    b=14;
  if(a>b)
    cout<<"Alice";
  else
    if(a<b)
      cout<<"Bob";
  else
    cout<<"Draw";
    
}
  

Measured memory_bytes: 3608
// package app;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        int K = sc.nextInt();

        int N = sc.nextInt();

        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int max = K - A[N - 1] + A[0];
        for (int i = 1; i < N; i++) {
            max = Math.max(max, A[i] - A[i - 1]);
        }

        int ans = K - max;
        System.out.println(ans);
    }
}

Measured memory_bytes: 83064
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();		//n枚の投票用紙
		
		 Map<String, Integer>map=new HashMap<>();
		 
	        int max=0;
	        for(int i=0;i<n;i++) {
	            String s=sc.next();
	            if (map.containsKey(s)) {
	                map.put(s,map.get(s) + 1);
	 
	            }else{
	                map.put(s,1);
	            }
	            max=Math.max(max,map.get(s));
	        }
	 
	        List<String>array= new ArrayList<>();
	        for (Map.Entry<String, Integer>key: map.entrySet()) {
	            if (key.getValue() == max) {
	                array.add(key.getKey());
	            }
	        }
	        Collections.sort(array);
	        for (String s:array) {
	            System.out.println(s);
	    }
	        sc.close();
	}

}

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

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

using ll = long long;
using namespace std;

template <long long N>
class Modulo {
 public:
  using Type = decltype(N);
  // constructor
  constexpr Modulo (Type n = 0) : number_((N + n) % N) {}
  // unary operator
  constexpr auto operator - () const {
    return Modulo(-number_);
  }
  constexpr auto operator ~ () const {
    // Only if N is prime, and number_ and N are coprime
    return power(*this, N - 2);
  }
  // compound assign operator
  constexpr auto & operator += (const Modulo & m) {
    number_ = (number_ + m.number_) % N;
    return *this;
  }
  constexpr auto & operator -= (const Modulo & m) {
    return *this += -m;
  }
  constexpr auto & operator *= (const Modulo & m) {
    number_ = (number_ * m.number_) % N;
    return *this;
  }
  constexpr auto & operator /= (const Modulo & m) {
    return *this *= ~m;
  }
  // binary operator with type conversion
  constexpr friend auto operator + (Modulo lhs, const Modulo & rhs) {
    return lhs += rhs;
  }
  constexpr friend auto operator - (Modulo lhs, const Modulo & rhs) {
    return lhs -= rhs;
  }
  constexpr friend auto operator * (Modulo lhs, const Modulo & rhs) {
    return lhs *= rhs;
  }
  constexpr friend auto operator / (Modulo lhs, const Modulo & rhs) {
    return lhs /= rhs;
  }
  // friend function
  constexpr friend auto power (const Modulo & m, Type exponent) {
    constexpr auto unit = Modulo(1);
    if ( exponent == 0 ) return unit;
    return (exponent & 1 ? m : unit) * power(m*m, exponent >> 1);
  }
  constexpr friend auto number (const Modulo & m) {
    return m.number_;
  }
  // stream operator
  friend auto & operator << (std::ostream & os, const Modulo & m) {
    return os << number(m);
  }
 private:
  Type number_;
};

class Factorizer {
 public:
  explicit Factorizer (int n) : table_(n + 1, 0) {
    for (int i = 2; i <= n; ++i) {
      if (table_[i]) continue;
      // Now, i is prime
      for (int j = i; j <= n; j += i) {
        if (table_[j]) continue;
        table_[j] = i;
      }
    }
  }
  auto factorList (int n) {
    vector<int> list;
    while ( 2 <= n ) {
      list.push_back(table_[n]);
      n /= table_[n];
    }
    return list;
  }
  auto factorMap (int n) {
    map<int, int> map;
    for (const auto & p : factorList(n)) {
      map[p]++;
    }
    return map;
  }
 private:
  vector<int> table_;
};

int
main ()
{
    using Number = Modulo<1'000'000'007ll>;
    auto x = Factorizer(1'000'000);

    int n;
    cin >> n;

    map<int, int> lcm_m;
    vector<int> a(n);
    for (auto & e : a) {
      cin >> e;
      for (auto p : x.factorMap(e)) {
        lcm_m[p.first] = max(lcm_m[p.first], p.second);
      }
    }

    auto lcm_n = Number(1);
    for (auto p : lcm_m) {
      lcm_n *= power(Number(p.first), p.second);
    }

    auto answer = Number(0);
    for (auto e : a) {
      answer += lcm_n / e;
    }

    std::cout << answer << std::endl;
}


Measured memory_bytes: 4608
n,q=map(int,input().split())
s=input()
lr=[]
for i in range(q):
    a=[int(j) for j in input().split()]
    lr.append(a)

la=[0 for i in range(n)]
lc=[0 for i in range(n)]
x=0
y=0
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        x+=1
        y+=1
        
    la[i]=x
    lc[i+1]=y
        
for i in range(q):
    print(min(la[lr[i][1]-2]-la[lr[i][0]-2],lc[lr[i][1]-1]-lc[lr[i][0]-1]))
    














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

int main(){
  long long X,Y;
  cin>>X>>Y;
  
  long long tmp=X;
  int ans=0;
  while(tmp<=Y){
    ans++;
    tmp*=2;
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n[3];
  cin >> n[0] >> n[1] >> n[2];
  sort(n, n + 3);
  cout << n[0] << ' ' << n[1] << ' ' << n[2] << endl;
  return 0;
}

Measured memory_bytes: 3144
function gets(str){
  this._s = str.split("\n");
  this._y = 0;
};
gets.prototype = {
  a: function(f){
    var s = this._s, y = this._y, r;
    if(typeof s[y] === "string")s[y] = s[y].split(" ").reverse();
    r = s[y].pop();
    if(!s[y].length)this._y++;
    return f?r:+r;
  },
  l: function(f){
    var s = this._s[this._y++].split(" ");
    return f?s:s.map(a=>+a);
  },
  m: function(n,f){
    var s = this._s, y = this._y, r = [], i = 0;
    if(f)for(;i < n; i++)r[i] = s[y+i].split(" ");
    else for(;i < n; i++)r[i] = s[y+i].split(" ").map(a=>+a);
    this._y += n;
    return r;
  },
};
var o=new gets(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var s = o.a(1).trim();
  var t = o.a(1);
  var l = s.length;
  var a = {}, b = {};
  for(var i = 0; i < l; i++){
    if(a[s[i]] >= 0 || b[t[i]] >= 0){
      if(a[s[i]] === b[t[i]])continue;
      else return "No";
    }
    a[s[i]] = b[t[i]] = i;
  }
  return "Yes";
}

Measured memory_bytes: 21064
use std::io;

fn main() {

    println!("{}", if testg() {"TBD"} else {"Heisei"});
}

fn testg() -> bool {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let splitter : Vec<&str> = input.trim().split('/').collect();
    let i1 : i32 = splitter[0].parse().ok().unwrap();
    if i1 < 2019 {
        return false
    } else if i1 > 2019 {
        return true
    }

    let i1 : i32 = splitter[1].parse().ok().unwrap();
    if i1 > 4 {
        return true
    } 
    false
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long ll;
typedef pair<int, int> P;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 100 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    int Sx, Sy, Tx, Ty;
    string ans;
    cin >> Sx >> Sy >> Tx >> Ty;
    int diffx = Tx - Sx;
    int diffy = Ty - Sy;
    // 1
    rep(i, diffy) {
        ans += 'U';
    }
    rep(i, diffx) {
        ans += 'R';
    }
    // 2
    rep(i, diffy) {
        ans += 'D';
    }
    rep(i, diffx) {
        ans += 'L';
    }
    // 3
    ans += 'D';
    rep(i, diffx) {
        ans += 'R';
    }
    ans += 'R';
    ans += 'U';
    rep(i, diffy) {
        ans += 'U';
    }
    ans += 'L';
    // 4
    ans += 'U';
    rep(i, diffx) {
        ans += 'L';
    }
    ans += 'L';
    ans += 'D';
    rep(i, diffy) {
        ans += 'D';
    }
    ans += 'R';
    cout << ans << endl;
}


Measured memory_bytes: 256