akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int n,k,id;
int main()
{
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		int a;
		scanf("%d",&a);
		if(a==1)
			id=i;
	}
	printf("%d\n",(n-1+k-2)/(k-1));
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    string s; cin >> s;
    int n = s.size();
    vector<ll> v(n);
    REP(i, n) v[i] = s[i]-'0';
    // set<ll> S;
    ll ans = 0;
    REP(i, 1<<(n-1)) {
        ll val = 0;
        ll sum = 0;
        REP(j, n) {
            val = val*10 + v[j];
            if ((i & (1 << j)) || j == n-1) {
                sum += val;
                val = 0;
            }
        }
        ans += sum;
        // S.insert(sum);
    }
    // EACH(i, S) {
    //     // cout << i << endl;
    //     ans += i;
    // }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while(true) {
			int a = scan.nextInt();
			String op = scan.next();
			int b = scan.nextInt();
			if (op.equals("?")) {
				break;
			}
			else if (op.equals("+")) {
				System.out.println(a+b);
			}
			else if (op.equals("-")) {
				System.out.println(a-b);
			}
			else if (op.equals("*")) {
				System.out.println(a*b);
			}
			else if (op.equals("/")) {
				System.out.println(a/b);
			}
		}
	}
}


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

int main()
{
  string s, t;
  cin >> s >> t;
  
  string ans = "NO";
  if (s.at(0) == t.at(2) && s.at(1) == t.at(1) 
      && s.at(2) == t.at(0)) ans = "YES";
  
  cout << ans << endl;
}

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

using namespace std;

int n, m, c, ans;
vector<pair<int, int>> a;

int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int l, r;
    cin >> l >> r;
    a.emplace_back(l, 1);
    a.emplace_back(r + 1, -1);
  }
  sort(a.begin(), a.end());
  for (int i = 1, j = 0; i <= n; ++i) {
    while (j < a.size() && a[j].first <= i)
      c += a[j++].second;
    if (c == m) ++ans;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
using namespace std;
const int mod = 100000;
int main() {
    while (true) {
        int n, m, s; cin >> n >> m >> s;
        if (n == 0 and m == 0 and s == 0) break;
        vector<vector<int> > dp(n*n+1, vector<int>(s+1));
        dp[0][0] = 1;
        repeat (i,m) {
            repeat_reverse (j,n*n) {
                repeat (k,s-i) {
                    dp[j+1][k+(i+1)] += dp[j][k];
                    dp[j+1][k+(i+1)] %= mod;
                }
            }
        }
        cout << dp[n*n][s] << endl;
    }
    return 0;
}

Measured memory_bytes: 3288
import sys
sys.setrecursionlimit(1000000) # 再帰上限を増やす

def main():
    input = sys.stdin.readline  # 文字列に対してinputした場合は、rstripするのを忘れずに！
    N, W = map(int, input().rstrip().split())
    item_list = []
    for _ in range(N):
        w, v = map(int, input().rstrip().split())
        item_list.append((w, v))

    # dp[i][v] = i番目まで見て価値vを達成できる最小の重さ
    dp = [[float("inf")] * (100001) for _ in range(N+1)]
    dp[0][0] = 0

    max_value = 0
    for i, item in enumerate(item_list, 1):
        for v in range(100001):
            # もし品物iが入れられる
            if dp[i-1][v] + item[0] <= W:
                dp[i][v+item[1]] = min(dp[i][v+item[1]], dp[i-1][v]+item[0])
                max_value = max(max_value, v+item[1])
            # 入れないパターン
            dp[i][v] = min(dp[i][v], dp[i-1][v])
    print(max_value)

if __name__ == '__main__':
    main()

Measured memory_bytes: 312488
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define at(x,i) get<i>(x);
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
int main(){
  string s;cin >> s;
  ll k;cin >> k;
  set<string> set;
  char x='z';
  ll sz=s.size();
  rep(i,sz)chmin(x,s[i]);
  bool check=true;
  while(check){
    rep(i,sz){
      if(x==s[i]){
        rep(j,5){
          if(i+j<sz){
            set.ins(s.substr(i,j+1));
          }
        }
      }
    }
    if(set.size()>=k)check=false;
    x++;
  }
  ll cnt=0;
  for(auto p:set){
    cnt++;
    if(cnt==k){
      cout << p <<endl;
      return 0;
    }
  }
}


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

using namespace std;

/*****************MACRO*****/

#define ll long long
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

/*******CONSTANT***********/
#define INF (1<<30) //infinity value
#define EPS 1e-9
#define MOD 10000007
#define SIZ 1005
#define PI (acos(-1))


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

    int n;
    cin>>n;
    int arr[n];
    for(int i=0; i<n; i++) cin>>arr[i];

    int soFarMin = arr[0];
    int cnt= 1;
    for(int i=1; i<n; i++){
        if(arr[i]<=soFarMin) cnt++; // cout<<"CNt increasing: soMin="<<soFarMin<<" a[i]="<<arr[i]<<"\n";;
        if(arr[i]<soFarMin) soFarMin= arr[i];

        //cnt++;
    }
    cout<<cnt<<"\n";
    return 0;
}

