akhauriyash/Code-Regression huggingface dataset:
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn solve(n: usize, m: usize, v: i64, p: i64, a: &Vec<usize>) -> usize {
    let mut l = (p-1) as usize;
    let mut r = n;
    while r - l > 1 {
        let mid = (l+r)/2;

        let border = a[mid] + m;
        if border >= a[(p-1) as usize] {
            let mut rest = (m as i64) * cmp::max(v - p, 0);
            let mut tmp = (p - 1) as usize;
            while tmp < n && rest > 0 {
                if tmp != mid {
                    rest -= cmp::min(m, border - a[tmp]) as i64;
                }
                tmp += 1;
            }
            if rest > 0 {
                r = mid;
            } else {
                l = mid;
            }
        } else {
            r = mid;
        }
    }
    l + 1
}


fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let n = line[0];
    let m = line[1];
    let v = line[2] as i64;
    let p = line[3] as i64;

    let mut a: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    a.sort();
    a.reverse();

    let ans = solve(n, m, v, p, &a);

    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
double D[80]; int d;

double pop_n(){
  return (D[--d]);}
void push_n(double a) {
  D[d]=a; d++;
}

int main() {
  char inbuf[99];
  while (gets(inbuf)) {
    char *tp = strtok(inbuf, " \n");
    while (tp != NULL) {
      double a,b;
      if ((tp[0] == '+') && (tp[1]==0)) {
        b = pop_n(); a = pop_n();
        push_n(a+b);
      }
      else if (tp[0] == '*') {
        b = pop_n(); a = pop_n();
        push_n(a*b);
      }
      else if ((tp[0] == '-') && (tp[1]==0)) {
        D[d-2]-=D[d-1];
        d--;
      }
      else if (tp[0] == '/') {
        D[d-2]/=D[d-1];
        d--;
      }
      else {
        D[d++]=atof(tp);
      }
      tp = strtok(NULL, " \n");
    }
    printf("%.6lf\n",pop_n());
  }
  return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n; cin >> n;
    vl a(n);
    rep(i,n)cin>>a[i];
    ll s = accumulate(all(a),0LL);
    ll odd_a = 0;
    for(int i=1;i<n;i+=2)odd_a += a[i];
    ll x = s - 2*odd_a;
    rep(i,n){
        if(i)cout << " ";
        cout << x;
        x = 2*a[i]-x;
    }
    cout << endl;
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <algorithm>

using namespace std;

int x[200200];

int main()
{
	int i,j,n,l;
	scanf("%d %d",&n,&l);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&x[i]);
	}
	for(i=1;i<n;i++)
	{
		if(x[i]+x[i+1] >= l)
			break;
	}
	if(i == n)
	{
		printf("Impossible\n");
	}
	else
	{
		printf("Possible\n");
		for(j=1;j<i;j++)
			printf("%d\n",j);
		for(j=n-1;j>=i;j--)
			printf("%d\n",j);
	}
	return 0;
}

Measured memory_bytes: 1152
use text_io::*;
use std::process::exit;
use im_rc::HashMap;
use std::cmp::min;

fn main(){
    let mut a:usize = read!();
    let mut b:usize = read!();
    let mut c:usize = 1;
    for mut i in 2..a+b {
        while a%i == 0 && b%i == 0{
            c*=i;
            a/=i;
            b/=i;
        }
    }
    println!("{}",a*b*c);
}

Measured memory_bytes: 2084
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
typedef long long int ll;
ll m[3],a[3];
ll gcd(int a,int b){
  if(a<b)swap(a,b);
  if(b == 0)return a;
  else return gcd(b,a%b);
} 

