akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.*;
public class Main {
	static int INF = (int)1e9 + 7;
	int N,W;
	int[] v,w;
	int[][] dp;
	
	public int dfs(int n,int weight){
		if(n == N){
			return 0;
		}
		if(dp[n][weight] != -1)return dp[n][weight];
		int ret = 0;
		if(weight - w[n] >= 0)ret = Math.max(ret,dfs(n + 1,weight - w[n]) + v[n]);
		ret = Math.max(ret,dfs(n + 1,weight));
		return dp[n][weight] = ret;
	}
	
	public void solve() {
		N = nextInt();
		W = nextInt();
		v = new int[N];
		w = new int[N];
		dp = new int[N + 1][W + 1];
		for(int i = 0;i < N;i++){
			v[i] = nextInt();
			w[i] = nextInt();
		}
		for(int i = 0;i < N + 1;i++){
			for(int j = 0;j < W + 1;j++){
				dp[i][j] = -1;
			}
		}
		out.println(dfs(0,W));
	}
 
	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}
 
	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;
 
	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}
 
	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}
 
	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}
 
	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}
 
	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}
 
	public int nextInt() {
		return Integer.parseInt(next());
	}
 
	public long nextLong() {
		return Long.parseLong(next());
	}
 
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 29936
import math


while True:

    n = int(input())
    if n == 0:
        break

    else:
        point = list(map(int, input().split()))

        average = sum(point)/len(point)

        p_sum = []

        for i in range(n):
            delta = (point[i] - average)**2
            p_sum.append(delta)

        sigma = math.sqrt(sum(p_sum) / len(point))

        print(sigma)


Measured memory_bytes: 5708
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

bool cmp(pll p1, pll p2){
    return p2.first * (1+p1.second) < p1.first * (1+p2.second);
}

class DMangaMarket {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        lint T;
        in>>N>>T;
        vc<pll> A;
        vc<lint> B;
        REP(i, N){
            lint a, b;
            in>>a>>b;
            if(a) A.pb(mp(a, b));
            else B.pb(b);
        }
        sort(ALL(A), cmp);
        sort(ALL(B));
        int M = LEN(A), K = LEN(B);
        vvc<lint> dp(M+1, vc<lint>(31, 2*ten(9)));
        REP(i, M+1) dp[i][0] = 0;
        RREP(i, M) RREP(j, 30){
            dp[i][j] = min(dp[i-1][j], dp[i-1][j-1]+1+A[i-1].first*(dp[i-1][j-1]+1)+A[i-1].second);
        }
        int ans = 0;
        REP(i, 31){
            int tmp = i;
            if(dp[M][i]>T) break;
            lint cur = dp[M][i];
            REP(j, K){
                if(cur+1+B[j]>T) break;
                cur += B[j] + 1;
                ++tmp;
            }
            chmax(ans, tmp);
        }
        out<<ans<<'\n';
    }
};


