akhauriyash/Code-Regression huggingface dataset:
n = int(input())
h = list(map(int, input().split()))

def dfs(a):
  if not a:
    return 0
  cnt = 0
  while True:
    if 0 in a:
      z = [i for i,x in enumerate(a) if x==0]
      cnt += dfs(a[:z[0]])
      for i in range(1,len(z)):
        cnt += dfs(a[z[i-1]+1:z[i]])
      cnt += dfs(a[z[-1]+1:])
      return cnt
    else:
      a = [x-1 for x in a]
      cnt += 1

print(dfs(h))

Measured memory_bytes: 9168
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main(){
    string T;
    cin>>N>>S>>T;
    rep(i,N) cout<<S[i]<<T[i];
    cout<<endl;
}

Measured memory_bytes: 256
///http://www.cnblogs.com/henry-1202/p/9537952.html
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

const int maxn=1e5+10;
int a[maxn];
int n;
int c[maxn*15];
int pre[maxn*15];
int lowbit(int x)
{
    return x&-x;
}
void add(int x)
{
    for(int i=x;i<=2*maxn;i+=lowbit(i))c[i]++;
}
LL query(int x)
{
    LL res=0;
    for(int i=x;i>0;i-=lowbit(i))res+=c[i];
    return res;
}

bool check(int x)
{
    memset(c,0,sizeof(c));
    pre[0]=0;
    for(int i=1;i<=n;i++)pre[i]=pre[i-1]+(a[i]>=x?1:-1);
    LL res=0;
    for(int i=0;i<=n;i++){
        res+=query(pre[i]+maxn);
        add(pre[i]+maxn);
    }
    return res>=1LL*n*(n+1)/4;
}