ll lcm(int a,int b){
  if(a<b)swap(a,b);
  return (a/gcd(a,b))*b;
}
int main(){
  while(cin >> a[0] >> m[0] >>a[1] >> m[1] >>a[2] >> m[2],a[0])
    {
      ll xyz[3],res[3];
      xyz[0]=xyz[1]=xyz[2]=1;
      for(int i = 0 ; i <  3 ; i++ ){
	ll cnt = 0;
	do{
	  cnt++;
	  xyz[i] = a[i]*xyz[i]%m[i];
	}while(xyz[i] != 1);
	res[i] = cnt;
      }
      cout << lcm(res[0],lcm(res[1],res[2])) << endl;
    }
  return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <random>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	int M = rei();
	int D = rei();
	int ans = 0;
	for(int i=1;i<=M;i++){
		for(int j=1;j<=D;j++){
			if((j % 10) * (j / 10) == i && j % 10 >= 2 && j / 10 >= 2){
				ans++;
			}
		}
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

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

ll search(int i) {
  if (dp[i] != 0) return dp[i];
  ll ret = 0;
  for (auto v : G[i]) {
    ret = max(ret, search(v) + 1);
  }
  dp[i] = ret;
  return ret;
}

int main(void) {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  G.resize(N);
  rep(i, M) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    G[x].push_back(y);
  }
  dp.resize(N, 0);

  ll Ans = 0;
  rep(i, N) {
    ll ret = search(i);
    Ans = max(Ans, ret);
  }
  cout << Ans << endl;
  return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+50;
const ll mod=1e9+7;
//dp[i][0/1]表示前i位满足条件的a和b(a+b!=L 或者a+b==L)的方案数
ll dp[N][2];
char s[N];
int main(void){
    scanf("%s",s+1);
    int n=strlen(s+1);
    //前0位,空,认为相等,所以有一种方案
    dp[0][1]=1ll;
    for(int i=1;i<=n;i++){
        //前面不相等,这一位可以选01 10 00,都满足不等于L
        dp[i][0]+=dp[i-1][0]*3ll;
        dp[i][0]%=mod;
        if(s[i]=='0'){
            dp[i][1]+=dp[i-1][1];
        }else{
            dp[i][0]+=dp[i-1][1];
            dp[i][1]+=dp[i-1][1]*2ll;
        }
        dp[i][0]%=mod;
        dp[i][1]%=mod;
    }
    printf("%lld\n",(dp[n][0]+dp[n][1])%mod);
    return 0;
}
// #include <bits/stdc++.h>
// using namespace std;
// const int MOD = 1000000007;
// int main() {
//     std::ios::sync_with_stdio(0); cin.tie(0);
//     string s;
//     cin >> s;
//     int n = s.length();

//     vector<vector<int>> dp(n+1, vector<int>(2, 0));
//     dp[0][0] = 1;
//     for(int i=0;i<n;++i) {
//         if(s[i] == '1') {
//             dp[i+1][0] = (dp[i][0] * 2) % MOD;
//             dp[i+1][1] = (dp[i][1] * 3 + dp[i][0]) % MOD;
//         } else {
//             dp[i+1][0] = dp[i][0];
//             dp[i+1][1] = (dp[i][1] * 3) % MOD;
//         }
//     }

//     cout << (dp[n][0]+dp[n][1]) % MOD << endl;
// }

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

int main()
{
	long H;
	cin>>H;
	long ans=0,res=1;
	while(H>1)
	{
		H/=2;
		ans=ans+res;
		res=res*2;
	}
	ans=ans+res;
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int INF=1e+9;
const ll INFLL=1e+17;
char s[110];
int n;
int main(){
  cin>>n;
  rep(i,n) cin>>s[i];
  int cnt=0;
  rep(i,n){
    if(s[i]=='R'){
      cnt++;
    }
  }
  if(2*cnt>n){
    prin("Yes");
  }
  else{
    prin("No");
  }

  return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    string s, t;
    cin >> s >> t;
    int ans = N;
    for(int i=0; i<N; i++)
    {
        if(s.substr(i, N-i) == t.substr(0, N-i)) break;
        ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false)
#define mem(a,n) memset(a,n,sizeof(a))
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=3.1415926;
const int MOD=1e9+7;
const int N=1e6+5;
int main()
{
    IO;
    int n,a,b;
    while(cin>>n>>a>>b)
    {
        cout<<(n-a)%b<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int n, w[110], presum[110];
int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> w[i];
	for(int i = 1; i <= n; i++) presum[i] = presum[i - 1] + w[i];
	int ans = 1e9;
	for(int k = 1; k <= n; k++) ans = min(ans, abs(presum[k] - presum[n] + presum[k]));
	cout << ans << endl;
	return 0;
}
/*
5
1 5 10 7 9
0

2
1 100 
99 
*/

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

int main() {
    int num;
    int heightLim;
    
    cin >> num >> heightLim;
    
    int people[num];
    int nCnt = 0;
    
    for(int i = 0; i < num; i++){
        cin >> people[i];
        if(people[i] >= heightLim) nCnt++;
    }
    
    cout << nCnt;
    
	return 0;
}


Measured memory_bytes: 640
n = int(input())
a = sorted(list(map(int,input().split())))
a_max = a[-1]
dp = [0]*(a_max+1)

for i in a:
    dp[i] += 1
    if dp[i] == 1:
        for j in range(i*2,a_max+1,i):
            dp[j] = 2
print(dp.count(1))

Measured memory_bytes: 32380
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	int i, j, k, n, id;
	long double t, a, h, x, best, xx;
	cin >> n >> t >> a;
	best = 1000000;
	for (i = 1; i <= n; i++) {
		cin >> h;
		xx = (t - h * 0.006);
		if (a > xx) x = a - xx;
		else x = xx - a; 
		if (x < best) {
			best = x;
			id = i;
		}
	}
	cout << id << "\n";


	return 0;
}


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

int main() {
  int N;
  int j=0;
  string s,t;
  cin >> N;
  cin >> s >> t;
  vector<char>u(N*2);

  for(int i=0;i<N;i++){
    u.at(j) =s.at(i);
    j++;
    u.at(j) =t.at(i);
    j++;
  }
  for(int i=0;i<N*2;i++){
    cout<<u.at(i);
  }
	cout<<endl;
}
/*
    u.at(j) =s.at(i);
    j++;
    u.at(j) =t.at(i);
    j++;
  }
*/

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long


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

    int n; cin >> n;
    vector<int> d(n);
    for(int i = 0;i < n;i ++) cin >> d.at(i);

    sort(d.begin(),d.end());

    cout << d.at(n/2) - d.at(n/2 -1) << endl;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] linesp = line.split(" ");
        int x = Integer.parseInt(linesp[0]);
        int y = Integer.parseInt(linesp[1]);
        int[] nums = new int[2];
    
        if(x > y) {
            nums[0] = x;
            nums[1] = x % y;
            while(nums[0] > 0 && nums[1] > 0) {
                int a = nums[1];
                nums[1] = nums[0] % nums[1];
                nums[0] = a;
            }
        } else {
            nums[0] = y;
            nums[1] = y % x;
            while(nums[0] > 0 && nums[1] > 0) {
                int a = nums[1];
                nums[1] = nums[0] % nums[1];
                nums[0] = a;
            }
        }
        
        if(nums[0] == 0) {
            System.out.println(nums[1]);
        }else {
            System.out.println(nums[0]);
        }
        
    }
 }
 


Measured memory_bytes: 26112
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<pair<int,int>>>;
#define INF 1000000000000000000
#define MOD 1000000007

int N;
vector<vector<ll>> a;
vector<bool> flag;
vector<ll> dp;

ll solve(int S){
  if(flag.at(S)){
    return dp.at(S);
  }
  flag.at(S)=true;

  ll ans=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if((((S>>i)&1)&((S>>j)&1))==1){
        ans+=a.at(i).at(j);
      }
    }
  }

  for(int T=(S-1)&S;T>0;T=(T-1)&S){
    ans=max(ans,solve(T)+solve(S^T));
  }
  return dp.at(S)=ans;
}