int main() {
	DMangaMarket solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 58988
#include<iostream>
#include<string>
#include<vector>
using ll = unsigned long long;
using namespace std;


int main(void) {

    int n, l;
    cin >> n >> l;

    int planned = 0;
    int current_taste = 0;
    int min_ix = INT32_MAX;
    int min_taste = INT32_MAX;

    for(int i = 1; i <= n; ++i) {
        current_taste = l + i - 1;
        planned += current_taste;

        if (abs(current_taste) < abs(min_taste)) {
            min_ix = i;
            min_taste = current_taste;
        }
    }

    cout << planned - min_taste << endl;

    return 0;
}

Measured memory_bytes: 256
a,b,c,x,y = list(map(int,input().split()))

if (a+b)/2 >= c:
    if x >= y:
        ans1 = 2*c*y + a*(x-y)
        ans2 = 2*c*x
        print(min(ans1,ans2))
    
    else:
        ans1 = 2*c*x + b*(y-x)
        ans2 = 2*c*y
        print(min(ans1,ans2))
        
else: print(a*x + b*y)

Measured memory_bytes: 3064
def InsertionSort(a:list, n:int):
    for i in range(0,n):
        key = a[i]
        j = i - 1
        while( j >= 0 and a[j] > key):
            a[j+1] = a[j]
            j = j - 1
        a[j+1] = key
        print(" ".join(map(str,a)))
    return a

def main():
    n = int(input())
    a = list(map(int, input().split()))
    InsertionSort(a, n)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5600
s=input()
t=input()
sd={}
td={}
for i in s:
  if i in sd.keys():
    sd[i]+=1
  else:
    sd[i]=1
for i in t:
  if i in td.keys():
    td[i]+=1
  else:
    td[i]=1
if sorted(sd.values()) == sorted(td.values()):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(int a, int b){
   return b ? GCD(b, a%b) : a;
}

int LCM(int a, int b){
   return (a * b)/(GCD(a, b));
}

int sum(vector<int> a, int start, int last){
   int ans = 0;
   for(int i =start; i < last; i++){
      ans += a[i];
   }
   return ans;
}

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

   int v_min = INF;
   for(int i = 0; i < n; i++){
      //int s1 = accumulate(w.begin(), w.begin() + i, 0);
      //int s2 = accumulate(w.begin() + i, w.end(), 0);
      int s1 = sum(w, 0, i);
      int s2 = sum(w, i, n);
      int diff = abs(s1 - s2);
      v_min = min(diff, v_min);
   }

   cout << v_min << endl;

   return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[100002] = {0};
    rep(i,n) {
        int m;
        cin >> m;
        a[m]++;
    }
    int ans = 0;
    rep(i,100000) {
        ans = max(a[i] + a[i+1] + a[i+2], ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
// itne me hi thakk gaye?
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")
#define ll long long 
#define ull unsigned long long
using ld = long double;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ll rk = 256;
const ll mod2 = 998244353;
const ld PI = 3.141592653589793;
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define print(a) for(auto j:a) {cout<<j<<",";} cout << "\n";
#define endl '\n'
#define whatis(x) cout << "> "<<#x << " ==> " << x << endl;
#define lwi(x) cout << " your " << #x << " is ---> " << x << " ";
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
// // Printing pair
ostream & operator << (ostream & os, pair <ll, ll> const& x) {
    os << x.first << "," << x.second;
    return os;
}
 
// printing vector
template <class T>
ostream & operator << (ostream & os, vector <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
// printing set
template <class T>
ostream & operator << (ostream & os, set <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}
const int mxn = 1e6+5;
int32_t main(){
    FastIO;
    ll n, m, k;
    cin >> n >> m >> k;
    vc <ll> a(n), b(m);
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<m; i++) cin >> b[i];
    vc <ll> pre1(1, a[0]), pre2(1, b[0]);
    for(int i=1; i<n; i++) pre1.pb(pre1.back() + a[i]);
    for(int i=1; i<m; i++) pre2.pb(pre2.back() + b[i]);
    // cout << a << endl;
    // cout << b << endl;
    // cout << pre1 << endl;
    // cout << pre2 << endl;
    ll ans = 0;
    for(int i=0; i<m; i++) {
        if(pre2[i] <= k) ans = i+1;
    }
    for(int i=0; i<n; i++) {
        if(k-pre1[i] <0) continue;
        ll index = ub(all(pre2), k-pre1[i]) - pre2.begin();
        if(index == m) {
            ans = max(ans, i+1+m);
        } else {
            ans = max(ans, i+1+index);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11080
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef vector< pii > vii;

#define ll          long long
#define ff          first
#define ss          second
#define pb          push_back
#define mkp         make_pair
#define sz          size()

#define forf(a,b,c)    for(int i=a;i<=b;i+=c)
#define forr(a,b,c)    for(int i=a;i>=b;i-=c)
#define all(a)      a.begin(),a.end()
#define mem(a,b)    memset(a,b,sizeof(a))
#define pi          2*acos(0.0)
#define End         return 0;

#define scan1(a)    scanf("%d",&a)
#define scan2(a,b)  scanf("%d %d",&a,&b)
#define scan3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define scanl(a)    scanf("%lld",&a)
#define scanll(a,b) scanf("%lld %lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define print1(a)    printf("%d",a)
#define print2(a,b)  printf("%d %d",a,b)
#define print3(a,b,c)  printf("%d %d %d",a,b,c)
#define printl(a)    printf("%lld",a)
#define printll(a,b) printf("%lld %lld",a,b)
#define printlll(a,b,c) printf("%lld %lld %lld",a,b,c)

#define MAXN        100000007
#define INF 0x3f3f3f3f
//int dx[]={+1,-1,+0,+0};///Four Directions
//int dy[]={+0,+0,+1,-1};///Four directions
//int dx [] = {+1,-1,+0,+0,-1,-1,+1,+1};///Eight Directions
//int dy [] = {+0,+0,+1,-1,+1,-1,-1,+1};///Eight Directions

//int mark[10007];vi prime;void seive(){for(int i=2;i<10000;i++){if(mark[i]==0){prime.pb(i);for(int j=i+i;j<=10000;j+=i)mark[j]=1;}}}

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

int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   ll n, k;
   cin>>n>>k;

   ll ans=0,st=0,en=0;
   for(int i=0,j=n;i<k;i++,j--) st+=i,en+=j;

   ans+=abs(en-st)+1;
   ans%=1000000007;
   for(int i=k,j=n-k;i<=n;i++,j--){
    st+=i; en+=j;
    ans+=(en-st)+1;
    ans%=1000000007;
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int n;
    cin >> n;
    if (n % 2 == 0) {
    	cout << n<< endl;
    } else {
    	cout << 2 * n << endl;
    }

}


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


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

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

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



int main() {
    ll n;
    scanf("%lld", &n);
    vector<ll> a(n);
    REP(i, n){
        scanf("%lld", &a[i]);
    }
    map<ll, ll> m;
    m[0]++;
    m[a[0]]++;
    for(int i = 1; i < n; i++){
        a[i] += a[i - 1];
        m[a[i]]++;
    }
    ll ans = 0;
    for(auto x : m){
        ans += x.second * (x.second - 1) / 2;
    }
    printf("%lld\n", ans);
}


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

using namespace std;
int main()
{
  int n,i,c=0;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)
  {
      cin>>a[i];
  }
  sort(a,a+n);
  for(i=0;i<n;i++)
  {
      if(a[i]==a[i+1])
        c++;
  }
  if(c>=1)
    cout<<"NO"<<endl;
  else
    cout<<"YES"<<endl;

   return 0;
}


Measured memory_bytes: 4424
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;


int dp[1001][(1<<12)+1];

int vectortobit(vector<int> vec)
{
	int res = 0;
	int n = vec.size();
	for(int i = 0;i<n;i++)
	{
		res += (1<<(vec[i]-1));
	}
	return res;
}

int main()
{
	int n,m;
	cin >> n >> m;
	for(int i = 0;i<1001;i++)
	{
		for(int j = 0;j<((1<<12)+1);j++)
		{
			dp[i][j] = INF;
		}
	}

	for(int i = 0;i < m;i++)
	{
		int a,b;
		cin >> a >> b;
		vector<int> vec(b);
		for(int j = 0;j<b;j++)cin >> vec[j];
		int c = vectortobit(vec);
		for(int j = 0;j<(1<<n);j++)
		{
			dp[i+1][j] = dp[i][j];
		}
		for(int j = 0;j<(1<<n);j++)
		{
			if((j&c)==j)dp[i+1][j] = min(dp[i+1][j],a);
		}
		for(int j = 0;j<(1<<n);j++)
		{
			dp[i+1][j|c] = min(dp[i+1][j|c],a+dp[i][j]);
		}
	}
	
	cout<<(dp[m][(1<<n)-1]==INF?-1:dp[m][(1<<n)-1])<<endl;
	return 0;
}


Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007LL;
int main() {
    int N;
    cin >> N;
    vector<int> X(N),S(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> X[i];
        S[i] = X[i];
    }
    sort(S.begin(), S.end());
    int m1 = S[N/2-1], m2 = S[N/2];
    for ( int i = 0; i < N; i++ ) {
        if (X[i] <= m1 ) cout << m2 << '\n';
        else cout << m1 << '\n';
    }
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define AC ios_base::sync_with_stdio(0); cin.tie(NULL);
using namespace std;
const int M = 1e9+7;
const int N = 2*1e5;
#define PI 	3.14159265358979323846


int main(){
    AC
    int a, b, h, m;
    cin>>a>>b>>h>>m;
    int mm = h*60+m;
    double hour_deg = 0.5 * mm;
    double min_deg = 6*m;
    double d = min(abs(hour_deg-min_deg), abs(min_deg-hour_deg));
    double tmp = a*a+b*b;
    double dist = sqrt(tmp-2*a*b*cos(d*PI/180.0));
    cout<<setprecision(17)<<dist<<endl;

}

Measured memory_bytes: 4308
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll a[100000],dp[100000];
ll n;
int frog(ll i){
	if(i==2)
		return abs(a[2]-a[1]);
	else if(i==1)
		return 0;
	if(dp[i]!=-1)
		return dp[i];
	else{
		return dp[i]=min(frog(i-1)+abs(a[i]-a[i-1]),frog(i-2)+abs(a[i]-a[i-2]));
	}
}
int main(){
	ll ans=0;
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>a[i];
		dp[i]=-1;
		}
		
	ans=frog(n);
	cout<<ans<<endl;
	}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int range = 2*d+1;
        System.out.println((n+range-1)/range);
        System.out.flush();
        sc.close();
    }

}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s.size()%2)
	{
		cout<<"No";
		return 0;
	}
	for(int i=0;i<s.size();i+=2)
	{
		if(s[i]=='h'&&s[i+1]=='i')
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

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

void solve(long long N, std::vector<long long> L){
    sort(L.begin(),L.end());
    ll ans =0;
    for(int i=1;i<N;i++){
        for(int j=i+1;j<N;j++){
            auto itr = upper_bound(L.begin(),L.end(),(L[j]-L[i]));
            int pos = itr -L.begin();
            // cerr <<"L[j]=" << L[j] <<"L[i]=" << L[i] <<"*itr=" << pos << endl;
            ans += max((i-pos),0);
        }
    }
    cout << ans << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


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

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    set<int> ans;
    for(int i = 0; i < k && a+i <= b; i++) {
        ans.insert(a+i);
        ans.insert(b-i);
    }
    while(!ans.empty()) {
        int i = *begin(ans);
        ans.erase(i);
        cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 256
s = input()
n = len(s)
rend = []
for i in range(n-1):
  if s[i] == 'R' and s[i+1] == 'L':
    rend.append(i)
l = len(rend)
ans = [0 for _ in range(n)]
here = 0
for i in range(n):
  if i > 0 and s[i-1] == 'L' and s[i] == 'R':
    here += 1
    if here == l:
      here -= 1
  r = rend[here]
  if (r - i) % 2 == 0:
    ans[r] += 1
  else:
    ans[r+1] += 1
#print(rend)
print(' '.join(list(map(str,ans))))

Measured memory_bytes: 12532
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner canner=new Scanner(System.in);
		int num=Integer.parseInt(canner.nextLine().trim());
		for(int i=0;i<num;i++){
			String line=canner.nextLine().trim();
			String[] ls=line.split(" ");
			int MinA=-1;
			int MinB=-1;
			boolean result=true;
			for(String s:ls){
				if(Integer.parseInt(s)>MinA){
					MinA=Integer.parseInt(s);
				}else if(Integer.parseInt(s)>MinB){
					MinB=Integer.parseInt(s);
				}else{
					result=false;
					break;
				}
			}
			
			System.out.printf("%s\n", result? "YES":"NO");
		}
		canner.close();

	}

}

Measured memory_bytes: 25836
/*------------------------------------------------,
|  __                                       __    |
| |  |--.-----.---.-.----.----.-----.-----.|  |_  |
| |  _  |  -__|  _  |  __|  __|  -__|  _  ||   _| |
| |_____|_____|___._|____|____|_____|   __||____| |
|                                   |__|          |
`------------------------------------------------*/
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;
using namespace std;
#define INF 2147483647
#define MOD 10000007
#define REP(count_ver, lower, upper) for (long long count_ver = lower; count_ver < upper; count_ver++)

int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
vector<long long> divisor(long long n) {
  vector<long long> ret;
  for(long long i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  return (ret);
}

void execute(){

  int n,k;
  cin>>n>>k;
  int ans=1;
  REP(i,0,n){
    if(ans*2 > ans+k){
      ans+=k;
    }else if(ans*2 < ans+k){
      ans*=2;
    }else{
      ans+=k;
    }
  }
  cout<<ans<<endl;

}
int main() {

  cin.tie(0);
  ios::sync_with_stdio(0);
  //cout<<fixed<<setprecision(20);

  execute();

  return 0;
}


Measured memory_bytes: 3192
class PrimeNum:
    def __init__(self, N):
        self.N = N
        [self.is_prime, self.primes, self.min_factor] = self.Eratosthenes(N)

    def Eratosthenes(self, n):
        # 素数テーブル
        is_prime = [True] * (n+1)
        is_prime[0] = False
        is_prime[1] = False

        # nを割り切る最小の素数を記録
        min_factor = [0] * (n+1)
        min_factor[1] = 1
        
        primes = []

        for i in range(2,n+1):
            if not is_prime[i]:
                continue

            primes.append(i)
            min_factor[i] = i
            for cur in range(i*2, n+1, i):
                is_prime[cur] = False
                if min_factor[cur] == 0:
                    min_factor[cur] = i
                cur += i

        return [is_prime, primes, min_factor]
    
    def PrimeFactorization(self, K):
        # Kの素因数分解を返す
        number = []
        exponent = []
        while K>1:
            ex = 0
            p = self.min_factor[K]
            while K%p==0:
                K //= p
                ex += 1
            number.append(p)
            exponent.append(ex)
        return [number, exponent]


N = int(input())
A = list(map(int,input().split()))
MOD = 10**9+7
# 素因数分解の形でLCMを求める

Prime = PrimeNum(max(A))
lcm_e = [0]*(max(A)+1)
for i in range(N):
    nums,exs = Prime.PrimeFactorization(A[i])
    for n,e in zip(nums,exs):
        lcm_e[n] = max(lcm_e[n], e)

LCM = 1
for i in range(len(lcm_e)):
    if lcm_e[i] != 0:   
        LCM *= pow(i, lcm_e[i], MOD)
        LCM %= MOD
ans = 0
for a in A:
    ans += LCM * pow(a, MOD-2, MOD)
    ans %= MOD
print(ans)
    

Measured memory_bytes: 70820
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    
    static final String PROBREM="ITP1 1 A";
    
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String inputLine = reader.readLine();
        
        Integer input = Integer.parseInt(inputLine);
        Integer cubic = input*input*input;
        
        System.out.println(cubic);
    }
    
}



Measured memory_bytes: 24160
def miller_rabin(n, k=100):
    import random
    if n == 2:
        return True
    if n == 1 or n & 1 == 0:
        return False
    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1
    for _ in range(k):
        a = random.randint(1, n - 1)
        t = d
        y = pow(a, t, n)
        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1
        if y != n - 1 and t & 1 == 0:
            return False
    return True
def main():
  x=int(input())
  for i in range(x,1000000):
    if miller_rabin(i):
      print(i)
      return
main()

Measured memory_bytes: 39152
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<string>;
using P =pair<int,int>;

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

int main(){
    int n;
    cin>>n;
    int cnt=0;
#if 0 
    for(int c=1;c<n;++c){
        for(int a=1;a*a<=n-c;++a){
            if((n-c)%a==0){
                if((n-c)/a==a)++cnt;
                else cnt+=2;
            }
        }
    }
#endif 
    for(int c=1;c<n;++c){
        cnt+=(n-1)/c;
        
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3516
import numpy as np
n,m=map(int,input().split())
if m==0:
    print(0)
    exit()
ans=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    ans[a-1].append((b-1))
    ans[b-1].append((a-1))
v=[]
def dfs(now,visited=[]):
    global v
    if len(visited)==n:
        v.append([visited])
        return
    for j in ans[now]:
        if j not in visited:
            dfs(j,visited+[j])
dfs(0,[0])
print(len(v))


Measured memory_bytes: 14424
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<math.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define mod 10007
using  namespace std;
int maxn (int a,int b,int c){return max(max(a,b),max(b,c));}
int main()
{

    int dp[100005],n,m;
    scanf("%d%d",&n,&m);
    int max1=0,min1=inf;
    int sum,x;
    mem(dp,0);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&x);
        dp[i]=max(0,x-min1);
        min1=min(min1,x);
       // max1=max(max1,x);
       max1=max(max1,dp[i]);
    }
    sum=0;
    for(int i=0;i<n;i++)
    {
        if(dp[i]==max1)
            sum++;
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    string s;
    cin >> s;

    int q;
    cin >> q;

    vector<int> c(n + 1);
    for (int i = 0; i < n; i++) {
        c[i + 1] = c[i] + (s[i] == 'C');
    }

    vector<int> m(n + 1);
    for (int i = 0; i < n; i++) {
        m[i + 1] = m[i] + (s[i] == 'M');
    }
    vector<ll> m2(n + 1);
    for (int i = 0; i < n; i++) {
        m2[i + 1] = m2[i] + (s[i] == 'M' ? c[n] - c[i + 1] : 0);
    }

    for (int h = 0; h < q; h++) {
        int k;
        cin >> k;

        ll r = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == 'D') {
                ll m1 = m[min(i + k, n)] - m[i];
                ll m3 = m2[min(i + k, n)] - m2[i];
                m3 -= m1 * (c[n] - c[min(i + k, n)]);
                r += m3;
            }
        }

        cout << r << endl;
    }

    return 0;
}

Measured memory_bytes: 17052
#include<stdio.h>

int main(){

  int i,j,k,minj,a,A[100],count = 0;

  scanf("%d",&a);

  for(i = 0; i < a; i++){
    scanf("%d",&A[i]);
  }

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

    minj = i;

    for(j = i; j < a; j++){
      if(A[j] < A[minj]) {
	minj = j;
      }
    }
    if(minj != i) count++;
    k = A[i];
    A[i] = A[minj];
    A[minj] = k;
  }

  for(i = 0; i < a; i++){
    printf("%d",A[i]);
    if(i == a -1) break;
    printf(" ");
  }

  printf("\n");

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

  return 0;
}

