akhauriyash/Code-Regression huggingface dataset:
/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (Windows, macOS, Linux)
 * Author: alireza_kaviani
 * Time: 2020-05-22 11:58:12
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define SZ(x)                       ll(x.size())

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

int r , c , n , mark[MAXN];
vector<int> points , vec;
vector<pii> LX , RX , LY , RY;

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

    cin >> r >> c >> n;
    for(int i = 0 ; i < n ; i++){
        int ax , ay , bx , by;
        cin >> ax >> ay >> bx >> by;
        if(ax != 0 && ax != r && ay != 0 && ay != c)    continue;
        if(bx != 0 && bx != r && by != 0 && by != c)    continue;
        if(ax == 0)         LX.push_back({ay , i});
        else if(ax == r)    RX.push_back({ay , i});
        else if(ay == 0)    LY.push_back({ax , i});
        else if(ay == c)    RY.push_back({ax , i});
        if(bx == 0)         LX.push_back({by , i});
        else if(bx == r)    RX.push_back({by , i});
        else if(by == 0)    LY.push_back({bx , i});
        else if(by == c)    RY.push_back({bx , i});
    }
    sort(all(LX));
    sort(all(RY));
    sort(all(RX) , greater<pii>());
    sort(all(LY) , greater<pii>());
    for(pii i : LX) points.push_back(i.Y);
    for(pll i : RY) points.push_back(i.Y);
    for(pii i : RX) points.push_back(i.Y);
    for(pii i : LY) points.push_back(i.Y);
    
    for(int i : points){
        if(!mark[i])    {mark[i] = 1 ; vec.push_back(i) ; continue;}
        if(vec.back() != i) return cout << "NO" << endl , 0;
        vec.pop_back();
    }
    cout << "YES" << endl;

    return 0;
}
/*

*/


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

typedef long long ll;


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

    for ( int i=1; i<n; i++ )
        if ( a[i] - a[i-1] < 0)
            {
                int diff = a[i-1] - a[i] ;
                a[i] += diff;
                h += diff;
            }

    cout<<h<<endl;
}

Measured memory_bytes: 4404
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define pause system("pause")
#define PI acos(-1.0)


signed main() {
	int K, A, B;
	string frag = "NG";
	cin >> K >> A >> B;
	for(int i=1;K*i<=1000;i++) {
		if (A <= K*i&&K*i <= B) {
			frag = "OK";
		}
	}
	cout << frag << endl;
	pause;
}

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

int main() {
	long long h, w;
	cin >> h >> w;
	long long b_size;
	long long a, b, c;

	long long ans = 1e9;

	//case 1
	for (int a_size = 1; a_size < h; a_size++) {
		a = a_size * w;

		//縦向き
		if ((h - a_size) % 2 == 0) {
			b_size = (h - a_size) / 2;
		}
		else {
			b_size = (h - a_size - 1) / 2;
		}
		b = b_size * w;
		c = h * w - a - b;
		ans = min(ans, max(max(a, b), c) - min(min(a, b), c));

		//横向き
		if (w % 2 == 0) {
			b_size = w / 2;
		}
		else {
			b_size = (w - 1) / 2;
		}
		b = b_size * (h - a_size);
		c = h * w - a - b;
		ans = min(ans, max(max(a, b), c) - min(min(a, b), c));
	}

	//case 2
	for (int a_size = 1; a_size < w; a_size++) {
		a = a_size * h;

		//横向き
		if ((w - a_size) % 2 == 0) {
			b_size = (w - a_size) / 2;
		}
		else {
			b_size = (w - a_size - 1) / 2;
		}
		b = b_size * h;
		c = h * w - a - b;
		ans = min(ans, max(max(a, b), c) - min(min(a, b), c));

		//縦向き
		if (h % 2 == 0) {
			b_size = h / 2;
		}
		else {
			b_size = (h - 1) / 2;
		}
		b = b_size * (w - a_size);
		c = h * w - a - b;
		ans = min(ans, max(max(a, b), c) - min(min(a, b), c));
	}
	cout << ans << endl;

	return 0;
}

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

typedef long long ll;