int main(){
  cin>>N;
  a.resize(N);
  for(int i=0;i<N;i++){
    a.at(i).resize(N);
    for(int j=0;j<N;j++){
      cin>>a.at(i).at(j);
    }
  }

  flag.resize(1<<N,false);
  dp.resize(1<<N,0);
  cout<<solve((1<<N)-1)<<endl;
}


Measured memory_bytes: 896
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  double[] p; readA(n, p);

  auto dp = new double[][](n+1, n+1);
  dp[0][] = 0; dp[0][0] = 1;
  foreach (i; 1..n+1)
    foreach (j; 0..n+1) {
      dp[i][j] = dp[i-1][j] * (1-p[i-1]);
      if (j > 0) dp[i][j] += dp[i-1][j-1] * p[i-1];
    }

  writefln("%.10f", dp[$-1][n/2+1..$].sum);
}


Measured memory_bytes: 74364
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
struct mint {
    int x;
    mint(int x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(int t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return *this *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
mint F[2100010];
void fact(void) {
	F[0] = mint(1);
	F[1] = mint(1);
	for (int i = 2; i <= 2100000; i++) {
        mint x(i);
		F[i] = x * F[i - 1];
	}
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    fact();
    int N; cin >> N;
    string S; cin >> S;
    mint ans = F[N];
    int L = 0;
    rep(i, N * 2) {
        if((S[i] == 'W') ^ (i % 2 == 0)) L++;
        else ans *= L--;
    }
    if(L != 0) ans *= 0;
    cout << ans.x << endl;
    return 0;
}
//BWWB
//LLRR
//
//BWBBWWWB
//LLLRRLRR   

Measured memory_bytes: 20164
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int x = sc.nextInt();
	long[] a = new long[n];
	long cnt = 0;
	for(int i = 0; i<n; i++) {
	    a[i] = sc.nextInt();
	}

	if(a[0]>x) {
	    cnt = a[0]-x;
	    a[0] = x;
	}

	for(int i = 1; i<n; i++) {
            long tmp = Math.max(0,a[i]-(x-a[i-1]));
	    cnt += tmp;
	    a[i] = a[i]-tmp;
        }

	System.out.println(cnt);

    }
}

Measured memory_bytes: 61448
Scanf.scanf "%d %d %d %d" (fun a b c d ->
    let l1 = if a <= 0 && 0 <= b then [| a; 0; b |] else [| a; a; b |] in
    let l2 = if c <= 0 && 0 <= d then [| c; 0; d |] else [| c; c; d |] in

    let rec loop_i i acc =
        let rec loop_j j acc =
            if j = 3 then loop_i (i + 1) acc else
                loop_j (j + 1) (max acc (l1.(i) * l2.(j)))
        in
        if i = 3 then acc else loop_j 0 acc
    in
    loop_i 0 min_int |> Printf.printf "%d\n"
)

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

#define EPS (1e-7)
#define INF (1<<25)
#define PI (acos(-1))

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

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

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

using ll = long long;

int main() {
  int n; cin >> n;
  vector<int> a(n); REP(i,n) cin >> a[i];
  vector<ll> d(n+1); REP(i,n) d[i+1] = d[i] + (ll)a[i];
  whole(sort, d);
  ll ans = 0;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (d[i-1] == d[i]) cnt++;
    else cnt = 0;
    ans += cnt;
  }
  cout << ans << endl;
  return 0;
}


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

