akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<cstdlib>
#include<cctype>
#include<cmath>
#define ll  long long
#define inf 99999999
using namespace std;
int n,c;

struct node{
    int start;
    int end;
    int num;
};



node recorder[100005];
node list[100005];
bool cmp(node a,node b){
    if(a.start!=b.start){
        return a.start<b.start;
    }
    if(a.end!=b.end){
        return a.end<b.end;
    }
    return a.num<b.num;
}

int main()
{
    cin>>n>>c;
    for(int i=1;i<=n;i++){
        scanf("%d %d %d",&list[i].start,&list[i].end,&list[i].num);
    }
    sort(list+1,list+1+n,cmp);
    int res=1;
    recorder[res] = list[1];

    int flag=0;
    for(int i=2;i<=n;i++){
        flag=0;
        for(int j=1;i<=res;j++){
            if(recorder[j].num == list[i].num){
                recorder[j].end= list[i].end;
                flag=1;
                break;
            }
        }
        if(flag){
            continue;
        }
        for(int j=1;j<=res;j++){
            if(list[i].start>recorder[j].end){
                recorder[j] = list[i];
                flag=1;
                break;
            }
        }
        if(flag){
            continue;
        }
        ++res;
        recorder[res] = list[i];
    }
    if(res>c){
        res=c;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1408
from collections import Counter


def main():
    n = int(input())
    prime = [2, ]
    X = [i for i in range(0, n + 1)]
    for i in range(3, n + 1):
        x = i ** 0.5
        for p in prime:
            if p > x:
                prime.append(i)
                break
            if i % p == 0:
                X[i] = p
                break
        else:
            prime.append(i)

    def cnt(n):
        L = list()
        while n != 1:
            L.append(X[n])
            n //= X[n]
        C = Counter(L)
        ans = 1
        for c in C.values():
            ans *= c + 1
        return ans
    print(sum(cnt(i) for i in range(1, n)))



if __name__ == "__main__":
    main()


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

int main(){
  int n, k;
  int a[200005];
  cin >> n >> k;
  rep(i, n)cin >> a[i];
  
  for(int i=k;i<n;i++){
    if(a[i]>a[i-k]){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    } 
  }

  return 0;
}


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

using namespace std;

int gcd (int a, int b) {
    if (b == 0)
        return a;
    else
        return gcd (b, a % b);
}

int main() {

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

	int K, S = 0;
	cin >> K;
	for (int a = 1; a <= K; ++a) {
		for (int b = 1; b <= K; ++b) {
			for (int c = 1; c <= K; ++c) {
				S += gcd(gcd(a, b), c);
			}
		}
	}
	cout << S << '\n';
	return 0;
}

Measured memory_bytes: 3636
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <limits>
#include <numeric>
#include <utility>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#ifndef debug_on
#define debug_on 0
#endif

#define dbg \
    if(debug_on) cerr << "DEBUG:"
#define ast(cond)           \
    do {                    \
        if((cond) == false) \
        {                   \
            if(debug_on)    \
            cerr << "ASSERT" << #cond " failed at line:" << __LINE__ << endl;   \
            exit(1);        \
        }                   \
    }while(0)

int main(int, char *[])
{
    string S, T;
    cin >> S;
    cin >> T;

    for(size_t offset = 0; offset < S.length(); ++offset)
    {
        bool same = true;
        for(size_t i = 0; i < S.length(); ++i)
        {
            const char s = S[i];
            const char t = T[(i + offset) % T.length()];
            if(s != t)
            {
                same = false;
                break;
            }
        }
        if(same)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N = int(input())
a, d = map(int, input().split())
M = int(input())
data = {}

def get_i(data, i):
    if i in data:
        return data[i]
    else:
        return a + d * i

def data_swap(y, z, data):
    tmp = get_i(data, y)
    data[y] = get_i(data, z)
    data[z] = tmp

def data_write(y, z, data):
    data[y] = get_i(data, z)

for m in range(M):
    # for i in range(5):
    #     print(get_i(data, i))
    # print("---")

    x, y, z = map(int, input().split())
    y -= 1
    z -= 1
    if x == 0:
        data_swap(y, z, data)
    else:
        data_write(y, z, data)

K = int(input())
print(get_i(data, K-1))

Measured memory_bytes: 7724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define MOD 1000000007

void solve() {
    string s;
    ll n, ans;
    cin >> n >> s;
    vi r, g;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R')
            r.push_back(i);
        else if (s[i] == 'G')
            g.push_back(i);
    }
    ans = (ll)r.size() * (ll)g.size() * (n - (ll)r.size() - (ll)g.size());
    for (auto &i : r) {
        for (auto &j : g) {
            int k1 = 2 * i - j, k2 = 2 * j - i, k3 = (i + j) / 2;
            if (k1 >= 0 && k1 < n && s[k1] == 'B')
                --ans;
            if (k2 >= 0 && k2 < n && s[k2] == 'B')
                --ans;
            if ((i + j) % 2 == 0 && s[k3] == 'B')
                --ans;
        }
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define N 2*10e5
#define precise cout<<fixed<<setprecision(10)
#pragma GCC optimize("O0")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#define rep(i,a,b) for(int i=a;i<b;i++)
#define min3(a,b,c) min(a,min(b,c))
#define nl cout<<"\n";
#define all(v) v.begin(),v.end()
#define F first
#define S second
typedef unsigned long long ll;
typedef vector<long long> vl;
typedef vector<pair<long,long>> vp;
void get(ll arr[],ll n){for(ll i=0;i<n;i++) cin>>arr[i];}
ll gcd(ll a,ll b);
ll binpow(ll a,ll b);
void solve()
{
	ll n;
	cin>>n;
	ll arr[n];
	map <ll,ll> m;
	ll sum=0;
	rep(i,0,n)
	{
		cin>>arr[i];
		m[arr[i]]++;
		sum+=arr[i];
	}
	ll q;
	cin>>q;
	ll b,c;
	rep(i,0,q)
	{
		cin>>b>>c;
		ll co= m[b];
		sum = sum- co*b + co*c;
		m[b]=0,m[c]+=co;
		cout<<sum;nl; 
	}
	
}
int main()
{
 	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
	 	solve();
	}
	//cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}
ll binpow(ll a, ll b) {
   ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define Pi 1
#define LL long long
#define ULL unsigned long long
#define LD long double

using namespace std;

#define MAX_N 200005
#define MAX_M 200005

LL K;

int main()
{
  cin >> K;

  const LL N = 50;

  LL ans[N];
  LL LOOP = K / N;

  for (int i = 0; i < N; i++) {
    ans[i] = N - 1 + LOOP;
  }

  K %= N;

  while(K > 0){
    K--;

    LL tmp = 100000000000000000;
    int index = -1;
    for (int i = 0; i < N; i++) {
      if(ans[i] < tmp){
        tmp = ans[i];
        index = i;
      }
    }

    for (int i = 0; i < N; i++) {
      if(i == index){
        ans[i] += N;
      }
      else{
        ans[i]--;
      }
    }

  }

  cout << N << endl;
  for (int i = 0; i < N; i++) {
    cout << ans[i];
    if(i < N-1){
      cout << " ";
    }
  }

  cout << endl;

  return 0;
}


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

int S[2][222][222];
/*int S2[111][111];
  int S3[222][222];*/
int fie[111][111];
int W,H;
int dx[2][7]={{1,-1,-1,0,-1,0},
	      {1,-1,0,1,0,1}  };
int dy[]={0,0,1,1,-1,-1};

int mdx[]={0,1,-1,0,0,1};
int mdy[]={-1,-1,0,0,0,0};

int search(int x,int y){
  if(fie[x][y]==2) return 0;
  fie[x][y]=2;
  int kg=y%2;
  int ret=0;
  for(int i=0;i<6;i++){
    int nx = x+dx[kg][i];
    int ny = y+dy[i];
    if(nx<1 || ny<1 || nx>W || ny>H){
      ret++;
      continue;
    }
    if(fie[nx][ny]==1) continue;
    ret+=search(nx,ny);
  }
  return ret;
}

void ume(int x,int y){
  if(search(x,y)){
    for(int i=1;i<=H;i++){
      for(int j=1;j<=W;j++){
	if(fie[j][i]==2) fie[j][i]=-1;
      }
    }
  }else{
    for(int i=1;i<=H;i++){
      for(int j=1;j<=W;j++){
	if(fie[j][i]==2) fie[j][i]=1;
      }
    }
  }
}

void print_fie(){
 for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++) printf("%2d ",fie[j][i]);
    puts("");
  }
}

void solve(int x,int y){
  //  printf("%d %d\n",x,y);
  int kg = y%2;
  for(int i=0;i<6;i++){
    int ind = (i/2)%2;
    int mx = (x-1)*2+mdx[i]+kg;
    int my = y+mdy[i];
    if(i/2==1){
      mx = x+mdx[i];
      my = y+mdy[i];
    }
    //    printf("check : %d %d %d ... %d\n",ind,mx,my,S[ind][mx][my]);
    S[ind][mx][my]++;
  }
  for(int i=0;i<6;i++){
    int nx = x+dx[kg][i];
    int ny = y+dy[i];
    if(nx<1 || ny<1 || nx>W || ny>H) continue;
    if(fie[nx][ny]==1){
      fie[nx][ny]=2;
      solve(nx,ny);
    }
  }
}

main(){
  scanf("%d %d",&W,&H);
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++) scanf("%d",&fie[j][i]);
  }
  
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(fie[j][i]==0){
	ume(j,i);
      }
    }
  }
  //  print_fie();
  int res=0;
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(fie[j][i]==1){
	fie[j][i]=2;
	solve(j,i);
      }
    }
  }
  for(int k=0;k<2;k++){
    for(int i=0;i<H*2+2;i++){
      //      printf("%d : %d:::\n",k,i);
      for(int j=0;j<W*2+2;j++){
	//	printf("%2d ",S[k][j][i]);
	if(S[k][j][i]==1) ++res;
      }
      //      puts("");
    }
  }
  printf("%d\n",res);

}

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    ll A[N]; rep(i, N) cin >> A[i];
    ll sum[N]; sum[0] = A[0]; rep(i, N-1) sum[i+1] = sum[i]+A[i+1];
    ll ans = 10001000100010001ll;
    rep(i, N-1) ans = min(ans, abs(sum[N-1]-sum[i]-sum[i]));
    cout << ans << endl;
    return 0;
}

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

