akhauriyash/Code-Regression huggingface dataset:
#include<iostream>                                                        
using namespace std;
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
    char suit;
    int value;

};
struct Card L[MAX/2+2],R[MAX/2+2];
void merge(struct Card A[],int n,int left,int mid,int right){
    int i,j,k;
    int n1=mid-left;
    int n2=right-mid;
    for(i=0;i<n1;i++)L[i]=A[left+i];
    for(i=0;i<n2;i++)R[i]=A[mid+i];
    L[n1].value=R[n2].value=SENTINEL;
    i=j=0;
    for(k=left;k<right;k++){
        if(L[i].value<=R[j].value)
            A[k]=L[i++];
        else
            A[k]=R[j++];
    }
}
void mergeSort(struct Card A[],int n,int left,int right){
    int mid;
    if(left +1<right){
        mid=(left+right)/2;
        mergeSort(A,n,left,mid);
        mergeSort(A,n,mid,right);
        merge(A,n,left,mid,right);
    }
} 
int partition(struct Card A[],int n,int p,int r){
    int i,j;
    struct Card t,x;
    x=A[r];
    i=p-1;
    for(j=p;j<r;j++){
        if(A[j].value<=x.value){
            i++;
            swap(A[i],A[j]);
        }
    }
    swap(A[i+1],A[r]);
    return i+1;
}
void quickSort(struct Card A[],int n,int p,int r){
    int q;
    if(p<r){
        q=partition(A,n,p,r);
        quickSort(A,n,p,q-1);
        quickSort(A,n,q+1,r);
    }
}
  
int main(){ 
    int n,i,v;
    struct Card A[MAX],B[MAX];
    char S[10];
    int stable=1;

    cin>>n;
    for(i=0;i<n;i++){
        cin>>S>>v;
        A[i].suit=B[i].suit=S[0];
        A[i].value=B[i].value=v;
    }
    mergeSort(A,n,0,n);
    quickSort(B,n,0,n-1);
    for(i=0;i<n;i++){
        if(A[i].suit!=B[i].suit)
            stable=0;
    }
    if(stable==1)
        cout<<"Stable"<<"\n";
    else
        cout<<"Not stable"<<"\n";
    for(i=0;i<n;i++)
        cout<<B[i].suit<<" "<<B[i].value<<"\n";
    return 0;    
}




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

typedef long double ld;
typedef long long ll;

using namespace std;

vector<ll> divisors(ll n) {
	vector<ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			if (i * i == n) {
				ret.push_back(i);
			} else {
				ret.push_back(i);
				ret.push_back(n / i);
			}
		}
	}
	ret.push_back(n);
	sort(ret.begin(), ret.end());
	return ret;
}

bool sim(ll n, ll k) {
	ll cur = n;
	while (cur >= k) {
		if (cur % k == 0) {
			cur /= k;
		} else {
			cur %= k;
		}
	}
	return (cur == 1);
}

int main() {
	ll n;
	cin >> n;
	vector<ll> divs = divisors(n);
	vector<ll> v1 = divisors(n - 1);
//	vector<ll> v2 = divisors(n + 1);
//	set<ll> s1(v1);
//	set<ll> s2(v2);
//	set<ll> s;
//	merge(s1.begin(), s1.end(), s2.begin(), s2.end(), inserter(s, s.begin()));

//	for (int i = 0; i < divs.size(); i++) {
		//cout << divs[i] << endl;
//	}

	ll ret = 0;
	for (int i = 0; i < divs.size(); i++) {
		if (sim(n, divs[i])) {
			ret++;
		}
	}
	if (n == 2) {
		cout << "1" << endl;
	} else {
		cout << ret + v1.size() << endl;
	}

	return 0;
}


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

