akhauriyash/Code-Regression huggingface dataset:
s = input()
n = len(s)
bits = dict()
bits[0] = 0
bit = 0
for i in range(n):
	x = ord(s[i])-97
	bit ^= (1<<x)
	for j in range(26):
		new_bit = bit ^ (1<<j)
		if new_bit in bits:
			#print(bin(bit)[2:], bin(new_bit)[2:])
			if bit in bits:
				bits[bit] = min(bits[bit], bits[new_bit] + 1)
			else:
				bits[bit] = bits[new_bit] + 1
			#print(bits[bit])
		#print("-----")
if bit not in bits:
	print(-1)
else:
	print(max(1, bits[bit]))

Measured memory_bytes: 67788
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <bitset>

#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define rep1(i,n) for (int (i) = 1; (i) <= (n); i++)
typedef long long int llint;

using namespace std;

const long long int inf = 1 << 29 ;

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

  vector<int> tako(n);
	rep(i, n) {
	  cin >> tako[i];
	}

	int ans = 0;
	for (int i = 1; i < n; i++) rep(j, i) {
	  ans += tako[i]*tako[j];
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NMK = Sarray();
            var N = NMK[0];
            var M = NMK[1];
            var K = NMK[2];
            // friend
            var friend = Enumerable.Range(0, (int)N).Select(_ => new List<long>()).ToArray();
            var funion = new UnionFind((int)N);
            for (var i = 0; i < M; ++i)
            {
                var ab = Sarray();
                friend[ab[0] - 1].Add(ab[1] - 1);
                friend[ab[1] - 1].Add(ab[0] - 1);
                funion.merge((int)ab[0] - 1, (int)ab[1] - 1);
            }
            // block
            var block = Enumerable.Range(0, (int)N).Select(_ => new List<long>()).ToArray();
            for (var i = 0; i < K; ++i)
            {
                var cd = Sarray();
                block[cd[0] - 1].Add(cd[1] - 1);
                block[cd[1] - 1].Add(cd[0] - 1);
            }
            var ans = new long[N];
            for (var i = 0; i < N; ++i)
            {
                var t = funion.size(i) - 1;//自分は除く
                t -= friend[i].Count;
                foreach (var b in block[i])
                    if (funion.issame(i, (int)b)) --t;
                ans[i] = t;
            }
            WriteLine(string.Join(" ", ans));
            //Out.Flush();
        }
    
        class UnionFind
        {
            int[] par;
            public UnionFind(int n)
            {
                init(n);
            }
            public void init(int n)
            {
                par = new int[n];
                for (var i = 0; i < n; ++i) { par[i] = -1; }
            }
            public int root(int x)
            {
                if (par[x] < 0) return x;
                else return par[x] = root(par[x]);
            }
            public bool issame(int x, int y)
            {
                return root(x) == root(y);
            }
            public bool merge(int x, int y)
            {
                x = root(x);
                y = root(y);
                if (x == y) return false;
                if (par[x] > par[y])
                {
                    var tmp = y;
                    y = x;
                    x = tmp;
                }
                par[x] += par[y];
                par[y] = x;
                return true;
            }
            public int size(int x)
            {
                return -par[root(x)];
            }
        }
    }
}