Measured memory_bytes: 604
n, m = map(int, input().split())
# 向かう先
outs = [[] for _ in range(n + 1)]
# 向かわれる数
ins = [0] * (n + 1)
for _ in range(m):
    x, y = map(int, input().split())
    outs[x].append(y)
    ins[y] += 1
queue = [i for i in range(1, n + 1) if ins[i] == 0]

l = []

while queue:
    s = queue.pop()
    l.append(s)
    for r in outs[s]:
        ins[r] -= 1
        if ins[r] == 0:
            queue.append(r)


dp = [0] * (n + 1)
for v in l:
    d = dp[v] + 1
    for k in outs[v]:
        dp[k] = max(dp[k], d)
print(max(dp))


Measured memory_bytes: 63776
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    int num=(n+1)/2;
    double test=num;
    test/=n;
    cout<<setprecision(10)<<test<<endl;
    
    return 0;   
}


 
 


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,Q;
string S;

int sum[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q;
	cin>>S;
	FOR(i,N) {
		sum[i+1]=sum[i];
		if(i&&S[i]=='C' && S[i-1]=='A') sum[i+1]++;
	}
	FOR(i,Q) {
		int L,R;
		cin>>L>>R;
		L--,R--;
		int ret=sum[R+1]-sum[L];
		if(L&&S[L]=='C' && S[L-1]=='A') ret--;
		cout<<ret<<endl;
		
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1488
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, M, = map(int, input().split())
# L = [int(v) for v in input().split()]
L = [int(input()) for _ in range(N)]
# S = input().strip()

M -= sum(L)

print(len(L) + int(M // min(L)))

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while (stdIn.hasNext()) {
			int n = stdIn.nextInt();
			int h[] = new int[n + 1];
			int cou = 0;
			for (int i = 1; i < h.length; i++) 
				h[i] = 1;
			for (int a = 2; a < h.length; a++) {
				if (h[a] == 1) {
					for (int b = 1; b * a < h.length; b++)
						h[b * a] = 0;
					cou++;
				}
			}
			System.out.println(cou);
		}
	}
}

Measured memory_bytes: 54240
import java.io.*
import java.util.*

fun solve(N: Int, M: Int, K: Int, A: IntArray, B: IntArray, C: IntArray, D: IntArray) {
    val friend_uf = UnionFind(N + 1)
    val blocks = Array(N) { mutableSetOf<Int>() }
    val friends = Array(N) { mutableSetOf<Int>() }
    repeat(M) {
        friend_uf.unite(A[it] - 1, B[it] - 1)
        friends[A[it] - 1].add(B[it] - 1)
        friends[B[it] - 1].add(A[it] - 1)
    }
    repeat(K) {
        blocks[C[it] - 1].add(D[it] - 1)
        blocks[D[it] - 1].add(C[it] - 1)
    }
    (0 until N).map {
        friend_uf.getSize(it) - 1 - friends[it].count { fr -> friend_uf.isSame(fr, it) } - blocks[it].count { bl -> friend_uf.isSame(bl, it) }
    }.joinToString(separator = " ").let {
        println(it)
    }

    return
}

class UnionFind(n: Int) {
    data class Node(var parent: Int, var size: Int)
    val nodes = Array<Node>(n) { Node(parent = it, size = 1) }
    fun findRoot(x: Int): Int {
        if (x == this.nodes[x].parent) return x
        nodes[x].parent = findRoot(nodes[x].parent)
        return nodes[x].parent
    }
    fun unite(x: Int, y: Int) {
        var xRoot = findRoot(x)
        var yRoot = findRoot(y)
        if (xRoot == yRoot) return
        if (getSize(xRoot) < getSize(yRoot)) {
            nodes[xRoot].parent = yRoot
            nodes[yRoot].size += nodes[xRoot].size
        } else {
            nodes[yRoot].parent = xRoot
            nodes[xRoot].size += nodes[yRoot].size
        }
    }
    fun getSize(x: Int) = nodes[findRoot(x)].size
    fun isSame(x: Int, y: Int) = findRoot(x) == findRoot(y)
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val M = sc.next().toInt()
    val K = sc.next().toInt()
    val A = IntArray(M.toInt())
    val B = IntArray(M.toInt())
    for (i in 0 until M.toInt()) {
        A[i] = sc.next().toInt()
        B[i] = sc.next().toInt()
    }
    val C = IntArray(K.toInt())
    val D = IntArray(K.toInt())
    for (i in 0 until K.toInt()) {
        C[i] = sc.next().toInt()
        D[i] = sc.next().toInt()
    }
    solve(N, M, K, A, B, C, D)
}


Measured memory_bytes: 158204
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
ll add(ll x,ll y)
{
return (x%hell+y%hell)%hell;
}
ll mul(ll x,ll y)
{
return ((x%hell)*(y%hell))%hell;
}
ll sub(ll x,ll y)
{
return (x-y+hell)%hell;
}
#define N  100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
  // cin>>t;
    for(int ok=1;ok<=t;ok++)
    {
        ll n;
        cin>>n;
        string s;
        cin>>s;
        ll ans=0;
        for(int i=0;i<n;i++)
          if(s[i]=='R')
            ans++;
        ll cnt=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='R')
              ans--;
            else
            {
                if(ans>0)
                  ans--,cnt++;
                else
                  continue;
            }
        }
        cout<<cnt;
     
    }
    return 0;
}