int dfs(vector<vector<int>> const& g, int v, vector<bool>& used, set<int> vs) {
    vs.insert(v);
    if(vs.size() == g.size()) {
        return 1;
    }
    int res = 0;
    for(int i=0; i<g.size(); ++i) {
        if(g[v][i] == 1 && !used[i]) {
            used[v] = true;
            res += dfs(g, i, used, vs);
            used[v] = false;
        }
    }
    return res;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> g(N, vector<int>(N));
    for(int i=0; i<M; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a][b] = g[b][a] = 1;
    }
    set<int> s;
    s.insert(0);
    vector<bool> used(N, false);
    used[0] = true;
    cout << dfs(g, 0, used, s) << endl;
}


Measured memory_bytes: 256
from sys import stdin

[D, G] = [int(x) for x in stdin.readline().rstrip().split()]
data = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(D)]

def calculate_score(arr): #arrは100i点の問題を解いた数の配列, 長さはD
    tot_score = 0
    for i in range(len(arr)):
        num = arr[i]
        tot_score += num * 100*(i+1)
        if num == data[i][0]:
            tot_score += data[i][1]
    return tot_score

def func1(arr,G): #arrは長さDの配列で、それぞれi点問題のボーナスを得るかどうか
    #arrだけのボーナスを得たときに、総合スコアをG点にするための問題数は容易に求められる

    problem_num = 0
    tot_score = 0
    for i in range(len(arr)):
        if arr[i] == 1:
            tot_score += data[i][1]
            tot_score += data[i][0]*100*(1+i)
            problem_num += data[i][0]
    
    if tot_score>=G:
        return problem_num

    for i in range(len(arr)):
        if arr[len(arr)-i-1]==0:
            for j in range(data[len(arr)-i-1][0]-1):
                tot_score += 100*(len(arr)-i)
                problem_num+=1
                if tot_score>=G:
                    return problem_num
    
    return 100000