Measured memory_bytes: 48292
#include<iostream>
using namespace std;
int digit(int i)
{
	int sum=0;
	while(i)
	{
		sum+=i%10;
		i/=10;
	}
	return sum;
}
int main()
{
	int ans=0;
	int n,a,b;
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	{
		if(digit(i)>=a&&digit(i)<=b) ans+=i;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 45

int main(){
  int a[N], n, i;
  
  a[0] = a[1] = 1;
  scanf("%d",&n);
  for(i = n; i > 0; i--){
    a[n-i+2] = a[n-i+1] + a[n-i];
  }
  printf("%d\n",a[n]);
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

vector<int> a,b, sum(111111);
int ans = 1;

int main()
{
    int n;
    cin>>n;
    a.resize(n); b.resize(n);
    REP(i,n) {
        cin>>a[i]>>b[i];
        sum[a[i]]++;
        sum[b[i]+1]--;
    }
    sum[0]++;
    REP(i,100111) {
        sum[i+1] = sum[i] + sum[i+1];
        if (sum[i+1] >= i+1) {
            ans = i+1;
        }
    }
    cout<<ans - 1<<endl;

    return 0;
}



Measured memory_bytes: 4148
#include<cstdio>
#include<iostream>
#include<algorithm>
#define cou cnt
using namespace std;

int N,num[100],ans;
long long memo[100][21];

long long func(int n,int s){
    long long cou=0;

    if(s<0||s>20)return 0;
    if(memo[n][s]!=-1)return memo[n][s];
    if(n==N-1){
        if(s==ans)return 1;
        return 0;
    }
    cou += func(n+1,s+num[n]);
    if(n!=0){
        cou += func(n+1,s-num[n]);
    }
    memo[n][s]=cou;
    return cou;
}
int main(){
    cin>>N;

    for(int i=0;i<N;i++){
        for(int j=0;j<=20;j++){
            memo[i][j]=-1;
        }
    }

    for(int i=0;i<N-1;i++){
        cin>>num[i];
    }
    cin>>ans;
    cout<<func(0,0)<<endl;
}

Measured memory_bytes: 1172
//希尔排序
#include<iostream>
using namespace std;
#define N 1000005
long long cnt = 0;
int G[102];
int A[N];
void insertionSort(int A[],int n,int g)
{
	int v,j;
	for(int i =g;i<n;i++)
	{
		v=A[i];
		j = i-g;
		while(j>=0&&A[j]>v)
		{
			A[j+g] = A[j];
			j=j - g;
			cnt++;
		}
		A[j+g] = v; 
	}
} 

void shellSort(int A[],int n)
{
	int m = n ,i=0;
	while(m/3!=0)
	{
		G[i] = m/3+1;
		m = G[i];
		i++;
	}
	G[i]=1;
	m = i+1;
	cout<<m<<endl;
	for(i =0;i<m;i++)
	{
		insertionSort(A,n,G[i]);
		if(i<m-1)
		cout<<G[i]<<' ';
		else 
		cout<<G[i]<<endl;
	}
	
}
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>A[i];
	}
	shellSort(A,n);
	cout<<cnt<<endl;
	for(int i=0;i<n;i++)
	{
		cout<<A[i]<<endl;
	}
	return 0;
	
}



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

#define rep(i,a,b) for(auto (i)=a;i<b;i++)
#define list(i,N) for(auto (i)=0;i<N;i++)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
#define mp make_pair
#define pb push_back

#define int ll
#define INF 1e18+5
#define mod 1000000007

int32_t main(){

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int a, b; cin >> a >> b;
	string first = ""; string second = "";
	list(i,a) first += to_string(b);
	list(i,b) second += to_string(a);
	if(first<second) cout << first << "\n";
	else cout << second << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

ll n,k;
ll arr[100001];

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

	ll ans = (1LL<<30);

	for(int i = 0; i <= n-k; i++) {
		int _min = min(abs(arr[i]),abs(arr[i+k-1]));
		ll len = arr[i+k-1]-arr[i];
		ans = min(ans,len+_min);
		//cout << "----" << endl;
	}

	if(ans==(1LL<<30)) ans = 0;

	cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s,w;
	int c=0;

	cin >> w;
	while (cin >> s, s != "END_OF_TEXT"){
		
		for (int i = 0; i < s.size();++i)
		if (s[i] >= 65 && s[i] <= 90)s[i] += 32;

		if (s == w)++c;
	}

	cout << c << endl;		
}

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

using pii = pair<int, int>;
using vi = vector<int>;
using ll = long long;

constexpr int INF = 1e9;

struct edge {
    int u, v, cost;
    bool operator<(edge const& e) const {
        return cost < e.cost;
    }
};

using edges = vector<edge>;

class union_find {
public:
    union_find(int n) : par(n, -1) {}

    int root(int x) {
        return par[x] < 0 ? x : par[x] = root(par[x]);
    }

    bool unite(int x, int y) {
        x = root(x), y = root(y);
        if(x == y) {
            return false;
        }
        if(par[x] < par[y]) {
            par[x] += par[y];
            par[y] = x;
        } else {
            par[y] += par[x];
            par[x] = y;
        }
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }

private:
    vector<int> par;
};

int main() {
    int N, M;
    cin >> N >> M;
    edges es(M);
    for(int i = 0; i < M; ++i) {
        cin >> es[i].u >> es[i].v >> es[i].cost;
        es[i].u--; es[i].v--;
    }
    sort(begin(es), end(es));
    int min_cost = 0;
    edges MST;
    {
        union_find uf(N);
        for(auto& e : es) {
            if(uf.unite(e.v, e.u)) {
                min_cost += e.cost;
                MST.push_back(e);
            }
        }
    }
    int ans = 0, ans_cost = 0;
    for(auto& e : MST) {
        union_find uf(N);
        int t = 0;
        for(auto& e2 : es) {
            if(e.u == e2.u && e.v == e2.v) {
                continue;
            }
            if(uf.unite(e2.u, e2.v)) {
                t += e2.cost;
            }
        }
        if(min_cost < t || uf.size(0) != N) {
            ans++;
            ans_cost += e.cost;
        }
    }
    cout << ans << ' ' << ans_cost << endl;
}


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

#define ull unsigned long long int
#define ll long long int
#define vll vector<ll>
#define vi vector<int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define itr vll::iterator
#define all(c) c.begin(),c.end()
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define inf 1000000000000000001

#define rep(i, n)      for(ll i = 0; i <  n; ++i)
#define repA(i, a, n)  for(ll i = a; i <= n; ++i)
#define repD(i, a, n)  for(ll i = a; i >= n; --i)

using namespace std;

bool func(const pll &a, const pll &b){
    return a.s < b.s;
}

ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}

void solve(){
    ll n;
    cin >> n;
    ll m; cin >> m;
    vll v(n); rep(i, n) cin >> v[i];
    vector<vll> rs(n);
    vpll tr(m); 
    rep(i, m){
    	ll t1, t2;
    	cin >> t1 >> t2;
    	t1--; t2--;
    	rs[t1].pb(t2);
    	rs[t2].pb(t1);
    }
    ll cnt =0;
    rep(i, n){
    	int flg = 1;
    	rep(j, rs[i].size()){
    		if(v[rs[i][j]] >= v[i]) flg = 0;
    	}
    	if(flg) cnt++;
    }
    cout << cnt;
}

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

    int t, tmp = 0;
    // cin >> t;
    t = 1;
    while(t--){
        // cout << "Case #" << ++tmp << ": ";
        solve();
        if(t) cout << "\n";
    }
    cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
    return 0;
}

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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N;
    cin >> N;
    vector<int> list(N);
    for (int i = 0; i < N; i++)
        cin >> list[i];
    sort(list.begin(), list.end());
    cout << abs(list[0] - list[N - 1]);
}

Measured memory_bytes: 256
class P2
  attr_reader :a, :b, :c

  def initialize(a,b,c)
    @a = a || 0; @b = b || 0; @c = c || 0
  end

  def f(t)
    @a*t*t + @b*t + @c
  end

  def df(t)
    2*@a*t + @b
  end

  def stationary
    @a == 0 ? nil : -@b.to_f/@a/2
  end

  def min(t1,t2)
    vs = [f(t1),f(t2)]
    ts = stationary
    if ts && t1 <= ts && ts <= t2
      vs << f(ts)
    end
    vs.min
  end