int main( void ) {
    vector< int > vt;
    int n, q, num;
    cin >> n;
    for( int i = 0; i < n; ++i ) {
        cin >> q;
        if( q == 2 ) vt.pop_back();
        else if( q == 0 ) cin >> num, vt.push_back(num);
        else {
            cin >> num;
            cout << vt[num] << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 3952
o1,o2,x,y=map(int,input().split())
x = x-o1
y = y-o2
res = ''
if x>=0 and y>=0:
    res='R'*x+'U'*y+'L'*x+'D'*y
    res+='L'+'U'*(y+1)+'R'*(x+1)+'D'
    res+='R'+'D'*(y+1)+'L'*(x+1)+'U'
print(res)

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};


int main() {
    string S;
    cin >> S;
    if (S.length() == 2) cout << S << endl;
    else {
        REP(i, 3) cout << S[2 - i];
        cout << "\n";
    }
    return 0;
}

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

bool search_x(int x, vector<int> p){
    for (int i = 0; i < p.size(); i++) {
        if (x == p.at(i))
            return true;
    }
    return false;
}

int main()
{
    int a, b, ans;
    cin >> a >> b;
    ans = (b % a == 0) ? a + b : b - a;
    cout << ans << endl;
}

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

#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)

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

	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	int x;
	cin>>x;
	if (x>=30)
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

int main() {
	int n; cin >> n;
	vector<int> x(n, 0);
	vector<int> y(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
		y[i] = x[i];
	}
	sort(y.begin(), y.end());
	for (int i = 0; i < n; i++) {
		if (x[i] <= y[n / 2-1]) { cout << y[n / 2] << endl; }
		else { cout << y[n / 2-1] << endl; }
	}
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int h, w, m;
vector<pair<int, int>> y_cnt, x_cnt;
set<pair<int, int>> s;

int main() {
    cin >> h >> w >> m;
    int m_y = 0, m_x = 0;
    y_cnt.resize(h + 1);
    x_cnt.resize(w + 1);
    reps(y, h) y_cnt[y].second = y;
    reps(x, w) x_cnt[x].second = x;
    rep(i, m) {
        int y, x;
        cin >> y >> x;
        y_cnt[y].first++, x_cnt[x].first++;
        s.insert(make_pair(y, x));
    }
    sort(y_cnt.begin(), y_cnt.end());
    sort(x_cnt.begin(), x_cnt.end());
    int ans = 0;
    rreps(y, h) {
        rreps(x, w) {
            bool f = s.count(make_pair(y_cnt[y].second, x_cnt[x].second));
            if (y_cnt[y].first + x_cnt[x].first > ans) {
                ans = y_cnt[y].first + x_cnt[x].first - f;
            } else {
                break;
            }
        }
    }

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

Measured memory_bytes: 21924
#include <iostream>

int main() {
  int X, A, B;
  std::cin >> X >> A >> B;
  if (A >= B)
    std::cout << "delicious" << std::endl;
  else if (A + X >= B)
    std::cout << "safe" << std::endl;
  else
    std::cout << "dangerous" << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	string s; cin >> s;
	bool valid = false;

	rep(i, 0, s.size()) {
		if (s[i] == s[i + 1])
		{
			cout << i + 1 << " " << i + 2 << endl;

			return 0;
		}
		if (i < s.size() - 1) {
			if (s[i] == s[i + 2] && s[i] != s[i + 1]) {
				cout << i + 1 << " " << i + 3 << endl;
				return 0;
			}
		}
	}

	cout << -1 << " " << -1 << endl;

	return 0;
}

Measured memory_bytes: 512
N = int(input())
ans = []

for i in range(N) :
    a, b, c = sorted(list(map(int, input().split())))
    if a ** 2 + b ** 2 == c ** 2 :
        ans.append("YES")
    else :
        ans.append("NO")
        
for a in ans :
    print(a)
        


Measured memory_bytes: 5716
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		if (F == 1) WriteLine("Hello World");
		else WriteLine(F + F);
	}
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int n;
int dp[2][10];
int main()
{
	scanf("%d", &n);
	int p = 0, q = 1;
	int xz; scanf("%d", &xz);
	memset(dp, -1, sizeof(dp));
	dp[0][xz % 10] = xz;
	dp[0][0] = max(0, dp[0][0]);
	for(int i = 2; i <= n; ++i)
	{
		p ^= 1; q ^= 1;
		memset(dp[p], -1, sizeof(dp[p]));
		int x;
		scanf("%d", &x);
		for(int j = 0; j < 10; ++j)
			if(dp[q][j] != -1) dp[p][(j + x) % 10] = max(dp[p][(j + x) % 10], dp[q][j] + x), dp[p][j] = max(dp[q][j], dp[p][j]);
	}
	int ans = 0;
	for(int i = 1; i < 10; ++i) ans = max(dp[p][i], ans);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

typedef long long LL;

const LL N=200000;
LL a[N+100];

int main() {
	LL n,i,ans=0;
	scanf("%lld",&n);
	for (i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	LL p=0,sum=0,tail=0;
	for (i=1;i<=n;i++) {
		while (tail+1<=n && (p^a[tail+1])==sum+a[tail+1]) {
			tail++;
			p^=a[tail];
			sum+=a[tail];
			//printf("i=%lld,tail=%lld,p=%lld,sum=%lld\n",i,tail,p,sum);
			ans+=tail-i+1;
		}
		p^=a[i];
		sum-=a[i];
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1664
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

ll powi ( ll x, ll y ) {
    if ( y == 0 ) return 1;
    return x*powi(x, y-1);
}

int main()
{
    int D, N;

    cin >> D >> N;

    if ( N == 100 ) ++N;
    
    cout << powi(100, D)*N << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n,i,t=0;
	cin>>n;
	int a[n+1];
	bool f=1;
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	while(f)
	{
		for(i=1;i<=n;i++)
			if(a[i]%2==0){
				a[i]/=2;
			}
			else{
				f=0;
			}
		if(f!=0){
			t++;
		}
	}
	cout<<t;
	return 0;
}

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

using namespace std;

int main()
{
    int a[3];
    int x=0,y=0;

    for(int i=0; i<3; i++)
    {
        cin>>a[i];

        if(a[i]==5)
        {
            x++;
        }

        else
        {
            y++;
        }
    }

    if(x==2 && y==1)
    {
        cout<<"YES"<<endl;
    }

    else
    {
        cout<<"NO"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int l=s.size();
  
  bool ans=true;
  for(int i=0; i<l/2; i++){
    if(s[i]!=s[l-i-1]) ans=false;
  }
  
  
  for(int i=0; i<l/4; i++){
   if(s[i]!=s[l/2-i-1]) ans=false;
  }
  
  reverse(s.begin(),s.end());
  for(int i=0; i<l/4; i++){
   if(s[i]!=s[l/2-i-1]) ans=false;
  }


  
    
  if(ans==false){
    cout << "No" << endl;
  }
  
  else cout <<  "Yes" << endl;
      
  
}

Measured memory_bytes: 256
#include <stdio.h>

int searchfunction(int A[],int num,int x){
    int j=0;
    int ans=0;
    
    while(A[j]!=num){
        j++;
        if(j==x)break;
    }
    
    if(j!=x)
        ans=1;
    
    return ans;
}

int main(){
    int n,q,S[10000];
    int keynum;
    int i,cnt=0;
    
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&S[i]);
    
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&keynum);
        cnt += searchfunction(S,keynum,n);
    }
    
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 636
s = str(input())
for i in range(8):
  t = s[0]
  x = int(t)
  if i%2 == 0:
    t = t + "+"+ s[1]
    x += int(s[1])
  else:
    t = t + "-" + s[1]
    x -= int(s[1])
  if (i//2)%2 == 0:
    t = t + "+" + s[2]
    x += int(s[2])
  else:
    t = t + "-" + s[2]
    x -= int(s[2])
  if (i//4)%2 == 0:
    t = t + "+" + s[3]
    x += int(s[3])
  else:
    t = t + "-" + s[3]
    x -= int(s[3])
  if x == 7:
    print(t+"=7")
    exit()
      
    
  
  

Measured memory_bytes: 61800
#include <stdio.h>
#include <string.h>
 
int main()
{
    char str1[205], str2[205];
    char *f=str1, *b=str2, *p, i;
    int m, h, len;
    while(scanf(" %s", f)) {
        if(strcmp(f, "-")==0) break;
        for(len=0; f[len]; len++);
        scanf("%d", &m);
        for(i=0; i<m; i++) {
            scanf("%d", &h);
            p=f, f=b, b=p;
            memcpy(f, b+h, len-h);
            memcpy(f+len-h, b, h);
            f[len]='\0';
        }
        puts(f);
    }
    return 0;
}

Measured memory_bytes: 604
N = int(input())
ans = 0
d = [1]*(1000010)
for k in range(2,1000010):
    t = 1
    while k*t <= 1000001:
        d[k*t] += 1
        t += 1
for M in range(1,N):
    ans += d[M]
print(ans)


Measured memory_bytes: 81016
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,d;
	cin>>n>>d;
	int now=2*d+1;
	int ans=1;
	while(now<n){
		ans++;
		now+=d*2+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9+5;
const int MOD=1e9+7;

int main(){
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    vector<bool>dp(k+1);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int stones=0;stones<=k;stones++){
        for(int x:a){
            if(stones>=x and !dp[stones-x]){
                dp[stones]=true;
            }
        }
    }
    cout<<(dp[k]?"First":"Second");
    return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b = map(int, readline().split())

    if a <= 0 <= b:
        print("Zero")
    else:
        if 0 < a:
            print("Positive")
        elif (-a + b + 1) % 2 == 0:
            print("Positive")
        else:
            print("Negative")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61780
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl v(n, -1);
    bool flag = false;
    rep(loop, m) {
        ll s, c;
        cin >> s >> c;
        s--;
        if(s == 0 && c == 0) {
            flag = true;
        }
        if(v[s] == -1) {
            v[s] = c;
        }
        else {
            if(v[s] != c) {
                flag = true;
            }
        }
    }

    if(n == 1 && v[0] == -1) {
        out(0);
        re0;
    }

    if(n == 1 && v[0] == 0) {
        out(0);
        re0;
    }

    if(flag) {
        out(-1);
        re0;
    }

    rep(i, n) {
        if(v[i] == -1) {
            if(i == 0) {
                v[i] = 1;
            }
            else {
                v[i] = 0;
            }
        }
    }

    rep(i, n) {
        cout << v[i];
    }

    cout << endl;
    re0;
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int main () {
	int n;
	while (scanf("%d", &n), n) {
		int recode[24 * 60 * 60];
		memset(recode, 0, sizeof(recode));
		for (int i = 0; i < n; i++) {
			int h, m, s;
			scanf("%d:%d:%d", &h, &m, &s);
			recode[h * 60 * 60 + m * 60 + s] += 1;
			scanf("%d:%d:%d", &h, &m, &s);
			recode[h * 60 * 60 + m * 60 + s] -= 1;
		}
		int current = 0, result = 0;
		for (int i = 0; i < 24 * 60 * 60; i++) {
			current += recode[i];
			result = max(current, result);
		}
		printf("%d\n", result);
	}
	return 0;
}

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

using namespace std;

int main() {
	int n, k; cin >> n >> k;
	vector<int> p(n);
	for (auto& e : p) cin >> e;
	sort(p.begin(), p.end());
	int ans = 0;
	for (int i = 0; i < k; ++i) ans += p[i];
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using VI = vector<int>;
using VB = vector<bool>;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;

int main()
{
  int n;
  scanf("%d", &n);
  int h[110000];
  rep(i, n) cin >> h[i];
  int dp[110000];

  dp[0] = 0;

  rep(i, n)
  {
    if (i == 0)
    {
      dp[i + 1] = abs(h[i + 1] - h[i]);
    }
    else
    {
      dp[i + 1] = min((dp[i] + abs(h[i + 1] - h[i])), (dp[i - 1] + abs(h[i + 1] - h[i - 1])));
    }
  }

  cout << dp[n-1] << endl;
}

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

typedef long long ll;
typedef pair<int,int> P;

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

int main(){
    int N; cin >> N;
    ll a[N],b[N];
    for(int i=0;i<N;i++){
        cin >> a[i] >> b[i];
    }
    reverse(b,b+N);
    reverse(a,a+N);
    ll ans=0;
    for(int i=0;i<N;i++){
        a[i]+=ans;
        ll tmp=(a[i]+(b[i]-1))/b[i];
        ans+=tmp*b[i]-a[i];
    }
    cout << ans << endl;
}

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

int main(){
    int N, M;
    int a,b;
    cin >> N >> M;
    int input[50][2] = {};
    int output[50] = {};
    
    for (int i =0; i <M; ++i) {
        cin >> a >> b;
        input[i][0] = a; //first
        input[i][1] = b; //second
    }
    
    for (int i =0; i <M; ++i) {
        output[input[i][0]-1] += 1;
        output[input[i][1]-1] += 1;
    }
    
    for (int i =0; i <N; ++i) {
        cout << output[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

bool included(int n, int l[], int p){
	for (int i=0; i<n; i++){
		if (l[i] == p){
			return true;
		}
	}
	return false;
}

void printarray(int n, int l[]){
	for (int i=0; i<n; i++){
		cout << l[i] << " ";
	}
	cout << endl;
}

int main(){

	int n;
	int q;
	int tmp;
	int tmppow;

	cin >> n;

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

	cin >> q;

	int b[q];
	for (int i=0; i<q; i++){
		cin >> tmp;
		b[i] = tmp;
	}

	int l[pow(2,n)];
	l[0] = 0;
	for (int i=0; i<n; i++){
		tmp = a[i];
		tmppow = pow(2,i);
		for (int j=0; j<tmppow; j++){
			l[j+tmppow] = l[j] + tmp;
		}
	}

	for (int i=0; i<q; i++){
		if (included(pow(2,n),l,b[i])){
			cout << "yes" << endl;
		}
		else{
			cout << "no" << endl;
		}
	}


	return 0;
}


Measured memory_bytes: 7156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    int N;cin >> N;
    vector<int> D(N);
    REP(i,N) cin >> D[i];
  	sort ALL(D);
    //sort(D.begin(), D.end()); D.erase(unique(D.begin(), D.end()), D.end());
    N = D.size();
    vector<int> M(N),V(N);
  	M = D;V = D;
    REP(i,M.size()){
        if(i % 2 == 0) M[i] = (24 - M[i]);
        else V[i] = (24 - V[i]);
    }
  	V.pb(0);V.pb(24);M.pb(0);M.pb(24);
    sort ALL(M);sort ALL(V);
    int minv = INF,minm = INF;
    REP(i,M.size()-1){
        minv = min(minv,M[i+1] - M[i]);
        minm = min(minm,V[i+1] - V[i]);
    }
    cout << max(minv,minm) << endl;
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

struct BIT {
    vector<ll> data;
    int N;
    BIT(int n) : data(n + 1), N(n) {}
    void update(int a, ll w) {
        for(int x = a; x <= N; x += x & -x) data[x] = max(data[x], w);
    }
    ll get(int a) {
        ll ret = 0;
        for(int x = a; x > 0; x -= x & -x) ret = max(ret, data[x]);
        return ret;
    }
};

void solve() {
    int N;
    cin >> N;
    vector<ll> H(N), A(N);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    BIT bit(N);
    for (int i = 0; i < N; i++) {
        ll ma = bit.get(H[i]);
        bit.update(H[i], ma + A[i]);
    }
    cout << bit.get(N) << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <string.h>
#include <cstdio>
#include <cctype>
#include <queue>
using namespace std;
int main(){
    
    while(true){
        string s; cin >> s;
        if(s=="-") break;
        string sd = s + s;
        queue<char> ss;
        for(int i=0; i<sd.size(); i++){
            ss.push(sd.at(i));
        }
        int n, cnt =0; cin >> n;
        for(int i=0; i<n; i++){
            int a; cin >> a;
            cnt += a;
        }
        for(int i=0; i<cnt%s.size(); i++)  ss.pop();
        for(int i=0; i<s.size(); i++){
            cout << ss.front();
            ss.pop();
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3184
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp=[0]*N

    for i in range(1,N):
        dp[i] = min(
            dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
        )
    print(dp[N-1])
main()

Measured memory_bytes: 13980
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main(){
    cin.tie(0); ios_base::sync_with_stdio(false);
    int Q; cin >> Q;
    
    // xは中央値
    // f(x)について
    // 2がくる度に最小値を計算すると間に合わないので、
    // 1がくる度に解を更新していく。

    // L : 区間の左側(一番後ろが中央値)
    // R : 区間の右側
    // 常にmax(L) <= min(R) && L.size()==R.size()となるように値を挿入
    multiset<long> L, R;
    long ans = 0;
    for(int i=0; i < Q; ++i) {
        int q, a, b;
        cin >> q;
        if(q == 1) {
            cin >> a >> b;
            L.insert(a), R.insert(a);
            ans += b;

            long x = *--L.end(), y = *R.begin();
            L.erase(--L.end()), R.erase(R.begin());
            if(x > y) { // L の最大値 > Rの最小値 -> 中央値が更新された
                ans += x - y;
                swap(x, y);
            }
            L.insert(x), R.insert(y);
        } else {
            cout << *--L.end() << " " << ans << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 19072
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#define maxr 100005
#define maxn 
#define bit 19
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define gc() ((p1 == p2 && (p2 = (p1 = buffer) + fread(buffer, 1, maxr, stdin), p1 == p2)) ? EOF : *p1++)
using namespace std;

char buffer[maxr], *p1, *p2;
template <class T> void read(T& x){
	char ch = gc(); x = 0; bool f = 1;
	while (!('0' <= ch && ch <= '9') && ch != '-') ch = gc();
	if (ch == '-') f = 0, ch = gc();
	while ('0' <= ch && ch <= '9') x = (x << 1) + (x << 3) + ch - '0', ch = gc();
	if (!f) x = -x;
}

int n;
int a[1 << bit];
int mx[1 << bit];
int mx2[1 << bit];
int main(){
	read(n);
	int x;
	int t = 1 << n;
	rep(i, 0, t - 1) {
		read(x);
		int k = (t - 1) ^ i;
		for (register int j = k; j; j = (j - 1) & k){
			int op = i ^ j;
			if (x > mx[op]) mx2[op] = mx[op], mx[op] = x;
			else if (x > mx2[op]) mx2[op] = x;
		}
		if (x > mx[i]) mx2[i] = mx[i], mx[i] = x;
		else if (x > mx2[i]) mx2[i] = x;
	}
	int mx3 = 0;
	rep(i, 1, t - 1) mx3 = max(mx3, mx[i] + mx2[i]), printf("%d\n", mx3);
	return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define  itn int
using ll=int64_t;
#define rep(i,n) for (int i = 0; i < (int) (n); i++)
using vi = vector<int>;
using vll = vector<ll>;
int main(){
ll a,b,v,w,t;
  cin>>a>>v>>b>>w>>t;
  if (abs(a-b)>(v-w)*t){cout<<"NO";}
  else cout<<"YES";


}

Measured memory_bytes: 3604
#include <iostream>
#include<algorithm>
#include<vector>
#include <numeric>
#include<cmath>
using namespace std;
int main(void){
    long n,k;
    cin >> n>>k;
    long front[n],back[n];
    
    for(int i=0;i<n;i++){
        cin >> front[i];
    }
    for(int i=0;i<n;i++){
        back[n-1-i] = front[i];
    }
    
    // for(int i=0;i<n;i++){
    //     cout << back[i];
    // }
    // cout << endl;
    
    long get = min(n,k);
    long ans=0;
    // i回操作を行う
    for(int i=0;i<=k;i++){
        // j回取り出す(jはkの1/2以上である必要)
        for(int j=ceil(double(i)/2.0);j<=i;j++){
            if(n<j){
                break;
            }
            // m回前から
            for(int m=0;m<=j;m++){
                std::vector<long> jwery;
                
                // l回前から取り出す
                for(int l=0;l<m;l++){
                    jwery.push_back(front[l]);
                }
                for(int l=0;l<j-m;l++){
                    jwery.push_back(back[l]);
                }       
                
                sort(jwery.rbegin(),jwery.rend());
                // for(int l=0;l<jwery.size();l++){
                //     cout << jwery[l]<<' ';
                // }
                long tmp = accumulate(jwery.begin(),jwery.end()-(i-j),0);
                // cout <<"      :" << tmp<<", i="<<i<<",j="<<j<<", m="<<m<<endl;
                if(ans < tmp){
                    ans = tmp;
                }
            }
        }
    }
    cout << ans<<endl;
}


Measured memory_bytes: 256
n = int(input())
if n > 30:
    x = n // 10
    basenum = x * x + 8
    addnum = 0
    #print("{0} {1}".format(x* 10 + 1, n))
    hassame = False
    for i in range(x * 10 + 1, n+1):
        #print(i)
        for j in range(1, n+1):
            #print(j)
            if str(i)[0] == str(j)[-1] and str(i)[-1] == str(j)[0]:
                addnum += 1
                if i == j:
                    hassame=True
                #print("{0},{1}".format(i, j))
    res = basenum + addnum * 2
    if hassame:
        res-=1
    #print("n={0}, x={1}, basenum={2}, addnum={3} res ={4}".format(n,x,basenum,addnum,res))
    print(res)
elif n==1:
    print(1)
else:
    res = 0
    for i in range(1, n):
        for j in range(1, n):
            if str(i)[0] == str(j)[-1] and str(i)[-1] == str(j)[0]:
                res += 1
    print("{1}".format(n, res))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int N,M;
int k[15];
int s[15][15];
int keisan[15];
int p[15];
int ans=0;

int dfs(int current){
  if (current<N){
    keisan[current]=0;
    dfs(current+1);
    keisan[current]=1;
    dfs(current+1);
  }else{
  int whether=0;
    for(int i=0;i<M;i++){
      int count=0;
      for(int j=0;j<k[i];j++){
        if(keisan[s[i][j]-1]==1){
          count++;
        }
      }
      if(count%2!=p[i]){
        whether=1;
      }
    }
    if (whether==0){
      ans++;
    }
  }
  return 0;
}

int main(){
  cin >> N >> M;
  for(int i=0;i<M;i++){
    cin >> k[i];
    for(int j=0;j<k[i];j++){
      cin >> s[i][j];
    }
  }
  for(int i=0;i<M;i++){
    cin >> p[i];
  }
  dfs(0);
  cout << ans;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rs64() {
	int64_t n;
	scanf("%" SCNd64, &n);
	return n;
}
#define MOD 1000000007
template<int mod>
struct ModInt{
	int x;
	ModInt():x(0){}
	ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
	ModInt &operator+=(const ModInt &p){
		if((x+=p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator-=(const ModInt &p){
		if((x+=mod-p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator*=(const ModInt &p){
		x=(int)(1LL*x*p.x%mod);
		return *this;
	}
	ModInt &operator/=(const ModInt &p){
		*this*=p.inverse();
		return *this;
	}
	ModInt &operator^=(long long p){
		ModInt res = 1;
		for (; p; p >>= 1) {
			if (p & 1) res *= *this;
			*this *= *this;
		}
		return *this = res;
	}
	ModInt operator-()const{return ModInt(-x);}
	ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
	ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
	ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
	ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
	ModInt operator^(long long p)const{return ModInt(*this)^=p;}
	bool operator==(const ModInt &p)const{return x==p.x;}
	bool operator!=(const ModInt &p)const{return x!=p.x;}
	explicit operator int() const { return x; }						   // added by QCFium
	ModInt operator=(const int p) {x = p; return ModInt(*this);} // added by QCFium
	ModInt inverse()const{
		int a=x,b=mod,u=1,v=0,t;
		while(b>0){
			t=a/b;
			a-=t*b;
			std::swap(a,b);
			u-=t*v;
			std::swap(u,v);
		}
		return ModInt(u);
	}
	friend std::ostream &operator<<(std::ostream &os,const ModInt<mod> &p){
		return os<<p.x;
	}
	friend std::istream &operator>>(std::istream &is,ModInt<mod> &a){
		long long x;
		is>>x;
		a=ModInt<mod>(x);
		return (is);
	}
};
typedef ModInt<MOD> mint;

struct MComb {
	std::vector<mint> fact;
	std::vector<mint> inversed;
	MComb(int n) { // O(n+log(mod))
		fact = std::vector<mint>(n+1,1);
		for (int i = 1; i <= n; i++) fact[i] = fact[i-1]*mint(i);
		inversed = std::vector<mint>(n+1);
		inversed[n] = fact[n] ^ (MOD-2);
		for (int i = n - 1; i >= 0; i--) inversed[i]=inversed[i+1]*mint(i+1);
	}
	mint ncr(int n, int r) {
		return (fact[n] * inversed[r] * inversed[n-r]);
	}
	mint npr(int n, int r) {
		return (fact[n] * inversed[n-r]);
	}
	mint nhr(int n, int r) {
		assert(n+r-1 < (int)fact.size());
		return ncr(n+r-1, r);
	}
};

int main() {
	int n = ri(), r = ri();
	printf("%d\n", n >= 10 ? r : r + 100 * (10 - n));
	return 0;
}


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

int main(void){
    int n,m,l;
    cin>>n>>m>>l;
    long** A;
    long** B;
    long** C;
    long* rowA;
    long* rowB;
    long* rowC;
    A=new long*[n];
    B=new long*[m];
    C=new long*[n];
    for(int i=0;i<n;i++){
        rowA =new long[m];
        A[i]=rowA;
        for(int j=0;j<m;j++){
            cin>>A[i][j];
        }
    }
    for(int i=0;i<m;i++){
        rowB =new long[l];
        B[i]=rowB;
        for(int j=0;j<l;j++){
            cin>>B[i][j];
        }
    }
    for(int i=0;i<n;i++){
        rowC =new long[l];
        C[i]=rowC;
        for(int j=0;j<l;j++){
            C[i][j]=0;
        }
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            for(int k=0;k<m;k++){
                C[i][j]+=A[i][k]*B[k][j];
            }
        }
    }


    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            if(j<l-1){
                cout<<C[i][j]<<" ";
            }
            else{
                cout<<C[i][j]<<endl;
            }
        }
    }

    return 0;

}



Measured memory_bytes: 3328
#include <cstdio>
#include <string>
#include <algorithm>
 
using namespace std;
 
int N, M;
string U[257];
 
int main() {
  char s[11];
  scanf("%d", &N);
  for (int i=0;i<N;i++) {
    scanf("%s", s);
    U[i] = s;
  }
  scanf("%d", &M);
  bool opened = false;
  for (int i=0;i<M;i++) {
    scanf("%s", s);
    const string* p = find(U, U+N, (string)s);
    if (!p->empty()) {
      opened = !opened;
      printf("%s by %s\n", (opened ? "Opened" : "Closed"), s);
    } else {
      printf("Unknown %s\n", s);
    }
  }
  return 0;
}


Measured memory_bytes: 2836
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#include<vector>
#define endl "\n"
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
using namespace std;

int main(){
	string s;
	cin>>s;
	if(s[2]==s[3] and s[4]==s[5]){
		cout<<"Yes"<<endl;
	}
	else
	cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
	int n,m,q;
	int i,j,k,l,a,b;
	struct points
	{
		int towards[501];
	} point[501];
	cin>>n>>m>>q;
	for(i=0;i<=n;i++)
		for(j=i;j<=n;j++)
			point[i].towards[j]=0;
	for(i=0;i<m;i++)
	{
		cin>>j>>k;
		for(l=k;l<=n;l++)
			point[j].towards[l]++;
	}
	for(i=0;i<q;i++)
	{
		a=0;
		cin>>j>>k;
		for(l=j;l<=k;l++)
			a+=point[l].towards[k];
		cout<<a<<endl;
	}
	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
const int MAX_N = 500;
int h, w;
char table[MAX_N][MAX_N];
bool flag[MAX_N][MAX_N];
long long black;
int bfs(int y, int x)
{
    queue<P> que;
    que.push(P(y, x));
    flag[y][x] = true;
    int res = 0;
    while(!que.empty())
    {
        P p = que.front();
        que.pop();
        for(int i = 0; i < 4; i++)
        {
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if(nx < 0 || ny < 0 || ny >= h || nx >= w) continue;
            if(table[ny][nx] == table[p.first][p.second]) continue; 
            if(flag[ny][nx]) continue;
            if(table[ny][nx] == '.') res++;
            else black++;
            flag[ny][nx] = true;
            que.push(P(ny, nx));
        }
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    int cnt = 0;
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            cin >> table[i][j];
    long long ans = 0;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            if(table[i][j] == '#' && flag[i][j] == false)
            {
                black = 1;
                long long white = bfs(i, j);
                ans += black * white;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);
    int x = cin.nextInt();
    int a = cin.nextInt();

    if (x < a) {
      System.out.println(0);
    }
    else {
      System.out.println(10);
    }

  }

}


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

S = sum(A)
#print(S)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

S_div = make_divisors(S)

mod = []
for _ in range(N):
  mod.append(0)

ans = 1
for i in range(1,len(S_div)):
  for j in range(N):
    mod[j] = A[j] % S_div[i]
  group = sum(mod)//S_div[i]
  mod.sort(reverse=True)
  Ktmp = S_div[i]*group - sum(mod[:group])
  if Ktmp <= K:
    ans = max(ans,S_div[i])

print(ans)

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

int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<int>> ans(H+2,vector<int>(W+2,999999));
  vector<vector<bool>> mp(H+2,vector<bool>(W+2,false));
  char a;
  int white = 0;
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      cin >> a;
      if (a == '.') {
        mp[i+1][j+1] = true;
        white++;
      }
    }
  }
  ans[1][1] = 1;
  bool found = false;
  for (int i=1; i<H*W; i++) {
    for (int j=1; j<H+1; j++) {
      for (int k=1; k<W+1; k++) {
        if (ans[j][k] == i && mp[j][k]) {
          found = true;
          ans[j+1][k] = min(ans[j+1][k],i+1);
          ans[j-1][k] = min(ans[j-1][k],i+1);
          ans[j][k+1] = min(ans[j][k+1],i+1);
          ans[j][k-1] = min(ans[j][k-1],i+1);
        }
      }
    }
    if (!found) {
      cout << -1 << endl;
      break;
    }
    found = false;
    if (ans[H][W] == i+1) {
      cout << white - i - 1 << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl
 
 
int main(){
	int a,b;
	cin >> a >> b;
	int val = ((b-1) / (a-1)) + (((b-1) % (a-1)) != 0); 
	cout << val;
}

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

# 仮説
if x in (1,2*n-1):
    print('No')
    exit()

res = [i for i in range(1,2*n)]

flag = False
if x > n:
    x = 2 * n - x
    flag = True

res = res[x-n:] + res[:x-n]

if flag:
    for i in range(2*n-1):
        res[i] = 2 * n - res[i]

print('Yes')
print(*res, sep='\n')


Measured memory_bytes: 15668
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
	long long a,b,c,mls=0,j=0;
    cin>>a>>b>>c;
    if(b>=a){
        cout<<1<<endl;
        return 0;
    }
    if(c>=b){
        cout<<-1<<endl;
        return 0;
    }
    if((a-b)%(b-c)>=1) mls=1;
    j=((a-b)/(b-c)+mls)*2+1;
    cout<<j<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
int N;
int A,D,M;
int X,Y,Z;
int K;
map<int,int>Ma;
int main()
{
	scanf("%d%d%d%d",&N,&A,&D,&M);
	for(int i=0;i<M;i++){
		scanf("%d%d%d",&X,&Y,&Z);
		if(X==0){
			if(Ma[Y]!=0&&Ma[Z]!=0){
				int x=Ma[Y];
				Ma[Y]=Ma[Z];
				Ma[Z]=x;
			}
			else if(Ma[Y]!=0){
				Ma[Z]=Ma[Y];
				Ma[Y]=Z;
			}
			else if(Ma[Z]!=0){
				Ma[Y]=Ma[Z];
				Ma[Z]=Y;
			}
			else{
				Ma[Y]=Z;
				Ma[Z]=Y;
			}
		}
		else{
			if(Ma[Z]!=0)Ma[Y]=Ma[Z];
			else Ma[Y]=Z;
		}
	}
	scanf("%d",&K);
	if(Ma[K]!=0)printf("%d\n",A+(Ma[K]-1)*D);
	else printf("%d\n",A+(K-1)*D);
	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define rgi register int
#define ll long long
class fastin{
	private: int _ch,_f;
	public: inline fastin& operator>>(char&c) {c=getchar(); return *this;}
		template<typename _Tp> inline fastin& operator>>(_Tp&_x){
		_x=0; while(!isdigit(_ch)) _f|=(_ch==45),_ch=getchar();
		while(isdigit(_ch)) _x=(_x<<1)+(_x<<3)+(_ch^48),_ch=getchar();
		_f&&(_x=-_x,_f=0); return *this;}
	fastin() {_ch=_f=0;}
}fin;
class fastout{
#define endl '\n'
	private: int _num[32],_head;
	public: inline fastout& operator<<(char c) {putchar(c); return *this;}
		template<typename _Tp> inline fastout& operator<<(_Tp _x){
		_Tp _k; if(_x==0) {putchar('0'); return *this;} if(_x<0) putchar('-'),_x=-_x;
		while(_x>0) _k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k;
		while(_head>0) putchar(_num[_head]),--_head; return *this;}
	fastout() {_head=0;}
}fout;
// ----------------------------
// #define int ll
// using namespace std;
const int maxn=200004;
const int mod=998244353,inf=1000000007;

int cnt[maxn];
signed main()
{
	int n,q,a,b;
	fin>>n;
	ll ans=0;
	for(rgi i=1;i<=n;++i) fin>>a,++cnt[a],ans+=a;
	fin>>q;
	while(q--)
	{
		fin>>a>>b;
		if(a==b) continue;
		ans+=(ll)(cnt[a])*(b-a);
		cnt[b]+=cnt[a];
		cnt[a]=0;
		fout<<ans<<endl;
	}
	return 0;
}
// ----------------------------
// by imzzy


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int dp[MAX_N];
int h[MAX_N];

int rec(int n) {
    if (n == 0)
        return 0;

    if (dp[n] == INF) {
        int res = INF;
        if (n - 1 >= 0) res = min(res, rec(n - 1) + abs(h[n] - h[n - 1]));
        if (n - 2 >= 0) res = min(res, rec(n - 2) + abs(h[n] - h[n - 2]));
        dp[n] = res;
    }

    return dp[n];
}

int main() {
    int n, k;
    cin >> n >> k;
    rep(i, n) {
        dp[i] = INF;
        cin >> h[i];
    }

    dp[0] = 0;

    rep(i, n) {
        repeat(j, 1, k + 1) {
            if (i + j < n) dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }

        // debug(i);
        // debug(dp[i]);
    }

    out(dp[n - 1]);
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n;
ll c[200010];

void solve(){
    cin >> n;
    rep(i,n){
        cin >> c[i];
    }
    sort(c,c+n);
    ll ans=0;
    ll pow2=1;
    rep(i,2*n-2){
        pow2*=2;
        pow2%=mod;
    }
    rep(i,n){
        ans+=(i+2)*c[n-1-i];
        ans%=mod;
    }
    ans*=pow2;
    ans%=mod;
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 1792
fun main(args: Array<String>) {
    val N = readInt()
    val S = readString().map { it-'0' }
    val topList = BooleanArray(10) {false}
    val list = IntArray(100) {0}

    for (i in 0 until N-2) {
        if (topList[S[i]]) continue
        topList[S[i]] = true
        for (j in i+1 until N-1) {
            val ab = S[i]*10+S[j]
            if (list[ab] != 0) continue

            val l = BooleanArray(10) {false}
            for (k in j+1 until N) {
                l[S[k]] = true
            }
            list[ab] = l.count { it }
        }
    }
    println(list.sum())
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()

Measured memory_bytes: 39636
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

use std::collections::BTreeSet;

fn main() {
    let nk: Vec<usize> = read_vec();
    let n = nk[0];
    let k = nk[1];
    let dv: Vec<usize> = read_vec();
    let mut set = BTreeSet::new();
    for d in dv {
        set.insert(d);
    }
    for i in n..100000 {
        let mut v = i;
        while v > 0 {
            if set.contains(&(v % 10)) {
                break;
            }
            v /= 10;
        }
        if v == 0 {
            println!("{}", i);
            break;
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <math.h>
#include<algorithm>
using namespace std;

#define L 1000003


string A[L];

int num(char s){
  if(s=='A') return 1;
  else if(s=='C') return 2;
  else if(s=='G') return 3;
  else if(s=='T') return 4;
}

long long key(string s){
  long long sum=0;
  int k=1;
  for(int i=0;i<strlen(&s[0]);i++){
    sum+=num(s[i])*k;
    k*=5;
  }
  return sum;
}

int hash1(int x){
  return x%L;
}

int hash2(int x){
  return 1+x%(L-1);
}

void insert(string s){
  long long k=key(s);
  int h1,h2;
  h1=hash1(k); h2=hash2(k);
  for(int i=0;;i++){
    int h=(h1+i*h2)%L;
    if(A[h][0]=='\0'){ 
      A[h]=s; break;
    }
    else if(A[h]==s) break;
  }
}

void find(string s){
  long long k=key(s);
  int h1,h2;
  h1=hash1(k); h2=hash2(k);
  for(int i=0;;i++){
    int h=(h1+i*h2)%L;
    if(A[h][0]=='\0'){
      cout<<"no"<<endl; return;
    }
    if(A[h]==s){
      cout<<"yes"<<endl;
      return;
    }
  }
}


int main(){
  for(int i=0;i<L;i++){
    A[i]='\0';
  }
  string com,s;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>com>>s;
    if(com[0]=='i'){
      insert(s);
    }else{
      find(s);
    }
  }
  return 0;
}



Measured memory_bytes: 67044