/**********************************************************************************







*************************************************************************************/


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

using namespace std;

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

    unordered_set<int> L;
    vector<bool> C(N);
    for(int i=0; i<N; i++){
        auto it = L.find(K[i]+1);
        if(it != L.end()){
            C[K[i]-1] = true;
        }
        else{
            C[K[i]-1] = false;
        }
        L.insert(K[i]);
    }

    int max = 1;
    for(int i=1; i<=N; i++){
        int count = 1;
        int last = i;
        for(int j=i; j<=N; j++){
            if(!C[j-1] && j!=N){
                last++;
                count++;
                if(count > max){
                    max = count;
                }
            }
            else{
                i = j;
                break;
            }
        }
    }

    cout << (N-max) << endl;
}


Measured memory_bytes: 9288
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)








int main() {
    ll n;
    cin >> n;
    vector<ll> b(n);
    REP(i, n){
        cin >> b[i];
    }
    vector<ll> ans(n);
    REP(i, n){
        ll idx = -1;
        REP(j, n - i){
            if(b[j] == j + 1){
                idx = j;
            }
        }
        if(idx == -1){
            cout << -1 << endl;
            return 0;
        }
        ans[i] = idx + 1;
        for(ll j = idx; j < n - 1 - i; j++){
            b[j] = b[j + 1];
        }
    }
    reverse(ans.begin(), ans.end());
    REP(i, n){
        cout << ans[i] << endl;
    }
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> x(n);
  int ans=1000000000;


  for(int i=0; i<n; i++)
  {
    cin >> x.at(i);
  }

  sort(x.begin(), x.end());

  for(int i=x.at(0); i<=x.at(x.size()-1); i++)
  {
    int tmp=0;
    for(int j=0; j<n; j++)
    {
      tmp+=(x.at(j)-i)*(x.at(j)-i);
    }
    ans=min(ans, tmp);
  }

  cout << ans << endl;
}

Measured memory_bytes: 3624
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
manzoku=0
for i in range(n):
    manzoku+=b[a[i]-1]
for i in range(n-1):
    if a[i+1]-a[i]==1:
        manzoku+=c[a[i]-1]
print(manzoku)

Measured memory_bytes: 3064
#include<iostream>

int main() {

	int N;
	std::cin >> N;
	int res = 0;


	for (int i = 0; i < 15; i++) {
		for (int j = 0; j < 26; j++) {
			if ((7 * i + 4 * j) == N) {
				res++;
				//break;
			}
		}
	}

	if (res >0 )std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;

}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  for (int i=0; i<N; i++) {
    cin >> B[i];
  }
  for (int i=0; i<N-1; i++) {
    cin >> C[i];
  }
  
  int S=0;
  for (int i=0; i<N; i++) {
    S += B[A[i]-1];
    if (i==N-1) {continue;}
    if (A[i] + 1 == A[i+1]) {
      S += C[A[i]-1];
    }
  }
  cout << S << endl;
}

Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lec11A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] array = new int[n];
            for (int i = 0; i < n; i++)
            {
                Clean(array, n);
                string input = Console.ReadLine();
                string[] split = input.Split(' ');
                for ( int j = 0;j <  split.Length -2; j++)
                {
                    int m = int.Parse(split[j+2]);
                    array[m-1]=1;
                }              
     

                for(int index =0;index < n;index++)
                {
                    Console.Write(array[index]);
                    if (index != n-1){
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
            }
            Console.ReadLine();
            Console.ReadLine();
        }

        static void Clean(int[] A, int n)
        {
            for (int i = 0; i < n; i++)
            {
                A[i] = 0;
            }
        }
    }
}



Measured memory_bytes: 20008
object Main{
  def main(args: Array[String]){
    val in = new java.util.Scanner(System.in)
    val a = in.nextInt
    var count = 0;
 
    var arr = new Array[Int](a)
    for(i <- 0 to a-1){
      arr(i) = in.nextInt
    }
 
    for(i <- 0 to a-2){
      var minpos = i;
      var minval = arr(i);
 
      for(j <- i+1 to a-1){
        if(arr(j) < minval){
          minpos = j;
          minval = arr(j)
        }
      }
 
      if(minpos != i){
        var tmp = arr(minpos)
        arr(minpos) = arr(i)
        arr(i) = tmp
        count = count + 1
      }
    }
 
    println(arr.mkString(" "))
    println(count)
  }
}

