akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;

const int MOD = 1e9 + 7;
const int N = 55;
vector<vector<int>> g;
struct Matrix
{
	vector< vector<int> > mat;
	int n_rows, n_cols;

	Matrix(vector< vector<int> > values) : mat(values), n_rows(values.size()),
		n_cols(values[0].size()) {}

	static Matrix identity_matrix(int n)
	{
		vector< vector<int> > values(n, vector<int>(n, 0));
		for (int i = 0; i < n; i++)
			values[i][i] = 1;
		return values;
	}

	Matrix operator*(const Matrix& other) const
	{
		int n = n_rows, m = other.n_cols;
		vector< vector<int> > result(n_rows, vector<int>(n_cols, 0));
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++) {
				for (int k = 0; k < n_cols; k++) {
					result[i][j] = (result[i][j] + mat[i][k] * 1ll * other.mat[k][j]) % MOD;
				}
			}
		return Matrix(result);
	}

};

Matrix Power(Matrix m, long long power)
{
	Matrix result = Matrix::identity_matrix(m.n_rows);

	while (power) {
		if (power & 1)
			result = result * m;
		m = m * m;
		power >>= 1;
	}

	return result;
}

int main()
{
	long long n, k;
	cin >> n >> k;
	g.resize(n, vector<int>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> g[i][j];
		}
	}
	Matrix ans = Power(g, k);
	int answer = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			answer = (answer + ans.mat[i][j]) % MOD;
		}
	}
	cout << answer;
	return 0;
}



