akhauriyash/Code-Regression huggingface dataset:
fun main() {
    val builder = StringBuilder()

    val n = readInputLine().toInt()

    val aArr = LongArray(n)
    val bArr = LongArray(n)

    repeat(n) {
        val (a, b) = readInputLine().split(" ").map { it.toLong() }
        aArr[it] = a
        bArr[it] = b
    }

    aArr.sort()
    bArr.sort()

    if ((n and 1) == 0) {
        val min = aArr[n / 2 - 1] + aArr[n / 2]
        val max = bArr[n / 2 - 1] + bArr[n / 2]
        builder.appendln(max - min + 1)
    } else {
        val min = aArr[(n + 1) / 2 - 1]
        val max = bArr[(n + 1) / 2 - 1]
        builder.appendln(max - min + 1)
    }

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 64388
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll ans = 0;
    ll n = S.size();
    rep(i,0, 1 << (n-1)){
        vector<ll> pos;
        pos.push_back(0);
        rep(j,0,n-1){
            if(i >> j & 1){
                pos.push_back(j + 1);
            }
        }
        pos.push_back(n);
        ll sl = pos.size();
        rep(i,1,sl){
            string str = S.substr(pos[i-1], pos[i] - pos[i-1]);
            ans += atol(str.c_str());
        }
    }
    print(ans);

}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
	ll N, M;
	cin >> N >> M;
	ll tmp = N*(N-1)/2;
	vector<ll> res;
	res.push_back(tmp);
	UnionFind uf(N);
	vector<ll> X(M), Y(M);
	REP(i, M){	
		cin >> X[i] >> Y[i], X[i]--, Y[i]--;
	}
	REP(i, M){
		ll A = X[M-1-i];
		ll B = Y[M-1-i];
		if(!uf.issame(A, B)){
			ll sa = uf.size(A);
			ll sb = uf.size(B);
			tmp -= sa*sb;
			uf.merge(A, B);
		}
		res.push_back(tmp);
	}
	REP(i, M){
		cout << res[M-1-i] << endl;
	}
    return 0;
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define long long long 
#define db double
#define pii pair <int, int> 
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template <class T> inline void chmin(T& a, const T& val) { if (a > val) a = val; }
template <class T> inline void chmax(T& a, const T& val) { if (a < val) a = val; }
template <class T> long sqr(T& a) { return 1ll * a * a; }
template <class T> void compress(vector <T> &a){
  sort(all(a));
  a.resize(unique(all(a)) - a.begin());
}

const db pi = acos(-1.00);
const db eps = 1e-6;
const int INF = 1e9;
const int MOD = 1e9+7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};

const int N = 13;
int n, m, x, cur, res, cost[N], a[N][N], cnt[N];
   
void Try(int u){
  for (int i = 0; i < 2; i++){
    cur += i * cost[u];
    for (int j = 1; j <= m; j++){
      cnt[j] += i * a[u][j];
    }
    if (u == n){
      bool Check = true;
      for (int j = 1; j <= m; j++){
        if (cnt[j] < x) Check = false;
      }
      if (Check) chmin(res, cur);
    }
    else Try(u + 1);
    for (int j = 1; j <= m; j++){
      cnt[j] -= i * a[u][j];
    }
    cur -= i * cost[u];
  }
}

int main()
{
  fastio;
  cin >> n >> m >> x;
  for (int i = 1; i <= n; i++){
    cin >> cost[i];
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  }
  cur = 0; res = INF;
  Try(1); cout << (res == INF ? -1 : res);
  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int N = 2222;
int d[N][N], cnt[N];
int n, x, y;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> x >> y;
    if(x > y) swap(x, y);
    rep(i, 1, n) {
        rep(j, i + 1, n) {
            d[i][j] = min(j - i, abs(x - i) + 1 + abs(j - y));
            cnt[d[i][j]]++;
        }
    }
    rep(k, 1, n - 1) {
        cout << cnt[k] << endl;
    }
    return 0;
}


Measured memory_bytes: 18688
#include<bits/stdc++.h>
using namespace std;
string s,t;

