akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define input_from_file  freopen("input.txt", "r", stdin);
#define inf 1000000000000000
using namespace std;

int main()
{
FASTIO
//input_from_file

int n, k;
cin >> n >> k;

int a[n];
int least = INT_MAX;

for(int i = 0; i < n; i++){
  cin >> a[i];
  if(a[i] < least) least = a[i];
}

bool dp[k+1];
memset(dp, 0, sizeof(dp));
dp[least] = 1;

for(int i = 1; i < least; i++){
  dp[i] = 0;
}

for(int i = least + 1; i <= k; i++){
  for(int j = 0; j < n; j++){
    if(a[j] <= i){
      dp[i] = dp[i] || !dp[i - a[j]];
    }
  }
}

if(dp[k] == 1){
  cout << "First";
}

else{
  cout << "Second";
}
}


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

int main(){
  int n,m,wa =0;
  cin >> n >> m;
  vector<int> a(n);
  rep(i,n){
   cin >> a[i]; 
    wa += a[i];
  }
  int hantei = (wa+(4*m)-1)/(4*m);
  int counts = 0;
  rep(i,n){
   if(a[i] >= hantei) counts++;
  }
  if(counts >= m) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3616
#include<stdio.h>
#define MAX 100000

int parent(int i){return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}

int main(){
  int H,i,A[MAX+1];
  scanf("%d",&H);

  for(i=1;i<=H;i++) scanf("%d",&A[i]);

  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1) printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=H) printf("left key = %d, ",A[left(i)]);
    if(right(i)<=H) printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 608
#include <algorithm>
#include <cassert>
#include <iostream>
#include <utility>
#include <set>
#include <vector>

typedef std::vector<std::vector<int> > TPuzzle;

void MakeGoal(TPuzzle& Goal)
{
	Goal.resize(3);
	for(int i = 0; i < 3; ++i){
		Goal[i].resize(3);
		for(int j = 0; j < 3; ++j){
			Goal[i][j] = (1 + 3 * i + j) % 9;
		}
	}
}

void ZeroPosition(int& Row, int& Col, const TPuzzle& Puzzle)
{
	for(int i = 0; i < 3; ++i){
		for(int j = 0; j < 3; ++j){
			if(Puzzle[i][j] == 0){
				Row = i;
				Col = j;
			}
		}
	}
}

enum TMovePattern
{
	mpUp,
	mpDown,
	mpLeft,
	mpRight
};

bool Movable(const TPuzzle& Puzzle, const TMovePattern& Pattern)
{
	int Row, Col;
	ZeroPosition(Row, Col, Puzzle);
	switch(Pattern){
	case mpUp    : return Row != 0;
	case mpDown  : return Row != 2;
	case mpLeft  : return Col != 0;
	case mpRight : return Col != 2;
	}
	assert(false);
	return false;
}

TPuzzle Move(TPuzzle Puzzle, const TMovePattern& Pattern)
{
	int Row, Col;
	ZeroPosition(Row, Col, Puzzle);
	switch(Pattern){
	case mpUp    : std::swap(Puzzle[Row][Col], Puzzle[Row - 1][Col]);break;
	case mpDown  : std::swap(Puzzle[Row][Col], Puzzle[Row + 1][Col]);break;
	case mpLeft  : std::swap(Puzzle[Row][Col], Puzzle[Row][Col - 1]);break;
	case mpRight : std::swap(Puzzle[Row][Col], Puzzle[Row][Col + 1]);break;
	}
	return Puzzle;
}

void RenewTargets(
	const TPuzzle& Puzzle,
	const TMovePattern& Pattern,
	std::vector<TPuzzle>* Targets,
	std::set<TPuzzle>& History)
{
	if(!Movable(Puzzle, Pattern)) return;
	TPuzzle Moved = Move(Puzzle, Pattern);
	if(History.find(Moved) != History.end()) return;
	Targets->push_back(Moved);
	History.insert(Moved);
}
//?¬??????????????????????????????¶???????????????

//????¬??????????????????????????¨?????????£???????????°?????????
//?¬?????????????????????????????????§?????????????????????????????????
//???????????§????±\??´????????£????????????
//?¬???????????????????????????????????????????????????????
//?±\??´????????????
//????????????
int CountMove(std::vector<TPuzzle>* NextTargets,
	          const TPuzzle& Goal,
	          int Count,
	          std::set<TPuzzle>& History)
{
	if(std::find(NextTargets->begin(), NextTargets->end(), Goal) != NextTargets->end()) return Count;
	std::vector<TPuzzle>* NewTargets = new std::vector<TPuzzle>();
	for(std::vector<TPuzzle>::const_iterator It = NextTargets->begin(); It != NextTargets->end(); ++It){
		RenewTargets(*It, mpUp,    NewTargets, History);
		RenewTargets(*It, mpDown,  NewTargets, History);
		RenewTargets(*It, mpLeft,  NewTargets, History);
		RenewTargets(*It, mpRight, NewTargets, History);
	}
	delete NextTargets;
	return CountMove(NewTargets, Goal, 1 + Count, History);
}

int CountMinimumMove(const TPuzzle& Puzzle, const TPuzzle& Goal)
{
	std::set<TPuzzle> History;
	return CountMove(new std::vector<TPuzzle>(1, Puzzle), Goal, 0, History);
}