Measured memory_bytes: 45188
#include<iostream>
#include<math.h>
#define rep(i,n) for(i = 0; i < n; i++)
using namespace std;

int main() {
	int n, i;
	long long ans = 0;
	cin >> n;
	int b[100001];
	rep(i, n - 1) cin >> b[i];
	ans += b[0];
	for (int i = 0; i < n - 2; i++) {
		ans += (int)fmin(b[i], b[i + 1]);
	}
	ans += b[n - 2];
	cout << ans << endl;
}

Measured memory_bytes: 256
/*
PROG: agc26b
LANG: C++11
    _____
  .'     '.
 /  0   0  \
|     ^     |
|  \     /  |
 \  '---'  /
  '._____.'
 */
#include <bits/stdc++.h>

using namespace std;

template<class T>
void readi(T &x)
{
	T input = 0;
	bool negative = false;
	char c = ' ';
	while (c < '-')
	{
		c = getchar();
	}
	if (c == '-')
	{
		negative = true;
		c = getchar();
	}
	while (c >= '0')
	{
		input = input * 10 + (c - '0');
		c = getchar();
	}
	if (negative)
	{
		input = -input;
	}
	x = input;
}
template<class T>
void printi(T output)
{
	if (output == 0)
	{
		putchar('0');
		return;
	}
	if (output < 0)
	{
		putchar('-');
		output = -output;
	}
	int aout[20];
	int ilen = 0;
	while(output)
	{
		aout[ilen] = ((output % 10));
		output /= 10;
		ilen++;
	}
	for (int i = ilen - 1; i >= 0; i--)
	{
		putchar(aout[i] + '0');
	}
	return;
}
template<class T>
void ckmin(T &a, T b)
{
	a = min(a, b);
}
template<class T>
void ckmax(T &a, T b)
{
	a = max(a, b);
}
long long randomize(long long mod)
{
	return ((1ll << 30) * rand() + (1ll << 15) * rand() + rand()) % mod;
}

#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second

const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-10;

#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll

long long normalize(long long x, long long mod = INF)
{
	return (((x % mod) + mod) % mod);
}

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

int T;
ll A, B, C, D;
set<ll> seen;

ll gcd(ll a, ll b)
{
	return b == 0 ? a : gcd(b, a % b);
}

int32_t main()
{
	ios_base::sync_with_stdio(0); 
	srand(time(0));
	//	cout << fixed << setprecision(10);	
	//	cerr << fixed << setprecision(10);
	if (fopen("agc26b.in", "r"))
	{	
		freopen ("agc26b.in", "r", stdin);
		//	freopen ("agc26b.out", "w", stdout);
	}
	cin >> T;
	while(T--)
	{
		cin >> A >> B >> C >> D;
		if (A < B || D < B)
		{
			cout << "No\n";
			continue;
		}
		if (C + 1 >= B)
		{
			cout << "Yes\n";
			continue;
		}
		//				cout << A << ' ' << B << ' ' << C << ' ' << D << endl;
		//C+1...B-1
		ll g = gcd(B, D);
		bool flag = true;
//					for (int i = C + 1; i <= B - 1; i++)
//					{
//						if ((A - i) % (g) == 0)
//						{
//							flag = false;
//						}
//					}
		//C+1...B-1
		if (B - 1 - (C + 1) + 1 >= g)
		{
			flag = false;
		}
		ll lo = (C + 1) % g, hi = (B - 1) % g;
		if (lo > hi)
		{
			if (A % g >= lo || A % g <= hi)
			{
				flag = false;
			}
		}
		else
		{
			if (lo <= A % g && A % g <= hi)
			{
				flag = false;
			}
		}
		cout << (flag ? "Yes\n" : "No\n");
		//			cout << "start " << A << " want " << C + 1 << "..." << B-1 << " delta " << D << endl;
		//			cout << "No\n";
	}
	return 0;
//	cerr << "time elapsed = " << (clock() / (CLOCKS_PER_SEC / 1000)) << " ms" << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int cnt[100001];
int main(){
    int n,m;
    cin >> n >> m;
    for(int i = 0 ; i < m ; i++){
        int l,r;
        cin >> l >> r;
        cnt[l] += 1;
        cnt[r + 1] -= 1;
    }
    int ans = 0,cur = 0;
    for(int i = 1 ; i <= n ; i++){
        cur += cnt[i];
        if(cur == m) ans++;
    }
    cout << ans;
}

Measured memory_bytes: 640
import java.util.*;
import java.lang.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        while (true) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            
            if (h == 0 && w == 0) {
                break;
            }
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (i == 0 || i == h - 1 ||
                        j == 0 || j == w - 1) {
                        System.out.print("#");
                    } else {
                        System.out.print(".");
                    }
                }
                System.out.println("");
            }
            System.out.println("");
        }
        
        
    }
}