int main(){
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  //cout <<s << " " << t << endl;
  if(s<t) cout << "Yes"<< endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<deque>
#include<functional>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<string>
#include<vector>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
typedef long long ll;

using namespace std;

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

	int N;
	cin >> N;
	string s;
	cin >> s;
	REP(i, s.length()) {
		s[i] += N;
		if (s[i] > 90)s[i] -= 26;
	}
	cout << s << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll from;
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RES(a, n) (a).resize(n)
#define VLCIN(a, n) REP(i,n){cin >> a[i];}
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = (ll)pow(10,7);
/****** define constant end ********/
/****** define variable start ******/
ll l, r, d;
/******* define variable end *******/
int solve() {
	cin >> l >> r >> d;
	ll ans = 0;
	for(ll i = l; i <= r; i++){
		if(i % d == 0){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}
int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

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



int main(void) {
	
	while (1) {
		string s;
		int count = 0;
		int now = 0;
		int pos = -1;
		int dp[100] = {};

		getline(cin, s);
		if (s[0] == '.') {
			break;
		}
		FOR(i, 0, s.size() - 1) {
			switch (s[i]) {
			case '(':
				dp[i] = 1;
				count++;
				break;
			case ')':
				dp[i] = -1;
				count++;
				break;
			case '[':
				dp[i] = 2;
				count++;
				break;
			case ']':
				dp[i] = -2;
				count++;
				break;
			}
		}

		while (1) {
			bool check = false;
			int now;
			int i = 0;
			int t = 1;
			while (i<=s.size()-2) {
				if (dp[i] ==1||dp[i]==2) {
					now = dp[i];
					break;
				}
				i++;
			}
			t = i + 1;
			while (t <= s.size() - 1) {
				if (dp[t] + now == 0) {
					dp[i] = dp[t] = 0;
					count -= 2;
					break;
				}
				else if (dp[t] == 1 || dp[t] == 2) {
					now = dp[t];
					i = t;
				}
				else if (dp[t] == -1 || dp[t] == -2) {
					t = s.size() - 1;
				}
				t++;
			}
			if (t == s.size()) {
				break;
			}
			
		}

		if (count == 0) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
		
	}

}


Measured memory_bytes: 3144
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        final int N = scan.nextInt();
        int[] b = new int[N-1];
        for(int i = 0; i < N - 1; i++){
            b[i] = scan.nextInt();
        }
        scan.close();
        int result = b[0];
        for(int i = 0; i < N - 2; i++){
            if(b[i] > b[i+1]){
                result += b[i+1];
            }else{
                result += b[i];
            }
        }
        result += b[N - 2];
        System.out.println(result);
        
    }
    
}


Measured memory_bytes: 21844
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

vector<vector<int> > tree;
vector<int> visited, counter;

void bfs(int u) {
	visited[u] = 1;
	deque<int> vertices;
	vertices.push_back(u);

	while (!vertices.empty()) {
		int curr = vertices.front();
		vertices.pop_front();
		for (int i = 0; i < (int) tree[curr].size(); ++i) {
			if (!visited[tree[curr][i]]) {
				visited[tree[curr][i]] = 1;
				counter[tree[curr][i]] += counter[curr];
				vertices.push_back(tree[curr][i]);
			}
		}
	}
}

int main() {

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

	int n, q;
	cin >> n >> q;

	tree = vector<vector<int> > (n + 1, vector<int> ());
	int u, v;
	for (int i = 0; i < n - 1; ++i) {
		cin >> u >> v;
		tree[u].push_back(v);
		tree[v].push_back(u);
	}

	visited = vector<int> (n + 1);
	counter = vector<int> (n + 1);

	int p, x;
	while (q--) {
		cin >> p >> x;
		counter[p] += x;
	}

	bfs(1);

	for (int i = 1; i <= n; ++i) {
		cout << counter[i] << " ";
	}

	cout << "\n";

	return 0;

}

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

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

int main() {
    //cout.precision(10);
    int n, k;
    cin >> n >> k;
    /*for(int i = 1; i <= n; i++){
        int in;
        cin >> in;
        if(in == 1){
            cout << (i - 1 + k - 1 - 1) / (k - 1) + (n - i + k - 1 - 1) / (k - 1) << endl;
            return 0;
        }
    }*/
    cout << (n - 1 + k - 1 - 1) / (k - 1) << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
ps = list(map(int, input().split()))

ans = 0

for i in range(1, n-1):
  if ps[i-1] < ps[i] < ps[i+1]:
    ans += 1
  elif ps[i-1] > ps[i] > ps[i+1]:
    ans += 1

print(ans)

Measured memory_bytes: 3060
import numpy as np

S = np.array(list(input()))
S = (S == 'R') * 1
N = len(S)
L = np.zeros(N, dtype = int)
R = np.zeros(N, dtype = int)

count1 = 0
count0 = 0
for i in range(N):
    if S[i] == 1:
        count1 += 1
    if S[i] == 0 and count1 != 0:
        R[i] = count1 // 2
        R[i - 1] = (count1 + 1) // 2
        count1 = 0
    if S[N - 1 - i] == 0:
        count0 += 1
    if S[N - 1 - i] == 1 and count0 != 0:
        L[N - 1 - i] = count0 // 2
        L[N - i] = (count0 + 1) // 2
        count0 = 0
print(' '.join(map(str, list(R + L))))

Measured memory_bytes: 25340
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n; cin>>n;
  vector<int> l(n);
  for(auto& i:l) cin>>i;
  sort(l.begin(),l.end());
  int res=0;
  for(int i=0; i<(n-1); ++i) for(int j=i+1; j<n; ++j){
    int k=lower_bound(l.begin(),l.end(),l[i]+l[j])-l.begin();
    res+=max(k-(j+1),0);
  }
  cout<<res;
  return 0;
}

Measured memory_bytes: 3588
open Batteries

(* ===== MAIN ===== *)

let () =
  let s, t = Scanf.scanf " %s %s" (fun s t -> s, t) in
  let ans =
       List.combine (String.to_list s) (String.to_list t)
    |> List.filter (fun (a, b) -> a <> b)
    |> List.length
  in
    Printf.printf "%d\n" ans



Measured memory_bytes: 30920
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int a,b;cin>>a>>b;
    if(b%a == 0) cout<<a+b;
    else cout<<b-a;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#include<cctype> 
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
 
int main(){
  int r,g,b;
  cin >> r >> g >> b;
  int s=100*r+10*g+b;
  if(s%4==0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
                    
                              
  return 0;
} 



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(X: int):
    x = X // 500
    y = X % 500 // 5
    print(int(x * 1000 + y * 5))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
a,b,c,d,n;main(z){for(;scanf("%d%d%d%d%d",&n,&a,&b,&c,&d),n/=10;d>0&&printf("500 %d\n",d))--z&&puts(""),n-=a+5*b+10*c+50*d,d+=n/50,c+=n%50/10,b+=n%10/5,a+=n%5,a>0&&printf("10 %d\n",a),b>0&&printf("50 %d\n",b),c>0&&printf("100 %d\n",c);}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define int long long
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
int n,m,a,sum;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>a;
    n-=a;
  }
  if(n>=0) cout<<n<<"\n";
  else cout<<"-1\n";
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,k;
  cin>>a>>b>>k;
  int  cnt=0;
  for(int i=100; i>=1; i--){
    if(a%i==0&&b%i==0){
      cnt++;
      if(cnt==k)cout<<i<<endl;
    }
  }   
}

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

