akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<double, double> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

const ll mod = 1000000007;
const ll INF = 100000000000010000;

ll bit[200010];
//ll kai[1000010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

ll sum(ll i)
{
	i += 1;
	ll t = 0;
	while (i > 0)
	{
		t = max(bit[i], t);
		i -= i & -i;
	}
	return t;
}

void update(ll i, ll x)
{
	i += 1;
	while (i <= 200005)
	{
		bit[i] = max(bit[i], x);
		i += i & -i;
	}
}

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll y) {
	if (y == 0) return 1;
	if (y % 2 == 1) {
		return x * pow_mod(x, y - 1) % mod;
	}
	else {
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

/*ll com(ll x, ll y) {
	return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod;
	//毎回オーダーlog(n)かかる
}

void kaijo() {
	kai[0] = 1;
	for (ll i = 1; i <= 1000005; i++) {
		kai[i] = kai[i - 1] * i % mod;
	}
}*/

ll N;
ll h[200010], a[200010];
ll ans;

/*void init(ll n_) {
	n = 1;
	while (n < n_) n *= 2;
}

void update(ll k, ll a) {
	k += n - 1;
	dat[k] = a;
	while (k > 0) {
		k = (k - 1) / 2;
		dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
	}
}

ll query(ll a, ll b, ll k, ll l, ll r) {
	if (r <= )
}*/

void solve() {
	cin >> N;
	rep(i, N) cin >> h[i];
	rep(i, N) cin >> a[i];
	rep(i, N) {
		update(h[i], sum(h[i] - 1) + a[i]);
	}
	rep(i, N) {
		ans = max(ans, sum(i + 1));
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	ll N;
	cin >> N;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <math.h>
#include <limits.h>

int main(){

    long N = 0;
    double sN = 0;
    long tmp = 0;
    long move = LONG_MAX;

    scanf("%ld", &N);
    sN = sqrt(N);

    for (int i = 1; i <= sN; i++){
        if ((N % i) == 0){
            tmp = i + (N / i) - 2;
            if (tmp < move){
                move = tmp;
            }
        }  
    }
    printf("%ld", move);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
vector<int> nex[1145];
double dp[1145];
signed main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int s,t;
		cin>>s>>t;
		nex[s].pb(t);
	}
	for(int i=1;i<=n-1;i++){
		sort( nex[i].begin(), nex[i].end() );
	}
	double ans = 100000.0;
	for(int k=1;k<=n-1;k++){
		dp[n]=0.0;
		for(int i=n-1;i>=1;i--){
			int cnt = 0;
			double sum = 0.0;
			if( i == k ){
				vector<double> vec;
				for(int j=0;j<nex[i].size();j++){
					int nx = nex[i][j];
					vec.pb(dp[nx]);
					sum += dp[nx];
					cnt++;
				}
				sort( vec.begin(), vec.end() );
				if( vec.size() > 1 ){
					sum -= vec[vec.size()-1];
					cnt--;
				}
			}
			else{
				for(int j=0;j<nex[i].size();j++){
					int nx = nex[i][j];
					sum += dp[nx];
					cnt++;
				}
			}
			dp[i] = sum/cnt + 1.0;
		}
		if( ans > dp[1] ) ans = dp[1];
	}
	cout<<setprecision(16)<<ans<<endl;
	return 0;
}

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

int main(){
    int U,N,K,sum=0;
    cin>>N>>K;
    vector<int>vec(N);
    for(int i=0;i<N;i++){
        cin>>vec[i];
        U=vec[i]-K;
        if(U<0){U*=-1;}
        if(U<vec[i]){sum+=U*2;}
        else{sum+=vec[i]*2;}
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
<?php
$s = trim(fgets(STDIN));

$str = "AKIHABARA";
for($i = 0; $i < 2**9; $i++){
    $bin = sprintf("%09b\n", $i);
    $ss = "";
    for($j = 0; $j < 9; $j++){
        if($bin[$j] || $str[$j] != 'A')$ss.=$str[$j];
    }
    if($s==$ss){
        echo "YES";exit;
    }
}
echo "NO";


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

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	
	string s;
	cin >> s;
	int cnt0 = 0, cnt1 = 0, s0 = 0, s1 = 1; 
	for (int i = 0; i < s.length(); i++) {
		if ((s[i] - '0') != s0)
			cnt0++;
		else
			cnt1++;
		s0 = 1 - s0;
		s1 = 1 - s1;
	}
	cout << min(cnt0, cnt1) << endl;
    return 0;
}


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

int main()
{
    vector<vector<int>> A(3, {0, 0, 0});
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> A[i][j];
        }
    }
    vector<vector<bool>> ans(3, {false, false, false});
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (A[i][j] == x)
                {
                    ans[i][j] = true;
                }
            }
        }
        if ((ans[0][0] && ans[1][0] && ans[2][0]) ||
            (ans[0][1] && ans[1][1] && ans[2][1]) ||
            (ans[0][2] && ans[1][2] && ans[2][2]) ||
            (ans[0][0] && ans[0][1] && ans[0][2]) ||
            (ans[1][0] && ans[1][1] && ans[1][2]) ||
            (ans[2][0] && ans[2][1] && ans[2][2]) ||
            (ans[0][0] && ans[1][1] && ans[2][2]) ||
            (ans[2][0] && ans[1][1] && ans[0][2]))
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
//最大公約数
lint gcd( lint m, lint n )
{
	lint a=max(m,n),b=min(m,n);
	if(m==0) return n;if(n==0) return m;
	if(a%b==0) return b;
	return gcd(b,a-b*(a/b));
}

//最小公倍数
//（超えそうだったらlong longにすること！）
lint lcm( lint m, lint n )
{
	if (( 0 == m ) || ( 0 == n )) return 0;
	return ((m / gcd(m, n)) * n);
}
vector<lint> so;
bool sos[10010];
lint out[510][510];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
map<lint,int> me;
set<lint> se;
int main()
{
	lint inf=1000000000000000LL;
	memset(sos,false,sizeof(sos));
	REP(i,2,10010){
		if(sos[i]) continue;
		for(int j=i+i;j<10010;j+=i) sos[j]=true;
		if(i>501 && so.size()<510) so.pb(i);
	}
	rep(i,500) rep(j,500){
		if((i+j)%2==0) continue;
		out[i][j]=so[i/2]*(j+2);
		se.insert(out[i][j]-1);
	}
	rep(i,500) rep(j,500){
		if((i+j)%2==1) continue;
		out[i][j]=1;
		if(i>0) out[i][j]*=so[(i-1)/2];
		if(i<499) out[i][j]*=so[(i+1)/2];
		for(int k=max(0,j-1);k<min(500,j+2);k++) out[i][j]*=(k+2);
		lint t=1;
		while(se.find(out[i][j]*t)!=se.end()) t++;
		out[i][j]*=t;
		se.insert(out[i][j]);
		out[i][j]++;
	}
	rep(i,500) rep(j,500){
		assert(out[i][j]<=inf);
		if(out[i][j]>=inf){
			cout<<out[i][j]<<endl;
		}
		//assert(!me[out[i][j]]);
		if(me[out[i][j]]>0){
			cout<<out[i][j]<<' '<<i<<' '<<j<<' '<<me[out[i][j]]<<endl;
		}
		me[out[i][j]]++;
		rep(k,4){
			int x=i+dx[k],y=j+dy[k];
			if(x<0 || y<0 || x>499 || y>499) continue;
			lint a=max(out[i][j],out[x][y]),b=min(out[i][j],out[x][y]);
			if(a%b!=1LL){
				cout<<i<<' '<<j<<' '<<x<<' '<<y<<' '<<a<<' '<<b<<' '<<a%b<<endl;
			}
		}
	}
	int n;cin>>n;
	rep(i,n){
		rep(j,n){
			cout<<out[i][j];
			if(j<n-1) cout<<' ';else cout<<endl;
		}
	}
}


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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int f = 0;

    while (a >= b)
        b *= 2, f++;
    while (b >= c)
        c *= 2, f++;
    
    if (f <= k)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	int K;
	ll N;
	cin >> N >> K;
	ll ans = 0;
	for (int j = 1; j <= 5; j++) {
		int r = K-9*j-9;
		r %= 11;
		if (r < 0) r += 11;
		int l = (r*7)%11;
		if (l == 0) l = 11;
		if (N-l >= 0) {
			ll index = (N-l)/11;
			if (index*11 + l + 2 > N) --index;
			if (index >= 0) ans += index+1;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);
  if (n == 1) {
    printf("Hello World\n");
  }
	if (n == 2) {
    int a,b;
    scanf("%d\n%d", &a, &b);
    printf("%d\n", a+b);
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(){
    int n,K; cin>>n>>K;
    vector<int> x(n),y(n);
    rep(i,n)cin>>x.at(i)>>y.at(i);
    int ans=LLONG_MAX;
    rep(i,n)rep(j,n)rep(k,n)rep(l,n){
        int x1=x.at(i),x2=x.at(j),y1=y.at(k),y2=y.at(l);
        if(x1>=x2 or y1>=y2)continue;
        int cnt=0;
        rep(m,n){
            int X=x.at(m),Y=y.at(m);
            if(X>=x1 and X<=x2 and Y>=y1 and Y<=y2)cnt++;
        }
        if(cnt>=K){
            chmin(ans, abs(x2-x1)*abs(y2-y1));
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			int a=sc.nextInt();
			int b=sc.nextInt();
			String str=sc.next();
			int pt=0,os=1;
			for(int i=0;i<n;i++){
				if(str.charAt(i)=='a'){
					if(pt<a+b){
						System.out.println("Yes");
						pt++;
					}
					else System.out.println("No");
				}
				else if(str.charAt(i)=='b'){
					if(pt<a+b && os<=b){
						System.out.println("Yes");
						pt++;
						os++;
					}
					else System.out.println("No");
				}
				else System.out.println("No");
			}
		}
	}
}

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

using namespace std;

int main()
{
    int n;
    string s;

    cin >> n;
    cin >> s;

    long long int n_R = 0, n_G = 0, n_B = 0;

    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R')
            n_R++;
        if (s[i] == 'G')
            n_G++;
        if (s[i] == 'B')
            n_B++;
    }

    long long int condition_1 = n_R * n_G * n_B;

    long long int non_condition_2 = 0;

    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j)
        {
            int k = j + (j - i);
            if (k > n - 1)
            	break;
			else if(s[i] != s[j] && s[j] != s[k] && s[i] != s[k] )
				non_condition_2++;
        }

    long long int ans = condition_1 - non_condition_2;

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

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <utility>
#include <functional>
#include <map>
#include <string>
#include <set>
#include <math.h>

using namespace std;

bool judge(int a, int b, int x) {
  if (a > x) {
    return false;
  }

  int catR = x - a;

  return catR <= b;
}

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

  int a, b, x;
  cin >> a >> b >> x;

  if (judge(a, b, x)) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
an = list(map(int, input().split()))

r = 1
xor = an[0]
sums = an[0]

cnt = 0
for l in range(n):
  while xor == sums:
    if r >= n:
      r = n + 1
      break
    xor ^= an[r]
    sums += an[r]
    r += 1
    
  cnt += ((r-1) - l)
  xor ^= an[l]
  sums -= an[l]

print(cnt)

Measured memory_bytes: 23560
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

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

  int a,b,c,x,y,sum;
  sum = 0;

  cin >> a >> b >> c >> x >> y;

  if(c*2 <= a + b){
    if(x <= y){
      if(2*c <= b){
        sum += c * 2*y;
        x -= x;
        y -= y;
      }
      else{
        sum += c * 2*x;
        y -= x;
        x -= x;
      }
    }
    else{
      if(2*c <= a){
        sum += c * 2*x;
        x -= x;
        y -= y;
      }
      else{
        sum += c * 2*y;
        x -= y;
        y -= y;
      }
    }
  }
  if(c*2 <= a){
    sum += c*2 * x;
    x -= x;
  }
  if(c*2 <= b){
    sum += c*2 * y;
    y -=y;
  }
  sum += x * a + y * b;
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
S = input()

for i in range(len(S)):
    if S[0:i] == "keyence" or S[i:len(S)] == "keyence":
        print("YES")
        exit()
        
for i in range(len(S)):
    for j in range(len(S)):
        if S[0:i] + S[j:len(S)] == "keyence":
            print("YES")
            exit()
        
print("NO")

Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
  int a;
  scanf("%d", &a);
  if(a==19 || a==29 || a==39 || a==49 || a==59 || a==69 || a==79 || a>=89){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 128
program abc
    integer,dimension(5) :: anthennas
    integer k

    do i=1,5
        read *, anthennas(i)
    end do
    read *, k

    if ((maxval(anthennas)-minval(anthennas)) > k) then
        print '(A)', ':('
    else
        print '(A)', 'Yay!'
    end if
end program abc

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T,class U>
istream& operator >> (istream&is, P<T,U>&p){
  is >> p.first >> p.second;
  return is;
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v){
    is >> e;
  }
  return is;
}

int main(){
  int n,c; cin >> n >> c;
  int d[31][31];
  for(int i = 1; i <= c; ++i)
    for(int j = 1; j <= c; ++j)
      cin >> d[i][j];
  int cc[500][500];
  map<int,int> mp[3];
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      cin >> cc[i][j];
      mp[(i+j)%3][cc[i][j]]++;
    }
  }
  int ans = 1001001001;
  for(int i = 1; i <= c; ++i){
    for(int j = 1; j <= c; ++j){
      for(int k = 1; k <= c; ++k){
	if(set<int>({i,j,k}).size() < 3)continue;
	int tmp = 0;
	int v[] = {i,j,k};
	for(int l = 0; l < 3; ++l){
	  for(auto e:mp[l]){
	    tmp += d[e.first][v[l]] * e.second;
	  }
	}
	ans = min(tmp,ans);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4548
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b,c;
    int k;
    cin>>a>>b>>c>>k;
    bool green=false;
    for (int i = 0; i < k; i++)
    {
        if(b<=a){
            b*=2;
        }
        else if(c<=b){
            c*=2;
        }
    }
    if(a<b && b<c){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    sc.close();
    if (b == 1) {
      System.out.println(0);
      return;
    }
    b -= a;
    if (b <= 0) {
      System.out.println(1);
    } else if (b % (a - 1) == 0){
      System.out.println(1 + b / (a - 1));
    } else {
      System.out.println(2 + b / (a - 1));
    }
  }
}


Measured memory_bytes: 21972
/*
___mennat khoday ra azz o va jall ke taatash mojebe ghorbat ast o be shokr andarash mazide nemat.
___har nafasi ke foro miravad momedde hayatast o chon bar miayad mofarrahe zat.
___pas dar har nafasi 2 nemat mojod ast o bar har nematy shokry vajeb.

___az dast o zabane ke barayad ?
___kaz ohdeye shokrash be dar ayad !


___man be to dami gharar natvanam kard
___va ehsane to ra shomar natvanam kard
####################
___gar bar tane man zaban shavad har moyee
___yek shokre to az hezar natvanam kard

*/

#include <bits/stdc++.h>

#define pb push_back
#define SALI main
#define left(x) ((x)*2)
#define right(x) (((x)*2)+1)
#define fuck(x) cout << #x << " : " << x << endl;
#define findLowVec(v,x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define findUpVec(v,x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define findLowArr(a,n,x) (lower_bound(a, a+n, x) - a)
#define findUpArr(a,n,x) (upper_bound(a, a+n, x) - a)
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;

template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p)
{return out << "(" << p.first << ", " << p.second << ")";}

template<class A> ostream& operator <<(ostream& out, const vector<A> &v)
{out << "[";for(int i = 0; i < v.size(); i++) {if(i) out << ", ";out << v[i];}return out << "]";}

template<class A,class B> ostream& operator <<(ostream& out, const set<A,B> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}

template<class A> ostream& operator <<(ostream& out, const set<A> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}

const int N = 2e5 + 10;
int h[N];
int a[N];
int seg[4*N];
int n;
int dp[N];

void update(int l, int r, int id, int x)
{
    int m = (l+r)/2;
    if(x < l || x >= r) return;
    if(x == l && x == r-1){
        seg[id] = dp[x];
        return;
    }

        update(l, m, left(id), x);
        update(m,r, right(id), x);
        seg[id] = max(seg[left(id)] , seg[right(id)]);

}

int solve(int l, int r, int id, int x, int y)
{
    int m = (l+r)/2;
    if(x <= l && r <= y){
        return seg[id];
    }
    if(r <= x || l >= y){
        return 0;
    }
    return max(solve(l, m, left(id), x, y), solve(m, r, right(id), x, y));
}

int32_t SALI()
{
    cin >> n; for(int i = 0; i < n; i++) cin >> h[i]; for(int i = 0; i < n; i++) cin >> a[i];
    
    for(int i = 0; i < n; i++){
        // cal dp[h[i]]
        int m = solve(0,n+1,1,0,h[i]);
        dp[h[i]] = m + a[i];
        update(0,n+1,1,h[i]);
    }
    
    int ans = 0;
    ans = seg[1];
    cout << ans << endl;
}




/**< WRITEN BY ALI ADELKHAH */



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

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

int main() {
  string s;
  cin >> s;
  map<char, int> m;
  rep(i, s.size()) {
    if (m[s[i]] > 0) {
      cout << "no" << endl;
      return 0;
    }
    m[s[i]]++;
  }
  cout << "yes" << endl;
  return 0;
}


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

using namespace std;

const int N = 1e5+7;
const int MOD = 998244353;

template <int _MOD> struct Mint
{
    int v = 0;
    Mint() {}
    Mint(int _v) : v((_v%_MOD+_MOD)%_MOD) {}
    Mint(long long _v) : v(static_cast<int>((_v%_MOD+_MOD)%_MOD)) {}
    Mint operator = (const int _v) { this->v = _v; return *this; }
    Mint operator = (const long long _v) { this->v = static_cast<int>(_v%_MOD); return *this; }
    bool operator < (const Mint &b) const { return v < b.v; }
    bool operator > (const Mint &b) const { return v > b.v; }
    bool operator == (const Mint &b) const { return v == b.v; }
    bool operator != (const Mint &b) const { return v != b.v; }
    bool operator <= (const Mint &b) const { return v < b.v || v == b.v; }
    bool operator >= (const Mint &b) const { return v > b.v || v == b.v; }
    Mint operator + (const Mint &b) { return Mint(v+b.v); }
    Mint operator - (const Mint &b) { return Mint(v-b.v); }
    Mint operator * (const Mint &b) { return Mint(1ll*v*b.v); }
    Mint operator / (const Mint &b) { return Mint(b.inv()*v); }
    Mint operator += (const Mint &b) { return *this = *this+b; }
    Mint operator -= (const Mint &b) { return *this = *this-b; }
    Mint operator *= (const Mint &b) { return *this = *this*b; }
    Mint operator /= (const Mint &b) { return *this = *this/b; }
    Mint pow(int p) const {
        Mint res(1), x(*this);
        while (p) {
            if (p&1) res = res*x;
            x *= x;
            p >>= 1;
        }
        return res;
    }
    Mint inv() const { return pow(_MOD-2); }
    friend istream& operator >> (istream &is, Mint &mt) { return is >> mt.v; }
    friend ostream& operator << (ostream &os, const Mint &mt) { return os << mt.v; }
};
using mint = Mint<MOD>;

inline mint qpow(mint a, int p) {
    if (a == 0 || p == 0) return 0;
    mint res = 1;
    while (p) {
        if (p&1) res *= a;
        a *= a;
        p >>= 1;
    }
    return res;
}

int n, mx;
int a[N], cnt[N];
mint res = 1;

int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        ++cnt[a[i]];
        mx = max(mx, a[i]);
    }
    for (int i = 1; i <= mx; ++i) {
        res *= qpow(cnt[i-1], cnt[i]);
    }
    if (a[1] != 0 || cnt[0] > 1) res = 0;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,m,s[10000],e[10000],w[10000];
long long d[150][150];

int main(){
	cin >> n >> m;
	long long inf=1e18;
	for(int i=0 ; i<n ; i++){
		for(int j=0 ; j<n ; j++){
			d[i][j]=inf;
		}
	}
	
	for(int i=0 ; i<m ; i++){
		cin >> s[i] >> e[i] >> w[i];
		d[ s[i] ][ e[i] ]=w[i];
	}
	
	for(int k=0 ; k<n ; k++){
		for(int i=0 ; i<n ; i++){
			for(int j=0 ; j<n ; j++){
				if( i==k || j==k) continue;
				d[i][j]=min( d[i][j] , d[i][k]+d[k][j] );
				if(i==j){
					if(d[i][j]<0){
						cout << "NEGATIVE CYCLE";
						cout << endl;
						exit(0);
					}
				}
			}
		}
	}
	
	for(int i=0 ; i<n ; i++){
		for(int j=0 ; j<n ; j++){
			if(i==j){
				cout << "0";
				if(j<n-1) cout << ' ';
				continue;
			}
			if(d[i][j]>2e9){
				cout << "INF";
				if(j<n-1) cout << ' ';
				continue;
			}
			cout << d[i][j];
			if(j<n-1) cout << ' ';
		}
		cout << endl;
	}
	
}


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

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;

    auto odd = A.map!(a => a % 2).sum;
    auto even = A.map!(a => 1 - a % 2).sum;

    if (odd == 0 || even == 0) {
        writeln(0);
    } else if (odd % 2 == 1) {
        writeln(N - 1);
    } else {
        writeln(N - 2);
    }
}