string s,t;
long long ans=0;

void dfs(int d) {
	if(d==s.size()){
		if(t.back()!='+')return;
		long long tmp=0,pl=0;
		for(int i=0;i<t.size();++i){
			if(t[i]=='+')tmp+=pl,pl=0;
			else pl=pl*10+t[i]-'0';
		}
		ans+=tmp;
		return;
	}
	t.push_back(s[d]);
	dfs(d+1);
	t.push_back('+');
	dfs(d+1);
	t.pop_back();t.pop_back();
}

int main(){
	cin>>s;
	dfs(0);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

alias Mint = ModInt!(10^^9+7);

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto A = s[1];
    auto B = s[2];
    auto C = s[3];

    auto winA = Mint(A) / Mint(A + B);
    auto winB = Mint(B) / Mint(A + B);
    auto num = Mint(A + B + C) / Mint(A + B);
    auto ans = Mint(0);

    auto F = new Mint[](3*N);
    F[0] = F[1] = Mint(1);
    foreach (i; 2..3*N) F[i] = F[i-1] * Mint(i);

    Mint comb(int r, int c) {
        return F[r] / F[c] / F[r-c];
    }

    foreach (i; 0..N) {
        auto a = winA ^^ N;
        auto b = winB ^^ i;
        auto c = comb(N-1+i, i);
        ans += a * b * c * num * Mint(N + i);
    }

    foreach (i; 0..N) {
        auto a = winA ^^ i;
        auto b = winB ^^ N;
        auto c = comb(N-1+i, i);
        ans += a * b * c * num * Mint(N + i);
    }

    ans.writeln;
}

// This implementation of ModInt references https://github.com/yosupo06/dunkelheit/blob/master/source/dkh/modint.d

// Manually verified on: https://yukicoder.me/problems/no/117
// Manually verified on: https://atcoder.jp/contests/cpsco2019-s3/tasks/cpsco2019_s3_f

struct ModInt(uint mod) {
    import std.conv : to;

    uint n;

    this(int n) {
        this.n = (n % mod + mod) % mod;
    }

    this(long n) {
        this.n = (n % mod + mod) % mod;
    }

    private this(uint n) {
        this.n = n;
    }

    string toString() const {
        return to!string(this.n);
    }

    private uint normilize(uint n) const {
        return n < mod ? n : n - mod;
    }

    private ModInt pow(uint n, long x) const {
        long ret = 1;
        long a = n;
        while (x) {
            if (x & 1) ret = ret * a % mod;
            a = a * a % mod;
            x >>= 1;
        }
        return ModInt(to!ulong(ret));
    }

    ModInt opBinary(string op : "+")(ModInt rhs) const {
        return ModInt(normilize(n + rhs.n));
    }

    ModInt opBinary(string op : "-")(ModInt rhs) const {
        return ModInt(normilize(n + mod - rhs.n));
    }

    ModInt opBinary(string op : "*")(ModInt rhs) const {
        return ModInt(to!uint(to!long(n) * rhs.n % mod));
    }

    ModInt opBinary(string op : "/")(ModInt rhs) const {
        return this * pow(rhs.n, mod-2);
    }

    ModInt opBinary(string op : "^^")(ModInt rhs) const {
        return pow(this.n, rhs.n);
    }

    ModInt opBinary(string op, T)(T rhs) const {
        ModInt mod_rhs = ModInt(rhs);
        return opBinary!op(mod_rhs);
    }

    ModInt opOpAssign(string op)(ModInt rhs) {
        return mixin ("this=this"~op~"rhs");
    }
}