char m[9][9];
bool judge(int h, int w, int x, int y){
    if(m[1][1] == '.') return false;
    if(x == h && y == w){
        return true;
    }
    if(m[x+1][y] == '#'){
        return judge(h,w,x+1,y);
    }
    if(m[x][y+1] == '#'){
        return judge(h, w, x, y+1);
    }
    if(m[x][y+1] == '.' && m[x+1][y] == '.')return false;
}

void ans(int h, int w, int x, int y){
    if(x == h && y == w){
        m[x][y] = 'o'; 
    }
    if(m[x+1][y] == '#'){
        m[x][y] = 'o';
        ans(h, w, x+1, y);
    }
    if(m[x][y+1] == '#'){
        m[x][y] = 'o';
        ans(h, w, x, y+1);
    }
}

int main(){
    int h, w;
    cin >> h >> w;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> m[i][j];
        }
    }
    m[1][1] = 'o';
    ans(h, w, 1, 1);
    bool flag = false;
    for(int i = 1 ; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(m[i][j] == '#')flag = true;
        }
    }
    if(!flag)cout << "Possible";
    else cout << "Impossible";

}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;


typedef long long       ll;
struct edge { ll to; ll cost; };
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef vector<edge>    ve;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<ve>      vve;
typedef vector<vc>		vvc;

#define repr(itr, bgn, end) for (ll itr = (ll)bgn; itr < (ll)end; ++itr)
#define rep(itr, end) repr(itr, 0, end)
#define reprrev(itr, bgn, end) for (ll itr = (ll)end - 1; itr >= (ll)bgn; --i)
#define reprev(itr, end) reprrev(itr, 0, end)
#define all(container) container.begin(), container.end()
#define sortall(container) sort(all(container))
#define yn(cond) cond ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(cond) cond ? (cout << "YES" << endl) : (cout << "NO" << endl)