Measured memory_bytes: 10552
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	char s;
	cin >> s;
	if (isupper(s))
		cout << "A" << endl;
	else
	{
		cout << "a" << endl;
	}
}


Measured memory_bytes: 3568
import java.util.Scanner


object Main {

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val posList = for (_ <- 0 until 5) yield sc.nextInt()
    val k = sc.nextInt()
    for (x1 <- posList) {
      for (x2 <- posList) {
        if (Math.abs(x1 - x2) > k) {
          println(":(")
          return
        }
      }
    }
    println("Yay!")
  }
}

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

int main() {
  string n;
  cin >> n;
  bool ans = (n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3]);
  cout << (ans ? "Yes" : "No") << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_d() {
	ll n, m;
	ll a, b;
	//ll x, y;
	ll k;
	ll l_ans = 0;

	cin >> n >> a >> b;
	V x(n);
	rep(i, n) cin >> x[i];

	ll diff;
	rep(i, n - 1) {
		diff = x[i + 1] - x[i];
		if (diff * a > b) {
			l_ans += b;
		}
		else {
			l_ans += diff * a;
		}
	}

	cout << l_ans << "\n";
	return;
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(7);

	solve_abc_d();

	return 0;
}


Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main(){
    let n: usize = read();
    let m: usize = read();
    let mut bridge = Vec::new();
    for i in 0..m {
        let ai: i32 = read();
        let bi: i32 = read();
        bridge.push((ai, bi));
    }
    bridge.sort_by(|a, b| a.0.cmp(&b.0));
    let mut ans: i32 = 0;
    let mut now: i32 = 0;
    let mut last: i32 = 100001;
    for i in 0..m {
        if bridge[i].0 >= last {
            ans += 1;
            now = 1;
            last = bridge[i].1;
        } else {
            now += 1;
            last = std::cmp::min(last, bridge[i].1);
        }
    }
    if now > 0 {
        ans += 1;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    int l = 0, r = 0;
    int now = 0;
    ll ans = 0;
    while(l<n){
        while(r < n && (now^a[r]) == now + a[r]){
            now ^= a[r++];
            ans++;
        }
        now ^= a[l++];
        ans += r - l;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int N;
  cin >> N;
  long long int T;
  cin >> T;
  vector <long long int> A(N);
  
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  long long int maxT = A[N-1] + T;
  
  //maxTから空白期間を引いていく。
  maxT -= max(A[0]-T,0LL);
  for(int i = 1; i < N; i++){
  maxT -= max(A[i]-A[i-1] - T,0LL);
  }
  cout << maxT;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);



int main(){
	string s,t,u;
	cin >> s;
	for(auto x:s){
		cout << 'x';
	}
	cout << endl;
}



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

const int MAX_A = 300005;

int op(int a, int b) { return max(a,b);}
int e() { return 0;}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  segtree<int,op,e> dp(MAX_A);
  rep(i,n) {
    int x = a[i];
    int l = x-k, r = x+k+1;
    l = max(l,0);
    r = min(r,MAX_A);
    int now = dp.prod(l,r)+1;
    dp.set(x, now);
  }
  int ans = dp.prod(0,MAX_A);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin>>n;
    map<string ,int>mp;
    string s;
    int mx=-1e3;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        mp[s]++;
        mx=max(mx,mp[s]);
    }
    for(auto it:mp)
    {
        if(it.second==mx)
            cout<<it.first<<endl;
    }
}