int main()
{
    n=read();
    int L=0,R=0,ans=0;
    for(int i=1;i<=n;i++){
        a[i]=read();
        R=max(R,a[i]);
    }
    while(L<=R){
        int mid=(L+R)>>1;
        if(check(mid)){
            L=mid+1;ans=mid;
        }
        else{
            R=mid-1;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 8704
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
lat = 0
abstem = 1000
for i in range(n):
    avetem = t - h[i] * 0.006
    if abs(a - avetem) <= abstem:
        abstem = abs(a - avetem)
        lat = h[i]
print(h.index(lat) + 1)

Measured memory_bytes: 3060
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, W, H;
int X[100010], Y[100010];

signed main() {
    cin >> N >> W >> H;
    rep(i,0,N) {
        int x, y, w; cin >> x >> y >> w;
        X[max(0LL, x-w)]++;
        X[min(W, x+w)]--;
        Y[max(0LL, y-w)]++;
        Y[min(H, y+w)]--;
    }

    bool bw = X[0], bh = Y[0];
    rep(i,1,W) X[i] += X[i-1], bw &= X[i] != 0;
    rep(i,1,H) Y[i] += Y[i-1], bh &= Y[i] != 0;
    cout << (bw || bh ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 4664
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repm(i, a, n) for (int i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vs vector<string>
#define vii vector<vector<int>>
#define vll vector<ll>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Print(bool c)
{
    if (c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

int kaijo(int x)
{
    int ans = 1;
    rep(i, 1, x + 1) ans *= i;
    return ans;
}

string n_shin(int x, int n)
{
    string s;
    while (x > 0)
    {
        s += to_string(x % n + 1);
        x /= n;
    }
    while (s.size() < n)
    {
        s += '0';
    }
    s.reserve();
    //cout << s << endl;
    return s;
}

int main()
{
    int n;
    cin >> n;
    vi x(n);
    rep(i, 0, n) cin >> x[i];
    int ans = INF;
    rep(j, 0, 100)
    {
        int sum = 0;
        rep(i, 0, n)
            sum += pow(x[i] - j, 2);
        ans = min(ans, sum);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<complex>
#include<cmath>

using namespace std;

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

const int N = 111;

vector<int> edge[N];
int visit[N];

int saiki(int p){
	if(visit[p]==1)return 0;
	visit[p]=1;
	
	int ret = 0;
	rep(i,edge[p].size()){
		ret = max(saiki(edge[p][i])+1, ret);
	}
	
	visit[p]=0;
	return ret;
}

int main(){
	A:;
	
	int n;
	cin>>n;
	if(n==0)return 0;
	
	rep(i,N)edge[i].clear();
	
	rep(i,n){
		int a,b;
		cin>>a>>b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	
	rep(i,N)visit[i]=0;
	int ans = 0;
	rep(i,N){
		ans = max(saiki(i),ans);
	}
	
	printf("%d\n",ans);
	
	goto A;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>i) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL((a))), (a).end());} while(0)
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;

VPII res;

void prime_factorize(auto N, auto &result)
{
  int s = 2;
  while (N != 1)
  {
    int e = 0;
    while (N % s == 0)
    {
      N /= s;
      e++;
    }
    if (e != 0) result.push_back(PII(s, e));
    s++;
  }
}

void pff(auto N)
{
  REP2(i, 1, N+1)
  {
    VPII result;
    prime_factorize(i, result);
    REP(i, result.size())
    {
      bool flg = false;
      REP(j, res.size())
      {
        if (result.at(i).first == res.at(j).first)
        {
          res.at(j).second += result.at(i).second;
          flg = true;
          break;
        }
      }
      if (!flg) res.push_back(result.at(i));
    }
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  pff(N);
  int k = 0, l = 0, m = 0, n = 0, o = 0, p = 0, q = 0;
  REPx(x, res)
  {
    int b = x.second;
    if (2 <= b && b < 4) k++;
    if (b >= 4) l++;
    if (2 <= b && b < 24) m++;
    if (b >= 24) n++;
    if (4 <= b && b < 14) o++;
    if (b >= 14) p++;
    if (b >= 74) q++;
  }
  int ans = 0;
  if (l == 2) ans += k * l * (l-1) / 2;
  else if (l >= 3) ans += k * l * (l-1) / 2 + l * (l-1) * (l-2) / 2;
  ans += m * n + n * (n-1);
  ans += o * p + p * (p-1);
  ans += q;
  cout << ans << endl;

  return 0;
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

vector<vector<int>> g(200001);
vector<int> c(200001);

void solve(int i, int p) {
    c[i] += c[p];
    for (auto e: g[i]) {
        if (e == p) continue;
        else solve(e, i);
    }
}

int main() {
    int n, q; cin >> n >> q;
    REP(i, n - 1) {
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    REP(i, q) {
        int p, x; cin >> p >> x;
        c[p] += x;
    }
    solve(1, 0);
    FOR(i, 1, n + 1) {
        cout << c[i] << " ";
    }
}


Measured memory_bytes: 23552
import sys
sys.setrecursionlimit(200000)
s = input()
t = input()
dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]

def backtrack(dp, s, t, i, j):
    if i == 0 or j == 0:
        return ''
    if s[i-1] == t[j-1]:
        return backtrack(dp, s, t, i-1, j-1) + s[i-1]
    if dp[i][j-1] > dp[i-1][j]:
        return backtrack(dp, s, t, i, j-1)
    return backtrack(dp, s, t, i-1, j)

for i in range(1, len(s)+1):
    for j in range(1, len(t)+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1)
        else:
            dp[i][j] = max(dp[i][j-1], dp[i-1][j])
print(backtrack(dp, s, t, len(s), len(t)))

Measured memory_bytes: 116956
def gcd(x, y):
    m = max(x, y)
    n = min(x, y)
    z = y
    while m % n == 0:
        z = x % y
        x = y
        y = z
    return z

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

x, y = map(int, input().split())

z = prime_factorize(x)
w = prime_factorize(y)

zz = set(z) & set(w)
print(len(zz)+1)

Measured memory_bytes: 3188
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
g = []
lim_max = ((N - 1) * (N - 2)) // 2
if (K > lim_max):
  print(-1)
  exit()

for i in range(2, N + 1):
  g.append((1, i))

count = lim_max - K

for i in range(2, N + 1):
  for j in range(3, N + 1):
    if (count == 0):
      break
    if (i != j and i < j):
      g.append((i, j))
      count -= 1


print(len(g))
for t in g:
  print(t[0], t[1])

Measured memory_bytes: 43248
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll euclidean_gcd(ll a, ll b) {
  if(a < b) euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a[1000];
    int Min=99999;
    int Max=-99999;
    REP(i,n){
      cin >> a[i];
      Min = min(Min,a[i]);
      Max = max(Max,a[i]);
    }
    ll ans = INF;
    FOR(i,Min,Max+1){
      ll  sum = 0;
      REP(j,n)sum += pow(a[j]-i,2);
      ans = min(ans,sum);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,i,j;
	cin>>n;
	long long int a[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=0;i<n;i++)
	{
		j=j+a[i];
	}
	if(j%2==0)
	cout<<"YES"<<endl;
	if(j%2!=0)
	cout<<"NO"<<endl;
	return 0;
}

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

using namespace std;

int main(){
    int ans=0;
    int n,q;
    vector<int> s;
    vector<int> t;
    cin>>n;
    for (int i=0; i<n; i++) {
        int input;
        cin>>input;
        s.push_back(input);
    }
    cin>>q;
    for (int i=0; i<q; i++) {
        int input;
        cin>>input;
        t.push_back(input);
    }
        
    //??蔵?卒蔵?????????:t[i]
   for (int i=0; i<q; i++) {
       int low = 0; //???????????????
       int high = n; //???????????????
       int mid;
       while (low <= high) {
           mid = (low + high) / 2;
           if (s[mid] == t[i]) {
               ans++;
               break;
           }
           else if(s[mid] < t[i]){
               low = mid + 1;
           }
           else{
               high = mid - 1;
           }
       }
    }
    cout<<ans<<endl;
}

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

using namespace std;

#define pii pair<int,int>
#define pb push_back
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define MOD 1000000007

ll factorial(ll n) { if(n == 0 || n == 1) return 1; ll res = 1;for(ll i=2;i<=n;i++) res = (res*n)%MOD;return res;}
ll mpow(ll a, ll n) { ll ret=1; ll b=a; while(n) { if(n&1) {ret=(ret*b)%MOD;} b=(b*b)%MOD; n>>=1; } return (ll)ret; }
int toint(const string &s) { stringstream ss(s); int x; ss >> x; return x; }
ll xGCD(ll a, ll b, ll &x, ll &y) { if (b == 0) {x = 1;y = 0;return a;} ll x1, y1, gcd = xGCD(b, a % b, x1, y1); x = y1; y = x1 - (a / b) * y1; return gcd; }
ll inverse(ll a) {ll x, y;ll gcd = xGCD(a, MOD, x, y);return (x%MOD+MOD)%MOD;}
ll bc(ll n, ll k) { if(n == k || k == 0) return 1; if(k == 1 || k == n-1) return n;ll a = factorial(n);ll b = inverse(factorial(k));ll c = inverse(factorial(n - k));return ((a%MOD*b%MOD)*c%MOD)%MOD;}
void fastscan(ll &x) { bool neg=false; register int c; x =0;c=getchar();if(c=='-') {neg = true;c=getchar();}for(;(c>47 && c<58);c=getchar())x = (x<<1) + (x<<3) +c -48;if(neg) x *=-1;}


int main() {
//     fstream fin,fout;
//     fin.open("sample.txt");
//     fout.open("res.txt");
    ll n;
    cin>>n;
    
    string str = "";
    
    char ch[26];
    ch[0] = 'z';
    for(int i=1;i<26;i++)
        ch[i] = 'a'+i-1;
    
    while(n) {
        int tmp = n%26;
        //cout<<n<<" "<<tmp<<" ";
        //cout<<ch[tmp]<<endl;
        str = ch[tmp]+str;
        n = (n-tmp)/26;
        if(!tmp) n--;
        
    }
    
    cout<<str;
//     cout << duration.count() << endl;
//     fin.close();
//     fout.close();
    return 0;
}



Measured memory_bytes: 3616
import java.util.Scanner;

/**
 *
 * @author ena000078
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int s[] = new int[N];
        int max = 0;
        for(int i=0;i<N;i++){
            s[i] = sc.nextInt();
            max+=s[i];
        }
        if (max%10!=0){
            System.out.println(max);
        }else{
            int ss[] = sort(s);
            for(int i=0;i<ss.length;i++){
                if((max-ss[i]) % 10 != 0){
                    System.out.println(max-ss[i]);
                    return;
                }
            }
            System.out.println(0);
        }
    }
    static int[] sort(int s[]){
        int ans[] = s;
        
        for (int i=0;i<ans.length;i++){
            int min = ans[i];
            for (int k=i+1;k<ans.length;k++){
                if (min > ans[k]){
                    ans[i] = ans[k];
                    ans[k] = min;
                    min = ans[i];
                }
            }
        }
        
        return ans;
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<vector>
#include<utility>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<limits>
#include <bitset>      
#include<cstring>


#define LL long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define INF numeric_limits<int>::max()



using namespace std;


int dp[3030][3030];


int main(){

    string s, t;
    cin >> s >> t;

    int n, m;
    n = s.length();
    m = t.length();


    memset(dp, 0, sizeof dp);


    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(s[i-1] == t[j-1]) dp[i][j] = 1 + dp[i-1][j-1];
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
          }
       }
    
    
    string ans;
    int i = n, j = m;

    while(i > 0 && j > 0){
           if(s[i-1] == t[j-1]){
                ans.pb(s[i-1]);
                i--;j--;
             }
           else if(dp[i][j-1] > dp[i-1][j]){
                 j--;
               }
          else{
                 i--;
               }          
           }


       for(int k = ans.size()-1; k >= 0; k--){
            cout << ans[k];
         }



    
    return 0;
}






Measured memory_bytes: 36096
#include<bits/stdc++.h>
#define ll long long
using namespace std;const int N=200005;int a[N],n,num;ll ans=0;
int main(){scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%d",a+i),a[i]-=i;sort(a+1,a+n+1),num=a[(n+1)>>1];for(int i=1;i<=n;i++) ans+=(ll)abs(num-a[i]);cout<<ans<<endl;return 0;}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long[] x = new long[n];
		for(int i=0;i<n;i++) x[i] = sc.nextLong();
		long ans = 0;
		for(int i=0;i<n-1;i++) {
			long cost = Math.min((x[i+1] - x[i]) * a, b);
			ans += cost;
		}
		System.out.println(ans);
	}

}


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

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int res = 0;
    rep(i,n){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
constexpr const int INF=1<<30,MOD=1000000007;constexpr const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,v.size())
#define all(v)(v).begin(),(v).end()
#define bit(n)(1ll<<(n))
#define uniq(v)sort(all(v));v.erase(unique(all(v)),v.end())
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
#ifndef LOCAL
struct osd{template<class T>osd&operator<(const T&t){return*this;}template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;template<class...T>void _print(osd&a,T&&...t){}
#define cerr cer_
#endif
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}template<class T>istream&operator>(istream&i,T&t){return i>>t;}
void _print(ostream&s){}template<class T,class...U>void _print(ostream&s,T&&t,U&&...u){s<t<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(T&&...t){_print(cout,t...);}template<class...T>void dprint(T&&...t){_print(cerr,t...);}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<i<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<p.F<' '<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>p.F>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<i<' ';return o;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>queue<T>&operator<<(queue<T>&q,const T&t){q.push(t);return q;}template<class T>queue<T>&operator<<(T&t,queue<T>&q){t=q.front();q.pop();return q;}
template<class T>deque<T>&operator>>(const T&t,deque<T>&q){q.push_front(t);return q;}template<class T>deque<T>&operator<<(T&t,deque<T>&q){t=q.front();q.pop_front();return q;}
template<class T>deque<T>&operator<<(deque<T>&q,const T&t){q.push_back(t);return q;}template<class T>deque<T>&operator>>(deque<T>&q,T&t){t=q.back(t);q.pop_back();return q;}
template<class T>stack<T>&operator<<(stack<T>&s,const T&t){s.push(t);return s;}template<class T>stack<T>&operator>>(stack<T>&s,T&t){t=s.top();s.pop();return s;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n,k;
    cin>n>k;
    cout<((k!=1) * (n-k))<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vl = vector<ll>;
using vvl = vector<vl >;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

#define TR ","
#define TS " "
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define repe(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

int main()
{
    IO;

    ll N, ans=0; cin >> N;
    repe(i, 1, N + 1) {
        ll jj = N / i;
        ans += jj * (jj + 1) / 2 * i;
    }
    cout << ans << endl;

}

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#include<cstring>
#include <stack>
#include <numeric>
#include<climits>
#include<cmath>
#include<set>
#include<unordered_set>
#include<iomanip>
#include<queue>
#include<unordered_map>
#define vi vector<float>
#define vl vector<long long>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define loop(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define mp make_pair
#define ll long long
const int mod = 1e9 + 7;
using namespace std;

#define xx first
#define yy second


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



	ll n, k;
	cin >> n >> k;

	ll div = n / k;
	ll rem = n - (k * div);
	if (rem == 0) {
		cout << rem << endl;
	} else {
		cout << min(rem, abs(rem - k)) << endl;
	}


	return 0;
}










Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N = int(readline())
X,Y = [None] * N, [None] * N
for i in range(N):
  x,y = map(int,readline().split())
  X[i],Y[i] = x + y,x - y

print(max(abs(max(X) - min(X)),abs(max(Y) - min(Y))))


Measured memory_bytes: 24540
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define at(x,i) get<i>(x);
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
  ll x,y,z;cin >> x >>y >>z;
  cout << z <<" " << x <<" " << y <<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N, long long M) {
  ll ret = min(N, M / 2);
  M -= ret * 2;
  ret += M / 4;

  cout << ret << endl;
}

int main() {
  ios::sync_with_stdio(false);
  string a;
  string b;

  cin >> a;
  cin >> b;

  int num;
  num = (int)a.size();

  a = a + b;
  string answer;

  for(int i = 0; i < num; i++){
    cout << a[i];
    if(i+num<a.size())
      cout << a[i+num];
  }

  cout << endl;

  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){cin >> a[i];}
    int max = *max_element(a.begin(), a.end());
    int min = *min_element(a.begin(), a.end());
    cout << max - min;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int a,b,c;
    cin>>a>>b>>c;
    cout<<(b-a==c-b?"YES":"NO");
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    ans=1
    for i in range(N):
        a=I()
        if a%2==1:
            ans=0
            break
        
    S=["first","second"]
    print(S[ans])
                
    #奇数があれば先手の勝ち？
    #帰納法で証明できそう

main()


Measured memory_bytes: 73528
#include <iostream>
 
using namespace std;
 
int main()
{
    int n;
    cin >> n;
    int *a =new int[n];
    long long min=10000000000;
    long long sum=0;
    int c=0;
    for (int i=0;i<n;i++){
    	cin>>a[i];
        if(a[i]<0){
        	c++;
            sum-=a[i];
            if(min>-1*a[i]){
        		min=-1*a[i];
            }
        }else{
        	sum+=a[i];
          	if(min>a[i]){
        		min=a[i];
            }
        }
    }
    long long r;
	if(c%2==0){
    	r=sum;
    }else{
    	r=sum-2*min;
    }
          
    cout << r << endl;
}

Measured memory_bytes: 640
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TEMPLATE ENDS HERE */

#define MAXN (1 << 20)

int l[MAXN];
int r[MAXN];

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

	for (int i = 1; i <= n; i++) {
		l[i] += l[i - 1];
		if (s[i - 1] == 'W') {
			l[i]++;
		}
	}
	for (int i = n; i >= 1; i--) {
		r[i] += r[i + 1];
		if (s[i - 1] == 'E') {
			r[i]++;
		}
	}
	int ret = MAXN;
	for (int i = 1; i <= n; i++) {
		int cur = l[i - 1] + r[i + 1];
		ret = min(ret, cur);
	}
	cout << ret << endl;
	cout << fixed << setprecision(12);	
	return 0;
}


ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}



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

int main() {
  
  int a, b; cin >> a >> b;
  
  cout << a / b << " ";
  
  cout << a % b << " ";
  
  cout << fixed << setprecision(10);
  
  cout << double(a) / double(b) << endl;
  
}


Measured memory_bytes: 3284
#include <stdio.h>
#include <string.h>
int main(void){
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    if(A>=B&&A>=C){
        printf("%d",B+C);
    }
    else if(B>=A&&B>=C){
        printf("%d",A+C);
    }
    else{
        printf("%d",A+B);
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>

using namespace std;


long long sk(long long n, long long m) {
	long long N = max(n, m);
	long long M = min(n, m);

	if (M == 0) return N;

	return sk(M, N%M);
}

int main() {

	long long a, b, c, d;
	cin >> a >> b >> c >> d;

	long long tmp = 0;
	tmp += b/c;
	tmp -= (a-1)/c;

	tmp += b/d;
	tmp -= (a - 1) / d;

	long long g = sk(c, d);
	long long l = c*d / g;

	tmp -= b/l;
	tmp += (a - 1) / l;

	cout << b - a + 1 - tmp << endl;


	/*
	int N, L;

	cin >> N >> L;

	int min = 99999, tmp;
	int sum = 0;
	for (int i = 1; i <= N; i++) {
		if (min > L + i - 1) {
			min = abs(L + i - 1);
			tmp = L + i - 1;
		}

		sum += L + i - 1;
	}

	cout << sum - tmp << endl;
	*/


	/*
	string s;
	cin >> s;

	for (int i = 0; i < 3; i++) {
		if (s[i] == s[i + 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}

	cout << "Good" << endl;
	*/

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define lint long long
    #define st first
    #define nd second
    #define INF 0x3f3f3f3f
     
    using namespace std;
     
     
    int main(){
    	ios_base::sync_with_stdio(false);
    	cin.tie(NULL); cout.tie(NULL);
    	int k, n;
    	cin>>n>>k;
    	vector<int> v(n);
    	for(int &x:v)cin>>x;
    	sort(v.begin(), v.end());
    	int s = 0;
    	for(int i=0;i<min(n,k);i++){
    		s += v[i];
    		//cerr<<v[i]<<"\n";
    	}
    	cout<<s<<"\n";
    	
    	return 0;	
    }

Measured memory_bytes: 3636
H, W = map(int, input().split())
S = ['.' + input() + '.' for _ in range(H)]
S = ['.'*(W+2)] + S + ['.'*(W+2)]

ans = 'Yes'

for i in range(1, H+1):
    for j in range(1, W+1):
        if S[i][j]=='#':
            if S[i-1][j]!='#' and S[i][j-1]!='#' and S[i+1][j]!='#' and S[i][j+1]!='#':
                print('No')
                exit()

print(ans)

Measured memory_bytes: 3064
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

S = input()
x, y = int(S[:2]), int(S[2:])
yymm = 1 <= y <= 12
mmyy = 1 <= x <= 12
if yymm and mmyy:
    print('AMBIGUOUS')
elif yymm:
    print('YYMM')
elif mmyy:
    print('MMYY')
else:
    print('NA')


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

class Program
{
    static void Main(string[] args)
    {
        var n = long.Parse(Console.ReadLine());
        string[] s = new string[n];
        for(int i = 0; i < n; i++)
        {
            s[i] = Console.ReadLine();
        }

        var s2 = s.Distinct().ToArray();

        Console.WriteLine(s2.Length);
    }
}

Measured memory_bytes: 44388
import java.io.*;
import java.util.*;


public class Main{
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        // Start writing your solution here. -------------------------------------
        //int t = sc.nextInt();
        int t = 1;
        while(t -- > 0)
        {
            int n = sc.nextInt();
            int W = sc.nextInt();
            long res = 0l;
            long nw[][] = new long[n + 1][2];
            long dp[][] = new long[n + 1][W + 1];
            for(int i = 1; i <= n; i++)
                for(int j = 0; j < 2; j++)
                    nw[i][j] = sc.nextLong();
            for(int i = 1; i <= n; i++) {
                for (int j = W; j >= 0; j--) {
                    dp[i][j] = dp[i - 1][j];
                    if (nw[i][0] <= j)
                    dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - (int) nw[i][0]] + nw[i][1]);
                }
            }
            for(int i = 0; i <= W; i++)
                res = Math.max(res, dp[n][i]);
            //for(int i = 0; i <= n; i++) System.out.println(Arrays.toString(dp[i]));
            out.println(res);
        }

        out.close();

        /*
        int n      = sc.nextInt();        // read input as integer
        long k     = sc.nextLong();       // read input as long
        double d   = sc.nextDouble();     // read input as double
        String str = sc.next();           // read input as String
        String s   = sc.nextLine();       // read whole line as String

        int result = 3*n;
        out.println(result);                    // print via PrintWriter
        */
        // Stop writing your solution here. -------------------------------------
        out.close();
    }
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    //--------------------------------------------------------
}

Measured memory_bytes: 125524
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

struct flower {
    int height;
    int point;
};

#define NUM_MAX 200000
// 262144
#define NUM2_MAX (1<<18)
#define ROOT_NODE 1

struct range {
    int start;
    int end;
};

int is_overlap(struct range r1, struct range r2) {
    return r1.end >= r2.start && r2.end >= r1.start;
}

int is_contain(struct range elem, struct range box) {
    return elem.start >= box.start && elem.end <= box.end;
}

int64_t get_max(int64_t* seg, struct range r, int node, struct range nr) {
    if(!is_overlap(r, nr)) return 0;
    if(is_contain(nr, r)) return seg[node];
    struct range left = { nr.start, (nr.start + nr.end)/2 };
    struct range right = {left.end+1, nr.end};
    int64_t m1 = get_max(seg, r, node*2, left);
    int64_t m2 = get_max(seg, r, node*2+1, right);
    return max(m1, m2);
}

void update(int64_t *seg, int num, int idx, int64_t val) {
    int node = num + idx;
    seg[node] = val;
    while((node = node/2)) {
        seg[node] = max(seg[node*2], seg[node*2+1]);
    }
#ifdef DEBUG
    int i;
    for(i = num; i < 2*num; i++) {
        printf(" %lld", seg[i]);
    }
    putchar('\n');
#endif
    return;
}

int main(void) {
    int num = get_int();
    static int heights[NUM_MAX+1];
    static int points[NUM_MAX+1];
    static int64_t seg[NUM2_MAX*2];

    
    int i;
    fget_array(heights, num);
    fget_array(points, num);
    int num2 = 1;

    // 1-indexed
    while(num >= num2) num2 *= 2;

    struct range whole = {0, num2-1};
    for(i = 1; i <= num; i++) {
        int cur = heights[i-1];
        int64_t point = points[i-1];
        struct range r = {0, cur-1};
        int64_t new = get_max(seg, r, ROOT_NODE, whole) + point;
#ifdef DEBUG
        printf("%d: %lld\n", i, new);
#endif
        if(new > seg[num2+cur]) {
            update(seg, num2, cur, new);
        }
    }

    printf("%lld\n", seg[ROOT_NODE]);

    return 0;
}

Measured memory_bytes: 5376
#include <stdio.h>

int main(){
    int n,i,j,minIx=0,swapCount=0,needSwap=0;
    scanf("%d", &n);
    int a[n];
    for(i=0;i<n;i++) scanf("%d", &a[i]);
    for(i=0;i<n;i++){
        minIx = i;
        for(j=i;j<n;j++){
            if(a[j]<a[minIx]){
                minIx = j;
                needSwap = 1;
            }
        }
        if(needSwap){
        a[i]^=a[minIx];
        a[minIx]^=a[i];
        a[i]^=a[minIx];
        needSwap = 0;
        swapCount++;
        }
    }
    for(i=0;i<n-1;i++) printf("%d ",a[i]);
    printf("%d\n", a[i]);
    printf("%d\n", swapCount);
}


Measured memory_bytes: 2108
int required_taps(int A, int B) {
  int taps = 1, count = 0;
  while (taps < B) {
    taps += A - 1;
    ++count;
  }
  return count;
}

#include <iostream>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int A, B;
  cin >> A >> B;

  cout << required_taps(A, B) << "\n";
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace ABC099B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var A = input[0];
            var B = input[1];

            var diff = B - A;

            Console.WriteLine(Sum(diff) - B);
        }

        static int Sum(int x)
        {
            if (x == 1) return 1;
            return x + Sum(x - 1);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
const int INFI = 2147483647;
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


int main() {
  int n; cin >>n;
  cout <<(n+1)/2 <<endl;
}


Measured memory_bytes: 256
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


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

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


  int main()
  {
ios::sync_with_stdio(false);
    cin.tie(nullptr);
i64 n,t,p;
cin>>n;
cin>>t>>p;

i64 ans;
ans=__gcd(t,p);
forn(i,n-2)
{cin>>t;
  ans=__gcd(ans,t);

}cout<<ans;

    return 0;
  }


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
  int A,B,i=0;
  scanf("%d %d",&A,&B);
 int out=1;
  while(out<B){
    out--;
    out+=A;
    i++;
  }
    
  printf("%d\n",i);
      
      
  return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  
  int res=0;
  vector<int> c;
  c.pb(2e9);
  rep(i,n){
    if(c[c.size()-1]>=a[i]){
      c.pb(a[i]);
      res++;
    }else{
      int p=0,q=c.size()-1;
      int r;
      while(q-p!=1){
        r=(p+q)/2;
        if(c[r]>=a[i]) p=r;
        else q=r;
      }
      c[q]=a[i];
    }
  }
  cout<<res<<endl;
}

Measured memory_bytes: 1276
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int n, k; cin >> n >> k;
	int ans = 1;

	rep(i, n) {
		ans = min(ans * 2, ans + k);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), k = sc.nextInt(), h[] = new int[n];
		long dp[] = new long[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			dp[i] = Integer.MAX_VALUE;
		}
		dp[0] = 0;
		for (int i = 1; i < n; i++) {
			for (int j = i - 1; j >= 0 && j >= i - k; j--) {
				long a = Integer.MAX_VALUE;
				if (i - 1 >= 0)
					a = dp[j] + Math.abs(h[j] - h[i]);
				dp[i] = Long.min(dp[i], a);
			}
		}
		System.out.println(dp[n - 1]);
		sc.close();
	}
}


Measured memory_bytes: 60696