min_problem = 10000
for i in range(2**D):
    i_bin = bin(i)
    i_bin_arr = []
    for j in range(D-len(i_bin[2:])):
        i_bin_arr.append(0)

    for j in range(len(i_bin[2:])):
        i_bin_arr.append(int(i_bin[2+j]))

    problem_num = func1(i_bin_arr,G)
    if problem_num<min_problem:
        min_problem=problem_num

print(min_problem)








Measured memory_bytes: 3064
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,m;cin>>n>>m;
  V<Pi> ans(m);

  
  if(n%2){
    ll l=1,r=n-1;
    rep(i,0,m){
      ans[i]=mp(l,r);
      ++l;
      --r;
    }
  }else{
    ll l=1,r=n-1;
    rep(i,0,m){
      if(r-l == n/2)++l;
      ans[i]=mp(l,r);
      ++l;
      --r;

      if(r-l == n/2 -1)++l;
    }
  }
  rep(i,0,m){
    cout<<ans[i].fs<<" "<<ans[i].sc<<ENDL;
  }
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3928
#include<stdio.h>
int main()
{
	int x,count=0,bangou,syaryou[10];
	while(scanf("%d",&bangou)!=EOF)
	{
		if(bangou==0)
		{
			count--;
			printf("%d\n",syaryou[count]);
		}
		else
		{
			syaryou[count]=bangou;
			count++;
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <time.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 2020000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll n; cin >> n;
	vl a(n); rep(i,n) cin >> a[i];
	ll ans = 1000;
	ll kabu = 0;
	rep(i,n-1){
		if(a[i] < a[i+1]){
			kabu += ans / a[i];
			ans -= ans / a[i] * a[i];
		}else if(a[i] > a[i+1]){
			ans += a[i] * kabu;
			kabu = 0;
		}
	}
	ans += a[n-1] * kabu;
	cout << ans << "\n";
}

Measured memory_bytes: 3628
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int [] pasta = new int [3];
		int [] jyusu = new int [2];
		for(int i = 0; i < pasta.length; i++) {
			pasta[i] = sc.nextInt();
		}
		for(int i = 0; i < jyusu.length; i++) {
			jyusu[i] = sc.nextInt();
		}
		int low = pasta[0] + jyusu[0];
		for(int i = 0; i < pasta.length; i++) {
			for(int j = 0; j < jyusu.length; j++) {
				if (low > pasta[i] + jyusu[j]){
					low = pasta[i] + jyusu[j];
				}
			}
		}
		System.out.println(low-50);
	}

}