Measured memory_bytes: 3452
#include <bits/stdc++.h>
using namespace std;
const int N=310;
int n,m,dp[N][N][N];
char s[N];
int main()
{
	scanf("%s%d",s+1,&m);
	n=strlen(s+1);
	for (int i=1;i<=n;i++) dp[i][i][0]=1;
	for (int len=2;len<=n;len++)
	{
		for (int i=1;i<=n-len+1;i++)
		{
			int j=i+len-1;
			for (int k=0;k<=m;k++)
			{
				dp[i][j][k]=max(dp[i][j][k],dp[i+1][j][k]);
				dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k]);
				dp[i][j][k]=max(dp[i][j][k],dp[i+1][j-1][k]);
				if (s[i]==s[j]) dp[i][j][k]=max(dp[i][j][k],dp[i+1][j-1][k]+2);
				else if (k>0) dp[i][j][k]=max(dp[i][j][k],dp[i+1][j-1][k-1]+2);
			}
		}
	}
	// for (int len=1;len<=n;len++)
	// {
	// 	for (int i=1;i<=n-len+1;i++)
	// 	{
	// 		int j=i+len-1;
	// 		for (int k=0;k<=m;k++)
	// 		{
	// 			printf("%d %d %d: %d\n",i,j,k,dp[i][j][k]);
	// 		}
	// 	}
	// }
	int ans=0;
	for (int k=0;k<=m;k++) ans=max(ans,dp[1][n][k]);
	printf("%d\n",ans);
}

Measured memory_bytes: 59496
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    private static final Comparator<Integer> DESCENDING_ORDER = (a, b) -> Integer.compare(b, a);

    public static void main(String[] args) {
        TestCase testCase = readFromInput();

        final long result = process(testCase);

        output(result);
    }

    private static TestCase readFromInput() {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        List<Integer> X = new ArrayList<>();
        for (int i = 0; i < M; ++i) {
            X.add(sc.nextInt());
        }

        sc.close();
        return new TestCase(N, M, X);
    }

    public static long process(TestCase testCase) {
        final int M = testCase.M;
        final int N = testCase.N;
        final List<Integer> X = testCase.X;
        X.sort(Integer::compareTo);

        final PriorityQueue<Integer> pathDiffs = new PriorityQueue<>(DESCENDING_ORDER);

        for (int i = 1, length = X.size(); i < length; ++i) {
            pathDiffs.add(X.get(i) - X.get(i - 1));
        }

        for (int i = 0; i < N - 1; ++i) {
            pathDiffs.poll();
        }

        long sum = 0;
        while (!pathDiffs.isEmpty()) {
            sum += pathDiffs.poll();
        }
        return sum;
    }

    private static void output(long result) {
        System.out.println(result);
    }

    public static class TestCase {
        final int N;
        final int M;
        final List<Integer> X;

        public TestCase(int N, int M, List<Integer> X) {
            this.N = N;
            this.M = M;
            this.X = X;
        }
    }
}


Measured memory_bytes: 54164
#include<bits/stdc++.h>
using namespace std;
int main(void){
  
  int n;
  int i;
  int count=0,b=1;
  cin>>n;
  vector<int> a(n,0);
  
  for(i=0;i<n;i++) 
  {
    cin>>a.at(i);
  }
  
  for(i=0;i<n;i++)
  {
    b = a.at(b-1);
    count++;
    if(b==2)break;
  }
  if(count==n)cout<<-1;
  else cout<<count;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
#define mod 1000000007
#define int long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000000
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define mip map<int, pair<int,int> >
#define inf INT_MAX
#define inf1 LONGLONG_MAX
#define sz(v) v.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<#x<<"is "<<x<<endl;
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, 
         tree_order_statistics_node_update> pbds;
   
/* brownsands :Arpit */			

void solve()
{      string s;int i;
    cin >> s;
    for(i=0;i<s.size();i++)
    cout<< "x";
}
signed main()
{
   boost
        int test=0,t;
		//cin>>t;
		t=1;
		while(test++ <t){
            //cout<<"Case "<<test<<": ";
            solve();
            //cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
               }		
} 
               
			
 

				
		
		




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

int main (){
    int A, B, val, i = 0, count = 0;
    int each_dig[5], dig;

    cin >> A >> B;

    for(val = A; val <= B; val++){
        if (val / 10000 == val % 10){
            if(val / 1000 % 10 == val % 100 / 10){
                count++;
            }
        }
    }
    cout << count << endl;
}

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

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    ll N;
    cin >> N;
    auto calc_div = [](ll X) {
        vector<ll> res;
        for(int i = 1; (ll)i * i <= X; ++i){
            if(X % i == 0){
                res.emplace_back(i);
                if((ll)i * i != X)  res.emplace_back(X / i);
            }
        }
        sort(res.begin(), res.end());
        return res;
    };
    vector<ll> div = calc_div(N);
    ll ans = 0;
    for(ll p : div){
        ll m = N / p - 1;
        if(!m)  continue;
        ll q = N % m;
        if(p == q)  ans += m;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3700
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

c = 0
i = 0
while True:
    i = a[i]  - 1
    c += 1
    if i == 1:
        print(c)
        break
    if c > n:
        print(-1)
        break

Measured memory_bytes: 13052
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll h1, m1, h2, m2, k;

int main() {
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	cout << h2 * 60 + m2 - h1 * 60 - m1 - k << endl;
	return 0;
}

Measured memory_bytes: 3672
/*
author: Apoorv Singh
*/

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

typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define FOR(i, a, b) for (long long i = a; i < b; ++i)
#define FORR(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){ for (X a : v) x << a << ' '; return x;} 
template <typename X, typename Y> ostream& operator << (ostream& x, const vector< pair<X, Y> >& v) {for (pair <X, Y> it : v) x << it.first << ' ' << it.second << endl; return x;} 
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (pair <T, S> it : v) os << it.first << " => " << it.second << endl; return os; }

double pi = 3.14159265358979323846264338327950288419716939937510582097494459230;
int modulo = 1e9 + 7;

int fpow(int a, int n)
{
    int ans = 1;
    while (n)
    {
        if (n&1)
            ans = (ans * a)%modulo;
        a = (a*a)%modulo;
        n = n >> 1;
    }
    return ans;
}

/*
const int M = 1e6 + 10;
int composite[M] = {0};

void sieve()
{
    FOR(i,2,M)
    {
        if (!composite[i])
        {
            for (int j = 2*i; j < M; j += i)
                composite[j] = max(composite[j], i);
        }
    }
}
*/

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n; cin >> n;
    int arr[n];
    for (int i = 0; i < n; ++i)
        cin >> arr[i];
    int x[n];
    for (int i = 0; i < n; ++i)
        x[i] = arr[i];
    sort(arr, arr+n);
    int f = arr[n-1], s = arr[n-2];
    if (f == s)
    {
        for (int i = 0; i < n; ++i)
            cout << f << endl;
        return 0;
    }

    for (int i = 0; i < n; ++i)
    {
        if (x[i] == f)
            cout << s << endl;
        else
            cout << f << endl;
    }
    return 0;
}

