akhauriyash/Code-Regression huggingface dataset:
'use strict'
function main(input) {
    const tmp = input.split('\n');
    const N = parseInt(tmp[0], 10);
    const W = tmp[1].split(' ').map((elem) => parseInt(elem, 10));
    let leftSum = 0;
    let rightSum = W.reduce((sum, elem) => sum + elem);
    let absVal = [];

    for (let T = 1; T < N; T++) {
        leftSum += W[T - 1];
        rightSum -= W[T - 1];
        absVal.push(Math.abs(rightSum - leftSum));
    }
    const smallestAbs = absVal.reduce((min, elem) => Math.min(min, elem));
    console.log(smallestAbs);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main()
{
    long long n, a, b;
    cin >> n >> a >> b;

    long long destination;
    long long matchNum;
    if ((b - a) % 2 == 0)
    {
        destination = (b + a) / 2;
        matchNum = b - destination;
    }
    else
    {
        // 1卓で会う
        destination = 1;
        matchNum = b - 1;

        // N卓で会う
        destination = n;
        matchNum = min(matchNum, n - a);

        // aが1卓で一回待機
        long long aTable1Diff = a - 1;
        long long bLastPos = b - (aTable1Diff + 1);
        if (bLastPos >= 1)
        {
            destination = (bLastPos + 1) / 2;
            matchNum = min(matchNum, b - destination);
        }

        // bがN卓で待機
        long long bTableNDiff = n - b;
        long long aLastPos = a + (bTableNDiff + 1);
        if (aLastPos <= n)
        {
            destination = (aLastPos + n) / 2;
            matchNum = min(matchNum, destination - a);
        }
    }

    cout << matchNum << endl;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var A = cin.ReadDouble;
            var B= cin.ReadDouble;
            var H = cin.ReadDouble;
            var M = cin.ReadDouble;

            var thetaB = M * Math.PI / 30.0;
            var thetaA = 2.0 * Math.PI * (H + M / 60) / 12.0;


            var ans2 = (A * Math.Sin(thetaA) - B * Math.Sin(thetaB)) * (A * Math.Sin(thetaA) - B * Math.Sin(thetaB))
                + (A * Math.Cos(thetaA) - B * Math.Cos(thetaB)) * (A * Math.Cos(thetaA) - B * Math.Cos(thetaB));


            //WriteLine("theta A :{0} theta B :{1} ", thetaA, thetaB);
            //WriteLine("A : ({0} , {1})", A * Math.Sin(thetaA), A * Math.Sin(thetaA));
            //WriteLine("B : ({0} , {1})", B * Math.Sin(thetaB), B * Math.Sin(thetaB));

            WriteLine(Math.Sqrt(ans2));

        }

    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; i++)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }


        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


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

const int MOD = 998244353;

int add(int a, int b) {
  int res = a + b;
  if (res >= MOD) {
    res -= MOD;
  }
  if (res < 0) {
    res += MOD;
  }
  return res;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> arr(k);
  for (int i = 0; i < k; i++) {
    cin >> arr[i].first >> arr[i].second;
  }
  vector<int> dp(n + 5), pre(n + 5);
  auto range_query = [&](int lo, int hi) {
    return add(pre[hi], - (lo - 1 >= 0 ? pre[lo - 1] : 0) );
  };
  auto calc = [&](int idx, int lo, int hi) {
    const int LOW = max(0, idx - hi);
    const int HI = max(0, idx - lo);
    int add = range_query(LOW, HI);
    return add;
  };
  dp[1] = 1;
  pre[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      dp[i] = add(dp[i], calc(i, arr[j].first, arr[j].second));
    }
    pre[i] = add(pre[i - 1], dp[i]);
  }
  cout << dp[n] << '\n';
  return 0;
}


Measured memory_bytes: 4732
#include<stdio.h>

int main(void)
{
	int h,n,i,k,sum=0;
	
	scanf("%d%d",&h,&n);
	
	for(i=0;i<n;i++){
		scanf("%d",&k);
		sum+=k;
	}
	
	if(sum>=h)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 128
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val S = nextList()
    val N = S[0].toInt()
    val X = S[1].toLong()
    val D = LongArray(N) { 1L }
    val P = LongArray(N) { 1L }
    for (i in 1 until N) D[i] = 2 * D[i - 1] + 3
    for (i in 1 until N) P[i] = 2 * P[i - 1] + 1
    fun f(l: Int, x: Long): Long {
        if (l == 0) return if (x <= 0) 0L else 1L
        if (x <= D[l - 1] + 1) return f(l - 1, x - 1)
        return P[l - 1] + 1 + f(l - 1, x - 2 - D[l - 1])
    }
    println(f(N, X))
}