Measured memory_bytes: 3712
#include <iostream>

using namespace std;

int GCD(int a, int b) {
  while (a) {
    int tmp = a;
    a = b % a;
    b = tmp;
  }
  return b;
}


int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int gcd = GCD(a, b);
  int cnt = 0;
  for (int i = 1; i <= gcd; ++i) {
    if (gcd % i) continue;
    cnt++;
    if (cnt == k) {
      cout << gcd / i << endl;
      return 0;
    }
  }
}


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

using namespace std;

int main(){

int n,tmp;
//vector <int> a;
double ans=0;
cin>>n;
for(int i=0;i<n;i++){
    cin>>tmp;
    ans += 1.0/tmp;
   // a.push_back(tmp);
}
cout<<setprecision(15)<<1.0/ans;
}


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

int main() {
  int N;
  cin>>N;
  //N-termék ára, B-átadott bankjegyyek száma, C-visszajáró összeg
  if (N % 1000 == 0) {
    cout << 0;
  } else {
    cout << 1000 - (N%1000);
  }
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main()
{
    int n, x, t;
    cin >> n >> x >> t;
    int cnt = n / x;
    if (n % x == 0)
        cout << cnt * t << endl;
    else
        cout << (cnt + 1) * t << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<numeric>
#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
int main(){
	int n;
	string s;
	cin>>n>>s;
	ll ans=0;
	//暴力时间过不去，所以最大只能采用n^2的算法
	// for(int i=0;i<n-2;i++){
	// 	for(int j=i+1;j<n-1;j++){
	// 		if(s[i]==s[j])continue;
	// 		for(int k=j+1;k<n;k++){
	// 			if(s[j]!=s[k]&&s[i]!=s[k]&&j-i!=k-j){
	// 				ans++;
	// 			}
	// 		}
	// 	}
	// }
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			int k=j-i+j;//表示i,j,k三者之间间隔相同
			if(k>n-1)continue;
			if(s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k])ans++;
		}
	}
	ll r=0,g=0,b=0;//全部定义成long long 吧，不要再有什么骚操作了。。。
	for(int i=0;i<n;i++){
		if(s[i]=='R')r++;
		else if(s[i]=='G')g++;
		else b++;
	}
	ll res=r*b*g;
	cout<<res-ans<<endl;
	return 0;
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define F first
#define S second

