akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pll;

int main() {
    ll N; cin >> N;
    vector<ll> A(N); for (auto &x : A) cin >> x;
    vector<ll> dif(N); dif[0] = A[0] - A[N-1];
    ll sum = A[0];
    for (int i = 1; i < N; i++) {
        sum += A[i];
        dif[i] = A[i] - A[i-1];
    }
    if (sum % (N * (N + 1) / 2) == 0) {
        ll c = sum / (N * (N + 1) / 2);
        ll t = 0;
        for (int i = 0; i < N; i++) {
            if ((c - dif[i]) % N != 0 || c < dif[i]) {
                cout << "NO" << endl;
                return 0;
            } else {
                t += (c - dif[i]) / N;
            }
        }
        if (t == c) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int N;
    cin>>N;
    long long int Nc[5]={0};
    char C[5]={'M','A','R','C','H'};
    for (int i=0; i<N; ++i)
    {
        string S;
        cin>>S;
        for (int j=0; j<5; ++j)
        {
            if(S[0]!=C[j])
            {
                continue;
            }
            Nc[j]++;
            break;
        }
    }
    
    long long int ans=0;
    for (int i=0; i<5; ++i)
    {
        for (int j=i+1; j<5; ++j)
        {
            for (int k=j+1; k<5; ++k) {
                ans+=Nc[i]*Nc[j]*Nc[k];
            }
        }
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>



int main(void)
{
	//変数の宣言
	int k;
	int iti;
	int ni;
	int ans;
	
	//データの読み込み
	scanf("%d", &k);
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	iti = k/2;
	ni = (k+1)/2;
	ans = iti * ni;
	
//	printf("計算部分終了\n");
	
	//出力
	
	printf("%d",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
}

Measured memory_bytes: 128
N = int(input())
s = [input() for i in range(N)]

count_AB = [s[i].count("AB") for i in range(N)]

headB = 0
tailA = 0
headB_and_tailA = 0
for i in range(N):
    #print("i =", i)
    if s[i][0] == 'B':
        if s[i][-1] != 'A':
            #print("headB")
            headB += 1
        else:
            headB_and_tailA += 1
            #print("both")
    elif s[i][-1] == 'A':
        tailA += 1
        #print("tailA")

"""
print("both =", headB_and_tailA)
print("headB = ", headB)
print("tailA = ", tailA)
"""
result = sum(count_AB) + min(headB, tailA)
headB -= min(headB, tailA)
tailA -= min(headB, tailA)
for _ in range(headB_and_tailA):
    if tailA > 0:
        result += 1
    elif headB > 0:
        result += 1
    else:
        tailA += 1
#print("sum = ", sum(count_AB))
    
print(result)


Measured memory_bytes: 3700
def main():
    mod=1000000007
    inv=lambda x: pow(x,mod-2,mod)
    n,m=map(int,input().split())
    
    Fact=[1]
    for i in range(1,m+1):
        Fact.append(Fact[i-1]*i%mod)
    Finv=[0]*(m+1)
    Finv[-1]=inv(Fact[-1])
    for i in range(m-1,-1,-1):
        Finv[i]=Finv[i+1]*(i+1)%mod
    def comb(n,r):
        if n<r:
            return 0
        return Fact[n]*Finv[r]*Finv[n-r]%mod
    def perm(n,r):
        if n<r:
            return 0
        return Fact[n]*Finv[n-r]%mod
    
    ans=0
    p=1
    for i in range(n+1):
        ans+=comb(n,i)*perm(m,i)*perm(m-i,n-i)**2*p
        ans%=mod
        p*=-1
    print(ans)
    
if __name__=='__main__':
    main()

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

int main() {
  string S;
  cin >> S;
  long ans = 0, bc = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'B') bc++;
    else ans += bc;
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
S = input()
T = input()

t = T
cnt = len(T)

N = len(S)
M = len(T)

for i in range(N-M+1):
    check = S[i:i+M]
    ck = 0
    for j in range(M):
        if check[j] != T[j]:
            ck += 1
    if ck < cnt:
        cnt = ck

print(cnt)

Measured memory_bytes: 9068
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.datetime;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;
auto solve(){
}

string decode(string s) {
	if(s[0] < '1' || s[0] > '6' || s[1] < '1' || s[1] > '5') {
		return "NA";
	}
	auto c = (s[0] - '1') * 5 + s[1] - '1';
	if(c < 26) {
		return "" ~ cast(char)(c + 'a');
	}
	auto m = ['.', '?', '!', ' '];
	return "" ~ m[c-26];
}


void main(){
	string s;
loop:
	while((s = readln()).length > 0) {
		s = s.strip();
		if(s.length % 2 != 0) {
			writeln("NA");
			continue;
		}
		string t;
		foreach(i; 0..s.length/2) {
			auto u = decode(s[2*i..2*i+2]);
			if(u == "NA") {
				writeln("NA");
				continue loop;
			}
			t ~= u;
		}
		writeln(t);
	}
}

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

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

const int N = 2e5+10 , mod = 1e9+7;

int cnt[44][21][10];

void add(string s){
   int n = s.length();
   ll cur = 0;
   bool fnd = false;
   int num = 0;
   for(int i = 0 ; i < n ; i++){
      if(s[i] == '.'){
         fnd = true;
         continue;
      }
      if(fnd)
         num++;
      cur = cur * 10 + (s[i] - '0');
   }
   int num2 = 0 , num5 = 0;
   while(cur && cur % 2 == 0){
      cur /= 2;
      num2++;
   }
   while(cur && cur % 5 == 0){
      cur /= 5;
      num5++;
   }
   cnt[num2][num5][num]++;
}

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n;
   cin >> n;
   for(int i = 0 ; i < n ; i++){
      string s;
      cin >> s;
      int m = s.length();
      int id = -1;
      for(int j = 0 ; j < m ; j++)
         if(s[j] == '.')
            id = j;
      if(id != -1){
         while(s.back() == '0')
            s.pop_back();
         if(s.back() == '.')
            s.pop_back();
      }
      add(s);
   }
   ll ans = 0;
   for(int i = 0 ; i < 44 ; i++){
      for(int j = 0 ; j < 21 ; j++){
         for(int k = 0 ; k < 10 ; k++){
            if(min(2 * i , 2 * j) >= 2 * k)
               ans += 1ll * cnt[i][j][k] * (cnt[i][j][k] - 1) / 2;
            for(int p = i ; p < 44 ; p++){
               for(int q = 0 ; q < 21 ; q++){
                  for(int t = 0 ; t < 10 ; t++){
                     if(i == p && j > q)
                        continue;
                     if(i == p && j == q && k >= t)
                        continue;
                     int t1 = i + p;
                     int t2 = j + q;
                     int bad = k + t;
                     if(min(t1 , t2) >= bad)
                        ans += 1ll * cnt[i][j][k] * cnt[p][q][t];
                  }
               }
            }
         }
      }
   }
   cout << ans;
   return 0;
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"


#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) std::sort(v, v+n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define VRSORT(v) std::sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

ll a,b,c,k;
int main() {
    cin >> a>>b>>c>>k;

    if (a >= k) cout << k<<endl;
    else if (a < k && a + b >= k) cout << a<<endl;
    else cout << a - (k - a - b)<<endl;

    

}

Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define PB push_back
#define SP << " " <<

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;

__attribute__((constructor))
void initial(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed <<setprecision(15);
}


int main(void){
	string S;
    cin >> S;
    string ans = "Yes";
    if(S[2]!=S[3]) ans = "No";
    if(S[4]!=S[5]) ans = "No";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
int n,c,l[6],cnt[32],id[32];
double dp[310][310][32][16],ans;
vector<int>E[6];
inline int calc(int x,int m)
{
	if(x%n<=m)return x/n*n+m;
	else return (x/n+1)*n+m;
}
int main()
{
//	printf("%d\n",sizeof(dp));
	scanf("%d %d",&n,&c);
	for(int i=0;i<n;++i)scanf("%d",&l[i]);
	sort(l,l+n);
	dp[0][l[n-1]*n][0][0]=1;
	for(int i=1;i<1<<n-1;++i)cnt[i]=cnt[i>>1]+(i&1),id[i]=E[cnt[i]].size(),E[cnt[i]].push_back(i);E[0].push_back(0);
	int mx=c*n;
	for(int p=0;p<1<<n-1;++p)
		for(auto d:E[cnt[p]])
			for(int j=0;j<n-1;++j)if(!(p>>j&1))
				for(int k=0;k<n-1;++k)if(!(d>>k&1))
					for(int st=0;st<=mx;++st)
						for(int ed=st;ed<=mx;++ed)
							if(dp[st][ed][p][id[d]])
								for(int t=calc(st+1,k+1);t<=ed;t+=n)
								//	printf("%d %d %d %d %d %d %d %d %d\n",t,st,ed,p,d,t,max(min(t+n*l[j],mx),ed),p|(1<<j),d|(1<<k)),
									dp[t][max(min(t+n*l[j],mx),ed)][p|(1<<j)][id[d|(1<<k)]]+=dp[st][ed][p][id[d]];
	for(int i=0;i<=mx;++i)
		ans+=dp[i][mx][(1<<n-1)-1][id[(1<<n-1)-1]];
	for(int i=1;i<=n-1;++i)ans/=i,ans/=c;
	printf("%.12lf",ans);
	return 0;
}


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

using namespace std;
int debug=0;
int N;
long long A[1000000+10];
// Keep 'N' items, push K, pop minimum
priority_queue<long long, vector<long long>, greater<long long>> Que1;
long long Que1Val;
long long Que1Sum[1000000 + 10];
// Keep 'N' items, push K, pop maximum
priority_queue<long long, vector<long long>, less<long long>> Que2;
long long Que2Val;
long long Que2Sum[1000000 + 10];
// Keep 'N' items
priority_queue<long long, vector<long long>, less<long long>> QueAns;



int main(){

    cin >> N;

    // read 0..N-1
    Que1Val = 0;
    for(int i=0;i<N;++i){
        cin >> A[i];
        Que1.push(A[i]);
        Que1Val += A[i];
    }
    Que1Sum[N]=Que1Val;

    // read N..2*N-1
    for (int i = 0;i< N;++i){
        cin >> A[N+i];
    }

    // read 2*N..3N-1
    Que2Val = 0;
    for (int i = 0; i < N; ++i)
    {
        cin >> A[2 * N + i];
        Que2.push(A[2*N+i]);
        Que2Val += A[2*N+i];
    }
    Que2Sum[2*N]= Que2Val;

    if(debug){
        cout << "A[i]" << endl;
        for (int i = 0; i < 3 * N;++i){
            cout << A[i] << " ";
        }
        cout << endl;
        cout << "Que1Sum[N]=" << Que1Sum[N] << endl;
        cout << "Que2Sum[2*N]=" << Que2Sum[2*N] << endl;
    }

    if(debug) cout << "left to right" << endl;
    for (int i = 0; i < N;++i){
        // N+i..2N-1
        // calc val at N+i
        Que1.push(A[N + i]);
 
        long long tmp = Que1.top();
        if(debug) cout << "pop.." << tmp << endl;

        Que1.pop();

        Que1Val = Que1Val - tmp + A[N + i];
        Que1Sum[N+i+1] = Que1Val;
        if(debug) { 
            cout << "Max Que1Sum[" << N+i+1 << "]=";
            cout << Que1Sum[N+i+1]<< endl;
        }
    }

    if(debug) cout << "right to left " << endl;

    for (int i = 0; i < N;++i){
        // 2N-1-i .. N
        // cal val at 2N-1-i
        Que2.push(A[2*N -1 -i]);

        long long tmp = Que2.top();
        if(debug) cout << "pop.." << tmp << endl;

        Que2.pop();


        Que2Val = Que2Val - tmp + A[2*N -1 - i];
        Que2Sum[2*N- i-1] = Que2Val;
        if(debug) { 
            cout << "Min Que2Sum[" << 2*N-i-1 << "]=";
            cout << Que2Sum[2*N-i-1]<< endl;
        } 
    }


    if(debug) cout << "left to right" << endl;

    // calc from N to 2*N
    for (int i = 0; i < N+1;++i){
        long long tmp;
        tmp = Que1Sum[N+i]-Que2Sum[N+i];
        QueAns.push(tmp);
        if(debug){
            cout << "Ans[" << N+i << "]=";
            cout << tmp << endl;
        }
    }

    if(debug) cout << "ans=";
    long long tmp;
    tmp = QueAns.top();
    cout << tmp << endl;

    /*
    while(!Que.empty()){
        cout << Que.top() << endl;
        Que.pop();
    }
    */

}


Measured memory_bytes: 12276
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	cin>>n;
	int V[1<<18], W[1<<18];
	for(int i=1; i<=n; i++) cin>>V[i]>>W[i];
	const int d=10;
	vector<P> wv[1<<10];
	if(n>=(1<<d)){
		for(int t=(1<<(d-1)); t<(1<<d); t++){
			int v=t;
			vector<int> vs;
			while(v>1){
				vs.push_back(v);
				v>>=1;
			}
			vs.push_back(1);
			int m=vs.size();
			for(int i=0; i<(1<<m); i++){
				int vsum=0, wsum=0;
				for(int j=0; j<m; j++){
					if(i&(1<<j)){
						vsum+=V[vs[j]], wsum+=W[vs[j]];
					}
				}
				wv[t].push_back({wsum, vsum});
			}
			sort(wv[t].begin(), wv[t].end());
			for(int i=1; i<wv[t].size(); i++){
				wv[t][i].second=max(wv[t][i].second, wv[t][i-1].second);
			}
		}
	}
	int q; cin>>q;
	while(q--){
		int v, l;
		cin>>v>>l;
		if(v<(1<<d)){
			vector<int> vs;
			while(v>1){
				vs.push_back(v);
				v>>=1;
			}
			vs.push_back(1);
			int m=vs.size();
			int ans=0;
			for(int i=0; i<(1<<m); i++){
				int vsum=0, wsum=0;
				for(int j=0; j<m; j++){
					if(i&(1<<j)){
						vsum+=V[vs[j]], wsum+=W[vs[j]];
					}
				}
				if(wsum<=l) ans=max(ans, vsum);
			}
			cout<<ans<<endl;
			continue;
		}
		vector<int> vs;
		while(v>=(1<<d)){
			vs.push_back(v);
			v>>=1;
		}
		int m=vs.size();
		int ans=0;
		const int INF=1e9+7;
		for(int i=0; i<(1<<m); i++){
				int vsum=0, wsum=0;
				for(int j=0; j<m; j++){
					if(i&(1<<j)){
						vsum+=V[vs[j]], wsum+=W[vs[j]];
					}
				}
				if(l-wsum<0) continue;
			int t=lower_bound(wv[v].begin(), wv[v].end(), P(l-wsum, INF))-wv[v].begin();
			ans=max(ans, wv[v][t-1].second+vsum);
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 9544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    double x[8],y[8];
    rep(i,N){
        cin >> x[i] >> y[i];
    }
    int num = 1;
    for(int i=1;i<=N;i++){
        num*=i;
    }
    double dist[8][8];
    double ans = 0;
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            dist[i][j]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
            ans += dist[i][j];
        }
    }

    cout << setprecision(20) << ans/(N/2.0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const ll mod = 1000000007;

int a, b;

int main(){
  cin >> a >> b;
  cout << (a + b) % 24 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<omp.h>

typedef long long int llu;

llu max(llu a, llu b) {
    if (a < b) {
        return b;
    } else {
        return a;
    }
}

int main() {
    // INPUT
    int N, W;
    scanf("%d %d", &N, &W);

    int w[N], v[N];
    for (int i = 0; i < N; ++i) {
        scanf("%d %d", &w[i], &v[i]);
    }

    // INITIALIZE
    llu dp[N+1][W+1];
    for (int i = 0; i <= N; ++i) {
        dp[i][0] = 0;
    }
    for (int j = 0; j <= W; ++j) {
        dp[0][j] = 0;
    }

    // DP
    for (int i = 1; i <= N; ++i) {
        #pragma omp for schedule(dynamic)
        for (int j = 1; j <= W; ++j) {
            if (j < w[i-1]) {
                dp[i][j] = dp[i-1][j];
            } else {
                dp[i][j] = max( dp[i-1][j-w[i-1]] + v[i-1] ,
                                dp[i-1][j] );
            }
        }
    }

    // OUTPUT
    printf("%llu\n", dp[N][W]);
}


Measured memory_bytes: 79104
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, A);
    IN(ll, B);
    IN(ll, H);
    IN(ll, M);
    auto h = complex<double>(0, A) * exp(complex<double>{0, M_PI * (30 * H + 0.5 * M) / 180});
    auto m = complex<double>(0, B) * exp(complex<double>{0, M_PI * (6 * M) / 180});
    FOUT(abs(h - m));
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	string s;
	cin>>n>>s;
	vector<int>cnt(26,1);
	for(auto&i:s)++cnt.at(i-'a');
	int ans=1;const int mod=1e9+7;
	for(auto&i:cnt)ans=(int64_t)ans*i%mod;
	cout<<ans-1<<"\n"s;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */

int main() {
    int n, k;
    cin >> n >> k;
    double a[200100];
    a[0] = 0;
    rep1(i, n) {
        double A;
        cin >> A;
        A = (A+1)/2;
        a[i] = A;
        a[i] += a[i-1];
    }
    double ma = -1;
    rep(i, n - k + 1) ma = max(ma, a[i + k] - a[i]);
    cout << fixed << setprecision(10) << ma << endl;
    return 0;
}

Measured memory_bytes: 5296
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <ctype.h>
#include <cmath>
#include <iomanip>
#include <ios>
using namespace std;
int main(void){
    
    int s;
    cin>>s;
    int ans=1;
    int a=0;
    if(s==4||s==2||s==1)a+=1;
    int b=(s==4||s==2||s==1?s:4);
    while(a<2){
        if(s%2==0)s=s/2;
        else s=3*s+1;
        
        if(s==b)a+=1;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

#define ll long long
#define rep(i,N) for(ll i=0; i<N; i++)
const int mx = 2e5;

int main(void){
  ll N;
  cin >> N;
  ll A[N];
  ll jo[N];
  rep(i,N) jo[i]=0;
  rep(i,N-1){
    cin>>A[i];
  }
  jo[N-1] = 0;
  rep(i,N-1){
    jo[A[i]-1]++;
  }
  rep(i,N){
    cout << jo[i] << "\n";
  }
  return 0;
}

Measured memory_bytes: 6760
#include <bits/stdc++.h>
#define MOD 998244353

using namespace std;

long long power(long long x, long long n)
{
    if (n == 0)
        return 1;
    return (n % 2) ? x * power(x, n - 1) % MOD : power(x * x % MOD, n / 2);
}

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

    vector<int> D(N);
    vector<long long> num(N);
    for (int i = 0; i < N; i++)
    {
        cin >> D[i];
        num[D[i]]++;
    }

    long long ans = 1;
    if (D[0] != 0 || num[0] != 1)
        ans = 0;
    else
    {
        int i = 1;
        for (; i < N; i++)
        {
            if (num[i] == 0)
                break;
            ans *= power(num[i - 1], num[i]);
            ans %= MOD;
        }

        if (i != N)
        {
            i++;
            while (i != N)
            {
                if (num[i] != 0)
                {
                    ans = 0;
                    break;
                }
                i++;
            }
        }
    }

    cout << ans;
}

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

int main(){
  int w,h,n; cin >> w >> h >> n;
  vector<int> x(n);
  vector<int> y(n);
  vector<int> a(n);
  rep(i,n) cin >> x.at(i) >> y.at(i) >> a.at(i);

  int minx = 0,maxx = w,miny = 0,maxy = h,area;
//  bool flagminx = 0,flagmaxx = 0,flagminy = 0,flagmaxy = 0;

  rep(i,n){
    if(a.at(i) == 1){
      minx = max(minx, x.at(i));
    //  flagminx = 1;
    }
    else if(a.at(i) == 2){
      maxx = min(maxx, x.at(i));
      //flagmaxx = 1;
    }
    else if(a.at(i) == 3){
      miny = max(miny, y.at(i));
      //flagminy = 1;
    }
    else if(a.at(i) == 4){
      maxy = min(maxy, y.at(i));
      //flagmaxx = 1;
    }
  }

  //int sax =,say;
    
  if(minx < maxx && miny < maxy){
    area = (maxx - minx) * (maxy - miny);
    cout << area << endl;
  }
  else {
    cout << 0 << endl;
  }

 // cout << minx << ' ' << maxx << ' ' << miny << ' ' << maxy << endl;
}




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

using namespace std;
typedef long long ll;

ll h1[120000],h2[120000],h3[120000],h4[120000],x[120000],y[120000];
ll m,s,t;
 
int main()
{
    int i, n;
	scanf("%d%lld",&n,&m);
	for (i=1;i<=n;i++)
		scanf("%lld%lld",&x[i],&y[i]);
	for (i=1,t=0;i<=n;i++)
		t=t+y[i],h1[i]=max(h1[i-1],t-x[i]),h2[i]=max(h2[i-1],t-2*x[i]);
	for (i=n,t=0;i>0;i--)
		t=t+y[i],h3[i]=max(h3[i+1],t-(m-x[i])),h4[i]=max(h4[i+1],t-2*(m-x[i]));
	for (i=0;i<=n;i++)
		s=max(s,max(h1[i]+h4[i+1],h2[i]+h3[i+1]));
	return !printf("%lld\n",s);
}

Measured memory_bytes: 5248
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int a[100010], b[100010];
int main()
{
	int N, H;
	cin >> N >> H;
	int k = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i];
		k = max(k, a[i]);
	}
	sort(b, b + N, greater<int>());
	int ans = 0;
	int i = 0;
	while (H > 0) {
		if (b[i] > k) H -= b[i];
		else {
			ans += (H + k - 1) / k;
			break;
		}
		ans++;
		i++;
	}
	cout << ans << endl;
}

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

int main() {
  int a,b,N,A,x;
  cin >> a >> b;
  N = b - a - 1;
  for(int i = 0; i < N+1; i++){
    A = A + i;
  }
  x = A - a;
  cout << x << endl;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const ll MOD = (ll)(1e9 + 7);
const int MAX_N = 112345;
vector<int> g[MAX_N];

ll dp[MAX_N][2];

void dfs(int v, int prev) {
  ll res0 = 1; // v is white
  ll res1 = 1; // v is black
  for (int c : g[v]) if (c != prev) {
    dfs(c, v);
    res1 = res1 * dp[c][0] % MOD;
    res0 = res0 * (dp[c][0] + dp[c][1]) % MOD;
  }
  dp[v][0] = res0;
  dp[v][1] = res1;
}

int main2() {
  CLR(dp, 0);
  REP(i, MAX_N) g[i].clear();
  int N = nextInt();
  REP(i, N-1) {
    int a = nextInt() - 1;
    int b = nextInt() - 1;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  if (N == 1) {
    cout << 2 << endl;
    return 0;
  }
  if (N == 2) {
    cout << 3 << endl;
    return 0;
  }
  int s = -1;
  REP(i, N) if (g[i].size() >= 2) { s = i; break; }

  dfs(s, -1);

  ll ans = (dp[s][0] + dp[s][1]) % MOD;
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 14720
#!/usr/bin/env python3


import array


MAX_A = 55555


def sieve_of_eratosthenes(end, typecode="L"):
    """Enumerates the prime numbers below the given integer.

    :param int end: Prime numbers below this integer will be enumerated.
    :param str typecode: The type of the array to be returned (optional).
    :return: The array of the prime numbers.
    :rtype: :class:`array.array`
    """

    assert end > 1
    is_prime = array.array("B", (True for i in range(end)))
    is_prime[0] = False
    is_prime[1] = False
    primes = array.array(typecode)
    for i in range(2, end):
        if is_prime[i]:
            primes.append(i)
            for j in range(2 * i, end, i):
                is_prime[j] = False
    return primes


def solve(n):
    primes = sieve_of_eratosthenes(MAX_A + 1)
    return [prime for prime in primes if prime % 5 == 1][:n]


def main():
    print(*solve(int(input())))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
int main(){
  char s[7];
  int ans = 0;

  scanf("%s", s);

  for(int cnt = 0; cnt < 6; cnt++){
    if(s[cnt] == '1'){
      ans++;
    }
  }

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


}


Measured memory_bytes: 128
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<iomanip>
#include<map>
#include<iostream>
using namespace std;
const int N=1e5+5;
const int M=sqrt(2e5)+5;
int m,n;
int a[M][M];
int main(){
	scanf("%d",&n);
	m=n*2;
	//cout<<sqrt(m)<<" "<<sqrt(m)+1<<endl;
	if(m==(int)sqrt(m)*(int)(sqrt(m)+1)){
		printf("Yes\n");
		int k=sqrt(m)+1,x=1;
		printf("%d\n",k);
		for(int i=1;i<=k;i++){
	        for(int j=i;j<k;j++)a[i][j]=x+(j-i);
			for(int j=i+1;j<=k;j++)a[j][i]=x+(j-i-1);
			x+=(k-i-1);x++;		
		}
		for(int i=1;i<=k;i++){
			printf("%d",k-1);
			for(int j=1;j<k;j++){
				printf(" %d",a[i][j]);
			}
			printf("\n");
		}
	}
    else printf("No\n");
    return 0;
}



Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define INF 100000000
using namespace std;

int main() {
 
int64_t N,M;
cin >>N>>M;
// vector<int> A(N);
// for(int i=0; i<N; i++){cin>>A[i];}
// vector<vector<int>> A(N,vector<int>(M));
// for(int i=0; i<N; i++){for(int j=0; j<M; j++){cin>>A[i][j];}}
if(N%M==0)cout<<-1<<endl;
else cout<<N<<endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 305;

int n;
vector <int> red[MAXN], blue[MAXN];

int main() { 

  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    red[a].push_back(b);
  }
  for (int i = 0; i < n; i++) {
    int c, d;
    scanf("%d %d", &c, &d);
    blue[c].push_back(d);
  }

  int ans = 0;
  multiset<int> st;
  for (int i = 0; i < 2 * n; i++) {
    sort(all(blue[i]));
    for (int y : blue[i]) {
      auto it = st.upper_bound(y);
      if (it != st.begin()) {
        it--;
        ans++;
        st.erase(it);
      }
    }
    for (int y : red[i]) {
      st.insert(y);
    }
  }

  cout << ans << endl;

  return 0;
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 1 , 0 } ;
const int dy[] = { 0 , 1 , 0 , -1 } ;

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

const int N = 1e6 + 2 ;
int freq[N] ;

vb ok ( N , true ) ;

void solve ( int test_case )
{
    int n ;
    cin >> n ;

    for ( int i=0 ; i < n ; i ++ )
    {
        int val ;
        cin >> val ;

        freq[val] ++ ;
    }

    if ( freq[1] > 0 )
    {
        int ans = 0 ;

        if ( freq[1] == 1 )
            ans = 1 ;

        cout << ans ; line ; return ;
    }

    for ( int i = 2 ; i < N ; i ++ )
    {
        if ( freq[i] == 0 ) C ;

        if ( freq[i] > 1 )
            ok[i] = false ;

        for ( int j = i + i ; j < N ; j += i )
            ok[j] = false ;
    }

    int ans = 0 ;

    for ( int i = 2 ; i < N ; i ++ )
    {
        if ( freq[i] == 1 && ok[i] == true )
            ans ++ ;
    }

    cout << ans ; line ;
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i = 1 ; i <= t ; i ++ )
    {
        solve ( i ) ;
    }

    return 0;
}


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

slen=len(s)
tlen=len(t)
diffmin=99999

for iis in range(0,slen-tlen+1):
  diff=0
  for iit in range(0,tlen):
    if (s[iis+iit] != t[iit]):
      diff+=1
  diffmin=min(diffmin, diff)
print(diffmin)

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main()
{
    int n,p;
    cin >> n >> p;
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    vector<ll> d(n+1);
    d[0] = 0;
    ll ans = 0;
    rep(i,n){
        ll x = s[i] - '0';//今の桁
        d[i+1] = (d[i] + x*modpow(10,i,p))%p;
        
    }
    if(p == 2|| p == 5){
        rep(i,n){
            if((s[i] - '0')%p == 0)ans += n-i;
        }
        cout << ans << endl;
    }
    else{
        map<int,ll>m;
        rep(i,n+1){
            m[d[i]]++;
        }
        
        rep(pi,p){
            ans += m[pi] * (m[pi]-1) /2;

        }
        cout << ans << endl;

    }
        
    return 0;
}


Measured memory_bytes: 2564
S = input()
if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

A = list("abcdefghijklmnopqrstuvwxyz")
if len(S) < 26:
    for i in A:
        if i not in S:
            print(S+i)
            exit()

for i in range(24,0,-1):
    if S[i] != max(S[i:]):
        B = [j for j in S[i+1:] if j > S[i]]
        print(S[:i]+min(B))
        exit()
print(A[A.index(S[0]) + 1])

Measured memory_bytes: 9012
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
typedef long long ll;
using namespace std;

bool comp(const int& a, const int& b) {
	return a > b;
}

int main()
{
	string s;
	cin >> s;
	if (s == "ABC") {
		cout << "ARC" << endl;
	}
	else {
		cout << "ABC" << endl;
	}

}

Measured memory_bytes: 3116
#include <iostream>		 // cout, endl, cin
#include <string>		 // string, to_string, stoi
#include <vector>		 // vector
#include <algorithm>	 // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>		 // pair, make_pair
#include <tuple>		 // tuple, make_tuple
#include <cstdint>		 // int64_t, int*_t
#include <cstdio>		 // printf
#include <map>			 // map
#include <queue>		 // queue, priority_queue
#include <set>			 // set
#include <stack>		 // stack
#include <deque>		 // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>		 // bitset
#include <cctype>		 // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main()
{
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	// cout << typeid(int(s[0])).name() << endl;
	for(int i = 0; i < 10; i++){
		for(int j = 0; j < 10; j++){
			for(int k = 0; k < 10; k++){
				// cout << i  << j << k << endl;
				bool bool_i = false;				
				bool bool_j = false;	
				bool bool_k = false;
				for(int l = 0; l < n; l++){
					if(!bool_i){
						if(s[l] - '0' == i){
							bool_i = true;
						}
					}
					else if(!bool_j){
						if(s[l] - '0' == j){
							bool_j = true;
						}
					}
					else if(!bool_k){
						if(s[l] - '0' == k){
							bool_k = true;
						}
					}
				}
				// if(i == 0 && j == 2 && k == 2){
				// 	cout << bool_i << " " << bool_j << " " << bool_k << endl;
				// }
				if(bool_k){
					ans += 1;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

n3 = n - n%3
n5 = n - n%5
n15 = n - n%15


sum = n * (n+1) /2
sum3 = n3 * (n3 + 3) /6
sum5 = n5 * (n5 + 5) /10
sum15 = n15 * (n15 +15) /30

print(round(sum-sum3-sum5+sum15))

Measured memory_bytes: 9180
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def warshall_floyd(g):
    d = defaultdict(dict)
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v))
    V = set(V)
    for i in V:
        for j in V:
            if i in g and j in g[i]:
                d[i][j] = g[i][j]
            else:
                d[i][j] = sys.maxsize
    for k in g:
        for i in g:
            for j in g:
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]

    return d


@mt
def slv(H, W, C, A):
    g = defaultdict(dict)
    for i in range(10):
        for j in range(10):
            g[i][j] = C[i][j]

    d = warshall_floyd(g)

    a = Counter()
    for r in A:
        for n in r:
            a[n] += 1

    ans = 0
    for k in a:
        if k != -1:
            ans += d[k][1] * a[k]
    return ans


def main():
    H, W = read_int_n()
    C = [read_int_n() for _ in range(10)]
    A = [read_int_n() for _ in range(H)]
    print(slv(H, W, C, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5736
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

int main(){
    int n, k;
    cin >> n >> k;

    int a = 1;
    rep(i, n){
        if(a + k < a * 2){
            a += k;
        }else{
            a *= 2;
        }
    }

    cout << a << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  rep(i,n) cin >> a[i];
  int ans = 0; int cnt = 1;
  rep(i,n) {
    if(cnt==a[i]) ++cnt;
    else ++ans;
  }
  if(ans == n) ans=-1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
// F - LCS (Longest Common Subsequence)

// 最長共通部分文字列の長さだけでなく、部分文字列そのものを求める


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

int dp[3001][3001]; // dp[i][j]: sのi文字目, tのj文字目（1始まり）までのLCS
string s, t;

void update(int i, int j) {
	if (s[i] == t[j]) {
		dp[i][j] = dp[i-1][j-1] + 1;
	} else {
		dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
	}
}

int main(){
	cin >> s >> t;
	int m = s.size();
	int n = t.size();

	s = " " + s;
	t = " " + t;

	for (int i=1; i<=m; i++) {
		for (int j=1; j<=n; j++) {
			update(i, j);
		}
	}

	// 復元
	string ans = "";
	int i = m;
	int j = n;
	while(i>0 && j>0) {
		if (dp[i][j] == dp[i-1][j]) { // dp[i-1][j]からの遷移
			i--;
		} else if (dp[i][j] == dp[i][j-1]) { // dp[i][j-1]からの遷移
			j--;
		} else { // dp[i-1][j-1]からの遷移
			ans = s[i] + ans;
			i--;
			j--;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 35456
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES//(M_PIに使える（π）)

#include<stdio.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<string.h>
#include<algorithm>
#include<numeric>
#include<random>
#include <functional>
using namespace std;

int main() {
	int N = 0;
	int K = 0;
	int ans = 0;
	vector <int> xi;
	cin >> N >> K;
	for (int i = 0;i<N;i++) {
		int num = 0;
		cin >> num;
		xi.push_back(num);
	}


	for (int i = 0;i<N;i++) {
		ans += min(xi[i]-0,abs(xi[i]-K))*2;
	}

	cout << ans<<endl;


	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
A = list(map(int,(input().split())))
B = list(map(int,(input().split())))
C = list(map(int,(input().split())))
S = 0
before = 100

for i in range(n):
    S += B[A[i]-1]
    if A[i]-1 == before + 1:
        S += C[before]
    before = A[i]-1

print(S)
    


Measured memory_bytes: 3060
import java.util.Scanner;

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

    char judge_1 = input.charAt(0);
    char judge_2 = input.charAt(1);

    if(input.length() == 2){
      if(judge_1 == judge_2){
        System.out.println("1 2");
      }else{
        System.out.println("-1 -1");
      }
    }else{
      for(int i=2; i<input.length(); i++){
        if(judge_1 == input.charAt(i)){
          System.out.println(Integer.toString(i-1) + " " + Integer.toString(i+1));
          break;
        }
        if(judge_2 == input.charAt(i)){
          System.out.println(Integer.toString(i) + " " + Integer.toString(i+1));
          break;
        }
        if(i == input.length()-1){
          System.out.println("-1 -1");
        }
        judge_1 = judge_2;
        judge_2 = input.charAt(i);
      }
    }
  }
}


Measured memory_bytes: 26960
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import fractions
from functools import reduce



N = int(input())
A = [int(i) for i in input().split()]

def gcd(nums):
    return reduce(fractions.gcd,nums)

ans = 1
A.sort()
gcd1 = gcd(A)
for i in range(N):
    A[i] //= gcd1

ans *= gcd1

gcd2 = A[0]
for i in range(1,N):
    gcd2 = fractions.gcd(gcd2,A[i])
    if gcd2 == 1:
        key = i
        break

a = copy.deepcopy(A)
a.remove(A[0])
if gcd(a)!=1:
    ans *= gcd(a)
    print(ans)
    exit()

a = copy.deepcopy(A)
a.remove(A[key])
if gcd(a)!=1:
    ans *= gcd(a)
    print(ans)
    exit()
print(ans)


Measured memory_bytes: 16564
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,X,m;
  cin >> N >> X;
  int min=1000;
  int sum=0;
  for (int i=0; i < N; i++){
    cin >>m;
    if (m<min) min=m;
    sum = sum + m;
  }
  int ans = (X - sum)/min + N;
  cout << ans << endl;
}

Measured memory_bytes: 3632
#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 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(){
    ll n,ma,mb;cin >> n >>ma >>mb;
    vl a(n),b(n),c(n);
    rep(i,n)cin >> a[i] >>b[i] >>c[i];
    ll ans=INF;
    ll ia=ma,ib=mb;
    while(ma<=400&&mb<=400){
        ll dp[ma+1][mb+1];
        rep(j,ma+1)rep(k,mb+1)dp[j][k]=inf;
        dp[0][0]=0;
        rep(i,n){
            per(j,ma+1){
                per(k,mb+1){
                    chmin(dp[j][k],dp[j][k]);
                    if(j+a[i]<=ma&&k+b[i]<=mb){
                        chmin(dp[j+a[i]][k+b[i]],dp[j][k]+c[i]);
                    }
                }
            }
        }
        if(dp[ma][mb]!=inf){
            chmin(ans,dp[ma][mb]);
        }
        ma+=ia;
        mb+=ib;
    }
    if(ans!=INF)cout <<ans <<endl;
    else cout << -1 <<endl;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    
    int le=a+b;
    int ri=c+d;
    
    if(le>ri){
        cout<<"Left"<<endl;
    }
    else if(le<ri){
        cout<<"Right"<<endl;
    }
    else cout<<"Balanced"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctype.h>
using namespace std;

int main ()
{
    int a, b;
    char c[50];
    scanf("%d %d", &a, &b);
    for(int i = 0; i <a;i++)
        cin >> c[i];
    cout<<endl;
    c[b-1] = tolower(c[b-1]);
    for(int i = 0;i<a;i++)
        cout << c[i];
    cout<<endl;

    return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
	static IntStream INS(int n) {return REPS(n).map(i->getInt());}
	static Scanner s=new Scanner(System.in);
	static int getInt(){return Integer.parseInt(s.next());}
	public static void main(String[]$){
		int x=getInt();
		System.out.println(Math.abs(getInt()-x)<Math.abs(getInt()-x)?"A":"B");
	}
}


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

int main() {
    int n, k;
    cin >> n >> k;
    int a[n+1] = {0}, b[n+1] = {0};
    for(int i = 0; i < n; ++i) cin >> a[i];
    if(k >= n-1) {
        for(int i = 0; i < n; ++i) cout << n << ' ';
        cout << '\n';
        return 0;
    }
    while(k) {
        for(int i = 0; i < n; ++i) {
            b[max(0, i - a[i])]++;
            b[min(n, i + a[i] + 1)]--;
        }
        bool flag = true;
        for(int i = 1; i <= n; ++i) {
            b[i] += b[i-1];
            if(b[i-1] != n) flag = false;
        }
        
        if(flag) {
            for(int i = 0; i < n; ++i) cout << n << ' ';
            cout << '\n';
            return 0;
        }
        for(int i = 0; i <= n; ++i) a[i] = b[i], b[i] = 0;
        k--;
    }

    for(int i = 0; i < n; ++i) cout << a[i] << ' ';
    cout << '\n';
}


Measured memory_bytes: 5212