ll beki(ll a, ll n){
    if(n == 0){
        return 1;
    }
    ll ans = beki(a, n / 2);
    ans = ans * ans;
    if(n % 2 == 1){
        ans = ans * a;
    }
    return ans;
}

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

    ll h; cin >> h;
    ll cnt = 0;
    while(h>0){
        h /= 2;
        cnt++;
    }
    ll ans = 0;
    for(ll i=0;i<cnt;i++){
        ans += beki(2LL,i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from bisect import bisect_right
s = input()
t = input()
n = len(t)
index = [[] for i in range(26)]
for i in range(len(s)):
    j = ord(s[i])-97
    index[j].append(i)
tmp = -1
ans = 0
for i in range(n):
    j = ord(t[i])-97
    if len(index[j])==0:
        print(-1)
        sys.exit()
    k = bisect_right(index[j], tmp)
    if k<len(index[j]):
        tmp = index[j][k]
    else:
        ans+=1
        tmp = index[j][0]
print(ans*len(s)+tmp+1)
        
    

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

int main () {
    int a,b;
    string hugou;
    cin >> a >> b;
    if (a < b) {
        hugou = "<";
    }
    if (a > b) {
        hugou = ">";
    }
    if (a == b) {
        hugou = "==";
    }
    cout << "a" << " " << hugou << " " << "b" << endl;
}


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

int a;
int b;

void input(){
  cin >> a >> b;
}

void solve(){
  input();
  cout << max(0, a-b*2) << endl;
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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







int main(){
    int X; std::cin >> X;
    int ans(1);
    if(X < 1800) ans = 2;
    if(X < 1600) ans = 3;
    if(X < 1400) ans = 4;
    if(X < 1200) ans = 5;
    if(X < 1000) ans = 6;
    if(X < 800) ans = 7;
    if(X < 600) ans = 8;
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;

typedef long long LL;
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n)-1)
#define FOR(i,a,b) for(int (i)=(a); (i)<=(b) ;++(i))
#define PB push_back
#define MP make_pair
#define OUT(a) cout<<(a)<<endl;

int dep[100010],par[100010],n,k,ans;
priority_queue<pair<int,int>> d;
set<int> rem;
vector<set<int>> a(100010);
void dfs(int p){
    if(dep[p]<=k){
        rem.erase(p);
    }
    if(!a[p].empty()){
        for(auto&& x : a[p] ){
            dep[x]=dep[p]+1;
            rem.erase(x);
            if(dep[x]>k){
                d.push(make_pair(dep[x],x));
                rem.insert(x);
            }
            dfs(x);
        }
    }
    return;
}
void connectone(int b){
    a[par[b]].erase(b);
    par[b]=1;
    dep[b]=1;
    dfs(b);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    REP(i,n){
        cin >> par[i+1];
        if(i+1>1){
            a[par[i+1]].insert(i+1);
        }
    }
    dfs(1);

    int ans=0;
    if(par[1]!=1){
        ++ans;
        par[1]=1;
    }
    while(!rem.empty()){
        int top=d.top().second;
        d.pop();
        //OUT(top)
        //OUT(dep[top])
        if(rem.find(top)!=rem.end()){
            REP(i,k-1){
                top=par[top];
            }
            connectone(top);
            //OUT(top)
            ++ans;
        }
    }
    cout << ans <<endl;




    return 0;
}


Measured memory_bytes: 22132
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

ll N;

void solve() {
	cin >> N;
	cout << N * (N - 1) / 2 << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define popb pop_back()
#define sz size()
#define y1 luboi
using namespace std;
typedef long long ll;

int n;
int a[100100];
int cnt;
int main(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        if(i==1){
            if(a[i]==i){
                cnt++;
                swap(a[i],a[i+1]);
            }
        }
        else if(i==n){
            if(a[i]==i){
                cnt++;
                swap(a[i],a[i-1]);
            }
        }
        else{
            if(a[i]==i){
                    swap(a[i],a[i+1]);
                    cnt++;
            }
        }
    }
    cout<<cnt;
}


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

int main()
{
	long long A, B, C, K;
	cin >> A >> B >> C >> K;

	long long ans = min( A, K );
	K -= A;
	if( K >= 0 ) {
		K -= B;
		if( K >= 0 ) ans -= K;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int N=105,V=1005;
int dp[N][N*V+1],w[N],v[N];
int main()
{
    int n,W;
    scanf("%d%d",&n,&W);
    for(int i=0;i<n;i++)	
    	scanf("%d%d",&w[i],&v[i]);
    fill(dp[0],dp[0]+N*V+1,INT_MAX/2);
    dp[0][0]=0;
    for(int i=0;i<n;i++)
    	for(int j=0;j<=N*V;j++)
    		if(j<v[i])
    			dp[i+1][j]=dp[i][j];
    		else
    			dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]);
	int res=0;
	for(int i=0;i<=N*V;i++)
		if(dp[n][i]<=W)
			res=i;
	printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 43392
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
    int w, n, h[31][2], v[31], pos;
    cin >> w >> n;

    for (int i = 0; i < n; i++) {
        scanf("%d, %d", &h[i][0], &h[i][1]);
    }
    for (int i = 1; i <= w; i++) {
        pos = i;
        for (int j = 0; j < n; j++) {
            if (pos == h[j][0]) {
                pos = h[j][1];
            }
            else if (pos == h[j][1]) {
                pos = h[j][0];
            }
        }
        v[pos] = i;
    }
    for (int i = 1; i <= w; i++) {
        cout << v[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1240
#include <iostream>
using namespace std;
int main(){
	int n,a[100000],b[100000],i,j;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];}
		for(i=0;i<n;i++){
		
			
					 b[a[i]-1]=i+1;
					}
					for(i=0;i<n;i++){
						cout<<b[i]<<" ";}
						return 0;}

Measured memory_bytes: 1536
#include <iostream>

int main() {
    int a, b, c;
    std::cin >> a >> b >> c;
    if (a + b == c || b + c == a || c + a == b) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
SP = []
for i in range(N):
    SP.append(input().split())
#番号を入れる
for j in range(N):
    SP[j].append(j+1)

SP.sort(key=lambda x:int(x[1]), reverse=True)
SP.sort(key=lambda x:x[0])
for k in range(N):
    print(SP[k][2])

Measured memory_bytes: 3064
n = int(input())

flag = 0

if n <= 81:
    if n % 9 == 0:
        flag = 1
    if n % 8 == 0 and n <= 72:
        flag = 1
    if n % 7 == 0 and n <= 63:
        flag = 1
    if n % 6 == 0 and n <= 54:
        flag = 1
    if n % 5 == 0 and n <= 45:
        flag = 1
    if n % 4 == 0 and n <= 36:
        flag = 1
    if n % 3 == 0 and n <= 27:
        flag = 1
    if n % 2 == 0 and n <= 18:
        flag = 1
    if n <= 9:
        flag = 1

if flag == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <vector>

int scan() {
  int r = 0, c;
  while ((c = getchar_unlocked()) >= '0')
    r = r * 10 + c - '0';
  return r;
}

inline bool test(const int x, const int y) noexcept { return x & 1 << y; }

int main() {
  const int n = scan();
  std::vector<int> v(n, 0);
  for (int i = 0; i != n - 1; i += 1) {
    const int x = scan();
    const int y = scan();
    const int a = scan();
    v[x] ^= a;
    v[y] ^= a;
  }
  int ans = n;
  int b = 0;
  for (const int e : v) {
    if (e == 0) {
      ans -= 1;
      continue;
    }
    if (test(b, e))
      ans -= 1;
    b ^= 1 << e;
  }
  std::vector<int> dp(b / 2 + 1, -1);
  dp[b / 2] = 0;
  for (int s = b; s != 0; s -= 2) {
    if (dp[s >> 1] == -1)
      continue;
    int i = 16;
    while (i != 0) {
      i -= 1;
      if (test(s, i))
        break;
    }
    for (int j = 0; j != i; j += 1) {
      if (!test(s, j))
        continue;
      const int k = i ^ j;
      if (k > j)
        continue;
      int &d = dp[(s ^ 1 << i ^ 1 << j ^ 1 << k) >> 1];
      if (test(s, k))
        d = std::max(d, dp[s >> 1] + 1);
      else
        d = std::max(d, dp[s >> 1]);
    }
  }
  printf("%d", ans - dp[0]);
}

Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits>
#include <set>
#include <sstream>
#include <utility>
#include <ctime>
#include <cassert>
#include <fstream>
using namespace std;
typedef long long LL;
#define MSV(A,a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 1000000
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

LL arr[MAX], ans[MAX];

int main() {

	LL n,k, i;
	
	cin>>n>>k;
	
	for(i = 1 ; i <= n; i++) {
		cin>>arr[i];
	}

	for(i = k+1; i <= n ; i++) {
		if(arr[i] > arr[i-k]) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}

	return 0;
}

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

int32_t main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int k;
  cin >> k;
  int A = 1234567;
  for(int x = 1, p = 1 % k; x < A; p = (10 * p + 1) % k, ++x) {
    if((7 * p) % k == 0) {
      cout << x << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var nx = Input.ar;
        var ar = Input.ar;
        var res = long.MaxValue;
        var min = new long[nx[0], nx[0]];//i->jの最小
        for (var i = 0; i < nx[0]; i++)
        {//頂点
            min[i, i] = ar[i];
            for (var j = (i + 1)%nx[0]; j != i; j = (j + 1) % nx[0])
            {
                min[i, j] = Min(min[i, j == 0 ? nx[0] - 1 : j - 1], ar[j]);
            }
        }
        for(var i = 0; i < nx[0]; i++)
        {
            var sum = 0L;
            for (var j = 0; j < nx[0]; j++)
                sum += min[j, (j + i) % nx[0]];
            res = Min(res, sum + nx[1] * (long)i);
        }WriteLine(res);
    }
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public static long numL => ToInt64(read);
    public static char[][] gred(int h)
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[] ar1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => num).ToArray();
    public static long[] arL1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => numL).ToArray();
    public static string[] strs(int n)
        => Enumerable.Repeat(0, n).Select(_ => read).ToArray();
    public static int[][] ar2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => ar).ToArray();
    public static long[][] arL2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public static string[] Make<T1, T2>(out T1 v1, out T2 v2)
    {
        var r = read.Split(' ');
        v1 = getValue<T1>(r[0]);
        v2 = getValue<T2>(r[1]);
        return r;
    }
    public static string[] Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3)
    {
        var r = Make(out v1, out v2);
        v3 = getValue<T3>(r[2]);
        return r;
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public const int MOD = 1000000007;
}


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

using namespace std;

typedef long long ll;

ll calc(ll x)
{
    ll res = 1;
    for (ll i = 2; i * i <= x; i++) {
        if (x % i == 0) {
            res *= i;
            while (x % i == 0) {
                x /= i;
            }
        }
    }
    if (x != 1) res *= x;
    return res;
}

int main()
{
    ll p, q;
    cin >> p >> q;
    p = q / __gcd(p, q);
    cout << calc(p) << endl;
    return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> grid(H + 2, vector<char>(W + 2));
  
  for (int j = 0; j < W + 2; j++){
      grid.at(0).at(j) = '.';
  }
  for (int i = 1; i <= H; i++){
    grid.at(i).at(0) = '.';
    for (int j = 1; j <= W; j++){
      cin >> grid.at(i).at(j);
    }
    grid.at(i).at(W + 1) = '.';
  }
  for (int j = 0; j < W + 2; j++){
      grid.at(H + 1).at(j) = '.';
  }
  
  for (int i = 1; i < H + 1; i++){
    for (int j = 1; j < W + 1; j++){
      if (grid.at(i).at(j) == '#' && grid.at(i - 1).at(j) == '.'
          && grid.at(i + 1).at(j) == '.' && grid.at(i).at(j - 1) == '.'
          && grid.at(i).at(j + 1) == '.'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
        return 0;
  
}


Measured memory_bytes: 3628
n = int(input())
a = list(map(int,input().split()))
b = [0]
for i in range(n+1):
  b.append(b[-1]+a[-1-i])
b.reverse()
b.pop()
#print(a)
#print(b)
now = 1
ans = 0
for i in range(n+1):
  if now > b[i]:
    now = b[i]
  ans += now
  now -= a[i]
  if now <= 0 and i != n:
    print(-1)
    exit()
  if now < 0 and i == n:
    print(-1)
    exit()
  if now == 0 and i == n:
    print(ans)
    exit()
  now *= 2
  #print(i,now,ans)

Measured memory_bytes: 83540
#include <iostream>
#include <utility>
#include <stack>
#include <string>
using namespace std;

typedef pair<int,int> pii;

int main(void){
	int h,w;
	stack<pii> s;
	string m[21];
	while(cin>>w>>h,w||h){
		for(int i=0;i<h;i++)cin>>m[i];
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(m[i][j]=='@'){
					s.push(pii(i,j));
					i=j=999;
				}
			}
		}
		int c=0;
		while(!s.empty()){
			pii a=s.top();s.pop();
			int i=a.first;
			int j=a.second;
			if(!(0<=i&&i<h&&0<=j&&j<w))continue;
			if(m[i][j]=='#')continue;
			c++;
			m[i][j]='#';
			s.push(pii(i+1,j));
			s.push(pii(i-1,j));
			s.push(pii(i,j+1));
			s.push(pii(i,j-1));
		}
		cout<<c<<endl;
	}
	return 0;
}

Measured memory_bytes: 3168
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

#[allow(unused_macros)]
macro_rules! debug {
    ($var:expr) => {
        match &$var { v => eprintln!(concat!(stringify!($var), "={:?}"), v) }
    };
    ($var:expr, $($vars:expr),*) => {
        match &$var { v => eprint!(concat!(stringify!($var), "={:?} "), v) }
        debug!($($vars),*);
    };
}

fn main() {
    let n: usize = input();
    let x: i64 = input();

    let mut all = vec![0; n + 1];
    let mut pate = vec![0; n + 1];
    all[0] = 1;
    pate[0] = 1;
    for i in 0..n {
        all[i + 1] = 2 * all[i] + 3;
        pate[i + 1] = 2 * pate[i] + 1;
    }

    println!("{}", dfs(n, x, &all, &pate));
}

fn dfs(k: usize, rem: i64, all: &Vec<i64>, pate: &Vec<i64>) -> i64 {
    if rem >= all[k] {
        pate[k]
    } else {
        let mut ans = 0;
        let mut r = rem;
        if r > 0 {
            r -= 1;
        }
        if r >= all[k - 1] {
            ans += pate[k - 1];
            r -= all[k - 1];
            if r > 0 {
                ans += 1;
                r -= 1;
            }
            if r > 0 {
                ans += dfs(k - 1, r, all, pate);
            }
        } else {
            if r > 0 {
                ans += dfs(k - 1, r, all, pate);
            }
        }
        ans
    }
}


Measured memory_bytes: 4352
import java.util.*;
public class Main
{public static void main(String args[])
   { Scanner sc=new Scanner(System.in);
     int n=sc.nextInt();
     int h=n/500;
     int rest=n-(h*500);
     int f=rest/5;
     int tot=h*1000 + f*5;
    System.out.println(tot);
   }
}

Measured memory_bytes: 23636
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;

int main(){
    int x;
    cin >> x;
    if (x == 3 || x == 5 || x == 7) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque

k, n = map(int, input().split())
#d = deque()
#d = (d.append(int(_)) for _ in input().split())
d = [int(_) for _ in input().split()]

ans = k

for a in range(n):
    b = a - 1
    if b < 0:
        b += n
    #tmp = d.index(0) - d.index(-1)
    tmp = d[b] - d[a]
    if tmp < 0:
        tmp += k
    if tmp < ans:
        ans = tmp
    #d.rotate()

print(ans)

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

int main() {
    int n;
    cin >> n;
    int x[n], y[n], c[n];
    rep(i, n) cin >> x[i] >> y[i];
    rep(i, n) c[i] = i;

    double ans = 0.0, cnt = 0;
    do {
        rep(i, n - 1) {
            int lx = pow(x[c[i]] - x[c[i + 1]], 2.0);
            int ly = pow(y[c[i]] - y[c[i + 1]], 2.0);
            ans += sqrt(lx + ly);
        }
        cnt++;
    } while (next_permutation(c, c + n));

    printf("%.10f\n", ans / cnt);
    return 0;
}


Measured memory_bytes: 256
/*****************************************************

Code by: Vichitr
Compiled On: 23rd March 2019

*****************************************************/

#include<bits/stdc++.h>
#define MAX 9223372036854775807
#define endl "\n"
#define ll long long
#define int long long
#define pb push_back
#define pf pop_front
#define mp make_pair
#define loop(i,n) for(int i=0;i<n;i++)
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ip pair<int, int>
#define N 100007
const ll MOD = 1e9+7;
const ll SZ = 107;


signed main()
{
    fast;

    int n, k;
    cin>>n;
    int a[n+5], b[n+5], c[n+5];
    for(int i=1;i<=n;i++) cin>>a[i]>>b[i]>>c[i];
    int dp[n+5][3];
    dp[1][0]= a[1];
    dp[1][1] = b[1];
    dp[1][2] = c[1];
    //dp[2] = abs(h[2]-h[1]);
    for(int i=2;i<=n;i++)
    {
        dp[i][0] = a[i]+max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = b[i]+max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] =  c[i]+max(dp[i-1][0], dp[i-1][1]);    
    }
    int ans= max({dp[n][0], dp[n][1], dp[n][2]});
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4992
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n;cin >> n;
    vi rui(n+1);
    rep(i, n) {
        int a;cin >> a;
        rui[i+1]+=rui[i]+a;
    }
    int ans = 0;
    rep(i, n-1) {
        int p = (rui[i+1]-rui[i])%mod;
        int q = (rui[n]-rui[i+1])%mod;
        ans+=p*q;
        ans%=mod;
        // cout << ans << endl;
    }
    cout << ans << endl;
    // rep(i, n+1) cout << rui[i] << ' ';
    return 0;
}

Measured memory_bytes: 4900
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int A[1];
int size=1;
int m=2;
#define N 101
#define mod 1000000007
#define f(i,n) for(int i=0;i<n;i++)
#define in(i,arr) for(auto &i:arr)cin>>i;


int main() {
    fast;
    int t=1;
    //cin >> t;
    while (t--)
    { int l,r,d,count=0;
      cin>>l>>r>>d;
      for(int i=l;i<=r;i++)
      if(i%d==0)
          count++;
      cout<<count;





    }
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl

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

  string S; cin >> S;

  int res = 0;
  rep(i, S.size()) {
    string s = S.substr(i);
    int cnt = 0;
    while(cnt!=s.size()) {
      if(!(s[cnt]=='A' || s[cnt]=='C' || s[cnt]=='G' || s[cnt]=='T')) break;
        ++cnt;
    }
    res = max(res, cnt);
  }

  cout << res << endl;

  return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - NarrowRectanglesEasy
            var line = ReadLine();
            int w = line[0];
            int a = line[1];
            int b = line[2];

            if (a <= b)
            {
                if (a + w >= b)
                {
                    Console.WriteLine(0);
                }
                else
                {
                    Console.WriteLine(b - (a + w));
                }
            }
            else
            {
                Console.WriteLine(a - (b + w));
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
 
using namespace std;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i; ris; }
    eni(==) ris << range(begin(i), end(i)); }
    sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
    }
    sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
    }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<long double> vld;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846