// 定数
#define LLONG_MAX numeric_limits<ll>::max()
#define INT_MAX numeric_limits<int>::max()
constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 15;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;

// よく使うもの
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	for (T& x : vec) os << x << " ";
	return os;
}



int main()
{
	int D;
	cin >> D;
	
	switch (D)	
	{
	case 22:
		cout << "Christmas Eve Eve Eve" << endl;
		break;
	case 23:
		cout << "Christmas Eve Eve" << endl;
		break;
	case 24:
		cout << "Christmas Eve" << endl;
		break;
	case 25:
		cout << "Christmas" << endl;
		break;
	default:
		break;
	}



	return 0;
}

Measured memory_bytes: 256
res = input().split()
map(int, res)
q = res
cand = []
while len(q) > 0:
    now = q[0]
    q.pop(0)
    b = [x for i, x in enumerate(res) if i != now]
    for i in range(len(b)):
        cand.append(int(now) + int(b[i]))
print(min(cand))


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

int main(){
    int N, T;
    std::cin >> N >> T;
    std::vector< std::pair< int, int > > AB(N);
    for(int i=0; i<N; i++){
        std::cin >> AB[i].first >> AB[i].second;
    }
    
    std::sort(AB.begin(), AB.end());
    
    std::vector< std::vector< int > > dp(N + 1, std::vector< int >(T));
    dp[0].assign(T, 0);
    int max = 0;
    for(int i=1; i<N+1; i++){
        if(max < dp[i-1][T-1] + AB[i-1].second){
            max = dp[i-1][T-1] + AB[i-1].second;
        }
        for(int j=0; j<T; j++){
            if(j < AB[i-1].first){
                dp[i][j] = dp[i-1][j];
            }else{
                dp[i][j] = std::max(dp[i-1][j], dp[i-1][j-AB[i-1].first] + AB[i-1].second);
            }
        }
    }
    
    std::cout << max << std::endl;
    
    return 0;
}



Measured memory_bytes: 35584
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

#define dump(a) (cerr << (#a) << " = " << (a) << endl)

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

template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << '(' << p.first << ", " << p.second << ')';
	return os;
}

template<class Tuple, unsigned Index>
void print_tuple(ostream& os, const Tuple& t) {}

template<class Tuple, unsigned Index, class Type, class... Types>
void print_tuple(ostream& os, const Tuple& t) {
	if(Index > 0) os << ", ";
	os << get<Index>(t);
	print_tuple<Tuple, Index + 1, Types...>(os, t);
}

template<class... Types>
ostream& operator<<(ostream& os, const tuple<Types...>& t) {
	os << '(';
	print_tuple<tuple<Types...>, 0, Types...>(os, t);
	return os << ')';
}

template<class Iterator>
ostream& dump_range(ostream&, Iterator, const Iterator&);

template<typename T>
ostream& operator<<(ostream& os, vector<T> c) {
	return dump_range(os, c.cbegin(), c.cend());
}

template<class Iterator>
ostream& dump_range(ostream& os, Iterator first, const Iterator& last) {
	os << '[';
	for(int i = 0; first != last; ++i, ++first) {
		if(i) os << ", ";
		os << *first;
	}
	return os << ']';
}

int ans;
int n, m;
vector<int> cover;
int used;
vector<vector<int>> edges;

void dfs(int idx, int sum) {
	if(sum >= ans) return;

	if(idx == n) {
		if(used == (1 << n) - 1) ans = sum;
	}
	else {
		dfs(idx + 1, sum);
		const int tmp = used;
		used |= cover[idx];
		dfs(idx + 1, sum + 1);
		used = tmp;
	}
}