end

class P1
  attr_reader :a, :b
  def initialize(a,b)
    @a = a || 0; @b = b || 0
  end

  def f(t)
    @a*t+@b
  end

  def df(t)
    @a
  end

  def self.add(p1,p2)
    self.new(p1.a + p2.a, p1.b + p2.b)
  end

  def self.sub(p1,p2)
    self.new(p1.a - p2.a, p1.b - p2.b)
  end

  def self.prod(p1,p2)
    P2.new(p1.a*p2.a, p1.a*p2.b + p2.a*p1.b, p1.b*p2.b)
  end

  def zero_cross
    @a == 0 ? nil : -@b.to_f/@a
  end
end


N = gets.to_i
XYD = (0...N).map{ gets.split }.transpose
XS = XYD[0].map &:to_i
YS = XYD[1].map &:to_i
DS = XYD[2]

Xmax = {}
Ymax = {} 
Xmin = {}
Ymin = {} 

["L","R","U","D"].each{ |d|
  is = (0...N).select{ |i| DS[i] == d }
  xs = is.map{ |i| XS[i] }
  ys = is.map{ |i| YS[i] }
  Xmax[d] = xs.max; Xmin[d] = xs.min
  Ymax[d] = ys.max; Ymin[d] = ys.min
}

#p Xmin, Xmax, Ymin, Ymax

XUDmin = [Xmin["U"], Xmin["D"]].compact.min
XUDmax = [Xmax["U"], Xmax["D"]].compact.max
YLRmin = [Ymin["L"], Ymin["R"]].compact.min
YLRmax = [Ymax["L"], Ymax["R"]].compact.max

PXmin = []
PXmin << P1.new(0, -XUDmin) if XUDmin
PXmin << P1.new(-1, -Xmin["R"]) if Xmin["R"]
PXmin << P1.new(+1, -Xmin["L"]) if Xmin["L"]
PXmax = []
PXmax << P1.new(0, XUDmax) if XUDmax
PXmax << P1.new(+1, +Xmax["R"]) if Xmax["R"]
PXmax << P1.new(-1, +Xmax["L"]) if Xmax["L"]
PYmin = []
PYmin << P1.new(0, -YLRmin) if YLRmin
PYmin << P1.new(-1, -Ymin["U"]) if Ymin["U"]
PYmin << P1.new(+1, -Ymin["D"]) if Ymin["D"]
PYmax = []
PYmax << P1.new(0, YLRmax) if YLRmax
PYmax << P1.new(+1, +Ymax["U"]) if Ymax["U"]
PYmax << P1.new(-1, +Ymax["D"]) if Ymax["D"]

InterestTimes = {}
InterestTimes[0.0] = InterestTimes[1e10] = 1
[PXmin, PXmax, PYmin, PYmax].each{ |ps|
  (0...ps.size).each{ |i|
    (i+1...ps.size).each{ |j|
      t = P1.sub(ps[i], ps[j]).zero_cross
      if t && t > 0
        #p [ps[i],ps[j],t]
        InterestTimes[t] = 1
      end
    }
  }
}

ITS = InterestTimes.keys.sort
#p ITS
p (0...ITS.size-1).map{ |i|
  t1 = ITS[i]; t2 = ITS[i+1]
  ps = [PXmin, PXmax, PYmin, PYmax].map{ |ps|
    ps.sort_by{ |p| p.f((t1+t2)/2) }.last
  }
  px = P1.add(ps[1], ps[0])
  py = P1.add(ps[3], ps[2])
  p2 = P1.prod(px,py)
  #p ps, px, py, p2, p2.zero, p2.min(t1,t2)
  p2.min(t1,t2)
}.min



Measured memory_bytes: 28792
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt
from fractions import gcd

def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas



# N = intinput()
# S = input()
S, T = input().split()
# datas = list(mulinputs())
# datas = lineinputs(input)

# 出力
print(T+S)




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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int n;
  scanf("%d", &n);

  vector<int> p(n);
  REP (i, n) {
    scanf("%d", &p[i]);
  }

  int i = 0;
  int a = 0;
  while (i < n) {
    if (i + 1 == p[i]) {
      a++;
      if (i + 1 < n && i + 2 == p[i + 1]) i++;
    }
    i++;
  }

  i = n - 1;
  int b = 0;
  while (0 <= i) {
    if (i + 1 == p[i]) {
      b++;
      if (i - 1 > 0 && i - 1 == p[i]) i--;
    }
    i--;
  }
  printf("%d\n", min(a, b));
}


Measured memory_bytes: 640
// Delete the dynamically allocated memory
 
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define pb              push_back
#define pr              pair<long long,long long>
#define mp(a,b)         make_pair(a,b)
#define vr              vector<long long>
#define mod1            1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define fill(a,b)       memset(a, b, sizeof(a))
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)
ll power(ll base, ll exp) {
    ll res=1;
    while(exp>0) {
       if(exp%2==1) res=(res*base);
       base=(base*base);
       exp/=2;
    }
    return res;
}
int main()
{
	ll n;
	cin>>n;
	mk(a,n+1,ll)
	ll cnt=0;
	for(ll i=1;i<=n;i++){
		cin>>a[i];
		if(i%2==1&&a[i]%2==1){
			cnt++;
		}
	}
	cout<<cnt<<"\n";
	delete[] a;
	return 0;
}

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