Measured memory_bytes: 35736
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
using namespace std;
const int N=105;
int n,x[N],ans=1e9;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>x[i];
	for(int i=0;i<=100;i++)
	{
		int sum=0;
		for(int j=0;j<n;j++)
		{
			sum+=(x[j]-i)*(x[j]-i);
		}
		ans=min(ans,sum);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n,m,c=list(map(int,input().split()))
b=list(map(int,input().split()))
counter=0
 
for _ in range(n):
  a=list(map(int,input().split()))
  x = [a[i]*b[i] for i in range(m)]
  if sum(x)+c > 0:
    counter +=1
    
print(counter)

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

int main() {
    ios::sync_with_stdio(false);
    int n, ans = 0;
    int a[201];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] % 2 == 1) {
            cout << 0 << '\n';
            return 0;
        }
    }
    
    while (true) {
        for (int i = 0; i < n; i++) {
            if (a[i] % 2 == 1) {
                cout << ans << endl;
                return 0;
            }
            else {
                a[i] /= 2;
            }
        }
        ans++;
    }
    cout << ans << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N ((int)1e5+5)
using namespace std;
int main(){
	// interesting
	int n,m;
	cin>>n>>m;
	vector<vector<int>> gra(N);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u-=1;
		v-=1;
		gra[u].emplace_back(v);
	}
	int s,t;
	cin>>s>>t;
	s-=1;
	t-=1;
	queue<pair<int,int>> q;
	q.push(make_pair(0,s));
	vector<int> flag(3*n,-3);
	int dfsParent[3*n];
	memset(dfsParent,0,sizeof(dfsParent));
	while(!q.empty()){
		pair<int,int> nx=q.front();q.pop();
		int nxdis=nx.first;
		int nxpoi=nx.second;
		if(flag[nxpoi]!=-3)continue;
		flag[nxpoi]=nxdis;
		for(int i=0;i<(int)gra[nxpoi%n].size();i++){
			int nx=gra[nxpoi%n][i];
			q.push(make_pair(nxdis+1,(nxdis+1)%3*n+nx));
			dfsParent[(nxdis+1)%3*n+nx]=nxpoi;
		}
	}
	cout<<flag[t]/3<<endl;
	
	return 0;
}

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

int inf = 1e9;
using PP = pair<int, int>;

class ST {
  const int n;
  vector<PP> v;
public:
  ST(int k)
    : n(1 << k), v(2 << k, PP(inf, inf)) {
  }
  
  PP query(int l, int r) {
    l += n;
    r += n;
    PP mn(inf, inf); 
    while (l < r) {
      if (l & 1) mn = min(mn, v[l++]);
      if (r & 1) mn = min(mn, v[--r]);
      l /= 2;
      r /= 2;
    }
    return mn;
  }
  
  void update(int i, PP p) {
    i += n;
    while (i > 0) {
      v[i] = min(v[i], p);
      i /= 2;
    }
  }
};

int n, k;
string s;
ST seg(20);
int nxt[200000];

int main() {
  cin >> n >> k >> s;
  seg.update(n, PP(0, n));
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == '1') continue;
    int l = i + 1;
    int r = i + k + 1;
    auto res = seg.query(l, r);
    int d = res.first;
    int ni = res.second;
    if (d == inf) {
      cout << -1 << endl;
      return 0;
    }
    nxt[i] = ni;
    seg.update(i, PP(d + 1, i));
  }
  
  int ci = 0;
  while (ci != n) {
    cout << nxt[ci] - ci << ' ';
    ci = nxt[ci];
  }
  cout << endl;
}

Measured memory_bytes: 17408
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
int a[1000][1000], dp[1000][1000];
int main() {
	int h, w, n;
	while (scanf("%d%d%d", &h, &w, &n), h) {
		rep(i, h)rep(j, w) {
			getchar(); a[i][j] = getchar() - '0';
		}
		memset(dp, 0, sizeof(dp));
		dp[0][0] = n - 1;
		rep(i, h)rep(j, w) {
			if (i) {
				if (a[i - 1][j])dp[i][j] += dp[i - 1][j] >> 1;
				else dp[i][j] += (dp[i - 1][j] + 1) >> 1;
			}
			if (j) {
				if (a[i][j - 1])dp[i][j] += (dp[i][j - 1] + 1) >> 1;
				else dp[i][j] += dp[i][j - 1] >> 1;
			}
		}
		int x = 0, y = 0;
		while (x < h&&y < w) {
			if (dp[x][y] & 1)a[x][y] = !a[x][y];
			if (a[x][y])y++;
			else x++;
		}
		printf("%d %d\n", x + 1, y + 1);
	}
}