Measured memory_bytes: 17164
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	a := scanInts(n)
	ans := 0
	for i := 0; i < n; i++ {
		if (i+1)%2 == 1 && a[i]%2 == 1 {
			ans++
		}
	}
	fmt.Fprintln(wr, ans)
}


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

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


Measured memory_bytes: 3200
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

void init(); //ノードの初期化
void insert(int ); //ノードの追加
struct Node* listSearch(int );
void deleteNode(struct Node *);
void deleteFirst();
void deleteLast();
void deleteKey(int );
void print();

struct Node{

  int key;
  struct Node *prev;
  struct Node *next;

};

struct Node *NIL =NULL;

int main(){

  int sumcommand,i,key;
  char command[10];

  init();

  scanf("%d",&sumcommand);

  for(i = 0; i < sumcommand; i++){

    scanf("%s",command);

    if((strcmp("insert",command)) == 0){

      scanf("%d",&key);
      insert(key);
    

    }

    else if((strcmp("delete",command)) == 0){

      scanf("%d",&key);
      deleteKey(key);
    }

    else if((strcmp("deleteFirst",command))==0){

      deleteFirst();
    }

    else if((strcmp("deleteLast",command))== 0){

       deleteLast();

    }

  }

  print();

  return 0;

}

void init(){

  NIL = (struct Node *)malloc(sizeof(struct Node));

  NIL->next  = NIL;
  NIL->prev = NIL;

}

void insert(int key){

  struct Node *x = (struct Node*)malloc(sizeof(struct Node));


  x -> key = key;

  x->next = NIL->next;
  NIL->next->prev = x;

  NIL->next = x;

  x->prev = NIL;

}

struct Node* listSearch(int key){

  struct Node *y = NIL->next;


  while(y != NIL && y->key != key){

    y = y->next;

  }

  return y;

}

void deleteNode(struct Node *x){

  if(x == NIL){
    
    return ;
  
  }

  x->prev->next = x->next;
  x->next->prev = x->prev;

   free(x);

  
}

void deleteFirst(){

  deleteNode(NIL->next);

}

void deleteLast(){

  deleteNode(NIL->prev);

}

void deleteKey(int key){

  deleteNode(listSearch(key));
}

void print(){

  struct Node *z = NIL->next;

  int x;

  while(1){

    if(z == NIL){

      break;

    }

    if(x++ > 0){

      printf(" ");

    }

    printf("%d", z->key);

    z = z->next;

  }

  printf("\n");

}

Measured memory_bytes: 31788
S = input()

s = S[0]
n = int(s)

def F(ans,total,i):
  if i == 4:
    if total == 7:
      print(ans + "=7")
      exit()

  else:
    return F(ans + "+" + S[i],total + int(S[i]),i + 1),F(ans + "-" + S[i],total - int(S[i]),i + 1)

F(s,n,1)



Measured memory_bytes: 3060
# E - Red and Green Apples
def main():
    X, Y, A, B, C = map(int, input().split())
    P = sorted(map(int, input().split()), reverse=True)[:X]
    Q = sorted(map(int, input().split()), reverse=True)[:Y]
    R = list(map(int, input().split()))
    PQR = P + Q + R
    PQR.sort(reverse=True)
    ans = sum(PQR[: X + Y])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 22520
#include<iostream>
            using namespace std;
             
            int main(){
              int k;
              cin>>k;
              string str;
              cin>>str;
              int w= str.size();
              if(k>=w){
                cout<<str<<endl;
              }else{
                cout<<str.substr(0,k)+"..."<<endl;
              }
              
              
            }

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define all_white first
#define sth_is_black second

using namespace std;
using ll = long long;
const int nax = 1e5 + 5;

int n, mod;
vector<int> graph[nax];
pair<int, int> down[nax], up[nax];
vector<vector<int>> children;
vector<vector<pair<int, int>>> pref, suf;

int mul(int a, int b)
{
    a = (ll) a * b % mod;

    return a;
}

int add(int a, int b)
{
    a += b;

    if(a >= mod)
        a -= mod;

    return a;
}

pair<int, int> merge(const pair<int, int> &a, const pair<int, int> &b)
{
    pair<int, int>p{1, 0};
    p.all_white = mul(a.all_white, b.all_white);
    p.sth_is_black = add(mul(a.all_white, b.sth_is_black), mul(a.sth_is_black, add(b.all_white, b.sth_is_black)));

    return p;
}