Measured memory_bytes: 34580
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

int main() {
  ll n, m;
  cin >> n >> m;
  n -= 2;
  m -= 2;
  ll anser = abs(n * m);
  cout << anser << endl;
  return 0;
}

Measured memory_bytes: 384
N,A,B,C=gets.split.map(&:to_i)
S=N.times.map{gets.chop}
n=(?A..?C).zip([A,B,C]).to_h
ans=[]
N.times do |i|
  x,y=S[i].chars
  x,y=y,x if n[x]>n[y]
  x,y=y,x if n[x]==1 && n[y]==1 && i+1<N && S[i+1].include?(y)
  n[x]+=1
  n[y]-=1
  ans<<x
  next if 0<=n[y]
  puts :No
  exit 0
end
puts :Yes, ans


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int c[3][3];
    rep(i, 3)rep(j, 3) {
        cin >> c[i][j];
    }
    bool ok = true;
    if (c[0][1] - c[0][0] != c[1][1] - c[1][0] || c[1][1] - c[1][0] != c[2][1] - c[2][0]) ok = false;
    if (c[0][1] - c[0][2] != c[1][1] - c[1][2] || c[1][1] - c[1][2] != c[2][1] - c[2][2]) ok = false;
    if (c[1][0] - c[0][0] != c[1][1] - c[0][1] || c[1][1] - c[0][1] != c[1][2] - c[0][2]) ok = false;
    if (c[1][0] - c[2][0] != c[1][1] - c[2][1] || c[1][1] - c[2][1] != c[1][2] - c[2][2]) ok = false;
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int x = 7;
        int a = 0;

        if (S.equals("SUN")) {
            a = 0; 
        }
        else if (S.equals("MON")) {
            a = 1;
        }
        else if (S.equals("TUE")) {
            a = 2;
        }
        else if (S.equals("WED")) {
            a = 3;
        }
        else if (S.equals("THU")) {
            a = 4;
        }
        else if (S.equals("FRI")) {
            a = 5;
        }
        else if (S.equals("SAT")) {
            a = 6;
        }

        System.out.println(x - a);
    }
}

Measured memory_bytes: 20564
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int T, N, K;
string s;
int main(){
    int ans = 1;
    cin >> N >> K;
    int cnt = 0;
    while(cnt != N){
        ans = min(ans * 2, ans + K);
        cnt++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct point{
	string s;
	string path;
	int k;
	int i;
};
string s;
unordered_map<string,bool>vis;
queue<point> q;
int jb;
void solve(){
	point p;
	p.s=s;p.i=jb;p.k=0;
	q.push(p);
	while(!q.empty()){
		p=q.front();q.pop();
		string path=p.path;
		if(vis[p.s])continue;
		if(p.s=="123456780"){
			cout<<p.k<<"\n";
//			cout<<p.path<<"\n";
			exit(0);
		}
//		cout<<p.s<<endl;
		vis[p.s]=1;
		p.k+=1;
		if(p.k==5){
			p.k=p.k;
		}
		int i=p.i;
		if(i-3>=0){
			swap(p.s[i],p.s[i-3]);
			p.i=i-3;
			p.path=path+"u";
			q.push(p);
			swap(p.s[i],p.s[i-3]);
		}
		if(i-1>=0&&i%3!=0){
			swap(p.s[i],p.s[i-1]);
			p.i=i-1;
			p.path=path+"l";
			q.push(p);
			swap(p.s[i],p.s[i-1]);
		}
		if(i+3<9){
			swap(p.s[i],p.s[i+3]);
			p.i=i+3;
			p.path=path+"d";
			q.push(p);
			swap(p.s[i],p.s[i+3]);
		}
		if(i+1<9&&(i+1)%3!=0){
			swap(p.s[i],p.s[i+1]);
			p.i=i+1;
			p.path=path+"r";
			q.push(p);
			swap(p.s[i],p.s[i+1]);
		}
	}	
}
int main(){
//	freopen("a.txt","r",stdin);
//	freopen("b.txt","w",stdout);
	char tc;
	for(int i=0;i<9;i++){
		cin>>tc;
		if(tc=='0')jb=i;
		s+=tc;
	}
	solve();
	return 0;
}


Measured memory_bytes: 31340
x1, y1, x2, y2 = map(int, input().split())

x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)
x4 = x3 - (x2 - x1)
y4 = y3 - (y2 - y1)
print(x3, y3, x4, y4)


Measured memory_bytes: 2940
def Foods_Loved(n, m, kal):

    ans = 0

    for i in range(1, m+1):
        flag = True
        for ka in kal:
            if i not in ka[1:]:
                flag = False
        if flag:
            ans += 1

    return ans

def main():
    n, m = map(int, input().split())
    kal = [list(map(int, input().split())) for i in range(n)]
    print(Foods_Loved(n, m, kal))

if __name__ == '__main__':
    main()


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

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

    int ans = pow(10,9);
    for(int i=0; i<s.size(); i++){
        int cnt = 0;
        if(i+t.size() <= s.size()){
            for(int j=0; j<t.size(); j++){
                if(s[i+j] != t[j]) cnt++;
            }
            ans = min(ans, cnt);
        }else{
            break;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 3600
n,k=map(int,input().split())
mod=pow(10,9)+7
ans=[0]*(k+1)
# gcdがkiとなる数列。すべてがkiの倍数でかつ少なくとも一つkiを含む
for ki in range(k,0,-1):
    a=k//ki
    ans[ki]=pow(a,n,mod)
    i=2
    while i*ki<=k:
        ans[ki]-=ans[i*ki]
        i+=1
b=0
for ki in range(1,k+1):
    b+=(ans[ki]*ki)%mod
    b%=mod
print(b)


Measured memory_bytes: 68924
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int x = stdIn.nextInt();
		boolean flag = false;
		
		Outer:while(!flag) {
			for(int i = 2; i < x; i++) {
				if(x % i == 0) {
					x++;
					continue Outer;
				}
			}
			flag = true;
		}
		
		System.out.println(x);
				
				
	}

}


Measured memory_bytes: 21972
import bisect

N = int(input())
L = sorted(map(int, input().split()))

res = 0
for i in reversed(range(1, N)):
    for j in reversed(range(i)):
        index = bisect.bisect_left(L, L[i] + L[j])
        n = N - index
        res += (N - 1 - i) - n

print(res)


Measured memory_bytes: 3188
import java.util.*;

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

		int n = scan.nextInt();

		long hyo1 = 1, hyo2 = 1;

		for(int loop = 0; loop < n; loop++) {
			long t = scan.nextInt();
			long a = scan.nextInt();

			long value1 = (hyo2-1)/a+1;
			long value2 = (hyo1-1)/t+1;
			long value3 = Math.max(value1,value2);

			hyo1 = value3 * t;
			hyo2 = value3 * a;
		}

		System.out.println(hyo1+hyo2);
	}
}


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