Measured memory_bytes: 11000
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
	int n,a[100],i,j,ans=0,sum=0,av;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> a[i];
		sum += a[i];
	}
	av = (sum*10)/n;
	if(av<0){
		av = (av-5)/10;
	}else{
		av = (av+5)/10;
	}
	for(i=0; i<n; i++){
		ans += (a[i]-av)*(a[i]-av);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// AOJ Volume 0 Problem 0017

#include <stdio.h>

int main(void)
{
    char str[200];
    int i;
    
	fgets(str, 200, stdin);
	
	i = 0;
	while (str[i] != '\0'){
		if ('a' <= str[i] && str[i] <= 'z'){
			str[i] -= 0x20;
		}
		i++;
	}
	
	printf("%s", str);
	
    return (0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    int sorted_p=0,cnt=0;
    for(int i=0;i<n-1;i++){
        if(a[i]<a[i+1])cnt++;
        else cnt=0;
        if(cnt==k-1)sorted_p++;
    }
    set<int> s;
    for(int i=0;i<k;i++)s.insert(a[i]);
    int ans=1;
    for(int i=0;i<n-k;i++){
        ans++;
        int l=*s.begin(),r=*s.rbegin();
        //k個のうち一番小さいのが一番左、そして一番大きい数より大きい数が区間のすぐ右隣にあるならば次に参照する区間をソートしても得られる配列pの並びは同じになる
        if(a[i]==l&&a[i+k]>r)ans--;
        s.erase(a[i]);
        s.insert(a[i+k]);
    }
    if(sorted_p!=0)ans-=sorted_p-1;
    cout<<ans<<endl;
}


Measured memory_bytes: 10368
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    try {
      int sum = 0;
      int maxi = 0;
      
      int n = sc.nextInt();
      for (int i = 0; i < n; i++) {
        int a = sc.nextInt();
        sum += a;
        if (maxi < a) maxi = a;
      }

      System.out.println(maxi * 2 < sum ? "Yes" : "No"); 
    } finally {
      sc.close();
    }
  }
}


Measured memory_bytes: 35612
#include <iostream>
#include <vector>
#include <queue>

int main()
{
    int N, M;
    std::cin >> N >> M;

    std::vector<std::vector<int>> connection(N);
    for (auto i=0; i<M; ++i)
    {
        int from, to;
        std::cin >> from >> to;
        from--;
        to--;
        connection[from].push_back(to);
        connection[to].push_back(from);
    }

    const int NotChecked = -1;
    std::vector<int> fromTable(N, NotChecked);
    std::vector<int> distanceTable(N, NotChecked);

    std::queue<int> queue;
    queue.push(0);
    fromTable[0] = 0;

    while (!queue.empty())
    {
        auto v = queue.front();
        queue.pop();

        for (auto nv : connection[v])
        {
            if (distanceTable[nv] != NotChecked)
                continue;

            auto dist = distanceTable[v] + 1;
            distanceTable[nv] = dist;
            fromTable[nv] = v;
            queue.push(nv);
        }
    }

    for (auto from : fromTable)
    {
        if (from == NotChecked)
        {
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;
    for (auto i=1; i<N; ++i)
    {
        std::cout << fromTable[i] + 1 << std::endl;
    }
}


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

using namespace std;

#define ll long long



	
void solve() {

	int n;
	cin >> n;
	int arr[n];
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	sort(arr, arr + n);
	cout << max(0, arr[n / 2] - arr[n / 2 - 1]) << "\n";
	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	solve();

	return 0;
}

Measured memory_bytes: 3944
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

		int n = in.nextInt();
		
		int[] value = new int[n];
		for(int i = 0; i < n; i++) {
			value[i] = in.nextInt();
		}
		
		int[] cost = new int[n];
		for(int j = 0; j < n; j++) {
			cost[j] = in.nextInt();
		}

		int result = solve(n, value, cost);
		System.out.println(result);

		in.close();

	}
	
	public static int solve(int n, int[] value, int[] cost) {
		int result = 0;
		
		for(int i = 0; i < n; i++) {
			if((value[i] - cost[i]) > 0) {
				result += value[i] - cost[i];
			}
		}
		
		return result;
	}

}

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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	
	int ok_case = n - m;
	double bility = pow((double)2.0, (double)m);
	long long warst = 1900 * bility;
	
	long long answer = (100 * ok_case + m * 1900) * bility;
	
	cout << answer << endl;

	return 0;
}

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

vector<set<int>> graph;
vector<int> visited;
int sz;