int solve() {
	cover.assign(n, 0);
	for(int i = 0; i < n; ++i) {
		cover[i] |= (1 << i);
		for(int j = 0; j < static_cast<int>(edges[i].size()); ++j) {
			cover[i] |= (1 << edges[i][j]);
		}
	}

	used = 0;
	int cnt = 0;
	for(int i = 0; i < n; ++i) {
		if(edges[i].size() == 0) {
			used |= (1 << i);
			++cnt;
		}
		else if(!(used & (1 << i))) {
			for(int j = 0; j < static_cast<int>(edges[i].size()); ++j) {
				if(edges[edges[i][j]].size() == 1) {
					used |= cover[i];
					++cnt;
					break;
				}
			}
		}
	}

	ans = n - __builtin_popcount(used) + cnt;
	dfs(0, cnt);
	return ans;
}

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

	while(cin >> n >> m && n) {
		edges.assign(n, vector<int>());
		for(int i = 0; i < m; ++i) {
			int a, b;
			cin >> a >> b;
			edges[a].emplace_back(b);
			edges[b].emplace_back(a);
		}

		cout << solve() << endl;
	}

	return EXIT_SUCCESS;
}

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

int main(void){
    int n ;
    cin >> n ;
    vector<int> a,b ;
    for (int i=0; i<n; i++){
        int x ;
        cin >> x ;
        a.push_back(x) ;
        b.push_back(x) ;
    }
    sort(b.begin(), b.end(),greater<int>());
    for (int i=0; i<n; i++){
        if (a[i] == b[0]){
            cout << b[1] << endl ;
        } else {
            cout << b[0] << endl ;
        }
    }
}

Measured memory_bytes: 3436
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,j,n) for(int i=j;i<=n;i++)
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    if(n % 2)
        cout << n * 2;
    else
        cout << n;
} 


Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std ;
 
#define lli long long int
#define pb push_back
 
vector <int> v ;
int main ()
{
    int a , b , c ;
    cin >> a >> b >> c ;
    v.pb(a) , v.pb(b) , v.pb(c) ;
 
    sort(v.begin() , v.end());
 
    if (v[0] == v[1] && v[1] != v[2])
    {
        cout << "Yes\n" ;
    }
    else if (v[0] != v[1] && v[1] == v[2])
    {
        cout << "Yes\n" ;
    }
    else
    {
        cout << "No\n" ;
    }
    
    return 0 ;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val tList = readLine()!!.split(' ').map(String::toInt)
    val vList = readLine()!!.split(' ').map(String::toInt)
    val startList = mutableListOf(0)
    (0..(n - 2)).forEach { startList.add(startList.last() + tList[it]) }
    val maxSpeed = mutableMapOf<Double, Double>()
    val totalTime = tList.sum().toDouble()
    var i = 0.0
    while (i <= totalTime) {
        maxSpeed[i] = i
        i += 0.5
    }
    i = totalTime
    while (i >= 0) {
        maxSpeed[i] = Math.min(totalTime - i, maxSpeed[i]!!)
        i -= 0.5
    }
    for (j in 0 until n) {
        val t = tList[j]
        val v = vList[j]
        val start = startList[j]
        i = 0.0
        while (i <= totalTime) {
            val curSpeed = if (i <= start) {
                v.toDouble() + (start - i)
            } else if (i >= start + t) {
                v.toDouble() + (i - (start + t))
            } else {
                v.toDouble()
            }
            maxSpeed[i] = Math.min(maxSpeed[i]!!, curSpeed)
            i += 0.5
        }
    }
    var ans = 0.0
    i = 0.0
    while (i < totalTime) {
        ans += (maxSpeed[i]!! + maxSpeed[i + 0.5]!!) * 0.5 * 0.5
        i += 0.5
    }
    println(ans)
}


