akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

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

//main code

int main(int argc, char const* argv[])
{
    int n;
    cin >> n;
    VL a(n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int ave = int(round(double(sum) / double(n)));
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += pow(a[i] - ave,2);
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}
// }}}
/* vim:set foldmethod=marker: */

void solve(){
    int k,s;
    cin >> k >> s;

    int ans=0;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            int z = s-x-y;
            if (0 <= z && z <= k) {
                ans++;
            }
        }
    }

    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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 prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int h, w, k;
    cin >> h >> w >> k;
    vs s(h);
    REP(i, h) cin >> s[i];

    ll ans = 0;
    REP(i, 1 << h) {
        vs t = s;
        REP(j, h) {
            if ((1 & i >> j) == 1) {
                REP(x, w) t[j][x] = '.';
            }
        }
        REP(j, 1 << w) {
            vs u = t;
            REP(l, w) {
                if ((1 & j >> l) == 1) {
                    REP(x, h) u[x][l] = '.';
                }
            }
            int c = 0;
            REP(p, h) REP(q, w) if (u[p][q] == '#') c++;
            if (c == k) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main (){
  int H,W,n;
  cin>>H>>W;
  n=0;
  vector<vector<char>> vec(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>vec.at(i).at(j);
    }
  }
  for(int i=0;i<H;i++){
    n=0;
    for(int j=0;j<W;j++){
      if(vec.at(i).at(j)=='.'){
        n++;
      }
      if(n==W){
        for(int k=0;k<W;k++){
          vec.at(i).at(k)='0';
        }
      }
    }
  }
  for(int i=0;i<W;i++){
    n=0;
    for(int j=0;j<H;j++){
      if(vec.at(j).at(i)=='.'||vec.at(j).at(i)=='0'){
        n++;
      }
      if(n==H){
        for(int k=0;k<H;k++){
          vec.at(k).at(i)='0';
        }
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(vec.at(i).at(j)!='0'){
        cout<<vec.at(i).at(j);
      }
      if(j==W-1){
        cout<<endl;
      }
    }
  }
}




Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define debug(x) cerr << #x << ": " << x << "\n";
#define INF (1<<29) //53687091
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=(int) 1e5;
static const int MOD=(int) 1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
bool XOR(int a,int b){ return !a != !b; }
bool l[101];


int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    for(int k=0;4*k<=N;k++){
        for(int l=0;7*l+4*k<=N;l++){
            if(4*k+7*l==N){
                cout<< "Yes" <<"\n";
                return 0;
            }
        }
    }
    cout <<"No" <<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  





void solve(){
	int r , d , x ;
	cin >> r >> d >> x;
	int ans[12];
	ans[1] = x*r -d ;
	int n = 10;
	fr(i,2,n){
		ans[i] = ans[i-1]*r - d;
	}
	fr(i,1,n) cout << ans[i] << endl;
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3640
long long n, k, i, a[200000], f[200000], top, bottom, med;

int cmp (const void *a, const void *b) {
    return *((long long*)a) - *((long long*)b);
}

int rcmp (const void *a, const void *b) {
    return - (*((long long*)a) - *((long long*)b));
}

int test (long long targetTime) {
    long long sum = 0, i, tmp;
    for (i = 0; i < n; i++) {
        tmp = a[i] - targetTime / f[i];
        if (tmp > 0) sum += tmp;
    }
    return sum > k;
}

int main (void) {
    scanf("%lld %lld", &n, &k);
    for (i = 0; i < n; i++) scanf("%lld", &a[i]);
    for (i = 0; i < n; i++) scanf("%lld", &f[i]);

    qsort(a, n, sizeof(long long), cmp);
    qsort(f, n, sizeof(long long), rcmp);

    /* binary search */
    for (i = 0; i < n; i++) if (a[i] * f[i] > top) top = a[i] * f[i];
    bottom = -1;

    while (top - bottom > 1) {
        med = (top + bottom) / 2;
        if (test(med)) {
            bottom = med;
        } else {
            top = med;
        }
    }

    printf("%lld\n", top);
}


Measured memory_bytes: 4860
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define mod       1000000007
#define double    long double
#define ull       unsigned long long
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define rev       greater<int>()
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define ps(s)     for(auto i:s){cout<<i<<" ";}
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"This is test"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
void solve(){
	ll n;cin>>n;
	ll arr[n];for(int i=0;i<n;i++){cin>>arr[i];}
	sort(arr,arr+n);
	double ans=arr[0];
	for(int i=1;i<n;i++){
		ans=(ans+arr[i])/2;
	}
	cout<<sp(ans,10);
}
int32_t main(){
	kehsihba();
	//init();
	ll t=1;
	//cin>>t;
	for(int k=1;k<=t;k++){
		//cout<<"Case "<<k<<": ";
		solve();
		//e;
	}
}

Measured memory_bytes: 3792
fun main() {
    var n = 0
    nextInt()
    val values = nextIntList()
    values.forEach {
        n = n xor it
    }
    values.forEach {
        print(n xor it)
        if (it == values.lastIndex){
            println()
        } else {
            print(' ')
        }
    }
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }


Measured memory_bytes: 73468
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
int field[102][102];

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	for(int i = 0 ; i < 102 ; i++)
			for(int j = 0 ; j < 102 ; j++)  field[i][j] = 0;

	int H, W;  cin >> H >> W;
	int N;  cin >> N;
	V a(N);  VECCIN(a);

	int num = 1, count = 0;
	for(int i = 1 ; i <= H ; i++){
			//蛇状に進んでいく
			if(i % 2){
					for(int j = 1 ; j <= W ; j++){
							field[i][j] = num;
							count++;
							if(count == a[num - 1]){
									num += 1;
									count = 0;
							}
					}
			}else{
					for(int j = W ; 1 <= j ; j--){
							field[i][j] = num;
							count++;
							if(count == a[num - 1]){
									num += 1;
									count = 0;
							}
					}
			}
	}

	for(int i = 1 ; i <= H ; i++){
		for(int j = 1 ; j <= W ; j++)  cout << field[i][j] << " ";
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
using namespace std;
typedef long long ll;
//#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i =0;i<n;++i)
//#define mod (ll)(1e9+7)
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    int ans = 0;
    ans+=(N-1)/(K-1);
    if((N-1)%(K-1)>0)ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    ll n, d, a; cin >> n >> d >> a;
    typedef pair<ll, ll> P;
    vector<P> xh(n);
    rep(i,n) {
        ll x, h; cin >> x >> h;
        xh[i].first = x, xh[i].second = h;
    }
    sort(xh.begin(), xh.end());

    priority_queue<P, vector<P>, greater<P>> que;
    ll sum = 0, pos = 0;
    ll ans = 0;
    rep(i,n) {
        pos = xh[i].first;
        while (!que.empty() && que.top().first <= pos) {
            sum -= que.top().second;
            que.pop();
        }
        xh[i].second -= sum;
        if (xh[i].second > 0) {
            ll tmp = (xh[i].second+a-1)/a; // 攻撃回数
            ans += tmp;
            que.push({xh[i].first+d*2+1, tmp*a});
            sum += tmp*a;
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
using vi = vector<int>;
using vll = vector<ll>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
    char c;
    cin >> c;
    cout << char(c + 1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i < (int)(n);i++)
using namespace std;
bool cmp(pair<int64_t,int64_t> a,pair<int64_t,int64_t> b){
  return a.first + a.second < b.first + b.second;
}
int main(){
  int n;
  cin >> n;
  vector<pair<int64_t,int64_t>> ab(n);
  rep(i,n) cin >> ab.at(i).first >> ab.at(i).second;
  sort(ab.begin(),ab.end(),cmp);
  reverse(ab.begin(),ab.end());
  /*rep(i,n){
    cout << ab.at(i).first << "|" << ab.at(i).second << endl;
  }*/
  int64_t takahashi = 0;
  int64_t aoki = 0;
  rep(i,n){
    if(i % 2 == 0){
      takahashi += ab.at(i).first;
    }else{
      aoki += ab.at(i).second;
    }
  }
  cout << takahashi - aoki << endl;
}
  
  
  

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

ll N, M;
vector<ll> A;

ll sum[101010];

// x以上になる値がいくつあるか

bool ok(ll x) {
    ll ret = 0;
    rep(i, N) {
        ret += N - (lower_bound(A.begin(), A.end(), x-A[i]) - A.begin());
    }
    return ret >= M;
}

int main() {
    cin >> N >> M;

    A.resize(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    // rep(i, N) {
    //     cout << A[i] << " ";
    // }
    // cout << endl;

    rep(i, N) {
        sum[i+1] += sum[i] + A[i];
    }

    ll l = 0, r = 1e8;
    while (r-l>1) {
        ll m = (r + l) / 2;
        if (ok(m)) {
            l = m;
        }
        else {
            r = m;
        }
    }

    ll x = l;
    ll ans = 0;
    ll num = 0;
    for (int i=N-1; i>=0; --i) {
        if (num >= M) break;
        // 左手が A[i] のときにX以上得られる握手の仕方
        int idx = (upper_bound(A.begin(), A.end(), x-A[i]) - A.begin());
        ll tmp = N - idx;
        //ans += A[i] * min(M-num, tmp) + (sum[N] - sum[min((ll)idx, N-min(M-num, tmp))]);
        ans += (sum[N] - sum[idx]) + tmp * A[i];
        //cout << A[i] << ": " << idx << ", " << N-min(M-num, tmp) << ", " << num << endl;

        num += tmp;
    }
    ans -= (num - M) * x;
    cout << ans << endl;
}


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

int main()
{
    int x,y;
    cin>>x>>y;
    if(y%2){
        cout<<"No"<<endl;
        return 0;
    }
    if(2*x <= y && y <= 4*x){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int k, p;
		cin >> k >> p;
		if (k%p == 0) cout << p << endl;
		else cout << k%p << endl;
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll A, B, VA, VB; cin >> A >> VA >> B >> VB;
    ll T; cin >> T;
    ll diff = VA - VB;
    if(diff <= 0) cout << "NO" << endl;
    else{
        ll dist = abs(A-B);
        if(diff*T >= dist) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int MOD = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(){
  int n;
  cin >> n;
  
  long long int sum = 0;
  for (int i = 1; i < n; i++)
  {
  	sum += i;
  }
  
  cout << sum;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdio>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
const int N = 200007;
const int M = 15005;
const int offset = 7500;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
const double eps = 1e-20;
int n,m;
char s[N];
int main()
{
    while (~scanf("%s",s))
    {
        printf("ABC%s\n", s);
    }
    return 0;
}

/*


*/

Measured memory_bytes: 256
#coding:utf-8
N, T = map(int, input().split())
#ありえるコストの最大値+1で初期化しておく
ans = 1001

for _ in range(N):
    c, t = map(int, input().split())
    if t <= T:
        ans = min(ans, c)

if ans < 1001:
    print(ans)
else:
    print('TLE')

Measured memory_bytes: 3060
#include<stdio.h>
int main (void)
{
  int N,m,l=0;
  scanf("%d",&N);
  m=N;
  while(m!=0){
    l=l+m%10;
    m=m/10;
  }
  if(N%l==0)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
  

Measured memory_bytes: 128
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let kn = readInts()
    let (k, n) = (kn[0],kn[1])
    let aryN = readInts()
    var ans = aryN[0] - aryN[n - 1] + k
    for i in 0..<n - 1 {
        ans = max(ans, aryN[i + 1] - aryN[i])
    }
    
    print(k - ans)
}

main()




Measured memory_bytes: 24628
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 810114514
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int long long 

signed main(){
    int H,W;
    bool OK=0;
    char s[54][54];
    REP(i,54){REP(j,54){s[i][j]='#';}}
    cin >> H >> W;
    REP(i,H){REP(j,W){cin >> s[i+1][j+1];}}
    REP(i,H){
        REP(j,W){
            if(s[i+1][j+1]=='#'){
                if(s[i][j+1]=='.'&&s[i+1][j]=='.'&&s[i+2][j+1]=='.'&&s[i+1][j+2]=='.'){
                    OK=1;
                }
            }
        }
    }
    Yes(!OK);
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

# In[29]:


# Q, H, S, D = map(int, input().split())
# N = int(input())


# In[30]:


# volume = [0.25, 0.5, 1, 2]
# unit_c = [Q*4, H*2, S, D/2]
# act_c = [Q, H, S, D]

# mylist = [[volume[i], unit_c[i], act_c[i]] for i in range(len(volume))]
# mylist_sorted = sorted(mylist, key=lambda x: x[1])

# ans = 0
# target = N
# for v,c,a in mylist_sorted:
#     count = target//v
#     ans += count*a
#     target -= v*count 
# #     print(v, c, a, count, target)
#     if target == 0:
#         break
# print(int(ans))


# In[ ]:


q, h, s, d = map(int, input().split())
n = int(input())
 
cost_per_2l = min(q*8, h*4, s*2, d)
cost_per_1l = min(q*4, h*2, s)
 
a = n // 2
b = n % 2
 
print(a*cost_per_2l + b*cost_per_1l)



Measured memory_bytes: 2940
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
#include <sstream>
#include <iterator>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
const  long long INF = 1LL << 60;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}



int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }

    return true;
}

map<ll,ll> mp;

auto findFactors(ll num){
	
    ll i;
    while (num % 2 == 0){ // 偶数の素数は2のみ
        if(mp.count(2)){
			mp[2] = mp[2] + 1;
		}
		else{
			mp[2] = 1;
		}
        num /= 2;
    }
    for (i = 3; i <= num; i++){ // 他の素数で割っていく
        while (num % i == 0){
			if(mp.count(i)){
			mp[i] = mp[i] + 1;
		}
		else{
			mp[i] = 1;
		}
            num /= i;
        }
    }
    return 0;
}
ll kaizyou(ll n){
    if(n == 1){
        return 1;
    }
    else{
        return (n * kaizyou(n-1)) % 1000000007;
    }
}



int main(){
ll x; cin >> x;
if(x <= 5) cout << 1 << endl;
else{
    ll cnt,y;
    cnt = x / 11;
    y = x % 11;
    if(y == 0){
        cout << cnt * 2<< endl;
    }
    else if(y <= 6){
        cout << cnt * 2 + 1 << endl;
    }
    else{
        cout << cnt * 2 + 2 << endl;
    }
}
}






Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
a.sort()
res = 0
for i in range(2*n)[::2]:
    res += a[i]
print(res)


Measured memory_bytes: 62828
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#define N 500005
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define INF 1000000010
template<typename T> inline T max(T a,T b,T c){
    return max(a,max(b,c));
}
template<typename T> inline T min(T a,T b,T c){
    return min(a,min(b,c));
}
template<typename T> inline T max(T a,T b,T c,T d){
    return max(a,max(b,c,d));
}
template<typename T> inline T min(T a,T b,T c,T d){
    return min(a,min(b,c,d));
}
const int  dx[]={0,1,0,-1,0,1,-1,1,-1};
const int  dy[]={0,0,1,0,-1,1,-1,-1,1};

typedef long long ll;
using namespace std;
//coding...........................................
int main()
{
     char a[N];
     int num[5]={0};
     int flag=0;
     scanf("%s",a);
     int len=strlen(a);
     for (int i=0;i<len;i++)
        num[a[i]-'a']++;
     sort(num,num+3);
     if (abs(num[2]-num[1])<=1&&abs(num[2]-num[0])<=1&&abs(num[1]-num[0])<=1)
        cout << "YES" << endl;
     else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(){
    int n,x;
    while(true){
        scanf("%d%d",&n,&x);
        if (n==0&&x==0)break;
        int a=0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                for(int k=1;k<=n;k++){
                    if(i+j+k==x&&i<j&&j<k){
                        a++;
                    }
                }
            }
        }
        printf("%d\n",a);
    }
}




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

vector<int> v;

int dfs(int x){
	if(x==1)return 1;
	return 2*dfs(x/2) + 1;
}
signed main()
{
	
	int n;cin>>n;
	cout<<dfs(n);

	getchar();getchar();
	
}

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

int main(){
  int d, t, s;
  cin >> d >> t >> s;
  
  if(s*t >= d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  
  return 0;
  
}

Measured memory_bytes: 3632
import java.util.Scanner;

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

        String line = sc.next();
        int m, h;

        String first, second;

        while (!line.equals("-")) {
            m = sc.nextInt();
            for (int i = 0; i < m; i++) {
                h = sc.nextInt();
                first = line.substring(0,h);
                second = line.substring(h,line.length());

                line = second + first;
            }

            System.out.println(line);

            line = sc.next();

        }

        sc.close();
    }
}


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

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
int main(){
  int a;
  string b;
  cin >> a >> b;
  if (b.length()<=a){
    cout << b;
    return 0;
  }
  string c;
  rep(i, a) { c += b[i];
  }
  c += "...";
  cout << c;
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列(スタックとしても使える)
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
//ソート クイックだからO(NlogN)
sort(all(list));
sort(all(list), greater<int>());

//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";


//配列の最小最大(Nは要素数)
*min_element(all(c))
*max_element(all(c))

//a[0]からa[N]を逆順にする(計算量はO(N))
reverse(all(a));
//listの末尾に要素を追加
list.push_back(10);
//listの末尾から要素を削除
list.pop_back();
//空ですか？
list.empty()



//キュー(待ち行列)
//定義
queue<int> a;
//追加
a.push(x);
//取る
a.pop();
//チェック
a.front()
//サイズ
a.size()
//空ですか
a.empty()



//優先度付きキュー※全部計算量がO(NlogN)あるので注意
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義
priority_queue<int, vector<int>, greater<int>> Q1;
// double 型の要素を持ち、最も大きい値を取り出す形の priority_queueを定義
priority_queue<double, vector<double>, less<double>> Q2;
//追加
a.push(x);
//取る
a.pop();
//一番小さいの教えて下さい
a.top()
//サイズ
a.size()
//空ですか
a.empty()



//部分文字列
//添字3から5文字
s.substr(3,5)
//添字3から全部
s.substr(3)

//入れ替え
swap(a,b);



// int 型の番地に string 型の変数を記録する場合（2^31 要素の string型配列と同じような感じ）
map<int, string> mp;
for (auto itr =mp.begin(); itr != mp.end(); itr++) {
    //順番にマップを眺める。itr->firstでキー、itr->secondがバリュー
}

//ソート済みのaの中で初めてx以上になるインデックスを返す
lower_bound(all(a), x) - a

//next_permutation
do {
  //ここにパーテーションがくる
} while (next_permutation(s.begin(), s.end()));

//set
set<int> hoge;
hoge.insert(50);  //hogeに挿入。重複は無視される。
hoge.insert(20);  //内部は小さい順に並ぶ
hoge.erase(50);   //hogeから消し去る。
//40以上である最小の要素を指すイテレーターを返す。
//もちろんそんなものはないからEndが出力される
auto itr1 = Set.lower_bound(40);
if (itr1 == Set.end()) cout << "End" << endl;
else cout << (*itr1) << endl;

//pair
//たくさんつくる
vector<pair<int,string>> hoge(10);
//参照
hoge[0].first
sort(all(hoge), greater<pair<int, string>>());




*/


Measured memory_bytes: 3628
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>

using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 2 * 1000 * 100 + 47;
const int MIN = 404;
const int MOD = INF;



int main()
{
    // freopen("in.txt", "r", stdin);
    LL n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    LL L = a - n * d + d;
    LL R = a - n * c + c;
    FOR(i, 0, n)
    {
        if (b >= L && b <= R)
        {
            cout << "YES" << endl;
            return 0;
        }
        L += c + d;
        R += c + d;

    }
    cout << "NO" << endl;
    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
const int N = 10010, B = N * 16, M = B + N * 2;
int n, x[N], y[N];
 
struct edge{ int to, pre; }e[(N * 2 * 4 + N * 2 * 16 * 2) * 2 * 2]; int u[M], l = 0;
void ins(int a, int b) { e[++l] = (edge){b, u[a]}, u[a] = l; }
#define v e[i].to
#define reg(i,a) for(int i = u[a]; i; i = e[i].pre)
void add(int a, int b) { ins(a, b), ins(b^1, a^1); }
 
pair<int, int> nd[N * 2];
#define mid ((l + r) >> 1)
#define lc (x << 1)
#define rc (lc | 1)
#define lcq lc, l, mid
#define rcq rc, mid + 1, r
void build(int x, int l, int r) {
	if (l == r) 
		add(x << 1, nd[l].second ^ 1); 
	else 
		build(lcq), build(rcq), 
		add(x << 1, lc << 1), add(x << 1, rc << 1);
}
 
int a, b, c;
 
void modi(int x, int l, int r) {
	if (a <= l && r <= b) add(c, x << 1);
	else {
		if (a <= mid) modi(lcq); 
		if (b >  mid) modi(rcq);
	}
}
 
int pre[M], low[M], dfn = 0; 
int st[M], top = 0, cnt = 0, scc[M];
void dfs(int x) {
	pre[x] = low[x] = ++dfn; st[top++] = x;
	reg(i,x) if (!pre[v]) dfs(v), low[x] = min(low[x], low[v]);
	else if (!scc[v]) low[x] = min(low[x], pre[v]);
	if (pre[x] == low[x]) {
		cnt++; st[top] = 0;
		while (st[top] != x) top--, scc[st[top]] = cnt;
	}
}
 
void tarjan() {
	memset(pre, 0, sizeof(pre)), memset(scc,0,sizeof(scc));dfn = 0;
	rep(i,1,n * 2) if (!pre[nd[i].second]) dfs(nd[i].second);
}
 
bool check(int m) {
	memset(u, 0, sizeof(u)); l = 0;
	rep(i,1,n) 
		nd[i*2-1] = mp(x[i], B + (i << 1)), 
		nd[i*2] = mp(y[i],B + ((i << 1) | 1));
	sort(nd + 1, nd + 2 * n + 1);
	build(1, 1, n * 2);
	rep(i,1,n * 2) {
		int t = lower_bound(nd + 1, nd + n * 2 + 1, mp(nd[i].first - m + 1, 0)) - nd;
		a = t, b = i - 1, c = nd[i].second; if (a <= b) modi(1, 1, n * 2);
		t = lower_bound(nd + 1, nd + n * 2 + 1, mp(nd[i].first + m - 1, int(1e9))) - nd;
		a = i + 1, b = t - 1, c = nd[i].second; if (a <= b) modi(1, 1, n * 2);
	}
	tarjan();
	rep(i,1,2 * n) if (scc[nd[i].second] == scc[nd[i].second ^ 1]) return false;
	return true;
}
 
int main() {
	scanf("%d",&n); rep(i,1,n) scanf("%d%d",&x[i],&y[i]);
	int l = 0, r = 1e9 + 1;
	while (l + 1 < r) {
		int m = (l + r) >> 1;
		if (check(m)) l = m; else r = m;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 18304
import java.util.Scanner

object Main extends App{
  val sc = new Scanner(System.in)

  val a = sc.nextLong
  val b = sc.nextLong
  val c = sc.nextLong
  val d = sc.nextLong

  val res = target(b) - target(a - 1)

  println(res)

  def gcd(a: Long, b: Long): Long ={
    (a,b) match{
      case (x,y) if y == 0 => x
      case (x,y) if x < y  => gcd(y, x)
      case (x,y)           => gcd(y, x % y)
    }
  }

  def target(l: Long): Long =
    l - ( l/c + l/d - l/( c * d /gcd(c,d) ) )



}


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

struct Vector{
	double x,y,z;
	Vector(){}
	Vector(double x,double y,double z):x(x),y(y),z(z){}
	double norm(){return x*x+y*y+z*z;}
	double abs(){return sqrt(norm());}
	Vector normalize(){
		double d=abs();
		return Vector(x/=d,y/=d,z/=d);
	}
	Vector operator+(const Vector&u)const{
		return Vector(x+u.x,y+u.y,z+u.z);
	}
	Vector operator-(const Vector&u)const{
		return Vector(x-u.x,y-u.y,z-u.z);
	}
	double dot(const Vector&u)const{
		return x*u.x+y*u.y+z*u.z;
	}
};
struct Sphere{
	Vector p;
	double r;
	Sphere(){}
	Sphere(Vector p,double r):p(p),r(r){}
};
struct Ray{
	Vector p,d;
	Ray(Vector p,Vector d):p(p),d(d){}
	double intersect(Sphere c){
		d.normalize();
		double B=d.dot(p-c.p);
		double C=(p-c.p).norm()-c.r*c.r;
		double D=B*B-C;
		if(D<0)return -1;
		double E=sqrt(D);
		if(-B+E<EPS)return -1;
		if(-B-E>EPS)return -B-E;
		return -B+E;
	}
};

Sphere s[100];
ll l[100];

int main(){
	int n,q;scanf("%d%d",&n,&q);
	rep(i,n){
		double x,y,z,r;
		cin>>x>>y>>z>>r>>l[i];
		s[i]=Sphere(Vector(x,y,z),r);
	}
	rep(i,q){
		double sx,sy,sz;cin>>sx>>sy>>sz;
		double gx,gy,gz;cin>>gx>>gy>>gz;
		Ray L(Vector(sx,sy,sz),Vector(gx,gy,gz)-Vector(sx,sy,sz));
		double T=(Vector(gx,gy,gz)-Vector(sx,sy,sz)).abs();
		ll ans=0;
		rep(j,n){
			double t=L.intersect(s[j]);
			if(t>EPS&&t<=T)ans+=l[j];
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3264
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.12f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
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 A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int N; cin >> N;
    int dp[100100];
    int h[100100];
    Fill(dp, 1001001001);
    dp[0] = 0;
    rep(i,0,N) cin >> h[i];
    rep(i,1,N){
        chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if(i > 1) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 4400
N,A,B,C = map(int,input().split())
def sum3(dict_):
    ans = []
    for _ in range(N):
        xy = input()
        x = xy[0] 
        y = xy[1]
        if dict_[x]==0 and dict_[y]==0:
            return False, []
        elif dict_[x]>=dict_[y]:
            dict_[x] -= 1
            dict_[y] += 1
            ans.append(y)
        else:
            dict_[y] -= 1
            dict_[x] += 1
            ans.append(x)
    return True, ans
def sum2(dict_):
    ans = []
    flag = True
    q_list = []
    for _ in range(N):
        q_list.append(input())
    for i in range(N):
        xy = q_list[i]
        x = xy[0]
        y = xy[1]
        if (dict_[x]>=1 and dict_[y]==0):
            dict_[x]-=1
            dict_[y]+=1
            ans.append(y)
        elif (dict_[y]>=1 and dict_[x]==0):
            dict_[y]-=1
            dict_[x]+=1
            ans.append(x)
        elif  (dict_[x]==1 and dict_[y]==1):
            if i==N-1:
                ans.append(x)
            else:
                next_xy = q_list[i+1]
                if xy==next_xy: 
                    dict_[x]+=1
                    dict_[y]-=1
                    ans.append(x)
                elif (x in next_xy):
                    dict_[x]+=1
                    dict_[y]-=1
                    ans.append(x)
                else:
                    dict_[y]+=1
                    dict_[x]-=1
                    ans.append(y)
        else:
            return False, []
    return True,ans
def sum1(dict_):
    ans = []
    flag = True
    for _ in range(N):
        xy = input()
        x = xy[0] 
        y = xy[1]
        if dict_[x]==1:
            dict_[x]-=1
            dict_[y]+=1
            ans.append(y)
        elif dict_[y]==1:
            dict_[y]-=1
            dict_[x]+=1
            ans.append(x)
        else:
            flag = False
            return flag,[]
    return flag, ans
def s0(dict_):
    return False, []
dict_ = {"A":A,"B":B,"C":C}
sum_ = A+B+C
if sum_>=3:
    flag, ans = sum3(dict_)
elif sum_==2:
    flag, ans = sum2(dict_)
elif sum_==1:
    flag, ans = sum1(dict_)
elif sum_==0:
    flag, ans = False, []
if flag:
    print('Yes')
    for i in range(N):
        print(ans[i])
else:
    print("No")  







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

int main()
{	
	int N;
	long long K;
	cin >> N >> K;

	for (int man = 0; man <= N; man++) {
		for (int gosen = 0; gosen <= N - man; gosen++) {
			long long nokori = K - (10000 * man + 5000 * gosen);
			if (nokori % 1000 == 0 && nokori >= 0) {
				int sen = nokori / 1000;
				if (N == man + gosen + sen) {
					cout << man << " " << gosen << " " << sen << endl;
					return 0;
				}
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;

}

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

int main() {
	int n;
	cin>>n;
	vector<long double> store;
	for(int i = 0 ; i < n ;i++){
		long double temp;
		cin>>temp;
		store.push_back(1-temp);
	}                                                            
	vector<vector<long double> > dp(n+1 , vector<long double>(n+1,0));
	dp[0][0] = 1.000000000;
	for(int i = 1 ; i <=n ; i++){
		dp[0][i] = dp[0][i-1]*(1-store[i-1]); 
		dp[i][0] = dp[i-1][0]*store[i-1];
	}
	for(int i = 1 ; i <= n; i ++){
		for(int j = 1 ; j <=n && (i+j)<=n ; j++){
			dp[i][j] = dp[i][j-1]*(1-store[i+j-1]);
			dp[i][j] += dp[i-1][j]*store[i+j-1];
		}
	}
	int head = n/2 +1 ;
	int tail = n - head;
	long double ans = 0 ;
	while(tail>=0){
		ans+=dp[tail][head];
		head++;
		tail--;
	}
	cout<<setprecision(12);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 141056
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
using namespace std;

int main()
{
    int K, T;
    scanf("%d%d", &K, &T);
    vector<int> a(T);
    int max = 0;
    REP (i, T) {
        scanf("%d", &a[i]);
        if (max < a[i]) {
            max = a[i];
        }
    }
    if (max <= (K + 1) / 2) {
        printf("0\n");
        return 0;
    } else {
        printf("%d\n", max - 1 - (K - max));
        return 0;
    }
}

Measured memory_bytes: 256
import sys
import queue

#+++++
		
def main():
	n,m = map(int, input().split())
	al=list(map(int, input().split()))
	ppq=queue.PriorityQueue()
	for a in al:
		ppq.put(-a)
	
	for _ in range(m):
		t = ppq.get()
		ppq.put(t/2)
		
		
	rr=0
	while not ppq.empty():
		rr += int(ppq.get())
	print(-rr)
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 15292
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

#i がi番以降にあるなら可能
N = INT()
a = LIST()

ans = deque()
while a:
	for i in range(len(a)-1, -1, -1):
		if a[i] == i+1:
			ans.appendleft(a.pop(i))
			break
	else:
		print(-1)
		exit()

print(*ans, sep="\n")


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換

int main() {
ll a,b,c,k;
cin>>a>>b>>c>>k;
if(k % 2 == 1){
    cout<<b-a<<endl;
}else
{
    cout<<a-b<<endl;
}


    return 0;
}


Measured memory_bytes: 3552
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

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

    int ans = 0, temp;
    rep(i, n) {
        cin >> temp;
        ans += min(temp, k - temp);
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int a,b;
  string s;
  cin>>a>>s>>b;
  if(s[0]=='+')
    cout<<a+b<<endl;
  else
    cout<<a-b<<endl;
}


Measured memory_bytes: 764
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s, t := Scanner(), Scanner()
	ans := 0
	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2696
S = input()
T = input()
lenS = len(S)
lenT = len(T)
dp = [[0]*(lenT+1)for _ in range(lenS+1)]

for i in range(1,lenS+1):
    for j in range(1,lenT+1):
        if S[i-1]==T[j-1]:
            dp[i][j]=dp[i-1][j-1]+1
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
ans = ""
m = lenS
n = lenT
while m and n:
    if dp[m][n]==dp[m-1][n]:
        m -= 1
    elif dp[m][n]==dp[m][n-1]:
        n -= 1
    else:
        m -= 1
        n -= 1
        ans = T[n]+ans

print(ans)


Measured memory_bytes: 112220