Measured memory_bytes: 384
#include <algorithm>  //sort,二分探索,など
#include <array>
#include <bitset>         //固定長bit集合
#include <cmath>          //pow,logなど
#include <complex>        //複素数
#include <deque>          //両端アクセスのキュー
#include <functional>     //sortのgreater
#include <iomanip>        //setprecision(浮動小数点の出力の誤差)
#include <iostream>       //入出力
#include <map>            //map(辞書)s
#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>         //可変長配列

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#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 INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
  int N;
  cin >> N;
  ll ans = 0;
  cin >> ans;
  for (ll i = 1; i <= N; ++i) {
    if (i % 3 != 0 && i % 5 != 0) {
      ans+=i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3612
#include<stdio.h>

int isPrime(int x){
  int i;
  if ( x < 2 )return 0;
  else if ( x == 2 )return 1;
  if ( x % 2 == 0)return 0;
  for ( i = 3; i*i <= x; i+= 2) {
    if ( x % i == 0)return 0;
  }
  return 1;
}

int main(){
  int n,x,i;
  int cnt = 0;
   scanf("%d",&n);
  for( i = 0; i< n; i++){
  scanf("%d",&x);
  if ( isPrime(x) )cnt++;
}
printf("%d\n",cnt);

return 0;
}



Measured memory_bytes: 2052
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        char[] n = sc.nextLine().toCharArray();

        if(n[0]==n[1] && n[1]==n[2]){
            System.out.println("Yes");
        }else if(n[1]==n[2] && n[2]==n[3]){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

           

    }

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#include <algorithm>
#include <cmath>

int main(){
  int n, m;
  cin >> n >> m;
  
  //(Pi, (Yi, i))
  vector<pair<lli, pair<lli, lli>>> py(m);
  for(int i = 0; i < m; i++){
    cin >> py[i].first >> py[i].second.first;
    py[i].second.second = i;
  }
  
  sort(py.begin(), py.end());
  vector<int> pi_count(n, 0);
  vector<string> idlist(m, "");
  
  for(auto elem: py){
    int index = elem.second.second;
    int p = elem.first;
    
    for(int i = 0; i < 6-(int)log10(p)-1; i++)
      idlist[index] += '0';
    idlist[index] += to_string(p);
    
    pi_count[p]++;
    for(int i = 0; i < 6-(int)log10(pi_count[p])-1; i++)
      idlist[index] += '0';
    idlist[index] += to_string(pi_count[p]);
  }
  
  for(auto id: idlist)
    cout << id << endl;

}

Measured memory_bytes: 10880
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll N,A[100007],B[100007],ans=0,min,sum=0;
  vector<ll> plu;
  cin >> N;
  rep(i,N){
    cin >> A[i];
    sum+=A[i];
  }
  rep(i,N){
    cin >> B[i];
    sum-=B[i];
  }
  if(sum<0){
    cout << -1 << endl;
    return 0;
  }
  sum=0;
  rep(i,N){
    if(A[i]<B[i]){
      ans++;
      sum+=B[i]-A[i];
    }
    else{
      plu.pb(A[i]-B[i]);
    }
  }
  if(plu.size()>=1){
    sort(ALL(plu));
    reverse(ALL(plu));
  }
  ll k=0;
  while(sum>0){
    sum-=plu[k];
    ans++;
    k++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2936
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n=in();
	while(n--){
		int x,y,w,h;
		cin>>x>>y>>w>>h;
		int k;
		cin>>k;
		int res=0;
		while(k--){
			int xx,yy;
			cin>>xx>>yy;
			if(x<=xx&&xx<=x+w&&y<=yy&&yy<=y+h)res++;
		}
		cout<<res<<endl;
	}
	return 0;
}

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

vector<int> d(111111);

int main()
{
    int n;
    cin>>n;
    REP(i,n) {
        int td;
        cin>>td;
        d[td]++;
    }
    REP(i,101010) {
        d[i+1] += d[i];
        //cout<<d[i]<<" ";
    }
    int ans = COUNT(d,n/2);
    //ans += upper_bound(ALL(d), n / 2) - d.begin();
    //ans -= lower_bound(ALL(d), n / 2) - d.begin();
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define D(x) cerr << #x << " = " << (x) << '\n'
using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	int ans = 0;
	for(int a = 1; a <= n; ++ a)
		for(int b = 1; b <= n; ++ b)
			for(int c = 1; c <= n; ++ c)
				ans += __gcd(a, __gcd(b, c));
	cout << ans << '\n';
}


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

#define ll long long
ll MOD = 1000000007;

using namespace std;

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

    string s;
    cin >> s;

    int curr = 0;
    vector<int> v(2 * n);
    if (s[0] != 'B') {
        cout << "0";
        return 0;
    } else {
        v[0] = 1;
        curr = 1;
    }

    for (int i = 1; i < 2 * n; i++) {
        if (s[i] == 'B') {
            if (curr % 2 == 0) {
                v[i] = v[i - 1];
                curr += v[i];
            } else {
                v[i] = -1 * v[i - 1];
            }
        } else {
            if (curr % 2 == 1) {
                v[i] = v[i - 1];
                curr += v[i];
            } else {
                v[i] = -1 * v[i - 1];
            }
        }
    }

    // check
    int count = 0;
    bool poss = true;
    ll ans = 1;
    for (int i = 0; i < 2 * n; i++) {
        if (v[i] == 1)
            count++;
        else {
            count--;
            if (count < 0) {
                poss = false;
                break;
            } else {
                ans = (ans * (count + 1)) % MOD;
            }
        }
    }

    if (!poss || count != 0) {
        cout << "0";
        return 0;
    }

    ll fact = 1;
    for (int i = 1; i <= n; i++) {
        fact = (fact * i) % MOD;
    }

    cout << (fact * ans) % MOD;

    return 0;
}

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

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

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define MOD 1000000007

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

bool contain(vector<ll>& arr, ll x){
  bool res = false;
  for(auto a : arr){
    if(a == x){
      res = true;
      break;
    }
  } 
  return res;
}

int main(){
  ll X, N;
  cin >> X >> N;
  vector<ll> p(N);
  rep(i, N) cin >> p[i];

  ll ans;
  rep(diff, 101){
    if(!contain(p, X-diff)){
      ans = X - diff;
      break;
    }
    if(!contain(p, X+diff)){
      ans = X + diff;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3616
#include<cstdio>
int a,b;
int main()
{
	scanf("%d%d",&a,&b);
	if(a>b)a^=b^=a^=b;
	if(a==1&&b==2)puts("3");
	else if(a==1&&b==3)puts("2");
	else puts("1");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int a1,a2,a3,A1,A2,A3,b1,b2,b3,B1,B2,B3,c1,c2,c3,C1,C2,C3;
    int a4,A4,A5,A6,A7,A8,b4,B4,B5,B6,B7,B8,c4,C4,C5,C6,C7,C8;
    cin>>a1>>a2>>a3>>A1>>A2>>A3>>b1>>b2>>b3>>B1>>B2>>B3>>c1>>c2>>c3>>C1>>C2>>C3;
    a4=a1*3600+a2*60+a3;
    A4=A1*3600+A2*60+A3;
    A5=A4-a4;
    A6=A5/3600;
    A7=A5%3600/60;
    A8=A5%3600%60;
    b4=b1*3600+b2*60+b3;
    B4=B1*3600+B2*60+B3;
    B5=B4-b4;
    B6=B5/3600;
    B7=B5%3600/60;
    B8=B5%3600%60;
    c4=c1*3600+c2*60+c3;
    C4=C1*3600+C2*60+C3;
    C5=C4-c4;
    C6=C5/3600;
    C7=C5%3600/60;
    C8=C5%3600%60;
    cout<<A6<<" "<<A7<<" "<<A8<<endl;
    cout<<B6<<" "<<B7<<" "<<B8<<endl;
    cout<<C6<<" "<<C7<<" "<<C8<<endl;
    return 0;
}

Measured memory_bytes: 3104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	Scanner scan=new Scanner(System.in);
	String s=scan.next();
	char[] c=s.toCharArray();
	if(c[0]==c[1] && c[1]==c[2]) {
		System.out.println("Yes");
	}
	else if(c[1]==c[2]&&c[2]==c[3]) {
		System.out.println("Yes");
	}
	else {
		System.out.println("No");
	}
	

	}

}

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

template<class Monoid> struct SegmentTree {
	using Function = function< Monoid(Monoid, Monoid) >;

	int N; vector<Monoid> segment;
	const Function func;
	const Monoid id;

	SegmentTree(int n, const Function func, const Monoid id) : func(func), id(id) {
		N = 1;
		while (N < n) N <<= 1;
		segment.assign(2 * N, id);
	}

	void set(int num, Monoid x) {
		segment[N + num] = x;
	}
	void build() {
		for (int k = N - 1; k > 0; k--) {
			segment[k] = func(segment[2*k], segment[2*k+1]);
		}
	}
	void update(int k, Monoid x) {
		k = k + N; segment[k] = x;
		while(k >>= 1) {
			segment[k] = func(segment[2*k], segment[2*k+1]);
		}
	}

	// query:[a, b)
	Monoid query(int a, int b) {
		Monoid L = id; Monoid R = id; a += N; b += N;
		for (; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = func(L, segment[a++]);
			if (b & 1) R = func(segment[--b], R);
		}
		return func(L, R);
	}
	// 0-based numbering;
	Monoid operator[](const int k) const {
		return segment[N+k];
	}
};

struct data {
    int index, num;
};

data inf = {-1, (int) 1e9};

data mg(data a, data b) {
    if (a.num < b.num) return a;
    return b;
}

vector<vector<int>> e;
vector<pair<int, int>> pv;

void search(int l, int r, int par, vector<int> &v, SegmentTree<data> &odd, SegmentTree<data> &even) {
    if (r - l <= 0) return;
    data min1, min2;
    if (l & 1) {
        min1 = odd.query(l, r);
        min2 = even.query(min1.index, r);
    } else {
        min1 = even.query(l, r);
        min2 = odd.query(min1.index, r);
    }
    pv[min1.index] = {min1.num, min2.num};
    e[par].emplace_back(min1.index);
    search(l, min1.index, par, v, odd, even);
    search(min1.index+1, min2.index, min1.index, v, odd, even);
    search(min2.index+1, r, par, v, odd, even);
}

vector<int> ans;

void dfs(int root) {
    priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int>>, greater<pair<pair<int, int>, int>>> pq;
    for (auto x: e[root]) {
        pq.push({pv[x], x});
    }
    while (!pq.empty()) {
        pair<pair<int, int>, int> pp = pq.top(); pq.pop();
        for (auto x: e[pp.second]) {
            pq.push({pv[x], x});
        }
        ans.emplace_back(pp.first.first);
        ans.emplace_back(pp.first.second);
    }
}

int main(){
    int n; cin >> n;
    SegmentTree<data> odd(n, mg, inf), even(n, mg, inf);
    vector<int> v(n);
    e.resize(n+1); pv.resize(n+1);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        if (i&1) odd.set(i, {i, v[i]});
        else even.set(i, {i, v[i]});
    }
    odd.build(); even.build();
    search(0, n, n, v, odd, even);
    dfs(n);
    for (int i = 0; i < n; i++) {
        if (i) cout << " ";
        cout << ans[i];
    }
    cout << endl;
	return 0;
}

Measured memory_bytes: 72308
#include <bits/stdc++.h>
#define  maxs 202002
#define mme(i,j) memset(i,j,sizeof(i))
using namespace std;

int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        if(n==1||m==1){
            puts("1");
            continue;
        }
        if(n==2&&m==2){
            puts("1");
            continue;
        }
        int ans = (n-1)*(m-1);
        printf("%d\n",ans);
    }
    return 0;
}

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

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

	int n;
	cin >> n;
	int d, x;
	cin >> d >> x;
	int a[109];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= d; j += a[i]) {
			cnt++;
		}
	}
	cout << cnt + x << "\n";

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define DBG 0
void solve(int R, int N) {

	vector<int>xl(N), xr(N), h(N);
	rep(i, 0, N) {
		cin >> xl[i] >> xr[i] >> h[i];
	}

	const int offset = 25;
	vector<vector<int>>field(2 * offset, vector<int>(2 * offset));
	rep(i, 0, N) {
		rep(x, xl[i], xr[i]) {
			rep(y, 0, h[i]) {
				field[y][x + offset] = 1;
			}
		}
	}

	if (DBG) {
		for (int y = field.size() - 1; y >= 0; y--) {
			rep(x, 0, field[y].size()) {
				cout << field[y][x];
			}
			cout << endl;
		}
	}

	auto f = [&](double t) {
		auto g = [&](int x, int y) {
			double d = (x) * (x) + (t - y) * (t - y);
			return d < R * R;
		};
		int dx[] = { 0,1,1,0 }, dy[] = { 0,0,1,1 };
		bool ret = true;
		rep(i, 0, field.size()) {
			rep(j, 0, field[i].size()) {
				if (field[i][j] == 1)continue;
				int x = j - offset;
				int y = i;
				rep(k, 0, 4) {
					int nx = x + dx[k], ny = y + dy[k];
					if (g(nx, ny)) {
						return false;
					}
				}


			}
		}
		return true;
	};
	if (DBG) {
		cout << "f(-R) = " << f(-R) << endl;
		cout << "f(1000) = " << f(1000) << endl;
	}
	double l = -R, r = 20;
	for (int loop = 0; loop < 100; loop++) {
		double m = (l + r) / 2;
		if (f(m)) {
			l = m;
		}
		else {
			r = m;
		}
	}
	cout << l+R << endl;

}