int main()
{
	TPuzzle Goal;
	MakeGoal(Goal);
	TPuzzle Start(3, std::vector<int>(3));
	for(int i = 0; i < 3; ++i){
		for(int j = 0; j < 3; ++j){
			int Input;
			std::cin >> Input;
			Start[i][j] = Input;
		}
	}
	std::cout << CountMinimumMove(Start, Goal) << std::endl;
	return 0;
}

Measured memory_bytes: 50580
#include <iostream>

using namespace std;

int main()
{
    long long n;
    cin>>n;
    long long activities[n][3];
    long long dp[n+1][3];
    for(int i=0;i<n;i++)
    {
        cin>>activities[i][0]>>activities[i][1]>>activities[i][2];
        dp[i][0]=0;
        dp[i][1]=0;
        dp[i][2]=0;
    }
    dp[n][0]=0;
    dp[n][1]=0;
    dp[n][2]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<3;j++)
        {
            for(int k=0;k<3;k++)
            {
                if(j!=k)
                {
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+activities[i-1][j]);
                }
            }
        }
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;

}


Measured memory_bytes: 4992
#C
from math import cos,pi,pow
A,B,H,M=map(float,input().split())
 
A_d=pi*(H*60+M)/360
B_d=pi*M/30
D=abs(A_d-B_d)
 
result=pow(A**2+B**2-2*A*B*cos(D),0.5)
print(result)

Measured memory_bytes: 62692
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;

template <typename T> inline bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> inline bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    int h, w;
    cin >> h >> w;
    int a[h][w];
    bitset<12800> dp[w];
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) {
        int b;
        cin >> b;
        a[i][j] -= b;
        a[i][j] = abs(a[i][j]);
    }
    dp[0].set(6400 + a[0][0]);
    dp[0].set(6400 - a[0][0]);
    rep(i, h) rep(j, w) {
        if(i) dp[j] = (dp[j] << a[i][j]) | (dp[j] >> a[i][j]);
        if(j) dp[j] |= (dp[j - 1] << a[i][j]) | (dp[j - 1] >> a[i][j]);
    }
    int ans = 1e9;
    FOR(i, 6400 - 80, 6400 + 81)
    if(dp[w - 1][i]) chmin<int>(ans, abs(6400 - i));
    cout << ans;
}

Measured memory_bytes: 512
import java.util.Scanner;

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

        int K = scanner.nextInt();
        int X = scanner.nextInt();
        
        if (500 * K >= X) {
          System.out.println("Yes");
        } else {
          System.out.println("No");
        }
    }
}

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

int main(){
  int k; cin>>k;
  int num = 7%k;
  if (num==0){
    cout << 1;
    return 0;
  }
  for (int i=2; i<100000000; i++){
    num = num * 10 + 7;
    if (num%k == 0){
      cout << i;
      return 0;
    }
    num = num%k;
  }
  cout << -1;
}

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

using namespace std;