int main()
{
	string S;
	cin >> S;
	int t = 700;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'o') {
			t += 100;
		}
	}
	cout << t << endl;
		}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    ll n,a,b,c; cin>>n>>a>>b>>c;
    vector<char> res(n);
    vector<string> s(n);
    rep(i,n){
        cin>>s[i];
    }
    vector<vector<ll>> dp(n+1, vector<ll>(3));
    dp[0] = {a, b, c};
    stack<pair<ll,ll>> st; //dp[first] で second 番目の文字に1足した
    ll i=0;
    while(i<n){
        dp[i+1] = dp[i];
        if(s[i]=="AB") {
            if(dp[i+1][0] == 1 && dp[i+1][1] == 1) st.push({i, 0});
            if(dp[i+1][0] > dp[i+1][1]) {dp[i+1][0]--; dp[i+1][1]++; res[i]='B';}
            else {dp[i+1][0]++; dp[i+1][1]--; res[i]='A';}
        }else if(s[i]=="BC") {
            if(dp[i+1][1] == 1 && dp[i+1][2] == 1) st.push({i, 1});
            if(dp[i+1][1] > dp[i+1][2]) {dp[i+1][1]--; dp[i+1][2]++; res[i]='C';}
            else {dp[i+1][1]++; dp[i+1][2]--; res[i]='B';}
        }else{
            if(dp[i+1][2] == 1 && dp[i+1][0] == 1) st.push({i, 2});
            if(dp[i+1][2] > dp[i+1][0]) {dp[i+1][2]--; dp[i+1][0]++; res[i]='A';}
            else {dp[i+1][2]++; dp[i+1][0]--; res[i]='C';}
        }
        if(dp[i+1][0]<0 || dp[i+1][1]<0 || dp[i+1][2]<0){
            if(st.empty()){
                cout << "No" <<endl;
                return 0;
            }
            pair<ll,ll> p = st.top();
            st.pop();
            i = p.first;
            dp[i+1] = dp[i];
            if(s[i] == "AB") {dp[i+1][0]--; dp[i+1][1]++; res[i] = 'B';}
            else if(s[i] == "BC") {dp[i+1][1]--; dp[i+1][2]++; res[i] = 'C';}
            else {dp[i+1][2]--; dp[i+1][0]++; res[i] = 'A';}
        }
        i++;
    }
    cout<<"Yes"<<endl;
    rep(i,n){
        cout<<res[i]<<endl;
    }
    return 0;
}

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

n = int(input())
T = [[] for _ in range(n+1)]
for _ in range(n-1):
  u, v = map(int, input().split())
  T[u].append(v)
  T[v].append(u)
ans = 0
for i in range(1, n+1):
  temp = 1
  for j in T[i]:
    if j < i:
      temp -= 1
      ans += (i-j) * (n+1-i)
  ans += temp * (n+1-i) * i
print(ans)

Measured memory_bytes: 43676
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <stack>
#include <set>
#include <deque>
#pragma GCC optimize(3 , "Ofast" , "inline")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std ;
#define ios ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define x first
#define y second
#define pb push_back
#define ls rt << 1
#define rs rt << 1 | 1
typedef long long ll ;
const double esp = 1e-6 , pi = acos(-1) ;
typedef pair<int , int> PII ;
const int N = 1e6 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;
ll c[N] , b[N] ;
int e[N] ,idx , ne[N] , h[N] , p[N] ;
ll w[N] ;
void add(int a,  int b , ll c){
  e[idx] = b , ne[idx] = h[a] , w[idx] = c , h[a] = idx ++ ;
}
vector<int> v[N] ;
int vis[N] , Size[N] ;
void dfs(int u , int cnt){
  vis[u] = cnt ;
  Size[cnt] ++ ;
  v[cnt].push_back(u) ;
  b[cnt] += c[u] ;
  for(int i = h[u] ; ~i ; i = ne[i]) {
    int v = e[i] ;
    if(vis[v]) continue ;
    dfs(v , cnt) ;
  }
}
ll bfs1(int u , ll k){
  ll ans = -2e18 ;
  for(int i = 0 ;i < v[u].size() ;i ++ ) {
    ll res = 0 ;
    for(int t = k , x = i ;t >= 1 ;t -- , x ++ , x %= v[u].size())
     res += c[v[u][x]] , ans = max(ans , res);
  }
  return ans ;
}
int work()
{
  memset(h , -1 , sizeof h) ;
  int n , k ;
  cin >> n >> k ;
  for(int i = 1; i <= n ;i ++ ) cin >> p[i] ;
  for(int i = 1; i <= n ;i ++ ) cin >> c[i] ;
  for(int i = 1; i <= n ;i ++ ) {
    add(i , p[i] , c[p[i]]) ;
  }
  int cnt = 0 ;
  for(int i = 1; i <= n ;i ++ )
   if(!vis[i]) cnt ++ , dfs(i , cnt) ;
  ll ans = -2e18 ;
  for(int i = 1; i <= cnt ;i ++ ) {
    if(b[i] <= 0) {
      ans = max(ans , bfs1(i , min(k , Size[i]))) ;
    }else {
      ans = max(ans , 1ll * b[i] * (k / Size[i]) + max(0ll , bfs1(i, k % Size[i]))) ;
      ll p = k / Size[i] ;
      if(p)
      ans = max(ans , 1ll * b[i] * (p - 1) + max(0ll , bfs1(i , k % Size[i] + Size[i]) ) ) ;
    }
  }
  cout << ans << endl ;
  return 0 ;
}
int main()
{
  //   freopen("C:UsersspnooyseedDesktopin.txt" , "r" , stdin) ;
  //   freopen("C:UsersspnooyseedDesktopout.txt" , "w" , stdout) ;

  work() ;
  return 0 ;
}
/*
*/


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

#define fi first
#define se second

typedef pair<int, int> ii;
typedef pair<int, ii> p;
const int N = 100005;

int n, a[N], b[N], par[N];
vector<ii> va, vb;
vector<p> v;