Measured memory_bytes: 4736
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	cin>>n;
	int a[n];
	rep(i,n)cin>>a[i];
	int cnt=0;
	rep(i,n){
		while(a[i]%2==0){
			a[i]/=2;
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 764
N, M = map(int, input().split())
H = list(map(int, input().split()))
ans = [0 for i in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    if H[A-1] < H[B-1]:
        ans[A-1] += 1
    elif H[A-1] > H[B-1]:
        ans[B-1] += 1
    else:
        ans[A-1] += 1
        ans[B-1] += 1

print(len([i for i in ans if i == 0]))

Measured memory_bytes: 20040
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n ;
    n%=10;
    if(n == 2|| n == 4||n == 5||n == 7 ||n == 9){
        cout << "hon" << endl;
    }else if(n == 0||n==1||n== 6||n== 8)cout << "pon" << endl;
    else cout << "bon" << endl;
}

Measured memory_bytes: 3596
#ifndef LOCAL
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
const int MAXN = 1 << 18;

int a[MAXN];
int p[MAXN];
int n, k;
int up[MAXN];
int dw[MAXN];
vector<int> go[MAXN];

set<pair<int, int> > av;

int rev(int x, int k) {
	int ans = 0;
	for (int i = 0; i < k; ++i) {
		ans = (ans * 2 + (x & 1));
		x >>= 1;
	}
	return ans;
}

void no() {
	cout << "NO\n";
	//assert(false);
	exit(0);
}

void run(int l, int r) {
	if (l + 1 == r)
		return;
	int len = (r - l) / 2;
	for (int i = l; i < l + len; ++i)
		if (a[i] > a[i + len])
			no();
	run(l, l + len);
	run(l + len, r);
}

int main() {
	cin >> k;
	n = (1 << k);
	fill(p, p + n, -1);
	for (int i = 0; i < n; ++i) {
		cin >> a[i], --a[i];
		if (a[i] != -1)
			p[a[i]] = i;
	}
	if (p[n - 1] == -1) {
		a[n - 1] = n - 1;
		p[n - 1] = n - 1;
	}
	for (int i = 0; i < n; ++i)
		up[i] = n - 1, dw[i] = 0;
	for (int i = 0; i < n; ++i)
		if (a[i] != -1)
			up[i] = min(up[i], a[i]);
	for (int i = 0; i < n; ++i)
		if (a[i] != -1)
			dw[i] = max(dw[i], a[i]);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < k; ++j) {
			if ((i >> j) & 1)
				dw[i] = max(dw[i], dw[i ^ (1 << j)]);
		}
	}
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < k; ++j)
			if (!((i >> j) & 1))
				up[i] = min(up[i], up[i ^ (1 << j)]);
	}
	for (int i = 0; i < n; ++i)
		if (a[i] == -1)
			go[dw[i]].push_back(i);
	for (int i = 0; i < n; ++i) {
		for (int j: go[i])
			av.insert(make_pair(up[j], j));
		if (p[i] != -1)
			continue;
		if (!av.empty()) {
			int x = av.begin()->second;
			av.erase(av.begin());
			a[x] = i;
			p[i] = x;
		}
	}
	for (int i = 0; i < n; ++i)
		if (a[i] == -1)
			no();
	run(0, n);
	for (int i = 0; i < n; ++i) {
		int x = rev(i, k);
		if (x > i)
			swap(a[x], a[i]);
	}
	cout << "YES\n";
	for (int i = 0; i < n; ++i)
		cout << a[i] + 1 << " ";
	cout << "\n";
	return 0;
}