pair<int, int> process(pair<int, int> p)
{
    return {p.all_white, add(p.all_white, p.sth_is_black)};
}

void dfs_one(int nod, int dad)
{
    pair<int, int> p{1, 0};

    for(int x : graph[nod])
    {
        if(x != dad)
        {
            children[nod].push_back(x);
            dfs_one(x, nod);
            p = merge(p, down[x]);
        }
    }

    down[nod] = process(p);
}

void dfs_two(int nod, int dad)
{
    for(int i = 0; i < (int) children[nod].size(); i++)
    {
        pair<int, int> p = {1, 0};

        if(i)
            p = merge(p, pref[nod][i - 1]);
        if(i != (int) children[nod].size() - 1)
            p = merge(p, suf[nod][i + 1]);

        int child = children[nod][i];

        if(nod != 1)
            p = merge(p, up[nod]);

        up[child] = process(p);

        dfs_two(child, nod);
    }
}

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

    for(int i = 0; i < n - 1; i++)
    {
        int a, b;

        cin >> a >> b;

        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    children.resize(n + 1);
    pref.resize(n + 1);
    suf.resize(n + 1);

    dfs_one(1, -1);
    for(int i = 1; i <= n; i++)
    {
        int m = children[i].size();
        pair<int, int> p = {1, 0};

        for(int j = 0; j < m; j++)
        {
            p = merge(p, down[children[i][j]]);
            pref[i].push_back(p);
        }

        p = {1, 0};

        for(int j = m - 1; j >= 0; j--)
        {
            p = merge(p, down[children[i][j]]);
            suf[i].push_back(p);
        }
        reverse(suf[i].begin(), suf[i].end());
    }

    dfs_two(1, -1);

    for(int i = 1; i <= n; i++)
    {
        pair<int, int> p = {1, 0};

        if(i != 1)
            p = merge(p, up[i]);

        if(children[i].size())
            p = merge(p, pref[i].back());

        p = process(p);
        cout << p.sth_is_black << '\n';
    }

    return 0;
}


Measured memory_bytes: 33496
#include <iostream>
#include <map>
#include <tuple>

using namespace std;

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

    map<pair<int, int>, int> W;
    for (int i = 0; i < N; ++i) {
        int x, y;
        cin >> x >> y;
        cin >> W[make_pair(x, y)];
    }

    int ans = 0;
    for (auto pp : W) {
        int x, y;
        tie(x, y) = pp.first;

        int sum = 0;
        for (int dx = 0; dx <= 1; ++dx) {
            for (int dy = 0; dy <= 1; ++dy) {
                auto p = make_pair(x + dx, y + dy);
                if (W.count(p)) sum += W[p];
            }
        }
        ans = max(ans, sum);

        sum = 0;
        for (int dx = -1; dx <= 0; ++dx) {
            for (int dy = 0; dy <= 1; ++dy) {
                auto p = make_pair(x + dx, y + dy);
                if (W.count(p)) sum += W[p];
            }
        }
        ans = max(ans, sum);
    }

    cout << ans << " / 1" << endl;
    return 0;
}



Measured memory_bytes: 9376
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,x,y,p,ans,q,r;
  cin>>a>>b>>c>>x>>y;
  p=max(x,y);
  p=p*2*c;
  if(x<y){
    q=2*c*x+(y-x)*b;
  }
  else{
    q=2*c*y+(x-y)*a;
  }
  r=a*x+b*y;
  ans=min({p,q,r});
  cout<<ans;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
//#include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
const int C=1e+9;
int N;
int p[20000];
int d[20000];
int a[20000];
int b[20000];
int X;

int main()
{
	cin>>N;
	rep(i,N){
		cin>>p[i];
		p[i]--;
		d[p[i]]=i;
	}
	a[0]=1;
	b[0]=C;
	rep1(i,N-1){
		X=d[i]-d[i-1];
		if(X>0){
			a[i]=a[i-1]+X+1;
			b[i]=b[i-1]-1;
		}
		else{
			a[i]=a[i-1]+1;
			b[i]=b[i-1]-1+X;
		}
	}
	rep(i,N-1) cout<<a[i]<<" ";
	cout<<a[N-1]<<endl;
	rep(i,N-1) cout<<b[i]<<" ";
	cout<<b[N-1]<<endl;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
	int A = 0;
	int B = 0;
	int C = 0;
	
	// 整数の入力
	scanf("%d", &A);
	scanf("%d", &B);
	
	C = A * B;
	
	// 出力
	printf("%d",C);

	return 0;
}

Measured memory_bytes: 1728
N, X, Y = map(int, input().split())
a = [0]*N
for i in range(1,N+1):
    for j in range(i+1,N+1):
        a[min(j-i, abs(i-X)+1+abs(j-Y))-1]+= 1