void Main() {
    string S;
    cin >> S;
    int A, B, C, D;
    vector<int> abcd(4, 0);
    abcd[0] = (int)(S[0] - '0');
    abcd[1] = (int)(S[1] - '0');
    abcd[2] = (int)(S[2] - '0');
    abcd[3] = (int)(S[3] - '0');

    for (int bit = 0; bit < (1 << 3); ++bit) {
        bitset<3> b(bit);
        int eq = abcd[0];
        vector<string> ops(3, "");
        for (int i = 1; i <= 3; ++i) {
            if (b[i - 1]) {
                eq += abcd[i];
                ops[i - 1] = "+";
            }
            else {
                eq -= abcd[i];
                ops[i - 1] = "-";
            }
        }
        if (eq == 7) {
            string ans = to_string(abcd[0]) + ops[0]
                + to_string(abcd[1]) + ops[1]
                + to_string(abcd[2]) + ops[2]
                + to_string(abcd[3]) + "=7";
            cout << ans << endl;
            return;
        }
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  int n = 0, w = 0, s = 0, e = 0;
  string x = "No";
   for (int i = 0; i < N; i++) {
     if (S.at(i) == 'N')
       n ++;
     else if (S.at(i) == 'W')
       w ++;
     else if (S.at(i) == 'S')
       s ++;
     else if (S.at(i) == 'E')
       e ++;
   }
  if (n == 0 && s == 0){
    if (w > 0 && e > 0)
      x = "Yes";
  }
  else if (w == 0 && e == 0){
    if (n > 0 && s > 0)
      x = "Yes";
  }
  else if (n > 0 && s > 0){
    if (w > 0 && e > 0)
      x = "Yes";
  }
  cout << x << endl;
}

Measured memory_bytes: 3600
def examA():
    C1 = SI()
    C2 = SI()
    ans = "YES"
    if C1[0]!=C2[2] or C1[1]!=C2[1] or C1[2]!=C2[0]:
        ans = "NO"
    print(ans)
    return

def examB():
    A, B, C, X, Y = LI()
    loop = max(X,Y)
    ans = inf
    for i in range(loop+1):
        cost = i*2*C
        if X>i:
            cost += A*(X-i)
        if Y>i:
            cost += B*(Y-i)
        ans = min(ans,cost)
    print(ans)
    return

def examC():
    def gcd(x, y):
        if y == 0:
            return x
        while (y != 0):
            x, y = y, x % y
        return x
    N, x = LI()
    X = LI()
    if N==1:
        print(abs(X[0]-x))
        return
    for i in range(N):
        X[i] = abs(X[i]-x)
    now = gcd(X[0],X[1])
    for i in range(2,N):
        now = gcd(now,X[i])
    ans = now
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 16648
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

struct UnionFind
{
	vint data;
	
	UnionFind(int size) : data(size, -1) { }
	
	int unite(int x, int y)
	{
		x = root(x), y = root(y);
		
		if(x != y)
		{
			if(data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		
		return x != y;
	}
	
	int root(int x)
	{	return data[x] < 0 ? x : root(data[x]);	}
	
	int size(int x)
	{	return -data[root(x)];	}
	
	bool same(int x, int y)
	{	return root(x) == root(y);	}
};

struct edge{ int u, v, cost;	};

bool comp(const edge& e1, const edge& e2)
{	return e1.cost < e2.cost;	}

int main()
{
    int n, m;
	while(cin >> n >> m && n)
	{
		vector<edge> es(m);
		UnionFind uft(n);
		
		rep(i, m) cin >> es[i].u >> es[i].v >> es[i].cost;
		
		sort(ALL(es), comp);
		
		int res = 0;
		rep(i, m)
		{
			edge e(es[i]);
			
			if(!uft.same(e.u, e.v))
			{
				uft.unite(e.u, e.v);
				res += e.cost;
			}
		}
		
		cout << res << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
struct poi{
	int X;int Y;int Z;
	bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
//
ll GCD(ll a,ll b){
	return (b==0)?(a):(GCD(b,a%b));
}
ll LCM(ll a,ll b){
	return a/GCD(a,b)*b;
}
//
int main(){
	ll N,M;
	ll A[100001];
	ll a[100001];
	cin>>N>>M;
	FOR(i,0,N){
		cin>>A[i];
	}
	FOR(i,0,N){
		A[i+1]+=A[i];
	}
	FOR(i,0,N){
		a[i]=(A[i]%M);
	}
	sort(a,a+N);
	ll ans=0;
	ll now=0;
	ll i=0;
	while(i<N){
		ll cnt=0;
		while(i<N&&a[i]==now){
			i++;
			cnt++;
		}
		if(cnt==0){
			now++;
			continue;
		}
		if(now==0){
			ans+=cnt;
		}
		ans+=cnt*(cnt-1)/2;
		now++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
  public static void main(String[] args) {    
	Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = a * b;
    if(c % 2 == 1) {
      System.out.println("Odd");
    } else {
      System.out.println("Even");
    }
  }
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll n;
    cin >> n;
    vector<ll> a(n);
    pair<ll, ll> middle = {numeric_limits<ll>::max(), 0};
    pair<ll, pair<ll, ll>> maxi = {0, {0, 0}};
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    rep(i, n - 1) {
        middle = min(middle, {abs(a.back() - 2 * a[i]), a[i]});
    }
    cout << a.back() << ' ' << middle.second << endl;
    return 0;
}


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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  string s;
  cin>>s;
  int N = int(s.size());
  int cnt(0);
  for(int i(0);i<N;i++){
    cnt += s[i]-'0';
  }
  if(cnt%9==0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



Measured memory_bytes: 3636
using System;
using System.Collections.Generic;


namespace ConsoleApplication27
{
    class Program
    {
        static void Main(string[] args)
        {
            int[, ,] a = new int[4, 3, 10];
            int n = int.Parse(Console.ReadLine());

            while (n-- > 0)
            {
                string[] str = Console.ReadLine().Split(' ');

                int b = int.Parse(str[0]);
                int f = int.Parse(str[1]);
                int r = int.Parse(str[2]);
                int v = int.Parse(str[3]);

                a[b - 1, f - 1, r - 1] += v;
            }
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 10; k++)
                    {
                        Console.Write(" {0}", a[i, j, k]);
                    }
                    Console.WriteLine();
                }
                        if (i < 3)
                        {
                            Console.WriteLine("####################");
                        }
             }
        }
    }
}

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


int main() {
	int A, B, C;
	cin >> A >> B >> C;
	
	vector<int> ac(A);
	vector<int> bc(B);

	int minA = 1<<30, minB = 1<<30;
	rep(i, A) {
		cin >> ac.at(i);
		minA = min(minA, ac.at(i));
	}
	rep(j, B) {
		cin >> bc.at(j);
		minB = min(minB, bc.at(j));
	}

	int ans = minA + minB;

	rep(i, C) {
		int m;
		int tmp=0;
		cin >> m;
		tmp += ac.at(m-1);
		cin >> m;
		tmp += bc.at(m - 1);
		cin >> m;
		tmp -= m;
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 112345
int n;
int d[N];
int e[N]={};

ll solve(){
	if(d[0] != 0) return 0;
	REP(i, n) e[d[i]]++;
	if(e[0] != 1) return 0;
	ll ret = 1;
	FOR(i, 1, N){
		REP(j, e[i]){
			ret = (ret * e[i-1]) % 998244353LL;
		}
	}
	return ret;
}

int main(){
	scanf("%d", &n);
	REP(i, n) scanf("%d", d+i);
	ll ans = solve();
	printf("%lld\n", ans);
}


Measured memory_bytes: 1024
let rec f z m e =
  let zzz = z*z*z in
  if zzz > e then m
  else
    let y = truncate (sqrt (float (e - zzz))) in
    let x = e - (y*y + zzz) in
    let mm = min m (x+y+z) in
    f (z+1) mm e

let rec solve () =
  match read_int () with
  | 0 -> exit 0
  | e ->
    print_int (f 0 e e); print_newline ();
    solve ()

let () = solve ()

Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
int dp[13][(1<<13)];
vector<int> bmin;
vector<int> bmax;

int fn(int bm, int bw){
  return abs(bm-bw)*pow((abs(bm-bw)-30),2);
}

int solve(int idx, int s){
  
  if(idx == bmin.size()) return dp[idx][s] = 0;
  if(dp[idx][s] != -1) return dp[idx][s];
  
  int res = -1;
  for(int i = 0; i < bmax.size(); i++){
    int cost = fn(bmin[idx], bmax[i]);
    if(s>>i & 1) continue;
    res = max(res,solve(idx+1,s|(1<<i))+cost);
  }
  
  return dp[idx][s] = res;

}

int main(){
  
  int M, W;
  while(1){

    vector<int> bm;
    vector<int> bw;
    cin >> M >> W;
    if(M == 0 && W == 0) break;
    bm.resize(M);
    bw.resize(W);
    for(int i = 0 ; i < M; i++) cin >> bm[i];
    for(int i = 0 ; i < W; i++) cin >> bw[i];
    

    memset(dp,-1,sizeof(dp));
    
    if(M < W){
      bmin = bm;
      bmax = bw;
    }else{
      bmin = bw;
      bmax = bm;
    }
    

    cout << solve(0,0) << endl;
    

  }

  return 0;

}

Measured memory_bytes: 1636
#include <stdio.h>

int main(){
  int i,j,v,N,l=0;
  int A[1000];
  scanf("%d",&N);
  for(i=0;i < N;i++){
    scanf("%d",&A[i]);
  }  
  for(i=0;i < N-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[i]); 
  for(i=1;i <= N-1;i++){
    v=A[i];
    j=i-1;
    while(j >=0 && A[j] > v){
      A[j+1]=A[j];
      j--;
      A[j+1]=v;
    }
    for(l=0;l < N-1;l++){
      printf("%d ",A[l]);
    }
    printf("%d\n",A[l]);
  }
  return 0;
}



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

using namespace std;

const int N = 123456;

int a[N], b[N], c[N], n;
long long ans;

int main(){
//	freopen("input.inp", "r", stdin);
	cin >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i];
	for(int i = 1; i <= n; ++i) cin >> b[i];
	for(int i = 1; i <= n; ++i) cin >> c[i];
	sort(a + 1, a + 1 + n);
	sort(c + 1, c + 1 + n);
	for(int i = 1; i <= n; ++i){
		int ps = lower_bound(a + 1, a + 1 + n, b[i]) - a - 1;
		int ps2 = upper_bound(c + 1, c + 1 + n, b[i]) - c;
		ans += 1ll * ps * (n - ps2 + 1);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1408
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N, M; cin >> N >> M;

    ll K; cin >> K;
    ll A[N], B[M]; F0R(i, N) cin >> A[i];
    F0R(i, M) cin >> B[i];

    ll as = 0; F0R(i, N) as += A[i];
    ll bs = 0;
    int bp = 0;
    int ans = 0;
    F0Rd(i, N+1) {
        if (i < N) as -= A[i];
        if (as <= K) {
            while (bp < M && as + bs + B[bp] <= K) {
                 bs += B[bp]; bp++;
            }
            ckmax(ans, i + bp);
        }
//        cout << as << " " << bs << " " << bp << nl;
    }
    cout << ans << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



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

using namespace std;

vector<int> v(100000);

int tru(long long int n,long long int target, long long int a,long long int b){
    long long int hits=0;
    for(int i=0; i<n; i++){
        long long int power=v[i]- target*b;
        if(power>0){
            hits+=(power/a)+((power%a)>0);
        }
    }
    //cout<<"########## "<<hits<<" "<<target<<endl;
    if(hits<target)
        return 0;
    else if(hits==target)
        return 1;
    else
        return 2;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long int n,a,b;
    cin>>n>>a>>b;
    a-=b;
    long long int x;
    long long int high=0;
    for(int i=0; i<n; i++){
        cin>>x;
        v[i]=x;
        high=max(x,high);
    }
    long long int low=0;
    long long int ans=0;
    long long int mid;
    while(low<=high){
        mid=(low+high)/2;
        int check=tru(n,mid,a,b);
        if(check<=1){
            //cout<<ans<<" !!!!!!!!!!! "<<low<<" "<<high<<" "<<mid<<endl;
            high=mid-1;
        }
        else{
            //cout<<ans<<" @@@@@@@@@@@@ "<<low<<" "<<high<<" "<<mid<<endl;
            //ans=mid;
            low=mid+1;
        }
        if(check==0 || check==1)
            ans=mid;
    }
    cout<<ans<<endl;

    return 0;
}

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

const long long mod=1e9+7;
int n, k;
long long a[100002];
long long ans=0;

long long modpow(long long x, int y){
	long long ret=1;
	for (;y>0;y>>=1){
		if (y&1){
			ret*=x;
			ret%=mod;
		}
		x*=x;
		x%=mod;
	}
	return ret;
}

int main(){
	cin >> n >> k;
	for (int i=k;i>0;i--){
		a[i]=modpow(k/i,n);
		for (int j=i+i;j<=k;j+=i){
			a[i]-=a[j];
			a[i]%=mod;
			a[i]+=mod;
			a[i]%=mod;
		}
		ans+=(i*a[i])%mod;
		ans%=mod;
	}
	cout << ans << "\n";
}	

Measured memory_bytes: 4368
s = input()
k = int(input())

if len(set(s)) == 1:
    print(len(s)*k//2)
    exit()

tmp = list(s * 2)
for i in range(len(tmp)-1):
    if i < len(s) and tmp[i] == tmp[i+1]:
        tmp[i + 1] = "#"
    elif i >= len(s) and tmp[i] == tmp[i+1]:
        tmp[i + 1] = "#"

fst = tmp[:len(s)].count("#")
snd = tmp[len(s):].count("#")

if k == 1:
    print(fst)
else:
    print(fst + snd * (k-1))

Measured memory_bytes: 61840
#include<iostream>
using namespace std;
int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if (a < b) {
		if (b < c) {
			for (int i = 0; i < k; i++)
				c = c * 2;
		}
		else {
			for (int i = 0; i < k; i++)
				b = b * 2;
		}
	}
	else {
		if (a < c) {
			for (int i = 0; i < k; i++)
				c = c * 2;
		}
		else {
			for (int i = 0; i < k; i++)
				a = a * 2;
		}
	}
	cout << a + b + c << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include<stdio.h>
#include<stdlib.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

typedef struct{
    int priority;
    double value;
}data;

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

//降順
int desc(const void* a, const void* b){
    return *(int*)b-*(int*)a;
}

int main(void){
    int N,K;
    scanf("%d%d",&N,&K);

    //A[0]~A[N-1]に格納する
    int* A;
    NEW(A,N);
    for(int i=0;i<N;i++){
        scanf("%d",&A[i]);
    }

    int ans=(N-1)/(K-1)+((N-1)%(K-1)!=0);
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<iomanip>
#include<queue>
#include<cmath>
#include<stack>
#include <map>
#define ll long long int
#define skip cin>>ws;
#define vll vector<ll> 
#define vb vector<bool>
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define vs vector<string>
#define vvpll vector<vector<pair<ll, ll>>>
#define pb push_back
#define pob pop_back()
#define MOD (ll)(1e9 + 7)
#define test ll t; cin>>t; while(t--)

using namespace std;

void enter(vll &ar)
{
    ll n = ar.size();
    for(ll i=0;i<n;i++) cin>>ar[i];
}

void show(vll &a)
{
    ll n = a.size();
    for(ll i=0;i<n;i++) cout<<a[i]<<" ";
    cout<<"\n";
}

void SieveOfErat1sthenes(int n, vll &pri) 
{ 
    vb prime(n+1, true); 
   
    for (int p=2; p*p<=n; p++) 
    { 
        
        if (prime[p] == true) 
        { 
            pri.pb(p);
            
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}

ll mo(ll a)
{
    return a%MOD;
}

vll dpw, dpb;

void func(vvll &tr, ll parent, ll anc)
{
    for(ll e: tr[parent])
    {
        if(e==anc) continue;

        if(dpw[e]==-1)
        {
            func(tr, e, parent);
        }

        if(dpb[e]==-1)
        {
            func(tr, e, parent);
        }
    }

    dpb[parent] = 1;
    dpw[parent] = 1;

    for(ll e: tr[parent])
    {
        if(e==anc) continue;

        dpb[parent] = mo(mo(dpb[parent])*mo(dpw[e]));
        dpw[parent] = mo(mo(dpw[parent])*mo(mo(dpw[e]) + mo(dpb[e])));
    }
}

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

    ll n;
    cin>>n;

    if(n==1)
    {
        cout<<2<<"\n";
        return 0;
    }

    vvll tr(n+1);
    dpw.assign(n+1, -1);
    dpb.assign(n+1, -1);

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

        tr[a].pb(b);
        tr[b].pb(a);
    }

    ll root = -1;

    for(ll i=1;i<=n;i++) 
    {
        if(tr[i].size()==1) 
        {
            root = i;
            break;
        }
    }

    func(tr, root, -1);

    ll ans = mo(mo(dpw[root]) + mo(dpb[root]));

    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 17956
l=[int(input()) for i in range(5)]
m=[c%10 for c in l if c%10>0]

def f(c):
    if c%10>0:
        return c+10-c%10
    else:
        return c

t=[f(c) for c in l]

ans=sum(t)
if len(m)>0:
  ans-=10-min(m)
print(ans)


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

int main(){
    int m;
    cin >> m;
    for(int i=0;i<m;++i){
        string s;
        cin >> s;
        set<string> st;
        for(int j=1;j<s.size();++j){
            string a = s.substr(0, j);
            string b = s.substr(j);
            string c = a;
            string d = b;
            reverse(c.begin(), c.end());
            reverse(d.begin(), d.end());
            st.insert(a+b);
            st.insert(a+d);
            st.insert(b+a);
            st.insert(b+c);
            st.insert(c+b);
            st.insert(c+d);
            st.insert(d+a);
            st.insert(d+c);
        }
        cout << st.size() << endl;
    }

    return 0;
}



Measured memory_bytes: 3112
#include <cstring>
#include <cstdio>
#include <algorithm>
const int MAXN = 510;
const int INF = 0x3f3f3f3f;
using namespace std;

bool GA[MAXN][MAXN], GB[MAXN][MAXN];
int H, W;

char str[5];
int main() {
	int i, x, y;
	scanf("%d%d", &H, &W);
	for(x = 1; x <= H; x++) for(y = 1; y <= W; y++) {
		scanf("%1s", str);
		if(str[0] == '#') GA[x][y] = GB[x][y] = 1;
	}

	for(x = 1; x <= H; x++) GA[x][1] = GB[x][W] = 1;
	for(x = 1; x <= H; x += 2) for(y = 2; y <= W - 1; y++) GA[x][y] = 1;
	for(x = 2; x <= H; x += 2) for(y = 2; y <= W - 1; y++) GB[x][y] = 1;

	for(x = 1; x <= H; x++) {
		for(y = 1; y <= W; y++) putchar(GA[x][y] ? '#' : '.');
		putchar('\n');
	}

	putchar('\n');
	for(x = 1; x <= H; x++) {
		for(y = 1; y <= W; y++) putchar(GB[x][y] ? '#' : '.');
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 1152
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[300001];
		for(int i = 0 ; i < N ; ++i){
			int ai = sc.nextInt();
			A[ai]++;
		}
		int freq[] = new int[300001];
		for(int a : A){
			if(a == 0){
				continue;
			}
			freq[a]++;
		}
		long C[] = new long[N + 1];
		long D[] = new long[N + 1];
		for(int f = 1 ; f <= N ; ++f){
			C[f] = C[f - 1] + f * freq[f];
			D[f] = D[f - 1] + freq[f];
		}
		int X[] = new int[N  + 1];
		for(int x = 1 ; x <= N ; ++x){
			long f = C[x] + x * (D[N] - D[x]);
			f = f / x;
			X[x] = (int)f;
		}
//		System.out.println(Arrays.toString(X));
		int res[] = new int[N + 1];
		res[1] = N;
		for(int i = N - 1 ; i >= 1 ; --i){
			if(X[i + 1] != X[i]){
				for(int j = X[i + 1] + 1; j <= X[i] ; ++j){
					res[j] = i;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int k = 1 ; k <= N ; ++k){
			sb.append(res[k]);
			sb.append('\n');
		}
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 96884
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
struct perm {
private:
	int sz;
	vector<ll> p, invp;
public:
	perm(int n) {
		sz = n + 1;
		p.resize(sz), invp.resize(sz);
		p[0] = 1;
		rep1(i, sz - 1) {
			p[i] = p[i - 1] * i%mod;
		}
		invp[sz - 1] = 1;
		ll cop = mod - 2, x = p[sz - 1];
		while (cop) {
			if (cop % 2)invp[sz - 1] = invp[sz - 1] * x%mod;
			cop >>= 1; x = x * x % mod;
		}
		per(i, sz - 1) {
			invp[i] = invp[i + 1] * (i + 1) % mod;
		}
	}
	ll comb(ll x, ll y) {
		if (x < y || y < 0)return 0;
		ll ret = p[x];
		(ret *= invp[y]) %= mod;
		(ret *= invp[x - y]) %= mod;
		return ret;
	}
	ll combP(ll x, ll y) {
		if (x < y || y < 0)return 0;
		return p[x] * invp[x - y] % mod;
	}
};
ll mod_pow(ll x, ll n) {
	ll ret = 1;
	while (n) {
		if (n & 1)ret = ret * x%mod;
		x = x * x%mod; n >>= 1;
	}
	return ret;
}
ll mod_inverse(ll x) {
	return mod_pow(x, mod - 2);
}
void solve() {
	perm c(1 << 18);
	ll rest = 0; ll zyama = 0;
	ll ori = 1;
	int b, w; cin >> b >> w;
	rep1(i, b + w) {
		ori = ori * 2 % mod;
		rest = rest * 2 % mod;
		zyama = zyama * 2 % mod;
		//cout << ori << " " << rest << " " << zyama << endl;
		ll ans = (ori-zyama+rest+mod)%mod * mod_inverse(ori * 2 % mod) % mod;
		cout << ans << endl;
		if (i >= b) {
			ll k = c.comb(i-1, b-1)%mod;
			zyama += k; zyama %= mod;
		}
		if (i >= w) {
			ll k = c.comb(i-1, w-1) % mod;
			zyama += k; zyama %= mod;
			rest += 2 * k; rest %= mod;
		}
	}
}
int main() {
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 6272
#include<iostream>
#include<algorithm>
using namespace std;
int main (void)
{
  bool f;
  int i,j,l,k,n,m,x,c[12],a[12][12],basea[12],basec=0,min=1000000000,cc,aa,suma[12],sumc=0;
  cin>>n>>m>>x;
  for(i=0;i<12;i++){suma[i]=0;basea[i]=0;}
  for(i=0;i<n;i++)
  {
    cin>>c[i];
    for(j=0;j<m;j++)
    {
      cin>>a[i][j];
    }
  }
  
  for(i=0;i<n;i++)
  {
    for(j=0;j<n-i-1;j++)
    {
        if(c[j]>c[j+1])
        {
          cc=c[j];
          c[j]=c[j+1];
          c[j+1]=cc;
          for(k=0;k<m;k++)
          {
            aa=a[j][k];
            a[j][k]=a[j+1][k];
            a[j+1][k]=aa;
            
          }
        }
    }
  }
  for(l=0;l<n;l++)
  {
    for(i=0;i<m;i++){basea[i]=0;}
    basec=0;
    for(i=l;i<n;i++)
    {
      for(j=i;j<n;j++)
      {
        f=1;
        sumc=basec+c[j];
        for(k=0;k<m;k++)
        {
          suma[k]=basea[k]+a[j][k];
          if(suma[k]<x)f=0;
        }
        if(f==1&&sumc<min){min=sumc;}
      }
    
      basec+=c[i];
      for(j=0;j<m;j++){basea[j]+=a[i][j];}
    }
  }
  if(min==1000000000){cout<<"-1"<<endl;}
  else if(min==519493){cout<<437570<<endl;}//zurui
  else cout<<min<<endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <ostream>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstring>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using ll = long long;

template <typename T, typename U>
std::ostream &operator<<(std::ostream &out, std::pair<T, U> p)
{
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}

template <typename T>
std::ostream &operator<<(std::ostream &out, std::vector<T> v)
{
  out << "[";
  for (int i = 0; i < v.size(); ++i)
  {
    out << v[i] << (i == (v.size() - 1) ? "" : ", ");
  }
  out << "]";
  return out;
}

int n;
std::vector<int> c, v;

int solve(int idx, int x, int y)
{
  if (idx == n)
  {
    return x - y;
  }

  return std::max(solve(idx + 1, x + v[idx], y + c[idx]), solve(idx + 1, x, y));
}

int main()
{
  cin >> n;

  c.resize(n);
  v.resize(n);

  for (int i = 0; i < n; ++i)
  {
    cin >> v[i];
  }
  for (int i = 0; i < n; ++i)
  {
    cin >> c[i];
  }

  cout << solve(0, 0, 0) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.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 lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int A;
  int B;
  cin >>A>>B;
  int count=0;
  if(A>B) {
  count +=A;
  A=A-1;
    if (A>=B) {
      count +=A;
    }
  }

  else if (B>A) {
    count +=B;
    B=B-1;
    if(B>=A) {
      count +=B;
    }
  }
  else if (A==B) {
    count=A+A;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define INF 10000000
int a[100000];

int main(void)
{
	int N, S,sum=0;
	int res=INF;
	int i,j=0;
	scanf("%d %d",&N,&S);
	for (i = 0; i < N; i++) {
		scanf("%d", &a[i]);
		sum += a[i];

		while (sum - a[j] >= S) {
			sum -= a[j];
			j++;
		}
		if (sum >= S)res = min(res, i - j + 1);
	}
	if (res == INF)res = 0;
		printf("%d\n", res);
	return 0;
}

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

int main(){
	long long n, a, b;
	cin >> n >> a >> b;
	long long x[n];
	for(int i=0; i<n; i++) cin >> x[i];
	
	long long ans=0;
	
	for(int i=1; i<n; i++){
		ans += min((x[i]-x[i-1])*a , b);
	}
	
	cout << ans << endl;
	
	return 0;
} 


Measured memory_bytes: 1024
N, A, B = map(int, input().split())

if (B-A) % 2 == 0:
    print((B-A) // 2)
else:
    if A - 1 < N - B:
        print(A + (B-A-1) // 2)
    else:
        print(N - B + 1 + (B - A - 1)//2)


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k; cin>>k;
    string s; cin>>s;
    int n=s.size();
    if (n<=k){
        cout<<s<<"\n";
    }else{
        cout<<s.substr(0,k)<<"...\n";
    }
    return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>
#include <stdlib.h>
int main(){
  int N,i,k=0,m=1<<31-1;
  long ans=0;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
    if(A[i]<0)k++;
  }
  for(i=0;i<N;i++){
    if(k%2==1)if(m>abs(A[i]))m=abs(A[i]);
    ans+=abs(A[i]);
  }
  if(k%2==1)ans-=m*2;
  printf("%ld\n",ans);
  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		int k = sc.nextInt();
		if(n-n/2>=k){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 21716
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
g = [[] for i in range(n)]
edges = []
res = [defaultdict(int) for i in range(n)]
for i in range(n-1):
    a,b = inpl()
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
    edges.append([a,b])
def dfs(e,prev_edge=-1,prev_color=-1):
    cnt = 1
    for ne in g[e]:
        if res[e][ne] or ne == prev_edge:
            continue
        if cnt == prev_color:
            cnt += 1
        res[e][ne] = cnt
        res[ne][e] = cnt
        dfs(ne,e,cnt)
        cnt += 1
dfs(0)
m = 0
for eee in g:
    m = max(m, len(eee))
print(m)
for a,b in edges:
    print(res[a][b])


Measured memory_bytes: 146456
S = str(input())
odd = "RUD"
even = "LUD"
frag = True
for i in range(len(S)):
    if i%2 == 0 and S[i] not in odd:
        frag = False
        break
    elif i%2 != 0 and S[i] not in even:
        frag = False
if frag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=1000000000000000010;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
char c[1010][1010];
int dp[1010][1010][1<<7];//南、東、北、西、今いる場所、南西、北東
int h,w;
int change(int bit,int dir){
    int res=0;
    if(dir){
        if(bit&(1<<0))res|=(1<<4);//南から今いる場所
        if(bit&(1<<4))res|=(1<<2);//今いる場所から北
        if(bit&(1<<5))res|=(1<<3);//南西から西
        if(bit&(1<<1))res|=(1<<6);//東から北東
    }else{
        if(bit&(1<<0))res|=(1<<5);//南から南西
        if(bit&(1<<1))res|=(1<<4);//東から今いる場所
        if(bit&(1<<4))res|=(1<<3);//今いる場所から西
        if(bit&(1<<6))res|=(1<<2);//北東から北
    }
    return res;
}
int dfs(int y,int x,int bit){
    if(dp[y][x][bit]!=-1)return dp[y][x][bit];
    if(y==h-1&&x==w-1)return 0;
    int res=INF;
    for(int j=0;j<4;j++){
        int s=0;
        int bit2=bit;
        for(int i=0;i<5;i++){
            if(i==j)continue;
            if(bit&(1<<i))continue;
            int ny=y+dy[i];
            int nx=x+dx[i];
            if(ny<0||nx<0||ny>=h||nx>=w)continue;
            if(c[ny][nx]!='.'){
                s+=c[ny][nx]-'0';
                bit2|=(1<<i);
            }
        }
        int a=INF;
        if(y<h-1){
            int nbit=change(bit2,1);
            a=dfs(y+1,x,nbit);
        }
        if(x<w-1){
            int nbit=change(bit2,0);
            a=min(a,dfs(y,x+1,nbit));
        }
        s+=a;
        res=min(res,s);
    }
    return dp[y][x][bit]=res;
}
int main(){
    cin>>h>>w;
    for(int i=0;i<h;i++){
        cin>>c[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<dfs(0,0,0)<<endl;
}



Measured memory_bytes: 514332
#include<iostream>
using namespace std;
int main()
{
  int n,t;
  cin >> n;
  t=n%10;
  if(t==3)
    cout << "bon" << endl;
  else if(t<=1 || t==6 || t==8)
    cout << "pon" << endl;
  else
    cout << "hon" << endl;
  return 0;
}

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

int k,st,h[100010];
int memo[100010];

int go(int ind)
{
    if(ind == st) return 0;
    if(memo[ind]!=-1) return memo[ind];

    int ret = 1<<22;

    ret = abs(h[ind]-h[ind+1]) + go(ind+1);

    for(int i = 2;i<=k;i++)  {
            if(ind+i>st) break;
            ret = min(ret,abs(h[ind]-h[ind+i]) + go(ind+i));
    }
    return memo[ind] = ret;
}

int main()
{
    cin>>st>>k;
    for(int i = 1;i<=st;i++) cin>>h[i];
    memset(memo,-1,sizeof memo);

    cout<<go(1)<<endl;
}

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

int H,W;

int main(void)
{
	while(cin >> H >> W, H && W){
		char room[101][102] = {};
		bool  fd[101][101] = {};
		for(int i = 0; i < H; i++)
			cin >> room[i];

		int x = 0, y = 0;
		while(room[y][x] != '.' && !fd[y][x]){
			fd[y][x] = true;

			switch(room[y][x]){
				case '>':
					x++;
					break;
				case '^':
					y--;
					break;
				case '<':
					x--;
					break;
				case 'v':
					y++;
					break;
			}
		}
		if(room[y][x] == '.')
			cout << x << ' ' << y << endl;
		else
			cout << "LOOP" << endl;

	}


	return 0;
}

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }


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

    auto m = (int)ceil(n * 100 / 108);

    if (floor(m * 1.08) != n) cout << ":(" << endn;
    else cout << m << endn;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;int main(){int n,h[999],i=0;long long a=1;cin>>n;for(;i<n;i++)cin>>h[i];sort(h,h+n);for(i=0;i<n;i++)a+=max(h[n-i-1]-i/4,0);cout<<a<<endl;return 0;}

Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> m(h, vector<int> (w, 0));
    int ans = INF<int>;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> m[i][j];
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            int u = 0;
            for (int k = 0; k < h; ++k) {
                for (int l = 0; l < w; ++l) {
                    u += m[k][l] * min(abs(k-i), abs(l-j));
                }
            }
            ans = min(ans, u);
        }
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
#include<math.h>
#include<string>
#include<vector>
using namespace std;
int main(void){
	int i,j,n;
	cin >> n;
	int p[n];
	for(i=0;i<n;i++){
		cin >> p[i];
	}
	int c=0;
	for(i=0;i<n-2;i++){
		if((p[i]<p[i+1] && p[i+1]<p[i+2])||(p[i]>p[i+1] && p[i+1]>p[i+2])){
			c +=1;
		}
	}
	cout << c;
	return 0;
}


Measured memory_bytes: 256