#define sqr(a) ((a) * (a))
#define len(V) (int)V.size()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define fix(a) fixed << setprecision(a)
#define readv(x) for(auto &_ : (x)) {cin >> _;}
#define printv(x) for(auto &_ : (x)) {cout << _ << ' ';} cout << endl
#define EPS 1e-6
#define MAXN 100047

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n; cin >> n;
	vi a(n); readv(a);
	sort(rall(a));
	
	int A = 0, b = 0;
	FOR(i, 0, n){
		if (i % 2 == 0) A += a[i];
		else b += a[i];
	}
	
	cout << A - b << endl;
	
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;

int main(void){
    int n, p[25];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> p[i];
    
    int ans =0;
    for (int i = 0; i < n - 2; i++) {
        if (min(p[i], p[i + 2]) < p[i + 1] && p[i + 1] < max(p[i], p[i + 2])) ans++;
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
package main

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

func main() {

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	b, _ := strconv.Atoi(sc.Text())

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	if a >= n {
		a -= n
	} else if a+b >= n {
		b -= n - a
		a = 0
	} else {
		a, b = 0, 0
	}
	fmt.Println(a, b)
}


Measured memory_bytes: 640
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

type runes []rune

func (rs runes) Len() int           { return len(rs) }
func (rs runes) Swap(i, j int)      { rs[i], rs[j] = rs[j], rs[i] }
func (rs runes) Less(i, j int) bool { return rs[i] < rs[j] }

func main() {
	sc.Split(bufio.ScanWords)
	var N int
	N = nextInt()
	mp := make(map[string]int)
	for i := 0; i < N; i++ {
		s := []rune(next())
		sort.Sort(runes(s))
		mp[string(s)]++
	}
	ans := 0
	for _, n := range mp {
		ans += n * (n - 1) / 2
	}
	fmt.Println(ans)

}


Measured memory_bytes: 11520
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int, int> P;
typedef pair<P, int>PP;
const long long mod = 998244353;

signed main() {
	int x, y, z; cin >> x >> y >> z;
	cout << z << ' ' << x << ' ' << y << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
int main (void) {
    int flag=0;
    string str;
    cin >> str;
    vector<char> ch;
    for(int i=str.size()-1;i>=0;i--){
        if(str[i]=='B') flag++;
        else if(flag==0)    ch.push_back(str[i]);
        else    flag--;
    }
    for(int i=ch.size()-1;i>=0;i--)    cout << ch[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
R, G,B,N = map(int, input().split())
l = [R,G,B]
l = sorted(l)
ma = l[2]
mi = l[0]
mid = l[1]
id = N // ma
count = 0
for i in range(id+1):
    res = N - ma * i
    if res >= mid:
        for j in range(res//mid+1):
            if res % mi == 0:
                count += 1
            res -= mid
    else:
        if res % mi == 0:
            count +=1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm> 

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

int ab = 5;
int solve(int a_){
    return a_ + 1;
}

int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
   
  int a[200000] = {};
  int ans[200000] = {};
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  int kib = 0;
  int gub = 0;
  int ba = 0;
  if(n%2==0){
    ba = n /2;
    kib = ba + 1;
    gub = ba - 1;
    ans[ba] = a[0];
    for(int i = 1; i < n; i++){
      if(i % 2 == 1){
        ans[gub] = a[i];
        gub--;
      }else{
        ans[kib] = a[i];
        kib++;
      }
    }
  }else{
    ba = n / 2;
    kib = ba - 1;
    gub = ba + 1;
    ans[ba] = a[0];
    for(int i = 1; i < n; i++){
      if(i % 2 == 1){
        ans[gub] = a[i];
        gub++;
      }else{
        ans[kib] = a[i];
        kib--;
      }
    }
  }

  for(int i = 0; i < n-1; i++){
    cout << ans[i] << ' ';
  }
  cout << ans[n-1] << '\n';

   return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	reverse(all(a));
	int Alice = 0, Bob = 0;

	rep(i, n) {
		if (i % 2 == 0) Alice += a[i];
		else Bob += a[i];
	}

	dunk(Alice - Bob);

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

signed main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0)break;
        vector<int> a(n);
        rep(i,n)cin >> a[i];
        sort(a.begin(),a.end());
        int ans = 10000000;
        rep(i,n-1)ans = min(ans,abs(a[i]-a[i+1]));
        cout << ans << endl;
    }
    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc133.contest.atcoder.jp/tasks/abc133_b


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN=1e6+69;
const int INF = 1e10;
const int mod = 1e9+7;
int m,n,k,q;
string s;
int hsh[MAXN];
int Pow[MAXN];
int fact[MAXN];
struct vl{
    int x,y;
    bool operator<(vl t)const{
        if(x==t.x)return y<t.y;
        return x<t.x;
    }
};
int luythua(int x, int y){
    if(y==0)return 1;
    if(y==1)return x%mod;
    int k = luythua(x,y/2);
    if(y%2==0)return k*k%mod;
    return k*k%mod*x%mod;
}
int a[MAXN],b[MAXN];
int c[MAXN];
int dp[MAXN];
signed main(){                                                                                                                                                                                                                                                                                                  ios_base::sync_with_stdio(false);    cin.tie(0);    cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>a[i]>>b[i];
        for(int j=0;j<b[i];j++){
            cin>>k;
            k--;
            c[i]|=(1<<k);
        }
    }
    dp[0]=1;
    for(int i=1;i<(1<<n);i++)dp[i]=INF;
    for(int mask = 0;mask<(1<<n);mask++){
        if(dp[mask]!=INF){
            for(int i=1;i<=m;i++){
                dp[mask|c[i]]=min(dp[mask|c[i]],dp[mask]+a[i]);
            }
        }
    }
    if(dp[(1<<n)-1]!=INF)cout<<dp[(1<<n)-1]-1;
    else cout<<-1;
}


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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;



void solve()
{
    int n;
    cin >> n;
    int ans = 0;
    lop(a, 1, n)
    {
        int y = n / a;
        if ( n % a == 0 ) y--;
        ans += y;
    }

    cout << ans << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);

    int test = 1;
    // cin >> test;
    while (test--)solve();


}





















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

int main() {
  int N, A, x;
  
  cin >> N;
  cin >> A;
  
  x = N % 500;
  
  if (x <= A) {
    cout << "Yes" << endl;
  } else if (x > A){
    cout << "No" << endl;
  }
}

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

int main(){
  int N, K;
  cin>>N>>K;
  vector<int> tree(N);
  for(int i=0; i<N; i++){
    int h;
    cin>>h;
    tree[i]=h;
  }
  sort(tree.begin(), tree.end());
  reverse(tree.begin(), tree.end());
  int min=tree[0];
  for(int i=0; i<N-K+1; i++){
    if(tree[i]-tree[i+K-1]<min) min=tree[i]-tree[i+K-1];
  }
  cout<<min<<endl;
}
 


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod =1000000007;



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

	k--;
	char c = s[k];

	REP(i, n) {
		if (s[i] != c)s[i] = '*';
	}

	cout << s << endl;

}

Measured memory_bytes: 256
x,n,*p=map(int,open(0).read().split())
if n==0:
    print(x)
else:
    q=[i for i in range(102) if not(i in p)]
    m=[]
    for j in q:
        m.append(abs(j-x))
    a,b=x-min(m),x+min(m)
    if a in q:
        print(a)
    else:
        print(b)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(int X = 0; X < N; X++)
#define repvin(V,N) for(int i = 0; i < N; i++) {int tmp; cin >> tmp; V.push_back(tmp);}

using namespace std;

int gcd(int a, int b){
    if(a < b) return gcd(b,a);

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

int main(){

    int n,x;
    cin >> n >> x;

    vector<int> v;

    repvin(v,n);

    v.push_back(x);

    sort(v.begin(),v.end());

    vector<int> diff;

    rep(i,n){
        diff.push_back(v[i + 1] - v[i]);
    }

    int ans;

    if(diff.size() > 1){
        ans = gcd(diff[0], diff[1]);
    }else{
        ans = diff[0];
    }

    rep(i,n - 2){
        ans = gcd(ans,diff[i + 2]);
    }

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

Measured memory_bytes: 1400
#include <iostream>
//#include <algorithm>
#include <cstring>
#include<cstdio>
using namespace std;

int ans = -1000000000;
int a[10];
int n, f[100][10], p[100][11];
int max(int ans, int score)
{
	if (ans > score)
		return ans;
	else
		return score;
}
void func(void){
	int score = 0, cnt;
	for (int i = 0; i < n; i++){
		cnt = 0;
		for (int j = 0; j < 10; j++){
			if (a[j] == 1 && f[i][j] == 1)
				cnt++;
		}
			score += p[i][cnt];
	}
	ans = max(ans, score);
}
void dfs(int pos)
{
	if (pos == 10){
		int flag = 0;
		for (int i = 0; i < 10; i++){
			if (a[i] == 1)
				flag = 1;
		}
		if (flag)
		func();
		return;
	}
		a[pos] = 0; dfs(pos + 1);
		a[pos] = 1; dfs(pos + 1);

}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++){
		for (int j = 0; j < 10; j++)
			scanf("%d", &f[i][j]);
	}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < 11;j++)
		scanf("%d", &p[i][j]);

	dfs(0);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256