void dfs(int u) {
	if (!visited[u]) {
		visited[u] = 1;
		++sz;
	}
	for (auto v : graph[u]) {
		if (!visited[v]) {
			dfs(v);
		}
	}
}

int main() {
	int n, m, u, v;
	cin >> n >> m;

	graph = vector<set<int>> (n, set<int>());
	for (int i = 0; i < m; ++i) {	
		cin >> u >> v;
        u--; v--;
		graph[u].insert(v);
		graph[v].insert(u);
	}

	visited = vector<int> (n);
	int groups = 0;
	for (int i=0; i<n; i++) {
		sz = 0;
		if (!visited[i]) {
			dfs(i);
		}
		groups = max(groups, sz);
	}

	cout << groups << endl;

	return 0;

}


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

using namespace std;

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

    int n, m;
    cin >> n >> m;

    vector<int> a[n+1];

    for(int i=0; i<m; i++)
    {
        int j, k;
        cin >> j >> k;
        a[j].push_back(k);
        a[k].push_back(j);
    }

    bool yes = false;

    vector<int>::iterator it = find(a[1].begin(),a[1].end(),n);
    if(it != a[1].end())
    {
        cout << "POSSIBLE" << endl;
        yes = true;
    }
    else
    {
        int size = a[1].size();
        sort(a[n].begin(), a[n].end());
        vector<int>::iterator it = a[1].begin();
        for(; size > 0 ; it++,size--)
        {
            if(binary_search(a[n].begin(), a[n].end(), *it))
            {
                cout << "POSSIBLE" << endl;
                yes = true;
                break;
            }
        }
    }

    if(!yes) cout << "IMPOSSIBLE" << endl;

    return 0;
}


Measured memory_bytes: 12016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
const int mod=1000000007,MAX=2000005,INF=1<<30;

ll inv[MAX],fac[MAX],finv[MAX];

void make(){
    
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    
    for(int i=2;i<MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll)i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
    
}

ll comb(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*(finv[b]*finv[a-b]%mod)%mod;
}

ll perm(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*finv[a-b]%mod;
}

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    make();
    int K;cin>>K;
    string S;cin>>S;
    
    ll ans=0;
    
    for(int i=0;i<=K;i++){
        ans+=rui(25,K-i)*comb(K-i+si(S)-1,si(S)-1)%mod*rui(26,i)%mod;
        ans%=mod;
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 51144
#include<stdio.h>
#define N 100
int main(){
  int ary[N];
  int i,j,n,minj,tmp,count=0,flag=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&ary[i]);
  }
  for(i=0;i<n-1;i++){
    minj=i;
    for(j=i+1;j<n;j++){
      if(ary[j]<ary[minj]){
	minj=j;
	flag=1;
      }
    }
    tmp=ary[i];
    ary[i]=ary[minj];
    ary[minj]=tmp;
    if(flag==1){
      count++;
    }
    flag=0;
  }
  for(i=0;i<n;i++){
    if(i>0)printf(" ");
    printf("%d",ary[i]);
  }
  printf("\n%d\n",count);
}