for i in range(N-1):
    print(a[i])

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long 
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
 
 
//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b,ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
 
 int power(long long int x, long long  int y,long long  int p)  
{  
     int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p  
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  
 int  main() {
     
      long long int n,a,b;
     cin>>n>>a>>b;
     long long int ans=power(2,n,1000000007);
     ans -= 1;
	ans -= c(n, a,mod);
	ans -= c(n, b,mod);
	while (ans < 0)ans += mod;
	ans %= mod;
	cout << ans << endl;
	return 0;
}

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

int main()
{
    int K;
    cin >> K;
    rep (i, K) {
        cout << "ACL";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3592
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

set <long long> ans;

void check(long long n, long long k) {
    if (!(2 <= k && k <= n))
        return;
    while (n >= k) {
        if (n % k == 0)
            n /= k;
        else 
            n %= k;
    }
    if (n == 1) {
        ans.insert(k);
        //cout << k << " ";
    }
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    long long n;
    cin >> n;
    for (long long i = 1; i * i <= n - 1; ++i) {
        if ((n - 1) % i == 0) {
            check(n, i);
            check(n, (n - 1) / i);
        }
    }
    for (long long i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            check(n, i);
            check(n, n / i);
        }
    }
    cout << sz(ans);
    return 0;
}

Measured memory_bytes: 256
// Author by Md. Jashim Uddin_RMSTU

#include<bits/stdc++.h>
using namespace std;
#define     sf(a)           scanf("%d",&a)
#define     sff(a,b)        scanf("%d %d",&a,&b)
#define     sfff(a,b,c)     scanf("%d %d %d",&a,&b, &c)
#define     pb              push_back
#define     ll              long  long int
#define     fast            ios_base :: sync_with_stdio(false);cin.tie(0)
#define     pi              2*acos(0)
#define     sp              fixed<<setprecision
#define     lcm(a,b)        (a*b)/gcd(a,b)
#define     gcd(a,b)        _gcd(a,b)

#define     forn(i,n)       for(int i=1;i<=n;i++)
#define     min3(a,b,c)     min(a,min(b,c)
#define     M             32000

int main()
{
    ll n,m;
    cin>>n>>m;
    if(n<10)
    {
        ll s= 100*(10-n);
        cout<<(m+s)<<endl;

    }
    else cout<<m<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> xv(N+1), yv(M+1);
  xv.at(0) = X;
  yv.at(0) = Y;
  for(int i=1;i<=N;i++){
    cin >> xv.at(i);
  }
  for(int i=1;i<=M;i++){
    cin >> yv.at(i);
  }
  std::sort(xv.begin(), xv.end() );
  std::sort(yv.begin(), yv.end() );
  if(xv.at(N) < yv.at(0)){
    cout << "No War" << endl;
  }else{
    cout << "War" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n, m, x;
  cin>>n>>m>>x;
  int c[n];
  int a[n][m];
  REP(i, n){
    cin>>c[i];
    REP(j, m) cin>>a[i][j];
  }
  bool flag = false;
  int ans = 0;
  REP(k, 1<<n){
    vector<int> temp(m, 0);
    int v = 0;
    REP(i, n){
      if(k>>i&1){
        v += c[i];
        REP(j, m) temp[j] += a[i][j];
      }
    }
    bool ok = true;
    REP(j, m){
      if(temp[j] >= x) continue;
      ok = false;
      break;
    }
    if(!ok) continue;
    if(!flag){
      flag = true;
      ans = v;
    }else{
      ans = min(ans, v);
    }
  }
  if(!flag){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}


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

import sys
sys.setrecursionlimit(300000)

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, S: str):
    if S[:N // 2] == S[N // 2:]:
        ret = YES
    else:
        ret = NO
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
// ABC166D.cpp

#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
int main()
{
    int x;
    cin >> x;
    for (int a = 1; a < 1000; a++) {
        ll a5 = 1;
        rep(i, 5) a5 *= a;
        for (int b = -1000; b < 1000; b++) {
            ll b5 = 1;
            rep(i, 5) b5 *= b;
            if (a5 - b5 == x) {
                cout << a << " "<<b << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3196
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())
    S = list(input())
 
    c = [[] for _ in range(3)] #c = [[]] * 3 とすると全ての要素にappendされてしまうのでNG
    for i in range(len(S)):
        if S[i] == 'R':
            c[0].append(i)
        elif S[i] == 'G':
            c[1].append(i)
        else : # 'B'のとき
            c[2].append(i)
    total = len(c[0]) * len(c[1]) * len(c[2])

    reigai = 0 #先に条件2を満たすものを考えてから、条件1に当てはまるかを判定
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            k = j + (j - i)
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                reigai += 1
    print(total - reigai)


if __name__ == "__main__":
    main()

Measured memory_bytes: 68444
n = int(input())
a = list(map(int, input().split()))
_a = list(map(lambda x: x * (-1), a))


def func(l: list):
    _ans = 0
    product = 0
    for i in range(n):
        product += l[i]

        if i % 2 == 0:
            if product <= 0:
                _ans += abs(product) + 1
                product = 1

        elif i % 2 == 1:
            if product >= 0:
                _ans += abs(product) + 1
                product = -1
    return _ans

ans = min(func(a), func(_a))
print(ans)


Measured memory_bytes: 14468
def dist(p, q)
  Math.sqrt( (p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2 )
end

INF = 1<<29
def dijkstra(n, start, goal, route, bn)
  arr = [start]
  ret = { start => start }
  min_d = [INF] * 1001
  min_d[start] = 0
  until arr.empty?
    a = arr.min{ |x, y| min_d[x] <=> min_d[y] }
    arr.delete(a)
    if a == goal
      return ret[a]
    end
    idx = bn.index(a)
    n.times do |i|
      next if idx == i
      if route[idx][i]
        d = min_d[a] + route[idx][i]
        if (old = min_d[bn[i]]) > d
          min_d[bn[i]] = d
          ret[bn[i]] = [*ret[a], bn[i]]
          if old == INF
            arr << bn[i]
          end
        end
      end
    end
  end
end

while n = gets.to_i
  break if n == 0
  bn = []
  bld = []
  n.times{ a, x, y = gets.split.map(&:to_i); bn << a; bld << [x, y] }
  route = bld.map{|a| bld.map{ |b| dist(a, b) if dist(a, b) <= 50 } }
  gets.to_i.times do
    s, g = gets.split.map(&:to_i)
    ans = dijkstra(n, s, g, route, bn)
    puts ans.nil? ? 'NA' : ans.join(' ')
  end
end

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 100005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

struct edge{int to;ll cost;};
vector<edge> G[SIZE];
ll d[SIZE];

void dijkstra(int s){
  priority_queue<P,vector<P>,greater<P>> que;
  fill(d,d+SIZE,INF);
  d[s] = 0;
  que.push(P(0,s));

  while(!que.empty()){
    P p = que.top();que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(edge e : G[v]){
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to],e.to));
      }
    }
  }
}

void add_edge(int a,int b,ll c){
  G[a].push_back((edge){b,c});
}

int V,E,r;

int main(){
  cin >> V >> E >> r;
  rep(i,0,E){
    int s,t;
    ll D;
    cin >> s >> t >> D;
    add_edge(s,t,D);
  }
  dijkstra(r);
  rep(i,0,V){
    if(d[i] >= INF){
      cout << "INF" << endl;
      continue;
    }
    cout << d[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 18552
#include "bits/stdc++.h"
using namespace std;
int gcd(int a, int b)
{
    if(a < b)
    {
        swap(a, b);
    }
    if(a % b)
    {
        return gcd(b, a % b);
    }
    else
    {
        return b;
    }
}

int main()
{
    int n;
    scanf("%d", &n);
    vector<int> a(n + 1, 1000000000);
    scanf("%d", &a[n]);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &a[i]);
    }
    sort(a.begin(), a.end());
    int mx = a[1] - a[0];
    for (int i = 1; i < n; ++i)
    {
        mx = gcd(mx, a[i + 1] - a[i]);
    }
    printf("%d\n", mx);
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<math.h>
using namespace std;

int main(){

    int n, t, max, min;
    long sum;
    t = 0;
    sum = 0;
    cin >> n;
    int an[n];
    while(t != n){
        cin >> an[t];
        t++;
    }
    t = 0;
    max = an[0];
    min = an[0];
    while(t != n){
        if(max<an[t]) max = an[t];
        if(min>an[t]) min = an[t];
        sum = sum + an[t];
        t++;
    }

    cout << min << " " << max << " " << sum << endl;

    return 0;
}


Measured memory_bytes: 3100
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		UINT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main()
{
	ll N = 0;
	ll K = 0;
	ll ret = 1;

	cin >> N;
	cin >> K;

	Rep(i, N) {
		if ( ret < K ) {
			ret *= 2;
		}
		else {
			ret += K;
		}
	}

	cout << ret << endl;

	return 0;
}





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

int main() {
	//入力
	int n,k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	//答え
	for (int i = 0;i < n - k;++i) {
		if ((double)a[i+k]/a[i]>1.0)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
}

Measured memory_bytes: 4012
#include <cstdio>
using namespace std;

int N;
int resp[1001];
int days[1001][8];

int main(){
  scanf("%d", &N);
  
  char c[N + 1];
  scanf("%s", c);
  
  resp[0] = 1;
  
  for(int i = 1; i <= N; i++){
    if(c[i - 1] == 'J'){
      resp[i] = 1;
    }else if(c[i - 1] == 'O'){
      resp[i] = 2;
    }else if(c[i - 1] == 'I'){
      resp[i] = 4;
    }
    for(int j = 0; j < 8; j++){
      days[i][j] = 0;
    }
  }
  
  for(int i = 0; i < 8; i++){
    if(i == 1){
      days[0][i] = 1;
    }else{
      days[0][i] = 0;
    }
  }
  
  for(int i = 1; i <= N; i++){
    for(int j = 0; j < 8; j++){
      if((j & resp[i]) != 0){
        for(int k = 0; k < 8; k++){
          if((j & k) != 0){
            days[i][j] += days[i - 1][k];
            days[i][j] %= 10007;
          }
        }
      }
    }
  }
  
  int ret = 0;
  
  for(int i = 0; i < 8; i++){
    ret = (ret + days[N][i]) % 10007;
  }
  
  printf("%d\n", ret);
  
  return 0;
  
}

Measured memory_bytes: 1060
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll n;
    cin>>n;
    ll a=1,b=1,c=1;
    for(int i=0;i<n;i++){
        a*=10;
        a%=MOD;
        b*=9;
        b%=MOD;
        c*=8;
        c%=MOD;
    }
    ll ans=a - (2 * b) + c;
    ans%=MOD;
    ans+=MOD;
    ans%=MOD;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3628
import sys
sys.setrecursionlimit(10000)
input = sys.stdin.readline
N, M = [int(i) for i in input().split()]
AB = [[int(i) - 1 for i in input().split()] for _ in range(M)]
ans = [N * (N - 1) // 2]

class UnionFind:
    def __init__(self, element_count):
        self.parent = [i for i in range(element_count)]
        self.counter = [1 for _ in range(element_count)]
    
    def root(self, index):
        root = index
        while root != self.parent[root]:
            root = self.parent[root]
        while index != root:
            index, self.parent[index] = self.parent[index], root
        return root
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            self.parent[y] = x
            self.counter[x] += self.counter[y]
            self.counter[y] = 0
    
    def count(self, index):
        return self.counter[self.root(index)]

    def is_same(self, x, y):
        return self.root(x) == self.root(y)

uf = UnionFind(N)
for a, b in AB[:0:-1]:
    if not uf.is_same(a, b):
        ans.append(ans[-1] - uf.count(a) * uf.count(b))
        uf.unite(a, b)
    else:
        ans.append(ans[-1])
for a in ans[::-1]:
    print(a)

Measured memory_bytes: 78172
# 初期入力
import sys
input = sys.stdin.readline
N = int(input())
p = list(map(int, input().split()))
p_sort =sorted(p)
"""
max_p =max(p)
max_index =p.index(max_p)
min_p =min(p)
min_index =p.index(min_p)

#max minの位置を入れ替える
if max_index != N and min_index !=0:
p[max_index] =min_p
p[min_index] =max_p
"""
#昇順か判定
count =0
ans ="YES"
for i in range(N):
    if p[i] !=p_sort[i]:
        count +=1
        if 2 < count:
            ans ="NO"

print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;

public static class Program
{
    public static void Main(string[] args)
    {
        var x = int.Parse(Console.ReadLine());
        foreach (var item in GetPrimeNumbers(x))
        {
            Console.WriteLine(item);
            return;
        }
    }

    public static IEnumerable<int> GetPrimeNumbers(int x)
    {
        var candidate = x;
        if (candidate == 2)
        {
            yield return candidate;
        }
        while (true)
        {
            if (IsPrimeNumbers(candidate))
            {
                yield return candidate;
            }
            candidate++;
        }
    }

    public static bool IsPrimeNumbers(int x)
    {
        if (x % 2 == 0)
        {
            return false;
        }
        for (int i = 3; i <= x / i; i+=2)
        {
            if (x % i == 0)
            {
                return false;
            }
        }
        return true;
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const int mod = 1000000007;
int dp[100005][2];//0->same 1->smaller

int main(){
    string s; cin >> s;
    int n = s.size();
    dp[0][0] = 1;
    rep(i,n){
        //i桁目でa+b=0
        if(s[i] == '0'){
            (dp[i+1][0] += dp[i][0]) %= mod;
            (dp[i+1][1] += dp[i][1]) %= mod;
        }else{
            (dp[i+1][1] += (dp[i][0] + dp[i][1]) % mod) %= mod;
        }
        //i桁目でa+b=1
        if(s[i] == '0'){
            (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;//aとbどちらにbitが立っているか
        }else{
            (dp[i+1][0] += dp[i][0]*2 % mod) %= mod;
            (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
        }
    }
    int ans = (dp[n][0] + dp[n][1]) % mod;
    cout << ans << endl;
    return 0;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

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

    bool valid = true;
    char prev_tail;
    string w;
    set<string> said;
    rep(0, n) {
        cin >> w;

        if (said.find(w) != said.end()) {
            valid = false;
        }

        if (0 < i) {
            if (prev_tail != w[0]) {
                valid = false;
            }
        }

        prev_tail = w[w.size() - 1];
        said.insert(w);
    }

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

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 256