akhauriyash/Code-Regression huggingface dataset:
# include <iostream>
# include <vector>
# include <algorithm>

using namespace std;

bool judge(int X, int Y, vector<int> xs , vector<int> ys)
{
	xs.push_back(X);
	ys.push_back(Y);
	
	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());
	
	for (int Z = X + 1; Z <= Y; Z++)
	{
		if (xs[xs.size() - 1] < Z && Z <= ys[0])
		{
			return true;
		}
	}
	
	return false;
}

int main()
{
	int N, M, X, Y;
	vector<int> x;
	vector<int> y;
	
	cin >> N;
	cin >> M;
	cin >> X;
	cin >> Y;
	for (int i = 0; i < N; ++i)
	{
		int a;
		cin >> a;
		x.push_back(a);
	}
	
	for (int i = 0; i < M; ++i)
	{
		int a;
		cin >> a;
		y.push_back(a);
	}
	
	if (judge(X, Y, x, y) == true)
	{
		cout << "No War" << endl;
	}
	else
	{
		cout << "War" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
N, K = map(int,input().split())
S = input()

i = 0
for j in range(N):
    if S[j] == "0" and (j==0 or S[j-1] == "1"):
        K -= 1
    if (K<0):
        if(S[i]=="0" and S[i+1] == "1"):
            K += 1
        i+=1

print(N-i)

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
int main() {
	string a;
	bool b = 0;
	cin >> a;
	for (int i = 0; i < 3; i++)
	{
		if (a[i]=='7')
		{
			b = true;
		}
	}
	b ? cout << "Yes" << endl : cout << "No" << endl;
}


Measured memory_bytes: 3524
# -*- coding: utf-8 -*-
"""
Created on Sat Jun  1 20:46:37 2019

@author: Yamazaki Kenichi
"""
from collections import deque

N = int(input())
ab = [list(map(int,input().split())) for i in range(N-1)]
C = list(map(int,input().split()))

C.sort(reverse=True)

T = [[] for i in range(N+1)]

for b in ab:
    T[b[1]].append(b[0])
    T[b[0]].append(b[1])

ans = [-1 for i in range(N+1)]
q = deque(T[1])
ans[1] = C[0]

i = 0
while len(q) > 0:
    tmp = q.pop()
    if ans[tmp] == -1:
        ans[tmp] = C[i+1]
        for c in T[tmp]:
            q.append(c)
#        print(q,i,tmp,ans)
        i += 1

print(sum(ans[2:]))
print(' '.join(map(str,ans[1:])))


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

int main () {
    #ifdef TooLazy
        freopen("in.txt", "r", stdin);
    #endif // TooLazy

    int n, cnt = 0, a;
    cin >> n;
    for(int i=1; i<=n; i++) {
        cin >> a;
        if( a % 4 == 0 ) cnt +=2;
        else if( a % 2 == 0 ) cnt++;
    }

    if( n % 2 == 0 ) {
        cnt >= n? puts("Yes") : puts("No");
    }
    else{
        cnt >= n-1? puts("Yes") : puts("No");
    }

    return 0;
}


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

int main() {
  
	string s;
  	cin >> s;
  	int x = 0;
  
  	for (int i = 0; i < 3; i++){
      
      if (s.at(i) == '1'){
        x = x + 1;
      }
      
    }
  
  cout << x << endl;

 }

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
 
#define rep(i, n) for(int i = 0; i < (n); ++i)
 
using namespace std;
 
int h, w;
char a[100][101];
int ex, ey;
int c[101][101];
int dp[100][100][100][100];
 
int box(int x, int y, int z, int w){
	return c[z][w] - c[z][y] - c[x][w] + c[x][y];
}
 
int main(){
	cin >> h >> w;
	rep(i, h){
		cin >> a[i];
		rep(j, w){
			if(a[i][j] == 'E'){
				ex = i;
				ey = j;
			}
			else if(a[i][j] == 'o'){
				c[i + 1][j + 1] = 1;
			}
		}
	}
 
	rep(i, h + 1){
		for(int j = 1; j <= w; ++j){
			c[i][j] += c[i][j - 1];
		}
	}
	for(int i = 1; i <= h; ++i){
		rep(j, w + 1){
			c[i][j] += c[i - 1][j];
		}
	}
 
	int ans = 0;
	rep(i, ex + 1){
		rep(j, h - ex){
			rep(k, ey + 1){
				rep(l, w - ey){
					ans = max(dp[i][j][k][l], ans);
 
					if(l < w - k && j < h - i){
						int p = max(ex - i, j);
						int q = min(ex + j + 1, h - i);
						int r = max(ey - k, l);
						int s = min(ey + l + 1, w - k);
 
						if(r <= s && p <= q){
							if(j < p){
								dp[i + 1][j][k][l] = max(dp[i + 1][j][k][l], box(p - 1, r, p, s) + dp[i][j][k][l]);
							}
							if(q < h - i){
								dp[i][j + 1][k][l] = max(dp[i][j + 1][k][l], box(q, r, q + 1, s) + dp[i][j][k][l]);
							}
							if(l < r){
								dp[i][j][k + 1][l] = max(dp[i][j][k + 1][l], box(p, r - 1, q, r) + dp[i][j][k][l]);
							}
							if(s < w - k){
								dp[i][j][k][l + 1] = max(dp[i][j][k][l + 1], box(p, s, q, s + 1) + dp[i][j][k][l]);
							}
						}
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 67328
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <set>
#include <cstdio>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
//#define P pair<int, int>
#define P pair<ll, ll>

#define MOD 1000000007
#define INF 1012345678
#define NINF (-2147483647-1)
#define LLINF 9012337203685477580
using ll = long long;
using namespace std;

// dijkstra法
const int MAX_V = 100000;
struct edge { int to, cost; };
int V;
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P>> pq;
    fill(d, d + V, LLINF);
    d[s] = 0;
    pq.push(P(0, s));

    while (!pq.empty()) {
        P p = pq.top(); pq.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (edge e : G[v])
        {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                pq.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    V = N;
    for (int i = 0; i < N-1; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back(edge{b,c});
        G[b].push_back(edge{a,c});
    }
    int Q, K;
    cin >> Q >> K;
    K--;
    dijkstra(K);
    vector<ll> ans(Q);
    for (int i = 0; i < Q; i++)
    {
        int x, y;
        cin >> x >> y;
        x--; y--;
        ans[i] = d[x] + d[y];
    }
    for (int i = 0; i < Q; i++)
    {
        cout << ans[i] << endl;
    }
    getchar(); getchar();
}

Measured memory_bytes: 9460
package main
 
import (
	"fmt"
)
 
func main() {
	var a string
	var b string
	fmt.Scan(&a)
	b = "Sunny"
	if a == "Sunny" {
		b = "Cloudy"
	} else if a == "Cloudy" {
		b = "Rainy"
	}
	fmt.Print(b)
}

Measured memory_bytes: 512
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

int mpow(int a, int b, int m) {
  if (b == 0) return 1;
  int nesf = mpow(a, b / 2, m);
  if (b % 2 == 0) {
    return nesf * nesf % m;
  }
  return a * nesf % m * nesf % m;
}

class Hash {
  public:
    const int A1 = 970592641, B1 = 1e9 + 7,
              A2 = 1e9 + 9, B2 = 970592641;
    int n;
    string s;
    vector<int> h1, h2;
    Hash(string _s) {
      s = _s;
      n = sz(s);
      h1.resize(n);
      h2.resize(n);
      compute(h1, A1, B1);
      compute(h2, A2, B2);
    }

    void compute(vector<int> &h, const int &A, const int &B) {
      h[0] = s[0];
      for (int i = 1; i < n; i++) {
        h[i] = (h[i - 1] * A + s[i]) % B;
      }
    }

    int get_h(vector<int> &h, int a, int b, const int &A, const int &B) {
      if (a == 0) {
        return h[b];
      }
      return ((h[b] - h[a - 1] * mpow(A, b - a + 1, B)) % B + B) % B;
    }
    
    int get_h1(int a, int b) {
      return get_h(h1, a, b, A1, B1);
    }

    int get_h2(int a, int b) {
      return get_h(h2, a, b, A2, B2);
    }
};
signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n;
  cin >> n;
  string s;
  cin >> s;
  Hash H(s);
  int l = 0, r = n;
  int ans = 0;
  while (l <= r) {
    int len = (l + r) / 2;
    map<int, int> mp1, mp2;
    bool found = false;
    for (int i = 0; i + len - 1 < n; i++) {
      int h1 = H.get_h1(i, i + len - 1);
      int h2 = H.get_h2(i, i + len - 1);
      bool b1 = false, b2 = false;
      if (mp1.find(h1) == mp1.end()) {
        mp1[h1] = i;
      } else if (i - mp1[h1] >= len){
        b1 = true;
      }
      if (mp2.find(h2) == mp2.end()) {
        mp2[h2] = i;
      } else if (i - mp2[h2] >= len) {
        b2 = true;
      }
      if (b1 && b2) {
        found = true;
        break;
      }
    }
    if (found) {
      ans = len;
      l = len + 1;
    } else {
      r = len - 1;
    }
  }
  cout << ans << "\n";
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((ll)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
typedef long long ll;
ll INF = 1e18;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;

int main(){
  ll X,Y,Z,K;
  cin >> X >> Y >> Z >> K;
  vector<ll> A(X),B(Y),C(Z);
  rep(i,X)cin >> A[i];
  rep(i,Y)cin >> B[i];
  rep(i,Z)cin >> C[i];
  
  vector<ll> AB;
  rep(i,X)rep(j,Y){
    AB.emplace_back(A[i]+B[j]);
  }
  sort(all(AB), greater<ll>());
  AB.resize(K);
  
  vector<ll> ABC;
  for(auto ab: AB)rep(i,Z){
    ABC.emplace_back(ab + C[i]);
  }
  
  sort(all(ABC), greater<ll>());

  rep(i,K){
    cout << ABC[i] << endl;
  }


  return 0;
}


Measured memory_bytes: 43368
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;

    int r = count(s.begin(), s.end(), 'R');
    int b = count(s.begin(), s.end(), 'B');

    if (r > b) {
        cout << "Yes" << endl;
    } else {
        cout << "No"<< endl;
    }

    return 0;
}


Measured memory_bytes: 256
from math import factorial as f
from math import sqrt as sq

n = int(input())
l = []
s = 0
for i in range(n):
	x, y = map(int, input().split())
	l.append([x, y])
p = 0
for i in range(n):
	for j in range(n):
		if i != j:
			s += (sq((l[i][0] - l[j][0])**2 + (l[i][1] - l[j][1])**2) * (n - 1))
		p += 1
print(s / (n * (n - 1)))

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
#include <chrono>
#include <fstream>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


int main() {
    ll n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;

    ll l = lcm(n, m);
    ll a = l / n, b = l / m;
    rep(i, gcd(n, m)) {
        //cout << s[b * i] << " " << t[a * i] << endl;
        if (s[b * i] != t[a * i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << l << endl;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
    
int main() {
    int N,A,B;
    cin>>N>>A>>B;
    string S;
    cin>>S;
    
    int counter_all = 0;
    int counter_b = 0;
    for (int i=0;i<N;i++) {
        if (S.at(i)=='c') cout << "No" << endl;
        else if (S.at(i)=='a' && (A+B)>counter_all) {
            cout << "Yes" << endl;
            counter_all++;
        }
        else if (S.at(i)=='b' && (A+B)>counter_all && B>counter_b) {
            cout << "Yes" << endl;
            counter_all++;
            counter_b++;
        }
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 896
function Main(input) {
  "use strict";
  const lines = input.split("\n");
  const l1 = lines[0].split(" ").map(n => parseInt(n, 10))
  const N = l1[0]
  const Y = l1[1]

  var r10000  = -1, r5000 = -1, r1000 = -1;

  for (var a = 0; a <= N; a++) {
    for (var b = 0; a+b <= N; b++) {
      var c = N  - a - b
      var total = 10000*a + 5000*b + 1000*c;
      if (total === Y) {
        r10000 = a
        r5000 = b
        r1000 = c
        break;
      }
    
    }
  }
  console.log("" + r10000 + " " + r5000 + " " + r1000)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 32460
#include<cstdio>
#include<iostream>
using namespace std;
const int MAXN=501;
int n,dp[MAXN][MAXN];
int C[MAXN],S[MAXN],F[MAXN];
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	n=read();
	for(int i=1;i<n;++i)
		{C[i]=read();S[i]=read();F[i]=read();}
	for(int i=1;i<n;++i)
	{
		int ans=0;
		for(int j=i;j<n;++j)
		{
			int temp=0;
			while(ans>S[j]+F[j]*temp) ++temp;
			ans=S[j]+F[j]*temp;
			ans+=C[j];
		}
		printf("%d\n",ans);
	}
	printf("0");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll long long
#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define endl '\n' 
#define ull unsigned long long
 
using namespace std;

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

    cin >> n ;

    int day = 0 ;

    vector <int> dp(3) ; 
    for(int day = 0 ; day < n ; day++ ){
        vector < int > new_dp(3) ; 
        vector < int > c(3) ; 
        for(int i = 0 ; i < 3 ; i++){
            cin >> c[i] ; 
        }

        for(int i = 0 ; i < 3 ; ++i){
            for(int j = 0 ; j < 3 ; ++j){
                if(i != j){
                    new_dp[j] = max(new_dp[j] , dp[i] + c[j]) ;
                }
            }
        }

        dp = new_dp ; 
    }

    cout << max(dp[0] , max(dp[1] , dp[2])) ; 
    return 0 ;
}

Measured memory_bytes: 256
N = int(input())
ans = [[0]*9 for i in range(9)]
for i in range(1,N+1):
    if i%10 == 0:
        continue
    X = str(i)
    A,B = int(X[0])-1,int(X[-1])-1
    ans[A][B]+=1
ret = 0
for i in range(9):
    for j in range(9):
        ret += ans[i][j]*ans[j][i]
print(ret)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int N;
int P[8], Q[8];

int comp(int const *p, int const *q, int n) {
    for (int i = 0; i < n; i++) {
        if (p[i] < q[i]) {
            return -1;
        } else if (p[i] > q[i]) {
            return 1;
        }
    }
    return 0;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> P[i];
    for (int i = 0; i < N; i++) cin >> Q[i];

    int ans = 0;
    int *p = P, *q = Q;

    if (comp(P, Q, N) == 1) {
        p = Q, q = P;
    }

    while (comp(p, q, N) != 0) {
        next_permutation(p, p + N);
        ans++;
    }

    cout << ans << endl;
}

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

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

	int n = N % 10;

	if (n == 3) {
		cout << "bon" << endl;
	}
	else if (n == 0 || n == 1 || n == 6 || n == 8) {
		cout << "pon" << endl;
	}
	else {
		cout << "hon" << endl;
	}

	return 0;
}

Measured memory_bytes: 3100
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int n, q, a[100001], x;
int priority(int x, int d) {
	int *low = lower_bound(a + 1, a + n + 1, x - d);
	int *upp = upper_bound(a + 1, a + n + 1, x + d);
	return upp - low;
}
int *nearest(int x) {
	int *low = lower_bound(a + 1, a + n + 1, x);
	if (low == a + 1)
		return low;
	if (low == a + n + 1)
		return low - 1;
	return (x - low[-1]) < (low[0] - x) ? low - 1 : low;
}
ll cross_c[100001], csum[100001];
int main() {
	scanf("%d %d", &n, &q);
	for (int i = 1; i <= n; i++)
		scanf("%d", a + i), cross_c[i] = csum[i] = a[i];
	cross_c[0] = csum[0] = 0;
	for (int i = 1; i <= n; i++) {
		if (0 <= i - 2)
			cross_c[i] += cross_c[i - 2];
		if (0 <= i - 1)
			csum[i] += csum[i - 1];
	}

	for (int task = 0; task < q; task++) {
		scanf("%d", &x);
		int low = nearest(x) - (a + 1);
		if ((n - 1) <= low) {
			printf("%lld\n", cross_c[n]);
			continue;
		}
		int upp = n, cen = (low + upp) / 2;
		while (2 <= upp - low) {
			if ((n - cen + 1) <= priority(x, abs(a[cen] - x)))
				upp = cen;
			else
				low = cen;
			cen = (upp + low) / 2;
		}
		ll cost = csum[n] - csum[low];
		int take = n - low;
		cost += cross_c[max(low - take, 0)];
		printf("%lld\n", cost);
	}
}

Measured memory_bytes: 3584
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
int n,i,mn[nmax],rs,mn1,mn2,mn3;
pair<int,int>a[nmax];
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i].fr>>a[i].sc;
	}
	sort(a+1,a+n+1);
	mn[0]=inf;
	for(i=1;i<=n;i++)mn[i]=min(mn[i-1],a[i].sc);
	mn2=a[n].sc;
	for(i=n-1;i>=1;i--)
	{
		mn1=a[i].sc;
		mn3=mn[i-1];
		rs=max(rs,max(min(mn2,mn3)-a[n].fr+1,0)+mn1-a[i].fr+1);
		rs=max(rs,max(min(mn1,mn3)-a[i].fr+1,0)+max(mn2-a[n].fr+1,0));
		mn2=min(mn2,a[i].sc);
	}
	cout<<rs<<endl;
	return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define INF (1<<29)
int dp[1001][1001];
int main()
{
	fill(dp[0], dp[1000], INF);
	string s1, s2; cin >> s1 >> s2;
	int s1sz = s1.size()+1, s2sz = s2.size()+1;
	for (int i = 0; i < s1sz; ++i) {
		dp[i][0] = i;
	}
	for (int j = 0; j < s2sz; ++j) {
		dp[0][j] = j;
	}
	for (int i = 1; i < s1sz; ++i) {
		for (int j = 1; j < s2sz; ++j) {
			dp[i][j] = min(dp[i - 1][j - 1] + (s1[i - 1] != s2[j - 1]), min(dp[i - 1][j] + 1, dp[i][j - 1] + 1));
		}
	}
	cout << dp[s1sz-1][s2sz-1] << endl;
}

Measured memory_bytes: 5096
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
const int limit=100010;
struct Edge{
    int to,cost;
    Edge(int to,int cost):to(to),cost(cost) {}
};
vector<Edge> tree[limit];
int depth[limit];

void dfs(int o,int k,int d){
    depth[k]=d;
    for(auto &v:tree[k]){
        if(v.to==o)continue;
        dfs(k,v.to,d+v.cost);
    }
}

signed main(){
    int N;cin>>N;
    REP(i,N-1){
        int a,b,c;cin>>a>>b>>c;a--;b--;
        tree[a].pb({b,c});
        tree[b].pb({a,c});
    }
    int Q,K;cin>>Q>>K;K--;
    dfs(-1,K,0);
    REP(i,Q){
        int x,y;cin>>x>>y;x--;y--;
        cout<<depth[x]+depth[y]<<endl;
    }
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

int res[100010];

vector<int> tree[100010];

void dfs(int v) {
	res[v] = 0;
	vector<int> children;
	for(auto u : tree[v]) {
		dfs(u);
		children.push_back(res[u]);
	}
	sort(children.rbegin(),children.rend());
	for(int i = 0;i < (int)children.size();i++) {
		res[v] = max(res[v],children[i] + i + 1);
	}
}

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

	int N,a,b;
	cin>>N;
	for(int i = 1;i < N;i++) {
		cin>>a;
		b = i;
		a--;
		tree[a].push_back(b);
	}
	dfs(0);
	cout<<res[0]<<'\n';
	return 0;
}
/**/


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

using namespace std;

int n,pp;

int main()
{
	pp=0; scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int k; scanf("%d",&k);
		pp^=(k&1);
	}
	if(pp) puts("NO"); else puts("YES");
}

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();
		n = n % 10;
		
		if (n == 3) {
			System.out.println("bon");
		} else if(n == 0 || n == 1 || n == 6 || n == 8) {
			System.out.println("pon");
		} else {
			System.out.println("hon");
		}

        sc.close();
	}
}

Measured memory_bytes: 35756
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();
		int c = sc.nextInt();

		if(a+b+c >= 22) {
			System.out.println("bust");
		}else {
			System.out.println("win");
		}
	}

}


Measured memory_bytes: 22996
from sys import stdin
import numpy as np

def main(args):
    r = int(args[0])
    d = int(args[1])
    x = int(args[2])
    ar = np.zeros([10], dtype=int)

    ar[0] = r*x-d
    for i in range(1,len(ar)):
        ar[i] = r*ar[i-1]-d

    for i in ar:
        print(i)

if __name__ == "__main__":
    main(stdin.readline().rstrip().split())

Measured memory_bytes: 20112
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define fast_io ios::sync_with_stdio(false);cin.tie(NULL);
#define input freopen("Test.txt","r",stdin)
#define output freopen("Output.txt","w",stdout);
#define what_is(x) cout<<#x<<" is "<<x<<endl;
#define F(i,a,b) for(int i = a; i < b; i++)
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define inf 1000000000
const double pi = 3.141592653589793238460;
#define debug false
#define MAXN 100010
#define mod 1000000007


void solve()
{
	int a,b;
	cin>>a>>b;
	int ans = 6-a-b;
	cout<<ans<<"\n";
}

int main()
{
     // input; // output; // if(debug){watch_is();}
    fast_io;
    solve();   
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define vl vector<ll>
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define sz size()
#define en end()
#define ro return 0
#define br break
#define con continue
#define um unordered_map<ll,ll>
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define forr(i,a,b) for(ll i=a;i<b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace2(a,b) cerr <<"a is " << a << " b is " << b << el;
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;
int main()
{
    string s , s1 = "" , s2 = "" ;
    cin >> s ;
    ll n = s.length() ;
    forn(i , 0 , n-1){
       if(i % 2) {
        s1 = s1 + "0";
       }
       else s1 = s1 + "1";
    }
    forn(i , 0 , n-1){
       if(i%2){
        s2 = s2 + "1" ;
       }
       else s2 = s2 + "0";
    }
    ll ans1 = 0, ans2 = 0 ;
    forn(i , 0 , n-1){
      if(s[i] !=s1[i]) ++ ans1;
    }
    forn(i , 0 , n-1){
       if(s[i] !=s2[i]) ++ans2 ;
    }
    cout << min(ans1 , ans2 ) ;
    cout << el ;
    ro ;
}

































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

int main(){  
    int H, N;  cin >> H >> N;
    vector<int> A(N), B(N);
    int maxA = 0;
    for(int i=0; i<N; i++){
        cin >> A[i] >> B[i];
        maxA = max(maxA, A[i]);
    }
    
    int Hmax = H + maxA + 1;
    vector<vector<int>> dp(N, vector<int>(Hmax+1, 1e9));
    for(int h=0; h<=Hmax; h++){
        dp[0][h] = (h + A[0] - 1)/A[0] * B[0];
    }

    for(int i=0; i<N-1; i++) for(int h=0; h<=Hmax; h++){
        dp[i+1][h] = dp[i][h];
        if(h-A[i+1] >= 0)
            dp[i+1][h] = min(dp[i+1][h], dp[i+1][h-A[i+1]] + B[i+1]);
    }

    int ans = 1e9;
    for(int h=H; h<=Hmax; h++){
        ans = min(ans, dp[N-1][h]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 44032
#include <bits/stdc++.h>
using namespace std;
   
int main() {
    long long n,k;
    cin>>n>>k;
    long long ans=0;
    for(long long i=k;i<=n+1;i++){
        long long com=0;
       com+=((-1)*i*i)+i+(n*i)+1;
       ans+=com;
    }
    cout<<ans%1000000007;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  ll a[N];
  ll xo = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    xo ^= a[i];
  }
  for (int i = 0; i < N; i++) {
    ll res = xo ^ a[i];
    cout << res << " ";
  }
  return 0;
}

Measured memory_bytes: 5088
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int main()
{
  int n;
  cin>>n;
  vector<int>p(n);
  for(int i=0;i<n;i++)cin>>p[i];
  int ans = 0;
  for(int i=1;i<n-1;i++){
    bool o=0,k=0;
    if(p[i] > p[i+1] || p[i] > p[i-1])o = 1;
    if(p[i] < p[i+1] || p[i] < p[i-1])k = 1;
    if(o&&k)ans++;
  }
  cout<<ans;
}

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

long long XORW(long long X){
	//cout << X << endl;
	if(X<1)return 0;
	long long ans=0;
	for(long long i=0;i<50;i++){
		long long x=X;
		long long c=0;
		c+=(x/(1LL<<(i+1)))*(1LL<<i);
		x%=(1LL<<(i+1));
		c+=max(0LL,x-(1LL<<i)+1);
		if(c%2==1)ans+=(1LL<<i);
		//cout << "i=" << i << ",c=" << c << endl;
	}
	return ans;
}

int main(){
	long long A,B;
	cin >> A >> B;
	long long ans=(XORW(B)^XORW(A-1));
	//cout << XORW(B) << "," << XORW(A-1) << endl;
	cout << ans << endl;
	return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    REP(i,n){
        cin >> vec[i];
    }
    int count = 0;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            for(int k=j+1;k<n;k++){
                if((vec[i]!=vec[j])&&(vec[j]!=vec[k])&&(vec[k]!=vec[i])){
                    int max1 = max({vec[i],vec[k],vec[j]});
                    int sum = vec[i]+vec[k]+vec[j];
                    if(2*max1-sum<0){
                        count++;
                    }
                }
            }
        }
    }
    COUT(count);
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<cstdlib>
#include<cmath>
#include <iomanip>
using namespace std;

int main(){
  int A,B,H,M;
  cin >> A >> B >> H >> M;
  double ta,tb;
  ta = 30*H+0.5*M;
  tb = 6*M;
  ta = ta-tb;
  // ta = abs(ta-tb);
  double C = sqrt(A*A + B*B - 2*A*B*cos(ta*M_PI/180));
  cout << fixed << setprecision(20) << C << endl;
  return 0;
}


Measured memory_bytes: 4076
#include<iostream>
#include<cstdio>

using namespace std;

const long long P=1000000007ll;
long long n,k,f[10001];

long long qpow(long long a,int x){
    if(x<0)return 1;
    long long s=1ll;
    while(x){if(x&1)(s*=a)%=P;(a*=a)%=P;x>>=1;}
    return s;
}

int main(){
    scanf("%lld%lld",&n,&k);
    f[0]=1ll;
    for(int i=1;i<n;++i){for(int j=i;j;--j)f[j]=(f[j+1]+f[j-1])%P;f[0]=f[1];}
    printf("%lld",f[n-k]*qpow(2ll,n-k-1)%P);
}

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

 int main() {
   ll N, ans = 0;
   cin >> N;

   if (N % 2 == 1) ans = 0;
   else {
     ll i = 5, n = N / 2;
     while (n / i > 0) {
       ans += n / i;
       i *= 5;
     }
   }

   cout << ans << endl;
 }


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

int main() {
    int n;
    std::vector<int> a;
    std::cin >> n;
    for (int i=0;i<n;i++) {
        int tmp;
        std::cin >> tmp;
        a.push_back(tmp);
    }

    for (int i=n-1;i>0;i--)
        std::cout << a[i] << " ";
    std::cout << a[0] << std::endl;
        
    return 0;
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
ll GEt_ans(ll a)
{
    if(a%4==0)return a;
    if(a%4==1)return 1;
    if(a%4==2)return a+1;
    if(a%4==3||a==0)return 0;
}
 
int main()
{
 
    long long a,b,ans=0;
    scanf("%lld%lld",&a,&b);
    if(a==0)
        printf("%lld\n",GEt_ans(b));
    else
        printf("%lld\n",GEt_ans(b)^GEt_ans(a-1));
}

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

bool isPrime(int x) {
  if (x == 2) return true;
  else if (x % 2 == 0) return false;
  else {
    for (int i = 3; i <= sqrt(x); i+=2) {
      if (x % i == 0) return false;
    }
    return true;
  }
}

int main() {
  int n;
  cin >> n;
  int A[n];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (isPrime(A[i])) count++;
  }
  cout << count << endl;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int sum = 0;
  for(int i = 0;i < 4;i++) {
    if(s.at(i) == '+') {
      sum++;
    }else {
      sum--;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005
char buf[SIZE];
int near_L[SIZE],near_R[SIZE];
int ans[SIZE];


int main(){

	scanf("%s",buf);
	int len;
	for(len = 0; buf[len] != '\0'; len++);

	for(int i = 0; i < len; i++){
		if(buf[i] == 'R'){

			near_R[i] = i;

		}else{

			near_R[i] = near_R[i-1];
		}
	}

	for(int i = len-1; i >= 0; i--){
		if(buf[i] == 'L'){

			near_L[i] = i;

		}else{

			near_L[i] = near_L[i+1];
		}
	}

	for(int i = 0; i < len; i++){

		ans[i] = 0;
	}

	for(int i = 0; i < len; i++){
		if(buf[i] == 'R'){

			if((near_L[i]-i)%2 == 0){

				ans[near_L[i]]++;

			}else{

				ans[near_L[i]-1]++;
			}

		}else{ //buf[i] == 'L'

			if((i-near_R[i])%2 == 0){

				ans[near_R[i]]++;
			}else{

				ans[near_R[i]+1]++;
			}
		}
	}

	printf("%d",ans[0]);
	for(int i = 1; i < len; i++){

		printf(" %d",ans[i]);
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
const i64 MOD = 1e9 + 7;

struct int_m {
    static int64_t mod;
    int64_t v;
    int_m() {}
    int_m(int64_t x) : v(x) {}
    int_m operator+(const int_m &y) { return (v + y.v) % mod; }
    int_m operator-(const int_m &y) { return (v - y.v + mod) % mod; }
    int_m operator*(const int_m &y) { return (v * y.v) % mod; }
    void operator+=(const int_m &y) { *this = *this + y; }
    void operator-=(const int_m &y) { *this = *this - y; }
    void operator*=(const int_m &y) { *this = *this * y; }
    friend istream &operator>>(istream &ist, int_m &m) { return ist >> m.v; }
    friend ostream &operator<<(ostream &ost, int_m &m) { return ost << m.v; }
};

int64_t int_m::mod = MOD;

int main() {
    int n, m;
    cin >> n >> m;
    vector<i64> x(n), y(m);
    for(auto &a : x) cin >> a;
    for(auto &a : y) cin >> a;
    sort(WHOLE(x)), sort(WHOLE(y));
    int_m ans = 1;
    for(int b = 0; b < 2; b++) {
        int_m S = 0;
        int_m acc = 0;
        for(int i = n - 1; i > 0; i--) {
            acc += x[i];
            S += acc - int_m((n - i) * x[i - 1]);
        }
        ans *= S;
        swap(x, y);
        swap(n, m);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;

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

vector<ll> to[100001];
map<pair<ll, ll>, int> color;
pair<ll, ll> lis[100001];
int main() {
    cin >> N;
    rep(i, N-1){
        cin >> A >> B;
        to[A].push_back(B);
        to[B].push_back(A);
        lis[i] = make_pair(A, B);
    }
    rep(i, N){
        max_value = max(max_value, (ll)to[i+1].size());
    }

    cout << max_value << endl;
    queue<pair<ll, ll>> que;
    pair<ll, ll> curr = make_pair(1, 0);
    rep(i, to[curr.first].size()){
        ll next = to[curr.first][i];
        color.emplace(make_pair(curr.first, next), (ll)(i+1));
        color.emplace(make_pair(next, curr.first), (ll)(i+1));
        que.push(make_pair(next, curr.first));
    }
    while(!que.empty()){
        curr = que.front(); que.pop();   
        int color_index = 1;
        rep(i, to[curr.first].size()){
            ll next = to[curr.first][i];
            if(color_index == color[make_pair(curr.first, curr.second)]) color_index++;
            if(next == curr.second) continue;
            color.emplace(make_pair(curr.first, next), (ll)color_index);
            color.emplace(make_pair(next, curr.first), (ll)color_index);
            que.push(make_pair(next, curr.first));
            color_index++;
        }
    }
    rep(i, N-1){
        cout << color[lis[i]] << endl;
    }
}


Measured memory_bytes: 20608
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
int main() {
    int x,y;
    cin>>x>>y;
    int p=0,q=0;
    if(x==2)p=1;
    else if(x==4||x==6||x==9||x==11)p=2;
    if(y==2)q=1;
    else if(y==4||y==6||y==9||y==11)q=2;
    cout<<(p==q?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=1e9;
const long long LINF=1e18;
#define int long long
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
//main
signed main(){
  int N;cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  int ans=0;
  std::vector<int> can(N,0);
  for(int i=N-2;i>=0;i--)if(v[i]>=v[i+1])can[i]=can[i+1]+1;
  for(int i=0;i<N;i++)ans=max(ans,can[i]);
  fin(ans);
}


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


int main(){
	long long int h=0, c;
	scanf("%lld", &c);
	while(c>4){
		if(c>=500){
			h+=1000;
			c-=500;
		}
		else if(c>4){
			h+=5;
			c-=5;
		}
	}	
	printf("%lld\n", h);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int a;
  int M = 0;
  int m = 1000000000;
  for (int i = 0; i < N; i++){
    cin >> a;
    M = max(M,a);
    m = min(m,a);
  }
  cout << M - m;
}

Measured memory_bytes: 256
#include<iostream>
#include <cmath>
#include<vector>
#define rep(i, n) for (int i=0;i<n;i++)
#include <map> 
#include<algorithm>
#include <numeric>
#include<deque>
#include<queue>
#include<string>
#include <iomanip>

using namespace std;
typedef long long ll;

int main(void){
    int n;
    cin>>n;
    vector<int> b(n);
    rep(i, n-1){
        cin>>b[i];
    }
    b[n-1]=b[n-2];
    vector<int>a(n);
    a[0]=b[0];
    rep(i, n-1){
        a[i+1]=min(b[i], b[i+1]);
    }
    
    int ans=accumulate(a.begin(), a.end(), 0);
    cout<<ans<<endl;
}

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 k = sc.nextInt();
        sc.close();
        
        double pos = 0;
        for (int i = 1; i <= n; i++) {
            if (i >= k) {
                pos +=  ((double)1 / (double)n) * (double)(n - i + 1);
                break;
            } else {
                int times = 0;
                int diceNum = i;
                while (diceNum < k) {
                    times++;
                    diceNum = diceNum * 2;
                }
                pos += ((double)1 / (double)n) * (double)Math.pow(0.5, times);
            }
        } 
        System.out.println(pos);
    }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vs= vector<string>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int n,i;
  cin >> n >> i;
  cout << n-i+1;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Map.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();

		HashMap<Integer,Integer> o=new HashMap<>(),e=new HashMap<>();
		o.put(0,0);
		e.put(0,0);

		for(int i=0;i<n;++i)
			(i%2==0?e:o).merge(s.nextInt(),1,Integer::sum);

		Comparator<Entry<Integer,Integer>> c=Entry.comparingByValue();
		Entry<Integer,Integer> O=o.entrySet().stream().max(c).get(),E=e.entrySet().stream().max(c).get();
		o.remove(O.getKey());
		e.remove(E.getKey());
		Entry<Integer,Integer> O2=o.entrySet().stream().max(c).get(),E2=e.entrySet().stream().max(c).get();

		n-=O.getKey().equals(E.getKey())
				?Math.max(O.getValue()+E2.getValue(),
						E.getValue()+O2.getValue())
				:O.getValue()+E.getValue();
		System.out.println(n);
	}
}


Measured memory_bytes: 66744
s=input()
t=input()

st=[]
ts=[]
for i in range(len(s)):
    st.append([s[i],t[i]])
    ts.append([t[i],s[i]])
#print(st)
st.sort()
ts.sort()
#print(st)
    
yesno="Yes"
for i in range(len(st)-1):
    sj,tj=st[len(st)-i-1]
    sk,tk=st[len(st)-i-2]
    if sj==sk and tj!=tk:
        yesno="No"
        break
    tj,sj=ts[len(ts)-i-1]
    tk,sk=ts[len(ts)-i-2]
    if tj==tk and sj!=sk:
        yesno="No"
        break
    
print(yesno)


Measured memory_bytes: 45468
#include <bits/stdc++.h>
using namespace std;
int n ,m;
map<int,bool>broken;
long long mem[100005];
long long mod =1e9+7;
int main() {
	cin>>n>>m;
	for(int i = 0; i < m ; i++){
		int x ;cin>>x;
		broken[x] = true;
	}
	mem[0] = 1;if(!broken[1])mem[1] = 1;
	for(int i = 2 ; i<= n; i++){
		if(broken[i])
			continue;
		mem[i]+=(mem[i-1] + mem[i-2])%mod;
	}
	cout<<mem[n];
    return 0;
}


Measured memory_bytes: 5760
#from distutils.util import strtobool
s = input()
ss = [int(s[0]) if x % 2 == 0 else int(s[0])^1 for x in range(len(s))]

cnt = 0
for i in range(len(s)):
    if int(s[i]) != ss[i]:
        cnt += 1

print(cnt)

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

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;

    vector <ll> w(n+1),b(n+1);
    ll ww=0,bb=0;
    string s2;
    w[0]=0;
    b[n]=0;
    rep(i,n){
        s2=s[i];
        if(s2=="."){
            ++ww;
        }
        w[i+1]=ww;
        s2=s[n-i-1];
        if(s2=="#"){
            ++bb;
        }
        b[n-i-1]=bb;
    }

    ll ans=n;
    rep(i,n+1){
        ans=min(ans,n-w[i]-b[i]);
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 6808
def main():
    a = int(input())
    ans = ""

    if a == 0:
        print (0)
        return 
    while a != 0:
        ans += str(int(abs(a) % 2))
        if int(abs(a)) & 1:
            a -= 1
        a /= (-2)

    print (ans[::-1])

main()


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

int main(){
	string s;
	cin>>s;
	int len=s.size();
	int ans1=0,ans2=0;
	for(int i=0;i<len;i++){
		if(i%2==0&&s[i]!='0'){
			ans1++;
		}
		if(i%2==1&&s[i]!='1'){
			ans1++;
		}
		if(i%2==0&&s[i]!='1'){
			ans2++;
		}
		if(i%2==1&&s[i]!='0'){
			ans2++;
		}
	}
	cout<<min(ans1,ans2)<<endl;
	
	return 0;
}

Measured memory_bytes: 512
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    private static FastScanner sc = new FastScanner();
    private static long mod = 1000000007;

    public static void main(String[] args) {
    	int N = sc.nextInt();
    	int M = sc.nextInt();
    	int[] S = new int[N];
    	for(int i=0; i<N; i++) {
    		S[i] = sc.nextInt();
    	}
    	int[] T = new int[M];
    	for(int i=0; i<M; i++) {
    		T[i] = sc.nextInt();
    	}
    	long[][] dp = new long[N+1][M+1];
    	long[][] ans = new long[N+1][M+1];
    	for(int i=1; i<=N; i++) {
    		for(int j=1; j<=M; j++) {
    			if(S[i-1] == T[j-1]) {
    				ans[i][j] = (1 + dp[i-1][j-1]) % mod;
    			}
    			dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + ans[i][j] + mod) % mod;

    		}
    	}

    	long sum = 0;
    	for(int i=1; i<=N; i++) {
    		for(int j=1; j<=M; j++) {
    			sum = (sum + ans[i][j]) % mod;
    		}
    	}
    	sum = (sum + 1) % mod;
    	System.out.println(sum);
    }

    static long power(long m , long n){
    	if(n == 0) {
    		return 1;
    	}else if(n == 1){
            return m;
        }else if(n % 2 == 0){
            long s = power(m, n/2);
            return ( (s % mod) * (s % mod) ) % mod;
        }else{
            return ( (m % mod) * (power(m, n-1) % mod) ) % mod;
        }
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 131540
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

/*-- template --*/

int main() {
    int N; cin >> N;
    ll creatures[N];
    rep(i, N) cin >> creatures[i];
    sort(creatures, creatures + N);
    ll sum_creatures[N];
    sum_creatures[0] = creatures[0];
    rep(i, N - 1)sum_creatures[i + 1] = sum_creatures[i] + creatures[i + 1];
    if(creatures[1] <= 2 * creatures[0])
        sum_creatures[0] += creatures[1];
    int ans = 1;
    rep(i, N - 1) {
        if(creatures[N - i - 1] <= 2 * sum_creatures[N - i - 2]) {
            ++ans;
        }else {
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1920
H,W = map(int,input().split())
INF = float("inf")
c = []
for i in range(10):
  temp = list(map(int,input().split()))
  c.append(temp)

#d = [[INF]*10 for _ in range(10)]
#print(c)
for k in range(10):
  for i in range(10):
    for j in range(10):
      c[i][j] = min(c[i][j],c[i][k] + c[k][j])
#print(c)
ans = 0
for i in range(H):
  temp = list(map(int,input().split()))
  for j in range(W):
    if temp[j] == -1:
      continue
    ans += c[temp[j]][1]
print(ans)
    

Measured memory_bytes: 73508
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
int getDigit( long long n )
{
	int cnt = 0;
	while ( n >= 10 )
	{
		n /= 10;
		cnt++;
	}
	return cnt+1;
}
int main( void )
{
	int n;
	cin >> n;

	for ( int lpc = 0; lpc < n; lpc++ )
	{
		long long s;
		cin >> s;

		cout << "Case " << lpc+1 << ":" << endl;
		for ( int i = 0; i < 10; i++ )
		{
			int d = getDigit( s );
			s *= s;
			ostringstream os;
			os << setfill('0') << setw(8) << s << endl;
			string s_str = os.str();
			string s_next;
			s_next = s_str.substr( 2, 4 );
			istringstream is( s_next );
			is >> s;
			cout << s << endl;
		}

	}

	return 0;
}

Measured memory_bytes: 0