using ll = long long;
using P = pair<ll,ll>;
using PP = pair<P, P>;

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

  vector<int> arr(n+1, 0);
  rep(i, n) {
    cin >> arr[i];
  }

  ll res = 1000;
  queue<PP> que;
  que.push(PP(P(1000, 0), P(0, 0)));

  vector<ll> memo(n+1, -1);

  vector<bool> tab(n, false);
  rep(i, n) {
    bool f = false;
    for(int j = i+1; j < n; j++) {
      if (arr[i] < arr[j]) {
        f = true;
        break;
      }
    }
    tab[i] = f;
  }

  while(!que.empty()) {
    PP t = que.front();
    que.pop();

    ll m = t.F.F;
    ll s = t.F.S;
    ll d = t.S.F;
    ll b = t.S.S;

    if (memo[d] > m + s * arr[d]) continue;
    memo[d] = m + s * arr[d];

    if (m > res) {
      res = m;
    }
    if (d + 1 > n) {
      continue;
    }

    que.push(PP(P(m, s), P(d+1, b)));
    if(m >= arr[d] && tab[d]) {
      ll k = m / arr[d];
      que.push(PP(P(m - arr[d] * k, s + k), P(d+1, arr[d])));
    }
    if(s > 0 && arr[d] > arr[d+1] && arr[d] > b) {
      que.push(PP(P(m + arr[d] * s, 0), P(d+1, 0)));
    }
  }

  cout << res << endl;


  return 0;
}