signed main(int argc, char* argv[]) {
	int R, N;
	while (cin >> R >> N, R or N) {
		solve(R, N);
	}
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
#define MAX 200000
using namespace std;

long N, K, A[MAX];

void solve(){
    bool C[N]; fill(C, C + N, false);
    long D[N]; fill(D, D + N, 0);
    long i = 0, j = 1;
    while(1){
        i++;
        j = A[j - 1];
        if(C[j - 1]) break;
        C[j - 1] = true;
        D[j - 1] = i;
    }
    if(K > D[j - 1]){
        K = (K - D[j - 1]) % (i - D[j - 1]) + D[j - 1];
    }
    long ans = 1;
    for(int l = 0; l < K; l++){
        ans = A[ans - 1];
    }
    cout << ans << endl;
    return;
}

int main(){
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 6960
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    int n, z, w;
    cin >> n >> z >> w;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    cout << (n > 1 ? max(abs(a[n-2] - a[n-1]), abs(a[n-1] - w)) :
        abs(a[n-1] - w)) << endl;
}


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

void print_vec(vector<int> & v){
for (vector<int>::iterator vec_itr = begin(v); vec_itr!=end(v)-1; ++vec_itr ){
                cout << *vec_itr << " ";
            }
            cout << *(end(v)-1)<< "\n";
}

vector<int> & insertion_sort(vector<int> & vec, int const & n){
    int key;
    REP(i, n){
        key = vec[i];
        int j = i;
        while( j > 0 && vec[j-1] > key ){
            swap(vec[j-1], vec[j]);
            j--;
        }
        // print
        print_vec(vec);
    }
    return vec;
}

int main () {
    // input
    int n;
    cin >> n;
    vector<int> input(n, 0);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &input[i]);
    }

    insertion_sort(input, n);
}