Measured memory_bytes: 2084
#include<stdio.h>
int main()
{
    int x,i=0,count=0;
    scanf("%d",&x);
    char a[x+1];
   scanf("\n");
   gets(a);
    while(i<x)
    {
        if(a[i]=='A'&&a[i+1]=='B'&&a[i+2]=='C')
        {
            count++;
            i+=3;
        }
        else
            i++;
    }
    printf("%d",count);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  if ((a + b) % 2 == 0){
    cout << (a + b) / 2 << endl;
  }
  else{
    cout << (a + b) / 2 + 1<< endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

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

const int mod = 1e9 + 7;
const int mod2 = 998244353;

void fact_init(int n);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll komb(ll a, ll b);

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
	fact.resize(n+5);
	inv_fact.resize(n+5);
	fact[0] = inv_fact[0] = 1;
	for(int i = 1; i <= n; i++){
		fact[i] = (fact[i-1] * i) % mod;
		inv_fact[i] = exp(fact[i], mod-2, mod);
	}
}
ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
	if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll komb(ll a, ll b){
	if(a < b) return 0;
	return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}

const int N = 4e5 + 5;

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	vector<int> vec(n);
	for(auto &x: vec) cin>>x;
	RSORT(vec);
	ll ans = vec[0];
	int cnt = n-2;
	for(int i = 1; i < n-1 && cnt; i++){
		ans += vec[i];
		cnt--;
		if(cnt == 0) break;
		ans += vec[i];
		cnt--;
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 3984
#include <iomanip>
#include <iostream>
#include <vector>

int main() {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> p(n);
  for (int i=0; i<n; i++) {
    std::cin >> p.at(i);
  }
  
  double res = 0.0, tmp = 0.0;
  for (int i=0; i<k; i++) {
    tmp += (p.at(i) + 1) / 2.0;
  }
  res = tmp;
  for (int i=k; i<n; i++) {
    tmp += (p.at(i) + 1) / 2.0 - (p.at(i-k) + 1) / 2.0;
    if (tmp > res) {
      res = tmp;
    }
  }
  
  std::cout << std::fixed << std::setprecision(10) << res << std::endl;
  return 0;
}

  

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<ll, ll>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    //if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n; cin >> n;
  vector<vector<int>> a(n, vector<int>(n-1));
  rep(i, n) rep(j, n-1) {
    cin >> a[i][j];
    --a[i][j];
  }
  vector<int> now(n, 0);
  vector<bool> yesterday(n, true);

  for(int day = 0;;++day) {
    vector<bool> f(n, false);
    bool update = false;
    rep(i, n) {
      if(!yesterday[i]) continue;
      int j = a[i][now[i]];
      if(f[i] || f[j]) continue;
      if(now[i] == n-1 || a[j][now[j]] != i) {
        yesterday[i] = false;
        continue;
      }
      update = true;
      ++now[i];
      ++now[j];
      yesterday[i] = true;
      yesterday[j] = true;
      f[i] = true;
      f[j] = true;
    }
    if(!update) {
      rep(i, n) if(now[i] != n-1) {
        cout << -1 << endl;
        return 0;
      }
      cout << day << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 4224
#include<stdio.h>
#define N 1000

void swap(int a[],int x,int y){
	int temp=a[x];
	a[x]=a[y];
	a[y]=temp;
	return;
}

int main(){
	int n,q,i,b,e,t;
	int a[N];
	
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d %d %d",&b,&e,&t);
		for(int j=0;j<(e-b);j++){
			swap(a,b+j,t+j);
		}
	}
	
	for(i=0;i<n-1;i++){
		printf("%d ",a[i]);
	}
	printf("%d\n",a[n-1]);
	
	return 0;
	
}


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

using namespace std;

const int N=200010,M=524444,mo=1e9+7;

typedef long long LL;

int n,a[N],cnt[N],s0[N],s1[N],p0[N],p1[N],ans,Inv,t[M],tag[M];

vector <int> A[N];

int quick(int x,int y)
{
	int s=1;
	for (int i=1;i<=y;i<<=1,x=(LL)x*x%mo) if (i&y) s=(LL)s*x%mo;
	return s;
}

void pushdown(int x)
{
	if (tag[x]==1) return;
	tag[x<<1]=(LL)tag[x<<1]*tag[x]%mo; t[x<<1]=(LL)t[x<<1]*tag[x]%mo;
	tag[x<<1|1]=(LL)tag[x<<1|1]*tag[x]%mo; t[x<<1|1]=(LL)t[x<<1|1]*tag[x]%mo;
	tag[x]=1;
}

void Ins(int l,int r,int g,int v,int x)
{
	if (l==r)
	{
		t[x]=v; return;
	}
	pushdown(x);
	int mid=l+r>>1;
	if (g<=mid) Ins(l,mid,g,v,x<<1);else Ins(mid+1,r,g,v,x<<1|1);
	t[x]=(t[x<<1]+t[x<<1|1])%mo;
}

int calc(int l,int r,int g,int x)
{
	if (r==g) return t[x];
	pushdown(x);
	int mid=l+r>>1;
	if (g<=mid) return calc(l,mid,g,x<<1);
	return (calc(mid+1,r,g,x<<1|1)+t[x<<1])%mo;
}

int main()
{
	scanf("%d",&n); Inv=quick(2,mo-2);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]); cnt[a[i]]++;
		A[a[i]].push_back(i);
	}
	for (int i=n;i;i--) cnt[i]+=cnt[i+1];
	for (int i=n;i;i--) cnt[i]-=n-i;
	s0[n+1]=s1[n+1]=p0[0]=p1[0]=1;
	for (int i=1;i<=n;i++)
	{
		p0[i]=(LL)p0[i-1]*cnt[i]%mo;
		p1[i]=(LL)p1[i-1]*(cnt[i]-1)%mo;
	}
	for (int i=n;i;i--)
	{
		s0[i]=(LL)s0[i+1]*cnt[i]%mo;
		s1[i]=(LL)s1[i+1]*(cnt[i]-1)%mo;
	}
	
	for (int i=1;i<M;i++) tag[i]=1;
	for (int j=1;j<=n;j++)
	{
		sort(A[j].begin(),A[j].end());
		tag[1]=(LL)tag[1]*(cnt[j]-1)%mo;
		t[1]=(LL)t[1]*(cnt[j]-1)%mo;
		for (int i=0;i<A[j].size();i++)
		{
			int s=calc(1,n,A[j][i],1);
			ans=(ans+(LL)s*s0[j+1]%mo*Inv)%mo;
			Ins(1,n,A[j][i],p0[j],1);
		}
	}
	//<=
	
	for (int i=1;i<M;i++) tag[i]=1,t[i]=0;
	for (int j=n;j;j--)
	{
		for (int i=A[j].size()-1;i>=0;i--)
		{
			int s=calc(1,n,A[j][i],1);
			ans=(ans-(LL)s*p0[j]%mo*Inv)%mo;
			Ins(1,n,A[j][i],s0[j+1],1);
		}
		tag[1]=(LL)tag[1]*(cnt[j]-1)%mo;
		t[1]=(LL)t[1]*(cnt[j]-1)%mo;
	}
	for (int i=1;i<M;i++) tag[i]=1,t[i]=0;
	for (int j=n;j;j--)
	{
		for (int i=A[j].size()-1;i>=0;i--)
		{
			int s=calc(1,n,A[j][i],1);
			ans=(ans+s)%mo;
			Ins(1,n,A[j][i],p0[n],1);
		}
	}
	//>
	if (ans<0) ans+=mo;
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 19968
#Sの文字数分、Sの先頭を後ろに持っていき、Tと一致するか確認する
#(問題では後ろの数字を前に持ってきていましたが、
# こちらの方がシンプルになると思ったので、先頭を後ろに持ってきています。)

#入力値読み込み
S = str(input())
T = str(input())

#Sの文字数分、Sの先頭の文字を最後尾に持っていく
for i in S:
    S = S[1::] + S[0]
    
    #もしSとTが一致したらYes, break
    if S == T:
        print('Yes')
        break
#もしBreakが起こらなかったらNo
else:
    print('No')

Measured memory_bytes: 3060
s1 = input()
s2 = input()
dp = [[i+j for j in range(len(s2)+1)] for i in range(len(s1)+1)]

for i in range(len(s1)):
    for j in range(len(s2)):
        dp[i+1][j+1] = min(dp[i][j+1] + 1, dp[i+1][j] + 1, dp[i][j] + 1 * (s1[i] != s2[j]))
print(dp[len(s1)][len(s2)])

Measured memory_bytes: 46572
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int A = 0;
  
  for (int i = 0; i < N; i++){
    int l, r;
    cin >> l >> r;
    
    A += r - l +1;
  }
  
  cout << A << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h = in.nextInt();
            int w = in.nextInt();
            char[] s = new char[w + 2];
            Arrays.fill(s, '#');
            out.println(new String(s));
            for (int i = 0; i < h; i++) {
                out.println('#' + in.nextLine() + '#');
            }
            out.println(new String(s));
        }

    }

    static class InputReader {
        StringTokenizer st;
        BufferedReader br;

        public InputReader(InputStream is) {
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            this.br = br;
        }

        public String next() {
            if (st == null || !st.hasMoreTokens()) {
                String nextLine = null;
                try {
                    nextLine = br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (nextLine == null)
                    return null;
                st = new StringTokenizer(nextLine);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String nextLine() {
            String str = null;
            try {
                str = br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return str;
        }

    }
}



Measured memory_bytes: 22740
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <stack>
#include <string>
#include <fstream>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int N;
int A[200000];
int L[200000];
int R[200000];
int main(){
  cin>>N;
  FOR(i,0,N){
    cin>>A[i];
  }
  VE V;
  FOR(i,0,N){
    while(!V.empty()&&A[V.back()]>A[i]){
      V.pop_back();
    }
    if(V.empty()){
      L[i]=0;
    }else{
      L[i]=V.back()+1;
    }
    V.PB(i);
  }
  V.clear();
  ROF(i,0,N){
    while(!V.empty()&&A[V.back()]>A[i]){
      V.pop_back();
    }
    if(V.empty()){
      R[i]=N-1;
    }else{
      R[i]=V.back()-1;
    }
    V.PB(i);
  }
  LL ans=0;
  FOR(i,0,N){
    ans+=(LL)A[i]*(i-L[i]+1)*(R[i]-i+1);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3448
#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int mod = 1000000007;
const int mod2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> a(n+1),b(n);
    cin >> a >> b;
    ll ans = 0;
    for(int i = 0;i<n;i++){
        ll sub = min(a[i],b[i]);
        ans += sub;
        a[i] -= sub;
        b[i] -= sub;
        
        sub = min(b[i],a[i+1]);
        ans += sub;
        b[i] -= sub;
        a[i+1] -= sub;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3944
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
using namespace std;
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

template <int32_t MOD>
struct mint {
    int64_t value;
    mint() = default;
    mint(int64_t value_) : value(value_) {}
    inline mint<MOD> operator + (mint<MOD> other) const { int64_t c = this->value + other.value; return mint<MOD>(c >= MOD ? c - MOD : c); }
    inline mint<MOD> operator * (mint<MOD> other) const { int64_t c = this->value * int64_t(other.value) % MOD; return mint<MOD>(c < 0 ? c + MOD : c); }
    inline mint<MOD> & operator += (mint<MOD> other) { this->value += other.value; if (this->value >= MOD) this->value -= MOD; return *this; }
    inline mint<MOD> & operator *= (mint<MOD> other) { this->value = this->value * int64_t(other.value) % MOD; if (this->value < 0) this->value += MOD; return *this; }
    inline mint<MOD> operator - () const { return mint<MOD>(this->value ? MOD - this->value : 0); }
    mint<MOD> pow(uint64_t k) const {
        mint<MOD> x = *this, y = 1;
        for (; k; k >>= 1) {
            if (k & 1) y *= x;
            x *= x;
        }
        return y;
    }
    mint<MOD> inv() const { return pow(MOD - 2); }  // MOD must be a prime
};

constexpr int MOD = 1e9 + 7;
mint<MOD> solve(int n, int q, vector<int> const & a, vector<int> const & x, vector<int> const & y) {
    auto dp = vectors(n, n, mint<MOD>());
    REP (i, n) REP (j, n) {
        dp[i][j] = (a[i] > a[j]);
    }

    const auto half = mint<MOD>(2).inv();
    REP (t, q) {
        int i = x[t];
        int j = y[t];
        dp[i][j] = dp[j][i] = (dp[i][j] + dp[j][i]) * half;
        REP (k, n) if (i != k and j != k) {
            dp[k][i] = dp[k][j] = (dp[k][i] + dp[k][j]) * half;
            dp[i][k] = dp[j][k] = (dp[i][k] + dp[j][k]) * half;
        }
    }

    mint<MOD> acc = 0;
    REP (i, n) REP3 (j, i, n) {
        acc += dp[i][j];
    }
    return acc * mint<MOD>(2).pow(q);
}

int main() {
    int n, q; cin >> n >> q;
    vector<int> a(n);
    REP (i, n) cin >> a[i];
    vector<int> x(q), y(q);
    REP (i, q) {
        cin >> x[i] >> y[i];
        -- x[i];
        -- y[i];
    }
    cout << solve(n, q, a, x, y).value << endl;
    return 0;
}


Measured memory_bytes: 72704
a1, b1 = input().split()
a2, b2 = input().split()
a3, b3 = input().split()

l = [a1, a2, a3, b1, b2, b3]

if len(list(set(l))) != 4:
    print("NO")
else:
    count_list = sorted([str(l.count(str(i))) for i in range(1, 5)])
    if "".join(count_list) == "1122":
        print("YES")
    else:
        print("NO")

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

// in-short-use macros

#define all(c) (c).begin(),(c).end()
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define PI 3.14159265
#define sizes 1000010



//main function here

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   
    ll x;
    cin>>x;
    map<ll,ll> ma,invma;
    for(ll i=0;i<=1000;i++)
    {
        ma[i]=i*i*i*i*i;
        invma[i*i*i*i*i]=i;
    }
    ll a=0,b=0;
    for(auto e:ma)
    {
        ll el=abs(x-e.ss);
        // cout<<e.ff<<" "<<e.ss<<"\n";
        if(invma.find(el)!=invma.end())
        {
            a = e.ff;
            b= invma[el];
            if(a>b)
                swap(a,b);
            break;
        }
    }
    if(b*b*b*b*b - a*a*a*a*a==x)
        cout<<b<<" "<<a<<"\n";
    else if(b*b*b*b*b + a*a*a*a*a ==x) 
        cout<<b<<" "<<-a<<"\n";
    // cout<<a<<" "<<b<<"\n";
    return 0;
}

Measured memory_bytes: 3716
S = input()

b_l = 10**9
w_poslist = []
for i in range(len(S)):
    s = S[i]
    if s == "B" and i < b_l:
        b_l = i
    if s == "W":
        w_poslist.append(i)
if b_l == 10**9:
    print(0)
else:
    ans = 0
    for i in range(len(w_poslist)):
        if w_poslist[i] < b_l:
            continue
        ans += w_poslist[i] - b_l
        b_l += 1
    print(ans)


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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;


#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;



int main() {
  ll n,k;
  ci(n>>k);
  ll count=1;
  ll ans=1;
  
  FOR(i,0,n){
    if(count<k){
      ans*=2;
      count*=2;
    }
    else{
      ans+=k;
    }
  }
  co(ans)
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;
ll INF = 9999999999999999;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll max(ll a, ll b){
    if(a > b) return a;
    else return b;
}
 
ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}
 
int main(void){
    int K,X; cin >> K >> X;
    
    ll Min = max(-1000000, X-K+1);
    ll Max = min(1000000, X+K-1);
    for(int i = Min; i <= Max; i++){
        cout << i << ' ';
    }
}

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

typedef long long ll;
typedef unsigned long long ull;

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

  double x = double(n) / 1.08;
  double xf = floor(x);
  ll n2 = floor(xf * 1.08);
  double xc = ceil(x);
  ll n3 = floor(xc * 1.08);

  if (n == n2) {
    cout << ll(xf) << endl;
  } else if (n == n3) {
    cout << ll(xc) << endl;
  } else {
    cout << ":(" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
/*input
a
aa
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 
//change null_type to get ordered_map
#define N  100005
#define DEC(N)	cout << std::fixed; cout << setprecision(N);
void solve()
{
	string s,t;
	cin >> s >> t;
	s+=t.back();
	if(s==t){
		cout << "Yes" << endl;
	} 
	else{
		cout << "No" << endl;
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

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

int main() {

	int n;
	cin >> n;

	vector<int> integers;
	int max = 0;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		integers.push_back(tmp);
		if (max < tmp) max = tmp;
	}

	int half = max / 2, remarkable_point = 0;
	for (int i = 0; i < n; i++) {
		if (abs(integers[i] - half) < abs(remarkable_point - half))
			remarkable_point = integers[i];
	}
	cout << max << " " << remarkable_point << endl;

	return 0;
}


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout<< #i<< "= "<< i << endl
using namespace std;

int main(){
    int l,r,d,cnt = 0;
    cin >> l >> r >> d;

    FOR(i,l,(r+1)){
        if(i % d == 0) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3628
n,m = map(int,input().split())
x = [list(map(int,input().split())) for i in range(m)]
y = []
z = []

for k in range(m):
    y = y + x[k]

for l in range(1,n+1):
    z = z + [y.count(l)]
    
for p in z:
    print(p)

Measured memory_bytes: 9188
#include<bits/stdc++.h>
#define lln long long int
using namespace std;
int main()
{
    lln total=0;
    string s;
    cin>>s;
    for(int i=0; s[i]; i++)
    {
        total+=s[i]-'0';
    }
    if(total%9==0)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define ll long long
using namespace std;
int a,b;
int main(){
	cin>>a>>b;
	double a1,a2,b1,b2;
	a1=(double)a/0.08;
	a2=(double)(a+1)/0.08;
	b1=(double)b/0.1;
	b2=(double)(b+1)/0.1;
	double ans=max(a1,b1);
	double ans1=min(a2,b2);
	if(ans>=ans1)
		cout<<"-1"<<endl;
	else
		cout<<ceil(ans)<<endl;
	return 0;
} 

Measured memory_bytes: 256
def get_gcd(a, b): 
    if a < b:
        a, b = b, a
    if a % b == 0:
        return b
    else:
        return get_gcd(b, a % b)
        
def get_lcm(a, b, gcd):
    lcm = a * b // gcd
    return lcm 


N=int(input())

a=int(input())

for i in range(N-1):
    b=int(input())
    a=get_lcm(a,b,get_gcd(a,b))

print(a)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vs vector<string>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 10000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

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

    cout<<(n*(n-1)/2) + (m*(m-1)/2)<<endl;
} 

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

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

    std::vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> a[i];
    }
    
    std::sort(a.begin(), a.end(), std::greater<int>());

    int alice = 0;
    int bob = 0;
    for (int i = 0; i < N; ++i) {
        if (i % 2 == 0) {
            alice += a[i];
        } else {
            bob += a[i];
        }
    }

    const int ret = alice - bob;

    std::cout << ret << std::endl;
}


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

ll a[100005];

int main(){
    int n;
    ll t;

    cin >> n >> t;

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

    ll smll=1e9+5, def=0, memo=0, memo2=1e9+5;
    for (int i=0; i<n; i++){
        if (a[i] < smll){ 
            smll = a[i];
        }
        else if (def < a[i]-smll){ 
            def =  a[i]-smll;
            memo2 = memo;
            memo = 1;
            }
        else if (def == a[i]-smll) memo += 1;
            
    }
    memo2 = memo;

    cout << memo2 << endl;

    return 0;
}

Measured memory_bytes: 1024