int find(int x) {
    return (x == par[x]) ? x : par[x] = find(par[x]);
}

bool join(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return 0;
    par[x] = y; return 1;
}

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; ++i) par[i] = i;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        va.push_back(ii(a[i], i));
        vb.push_back(ii(b[i], i));
    }
    sort(va.begin(), va.end());
    sort(vb.begin(), vb.end());
    for (int i = 1; i < n; ++i) {
        v.push_back(p(va[i].fi - va[i - 1].fi, ii(va[i].se, va[i - 1].se)));
        v.push_back(p(vb[i].fi - vb[i - 1].fi, ii(vb[i].se, vb[i - 1].se)));
    }
    sort(v.begin(), v.end());
    long long res = 0;
    for (int i = 0; i < v.size(); ++i) {
        if (join(v[i].se.fi, v[i].se.se)) {
            res += v[i].fi;
        }
    }
    cout << res;
}


Measured memory_bytes: 9448
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  int pasta1, pasta2, pasta3, juice1, juice2;
  cin >> pasta1 >> pasta2 >> pasta3 >> juice1 >> juice2;

  int min_pasta = min(min(pasta1, pasta2), pasta3);
  int min_juice = min(juice1, juice2);

  cout << min_pasta + min_juice - 50 << endl;

  return 0;
}


Measured memory_bytes: 3092
N = int(input())
h = list(map(int, input().split()))
# N = 6
# h = [30,10,60,10,60,50]
dp = [0]*(N+1)
# print(dp)
for i in range(1, N):
    if i == 1:
        dp[1] = abs(h[1]-h[0])
        # print(dp)
    else:
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
        # print(dp)
print(dp[N-1])



Measured memory_bytes: 20704
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }  
 
  sort(d.begin(), d.end());
  
  int kagamimochi = 1;
  for (int i = 0; i < N -1   ; i++) {
    if (d.at(i) < d.at(i+1)) {
      kagamimochi += 1;
    } 
  }
  cout << kagamimochi << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5 + 42;
int h[N];
int dp[N];
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int n = 0, k = 0;

  cin >> n >> k;

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

  for(int i = 0; i < n; i++) dp[i] = 1e9 + 42;

  dp[0] = 0;

  for(int i = 0; i < n; i++) {
    for(int j = i; j < min(n, i + k + 1); j++)
      dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]));
  }

  cout << dp[n - 1];

  return 0;
}
/*

*/


Measured memory_bytes: 4440
#include<bits/stdc++.h>
using namespace std;
#define MAX5 100010
#define MAX6 1000010
#define pb push_back
#define mp make_pair
typedef long long int ll;
vector<pair<ll,ll> >vec[MAX5];
bool vis[MAX5];
int color[MAX5];
void dfs(ll src)
{
    vis[src]=1;
    for(int i=0;i<vec[src].size();i++)
    {
        if(vis[vec[src][i].first]!=1)
        {
            if(vec[src][i].second%2==0)
                color[vec[src][i].first]=color[src];
            else if(vec[src][i].second%2!=0)
            {
                if(color[src]==0)
                    color[vec[src][i].first]=1;
                if(color[src]==1)
                    color[vec[src][i].first]=0;
            }
            dfs(vec[src][i].first);
        }
    }
}
int main()
{
    ll n;
    cin>>n;
    memset(vis,0,sizeof(vis));
    for(ll i=0;i<n-1;i++)
    {
        ll u,v,w;
        cin>>u>>v>>w;
        vec[u].pb(mp(v,w));
        vec[v].pb(mp(u,w));
    }
    for(int i=1;i<=n;i++)
    {
        if(vis[i]!=1)
        {
            color[i]=1;
            dfs(i);
        }
    }
    for(int i=1;i<=n;i++)
    cout<<color[i]<<'\n';
    //dfs(1);
return 0;
}

Measured memory_bytes: 9984
T = int(input())
ABCD = [list(map(int, input().split())) for _ in range(T)]

from fractions import gcd

