akhauriyash/Code-Regression huggingface dataset:
package main

import "fmt"

func main() {
	var c string
	fmt.Scan(&c)
	const alphabet = "abcdefghijklmnopqrstuvwxyz"
	for i := 0; i < len(alphabet); i++ {
		if c == string(alphabet[i]) {
			fmt.Println(string(alphabet[i+1]))
			break
		}
	}
}


Measured memory_bytes: 512
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define MOD 1000000007
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
template<typename T> inline T gcd(T&a,T&b){return b==0?a:gcd(b,a%b);}
template<typename T> inline T lcm(T&a,T&b){return a/gcd(a,b)*b;}
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
string s1,s2;
void init(){}
int main(){
	cin>>s1;
	s2=s1;
	reverse(s2.begin(),s2.end());
	if (s1==s2) puts("Yes");
	else puts("No");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")
#define MINS(a,b) a = min(a,(decltype(a))(b))
#define MAXS(a,b) a = max(a,(decltype(a))(b))

ll L, A, B, M;

ll pow10(int x) {
	ll ans = 1;
	REP(i, 0, x)ans *= 10LL;
	return ans;
}

using mat = array<array<ll, 3>, 3>;
using vec = array<ll, 3>;
mat dot(const mat& m1, const  mat& m2) {
	mat dst;
	REP(i, 0, 3)REP(j, 0, 3) dst[i][j] = 0;
	REP(i, 0, 3)REP(j, 0, 3) {
		REP(k, 0, 3) dst[i][j] = (dst[i][j] + m1[i][k] * m2[k][j]) % M;
	}
	return dst;
}
vec dot(const mat& m1, const vec& v2) {
	vec dst;
	REP(i, 0, 3) dst[i] = 0;
	REP(i, 0, 3) REP(j, 0, 3) {
			dst[i] = (dst[i] + m1[i][j] * v2[j]) % M;;
	}
	return dst;
}


int main() {
	cin >> L >> A >> B >> M;
	auto f = [&](vec v, ll p, ll c) {
		mat tmp = { array<ll,3>{pow10(p)%M,1,0},array<ll,3>{0,1,B},array<ll,3>{0,0,1} };
		mat buf = { array<ll,3>{1,0,0},array<ll,3>{0,1,0},array<ll,3>{0,0,1} };
		while (c > 0) {
			if ((c & 1) == 1) buf = dot(tmp, buf);
			tmp = dot(tmp, tmp);
			c >>= 1;
		}
		v = dot(buf, v);
		return v;
	};
	vec v = { 0, A, 1 };
	REP(i, 1, 19) {
		ll I = min(L, max(0LL, (pow10(i - 1) - A + B - 1) / B));
		ll J = max(0LL, min(L, (pow10(i) - A + B - 1) / B));
		v = f(v, i, J - I);
	}
	PRI(v[0]);
	return 0;
}




Measured memory_bytes: 3616
import sys
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
aint = lambda: int(input())

n = aint()
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')
a = 0
if n<4:
    print(0)
else:
    for i in range(len(s)-2):
        for j in range(int(0.5*(len(s)-i-1))):
            if s[i]!=s[i+j+1] and s[i+j+1]!=s[i+2*j+2] and s[i]!=s[i+2*j+2]:
                a += 1
    print(r*g*b-a)

Measured memory_bytes: 9468
N = int(input())
X = list(map(int, input().split()))
ptc = 0
tc = 100**2*100
for i in range(min(X), max(X)+1):
    for k in X:
        ptc += (k-i)**2
    tc = min(ptc,tc)
    ptc = 0
print(tc)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll>h(n);
    ll answer = 10000000000;
    REP(i,n)cin >> h[i];
    SORT(h);
    REP(i,n-k+1){
        answer = min(h[i+k-1]-h[i],answer);
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 1024
package main

import (
        "fmt"
        "bufio"
        "os"
        "strings"
        "strconv"
)

var (
        qset []int
        setnum int
)

func main(){
        //read item number
        fmt.Scan(&setnum)

        //read array, set into strset
        scanner := bufio.NewScanner(os.Stdin)
        scanner.Scan()
        strset := strings.Fields(scanner.Text())

        //save array data into []int array
        qset = make([]int,setnum)

        for i := 0 ; i<len(strset); i++ {
                qset[i] ,_ = strconv.Atoi(strset[i])
        }

        showQueue(qset)


        for i := 1 ; i<len(qset); i++ {
                key := qset[i]
                j := i-1

                for (j>=0) && (qset[j] > key) {
                        qset[j+1] = qset[j]
                        j--
                }

                qset[j+1] = key

                //print qset for each step
                showQueue(qset)
        }
}

//convert []int -> []string, and print (delimiter= )
func showQueue(qset []int){
        printstr := make([]string,len(qset))
        for i := 0 ; i<len(qset); i++ {
                printstr[i]= strconv.Itoa(qset[i])
        }

        fmt.Println(strings.Join(printstr," "))
}


Measured memory_bytes: 1444
import java.util.Scanner;

//2018-04-08
public class Main {
/**
 public static void main(String[] args){
     Scanner sc = new Scanner(System.in);
     int r = sc.nextInt()*100;
     int b = sc.nextInt()*10;
     int g = sc.nextInt()*1;

     int rbg = r+b+g;
     String ans = null;

     if(rbg%4!=0){
         ans = "NO";
     }else{
         ans ="YES";
     }
     System.out.println(ans);
 }
*/
 public static void main(String[] args){
     Scanner sc = new Scanner(System.in);

     String r = sc.next();
     String g = sc.next();
     String b = sc.next();

     String s = r + g + b;
     int rbg = Integer.parseInt(s);

     String ans = null;

     if(rbg%4!=0){
         ans = "NO";
     }else{
         ans ="YES";
     }
     System.out.println(ans);
 }
}



Measured memory_bytes: 23764
import math

def merge(a,l,m,r):
    global cnt
    L = a[l:m]+[math.inf]
    R = a[m:r]+[math.inf]
    i = 0
    j = 0
    for k in range(l,r):
        cnt+=1
        if L[i]<=R[j]:
            a[k] = L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
def mergeSort(a,l,r):
    if l+1<r:
        m = (l+r)//2
        mergeSort(a,l,m)
        mergeSort(a,m,r)
        merge(a,l,m,r)
n = int(input())
a = list(map(int, input().split()))
cnt = 0

mergeSort(a,0,n)
print(*a)
print(cnt)


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

int main() {
  int n;
  string s;
  cin>>s;
  n=s.size();
  int b=0;
  int w=0;
  for(int i=0;i<n;i++){
    if(s[i]=='0')w++;
    else b++;
  }

  cout<<min(b,w)*2<<endl;
  return 0;
  
}

Measured memory_bytes: 512
#include <iostream>

#define N_MAX 100

using namespace std;

int bubbleSort(int* A, const int N);

int main() {
	ios::sync_with_stdio(false);

	int N, A[N_MAX], swapCount;
	swapCount = 0;
	
	cin >> N;
	for(int i = 0; i < N; ++i) {
		cin >> A[i];
	}

	swapCount = bubbleSort(A, N);

	for(int i = 0; i < N; ++i){
		cout << A[i] << (N - 1 == i ? "\n" : " ");
	}
	cout << swapCount << endl;
	return 0;
}

int bubbleSort(int* A, const int N){
	int swapCount = 0;
	bool flag = true;
	while(flag){
		flag = false;
		for(int i = N - 1; i > 0; --i){
			if(A[i] < A[i-1]){
				swap(A[i], A[i - 1]);
				swapCount++;
				flag = true;
			}
		}
	}
	return swapCount;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX




 
void solve()
{
    int n;
    cin >> n;
    int arr[n];
    inp(arr, n);
    int c[n+1] = {0};
    rep(i,0,n-1)
        c[arr[i]]++;
    int ans = 0;
    rep(i,1,n)
        ans += (c[i]*(c[i]-1))/2;

    rep(i,0,n-1)
    {
        cout << ans-c[arr[i]]+1 << endl;
    }

}   


signed main()
{


  
    
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <queue>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    int h = 100;
    int w = 100;
    int grid[100][100];
    REP(i, 100) {
        REP(j, 100) {
            if (j < 50) {
                grid[i][j] = 0;
            }
            else {
                grid[i][j] = 1;
            }
        }
    }
    REP(i, a - 1) {
        grid[2 * (i % 50)][2 * (i / 50)] = 1;
    }
    REP(i, b - 1) {
        grid[2 * (i % 50)][51 + 2 * (i / 50)] = 0;
    }
    cout << h << " " << w << endl;
    REP(i, 100) {
        REP(j, 100) {
            if (grid[i][j] == 0) {
                cout << "#";
            }
            else {
                cout << ".";
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A=0;
  cin >> N;
  int x,sum=0;
  cin >> x;
  
  while(x % 2 == 0){
    sum++;
    x = x/2;
  }
  
  A = sum;
  
  for(int i=0;i<N-1;i++){
    cin >>x;
    sum=0;
    
    while(x % 2 == 0){
	  sum++;
      x = x/2;  
	}
  if(sum<A)
    A=sum;
  }
 
  cout << A << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define SUM(v) accumulate(v.begin(),v.end(),lli(0))
#define rev(n,d) for(int i=n;i>=d;i--)
#define FOR0(n) for(int i=0;i<n;i++)
#define FOR(a,n) for(int i=a;i<n;i++)
#define FORQ(a,n) for(int i=a;i<=n;i++)
#define inf 1000000009
#define inff 0x3f3f3f3f
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define mem(ar,x) memset(ar,x,sizeof ar)
#define present(container, element) (container.find(element) != container.end())
#define max3(a,b,c) return (lli(a)>lli(b)?(lli(a)>lli(c)?a:c):(lli(b)>lli(c)?b:c))
#define max4(a,b,c,d) return (max3(a,b,c)>lli(d)?(max3(a,b,c)):d)
#define min3(a,b,c) return (lli(a)<lli(b)?(lli(a)<lli(c)?a:c):(lli(b)<lli(c)?b:c))
#define min4(a,b,c,d) return (max3(a,b,c)<lli(d)?(max3(a,b,c)):d)
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<int,pii>ppii;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<pii>vpii;
const int N=100005;
int dr8[]={0,0,1,-1,1,1,-1,-1};
int dc8[]={1,-1,0,0,-1,1,-1,1};
int dr4[]={0,1,-1,0};
int dc4[]={1,0,0,-1};
int main(){
	fast
	int n;
	cin>>n;
	double p[n+1],q[n+1];
	FOR0(n){ cin>>p[i+1];q[i+1]=1-p[i+1];}
	double dp[n+5][n+5];
	mem(dp,0);
	dp[1][1]=p[1];
	dp[1][0]=q[1];
	for(int i=2;i<=n;i++){
		for(int j=0;j<=n;j++){
			if(j==0){
				dp[i][j]=dp[i-1][j]*q[i];
			}
			else{
				dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*q[i];
			}
		}
	}
	int h=(n/2)+1;
	double ans=0;
	for(int i=h;i<=n;i++){
		ans+=dp[n][i];
	}
	cout<<setprecision(15)<<ans;
}



Measured memory_bytes: 70784
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define vi vector<int>
#define fi first
#define se second 
#define mp make_pair
#define show(x) cout<<#x<<" = "<<x<<endl;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define LL long long 
#define pi acos(-1)
#define fin freopen("in","r",stdin);
const int inf=0x3f3f3f3f;
const double eps=1e-8;
#define zero(x) (((x)>0?(x):-(x))<eps)
#define _sign(x) ((x)>eps?1:((x)<-eps?2:0))
typedef long long ll;
const int maxn = 10000005, mod = 1e9+7;
#define fin freopen("in","r",stdin);
string s[101];
int n;
vector<int> v(maxn,1);
vector<ll> p;
int main(){
	int a,b;
	cin>>a>>b;
	if(a!=b)cout<<2*max(a,b)-1<<endl;
	else cout<<a+b<<endl;
	return 0;
}

Measured memory_bytes: 39296
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		if (s.equals("AAA") || s.equals("BBB")) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
		sc.close();
	}
}


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

using namespace std;

string s;

int main(void)
{
	cin >> s;
	
	int cnt0 = 0, cnt1 = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == '0') cnt0++;
		else cnt1++;
	}
	cout << min(cnt0, cnt1) * 2 << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;

int MOD = 998244353;

struct edge{
    int from;
    int to;
    int cost;
};
int n,m;
int d[2510];

signed main(){
    vector<edge> es;

    int n,m,p;
    cin >> n >> m >> p;
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        edge e1 = {a-1,b-1,p-c};
        es.push_back(e1);
    }

    fill(d,d+n,INF);
    d[0] = 0;
    rep(i,n){
        rep(j,m){
            struct edge e = es[j];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                if(i == n-1)d[e.to] = -INF;
            }   
        }
    }
    rep(i,n){
        rep(j,m){
            struct edge e = es[j];
            if(d[e.from] == -INF){
                d[e.to] = -INF;
            }
        }
    }

    // rep(i,n){
    //     cerr << i << " : ";
    //     if(d[i] == -INF)cerr << "-INF" << endl;
    //     else cerr << d[i] << endl;
    // }
    if(d[n-1] == -INF)cout << -1 << endl;
    else cout << max(-d[n-1],0LL) << endl;
    
    
    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc137.contest.atcoder.jp/tasks/abc137_b


Measured memory_bytes: 576
#include<iostream>
#include<string>
#include<cctype>
using namespace std;

string toUpper(string s){
    string t = s;
    for(int i = 0; i < s.size(); i++){
        t[i] = toupper(s[i]);
    }
    return t;
}

int main(){
    string str, order, p;
    int n = 0, a = 0, b = 0;
    cin >>str >>n;
    for(int i =0; i<n; i++){
        cin >>order >>a >>b;
        if(order == "print") cout << str.substr(a, b - a + 1) << endl;
        else if(order == "reverse"){
            string tmp = str.substr(a, b - a + 1);
            int t = tmp.size();
            for(int j =0;j < t;j++) str[j+a] = tmp[t - j -1];
        }
        else if(order == "replace"){
            cin >>p;
            str.replace(a, b - a + 1, p);
        }
    }

    return 0;
}


Measured memory_bytes: 3176
#include <stdio.h>

int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	
	if(a+b<24){
		printf("%d\n",a+b);
	}else if(a+b>=24){
		printf("%d\n",a+b-24);
	}
	
	return 0;
}
	

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

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  i64 n, h, a = 0;
  vector<i64> b(1, 0);
  cin >> n >> h;
  for (i64 i = 0; i < n; ++i) {
    i64 x, y;
    cin >> x >> y;
    a = max(a, x);
    b.push_back(y);
  }
  sort(begin(b), end(b));
  i64 ans = 0;
  while (h > 0) {
    if (b.back() > a) {
      h -= b.back();
      b.pop_back();
      ++ans;
    } else {
      break;
    }
  }
  for (; h > 0; h -= a, ++ans);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1528
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N, M;
int A[100011], B[100011];
int depth[100011];
int odd[100011];
VI G[100011];


void MAIN() {
    scanf("%d%d", &N, &M);
    REP (i, M) {
	int x, y;
	scanf("%d%d", &x, &y);
	x--; y--;
	A[i] = x;
	B[i] = y;
	G[x].push_back(i);
	G[y].push_back(i);
    }

    memset(depth, -1, sizeof depth);
    VI ord;
    ord.push_back(0);
    depth[0] = 0;
    REP (i, N) {
	int v = ord[i];
	EACH (e, G[v]) {
	    int w = A[*e]^B[*e]^v;
	    if (depth[w] == -1) {
		depth[w] = depth[v] + 1;
		ord.push_back(w);
	    }
	}
    }

    REP (i, N) {
	int v = ord[N-1-i];
	EACH (e, G[v]) {
	    int w = A[*e]^B[*e]^v;
	    if (depth[w] == depth[v] + 1) {
		if (odd[w]) {
		    A[*e] = w;
		    B[*e] = v;
		    odd[w] ^= 1;
		} else {
		    A[*e] = v;
		    B[*e] = w;
		    odd[v] ^= 1;
		}
	    } else if (depth[w] == depth[v] && v < w) {
		A[*e] = v;
		B[*e] = w;
		odd[v] ^= 1;
	    }
	}
    }

    if (*max_element(odd, odd+N) == 0) {
	REP (i, M) printf("%d %d\n", A[i]+1, B[i]+1);
    } else {
	puts("-1");
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 8956
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()
#define INPUT1(var) FOR(i,countof(var)) var[i] = ri() - 1

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
  int a = ri();
  int b = ri();
  cout << ((a%2 && b%2)?"Yes":"No") << endl;
  
  return 0;
}


Measured memory_bytes: 256
def create_List():
	re_list = [[],[],[],[]]
	for i in range(4):
		for j in range(3):
			re_list[i].append([0 for k in range(10)])
	return re_list

# ????????§??¨?????????????????§????????¨????????????(??????)
num = create_List()
for _ in range(int(input())):
	data = list(map(int,input().split()))
	num[data[0]-1][data[1]-1][data[2]-1] += data[3]

# ????????????
for i in range(4):
	for j in range(3):
		print(' ' + ' '.join(map(str,num[i][j])))
	if i == 3:
		break
	print('#'*20)

Measured memory_bytes: 7704
#include<iostream>

using namespace std;

int main(){
  int a,b,c,d = 0;
  cin >> a >> b >> c;
  for(;a <= b;++a){
    if(c % a == 0){
      ++d;
    }
  }
  cout << d << endl;  
  return 0;
}
 



Measured memory_bytes: 3088
N=int(input())
A=list(map(int,input().split()))

DPLIST=[[None]*N for i in range(N)]

for i in range(N):
    DPLIST[i][i]=[0,A[i]]

for i in range(1,N):
    for j in range(i,N):
        #print(i,j)
        ANS=float("inf")
        slime=float("inf")

        for k in range(j-i,j):
            sc1,sl1=DPLIST[j-i][k]
            sc2,sl2=DPLIST[k+1][j]

            if ANS>sc1+sc2+sl1+sl2:
                ANS=sc1+sc2+sl1+sl2
                slime=sl1+sl2
        
        DPLIST[j-i][j]=[ANS,slime]

    #print(DPLIST)
    #print()
            

print(DPLIST[0][N-1][0])

Measured memory_bytes: 50652
n, m = list(map(int, input().split()))

graph = [[] for i in range(n)]

for i in range(m):
    l, r, d = list(map(int, input().split()))
    graph[l-1].append([r-1, d])
    graph[r-1].append([l-1, -d])



def func():
    x = [None for i in range(n)]
    for i in range(n):
        if x[i] == None:
            x[i] = 0
            q = [i]
        while q:
            j = q.pop()
            for k, d in graph[j]:
                if x[k] == None:
                    q.append(k)
                    x[k] = x[j] + d
                elif x[k] != x[j] + d:
                    return False
    return True

if func():
    print('Yes')
else:
    print('No')

Measured memory_bytes: 77432
def print_format(N,input_list, count):
    for i in range(N):
        if i != N-1:
            print(input_list[i],end=" ")
        else :
            print(input_list[i])
    print(count)
def bubble_sort(N,input_list):
    count = 0
    flag = True
    while flag:
        flag = False
        for j in range(1,N)[::-1]:
            if input_list[j] < input_list[j-1]:
                input_list[j],input_list[j-1] = input_list[j-1],input_list[j]
                count += 1
                flag = True
    return input_list, count

def main():
    N = int(input())
    input_list = [int(i) for i in input().split()]
    input_list,count = bubble_sort(N,input_list)
    print_format(N,input_list,count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 5608
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime> 
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	int n, m, k;
	cin >> n >> m >> k;
	for (int f = 0; f <= n; f++) {
		for (int s = 0; s <= m; s++) {
			if (f * m + s * n - 2 * f * s == k) {
				cout << "Yes\n";
				return 0;
			}
		}
	}
	cout << "No\n";
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

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

main()
{
   int N; cin >> N;
   V<int> a(N);
   for (int i = 0; i < N; i++) {
      cin >> a[i];
   }

   sort(a.begin(), a.end());
   if (a[N-1] - a[0] == 0) {
      if (a[0] == N-1 || a[0] <= N/2) {
         cout << "Yes" << endl;
         return 0;
      }
   }
   if (a[N-1] - a[0] == 1) {
      int A = lower_bound(a.begin(), a.end(), a[N-1]) - a.begin();
      int B = N - A;
      if (A+1 <= a[0]+1 && a[0]+1 <= A + B/2) {
         cout << "Yes" << endl;
         return 0;
      }
   }
   cout << "No" << endl;
}


Measured memory_bytes: 1024
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);
        if (B % A == 0)
            Console.WriteLine(A + B);
        else
            Console.WriteLine(B - A);
    }
}


Measured memory_bytes: 11092
#include <iostream>

using namespace std;

typedef long long int ll;

void func(ll n)
{
	if (n == 0) return;

	n--;
	func(n / 26);
	cout << char('a' + n % 26);
}

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

	ll num;
	cin >> num;
	func(num);
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <numeric>
#include <string>
#include <map>
#include <queue>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;
typedef long long ll;
const ll INF = 1e12;

int pow(int a,int b){
        int sum =1;
        for(int i=0; i<b; i++){
                sum *= a;
        }
        return sum;
}

int main(){
        int X;
        cin >> X;
        int n=2;
        int AllCount=1;
        int Count;
        while(pow(2,n)<=X){

                for(int i=0; pow(i,n)<=X; i++){
                        Count = i;
                }
                if(pow(Count,n)> AllCount) AllCount = pow(Count ,n);
                n++;
        }
        cout << AllCount;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import *

K, A, B = map(int, input().split())

if A>=B:
    print(K+1)
else:
    if B-A==1:
        print(K+1)
    else:
        if A-1>=K:
            print(K+1)
        else:
            rem = K-(A-1)
            ans = A+(B-A)*(rem//2)
            
            if rem%2==1:
                ans += 1
            
            print(ans)

Measured memory_bytes: 38384
module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";var n=r(1);r(2)(n.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,r){"use strict";var n=r(3),i=r(5);t.exports=function(t){var e=new n(t);i(e)}},function(t,e,r){"use strict";var n=r(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new n(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,r){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,r){"use strict";t.exports=function(t){for(var e=t.in(),r=t.in(),n=t.in(),i=new Array(r),o=0;o<r;o++)i[o]=t.in();for(var s=0,u=0;u<e;u++){for(var c=n,f=0;f<r;f++){c+=t.in()*i[f]}c>0&&s++}console.log(s)}}]);


Measured memory_bytes: 7756
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip()
    ls = len(s)
    t = input().rstrip()
    lt = len(t)
    alphabet = 'abcdefghijklmnopqrstuvwxyz' #26
    dic = {}
    for i in range(26):
        dic[alphabet[i]] = i
    moji = [[] for _ in range(26)]
    for i in range(ls):
        moji[dic[s[i]]].append(i+1)
    
    cnt = 0
    res = 0
    while cnt < lt:
        for i in range(cnt, lt):
            if not moji[dic[t[i]]]:
                print(-1)
                exit()
            if i == cnt:
                now = moji[dic[t[i]]][0] + 1
            else:
                nex = bisect_left(moji[dic[t[i]]], now)
                if nex == len(moji[dic[t[i]]]):
                    res += ls
                    cnt = i
                    break
                now = moji[dic[t[i]]][nex] + 1
        else:
            res += now - 1
            break
    print(res)

if __name__ == '__main__':
    main()

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

int main() {
	string s,t,u;
	cin >> s >>t>>u;
	char c1,c2,c3;
	c1 = s.at(0);
	c2 = t.at(0);
	c3 = u.at(0);
	cout << c1 << c2 << c3 << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())

if n <= 111:
    print(111)
if n > 111 and n <= 222:
    print(222)
if n > 222 and n <= 333:
    print(333)
if n > 333 and n <= 444:
    print(444)
if n > 444 and n <= 555:
    print(555)
if n > 555 and n <= 666:
    print(666)
if n > 666 and n <= 777:
    print(777)
if n > 777 and n <= 888:
    print(888)
if n > 888 and n <= 999:
    print(999)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
	string S;
	cin >> S;
	if (S.size() % 2) {
		cout << "No";
		return 0;
	}
	else {
		for (int i = 0; i < S.size(); i += 2) {
			if (S[i] != 'h' || S[i + 1] != 'i') {
				cout << "No";
				return 0;
			}
		}
		cout << "Yes";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define pb push_back
#define int long long
#include <iostream>
 
signed main(){
    int n;
    int count=0;
    int count_tmp=0;
    cin>>n;
 
    int a[n];
 
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
 
    for(int i=0;i<n;i++){
        if(a[i]%4==0)count++;
        if(a[i]%2==0&&a[i]%4!=0)count_tmp++;
    }
 
    // count+=count_tmp/2;

    if(count_tmp==n){
        cout<<"Yes"<<endl;
        return 0;
    }
 
    if(count==0){
        cout<<"No"<<endl;
        return 0;
    }
    // cout<<n/2<<" "<<count<<endl;
    
    if(count_tmp==0){
 
        if(n/2<=count){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }else{
        int tmp=n-count*2;
 
        if(tmp-count_tmp>0){
            cout<<"No"<<endl;
        }else{
            cout<<"Yes"<<endl;
        }
    }
}

Measured memory_bytes: 1024
from math import floor, ceil
n = int(input())
data = list(map(int, input().split()))
avg = sum(data)/float(n)
y1 = floor(avg)
y2 = ceil(avg)
f = sum((x-y1)**2 for x in data)
c = sum((x-y2)**2 for x in data)
print(min(f, c))

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

using namespace std;
using ll = long long;
using ld = long double;

const int MOD = 1e9 + 7;
int power (int n, int k) {
	int res = 1;

	while (k) {
		if (k % 2) res = (res * 1LL * n) % MOD;
		n = (n * 1LL * n) % MOD;
		k /= 2;
	}

	return res;
}

int main () {
	int n;
	cin >> n;
	int sol = power(10, n);
	sol = (sol - ((2 * power(9, n)) % MOD) + MOD) % MOD;
	sol = (sol + power(8, n)) % MOD;
	cout << sol << '\n';
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//===

//const ll mod = static_cast<int>(1e9 + 7);



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

	Vi H(N);
	for (int i = 0; i < N; ++i) {
		cin >> H[i];
	}

	bool ok = true;

	for (int i = N - 2; i >= 0; --i) {
		if (H[i] > H[i + 1]) {
			--H[i];
		}
		if (H[i] > H[i + 1]) {
			ok = false;
			break;
		}
	}

	cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Test
{
    public static void Main()
    {
        while (true)
        {
            string[] str = Console.ReadLine().Split(' ');
            int h = int.Parse(str[0]);
            int w = int.Parse(str[1]);
            if (h == 0 && w == 0)break;
            
            for(int i= 0; i < h; ++i)
            {
               
                for (int j = 0; j < w; ++j)
                {
                    if ((i+j)%2==0)
                    {
                        Console.Write("#");
                    }
                    else
                        Console.Write(".");

                }



                Console.Write("\n");

            }
            Console.Write("\n");
        }
        return ;
    }
}


Measured memory_bytes: 15932
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        
        int count = 0;
        for (int i=0; i<S.length(); i++) {
            if (S.charAt(i) == T.charAt(i)) {
                count ++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)

using ll = long long;

constexpr long long INFL = LLONG_MAX / 2;


class SegTree {
public:
	int n;	// 葉の数
	vector<ll> dat;	// 各ノードの値
	
	ll def = INFL;	// デフォルト値（零元）
	
	// 区間クエリを決める関数
	ll operation(ll a, ll b) {
		return min(a, b);
	}

	// 初期化（n_は必要な要素数）
	SegTree(int n_) {
		n = 1;
		while (n < n_) {
			n *= 2;
		}
		dat = vector<ll>(2 * n - 1, def);
	}

	// 場所i(0-indexed)の値をxに更新
	void change(int i, ll x) {
		i += n - 1;
		dat[i] = x;
		while (i > 0) {
			i = (i - 1) / 2;
			dat[i] = operation(dat[i * 2 + 1], dat[i * 2 + 2]);
		}
	}

	// 場所i(0-indexed)の値を返す
	ll at(int i) {
		return dat[i + n - 1];
	}

	// 区間[a,b)の値。ノードk=[l,r)に着目している。
	ll _query(int a, int b, int k, int l, int r) {
		if (b <= a) return def;	// 不正な区間の指定
		if (r <= a || b <= l)return def;  // 交差しない
		if (a <= l && r <= b)return dat[k];   // a,l,r,bの順で完全に含まれる
		else {
			ll c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2);    // 左の子
			ll c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r);    // 右の子
			return operation(c1, c2);
		}
	}

	// 内部クエリ_query()を呼び出す
	ll query(int a, int b) {
		return _query(a, b, 0, 0, n);
	}
};

int main(void) {
	int N, Q, A, B;
	cin >> N >> Q >> A >> B;
	A--; B--;	// 座標を0-indexedに変更する
	vector<int> x(Q + 1);

	x[0] = A;	// 計算しやすいよう、0番目のクエリの値をAにする
	rep(i, Q) {
		cin >> x[i + 1];
		x[i + 1]--;		// 座標を0-indexedに変更する
	}

	// 左側担当と右側担当のセグ木を用意
	SegTree dpl(N);	// dp[i]-i を格納
	SegTree dpr(N);	// dp[i]+i を格納

	// dp[B] = 0, dp[他] = ∞
	dpl.change(B, 0 - B);
	dpr.change(B, 0 + B);

	// 全要素に一律に足す値
	ll add = 0;

	repr(q, 1, Q + 1) {
		// 一律に足す値
		int diff = abs(x[q] - x[q - 1]);
		add += diff;

		// 更新すべきはdp[x[q-1]]のみ

		// 新しい値を計算
		// dplの区間 [0, x[q]) 、dprの区間 [x[q], N) の最小値をx[q]で補正した値の小さい方）
		ll newval = min(dpl.query(0, x[q]) + x[q],
						dpr.query(x[q], N) - x[q]);

		// diffを足すことを考慮して、[真の値-diff]に更新
		dpl.change(x[q - 1], newval - diff - x[q - 1]);
		dpr.change(x[q - 1], newval - diff + x[q - 1]);
	}

	// 最小コストの計算
	ll ans = INFL;
	rep(i, N) {
		// dp[i]の値は、dpl[i]+i か dpr[i]-i のどちらでも計算できる
		ans = min(ans, dpl.at(i) + i);
	}

	// 全体に足す値を足して答えを出力
	cout << ans + add << endl;

	return 0;
}


Measured memory_bytes: 9344
import sys
from collections import defaultdict
sys.setrecursionlimit(100000)

N, M = map(int, input().split())
AB = []
D = defaultdict(lambda: [])
for i in range(N + M - 1):
    a, b = map(int, input().split())
    AB.append((a - 1, b - 1))
    D[a - 1].append(b - 1)

z = [0]*N
for a, b in AB:
    z[b] += 1

ans = [-1]*N
root = z.index(0)
ok = [False]*N
def rec(u, p):
    ans[u] = p
    ok[u] = True
    for v in D[u]:
        z[v] -= 1
    for v in D[u]:
        if z[v] == 0 and not ok[v]:
            rec(v, u)


rec(root, -1)

for i in range(N):
    print(ans[i] + 1)


Measured memory_bytes: 201956
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=(ll)a-1;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<26;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j=0,N,K;
  string s,ans="";
  cin>>s;
  N=s.size();
  vec term(1,N),ch(26,0);
  brep(i,N){
    j|=1LL<<(s[i]-'a');
    if(j+1==inf){
      j=0;
      term.pb(i);
    }
  }
  K=term.size();
  rep(i,term[K-1]){
    ++ch[s[i]-'a'];
  }
  N=0;
  while(ch[N])++N;
  ans+='a'+N;
  reverse(all(term));
  rep1(i,K){
    rep(j,26)ch[j]=0;
    j=term[i-1];
    while(s[j++]-'a'!=N);
    while(j<term[i])++ch[s[j++]-'a'];
    N=0;
    while(ch[N])++N;
    ans+='a'+N;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
using namespace std;
typedef long long ll;
template <class T> inline bool dpmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool dpmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(long long K) {
    ll x, n_lun = 0;
    queue<ll> q;

    for (ll i = 1; i <= 9; i++) {
        q.push(i);
    }

    while (n_lun < K) {
        n_lun++;
        x = q.front();
        q.pop();

        if (x%10 != 0) {
            q.push(x*10 + (x%10) - 1);
        }
        q.push(x*10 + (x%10));
        if (x%10 != 9) {
            q.push(x*10 + (x%10) + 1);
        }
    }

    cout << x << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long K;
  cin >> K;
  solve(K);
  return 0;
}


Measured memory_bytes: 5132
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        if (4 * h * n - N * n - N * h) != 0:
            if (N * h * n) % (4 * h * n - N * n - N * h) == 0:
                w = N * h * n // (4 * h * n - N * n - N * h)
                if w > 0:
                    res1 = h
                    res2 = n
                    res3 = w
                
print(res1, res2, res3)



Measured memory_bytes: 44176
#include <iostream>
#include <stdio.h>

char buf[10];

int main() {
    std::cin >> buf;
    int ans =0;
    for(int i=0; i<6; i++){
        if(buf[i] == '0'){
            
        }
        else if(buf[i] == '1'){
            ans++;
        }
    }

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256