Measured memory_bytes: 23420
import sys
import math
#import random
#sys.setrecursionlimit(100000000)
input = sys.stdin.readline
 
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input()))
def inara():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
################################################################
############ ---- THE ACTUAL CODE STARTS BELOW ---- ############

h1,m1,h2,m2,k=invr()

h=h2-h1
m=m2-m1

if m<0:
	m+=60
	h-=1

ans=h*60+m-k

print(ans)
	
	
		
		


Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl <<"\n"
#define con continue
#define br break
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
ll mx=INT_MAX;
ll mi=INT_MIN;
const ll MOD=998244353;
const ll inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
#define io { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define cer cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

int main()
{
        io;
        //////////////////////////////////
        string s1,s2;
        cin>>s1>>s2;
        ll s=0,i,j;
        for(i=0;i<s1.size();i++)
        {
            if(s1[i]!=s2[i]) s++;
        }
        cout<<s;
        //////////////////////////////////
        cer;
}

Measured memory_bytes: 3980
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>

using namespace std;

int main(void) {
	string s;
	cin >> s;
	if (s.length() < 4) {
		cout << "No" << endl;
	}
	else {
		if (s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <stdio.h>

int main(void)
{
	int n,l[100];
	int max=-1;
	int sum=0;
	
	scanf("%d\n",&n);
	
	int i=0;
	
	while(i<n){
		
		scanf("%d",&(l[i]));
		
		if(max<l[i]){
			max=l[i];
		}
		
		sum=sum+l[i];
		
		i++;
	}
	
	if((sum-max)>max){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}

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

int main() {
  int N,K;
  cin>>N>>K;
  vector<int> xs(N);
  for(int i=0;i<N;i++){cin>>xs.at(i);}
  long int min_d=pow(10,9);
  for(int i=0;i<N-(K-1);i++){
    long int init=min(abs(xs.at(i)),abs(xs.at(i+(K-1))));
    long int d=abs(xs.at(i+(K-1))-xs.at(i));
    min_d=min(min_d,init+d);
  }
  cout<<min_d<<endl;
}

Measured memory_bytes: 640
import numpy as np

n,m,k=map(int,input().split())
a=np.array(list(map(int,input().split())))
b=np.array(list(map(int,input().split())))

ak=np.cumsum(a,dtype=np.int64)
bk=np.cumsum(b,dtype=np.int64)
ak=ak[ak<=k]
bk=bk[bk<=k]
lak=len(ak)
lbk=len(bk)

an=lak
j=0
for i in range(lak-1,-1,-1):
    while bk[j]+ak[i]<=k:
        an=max(an,i+j+2)
        j+=1
        if j>=lbk:
            j-=1
            break
an=max(an,lbk)

print(an)

Measured memory_bytes: 53568
#include<stdio.h>

int solve(int,int);
int n,q;
int A[2000],mi[2000];

int main(){
  int i,j,k;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&mi[i]);
  }

  for(i=0;i<q;i++){
    if(solve(0,mi[i])==1)printf("yes\n");
    if(solve(0,mi[i])==0)printf("no\n");
  }
return 0;
}

int solve(int i, int m){
  if (m == 0){
    return 1;
      }
  if (i >= n){
    return 0;
  }
  return solve(i + 1, m - A[i])|| solve(i + 1, m );
}

Measured memory_bytes: 584
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<random>
using namespace std;
 
int main() {
 
  string s; cin >> s;
 
  bool f = false;
  if( s == "AKIHABARA" ) f = true;
  if( s == "KIHABARA" ) f = true;
  if( s == "AKIHBARA" ) f = true;
  if( s == "AKIHABRA" ) f = true;
  if( s == "AKIHABAR" ) f = true;
  if( s == "KIHBARA" ) f = true;
  if( s == "KIHABRA" ) f = true;
  if( s == "KIHABAR" ) f = true;
  if( s == "AKIHBRA" ) f = true;
  if( s == "AKIHABR" ) f = true;
  if( s == "AKIHBAR" ) f = true;
  if( s == "KIHBRA" ) f = true;
  if( s == "KIHBAR" ) f = true;
  if( s == "AKIHBR" ) f = true;
  if( s == "KIHABR" ) f = true;
  if( s == "KIHBR" ) f = true;
 
  cout << (f?"YES":"NO") << endl;
 
  return 0;
}
 
// EOF

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <math.h>

using namespace std;

int main(){
    int n; cin >> n;
    vector<bool> primes(1e7, true);
    for(int i = 2; i < sqrt(1e7); i++){
        if(primes[i]){
            for(int j = i*2; j < 1e7; j += i){
                primes[j] = false;
            }
        }
    }
    for(int i = n; i < 1e7; i++){
        if(primes[i]){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
  char s[2];
  for(int i=0;i<3;i++)
  {
    cin>>s[i];
  }
  if(s[0]==s[1] && s[1]==s[2])
  {
    cout<<"No";
  }
  else if(s[0]==s[1])
  {cout<<"Yes";}
  else if(s[0]==s[2])
  {cout<<"Yes";}
  else if(s[1]==s[2])
  {cout<<"Yes";}
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
#define pint pair<int,int>
#define vi(v) rep(i,v.size())cin >> v[i]
#define vc(v) rep(i,v.size())cout << v[i] << endl
#define ni(n) cin >> n
#define nc(n) cout << n << endl
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
// *max_element(all(d))
// priority_queue<ll,vector<ll>,greater<ll>>
int solve(){
  int n;
  cin >> n;
  vector<pair<string,pair<int,int>>>v(n);
  rep(i,n){
    string s;
    int p;
    cin >> s >> p;
    v[i].first = s,v[i].second.first = -p,v[i].second.second = i + 1;
  }
  sort(all(v));
  rep(i,n)cout << v[i].second.second << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e14;
using Graph = vector<vector<int>>;

signed main(){
  int N;
  cin >> N;
  if( N >= 30 ) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

long long gcd(long long a, long long b)
{
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return gcd(b, a%b);
}
int main()
{
    int n;
    long long t[100];

    cin >> n;
    for(int i=0; i<n; i++) cin >> t[i];

    long long tmp = t[0];
    for(int i=1; i<n; i++){
        tmp = tmp / gcd(tmp, t[i]) * t[i];
    }

    cout << tmp << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stack>
#define MN 400000
int n,k,a[MN+5];
struct xxx{int p,c;};
struct STACK{
	xxx mem[MN+5];
	int tp;
	void clear(){tp=0;}
	void push(xxx x){mem[++tp]=x;}
	void pop(){--tp;}
	xxx& top(){return mem[tp];}
}q;
void spj(){
	for(int i=1;i<=n;i++)
		if(a[i]<=a[i-1]) return;
	puts("1");
	exit(0);
}
bool push(xxx x){
//	printf("push %d %d\n",x.p,x.c);
	if(x.p==0) return false;
	if(x.p==q.top().p){
		q.top().c++;
//		printf("%d ? %d\n",q.top().c,k);
		if(q.top().c==k+1){
			q.pop();
			if(q.top().p!=x.p-1) q.push((xxx){x.p-1,1});
			if(!push((xxx){x.p-1,1})) return false;
			q.push(x);
			return true;
		}
	}else{
		q.push(x);
	}
	return true;
}
bool check(){
//	puts("--");
	q.clear();
	for(int i=1;i<=n;i++){
		bool ex=false;
		while(q.top().p>a[i]) q.pop(),ex=true;
		if(ex&&q.top().p!=a[i]) q.push((xxx){a[i],1});
		if(!push((xxx){a[i],1})) return false;
	}
	return true;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	spj();
	int l=2,r=n,mid;
	while(l<=r){
		mid=(l+r)>>1; k=mid;
		if(check()) r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",l);
}

Measured memory_bytes: 2688
n = int(input())
s = list(map(int,input().split()))

dic = {}
for i in s:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

dic2 = sorted(dic.items(),reverse=True)#[(4, 1), (3, 1), (2, 2), (1, 2)]

i = 0
tmp = 0
sq = 0
while i < len(dic2):
    if dic2[i][1] >= 4 and sq == 0:
        sq = (dic2[i][0])**2
    if dic2[i][1] >= 2 and tmp == 0:
        tmp = dic2[i][0]
    elif dic2[i][1] >= 2 and tmp != 0:
        print(max(sq,tmp*dic2[i][0]))
        exit()
    i += 1

if sq == 0:
    print(0)
else:
    print(sq)

Measured memory_bytes: 21004
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a<b)
        printf("a < b\n",a,b);
    else if(a>b)
        printf("a > b\n",a,b);
    else
        printf("a == b\n",a,b);
    return 0;
}



Measured memory_bytes: 2040