akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ff first
#define ss second
#define MAX 10005
#define endl "\n"
#define mp make_pair
#define pb push_back
#define int long long
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define vi vector<int>
#define mii map<int,int>
#define pii pair<int,int>
#define len(x) (x.size())
#define read(x) scanf("%lld",&x)
#define all(a) a.begin(),a.end()
#define write(x) printf("%lld",x)
#define rep(i,a) for(int i=0;i<a;i++)
#define f(i,a,b) for(int i=a;i<=b;i++)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define pset(x,y) fixed<<setprecision(y)<<x
#define T int tc;cin>>tc;for(int t=1;t<=tc;t++)
#define set_arr(arr,i) memset(arr,i,sizeof(arr))
#define trace1(x)							cerr << #x << ": " << x << endl;
#define trace2(x, y)						cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)						cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       			cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    			cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) 			cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
using namespace std;

signed main(){
	
	int h;
	cin>>h;
	int level = 0;
	int count = 1;
	int sum = 0;
	while(h>0){

		if(h>1){
			sum += count;
			h/=2;
			level+=1;
			count*=2;
		}
		else{
			sum += count;
			break;
		}
	}
	cout<<sum;
	return 0;
		
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        if(N*A > B){
            System.out.println(B);
        }else if(N*A == B){
            System.out.println(B);
        }else if(N*A < B){
            System.out.println(N*A);
        }
    }
}

Measured memory_bytes: 21844
def solve():
    from sys import stdin
    from itertools import accumulate
    from collections import Counter
    
    def combin(n):
        return n * (n - 1) // 2
    
    f_i = stdin
    
    while True:
        N, M = map(int, f_i.readline().split())
        if N == 0:
            break
        
        Y = (0,) + tuple(accumulate(int(f_i.readline()) for i in range(N)))
        X = (0,) + tuple(accumulate(int(f_i.readline()) for i in range(M)))
        
        V = Counter(y - x for x in X for y in Y)
        
        print(sum(map(combin, V.values())))
solve()


Measured memory_bytes: 101672
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long a, b, c, d = 0, e = 0, f = 0, g = 0, l = 0;
	cin >> a;
	for (int h = 1; h <= a; h++) {
		cin >> b >> c;
		if (b >= d && c >= e) {
			d = b;
			e = c;
		}
		else {
			g = d / b;
			l = e / c;
			if (d % b != 0) {
				g = d / b + 1;
			}
			if (e % c != 0) {
				l = e / c + 1;
			}
			f = max(g, l);
			d = b * f;
			e = c * f;
		}
	}
	cout << d + e << endl;
	cin >> e;
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const int mod=1e9+7;

struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};

mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}

map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}

void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}

int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );

  int n;
  cin>>n;
  
  vd x(n);
  vs u(n);
  rep(i,n){
    cin>>x[i];
    cin>>u[i];
  }
  
  double ans=0;
  double btc=380000.0;
  rep(i,n){
    if(u[i]=="BTC")ans+=x[i]*btc;
    else ans+=x[i];
  }

  coutd(ans);

  return 0;
}

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

using namespace std;
using ll = long long;

class UnionFind {
public:
  UnionFind(int n) : tree(vector<ll>(n, -1)) {}

  // 木の頂点を探す
  int find(int x) {
    if (tree[x] < 0)
      return x;
    return tree[x] = find(tree[x]);
  }

  // 長さを返す
  ll length(int x) {
    if (tree[x] < 0)
      return abs(tree[x]);
    return length(tree[x]);
  }

  // 同じグループか
  bool same(int x, int y) { return find(x) == find(y); }