Measured memory_bytes: 6124
import math
N,M=map(int,input().split())
if abs(N-M)>1:
  print(0)
elif abs(N-M)==1:
  n=math.factorial(N)%(10**9+7)
  m=math.factorial(M)%(10**9+7)
  print((n*m)%(10**9+7))
else:
  n=math.factorial(N)%(10**9+7)
  m=math.factorial(M)%(10**9+7)
  print((2*n*m)%(10**9+7))

Measured memory_bytes: 4096
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s1,s2;
  cin>>s1>>s2;
  if(s1[0]==s2[2]&&s1[1]==s2[1]&&s1[2]==s2[0])cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


void solve(int N) {
    int S = N * (N+1) / 2;
    vvi groups;
    if (N % 2) {
        groups.pb(vi{N});
        for (int i=1,j=N-1; i<j; ++i,--j) {
            groups.pb(vi{i,j});
        }
    } else {
        for (int i=1,j=N; i<j; ++i,--j) {
            groups.pb(vi{i,j});
        }
    }

    vii res;

    int G = groups.size();
    rep(g,G) {
        for (int gi: groups[g]) {
            rep(h,G) {
                if (h == g) continue;
                for (int hi: groups[h]) {
                    if (gi < hi)
                        res.emplace_back(gi, hi);
                }
            }
        }
    }

    printf("%d\n", (int)res.size());
    for (ii& p: res) {
        printf("%d %d\n", p.first, p.second);
    }
}