Measured memory_bytes: 115656
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n;
void dfs(string s,int cnt){
	if(s.size()==n){
		cout<<s<<"\n";
		re;
	}
	rep(i,cnt){
		string t=s;
		t+=(char)('a'+i);
		dfs(t,cnt);
	}
	string t=s;
	t+=(char)('a'+cnt);
	dfs(t,cnt+1);
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	dfs("a",1);
	re 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
int a[214514];
signed main(){
	int n;
	cin>>n;
	int ans=0;
	rep(0,i,n){
		cin>>a[i];
		ans+=a[i];
		ans-=i+1;
	}
	c(ans)
}	


Measured memory_bytes: 3900
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
V<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
V<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

int n, z, w;
V<int> a(2010);
V<V<int>> dp(2, V<int> (2010));
const int INF = 2e9;

int main () {
    cin >> n >> z >> w;
    rep(i, n) cin >> a[i];
    for (int i = n-1; i >= 0; i--) {
        dp[0][i] = -INF;
        int y;
        if (i == 0) y = w;
        else y = a[i-1];
        dp[0][i] = -INF;
        chmax(dp[0][i], abs(y - a[n-1]));
        for (int j = i+1; j < n; j++) chmax(dp[0][i], dp[1][j]);

        int x;
        if (i == 0) x = z;
        else x = a[i-1];
        dp[1][i] = INF;
        chmin(dp[1][i], abs(x - a[n-1]));
        for (int j = i+1; j < n; j++) chmin(dp[1][i], dp[0][j]);
    }
    cout << dp[0][0] << endl;
    
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define x             first
#define y             second
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define PI            3.14159265358979
#define N             200005

int solve(){
    int n; cin>>n;
    int a[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int ans=0;
    int t=(n+1)/2;
    for(int i=n-1; i>=n/2; i--){
        ans+=a[i];
        // cout<<a[i]<<" ";
    }
    for(int i=(n+1)/2; i<n-1; i++){
        ans+=a[i];
        // cout<<a[i]<<" ";
    }
    cout<<ans;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 5224
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    ll n, k;
    cin >> n >> k;
    ll a[n];
    rep(i, n) { cin >> a[i]; }

    ll ans = 0;
    ll count = 0;
    rep(i, n) {
        repd(j, i + 1, n) {
            if (a[i] > a[j]) {
                count++;
            }
        }
    }
    count *= k;
    count %= mod;
    ans += count;

    sort(a, a + n);
    ll counter[n];
    rep(i, n) { counter[i] = lower_bound(a, a + n, a[i]) - a; }

    ll sum = 0;
    rep(i, n) { sum += counter[i]; }

    sum %= mod;

    ll num = k * (k - 1) / 2;
    num %= mod;

    ans += sum * num;
    ans %= mod;

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

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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); }

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Long> a = new ArrayList<>();
        Long minNum = 0L;
        for (int i = 0; i < n; i++) {
            a.add(sc.nextLong());
            if (i == 0 || a.get(i) < minNum) {
                minNum = a.get(i);
            }
        }

        while (true) {
            Long minReminder = null;
            for (int i = 0; i < n; i++) {
                Long reminder = a.get(i) % minNum;
                if (reminder == 0) {
                    continue;
                }
                if (minReminder == null || reminder < minReminder) {
                    minReminder = reminder;
                }
            }
            if (minReminder == null) {
                break;
            }
            minNum = minReminder;
        }
        System.out.println(minNum);
    }

}


Measured memory_bytes: 61240
# coding: utf-8
# Your code here!

import heapq

N, x = map(int, input().split())
a = list(map(int, input().split()))
heapq.heapify(a)
tmp = 0
ctr = 0

for i in range(N):
    tmp += heapq.heappop(a)
    if tmp > x or (a == [] and tmp != x):
        print(ctr)
        exit()
    else:
        ctr += 1
else:
    print(ctr)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
#define coc g[node][i]
using namespace std;

typedef vector < int > vi;

int n, x;
vi g[N];

int dfs(int node){
	vi a;
	for(int i = 0; i < g[node].size(); i++){
		a.pb(dfs(coc));
	}
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	int ans = 0;
	// cout << node << " -> ";
	// for(int i = 0; i < a.size(); i++)cout << a[i] << " ";cout << endl;
	for(int i = 0; i < a.size(); i++)
		ans = max(ans, a[i] + i);
	return ans + 1;
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d",&n);
	for(int i = 2; i <= n; i++){
		scanf("%d", &x);
		g[x].pb(i);
	}
	cout << dfs(1) - 1 << endl;;
	return 0;
}

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