for a,b,c,d in ABCD:
  if a<b:
    print('No')
    continue
    
  l = gcd(b,d)
  a = a % b
  if (a + ((b-a-1)//l)*l) <= c and (a - (a//l)*l)+d>=b:
    print('Yes')
  else:
    print('No')

    

Measured memory_bytes: 5236
a, b, k = map(int, input().split())
ans = []
if b-a < 2*k:
    for i in range(a, b+1):
        print(i)
else:
    for i in range(a, a+k):
        print(i)
    for i in range(b-k+1, b+1):
        print(i)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n, k;
  cin >> n >> k;
  cout << (n % k == 0 ? 0 : 1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int mn=INT_MIN;
int dp[100000][3];

int f(int a[][3],int n,int i,int c,int last){
    
    if(i>n) return INT_MIN;
    if(i==n){
        return c;
    }
    int curmax=0;
    if(last!=0){
        if(dp[i][0]==-1)
            dp[i][0]=f(a,n,i+1,a[i][0],0);
        curmax=max(curmax,dp[i][0]);
    }
    if(last!=1){
        if(dp[i][1]==-1)
            dp[i][1]=f(a,n,i+1,a[i][1],1);
        curmax=max(curmax,dp[i][1]);
    }
    if(last!=2){
        if(dp[i][2]==-1)
            dp[i][2]=f(a,n,i+1,a[i][2],2);
        curmax=max(curmax,dp[i][2]);
    }
    
    mn=max(mn,c+curmax);
    return c+curmax;
    
}
 
int main() {
	   int n;cin>>n;
	   int a[n][3];
	   memset(dp,-1,sizeof dp);
	  
	   for(int i=0;i<n;i++){
	       cin>>a[i][0];cin>>a[i][1];cin>>a[i][2];
	   }
	   f(a,n,0,0,-1);
	   cout<<mn<<endl;
	   
	return 0;
}

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

using namespace std;

int n,k;

void solve(){
    cin >> n >> k;
    vector<int> dp(n);
    vector<int> h(n);
    for(int i = 0;i < n;i++) cin >> h[i];
    dp[0] = 0;
    for(int i = 1;i < n;i++){
        dp[i] = dp[i-1]+abs(h[i]-h[i-1]);
        for(int j = 2;j <= k && i-j >= 0;j++){
            dp[i] = min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
        }
    }
    cout << dp[n-1] << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

bool nw(bool f1,bool f2,char c){
  if(c=='o'^f2) return 1-f1;
  else return f1;
}

int main(){
  int n;
  string s;
  cin>>n>>s;
  bool f[100010];
  f[1]=0;f[2]=0;
  Fr(i,n-2) f[i+2]=nw(f[i],f[i+1],s[i]);
  if(nw(f[n-1],f[n],s[n-1])==f[1]&&nw(f[n],f[1],s[0])==f[2]){
    Fr(i,n) cout<<(f[i]?'S':'W');
    return 0;
  }
  f[1]=0;f[2]=1;
  Fr(i,n-2) f[i+2]=nw(f[i],f[i+1],s[i]);
  if(nw(f[n-1],f[n],s[n-1])==f[1]&&nw(f[n],f[1],s[0])==f[2]){
    Fr(i,n) cout<<(f[i]?'S':'W');
    return 0;
  }
  f[1]=1;f[2]=0;
  Fr(i,n-2) f[i+2]=nw(f[i],f[i+1],s[i]);
  if(nw(f[n-1],f[n],s[n-1])==f[1]&&nw(f[n],f[1],s[0])==f[2]){
    Fr(i,n) cout<<(f[i]?'S':'W');
    return 0;
  }
  f[1]=1;f[2]=1;
  Fr(i,n-2) f[i+2]=nw(f[i],f[i+1],s[i]);
  if(nw(f[n-1],f[n],s[n-1])==f[1]&&nw(f[n],f[1],s[0])==f[2]){
    Fr(i,n) cout<<(f[i]?'S':'W');
    return 0;
  }
  cout<<-1<<endl;
}

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

int main(){
    string S;
    cin >> S;
    int n = 0;
    if(S == "SUN"){
        n = 7;
    }else if(S == "MON"){
        n = 6;
    }else if(S == "TUE"){
        n = 5;
    }else if(S == "WED"){
        n = 4;
    }else if(S == "THU"){
        n=3;
    }else if(S == "FRI"){
        n=2;
    }else{
        n=1;
    }

    cout << n << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        HashMap<String, Integer> week = new HashMap<>();
        week.put("SAT", 1);
        week.put("FRI", 2);
        week.put("THU", 3);
        week.put("WED", 4);
        week.put("TUE", 5);
        week.put("MON", 6);
        week.put("SUN", 7);
        String S = br.readLine();
        System.out.println(week.get(S));
    }
}


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


def main():
    N = int(input())
    S = [1 if len(str(n)) % 2 == 1 else 0 for n in range(1, N + 1)]
    print(sum(S))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3912
package main

import (
	"fmt"
	"sort"
)

func main() {
	// Code for C - Energy Drink Collector
	var N, M int
	fmt.Scanf("%d %d", &N, &M)

	A := make(map[int]int, N)
	B := make([]int, 0)
	var a, b int
	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d", &a, &b)
		if A[a] == 0 {
			B = append(B, a)
		}
		A[a] += b
	}

	var count int
	var cost int
	sort.Sort(sort.IntSlice(B))

	for i := 0; i < N; i++ {

		if M >= count+A[B[i]] {
			count += A[B[i]]
			cost += A[B[i]] * B[i]
		} else {
			cost += (M - count) * B[i]
			count = M
		}

		if count == M {
			break
		}
	}

	fmt.Println(cost)
}


Measured memory_bytes: 9556
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > 
#define pii pair<int,int> 
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
using namespace std;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){rev|=c=='-';c=Getchar();if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	if(c=='.'){
		c=Getchar();double t=0.1;
		while(c>='0'&&c<='9') x=x+(c-'0')*t,c=Getchar(),t=t/10;
	}
	x=rev?-x:x;
	return 1;
}
template<class T1,class T2> inline bool read(T1 &x,T2 &y){return read(x)&read(y);}
template<class T1,class T2,class T3> inline bool read(T1 &x,T2 &y,T3 &z){return read(x)&read(y)&read(z);}
template<class T1,class T2,class T3,class T4> inline bool read(T1 &x,T2 &y,T3 &z,T4 &w){return read(x)&read(y)&read(z)&read(w);}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c='\n'){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[20];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
//--------------------------------head---------------------------------------------

const int inf=0x3f3f3f3f;
const int N=200005,M=100005,mod=1e9+7;
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n;
ld d,x;

inline ld solve(int n,ld d,ld x){
	if(!n) return 0;
	return (d+(n-1)/2.0*x)/2+solve(n-1,(d*(2*n+2)+3*x)/n/2,x*(n+2)/n);
}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	scanf("%d%Lf%Lf",&n,&d,&x);
	d=d*2+x;x*=4;
	printf("%.12Lf\n",solve(n,d,x));
	return 0;
}

Measured memory_bytes: 8576
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(m)]
for i in range(n):
  l,ans=pow(10,9),0
  for j in range(m):
    x=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
    if l>x:                           
      ans=j+1
    l=min(l,x)
  print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <atcoder/dsu>