int main() {
    int N; cin >> N;
    solve(N);
    return 0;
}


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

int main(void){
    string S;
    cin>>S;
    int ans=0;

    for (int i=1;i<S.size();i++){
        if (S[i]!=S[i-1]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((a+b) == (c+d))
    {
        cout<<"Balanced"<<endl;
    }
    else if((a+b) > (c+d))
    {
        cout<<"Left"<<endl;
    }
    else
    {
        cout<<"Right"<<endl;
    }
    
    
    return 0;
}

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

const ll INF = 1LL << 60;
const int MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, b, e) for (int i = (b); i <= (e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

char A = '0', B = '1';
int main() {
    string S;
    cin >> S;

    stack<char> st;

    REP(i, S.size()) {
        if (st.empty()) {
            st.push(S[i]);
            continue;
        }
        if (st.top() != S[i]) {
            st.pop();
        } else {
            st.push(S[i]);
        }
    }

    int ans = S.size() - st.size();
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int a, b, c, d, e, f;

int max_li=0,max_su=0;
bool dp_su[300001];
bool dp_li[31];
int main(){
  scanf("%d %d %d %d %d %d", &a,&b,&c,&d,&e,&f);
  dp_su[c]=true;
  dp_su[d]=true;
  for(int i=1;i<=300000;i++){
    if(dp_su[i]){
      if(i+c<=300000)
        dp_su[i+c]=true;
      if(i+d<=300000)
        dp_su[i+d]=true;
    }
  }
  dp_li[a]=true;
  dp_li[b]=true;
  for(int i=a;i<=30;i++){
    if(dp_li[i]){
      if(i+a<=30)
        dp_li[i+a]=true;
      if(i+b<=30)
        dp_li[i+b]=true;
    }
  }
  max_li=a*100;
  for(int i=a;i<=30;i++){
    if(dp_li[i]){
      for(int j=i*e;j>0;j--){
        if(dp_su[j]&&100*i+j<=f){
          if(max_su*(i*100+j)<j*max_li){
            max_su = j;
            max_li = i*100+j;
          }
          break;
        }
      }
    }
  }
  printf("%d %d\n", max_li, max_su);
}


Measured memory_bytes: 512
N, K = map(int, input().split())

if K == 0:
    print(N * N)
else:
    cnt = 0
    for b in range(1, N+1):
        l_max = N // b
        for l in range(l_max + 1):
            k = min(b-1, N - b*l)
            if k >= K:
                cnt += k - K + 1

    print(cnt)

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

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

    ll w, x, y, z;
    w = a * c;
    x = a * d;
    y = b * c;
    z = b * d;

    ll ans;
    ans = max(w, max(x, max(y, z)));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
import java.util.*;

public class Main {

    public static long grade = 0;

    public static long a;
    public static long b;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.valueOf(sc.nextLine());
        String[] P = sc.nextLine().split(" ");
        String[] Q = sc.nextLine().split(" ");
        sc.close();
        StringBuilder sb = new StringBuilder();

        grade = 1;

        for (String val : P) {
            sb.append(val);
        }
        long p = Long.valueOf(sb.toString());
        sb.setLength(0);
        for (String val : Q) {
            sb.append(val);
        }
        long q = Long.valueOf(sb.toString());

        String[] numArray = new String[N];
        boolean[] flags = new boolean[N];
        for (int i = 1; i <= N; i++) {
            numArray[i - 1] = String.valueOf(i);
            flags[i - 1] = false;
        }

        recurse(numArray, flags, p, q, "", N);

        System.out.println(Math.abs(a - b));

    }

    public static void recurse(String[] numArray, boolean[] flags, long p, long q, String esa, int N) {
        if (esa.length() == N) {
            grade++;
            long value = Long.valueOf(esa);
            if (value == p) {
                a = grade;
            }
            if (value == q) {
                b = grade;
            }
            return;
        }
        for (int i = 0; i < numArray.length; i++) {
            if (flags[i]) {
                continue;
            }
            String newEsa = esa + numArray[i];
            flags[i] = true;
            recurse(numArray, flags, p, q, newEsa, N);
            flags[i] = false;
        }

    }

}

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

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

  int score = 0;
  rep(i, n - 1) {
    if (s[i] == s[i + 1]) score++;
  }
  int ans = min(score + 2 * k, n - 1);

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

Measured memory_bytes: 3772
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N = int(input())
    ans = N * (N+1) // 2
    print(ans)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3060