Measured memory_bytes: 25216
//-----by LY02------------------------------------
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
//------------------------------------------------

vector<int> ed[100010];
int vis[100010];
int dp[100010];

int x(int p)
{
	if(vis[p]) return dp[p];
	vis[p]=1;
	
	int dx=0;
	
	for(auto i:ed[p])
	{
		dx=max(dx,x(i)+1);
	}
	
	dp[p]=dx;
	return dp[p];
}

//------------------------------------------------
int main() {
//------------------------------------------------
//	freopen("In.txt","r",stdin);
//	freopen("Out.txt","w",stdout);
//------------------------------------------------
	ios::sync_with_stdio(0);
	cin.tie(0);
//------------------------------------------------
int n,m;
cin>>n>>m;
int a,b;
for(int i=0;i<m;i++)
{
	cin>>a>>b; a--,b--;
	ed[a].emplace_back(b);
}

int ans=0;

for(int i=0;i<n;i++)
	ans=max(ans, x(i));

cout<<ans<<endl;

//------------------------------------------------
	return 0;
}





//-----by LY02------------------------------------


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n;
	cin>>n;
	vector<lli> a(3*n);
	REP(i,0,3*n)cin>>a[i];

	priority_queue<lli,vector<lli>,greater<lli>> mae;
	priority_queue<lli> ushi;

	lli sumMae[3*n+1]={0};
	lli sumUshiro[3*n+1]={INF};

	//maeについて前からn個取る.
	lli sum=0;
	REP(i,0,n){
		sum+=a[i];
		mae.push(a[i]);
		sumMae[i] = sum;
	}
	for(lli i=n;i<=2*n-1;i++){
		if(mae.top()<a[i]){
			sum = sum - mae.top() + a[i];
			mae.pop();
			mae.push(a[i]);
		}
		sumMae[i] = sum;
	}

	//ushiroについても同様
	sum = 0;
	REP(i,0,n){
		lli now = 3*n-1-i;
		sum += a[now];
		ushi.push(a[now]);
		sumUshiro[now] = sum;
	}
	for(lli i=n;i<=2*n-1;i++){
		lli now = 3*n-1-i;
		if(ushi.top() > a[now]){
			sum = sum - ushi.top() + a[now];
			ushi.pop();
			ushi.push(a[now]);
		}
		sumUshiro[now] = sum;
	}

	lli ans = -INF;

	if(DEBUG){
		REP(i,0,3*n){
			cout<<"mae = "<<sumMae[i]<<" ushiro="<<sumUshiro[i]<<endl;
		}
	}
	for(lli i=n-1;i<=2*n-1;i++){
		ans = max(ans,sumMae[i]-sumUshiro[i+1]);
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 9588
import sys
readline=sys.stdin.readline
read=sys.stdin.read

from operator import itemgetter

n=int(readline())
m=map(int,read().split())
robots=list(zip(m,m))
lr=[[i-j,i+j] for i,j in robots]
lr.sort(key=itemgetter(1))
prep=lr[0][1]
res=1
for l,r in lr[1:]:
  if l>=prep:
    res+=1
    prep=r
print(res)


Measured memory_bytes: 35200
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

long long A, B;
long long temp;
long long finalAns;

int main()
{
	scanf("%lld %lld", &A, &B);
	for(int i = 1; i <= 1000; i++) {
		if(((i * (i + 1)) / 2) - A >= 0 && ((i * (i + 1) / 2) - A) == ((i + 1) * (i + 2) / 2) - B) {
			temp = ((i * (i + 1) / 2));
			break ;
		}
	}
	finalAns = temp - A;
	printf("%lld\n", finalAns);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces
gi = lambda : list(map(int,input().split()))
m, n = gi()
l = gi()
ans = m - (m - l[-1] + l[0])
for k in range(1, n):
	ans = min(ans, m - (l[k] - l[k - 1]))
print(ans)

Measured memory_bytes: 25840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define f(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int> 
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define mem(a,n) memset(a,n,sizeof a)
#define ln(a) a.length()
#define sz(a) (ll)a.size()
#define endl "\n"
#define pi 3.14159265358979

const ll M=1e9+7;
const int P=31;
const int MaxM=200005;
/*__________________________________________________________________________________________________________________*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);  
    
  
      
  string n;cin>>n;
  long long int ans=0;
  for(int i=0;i<n.length();i++)
  {
      ans+=(n[i]-'0');
  } 
  if(ans%9==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
} 


Measured memory_bytes: 3716
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll>P;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
signed main() {
	ll m, d, ans = 0;
	cin >> m >> d;
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= d; j++) {
			if (j % 10 >= 2 && j / 10 >= 2 && (j % 10) * (j / 10) == i)ans++;
		}
	}
	cout << ans << endl;
	ggr
}


Measured memory_bytes: 764
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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

const ll mod = 1e9 + 7;

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


	int N = getint(), M = getint();
	ll kotae1 = 0;
	int mae = getint();
	rep1(i, N - 1) {
		ll tugi = getint();
		kotae1 += (tugi - mae) * i * (N - i)  % mod;
		mae = tugi;
	}
	kotae1 %= mod;

	ll kotae2 = 0;
	mae = getint();
	rep1(i, M - 1) {
		ll tugi = getint();
		kotae2 += (tugi - mae) * i * (M - i) % mod;
		mae = tugi;
	}
	kotae2 %= mod;

	printf("%lld", kotae1 * kotae2 % mod);

	Would you please return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    _A=list(mi())
    A = []

    for a in _A:
        if len(A) > 0 and A[-1] == a: continue
        A.append(a)
    
    N = len(A)
    bottoms = []
    
    if N < 2:
        print(1000)
        exit()

    if A[0] < A[1]:
        bottoms.append(0)

    for i in range(N-1):
        if not i+2 < len(A): continue
        # print(A[i], A[i+1], A[i+2])
        if A[i] > A[i+1] and A[i+1] < A[i+2]:
            bottoms.append(i+1)
    
    money = 1000
    kabu = 0
    # print(bottoms)
    for bi in bottoms:
        bottom = A[bi]
        i = bi
        while i < N-1 and A[i] < A[i+1]:
            i += 1
        
        top = A[i]

        # print(bi,i)
        # print(bottom,top)
        kabu += money//bottom
        money -= money//bottom * bottom
        
        money += kabu * top
        kabu = 0
        # print("money",money)
    
    print(money)

    

if __name__ == "__main__":
    main()


Measured memory_bytes: 62204
#include<iostream>
#include<string>
#include<map>
#include<algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    map<string, int>mp;
    for(int i=0; i<n; i++){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    long long ans = 0;
    for(auto& p : mp){
        int num = p.second;
        ans += (long long)num*(num-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

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


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

    ll H,ans=0;
    cin >> H;
    while(H != 0){
        H = H/2;
        ans++;
    }
    ans = pow(2,ans) -1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
use std::io;

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

fn f (s : &String) -> String {
    s.chars().map(|c| match c {',' => ' ', _ => c}).collect()
}

fn main(){
    let s = get_line();
    println!("{}", f(&s));
}

Measured memory_bytes: 380
#include<iostream>
#include<climits>
#include<numeric>
#include<algorithm>
#include <sstream>
#include<cstring>
#include<cmath>
#include<iterator>
#include<utility>
#include<array>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<forward_list>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define vs vector<string>
#define lin1(x) ll int x; x = scan();
#define lin2(x,y) ll int x, y; x = scan(), y = scan();
#define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x,y) make_pair(x,y)
#define mx(a,b) (a)>(b)?(a):(b)
#define mn(a,b) (a)<(b)?(a):(b)
#define fori(s,e) for(i=s;i<=e;i++)
#define forj(s,e) for(j=s;j<=e;j++)
#define fork(s,e) for(k=s;k<=e;k++)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;

int main()
{
#ifdef RAHUL
    freopen("input.txt","r",stdin);
#endif
char a;
cin>>a;
cout<<char(int(a)+1);

}

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

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, pll> ppll;

#define MOD 1000000007
#define f(a, b, c) for (ll(a) = (b); (a) < (c); ++(a))
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define rep(i, n) f(i, 0, n)
#define ff first
#define ss second
#define pb push_back
#define all(v) v.begin(), v.end()
#define wh(t) while (t--)
#define inf (ll)1e18
#define modd 998244353
#define pp(var) cout<<var<<"\n";
#define pm(var1, var2) cout<<var1<<" "<<var2<<"\n";
#define pv(i,v) rep(i,v.size()) cout<<v[i]<<" "; pp("");
#define pa(i,n,v) rep(i,n) cout<<v[i]<<" "; pp("");
#define K 1001
const ll N = 2e5 + 5;

ll pow(ll a, ll n, ll m)
{
	ll i = 1;
	while (n > 0)
	{
		if (n & 1)
			i = (i * a) % m;
		a = (a * a) % m;
		n = n >> 1;
	}
	return i % m;
}

ll isprime(ll n)
{
	if (n == 0 || n == 1)
		return n;
	if (n % 2 == 0)
		return (ll)2;
	if (n % 3 == 0)
		return (ll)3;
	else
	{
		for (ll i = 5; i * i <= n; i += 6)
		{
			if (n % i == 0)
				return i;
			if (n % (i + 2) == 0)
				return (i + 2);
		}
		return n;
	}
}

ll solve(ll n1, ll n2, ll check) {
	if (check == 1) {
		return max(n1, n2);
	}
	else return min(n1, n2);
}

int main() {
	fast;
	ll l, r, n, m, i, j, k, x, y, t, q;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	ll a[n];
	x = 0;
	for (auto &e : a) {
		cin >> e;
		x = x ^ e;
	}
	for (auto &e : a) {
		cout << (x ^ e) << " ";
	}
}

Measured memory_bytes: 5140
n = int(input())
a = []

for i in range(n):
    a.append(int(input()))

_max = max(a)
max_idx = a.index(_max)
a.remove(_max)
second = max(a)
for i in range(n):
    if i == max_idx:
        print("{}".format(second))
    else:
        print("{}".format(_max))

Measured memory_bytes: 12512
#include<iostream>
using namespace std;
int main(){
    while(1){
        int x,y,z;
        cin>>x>>y>>z;
        if(x==-1&&y==-1&&z==-1) break;
        else if(x==-1||y==-1) cout<<'F'<<endl;
        else if(x+y>=80) cout<<'A'<<endl;
        else if(x+y<80&&x+y>=65) cout<<'B'<<endl;
        else if(x+y<65&&x+y>=50) cout<<'C'<<endl;
        else if(x+y<50&&x+y>=30){
            if(z>=50) cout<<'C'<<endl;
            else cout<<'D'<<endl;
        }
        else if(x+y<30) cout<<'F'<<endl;
        
    }
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main()
{
    int n,m; cin >> n >> m;
    vector<int> wa(n,0);
    vector<bool> ac(n,false);
    rep(i,m){
        int p; cin >> p;
        string s; cin >> s;
        if(s=="AC") ac[p-1] = true;
        else if(!ac[p-1]) wa[p-1]++;
    }

    int ans1 = 0, ans2 = 0;
    rep(i,n){
        if(ac[i]){
            ans1++;
            ans2 += wa[i];
        }
    }

    cout << ans1 << " " << ans2 << endl;

}

/*
g++ c.cpp
./a.out

oj d URL
oj t
*/

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll tmp1[200005],tmp2[200005],a[200005],b[200005],c[200005],g[200005];
int q[200005],tl;
ll crs(int x,int y,int z){return ((y-x)*(g[y]-g[z])-(y-z)*(g[y]-g[x]));}
void add(int x)
{
    while(tl>1&&crs(q[tl-1],q[tl],x)<=0)tl--;
    q[++tl]=x;
}
int main()
{
    int n,mx=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&tmp1[i]);
        if(tmp1[i]>tmp1[mx])mx=i;
    }
    for(int i=1;i<=n;i++)scanf("%lld",&tmp2[i]);
    for(int i=mx;i<=n;i++)a[i-mx]=tmp1[i],b[i-mx]=tmp2[i];
    for(int i=1;i<=mx;i++)a[n-mx+i]=tmp1[i],b[n-mx+i]=tmp2[i];
    for(int i=2;i<=n;i++)c[i]=2*c[i-1]+2*b[i-1]-c[i-2];
    for(int i=0;i<=n;i++)g[i]=a[i]-c[i],add(i);
    int now=1;
    double res=0;
    for(int i=0;i<n;i++)
    {
        while(q[now+1]<=i)now++;
        res+=((((q[now+1]-i)*g[q[now]])+(i-q[now])*g[q[now+1]])*1.0/(q[now+1]-q[now]))+c[i];
    }
    printf("%.12lf",res/n);
    return 0;
}

Measured memory_bytes: 13828
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int a, b;
  cin >> a >> b;
  cout << max(max(a + b, a - b), a * b) << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

int main(){
    int sum, tmp;
    while(cin >>sum){
        if(sum == 0) break;
        int sumTmp = 0;
        for(int i = 0; i < 9; i++){
            cin >>tmp;
            sumTmp += tmp;
        }
        cout <<sum - sumTmp <<endl;
    }
    return 0;
}

Measured memory_bytes: 0
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
P=list(map(int,input().split()))

for i in range(len(P)):
    P[i]=(1+P[i])/2

#print(P)

temp=sum(P[:K])
ans=temp
for i in range(N-K):
    temp+=(P[i+K]-P[i])
    ans=max(ans,temp)
    #print(temp)
print(ans)

Measured memory_bytes: 25060
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

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

	cout<<(double)((N+1)/2) / N<<endl;
}

Measured memory_bytes: 256
import java.io.*;
public class Main {
	public static void main(String[] args)throws IOException{
		int x;
		String s;
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		s = buf.readLine();
		x=Integer.parseInt(s);
		
		System.out.println(x*x*x);
		
		
		
		
	}

}

Measured memory_bytes: 17000