Measured memory_bytes: 3240
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
prev=a[0]
s1=sum(b)
#ans=s1
ans=0
for i in range(1,len(a)):
  if a[i]==prev+1:
    ans+=c[prev-1]
  prev=a[i]
print(s1+ans)




Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int x=1000005;
int arr[x];
int gcd(int a,int b)
{
	if(a==0)
		return b;
	return gcd(b%a,a);
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	int a[n];
	int i;
	for(i=0;i<n;i++)
		cin>>a[i];
	memset(arr,0,sizeof(arr));
	for(i=0;i<n;i++)
		arr[a[i]]++;
	bool only_one=true;
	for(i=2;i<x;i++)
	{
		int cnt=0;
		for(int j=i;j<x;j+=i)
		{
			cnt+=arr[j];
		}
		if(cnt==n)
		{
			cout<<"not coprime"<<endl;
			return 0;
		}
		if(cnt>1)
			only_one=false;
	}
	if(only_one)
		cout<<"pairwise coprime";
	else
		cout<<"setwise coprime";
	return 0;
}

Measured memory_bytes: 11464
#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>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	int k;
	if (n % 2 == 0) {
		k = n / 2;
		for (int i = k; i >= 1; i--) {
			cout << a[2 * i - 1] << " ";
		}
		for (int i = 1; i <= k; i++) {
			cout << a[2 * i - 2] << " ";
		}
	}
	else {
		k = n / 2;
		for (int i = k; i >= 0; i--) {
			cout << a[2 * i] << " ";
		}
		for (int i = 1; i <= k; i++) {
			cout << a[2 * i - 1] << " ";
		}
	}
	return 0;
}