int main() {
  int N, M;
  std::cin >> N >> M;
  atcoder::dsu dsu(N);
  for (int i = 0; i < M; ++i) {
    int A, B;
    std::cin >> A >> B;
    dsu.merge(A - 1, B - 1);
  }
  std::cout << dsu.groups().size() - 1 << std::endl;
  return 0;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define int long long
using namespace std;

int32_t main()
{
	int n;
	cin>>n;
	vector<int> h(n);
	for(int i=0; i<n; i++)
		cin>>h[i];
	vector<int> dp(n,INT_MAX);
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(int i=2; i<n; i++)
	{
		dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
	} 
	cout<<dp[n-1];
	return 0;
}


Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll N, Q;
    cin >> N;
    ll suma=0;
    VL a(N); 
    map<ll, ll> mp;
    rep(i,0,N){
        cin >> a[i]; 
        suma += a[i];
        mp[a[i]]++;
    }

    cin >> Q;
    VL b(Q), c(Q); 
    rep(i,0,Q){
        cin >> b[i] >> c[i];
        if(mp[b[i]]==0){
          cout << suma <<endl;
          continue;
        }
        else{
            suma += (c[i]-b[i])*mp[b[i]];
            if(mp[c[i]]>0)mp[c[i]]+=mp[b[i]];
          	else mp[c[i]]=mp[b[i]];            
          	mp[b[i]]=0;
        }
        cout << suma << endl;
    }

    return 0;
}

Measured memory_bytes: 11296
#include<stdio.h>