  // 点xを含む木と点yを含む木の融合
  // 既に同じ木だったらfalseを返す
  bool unite(int x, int y) {
    int r1 = find(x);
    int r2 = find(y);
    if (r1 == r2)
      return false;
    // 大きい方に小さい方をくっつけたほうがコストが低い
    if (abs(r1) < abs(r2))
      swap(r1, r2);
    tree[r1] += tree[r2];
    tree[r2] = r1;
    return true;
  }

private:
  vector<ll> tree;
};

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

  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  vector<vector<int>> friends(n);
  vector<vector<int>> blocks(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
    friends[a].push_back(b);
    friends[b].push_back(a);
  }
  for (int i = 0; i < k; i++) {
    int c, d;
    cin >> c >> d;
    c--;
    d--;
    blocks[c].push_back(d);
    blocks[d].push_back(c);
  }

  for (int i = 0; i < n; i++) {
    int ans = uf.length(i) - 1;
    for (auto f : friends[i]) {
      if (uf.same(i, f))
        ans--;
    }
    for (auto b : blocks[i]) {
      if (uf.same(i, b))
        ans--;
    }
    cout << ans << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 15068
b,c,d,e,f,g,h;
main(a){scanf("%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f,&g,&h);a+=c+d+b;e+=f+g+h;printf("%d\n",a>e?a:e);exit(0);}

Measured memory_bytes: 0
/*
    author : Divyansh Gupta
*/

#include <iostream>
#include <iomanip>
#include <cstring>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <utility>
#include <map>

using namespace std;

void print_err() {
	cerr<<"\n";
}

template <class T,class... Arg>
void print_err(T x,Arg&&... args) {
	cerr<<x<<" ";
	print_err(args...);
}

#ifdef local
#define debug(...) print_err(__VA_ARGS__)
#else
#define debug(...)
#endif

#define test_case int test_cases;\
                cin>>test_cases;\
                while(test_cases--)
#define lu(var,l,r) for(var=l;var<r;var++)
#define ld(var,r,l) for(var=r;var>=l;var--)
#define ll long long
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>                	
#define br cout<<"\n"
#define sp cout<<" "
#define pr cout<<
#define in cin>>
#define f first
#define s second                    
#define mod 1000000007
            
ll who_will_win(vector<ll> &A,vector<vector<ll> > &dp,vector<vector<bool> > &visited,int l,int r) {
	if(l == r) {
		dp[l][l] = A[l];
		visited[l][l] = true;
		return dp[l][l];
	}
	if(visited[l][r]) 
		return dp[l][r];
	visited[l][r] = true;
	return dp[l][r] = max(
			A[l] - who_will_win(A,dp,visited,l+1,r),
			A[r] - who_will_win(A,dp,visited,l,r-1)
		);
}

void solve(){
	int n,i;
	ll x;
	vector<ll> A;
	vector<vector<ll> > dp(3001,vector<ll>(3001,0));
	vector<vector<bool> > dp_visited(3001,vector<bool>(3001,false));
	in n;
	lu(i,0,n) {
		in x;
		A.pb(x);
	}
	pr who_will_win(A,dp,dp_visited,0,n-1);
	br;
}

int main(){
    // test_case
    solve();
    return 0;
}

Measured memory_bytes: 72192
n,*l=map(int,open(0).read().split())
a=l[::3]
b=l[1::3]
c=l[2::3]
dp=[[0]*3 for _ in range(n)]
dp[0]=[a[0],b[0],c[0]]
A,B,C=dp[0]
for i in range(1,n):
	dp[i]=[ a[i]+max(B,C) , b[i]+max(C,A) , c[i]+max(A,B) ]
	A,B,C=dp[i]
print(max(dp[-1]))

Measured memory_bytes: 37148
//A Reward for a Carpenter
#include <iostream>
#include <cstdio>
#define rep(i,n) for(int i = 0;i < n;i++)
#define mp make_pair
using namespace std;

const int inf = 1e9;
int dis[30][30];
int main(){
    int n,m;
    cin >> n>>m;
    rep(i,n){
        rep(j,n){
            dis[i][j]=inf;
        }
    }
    rep(i,n){
        dis[i][i]=0;
    }
    rep(i,m){
        int a,b,c,d;
        scanf("%d,%d,%d,%d" ,&a,&b,&c,&d);
        a--;
        b--;
        dis[a][b]=c;
        dis[b][a]=d;
    }
    int x1,x2,y1,y2;
    scanf("%d,%d,%d,%d" ,&x1,&x2,&y1,&y2);
    x1--;
    x2--;
    rep(k,n){
        rep(i,n){
            rep(j,n){
                dis[i][j]=min(dis[i][j],min(inf,dis[i][k]+dis[k][j]));
            }
        }
    }
    
    cout << -dis[x2][x1]-dis[x1][x2] + y1 - y2 << endl;
}

Measured memory_bytes: 1244
def main():
    n = int(input())
    n = n % 26
    s = input()
    s_list = [d for d in s]
    new_s = ""
    new_ord_base = 64
    for i in s_list:
        new_ord = ord(i) + n
        if new_ord > 90:
            new_ord = new_ord % 90 + new_ord_base
        new_s += chr(new_ord)

    print(new_s)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int n;
long long ans = 0;
int Gcd(int x, int y) {if(x < y) swap(x, y); return x % y ? Gcd(y, x % y) : y;}
int gcd(int x, int y, int z) {return Gcd(x, Gcd(y, z));}
int main() {
	cin >> n;
	for(int i = 1;i <= n;i ++)
		for(int j = 1;j <= n;j ++) 
			for(int k = 1;k <= n;k ++) 
				ans += gcd(i, j, k);
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,m,p;
	while(cin>>n>>m>>p,n){
		int sum=0,num[101];
		for(int i=1;i<=n;i++){
			cin>>num[i];
			sum+=num[i];
		}
		if(num[m])cout<<(int)(sum*(float)(100-p)/num[m])<<endl;
		else cout<<0<<endl;
	}
}

Measured memory_bytes: 1160
A, B, C, D = map(int, input().split())

i = 0
while True:
    if i % 2 == 0:
        C -= B
    else:
        A -= D

    if A <= 0:
        print("No")
        break
    if C <= 0:
        print("Yes")
        break
    i += 1

Measured memory_bytes: 9172
#pragma GCC optimize("Ofast")
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include<set>
using namespace std;
#define INF 1LL<<62
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
//typedef pair<int,int> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
//http://drken1215.hatenablog.com/entry/2018/08/28/193000

int N;
vector<ll> A;
vector<ll> sum;

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

    cin>>N;
    A.resize(N); sum.resize(N+1); sum[0]=0;
    for(int i=0;i<N;i++) cin>>A[i],sum[i+1]=sum[i]+A[i];

    ll res=1LL<<60;
    for(int i=0;i<=N;i++){
        int low=0,high=i;
        while(high-low>1){
            int mid=(low+high)/2;
            if(sum[mid]>=sum[i]-sum[mid]) high=mid;
            else low=mid;
        }
        ll P=sum[low],Q=sum[i]-sum[low];
        ll P2=sum[high],Q2=sum[i]-sum[high];
        ll left_min=min(P,Q),left_max=max(P,Q);
        if(abs(P2-Q2)<abs(P-Q)) left_min=min(P2,Q2),left_max=max(P2,Q2);

        low=i,high=N;
        while(high-low>1){
            int mid=(low+high)/2;
            if(sum[mid]-sum[i]>=sum[N]-sum[mid]) high=mid;
            else low=mid;
        }
        ll R=sum[low]-sum[i],S=sum[N]-sum[low];
        ll R2=sum[high]-sum[i],S2=sum[N]-sum[high];
        ll right_min=min(R,S),right_max=max(R,S);
        if(abs(R2-S2)<abs(R-S)) right_min=min(R2,S2),right_max=max(R2,S2);

        ll temp=max(left_max,right_max)-min(left_min,right_min);
        chmin(res,temp);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3456
#include <iostream>
#include <string>

using namespace std;

int main(){
    string str;
    int b=0;
    int e=0;
    cin >> str;
    for(int i=0;;i++){
        if(str[i]=='A'){
            b=i;
            break;
        }
    }
    for(int i=str.length()-1;;i--){
        if(str[i]=='Z'){
            e=i;
            break;
        }
    }
    cout << e-b+1 << endl;
    return 0;
}


Measured memory_bytes: 640
import numpy as np

if __name__ == '__main__':
    
    n = raw_input()
    A0 = raw_input().split()
    A1 = raw_input().split()
    A0 = np.array(A0).astype(np.int)
    A1 = np.array(A1).astype(np.int)
    A = np.c_[A0, A1]
    nRow = A.shape[0]
    Asums = []
    for i in range(nRow):
        Asums.append(np.sum(A[0:i+1, 0]) + np.sum(A[i:, 1]))
    print max(Asums)

Measured memory_bytes: 19308
N, K, Q = map(int,input().split())
A = [int(input()) - 1 for _ in range(Q)]

note = [0] * N

for a in A:
    note[a] += 1

s = sum(note)

ans = 0
for i in range(N):
    if K - (s - note[i]) > 0:
        print("Yes")
    else:
        print("No")

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

int main()
{
	ll n;
	cin>>n;
	ll arr[n];
	//ll b[n];
	ll sum=0;
	ll minsofar = INT_MAX;
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
		if(arr[i]<=minsofar)
		{
			sum ++;
			minsofar = arr[i];
		}
		
	}
	
	
	
	cout<<sum;
}

Measured memory_bytes: 1792
x_1, y_1, x_2, y_2 = list(map(int, input().split()))

a = x_2 - x_1
b = y_2 - y_1

x_3 = x_2 - b
y_3 = y_2 + a
x_4 = x_3 - a
y_4 = y_3 - b

print(x_3, y_3, x_4, y_4)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<int,int> P;

int main(){
	int n;
	while( cin >> n , n ){
		int m[101][101] = {0};
		vector<P> v;
		vector<P> ans_p;
		
		for(int y=0 ; y < n ; y++ ){
			for(int x=0 ; x < n ; x++ ){
				cin >> m[y][x];
			}
		}
		
		for(int y=0 ; y < n ; y++ ){
			int min_ = m[y][0];
			for(int x=1 ; x < n ; x++ ){
				min_ = min( min_ , m[y][x] );
			}
			for(int x=0 ; x < n ; x++ ){
				if( m[y][x] == min_ ){
					P p(x,y);
					v.push_back( p ); 
				}
			}
		}
		for(int x=0 ; x < n ; x++ ){
			int max_ = m[0][x];
			for(int y=1 ; y < n ; y++ ){
				max_ = max( max_ , m[y][x] );
			}
			for(int y=0 ; y < n ; y++ ){
				if( m[y][x] == max_ ){
					P p(x,y);
					for(int i=0 ; i < v.size() ; i++ ){
						if( v[i] == p ){
							ans_p.push_back( p );
						}
					}
				}
			}
		}
		
		int ans = 0;
		for(int i=0 ; i < ans_p.size() ; i++ ){
			if( i == 0 ){
				int x = ans_p[i].first;
				int y = ans_p[i].second;
				ans = m[y][x];
			}else{
				int x = ans_p[i].first;
				int y = ans_p[i].second;
				ans = max( ans , m[y][x] );
			}
		}
		cout << ans << endl;
	}
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> cnt(100000 + 3);
  for (int i = 0; i < N; i++) {
    int val;
    cin >> val;
    val++;

    cnt[val - 1]++;
    cnt[val + 0]++;
    cnt[val + 1]++;
  }

  cout << *max_element(cnt.begin(), cnt.end()) << endl;

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
static const int MAX = 200000;

int main() {
  int R[MAX], n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> R[i];

  int maxv = - pow(10, 9) - 1;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i]-minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
  
}



Measured memory_bytes: 3892
def bb
    n = gets.chomp.to_i
    a = gets.chomp.split(/\s/).map{|x| x.to_i}

    r = 0
    for i in 0..(a.length-1)
        b = Rational(1, a[i])
        r += b
    end

    puts (1/r).to_f
end

bb


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

// #define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;

using P = pair<int, int>;


vector<int> to[100005];
int cost[100005];
signed main(){
    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;
    rep(i,n) {
        FOR(j, i+1, n) {
            int a = j-i;
            if(x<j || i <y) a = min(a, abs(x-i)+1+abs(y-j));
            cost[a]++;  
            //cout << i+1<<" "<<j+1<<" "<<a << endl; 
        }
    }
    FOR(i,1,n) cout << cost[i] << endl;

    return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
const int N = 100005;
int n;
int l[N], r[N];
set <pii> L, R;
int move(int &p, int l, int r) {
    if (l <= p && p <= r) return 0;
    int ans;
    if (p < l) ans = l - p, p = l;
    else ans = p - r, p = r;
    return ans;
}
bool used[N];
ll solve(int st) {
    ll ans = 0;
    for (int i = 0; i < n; ++ i) {
        used[i] = 0;
        L.insert(make_pair(l[i], i));
        R.insert(make_pair(r[i], i));
    }
    int p = 0;
    for (int t = 0; t < n; ++ t) {
        if (st & 1) {
            Rep1:
            auto it = L.rbegin();
            if (used[it -> second]) {
                L.erase(*it);
                goto Rep1;
            }
            ans += move(p, l[it -> second], r[it -> second]);
            used[it -> second] = 1;
            L.erase(*it);
        }
        else {
            Rep2:
            auto it = R.begin();
            if (used[it -> second]) {
                R.erase(*it);
                goto Rep2;
            }
            ans += move(p, l[it -> second], r[it -> second]);
            used[it -> second] = 1;
            R.erase(*it);
        }
        st ^= 1;
    }
    return ans + abs(p);
}
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++ i) {
        scanf("%d%d", &l[i], &r[i]);
    }
    printf("%lld\n", max(solve(0), solve(1)));
    return 0;
}

Measured memory_bytes: 10496
#include <stdio.h>
 
int isSame(const int *A,const int *B)
{
    int p1, p2, t1, t2, f1, f2, e, h;
 
    h = 0;
    for (p1 = 0; p1 < 6; p1++)
    {
        if (A[0] == B[p1] && A[5] == B[5 - p1])
        {
            h = 1;
            break;
        }
    }
    if (!h) return 0;
 
    h = 0;
    for (p2 = 0; p2 < 6; p2++)
    {
        if (p2 == p1 || p2 == 5 - p1) continue;
        if (A[1] == B[p2] && A[4] == B[5 - p2])
        {
            h = 1;
            break;
        }
    }
    if (!h) return 0;
 
    t1 = p1 / 3;
    t2 = t1 > 0 ? 3 - (t1 + p1 % 3) : p1 % 3;
    f1 = p2 / 3;
    f2 = f1 > 0 ? 3 - (f1 + p2 % 3) : p2 % 3;
 
    e = t1 ^ f1;
    e = f2 - (t2 + 1) % 3 != 0 ? !e * 3 : e * 3;
    e += e > 0 ? (t2 + f2) - 1 : 3 - (t2 + f2);
         
    if (A[2] != B[e] || A[3] != B[5 - e]) return 0;
 
    return 1;   
}
 
int main()
{
    int A[6];
    int B[6];
    int i;
 
    for (i = 0; i < 6; i++) scanf("%d", &A[i]);
    for (i = 0; i < 6; i++) scanf("%d", &B[i]);
 
    if (isSame(A, B)) printf("Yes\n");
    else printf("No\n");
 
    return 0;
 
}


Measured memory_bytes: 2104
import itertools
import numpy as np

n, m ,x = map(int, input().split())

# l = list(range(0, n))
# print(l)

ca_list = []
for _ in range(n):
    ca_list.append(list(map(int, input().split())))

l = [True, False]
    
# print(l)

value_list = []
for is_buy_list in itertools.product(l, repeat=n):
    sum_l = np.array([0] * (m + 1))
    for i in range(n):
        # print(ll[i])
        if is_buy_list[i]:
            sum_l += np.array(ca_list[i])
            # print(sum_l)

    # print(min(sum_l[1:]))
    if min(sum_l[1:]) >= x:
        # print(sum_l[0])
        value_list.append(sum_l[0])
# print(min(value_list))

if len(value_list) > 0:
    print(min(value_list))
else:
    print(-1)

Measured memory_bytes: 27340
from collections import deque
import sys
input = sys.stdin.readline
q = deque()
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
x = ((-1, 0), (1, 0), (0, -1), (0, 1))
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            for k in x:
                if 0 <= i + k[0] < h and 0 <= j + k[1] < w and a[i + k[0]][j + k[1]] == ".":
                    a[i + k[0]][j + k[1]] = "0"
                    q.append([i + k[0], j + k[1], 1])
ans = 0
while q:
    u, v, res = q.popleft()
    for k in x:
        if 0 <= u + k[0] < h and 0 <= v + k[1] < w and a[u + k[0]][v + k[1]] == ".":
            a[u + k[0]][v + k[1]] = "0"
            q.append((u + k[0], v + k[1], res + 1))
            ans = res + 1
print(ans)

Measured memory_bytes: 185416
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    rep(i, n)
    {
        cin >> a[i];
        sum += a[i];
    }
    int cnt = 0;
    rep(i, n)
    {
        if(sum <= 4*m*a[i]){
            cnt++;
        }
    }
    if(cnt >= m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 50;
int main()
{
    std::ios::sync_with_stdio(false);
    int k;
    cin >> k;
    int cnt = 0;
    for(int i = 1;i <= 1e7;i++){
        cnt *= 10;
        cnt += 7;
        cnt %= k;
        if(!cnt) return cout << i << endl, 0;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>

int main()
{
    int N;
    int H;
    int W;
    int A[1000];
    int B[1000];
    int i;
    int ans;

    scanf("%d %d %d\n",&N,&H,&W);

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

    ans=0;

    for(i=0;i<N;i++){
        if(H<=A[i] && W<=B[i]){
            ans++;        
        }
    }

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

    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
void read (int &x) {
    char ch = getchar(); x = 0;
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
} const int N = 1e5 + 5;
int n, x, m, res, w[N], a[N], tot, s[N];
signed main() {
    read (n), read (x), read (m);
    int now = x % m; res += now;
    a[++tot] = now, w[now] = 1;
    for (int i = 2; i <= n; ++i) {
        now = now * now % m;
        if (w[now]) {
            n -= (i - 1);
            for (int j = w[now]; j <= tot; ++j)
                s[j] = s[j - 1] + a[j];
            int len = tot - w[now] + 1;
            res += s[tot] * (n / len);
            n %= len;
            res += s[w[now] + n - 1];
        } else  res += now, a[++tot] = now, w[now] = tot;
    } return printf ("%lld\n", res), 0;
}


Measured memory_bytes: 5256
import qualified Data.ByteString.Char8 as C
import Data.Vector.Unboxed
import Prelude hiding (tail)

main = C.interact $ put . sol . get
get = unfoldr (C.readInt . C.dropWhile (<'0'))
put = C.pack . show
sol = ifoldl' (\s i a -> if even i then s-a+1 else s+a) 0 . tail

Measured memory_bytes: 3956
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            ans = i*500 + j*100 + k*50
            if ans == x:
                count += 1

print(count)

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

int main() {
  int a, S1, S2, S3;
  cin >> a;
  S1 = a / 100;
  S2 = (a % 100)/ 10;
  S3 = ((a % 100) % 10);
  cout << S1+S2+S3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
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; }
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);}

int main(){
  int N,K;
  cin >> N >> K;
  vector<double> p(N);
  rep(i,N) cin >> p.at(i);
  vector<double> pc(N);
  rep(i,N){
    pc.at(i) = (p.at(i)+1)*p.at(i)/2/p.at(i);
  }

  vector<double> ans(N-(K-1));

    double sum = 0;
    rep(j,K){
      sum+=pc.at(j);
    }
    ans.at(0) = sum;

  for(int i=0; i < N-(K-1)-1 ; i++){
    ans.at(i+1)=ans.at(i)-pc.at(i)+pc.at(i+K);
  }

  sort(all(ans));
  
  cout << fixed << setprecision(10) << (double)ans.back() << endl;
  
}


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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

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

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

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

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

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    int N = input();
    vector< pair<i64, int> > A(N);
    range(i, 0, N) {
        cin >> A[i].first;
        A[i].second = i;
    }

    whole(sort, A);

    auto dp = make_vector(N, N, 0ll);
    range(d, 0, N) {
        i64 idx, a;
        tie(a, idx) = A[d];

        range(i, d, N) {
            int l = i - d;
            int r = i;
            
            dp[l][r] = max(dp[min(l + 1, N - 1)][r] + a * abs(idx - l), dp[l][max(0, r - 1)] + a * abs(idx - r));
        }
    }
    
    cout << dp[0][N - 1] << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 34616
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }


// mod演算ライブラリ (factset以降に関しては, modは素数限定)
ll mod = 1000000007;

ll add_mod(ll a, ll b) {  // a + b
	return (a + b) % mod;
}

ll sub_mod(ll a, ll b) {  // a - b
	return (a + mod - b) % mod;
}

ll mul_mod(ll a, ll b) {  // a * b
	return ((a % mod) * (b % mod)) % mod;
}

ll pow_mod(ll x, ll y) { // x^y 単品利用可
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) {
		ll tmp = pow_mod(x, y / 2) % mod;
		return tmp * tmp % mod;
	}
	else {
		ll tmp = pow_mod(x, y / 2) % mod;
		return ((tmp * tmp) % mod) * x % mod;
	}
}

ll dvs_mod(ll a, ll b) {
	return mul_mod(a, pow_mod(b, mod - 2));
}

const ll SIZE_mod = 300005;
ll invfact[SIZE_mod];
ll fact[SIZE_mod];

void factset(ll a) {  // a までの 階乗 % mod 表を作成
	fact[0] = 1;
	for (ll i = 1; i <= a; ++i) {
		fact[i] = mul_mod(fact[i - 1], i);
	}
}

void cmbset(ll a) {  // 1~a までの階乗と階乗数の逆元のmod(mod)を用意 O(a)
	factset(a);
	invfact[a] = pow_mod(fact[a], mod - 2);
	invfact[0] = 1;
	for (ll i = a - 1; i >= 1; --i) {
		invfact[i] = mul_mod(invfact[i + 1], i + 1);
	}
}

ll cmb_mod(ll n, ll r) {  // nCr % mod  (cmbset後に使用)
	if (n < r || r < 0 || n < 0) return 0;
	return mul_mod(fact[n], mul_mod(invfact[r], invfact[n - r]));
}

ll prm_mod(ll n, ll r) {  // nPr % mod
	return mul_mod(cmb_mod(n, r), fact[r]);
}

ll homo_mod(ll n, ll r) {  // nHr % mod
	return cmb_mod(n + r - 1, r);
}


int main() {
	cmbset(200000);
	
	ll N, X;
	cin >> N >> X;
	vll S(N);
	rep(i, N) cin >> S[i];
	sort(all(S));

	ll dp[200][100001] = {0};	// i 番目までの数で X を割る
	rep(i, N) {
		rep(num, X + 1) {
			if (i == 0) dp[0][num] = num % S[i];
			else {
				dp[i][num] = add_mod(mul_mod(dp[i - 1][num] , i), dp[i - 1][num % S[i]]);
			}
		}
	}
	cout << dp[N - 1][X] << endl;
}

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

int main()
{
    int n;
    int p[20];
    int i,j;

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

    int ans=0;
    int temp=0;

    for(i=1;i<n-1;i++){
        if(p[i-1]>p[i+1]){
            if(p[i-1]>p[i] && p[i]>p[i+1]){
                ans++;
            }
        }else if(p[i-1]<p[i+1]){
            if(p[i-1]<p[i] && p[i]<p[i+1]){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
 
import sys
# 以下を記述しないとTLEになる, 何故？
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
# ---- ここまで -----------------------

S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        sys.exit()

ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1

print(ans)


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

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int r=count(s.begin(),s.end(),'R');
    if(r>n-r){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
s = str(input())
kekka = 1
for i in range(len(s)):
  if i%2 == 0 and s[i] != 'h':
    kekka = -1
    break
  elif i%2 == 1 and s[i] != 'i':
    kekka = -1
    break
if kekka == 1 and len(s)%2 == 0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
const ll INF = 1e18;
struct Point {
    ll x,y;
}a[N];
ll d[50];
ll dir[4][2]={{-1,0},{1,0},{0,1},{0,-1}};
string s="LRUD";
ll n,cnt=0;
ll dis(ll x1, ll y1, ll x2, ll y2) {
    return abs(x1-x2)+abs(y1-y2);
}
void solve(ll x, ll y) {
    Point now={0,0};
    for (int i=1; i<=cnt; i++) {
        ll mi=INF;
        ll pos=0;
        for (int j=0; j<4; j++) {
            ll tx=now.x+dir[j][0]*d[i],ty=now.y+dir[j][1]*d[i];
            ll t=dis(tx,ty,x,y);
            if (mi>t) mi=t,pos=j;
        }
        now.x+=d[i]*dir[pos][0],now.y+=d[i]*dir[pos][1];
        putchar(s[pos]);
    }
    puts("");
}
int main() {
    cin>>n;
    for (int i=1; i<=n; i++) {
        cin>>a[i].x>>a[i].y;
        if((abs(a[i].x+a[i].y)&1)!=(abs(a[1].x+a[1].y)&1)) return 0*puts("-1");
    }
    for (ll i=30; i>=0; i--) d[++cnt]=1<<i;
    if ((a[1].x+a[1].y)%2==0) d[++cnt]=1;
    cout<<cnt<<endl;
    for (int i=1; i<cnt; i++) cout<<d[i]<<" ";
    cout<<d[cnt]<<endl;
    for (int i=1; i<=n; i++) {
        solve(a[i].x,a[i].y);
    }
    return 0;
}

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

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

using namespace std;

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

  if(a%2 || b%2 || c%2){
    cout<<0; return 0;
  }

  if(a==b && b==c){
    cout<<-1; return 0;
  }

  bool f=1;
  ll count=0;
  while(f){
    ll ta = b/2+c/2;
    ll tb = a/2+c/2;
    ll tc = a/2+b/2;
    a=ta;b=tb;c=tc;
    f=!(a%2 || b%2 || c%2);
    count++;
  }

  cout<<count;

  return 0;
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

signed main() {
	std::string s;
	std::cin >> s;
	std::vector<char> t;
	for(char i:s) if(i!='x') t.emplace_back(i);
	// check if t is palindrome
	{
		int sz = t.size();
		bool is_palindrome = true;
		for(int i=0;i<sz/2;i++) {
			if(t[i]!=t[sz-1-i]) {
				is_palindrome = false;
				break;
			}
		}
		if(!is_palindrome) {
			print(-1);
			return 0;
		}
	}
	{
		int i=0;
		std::vector<int> count(t.size()+1,0);
		for(char c:s) {
			if(c!='x') {
				i++;
				continue;
			}
			count[i]++;
		}
		int sum = 0;
		for(int j=0;j<(t.size()+1)/2;j++) {
			sum+=std::abs(count[j]-count[t.size()-j]);
		}
		print(sum);
	}
	return 0;
}


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

using namespace std;

int main(void){

    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];

    int result = 0;
    sort(a.begin(), a.end());
    for(int i=0; i<n; i++) {
        if(a[i] < x && i==n-1) {
            if(a[i] == x) result++;
        }
        else if(a[i] < x) {
            result++;
            x -= a[i];
            
        }
        else if(a[i] == x) {
            result++;
            break;
        }
        else {
            break;
        }

    }

    cout << result <<endl;

    return 0;
    
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int n,i,x,t;
  cin >> n;
  for(i=1;i<=n;i++){
    if(i%3==0){
      cout << " " << i;
    } else if (i%10==3){
      cout << " " << i;
    } else {
      for(x=i;x>0;x/=10){
        if(x%10==3){
          cout << " " << i;
          break;
        }
      }

      }
    }

 cout << endl;
  return 0;
}



Measured memory_bytes: 3088
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 3e3 + 3;

int ns, nt;
char s[N], t[N];
int dp[N][N];
pair<int, int> trace[N][N];
bool inResult[N][N];

int main()
{
//    freopen("input.inp", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> s + 1 >> t + 1;
    ns = strlen(s + 1);
    nt = strlen(t + 1);
    for (int i = 1; i <= ns; ++i)
        for (int j = 1; j <= nt; ++j)
        {
            if (dp[i][j] < dp[i - 1][j])
            {
                dp[i][j] = dp[i - 1][j];
                trace[i][j] = {i - 1, j};
            }
            if (dp[i][j] < dp[i][j - 1])
            {
                dp[i][j] = dp[i][j - 1];
                trace[i][j] = {i, j - 1};
            }
            if (s[i] == t[j])
            {
                if (dp[i][j] < dp[i - 1][j - 1] + 1)
                {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                    trace[i][j] = {i - 1, j - 1};
                    inResult[i][j] = true;
                }
            }
        }
    string ans;
    int i = ns;
    int j = nt;
    while (i >= 1 && j >= 1)
    {
        if (inResult[i][j])
            ans.push_back(s[i]);
        int ni = trace[i][j].first;
        int nj = trace[i][j].second;
        i = ni;
        j = nj;
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
    return 0;
}


Measured memory_bytes: 114688
#include <bits/stdc++.h>
using namespace std;
// type
#define int long long
typedef long long ll;
typedef long double ld;
// loop
//#define For(i, l, r, x)     for (int i = l; i < r; i+=x)
//#define ForE(i, l, r, x)    for (int i = l; i <= r; i+=x)
//#define Ford(i, r, l)       for (int i = r; i > l; i--)
//#define FordE(i, r, l)      for (int i = r; i >= l; i--)
//#define Fora(i, a)          for (auto i : a)
// I/O 
#define openfile(file)      freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
#define testinput(file)     freopen(file".txt", "r", stdin); 
#define FAST_IO             std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//#define PrintV(a)           Fora(ii, a) cout << ii << ' '; cout << rl;
//#define PrintVl(a)          Fora(ii, a) cout << ii << rl;
//#define PrintA(a, l, r)     for (int ii = l; ii <= r; ii++) cout << a[ii] << ' '; cout << rl;
//#define PrintAl(a, l, r)    for (int ii = l; ii <= r; ii++) cout << a[ii] << rl;
//#define Ptest(x)            return cout << x, 0;
#define setpre(n)           fixed << setprecision(n)
// pair
#define F                   first
#define S                   second
#define pii                 pair<int, int>
#define pll                 pair<ll, ll>
#define pdd                 pair<ld, ld>
// vector & !!?(string)
#define eb                  emplace_back
#define pb                  push_back
#define all(a)              a.begin(), a.End()
#define rall(a)             a.rbegin(), a.rEnd()
#define sz(a)               a.size()
#define len(a)              a.length()
// geometry calc    
#define pi                  acos(-1.0)
#define g_sin(a)            sin(a*pi/180)
#define g_cos(a)            cos(a*pi/180)
#define g_tan(a)            tan(a*pi/180)
// set val
#define ms0(a)              memset(a,        0, sizeof(a));
#define ms1(a)              memset(a,        1, sizeof(a));
#define msn1(a)             memset(a,       -1, sizeof(a));
#define msinf(a)            memset(a, 0x3f3f3f, sizeof(a));
// constant
const int mod1 = 998244353, mod = 1e9+7;
const int MAXN = 1000005, MAXM = 200010;
// code

int n, dp[MAXM][20], a[MAXM];
vector<int> calc(){
	vector<int> res(n+1, 0);
	for (int i = 0; i < 16; i++)
		dp[n][i] = i;
	
	for (int i = n - 1; i > 0; i--){
		int p = 1, t = 1, c = 0;
		res[i] = 1e18;
		for(int j = 0; j < 16; j++){
			while((1.0*a[i+1]/p) < (1.0*a[i]/t)){
				t*=4;
				c++;
			}
			dp[i][j] = j + dp[i+1][min(15ll, c)] + (n - i) * max(0ll, c - 15);
			p *= 4;
			res[i] = min(res[i], dp[i][j]);
		}
	}
	return res;
}

void Solve(){
    cin >> n;
	for (int i = 1; i <= n; i++){
	    cin >> a[i];
	}
	vector<int> suff = calc();
	reverse(a+1, a+n+1);
	vector<int> pref = calc();
	
	int ans = 1e18;
    for (int i = 0; i <= n; i++)
        ans = min(ans, 2*(suff[i+1] + pref[n+1-i]) + i);
        //cout << ans << ' ';
    
    cout << ans << endl;
}

signed main(){
    //openfile("task");
    FAST_IO;
    int TC = 1;
	//cin >> TC;
    while(TC--) Solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}


Measured memory_bytes: 39020
def main():
    N, T = map(int, input().split())
    A = list(map(int, input().split()))
    min_A = float('inf')
    cnt = 0
    profit = 0
    for i in range(N):
        min_A = min(min_A,A[i])
        diff_A = A[i] - min_A
        if profit == diff_A:
            cnt += 1
        elif profit < diff_A:
            cnt = 1
            profit = diff_A
    print(cnt)



if __name__ == "__main__":
    main()

Measured memory_bytes: 85160
//B
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt(),a = sc.nextInt();
		int[] h = new int[n];
		int snum = -1;
		double d = 0,tem,hd;
		for(int i = 0;i < n;i ++) {
			tem = 0; hd = 0;
			h[i] = sc.nextInt();
			tem = t - h[i] * 0.006;
			hd = Math.abs(a-tem);
			if(i == 0 || d >= hd) {
				snum = i+1;
				d = hd;
			}
		}
		System.out.println(snum);
	}
}

Measured memory_bytes: 22228
L=int(input())
A=[int(input()) for _ in range(L)]
dp=[[0 for _ in range(5)] for _ in range(L+1)]

for i in range(1,L+1):
    a=A[i-1]
    back = a%2 if a>0 else 2
    through = (a+1)%2


    dp[i][0]=dp[i-1][0]+a
    dp[i][1]=min(dp[i-1][0:2])+back
    dp[i][2]=min(dp[i-1][0:3])+through
    dp[i][3]=min(dp[i-1][0:4])+back
    dp[i][4]=min(dp[i-1][0:5])+a

print(min(dp[L]))

Measured memory_bytes: 74076
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int n;
string str[4][255];

int migi(int y,int x) {
  int count = 0;

  for(int i=x;i<n;i++){
    if(str[0][y][i] == '1') {
      count++;
      str[0][y][i] = '0';
    }
    else break;
  }
  return count;

}

int sita(int y,int x) {
  int count = 0;
  for(int i=y;i<n;i++) {
    if(str[1][i][x] == '1') {
      count++;
      str[1][i][x] = '0';
    }
    else break;
  }

  return count;
}

int migisita(int y,int x) {
  int count = 0;
  int i=0;
  while(1) {
    if(y+i == n || x+i == n) break;

    if(str[2][y+i][x+i] == '1'){
      str[2][y+i][x+i] = '0';
      count++;
    }
    else break;
    i++;
  }
  return count;
}

int hidarisita(int y,int x) {
 int count = 0;
  int i=0;
  while(1) {
    if(y+i == n || x-i == -1) break;

    if(str[3][y+i][x-i] == '1'){
      str[3][y+i][x-i] = '0';
      count++;
    }
    else break;
    i++;
  }
  return count;
}


int main(){
  while(1) {
  cin >> n;
  if(n == 0) break;

  for(int i=0;i<n;i++) {
    cin >> str[0][i];
    str[1][i] = str[2][i] = str[3][i] = str[0][i];
  }

  int ans = 0,t;
    for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++) {
	if(str[0][i][j] == '1') ans = max(ans,migi(i,j));
	if(str[1][i][j] == '1') ans = max(ans,sita(i,j));
	if(str[2][i][j] == '1') ans = max(ans,migisita(i,j));
	if(str[3][i][j] == '1') ans = max(ans,hidarisita(i,j));
      }
    }

    cout << ans << endl;

  }

  return 0;
}

Measured memory_bytes: 1508
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000

int main(){

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

    for(int i = 0; i < 10; i++){
        bool flag = false;
        for(int j = 0; j < d.size(); j++){
            if(d[j] == i){
                flag = true;
                break;
            }
        }
        if(!flag){
            cout << i << endl;
            return 0;
        }
    }

    for(int i = 10; i < 100; i++){
        bool flag = false;
        for(int j = 0; j < d.size() - 1; j++){
            if(10 * d[j] + d[j + 1] == i){
                flag = true;
                break;
            }
        }
        if(!flag){
            cout << i << endl;
            return 0;
        }
    }

    for(int i = 100; i < 1000; i++){
        bool flag = false;
        for(int j = 0; j < d.size() - 2; j++){
            if(100 * d[j] + 10 * d[j + 1] + d[j + 2] == i){
                flag = true;
                break;
            }
        }
        if(!flag){
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>

using namespace std;

int main(int argc, char** argv){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> s(M, vector<int>(0));
    for (int i=0; i<M; i++){
        int k;
        cin >> k;
        for (int j=0; j<k; j++){
            int tmp;
            cin >> tmp;
            s[i].push_back( tmp);
        }
    }
    vector<int> p(M);
    for (int i=0; i<M; i++) cin >> p[i];

    int count = 0;
    bitset<100> bs_max;
    for (int i=0; i<N; i++) bs_max.set(i);
    unsigned int state = 0;
    while (1){
        //cerr << "State: " << state << "\n";
        bitset<100> bs = static_cast<bitset<100>>(state);
        bool flag = true;
        for (int i=0; i<M; i++){
            int on = 0;
            for (size_t j=0; j<s[i].size(); j++){
                if (bs.test(s[i][j]-1)) on++;
                //cerr << bs[s[i][j]-1] << "\n";
            }
            //cerr << "  Switch on: " << on << "\n";
            //cerr << "  Switch on % 2: " << on%2 << "\n";
            //cerr << "  p: " << p[i] << "\n";
            if ((on%2) != p[i]){
                //cerr << "  Lump " << i << " is off\n";
                flag = false;
                break;
            }
            //cerr << "  Lump " << i << " is on\n";
        }
        if (flag) count++;
        if (bs == bs_max) break;
        state++;
    }

    cout << count << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>




int main(void){




int m,n,ai,min,max;

long sum;




scanf("%d",&n);




for(m=0;m<n;m++){

scanf("%d",&ai);

        

if(m==0){

min=ai;

max=ai;

sum=ai;

}




else{

if(ai<min){

min=ai;

}




if(max<ai){

max=ai;

}




sum+=(long)ai;

}

}

    

printf("%d %d %ld\n",min,max,sum);




return 0;

}

Measured memory_bytes: 600
n=int(input())
l=[]
for i in range(n):
  a,b=map(int,input().split())
  l.append((a-b,a+b))
l.sort(key=lambda x:x[0])
L=l[0][0];R=l[0][1]
if n==1:print(1);exit()
ans=n
for i in range(1,n):
  if l[i][0]<R:
    ans-=1
    if R<l[i][1]:
      pass
    else:
      R=l[i][1]
  else:
    R=l[i][1]
print(ans)

Measured memory_bytes: 18216