Measured memory_bytes: 3712
import java.util.*;

public class Main {

    static final int MOD=1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        int k = sc.nextInt();
        System.out.println(n[k-1]);

    }
}


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

int main(){
    ll n,x,y,z;
    cin>>n>>x>>y>>z;
    vector<vector<ll>> dp(n+1,vector<ll> (1<<(x+y+z),0));
    dp[0][0]=1;
    rep(i,n){
        rep(j,1<<(x+y+z)){
            rept(k,1,11){
                int l=(j*2+1)<<(k-1);
                bitset<17> b(l);
                if(b.test(z-1)&&b.test(y+z-1)&&b.test(x+y+z-1)) continue;
                (dp[i+1][l&((1<<x+y+z)-1)]+=dp[i][j])%=MOD;
            }
        }

    }
    ll ans=1;
    rep(i,n) (ans*=10)%=MOD;
    rep(i,1<<(x+y+z)){
        ans+=MOD-dp[n][i];
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 43392
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] imp = new int[3];
            var impline = Console.ReadLine().Split(' ');

            for(int i = 0; i < 3; ++i)
            {
                imp[i] = int.Parse(impline[i]);
              
            }

            Array.Sort(imp);
            if (imp[0] == 5 && imp[1] == 5 && imp[2] == 7)
            {
                Console.Write("YES");
            }
            else
            {
                Console.Write("NO");
            }
          

        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define SZ(x) (int)((x).size())
#define xx first
#define yy second
#define pii pair<int, int>



void solve() {
    string s;
    cin >> s;
    int ans = 0;
    int cnt = 0;
    for (int i = 0; i < 3; i++)
        if (s[i] == 'R')
            cnt++;
    if (cnt != 2) ans = cnt;
    else if (s[1] == 'S') ans = 1;
    else ans = 2;
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


Measured memory_bytes: 3628
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll a,b,c;cin>>a>>b>>c;
  if((c-a)*(c-b)<0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
  

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

int main() {
	int n,t,a;
	cin >> n >> t >> a;
	int k;
	float cc = 1111;
	for(int i = 1;i <= n;i++)
	{
		int h;
		cin >> h;
		float c = t - (0.006 * h);
		if(cc > abs(a - c))
		{
			cc = abs(a - c);
			k = i;
		}
	}
	cout << k << endl;
	return 0;
}


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

int main() {
  int n, ans = 999999999;

  cin >> n;

  vector<int> w(n);

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

  for (int i = 1; i < n; i++) {
    int s1 = 0, s2 = 0;
    for (int j = 0; j < n; j++) {
      if (j <= i)
        s1 += w[j];
      else
        s2 += w[j];
    }
    if (ans > abs(s1 - s2)) ans = abs(s1 - s2);
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		//while(scan.hasNext()){
			int n = scan.nextInt();
			int m = scan.nextInt();
			String[] card = new String[2*n];
			for(int i = 1;i <= 2*n;i++){
				card[i-1] = String.valueOf(i);
			}
			int k;
			for(int i = 0;i < m;i++){
				k = scan.nextInt();
				if(k == 0){
					card = rShuffle(card,n);
				}else{
					card = shuffle(card,k,n);
				}
			}
			for(int j = 0;j < 2*n;j++){
				System.out.println(card[j]);
			}
		//}
	}
	
	public static String[] rShuffle(String[] a,int n){
		String[] b = new String[a.length];
		for(int i = 0,j = 0;i < a.length;i+=2,j++){
			b[i] = a[j];
		}
		for(int i = 1,j = n;i < a.length;i+=2,j++){
			b[i] = a[j];
		}
		return b;
	}
	
	public static String[] shuffle(String[] a,int k,int n){
		String[] b = new String[a.length];
		for(int i = 0,j = k;j < 2*n;i++,j++){
			b[i] = a[j];
		}
		for(int i = 2*n-k,j = 0;j < k;i++,j++){
			b[i] = a[j];
		}
		return b;
	}
}

Measured memory_bytes: 23404
day = input()
     
if(day=="SUN"):
  print(7)
elif(day=="MON"):
  print(6)
elif(day=="TUE"):
  print(5)
elif(day=="WED"):
  print(4)
elif(day=="THU"):
  print(3)
elif(day=="FRI"):
  print(2)
elif(day=="SAT"):
  print(1)

Measured memory_bytes: 3060
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, D, A = in.next().toInt
  var hoge = new Array[(Long, Int)](N)
  for (i <- 0 until N) {
    val X, H = in.next().toInt
    hoge(i) = (X, H)
  }

  hoge = hoge.sorted

  // 
  val c = new Array[(Long, Int)](N+2) // (x, HP)
  c(N+1) = (Long.MaxValue, 0)
  for (i <- 1 to N) {
    c(i) = hoge(i-1)
  }

  def check(i: Int, n: Long): Boolean = {
    val (ind, _) = c(i)
    n < ind
  }

  // 条件を満たす最小の値を返す
  def binarySearch(min: Int, max: Int, n: Long): Int = {
    val mid: Int = (max + min) / 2
      (max - min) match{
      case 0 | 1 =>
        check(min, n) match{
          case true  => min
          case false => max
        }
      case _ =>
        (check(mid, n)) match{
          case true  => binarySearch(min, mid, n)
          case false => binarySearch(mid, max, n)
        }
    }
  }

  val memo = new Array[Long](N+2) // 適用爆弾数の調整値
  var hand = 0L
  var ans = 0L
  for (i <- 1 to N) {
    val (x, hp) = c(i)
    hand -= memo(i)

    if (hand * A < hp) {
      val fuga = hp - hand * A
      val num = (fuga + (A-1)) / A // 必要投下爆弾数

      ans += num
      hand += num
      // にぶたん使って - をメモる
      val ind = binarySearch(i+1, N+1, x.toLong + 2L*D)
      memo(ind) += num
    }
  }

  println(ans)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 94256
// atcoder/abc161/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.setf(std::ios_base::fixed);
  std::cout.precision(15);

  lli n, k;
  while (cin >> n >> k) {
    lli x = n % k;
    cout << min(x, abs(x - k)) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
n,h=map(int,input().split())
a,b=[],[]
for _ in range(n):
    A,B=map(int,input().split())
    a+=[A]
    b+=[B]
c=max(a)
b.sort()
ans=0
for i in b[::-1]:
    if i>c and h>0:
        h-=i
        ans+=1
    else:
        break
print(ans-(-h//c)*(h>0))

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

const int mod = 1000000007;

int main() {
    int n, m;
    cin >> n >> m;

    vector<int> ls(m);
    rep(i, m) {
        int l;
        cin >> l;
        ls[i] = l;
    }
    sort(ls.begin(), ls.end());


    vector<int> distances(m - 1);
    for (int i = 0; i < m - 1; i++) {
        int distance = ls[i + 1] - ls[i];
        distances[i] = distance;
    }

    sort(distances.rbegin(), distances.rend());

    ll ans = accumulate(distances.begin(), distances.end(), 0);

    for (int i = 0; i < n - 1; i++) {
        if (i >= m - 1) break;
        ans -= distances[i];
    }

    cout << ans << endl;

}



Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<cstdlib> 
#include<string>
#include<math.h>
#include<bitset>
#include<algorithm>
#include<vector>
#include<set>
#include<stack>
#include<queue>
using namespace std;



int main(){

	string s;

	cin >> s;

	int gn=0,pn=0,ans =0;

	for(int i=0;i<s.size();i++){
		//cout << gn << ' ' << pn << ' ' << ans << endl;
		if(gn==pn){
			if(s[i]=='g'){
				gn+=1;
			}else{
				gn+=1;
				ans-=1;
			}
		}else if(gn>pn){
			if(s[i]=='g'){
				pn+=1;
				ans+=1;
			}else{
				pn+=1;
			}
		}
	}
	cout << ans << endl;
	
	//while(1);
}




Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  string A, B, C;
  cin >> A >> B >> C;
  if(A[A.length()-1] == B[0] && B[B.length()-1] == C[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
const long long mod = 1000000007;
int main() {
	int N, D;
	scanf("%d %d", &N, &D);
	int **p = new int*[N];
	for (int i = 0; i < N; i++) {
		p[i] = new int[D];
		for (int j = 0; j < D; j++) {
			scanf("%d", p[i] + j);
		}
	}
	int res = 0;
	for (int i1 = 0; i1 < N; i1++) {
		for (int i2 = i1 + 1; i2 < N; i2++) {
			int d = 0;
			for (int j = 0; j < D; j++) {
				d += (p[i1][j] - p[i2][j])*(p[i1][j] - p[i2][j]);
			}
			for (int j = 0; j < 1000; j++) {
				if (d == j * j) {
					res++;
					break;
				}
			}
		}
	}
	printf("%d", res);
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<bitset>
typedef long long ll;
double pi=3.1415926535897931159979635;
using namespace std;


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,d;
    cin>>n;
    ll ar[n],x=0,a;
    for(int i=0; i<n; i++){
    cin>>ar[i]; 
    x^=ar[i];
    }
    for(int i=0; i<n; i++){
    a=x^ar[i];
    if(i==0) cout<<a;
    else cout<<" "<<a;
    }
    cout<<"\n";
    return 0;

}

Measured memory_bytes: 5028
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n,m,q = lr()
abcd = [lr() for i in range(q)]
def getAns(s, num, l):
    if l == n:
        ret = 0
        for a,b,c,d in abcd:
            a-=1
            b-=1
            if s[b]-s[a] == c:
                ret+=d
        return ret
    else:
        ret = 0
        for i in range(num, m+1):
            tmp = s.copy()
            tmp.append(i)
            ret = max(ret, getAns(tmp, i, l+1))
        return ret
print(getAns([], 1, 0))

Measured memory_bytes: 83096
#include<iostream>
#include<variant>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<climits>
#include<set>

using namespace std;

int main(void) {
	int x = 0;
	cin >> x;
	if (x)cout << 0;
	else cout << 1;
	return 0;
}

Measured memory_bytes: 3632
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<stdio.h>
int main(void){
    int a;
    char s[10000];
    scanf("%d%s",&a,s);
    if(a>=3200) printf("%s\n",s);
    if(a<3200) printf("red\n");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, k, arr[200000];
	cin >> n >> k;
	
	for(int i = 0; i < n; i++)
	{
		cin >> arr[i];
 	}
 	int L, R;
	L = 0;
	R = 1000000000;
	while(L+1!=R)
	{
		int M=(L+R)/2;
		long long c=0;
		for(int i=0;i<n;i++)
		{
			c += (arr[i]-1)/M; 
	 	 }
 		if(c<=k)R=M;
		else L=M;
	}
	cout<<R<<endl;
	return 0;
}

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

int main() {
    int n, ans = 0;
    cin >> n;
    vector<int> a(n), b(n), c(n-1);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n-1) cin >> c[i];

    rep(i,n) {
        if (i != n-1 && a[i] - a[i+1] == -1){
            ans += c[a[i]-1];
        }
        a[i]--;
        ans += b[a[i]];
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000

//ナップザックじゃ無いよ！
//マッチの本数についての動的計画法で十分解ける。
//まずは桁数でだいたい決まる。
//動的計画法の良いところは、辿ってきた最善経路の記録が残っていること。
//桁数増えるにつれ、左側に桁を増やしていってると考えれば、数値の大きい順に左側から決めていけば良い。

//文字列の大小の比較。辞書順。

int max(int a, int b){
  if(a>=b){
    return a;
  }
  else{
    return b;
  }
}


char min_char(char a, char b){
  int dif=a-b;
  if(dif>=0){
    return b;
  }
  else{
    return a;
  }
}

int max_char(int a, int b){
  int dif=a-b;
  if(dif<0){
    return b;
  }
  else{
    return a;
  }
}

int match(int a){
  if(a==1){
    return 2;
  }
  else if(a==7){
    return 3;
  }
  else if(a==4){
    return 4;
  }
  else if(a==2 || a==3 || a==5){
    return 5;
  }
  else if(a==6 || a==9){
    return 6;
  }
  else{
    return 7;
  }
}


int main(){
  char buf[1024];
  int N,M;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d %d", &N, &M);

  int *A=(int *)malloc(sizeof(int)*M);
  rep(i,M){
    scanf("%d",&A[i]);
  }

  int *dp=(int *)malloc(sizeof(int)*(N+1));
  dp[0]=0;
  srep(i,1,N+1){
    dp[i]=-1;
  }

  srep(i,1,N+1){
    int res=0;
    rep(j,M){
      if(i-match(A[j])>=0 && dp[i-match(A[j])]!=-1){
        res=max(res, dp[i-match(A[j])]+1);
      }
    }
    if(res==0){
      ;
    }
    else{
      dp[i]=res;
    }
  }

  int digit=dp[N];

  int current=N;
  int *ans=(int *)malloc(sizeof(int)*digit);
  rrep(i,digit){
    int res=0;
    rep(j,M){
      int temp=current-match(A[j]);
      if(temp>=0 && temp!=-1 && dp[temp]==dp[current]-1){
        res=max(res, A[j]);
      }
    }
    ans[i]=res;
    current-=match(res);
  }

  rrep(i,digit){
    printf("%d", ans[i]);
  }
  printf("\n");

  return 0;

}


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

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        int x;  cin >> x;
        v[x-1] = i;
    }
    for(int i = 0; i < n; i++)  cout << v[i]+1 << " \n"[i+1==n];
    return 0;
}

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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF ((1LL<<62)-1)
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME ((1ll<<61)-1)

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

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

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

bool isout(int h, int w, int H, int W) {
	return ( h<0 || h>=H || w<0 || w>=W );
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int N;
intvec ans;

void input() {
	cin>>N;
}

void solve() {
	if(N==0) {
		cout<<0<<endl;
		return;
	}

	for(int i=0; N!=0; i++) {
		if(N%2==0) {
			ans.pushb(0);
			N/=2;
		}
		else {
			ans.pushb(1);
			if(i%2==0) N--;
			else       N++;
			N/=2;
		}
	}

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

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int x, y; cin >> x >> y;
	int ans = abs(abs(y) - abs(x));
	if (x < 0) {
		if (y != 0) {
			if (y < 0) {
				if (abs(x) < abs(y)) {
					ans += 2;
				}
			}
			else {
				ans++;
			}
		}
	}
	else {
		if (y == 0)ans++;
		else if (y < 0) {
			ans++;
		}
		else {
			if (abs(x) > abs(y))ans += 2;
		}
		
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200001];
int b[200001];
int c[200001];
int n;
int dp[200001][3][3][3];

int rec(int idx,int count1,int count2,int count3)
{
    if(dp[idx][count1][count2][count3]!=-1)
        return dp[idx][count1][count2][count3];
    if(idx==n) return 0;
    if(count1==1) return dp[idx][count1][count2][count3]=max((b[idx]+rec(idx+1,0,1,0)),(c[idx]+rec(idx+1,0,0,1)));
    if(count2==1) return dp[idx][count1][count2][count3]=max((c[idx]+rec(idx+1,0,0,1)),(a[idx]+rec(idx+1,1,0,0)));
    if(count3==1) return dp[idx][count1][count2][count3]=max((a[idx]+rec(idx+1,1,0,0)),(b[idx]+rec(idx+1,0,1,0)));
    return dp[idx][count1][count2][count3]=max((a[idx]+rec(idx+1,1,0,0)),max((b[idx]+rec(idx+1,0,1,0)),(c[idx]+rec(idx+1,0,0,1))));

}


int main()
{
    for(int i=0;i<200001;i++)
    {
        for(int j=0;j<3;j++)
        {
            for(int k=0;k<3;k++)
            {
                for(int y=0;y<3;y++)
                {
                 dp[i][j][k][y]=-1;
                }
            }
        }
    }
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        cin>>b[i]>>c[i];
        
    }
    cout<<rec(0,0,0,0);








}

Measured memory_bytes: 30976