int main(){
  int i,j,n,v,a[1000];

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

  for(i=0;i<n;i++){
    v=a[i];
    j=i-1;
    while(1){
      if(j<0 || a[j]<=v)break;
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=v;
    for(j=0;j<n;j++){
      if(j<n-1)printf("%d ",a[j]);
      else printf("%d\n",a[j]);
    }
  }
  return 0;
}

Measured memory_bytes: 604
#include <iostream>
using namespace std;

template<class T> inline void chmax(T& a, T b) {
  if (a < b) a = b;
}

template<class T> inline void chmin(T& a, T b) {
  if (a > b) a = b;
}

const long long INF = 1LL << 60;

int main() {
  int N;
  cin >> N;
  int h[N];
  for (int i = 0; i < N; ++i) cin >> h[i];
  long long dp[N];
  for (int i = 0; i < N; ++i) dp[i] = INF;
  dp[0] = 0;
  
  for (int i = 0; i < N; ++i) {
    chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  cout << dp[N-1] << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define int long long
using namespace std;

main()
{
    int n, a, b;
    cin >> n >> a >> b;
    int prev;
    cin >> prev;
    int cur;
    int ans = 0;
    for (int i = 1; i < n; i++) {
        cin >> cur;
        if ((cur - prev) * a < b) {
            ans += (cur - prev) * a;
        } else {
            ans += b;
        }
        prev = cur;
    }
    cout << ans;
}


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

int main() {
  int N;
  cin >> N;
  vector<long long> luca(87);
  luca.at(0) = 2;
  luca.at(1) = 1;
  for(int i = 2; i <= N; i++) {
    luca.at(i) = luca.at(i-1) + luca.at(i-2);
  }
  cout << luca.at(N) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
#define oo (1<<30)
using namespace std;
vector<int> G[N];
int n,k,l[N],r[N],d[N];
void merge(int t,int x,int y)
{
	l[t]=max(l[t],x),r[t]=min(r[t],y);
}
void dfs(int t,int fa)
{
	int i; d[t]=d[fa]^1;
	for(i=0;i<G[t].size();i++)
		if(G[t][i]!=fa){
			dfs(G[t][i],t);
			merge(t,l[G[t][i]]-1,r[G[t][i]]+1);
		  }
}
void DFS(int t,int fa)
{
	int i;
	for(i=0;i<G[t].size();i++)
		if(G[t][i]!=fa){
			merge(G[t][i],l[t]-1,r[t]+1);
			DFS(G[t][i],t);
		  }
}
void GG(){ printf("No"); exit(0);}
void sol(int t,int fa)
{
	int i;
	for(i=0;i<G[t].size();i++)
		if(G[t][i]!=fa){
			sol(G[t][i],t);
			merge(t,l[G[t][i]]-1,l[G[t][i]]+1);
		  }
}
int main()
{
	int i,x,y;
	scanf("%d",&n);
	for(i=1;i<=n;i++) l[i]=-oo,r[i]=oo;
	for(i=1;i<n;i++){
		scanf("%d %d",&x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	  }
	scanf("%d",&k);
	for(i=1;i<=k;i++){
		scanf("%d %d",&x,&y);
		l[x]=r[x]=y;
	  }
	dfs(1,0);
	DFS(1,0);
	for(i=1;i<=n;i++)
		if(l[i]>r[i]) GG();
	x=0;
	for(i=1;i<=n;i++)
		if(l[i]==r[i]){
			if(!x){ x=i; continue;}
			if((d[x]^d[i])!=((l[x]&1)^(l[i]&1))) GG();
		  }
	sol(1,0);
	printf("Yes\n");
	for(i=1;i<=n;i++)
		printf("%d\n",l[i]);
	return 0;
}


Measured memory_bytes: 13824
#include<cstdio>
#include<cstring>
#include<cmath>
#include <cstdlib>
#include<algorithm>

#define eps 1e-8
using namespace std;
const int N = 1000010;

struct Point {
    double x, y;

    Point() {
    }

    Point(double xx, double yy) {
        x = xx;
        y = yy;
    }
} p[N];

Point O;
double R;

double sqr(double x) {
    return x * x;
}

double dist(Point a, Point b) {
    return sqrt(sqr(a.x - b.x) + sqr((a.y - b.y)));
}

Point cnt(Point a, Point b) {
    return Point((a.x + b.x) / 2, (a.y + b.y) / 2.0);
}

Point cnt(Point a, Point b, Point c) {   //求三角形abc外心
    double x1 = a.x, y1 = a.y;
    double x2 = b.x, y2 = b.y;
    double x3 = c.x, y3 = c.y;

    double a1 = 2 * (x2 - x1);
    double b1 = 2 * (y2 - y1);
    double c1 = x2 * x2 + y2 * y2 - x1 * x1 - y1 * y1;

    double a2 = 2 * (x3 - x2);
    double b2 = 2 * (y3 - y2);
    double c2 = x3 * x3 + y3 * y3 - x2 * x2 - y2 * y2;

    double x = (c1 * b2 - c2 * b1) / (a1 * b2 - a2 * b1);
    double y = (a1 * c2 - a2 * c1) / (a1 * b2 - a2 * b1);

    return Point(x, y);
}

int n;

void work() { //求最小圆
    random_shuffle(p + 1, p + n + 1);
    O = p[1];
    R = 0;
    int i, j, k;
    for (i = 2; i <= n; i++) {
        if (dist(O, p[i]) < R + eps) continue;
        O = p[i];
        R = 0;
        for (j = 1; j < i; j++) {
            if (dist(O, p[j]) < R + eps) continue;
            O = cnt(p[i], p[j]);
            R = dist(O, p[i]);
            for (k = 1; k < j; k++) {
                if (dist(O, p[k]) < R + eps) continue;
                O = cnt(p[i], p[j], p[k]);
                R = dist(O, p[i]);
            }
        }
    }
    printf("%.16f\n", R);
}


int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%lf%lf", &p[i].x, &p[i].y);
    work();
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()

class UF {
 private:
  vi parent_, vrank_;
  vl setcnt_;

 public:
  UF(int N) : parent_(N), vrank_(N, 0), setcnt_(N, 1) {
    for (int i = 0; i < N; ++i) {
      parent_[i] = i;
    }
  }

  int find(int x) {
    if (parent_[x] == x) {
      return x;
    } else {
      return parent_[x] = find(parent_[x]);
    }
  }

  int setcnt(int x) { return setcnt_[find(x)]; }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    ll cnt = setcnt_[x] + setcnt_[y];
    // cout << "+" << cnt << endl;
    if (vrank_[x] < vrank_[y]) {
      parent_[x] = y;
      setcnt_[y] = cnt;
    } else {
      parent_[y] = x;
      setcnt_[x] = cnt;
      if (vrank_[x] == vrank_[y]) vrank_[x]++;
    }
  }

  bool same(int x, int y) { return find(x) == find(y); }
};

int main() {
  ll N, M;
  cin >> N >> M;
  vl ans(M);
  UF uf(N);
  ll total = N * (N - 1) / 2;
  vector<pii> bridges;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    bridges.push_back({a - 1, b - 1});
  }
  reverse(ALL(bridges));
  rep(i, M) {
    int a = bridges[i].first;
    int b = bridges[i].second;
    ans[M - 1 - i] = total;
    if (!uf.same(a, b)) {
      ll x = uf.setcnt(a);
      ll y = uf.setcnt(b);
      total -= x * y;
      uf.unite(a, b);
    }
  }
  rep(i, M) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int x, y;
    cin >> x >> y;
    cout << max({x + y, x - y, x * y}) << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  auto itr = A.begin();
  for(int n=0; n<N; n++){
    cin >> A.at(n);
  }
  vector<int> A_cpy(N);
  copy(A.begin(),A.end(),A_cpy.begin());
  sort(A_cpy.begin(),A_cpy.end());
  int max=A_cpy.at(N-1);
  int sec=A_cpy.at(N-2);
  for(int i=0; i<N; i++){
	if(A.at(i)==max){
      cout << sec << endl;
    }else{
      cout << max << endl;
    }
  }
  
}


Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int64_t N;
  cin >> N;
  
  int64_t tmp = N;
  for (int64_t A = 1; A * A <= N; ++A) {
    if (N % A != 0) continue;
    int64_t B = N / A;
    tmp = min(tmp, max(A, B));
  }
  int result = 0;
  while (tmp) {
    ++result;
    tmp /= 10;
  }
  cout << result << endl;
  return 0;
}


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

using ll = long long;
using pii = pair<int, int>;

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);

    int k, n;
    cin >> k >> n;
    vt<int> a(n);
    for (int &i : a) cin >> i;

    int mn = a.back() - a[0];
    for (int i = 1; i < n; i++) {
        mn = min(mn, a[i] + k - a[i + 1]);
    }
    cout << mn;
}


Measured memory_bytes: 3972
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long ll;
const int N=1e5+5;
ll m[N],s[N];
int main(){
   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
   cin>>n>>k;
   for(int i=0;i<n;i++){
    cin>>m[i];
   }

  ll ans=((n-1)/(k-1));
  if((n-1)%(k-1)!=0)ans++;
cout<<ans;




    return 0;
}


Measured memory_bytes: 4360
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  vector<string> ki(2);
  ki[0] = "+";
  ki[1] = "-";
  int s;
  cin >> s;
  int D = s % 10;
  s /= 10;
  int C = s % 10;
  s /= 10;
  int B = s % 10;
  s /= 10;
  int A = s % 10;
  REP(i, 2) {
    REP(j, 2) {
      REP(k, 2) {
        int a = A;
        if(i == 0) {
          a += B;
        } else {
          a -= B;
        }
        if(j == 0) {
          a += C;
        } else {
          a -= C;
        }
        if(k == 0) {
          a += D;
        } else {
          a -= D;
        }
        if(a == 7) {
          cout << A << ki[i] << B << ki[j] << C << ki[k] << D << "=7" << endl;
          return 0;
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256