int main() {
  int n, sum = 0, tmp, maxnum = 0;
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> tmp;
	sum += tmp;
    if (maxnum < tmp) maxnum = tmp;
  }
  cerr << sum  << '\n' << maxnum;
  cout << ((sum - maxnum > maxnum) ? "Yes\n" : "No\n");
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a  =sc.nextInt();
		int b = sc.nextInt();
		for(int i = 1; i <= 10000; i++) {
			int num1 =(int) (i*0.08);
			int num2 = (int) (i*0.10);
			if(num1 == a && num2 == b) {
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
int memo[100000], table[100000];
ll ans = 0;
int main(){
  int N,K,R,S,P;
  string T;
  int d[3];
  cin>>N>>K>>d[0]>>d[1]>>d[2]>>T;
  rep(i,0,N){
    if(T[i]=='r') memo[i] = 0;
    else if(T[i]=='s') memo[i] = 1;
    else memo[i] = 2;
    table[i] = -1;
  }
  map<int, int> own;
  own[0] = 2;  own[1] = 0;  own[2] = 1;
  rep(i,0,K){
    ans += d[own[memo[i]]];
    table[i] = own[memo[i]];
  }
  rep(i,K,N){
    int now = own[memo[i]];
    if(table[i-K] == now){
      if(i+K<N && own[memo[i+K]]==now){
        int future = own[memo[i+K]];
        table[i] = future+1;
      }else{
        table[i] = now;
      }
    }else{
      table[i] = now;
      ans += d[now];
    }
  }
  cout << ans << endl;
  return 0;
}


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

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

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

	string a,b; cin >> a >> b;

	int N = stoi(a+b);

	for (int i = 0;i*i <= N;i++){
		if(i*i == N){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;

}


Measured memory_bytes: 256
-- | Main entry point to the application.
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import Debug.Trace
import Text.Printf

rInt :: String -> Int
rInt str = read str :: Int

condd w h x y r
    | x - r < 0 = "No"
    | y - r < 0 = "No"
    | x + r > w = "No"
    | y + r > h = "No"
    | otherwise = "Yes"

-- | The main entry point.
main :: IO ()
main = do
    [w, h, x, y, r] <- (map rInt . words) <$> getLine
    putStrLn $ condd w h x y r

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include<set>
#include<map>
#include<bitset>
#define rep(i,a,b)  for(i=a;i<b;i++)
#define itrep(at)	for(auto it=at.begin();it!=at.end();it++)
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define db double
#define M 1000000007
#define INF 1e18
#define pi 3.1415926535897932384626433832795028841971

#define MAX 100005

using namespace std;
lli min(lli a,lli b){return a<b?a:b;}
lli min(lli a,lli b,lli c){a=min(a,b);a=min(a,c);return a;}
lli max(lli a,lli b){return a>b?a:b;}
lli max(lli a,lli b,lli c){a=max(a,b);a=max(a,c);return a;}
lli dsum(lli n){lli ans=0;while(n){ans+=(n%10);n/=10;}return ans;}
lli power(lli a,lli b){lli res=1;while(b){if(b&1) res=res*a;a=a*a;b>>=1;}return res;}

struct pll{
	lli x,y;
};
bool comp(pll a,pll b){
	if(a.x==b.x)	return a.y<b.y;
	else	return a.x<b.x;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	char ch;
	db aa,bb,cc;
	string s1,s2,s3,str;
    lli i,j,k,a,b,c,n,m,sum=0,ans=0,temp,t;
    cin >> k >> n;
    lli arr[n+1];
    rep(i,0,n)	cin >> arr[i];
    arr[n]=k;
    lli diff[n];
    for(i=0;i<n;i++){
    	if(i==n-1)	diff[i]=arr[i+1]-arr[i]+arr[0];
    	else	diff[i]=arr[i+1]-arr[i];
//    	cout << diff[i] << " ";
    	ans+=diff[i];
	}
	//cout << ans << endl;
	vector<lli>v;
	for(i=0;i<n;i++){
		v.pb(ans-diff[i]);
	}
	sort(v.begin(),v.end());
	cout << v[0];
	
    
    
    return 0;
}

















/* UJJWAL KESHRI */

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

#define pb push_back
#define F first
#define S second

#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define int long long
#define ll long long

const int N = 3e3 + 5;
int dp[N][N];
string s1, s2, ans;

int rec(int x, int y){
	if(x == s1.size() || y == s2.size())
		return 0;
	if(dp[x][y] != -1)
		return dp[x][y];
	if(s1[x] == s2[y])
		return dp[x][y] = 1 + rec(x + 1, y + 1);
	return dp[x][y] = max(rec(x + 1, y), rec(x, y + 1));
}
	
void solve(){
	memset(dp, -1, sizeof dp);
	cin >> s1 >> s2;
	rec(0, 0);
	int first = 0, second = 0;
	while(first < s1.size() && second < s2.size()){
		if(s1[first] == s2[second]){
			ans += s1[first];
			first++;
			second++;
		}
		else
		if(dp[first][second + 1] >= dp[first + 1][second]){
			second++;
		}
		else
			first++;

	}
	cout << ans << "\n";
}

signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 71040
/**
 *    author:  FromDihPout
 *    created: 2020-08-16
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    const int N = 3;
    vector<vector<int>> a(N, vector<int> (N));
    vector<int> mins(N, 500);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> a[i][j];
            mins[i] = min(mins[i], a[i][j]);
        }
    }
    
    vector<int> b(N);
    for (int j = 0; j < N; j++) {
        b[j] = a[0][j] - mins[0];
    }
    
    for (int i = 1; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (a[i][j] - mins[i] != b[j]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string dat;
    int n;
    cin>>dat>>n;
    string temp;
    temp+=dat[0];
    int t=n;
    while(t<dat.size())
    {
        temp+=dat[t];
        t+=n;
    }
    cout<<temp;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>)
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) a.size()
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl
#define debgp(a) cout<<#a<<" "<<a.fi<<" "<<a,se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) for(const auto&y:a){for(const auto&x:y)cout<<x<<" ";cout<<endl;}
#define out(a) cout<<(a)<<endl
#define fi first
#define se second
#define V vector
#define P pair
#define PQ priority_queue
typedef long long ll;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<PL> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<class T>T gcd(T a,T b){return (b==0?a:gcd(b,a%b));}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*a;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin>>n;
  ll num=1,sum=0;
  set<ll> ans;
  while(1){
    if(sum>=n)break;
    sum+=num;
    ans.insert(num);
    num++;
  }
  if(sum>n)ans.erase(sum-n);
  for(auto&a:ans)cout<<a<<"\n";
  
  
  
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(void){
   
 string s;
 int min = 10000000;
 cin >> s;
 int len = s.size();
 
 for(int i=0;i<len-2;i++){
     int v = ctoi(s[i]) * 100 + ctoi(s[i+1]) * 10 + ctoi(s[i+2]);
     if(abs(v - 753) < min) min = abs(v - 753);
 }
 
 cout << min <<endl;
}

Measured memory_bytes: 3612
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}
import java.lang

import scala.reflect.ClassTag

object Main {
  def get[T: ClassTag](implicit in: BufferedReader, converter: String => T): T = {
    converter(in.readLine)
  }

  def getArray[T: ClassTag](implicit in: BufferedReader, converter: String => T): Array[T] = {
    get[String].split("\\s+").map(converter)
  }

  implicit val intConverter: String => Int = s => Integer.parseInt(s)
  implicit val longConverter: String => Long = s => lang.Long.parseLong(s)

  def get[T1, T2](
                   implicit in: BufferedReader,
                   converter1: String => T1,
                   converter2: String => T2
                 ): (T1, T2) = {
    getArray[String] match {
      case Array(v1, v2) => (converter1(v1), converter2(v2))
    }
  }

  def get[T1, T2, T3](
                       implicit in: BufferedReader,
                       converter1: String => T1,
                       converter2: String => T2,
                       converter3: String => T3
                     ): (T1, T2, T3) = {
    getArray[String] match {
      case Array(v1, v2, v3) => (converter1(v1), converter2(v2), converter3(v3))
    }
  }

  implicit class TimesInt(val n: Int) {
    def times(f: Int => Unit): Unit = {
      for (i <- 0 until n) {
        f(i)
      }
    }
  }

  def main(args: Array[String]): Unit = {
    implicit val in: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val k = get[Int]

    out.println((k / 2) * ((k + 1) / 2))

    out.flush()
  }
}

Measured memory_bytes: 25300
#include<iostream>
#include<numeric>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){ 
	vector<char>n(3),m(3);
	for(int i=0;i<3;i++){
		cin>>n[i];
	}
	for(int j=0;j<3;j++){
		cin>>m[j];
	}
	if(n[2]==m[0]&&n[1]==m[1]&&n[0]==m[2]){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
fun main() {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    val rCnt = s.count { it == 'R' }
    var res = 0

    for (i in s.indices) {
        if (i < rCnt) {
            if (s[i] == 'W') res++

        } else {
            if (s[i] == 'R') res++
        }
    }
    println(res / 2)
}


Measured memory_bytes: 38828
from collections import defaultdict
mod = 10**9+7

def factorize(n):
    out=[]
    i = 2
    while 1:
        if n%i==0:
            out.append(i)
            n //= i
        else:
            i += 1
        if n == 1:break
        if i > int(n**.5+3):
            out.append(n)
            break
    
    return out
  
N=int(input())

if N==1:
  print(1)
  exit()

count = defaultdict(int)
for i in range(2,N+1):
  f = factorize(i)
  for j in range(len(f)):
    count[f[j]] += 1
    
ans = 1
for k in count.keys():
  ans *= count[k]+1 % mod
  
print(ans % mod)

Measured memory_bytes: 9592