int main(){
    int64_t s; cin >> s;
    const int64_t limit = 1e9;
    vector<pair<int64_t, int64_t>> x(3, {0, 0});
    x[1].first = limit; x[1].second = 1;
    x[2].second = (s + limit - 1) / limit;
    x[2].first = (limit * x[2].second - s) % limit;
    for (auto & elm : x) cout << elm.first << " " << elm.second << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public long MOD = 1000000007;

        public void Run()
        {
            N = Input.ReadInt();
            string A, B, C;
            A = Console.ReadLine();
            B = Console.ReadLine();
            C = Console.ReadLine();

            int ret = 0;
            for (int i = 0; i < N; i++)
            {
                char a = A[i];
                char b = B[i];
                char c = C[i];

                if (a == b && a == c)
                {
                    ret += 0;
                }
                else if (a == b || a == c || b == c)
                {
                    ret += 1;
                }
                else
                {
                    ret += 2;
                }
            }

            Console.WriteLine(ret);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13140
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	if (n < 1200) puts("ABC");
	else if (n < 2800) puts("ARC");
	else puts("AGC");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    if(n<=5) printf("0\n");
    else if(n>=13) printf("%d\n",m);
    else printf("%d\n",m/2);
    return 0;
}



Measured memory_bytes: 128
n = int(input())
v = list(map(int, input().split()))
def doit(vs):
    ret = {}
    for v in vs:
        ret[v] = ret.get(v, 0) + 1
    return sorted((-ret[v], v) for v in ret) + [(0, None)]
odd = doit(v[0::2])
even = doit(v[1::2])
if odd[0][1] != even[0][1]:
    print(n + odd[0][0] + even[0][0])
else:
    print(n + min(odd[1][0] + even[0][0], odd[0][0] + even[1][0]))

Measured memory_bytes: 66564
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll X;
    cin >>X;
    ll ans = 0;
    ll now = 100; 
    while(now<X){
        ans++;
        now = now + now/100;
    }
    
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
const int INF=1000000000;

int main(){
    string S;cin>>S;
    ll N=S.size();
    queue<ll> info;
    int check=0;
    if(S[0]=='<')check=1;
    char p=S[0];
    int count=0;
    rep(i,N){
        if(S[i]==p)count++;
        else{
            info.push(count);
            p=S[i];
            i--;
            count=0;
        }
    }
    if(S[N-2]==S[N-1])info.push(count);
    else info.push(1);
    ll ans[N+1];
    rep(i,N+1)ans[i]=0;
    ll i=0;
    while(info.size()){
        if(check){
            for(ll j=0;j<=info.front();j++)ans[i+j]=j;
            i+=info.front();
            info.pop();
            check=0;
        }
        else{
            for(ll j=info.front();j>=0;j--){
                if(j==info.front())ans[i+info.front()-j]=max(ans[i+info.front()-j],j);
                else ans[i+info.front()-j]=j;
            }
            i+=info.front();
            info.pop();
            check=1;
        }
    }
    ll sum=0;
    rep(i,N+1)sum+=ans[i];
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 6660
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;


int main()
{
	long long int i, j, k, l,c, m, n, o,N,M,K, p, sum, flag, cc, cnt;
	flag = 1;
	sum = 0;
	cin >> N >> K;
	vector<int>A(N);
	for (i = 0; i<N; i++) {
		cin >> A[i];
	}
	vector<long long int>B(N-K+1);
	for (i = 0; i < N-K+1; i++) {
		B[i] = fmin(abs(A[i]) + (A[K + i - 1] - A[i]), abs(A[K + i - 1]) + A[K + i - 1] - A[i]);
	}
	sort(B.begin(),B.end());
	cout << B[0] << endl;

    return 0;
}



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

string S;
int N, K;

int main() {
  cin >> S >> K;
  N = S.length();
  string o;
  for (int i=0; i<N; i++) {
    if (S[i] != 'a' && K >= '{'-S[i]) {
      int c = '{'-S[i];
      K -= c;
      o += 'a';
    }
    else {
      o += S[i];
    }
  }
  o[N-1] = (char)('a' + ((o[N-1]-'a'+K) % 26));
  cout << o << "\n";
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main() {
	int n, k, i;
	int integer = 1;
	scanf("%d %d", &n, &k);

	for(i=0; i<n; i++) {
		integer = (integer*2) < (integer+k) ? (integer*2) : (integer+k);
	}

	printf("%d\n", integer);

	return 0;
}


Measured memory_bytes: 128
while True:
    l=str(input())
    if l=="0": break
    A,B = 0,0
    for i in range(1,len(l)):
        if l[i]=="A":
            A+=1
        else:
            B+=1
    if A>B:
        A+=1
    else:
        B+=1
    print(A,B)


Measured memory_bytes: 5556
#include <bits/stdc++.h>
#define int long long int
#define double long double
#define mod 1000000007
#define PI 3.141592
#define w(t) int t; cin>>t; while(t--)
#define f(i,a,n) for( int i=a;i<n;i++)
#define pb push_back
#define pob pop_back
#define mk make_pair
#define ARMY ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
int dp[101][100001];
int solve(int *a,int n,int wt,int *w)
   {    
        if(n<0)
        {
        return 0;
        }
   
       if(wt<w[n])
       return solve(a,n-1,wt,w);
       if(dp[n][wt]!=0)
          return dp[n][wt];
         if(wt>=w[n])
         {
           return dp[n][wt]= max(a[n]+solve(a,n-1,wt-w[n],w),solve(a,n-1,wt,w));
         }          
   }



int32_t main()
  {

  int n,wt;
  cin>>n>>wt;
  int a[n],b[n];
  f(i,0,n)
  cin>>b[i]>>a[i];
   

   memset(dp,0,sizeof dp);
  cout<<solve(a,n-1,wt,b);


   /* w(t)
     {
        int m,n;
        int a[101][101];
        int dp[101][101];
        cin>>m>>n;
        f(i,1,m+1)
        f(j,1,n+1)
        cin>>a[i][j];
       int  ans=solve(a,n,m,dp);    
        cout<<ans+1<<"\n";
     }*/
  }

Measured memory_bytes: 82556
#include <stdio.h>

void div(int m){
	int p = m;
	while(p >= 10){
		if(p % 10 == 3){
			printf(" %d" , m);
			break;
		}else{
			p = p / 10;
		}
	}
	if(p < 10 && p % 10 == 3){
		printf(" %d" , m);
	}
}

void call(int n){
	int i;
	for(i=1; i<=n; i++){
		if ( i % 3 == 0 ){
			printf(" %d" , i);
		}else{
			div(i);
		}
	}
}

int main(void){
	int n;
	scanf("%d", &n);
	call(n);
	printf("\n");
	return 0;
}

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

int N,M;
vector<int> wacnt,accnt;

int main() {
    cin>>N>>M;
    wacnt.resize(N); accnt.resize(N);
    for (int i=0; i<M; i++) {
        int p; cin>>p; p-=1;
        string s; cin>>s;
        if (s=="WA"&&accnt[p]!=1) wacnt[p]++;
        if (s=="AC"&&accnt[p]!=1) accnt[p]=1;
    }
    int waans=0,acans=0;
    for (int i=0; i<N; i++) {
        acans+=accnt[i];
        if (accnt[i]==1) waans+=wacnt[i];
    }
    cout<<acans<<' '<<waans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

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

int main() {
	int N, M, Q;
	cin >> N >> M >> Q;

	vector<vector<int>> num_train(N + 1, vector<int>(N + 1));
	vector<vector<int>> c(N + 1, vector<int>(N + 1));
	vector<int> p(Q), q(Q);

	REP(i, M) {
		int L, R;
		cin >> L >> R;
		num_train[L][R]++;
	}
	
	REP(i, N + 1) {
		REP(j, N + 1) {
			if (j == 0) {
				c[i][j] = 0;
			}
			else {
				c[i][j] = c[i][j - 1] + num_train[i][j];
			}
		}
	}

	REP(i, Q) {
		cin >> p[i] >> q[i];
	}

	REP(i, Q) {
		int ans = 0;
		for (int j = p[i]; j < q[i] + 1; j++) {
			ans += c[j][q[i]] - c[j][p[i] - 1];
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3712
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<bitset>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=410;
const int maxm=1e5+1e2;
struct node {
	int x,y;
}s[maxm];
int n,m;
int f[maxn];
int Ans;
bitset<maxn>a[maxn];

inline void file() {
	freopen("c.in","r",stdin);
	freopen("c.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

inline int calc(int u) {
	a[u][u]=1;
	Forr (i,m,1) {
		int x=s[i].x,y=s[i].y;
		if (a[u][x] && a[u][y]) return 0;
		if (a[u][x] || a[u][y]) a[u][x]=a[u][y]=1;
	}
	return 1;
}

int main() {
//	file();
	n=read(); m=read();
	For (i,1,m) s[i].x=read(),s[i].y=read();
	For (i,1,n) f[i]=calc(i);
	For (i,1,n) if (f[i])
		For (j,i+1,n) if (f[j]) {
			if ((a[i]&a[j]).any()) continue;
			++Ans;
		}
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 1024
H, W = map(int, input().split())
Ass = [input() for _ in range(H)]

redss = [['#']+['.']*(W-1) for _ in range(H)]
bluess = [['.']*(W-1)+['#'] for _ in range(H)]

for i in range(H):
    if i % 2:
        redss[i]= ['#']*(W-1)+['.']
    else:
        bluess[i] = ['.']+['#']*(W-1)

for i in range(H):
    for j in range(W):
        if Ass[i][j] == '#':
            redss[i][j] = '#'
            bluess[i][j] = '#'

print('\n'.join(map(''.join, redss)))
print()
print('\n'.join(map(''.join, bluess)))


Measured memory_bytes: 8568
main=do
 s<-getLine
 getLine
 q<-lines<$>getContents
 let (t,l,r)=f q 0 ""(reverse s)
 let ans=if t==0 then l++(reverse r) else r++(reverse l)
 putStrLn ans
f[]t l r=(t,l,r)
f(q:qs)t l r
 |q=="1"=f qs(1-t)l r
 |(q!!2=='1')/=(t==1)=f qs t(q!!4:l)r
 |otherwise=f qs t l(q!!4:r)


Measured memory_bytes: 63100
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,ans,num;
    cin>>n;
    string s;
    cin>>s;
    int a[n],b[n];
    memset(a,0,sizeof(a));
    for(int i=0;i<n;i++){
        if(s[i]=='W'){
            a[i]--;
        }
        else{
            a[i]++;
        }
        if(i){
            b[i]=b[i-1]+a[i];
        }
        else{
            b[i]=a[i];
        }
    }
    for(int i=0;i<n;i++){
        if(i){
            num=abs(n-1-i+(b[n-1]-b[i]));
            num+=abs(i-b[i-1]);
            ans=min(ans,num/2);
        }
        else{
            num=abs(n-1+(b[n-1]-b[0]));
            ans=num/2;
        }
    }
    cout <<ans<<endl;


    return 0;
}




Measured memory_bytes: 2964
let [| N; K |] = stdin.ReadLine().Split() |> Array.map int
let A = stdin.ReadLine().Split() |> Array.map int

let d =
    A
    |> Seq.pairwise
    |> Seq.map (fun (x, y) -> y - x)
    |> Seq.append [ A.[0] + N - A.[K - 1] ]

(d |> Seq.sum) - (d |> Seq.max) |> printfn "%d"


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

using namespace std;

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  vector<long long> h(N);
  for (int i = 0; i < N; ++i)
    cin >> h[i];
  long long l = 0, r = 1LL << 32;
  while (l + 1 != r) {
    long long c = (l + r) / 2, need = 0;
    for (int i = 0; i < N; ++i)
      need += max(0LL, h[i] - B * c + A - B - 1) / (A - B);
    if (need <= c)
      r = c;
    else
      l = c;
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 1024
// G++ MACRO.CPP -STD=C++17
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair



int main(){
  CIN(n);
  V a(n);
  REP(i,n)scanf("%d",&a[i]);

  bitset<4000000> bs;
  bs[0]=1;
  REP(i,n){
    bs|=(bs<<a[i]);
  }

  ll sum = accumulate(ALL(a),0LL);
  FOR(i,(sum+1)/2,INF){
    if(bs[i]){
      COUT(i);
      return 0;
    }
  }

  

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;

const ll maxN = 1e7;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

void build(ll node, ll start, ll end){
	if(start == end)
		segtree[node] = A[start];
	else{
		ll mid = (start + end)/2;
		build(left(node), start, mid);
		build(right(node), mid+1, end);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

void update(ll node, ll start, ll end, ll l, ll r, ll val){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(start > end or l > start or r < end)
		return ;
	else if(start >= l and r >= end){
		segtree[node] += val;
		if(start != end){
			lazy[left(node)] += val;
			lazy[right(node)] += val;
		}
	}
	else{
		ll mid=(start + end)/2;
		update(left(node), start, mid, l, r, val);
		update(right(node), mid+1, end, l, r, val);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

ll sums(ll node, ll start, ll end, ll l, ll r){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(l > end or r < start or start > end)
		return 0;
	if(l <= start and r >= end)
		return segtree[node];
	ll mid = (start+end)/2;
	return sums(left(node), start, mid, l , r) + sums(left(node), mid + 1, end, l , r);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	ll cnt = 0;
	for(ll i=3; i<=n; i+=2){
		ll cur = 0;
		for(ll j=1; j*j <= i; j++){
			if(i%j == 0){
				cur++;
				if(j*j != i)
					cur++;
			}
		}
		if(cur == 8)
			cnt++;
	}
	cout << cnt;
	return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long n, std::vector<long long> a){
    LL ans1 = (a[0] == 0 ? 1 : 0), ans2 = abs(a[0]) + 1;
    LL tmp1 = (a[0] == 0 ? 1 : a[0]), tmp2 = (a[0] < 0 ? 1 : -1);
    REP1(i, n) {
        if(tmp1 < 0) {
            tmp1 += a[i];
            if (tmp1 <= 0) {
                ans1 += abs(tmp1) + 1;
                tmp1 = 1;
            }
        } else {
            tmp1 += a[i];
            if(0 <= tmp1) {
                ans1 += tmp1 + 1;
                tmp1 = -1;
            }
        }

        if(tmp2 < 0) {
            tmp2 += a[i];
            if (tmp2 <= 0) {
                ans2 += abs(tmp2) + 1;
                tmp2 = 1;
            }
        } else {
            tmp2 += a[i];
            if(0 <= tmp2) {
                ans2 += tmp2 + 1;
                tmp2 = -1;
            }
        }
    }

    cout << min(ans1, ans2) << endl;
}

int main(){
    long long n;
    scanf("%lld",&n);
    std::vector<long long> a(n);
    for(int i = 0 ; i < n ; i++){
        scanf("%lld",&a[i]);
    }
    solve(n, std::move(a));
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstring>
#include <algorithm>

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;

#define LOG(var, sep) (cerr << #var << " = " << (var) << (sep))
#define LOGM(msg) (cerr << (msg))
#define LOGV(vec, sep) { cerr << #vec << " ="; for (const auto& v : vec) cerr << " " << v; cerr << (sep); }
#define LOGA(arr, N, sep) { cerr << #arr << " ="; for (int i = 0; i < N; ++i) cerr << " " << (arr)[i]; cerr << (sep); }

ostream& operator<<(ostream& os, const ii& p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

const int MAX { 1000010 };
const ll oo { 2000000010 };
const int MOD { 1000000007 };

int as[MAX];

void solve(ll N, ll K)
{
    int pos = -1;

    while (as[++pos] != 1);

    int L = pos, R = N - 1 - pos;
    int r = L % (K - 1);

    L -= r;
    R -= (K - 1 - r);

    auto ans = 1 + (L/(K - 1)) + (R + K - 2)/(K - 1);

    cout << ans << endl;
}

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

    ll N, K;
    cin >> N >> K;

    for (int i = 0; i < N; ++i)
        cin >> as[i];

    solve(N, K);

    return 0;
}


Measured memory_bytes: 1020
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;
  int answer = K;
  for (int i = 1; i < N; ++i) answer *= (K - 1);
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256