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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(ll i=0; i<(n); i++)
#define REPj(n) for(ll j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
#define SORT(c) sort((c).begin(),(c).end())
#define CONTAINER_ALL(a) a.begin(),a.end()

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


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

    int N;
    cin >> N;

    vector<int> W(N + 1, 0);
    REPinit(i, 1, N + 1) {
        cin >> W[i];
        W[i] = W[i] + W[i - 1];
    }

    int ans = 100 * 100 + 9;
    REPinit(i, 1, N + 1) {
        ans = min(ans, abs((W[N] - W[i]) - W[i]));
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3660
s = input()
ans = ""
for _ in range(len(s)):
    if s[0] == "0":
        ans += "0"
        s = s[1:]
    elif s[0] == "1":
        ans += "1"
        s = s[1:]
    else:
        s = s[1:]
        ans = ans[:-1]
print(ans)

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

int main(){
    string str;
    cin >> str;
    int n = str.size();
    int ans = 0;
    for (int i=0; i<n/2; i++){
        if(str[i] != str[n-1-i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

const int MAX_N = 2 * 1e5 + 2;
const ll INF = 1LL << 40;

ll A[MAX_N], B[MAX_N];
vector<ll> mod_B[32];

int main(){
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) {
        cin >> B[i];
        for (int j = 0; j < 32; j++) {
            mod_B[j].push_back(B[i] % (1LL << (j + 1)));
        }
    }
    ll ans = 0;
    for (int i = 0; i < 32; i++) {
        mod_B[i].push_back(INF);
        sort(mod_B[i].begin(), mod_B[i].end());
        ll one_bit_cnt = 0;
        for (int j = 0; j < N; j++) {
            one_bit_cnt += distance(lower_bound(mod_B[i].begin(), mod_B[i].end(), (1LL << i) - (A[j] % (1LL << (i + 1)))), lower_bound(mod_B[i].begin(), mod_B[i].end(), 2 * (1LL << i) - (A[j] % (1LL << (i + 1)))));
            one_bit_cnt += distance(lower_bound(mod_B[i].begin(), mod_B[i].end(), 3 * (1LL << i) - (A[j] % (1LL << (i + 1)))), lower_bound(mod_B[i].begin(), mod_B[i].end(), 4 * (1LL << i) - (A[j] % (1LL << (i + 1)))));
        }
        if (one_bit_cnt % 2 == 1) {
            ans += (1LL << i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 57096
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N, M;
vector<int> G;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> N >> M) {
        G.resize(N+1, 0);
        for (int i = 0; i < M; ++i) {
            int l, r;
            cin >> l >> r;
            --l;
            G[l]++;
            G[r]--;
        }
        for (int i = 0; i < N; ++i) G[i+1] += G[i];
        int res = 0;
        for (int i = 0; i < N; ++i) {
            if (G[i] == M) ++res;
        }

        //COUT(G);
        
        cout << res << endl;
    }
}


















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

int main(){
    int m, f, r;
    char s;
    int sum;
    while(1){
        cin >> m >> f >> r;

        if (m == -1 && f == -1 && r == -1) break;
        
        sum = m + f;
        if (m == -1 || f == -1) s = 'F';
        else if (sum >= 80) s = 'A';
        else if (sum < 80 && sum >= 65) s = 'B';
        else if (sum < 65 && sum >= 50) s = 'C';
        else if (sum < 50 && sum >= 30){
            s = 'D';
            if (r >= 50) s = 'C';
        } 
        else s = 'F';
        
        cout << s << endl;
        
    }

    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
typedef long long ll;
int main(int argc, char const *argv[]) {
    std::string S;
    std::cin >> S;
    std::reverse(S.begin(), S.end());

    while (!S.empty()) {
        if (S.substr(0, 6) == "resare") {
            S.erase(S.begin(), S.begin() + 6);
        } else if (S.substr(0, 7) == "remaerd") {
            S.erase(S.begin(), S.begin() + 7);
        } else if (S.substr(0, 5) == "maerd" || S.substr(0, 5) == "esare") {
            S.erase(S.begin(), S.begin() + 5);
        } else {
            std::cout << "NO" << '\n';
            return 0;
        }
    }
    std::cout << "YES" << '\n';
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    long long ans = 0;
    int N;
    cin >> N;
    
    long long dist[300][300];
    
    for ( int i = 0; i < N; i++ ) {
    for ( int j = 0; j < N; j++ ) {
        long long a;
        cin >> a;
        dist[i][j] = a;
    }
    }
    
    
    for ( int i = 0; i < N; i++ ) {
    for ( int j = 0; j < N; j++ ) {
        bool have_path = true;
        for ( int k = 0; k < N; k++ ) {
            if ( dist[i][j] > dist[i][k] + dist[k][j] ) { cout << -1 << endl; return 0; }
            if ( k != i && k != j && dist[i][j] == dist[i][k] + dist[k][j] ) { have_path = false; }
        }
        if ( have_path ) {
            ans += dist[i][j];
        }
    }
    }
    
    cout << ans/2 << endl;
    
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 2e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll sq(ll x) {return (x * x) % MOD;}
ll modP(ll a, ll b) {return (!b ? 1 : (sq(modP(a, b / 2)) * (b % 2 ? a : 1)) % MOD);}

ll fact[maxN], invfact[maxN];

void initFact(){
	fact[0] = 1;
	for (ll i = 1; i < maxN; i++){
		fact[i] = (fact[i - 1] * i) % MOD;
	}
	invfact[maxN - 1] = modP(fact[maxN - 1], MOD - 2);
	for (ll i = maxN - 2; i > -1; i--){
		invfact[i] = (invfact[i + 1] * (i + 1)) % MOD;
	}
}

ll choose(ll n, ll k){
	return (((fact[n] * invfact[k]) % MOD) * invfact[n - k]) % MOD;
}

ll dp[maxN];
pll P[maxN];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	initFact();
	ll h, w, n;
	cin >> h >> w >> n;
	for (ll i = 0; i < n; i++){
		cin >> P[i].first >> P[i].second;
	}
	P[n] = {h, w};
	sort(P, P + n + 1);
	ll x = P[0].first;
	ll y = P[0].second;
	dp[0] = choose(x + y - 2, max(x - 1, y - 1));
	for (ll i = 0; i <= n; i++){
		ll x = P[i].first;
		ll y = P[i].second;
		dp[i] = choose(x + y - 2, max(x - 1, y - 1));
		for (ll j = 0; j < i; j++){
			if (P[i].second < P[j].second) continue;
			ll x = P[i].first - P[j].first;
			ll y = P[i].second - P[j].second;
			dp[i] -= dp[j] * choose(x + y, max(x, y));
			dp[i] = (dp[i] + MOD) % MOD;
		}
	}
	while (dp[n] < 0) dp[n] += MOD;
	cout << dp[n] % MOD << endl;
	return 0;
}



Measured memory_bytes: 6144
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main
{
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static void main(String args[])
    {
        FastReader obj = new FastReader();
        String s1 = obj.next();
        for(int i=0;i<s1.length();i++)System.out.print('x');
    }
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, Y;
	cin >> N >> Y;
	rep(i, 0, 2001)rep(j, 0, 2001)
	{
		if (i * 10000 + j * 5000 > Y || (Y - i * 10000 - j * 5000) % 1000 != 0)continue;
		int k = (Y - i * 10000 - j * 5000) / 1000;
		if (i + j + k != N)continue;
		cout << i << " " << j << " " << k << endl;
		return 0;
	}

	cout << "-1 -1 -1" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T> using vv=vector<vector<T>>;
typedef deque<int> di;
typedef deque<deque<int>> ddi;


int main() {
    while(1) {
        int n = 0,m = 0;
        int h[1550] = {}, w[1550] = {};
        int l[1500000] = {};
        cin >> n >> m;
        if(n == 0) {
            break;
        }
        int t = 0;
        FOR(i,1,n+1) {
            cin >> h[i];
            t += h[i];
            h[i] = t;
        }
        int s = 0;
        FOR(i,1,m+1) {
            cin >> w[i];
            s += w[i];
            w[i] = s;
        }
        sort(h, &h[n]);
        sort(w, &w[m]);
        ull sum = 0;
        rep(i,n) {
            FOR(j,i+1,n+1) {
                l[h[j]-h[i]] += 1;
            }
        }
        rep(i,m) {
            FOR(j,i+1,m+1) {
                sum += (ull)l[w[j]-w[i]]; 
            }
        }
        cout << sum << endl;
    }        
    return 0;
}

Measured memory_bytes: 8948
fun main(args : Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val aa = readLine()!!.split(" ").map { it.toInt() }

    for (i in k until n) {
        if (aa[i-k] < aa[i]) {
            println("Yes")
        } else {
            println("No")
        }
    }
}

Measured memory_bytes: 69120
#include <iostream>
using namespace std;
inline long long max(long long a, long long b){return (a>b)? a:b;}
int main(void){
    int n,m,k;
    cin >> n >> m >> k;
    long long sum=0,t;
    long long asum[n+1],bsum[m+1];
    int nmax=0, mmax=0;
    asum[0]=0;
    bsum[0]=0;
    for(int i=0;i<n;i++){
        cin >> t;
        if(sum>k){continue;}
        sum+=t;
        if(sum>k){continue;}
        asum[i+1]=sum;
        nmax=i+1;
    }
    sum=0;
    for(int i=0;i<m;i++){
        cin >> t;
        if(sum>k){continue;}
        sum+=t;
        if(sum>k){continue;}
        bsum[i+1]=sum;
        mmax=i+1;
    }
    long long max_count=0;
    int j_before=mmax;
    for(int i=0;i<=nmax;i++){
        sum=asum[i];
        long long _remaining=k-sum;
        if(_remaining==0){
            max_count=max(max_count,i);
            break;
        }else if(_remaining<0){
            break;
        }
        int j;
        for(j=j_before;j>0;j--){
            if(bsum[j]<=_remaining) break;
        }
        max_count=max(max_count,i+j);
        j_before=j;
    }
    cout << max_count << endl;
    return 0;
}

Measured memory_bytes: 6716
#include <stdio.h>
//#include <iostream>
//using namespace std; 

int selectSort(int A[], int N){
	int sw=0;
	int minNum,temp;
	int i,j;
	 
	for(i=0;i<N-1;i++){
		minNum = i;
		
		for(j=i+1;j<N;j++){		
			if(A[j]<A[minNum]){
			minNum = j;
			}		
		}
			if(minNum!=i){
			temp = A[minNum];
			 A[minNum] = A[i];
			 A[i] = temp;
			sw++;
		}	
		
	
    }
    return sw;
}




int main(){
	int A[100],N,sw;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	sw = selectSort(A,N);
	
	for(int i=0;i<N;i++){
		if(i==N-1){
			printf("%d\n",A[i]);
		}
		else{ 
			printf("%d ",A[i]);
		}
	
	}
    printf("%d\n",sw);
    return 0;
}










Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
 
int a[200005], b[200005];
int n, ans;
 
int main()
{
	scanf("%d", &n);
	for (int i = 0;i < n;i++) scanf("%d", a+i);
	for (int i = 0;i < n;i++) scanf("%d", b+i);
	for (int v = (1<<28);v;v>>=1)
	{
		for (int i = 0;i < n;i++) a[i] &= (v*2-1);
		for (int i = 0;i < n;i++) b[i] &= (v*2-1);
		sort(a, a+n); sort(b, b+n);
		int t = 0;
		for (int i = n-1, j = 0, k = 0, l = 0;i >= 0;i--)
		{
			while (j < n && a[i]+b[j] < v) j++;
			while (k < n && a[i]+b[k] < 2*v) k++;
			while (l < n && a[i]+b[l] < 3*v) l++;
			t += k-j+n-l;
			t &= 1;
		}
		if (t) ans |= v;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007LL;
const double INF=1000000000;
const int MAX=100001;
int main(){
    ll n,m;
    while(cin>>n>>m,n+m){
    vector<P> v;
    ll ans=0;
    for(int i=0;i<n;i++){
        int d,p;cin>>d>>p;
        ans+=p*d;
        v.push_back(P(p,d));
    }
    sort(all(v),greater<P>());
    int idx=0;
    while(m){
        ans-=v[idx].first*min(m,v[idx].second);
        m-=v[idx].second;
        if(m<=0){
            break;
        }
        idx++;
        if(idx==n){
            break;
        }
    }
    cout<<ans<<endl;
    }

    return 0;
}

                           



Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll d = b - a;
    if (d % 2 == 0) {
        cout << d / 2 << endl;
    } else {
        cout << min(a - 1, n - b) + 1 + (d - 1) / 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    inf=10**12
    n,max_w=map(int,readline().split())
    w=[0]*n
    v=[0]*n
    for i in range(n):
        w[i],v[i]=map(int,readline().split())

    dp=np.full((n+1,max_w+1),-inf,dtype=np.int64)
    dp[0][0]=0
    for i in range(n):
        dp[i+1,:w[i]]=dp[i,:w[i]]
        dp[i+1,w[i]:]=np.maximum(dp[i,w[i]:],dp[i,:max_w-w[i]+1]+v[i])

    print(dp[n].max())

if __name__=="__main__":
    main()

Measured memory_bytes: 92960
import bisect
from itertools import accumulate


def solve(n, aa, bb, cc):
    def f(ff, tt):
        pv = 0
        ret = [0] * n
        for i, e in enumerate(ff):
            ret[i] = pv = bisect.bisect(tt, e, pv)
        return ret

    ac = f(aa, bb)
    bc = f(bb, cc)
    ba = list(reversed(list(accumulate(n - b for b in reversed(bc)))))
    lim = bisect.bisect_left(ac, n)
    return sum(ba[a] for a in ac[:lim])


n = int(input())
aa = sorted(map(int, input().split()))
bb = sorted(map(int, input().split()))
cc = sorted(map(int, input().split()))
print(solve(n, aa, bb, cc))


Measured memory_bytes: 28672
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	char dp[n][k+1];
	for(int i=0;i<=k;i++)
	{
		if(a[0]>i)
		dp[0][i]='l';
		else
		{
			if(dp[0][i-a[0]]=='l')
			dp[0][i]='w';
			else
			dp[0][i]='l';
		}
	}
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<=k;j++)
		{
			if(a[i]>j)
			dp[i][j]=dp[i-1][j];
			else
			{
				int mark=0;
				for(int k=0;k<=i;k++)
				{
					if(dp[i][j-a[k]]=='l')
					{
						mark=1;
						dp[i][j]='w';
						break;
					}
				}
				if(mark==0)
				dp[i][j]='l';
			}
		}
	}
	/*for(int i=0;i<n;i++)
	{
		for(int j=0;j<=k;j++)
		cout<<dp[i][j]<<" ";
		cout<<endl;
	}*/
	if(dp[n-1][k]=='w')
	cout<<"First";
	else
	cout<<"Second";
	return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    ll x; cin>>x;

    ll ans = (x/11)*2;
    if (x%11 > 6) {
	ans+=2;
    } else if (x%11 > 0) {
	ans++;
    }
    out(ans);
    
    // if (x<=5) out(1);
    // if (x<=11) out(2);

    // ll ans = 2;
    // x -= 11;
    // ans += 2LL*(x/11);
    // x = x%11;
    
    // if (x==0) out(ans);
    // if (x<=5) ans++; else ans+=2;
    // out(ans);

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);



	void run() {

		for(;;){

		int w = sc.nextInt();

		int h = sc.nextInt();

		int d = sc.nextInt();

		if((w|h|d)==0) break;

		int n = sc.nextInt();

		double min1 = Math.min(w, h);

		double min2 = Math.min(d, Math.max(h, w));

		double r2sq = min1 * min1 + min2 * min2;

		for (;n-->0;) {

			int a2 = sc.nextInt() * 2;

			double a2sq = a2 * a2;

			if (r2sq < a2sq) {

				System.out.println("OK");

			} else {

				System.out.println("NA");

			}

		}

		}

	}



	public static void main(String[] args) {

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 12000
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

const int MAX_N = 1 << 17;
int n, q, data_min[2 * MAX_N - 1], data_max[2 * MAX_N - 1];

void init(int _n) {
    n = 1;
    while(n < _n) n *= 2;
    for(int i = 0; i < 2 * n - 1; ++i) data_min[i] = INT_MAX;
    for(int i = 0; i < 2 * n - 1; ++i) data_max[i] = INT_MIN;
}

void update(int k, int a) {
    k += n - 1;
    data_max[k] = data_min[k] = a;
    while(k > 0) {
	k = (k - 1) / 2;
	data_min[k] = min(data_min[k * 2 + 1], data_min[k * 2 + 2]);
	data_max[k] = max(data_max[k * 2 + 1], data_max[k * 2 + 2]);
    }
}

void query(int a, int b, int k, int l, int r, int& max_val, int& min_val) {
    int mid = (l + r) / 2;
    if(a <= l && r <= b) {
	max_val = data_max[k];
	min_val = data_min[k];
	return;
    } else if(b <= mid) {
	query(a, b, k * 2 + 1, l, (l + r) / 2, max_val, min_val);
    } else if(a > mid) {
	query(a, b, k * 2 + 2, (l + r) / 2 + 1, r, max_val, min_val);
    } else {
	int maxl, minl, maxr, minr;
	query(a, b, k * 2 + 1, l, (l + r) / 2, maxl, minl);
	query(a, b, k * 2 + 2, (l + r) / 2 + 1, r, maxr, minr);
	max_val = max(maxl, maxr);
	min_val = min(minl, minr);
    }
}


int main() {
    int N, Q;
    scanf("%d%d", &N, &Q);
    init(N);
    for(int i = 0; i < Q; ++i) {
	int c, a, b;
	scanf("%d%d%d", &c, &a, &b);
	if(c == 0) update(a, b);
	else {
	    int max_val, min_val;
	    query(a, b, 0, 0, n - 1, max_val, min_val);
	    printf("%d\n", min_val);
	}
    }
    return 0;
}

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

void inse(int *, int);
void extM(int *);
void maxH(int *, int);

int n = 0;

main(){
  int i;
  int t[2000002];
  char a[10];
  
  while(1){
    scanf("%s", a);
    if(a[2] == 'd') break;
    else if(a[0] == 'i'){
      scanf("%d", &t[0]);
      inse(t, t[0]);
    }
    else extM(t);
  }
  
  return 0; 
}
void maxH(int *t, int i){
  int l, r, large, c;
  
  if( i*2+1 < n + 1) r = i*2+1;
  else r = i;
  if( i*2 < n + 1) l = i*2;
  else l = i;
  
  if(l <= n && t[l] > t[i]) large = l;
  else large = i;
  
  if(r <= n && t[r] > t[large])large = r;
  
  if(large != i){
    c = t[i];
    t[i] = t[large];
    t[large] = c;
    maxH(t, large);
  }
}
void inse(int *t, int a){
  int i,c;
  
  n++;
  i = n;
  t[n] = a;
  
  while(i > 1 && t[i/2] < t[i]){
    c = t[i];
    t[i] = t[i/2];
    t[i/2] = c;
    i /= 2;
  }
}
void extM(int *t){
  
  printf("%d\n", t[1]);
  
  if(n > 1)t[1] = t[n];
  
  n--;
  
  if(n > 1) maxH(t, 1);
}

Measured memory_bytes: 5012
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{
  
  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String sl[];

    sl = r.readLine().split(" ");
    long a = Long.parseLong(sl[0]);
    long b = Long.parseLong(sl[1]);
    
    long v = 3000;
    long d = Math.min(a + 4050, b);
    for(long i = a; i <= d; i++)
    {
      for(long j = i + 1; j <= d; j++)
      {
        v = Math.min(v, ((i % 2019) * (j % 2019)) % 2019);
      }
    }
    
    System.out.println(v);
    
  }

}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, z, w;
    cin >> n >> z >> w;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    if (n == 1) cout << abs(a[0] - w);
    else cout << max(abs(a[n - 2] - a[n - 1]), abs(w - a[n - 1]));
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> V;
const long long MOD=1000000007LL;
const long long INFL=1LL << 60;
const int INF=1<<29;


int main() {
    string S;
    string ans;
    cin >>S;
    int flagYM=0;
    int flagMY=0;
    if((S[0]=='0'&&S[1]!='0')||(S[0]=='1'&&S[1]-'0'<=2)){
        flagMY=1;
    }
    if((S[2]=='0'&&S[3]!='0')||(S[2]=='1'&&S[3]-'0'<=2)){
        flagYM=1;
    }
    if(flagMY&&flagYM) ans="AMBIGUOUS";
    else if(flagMY) ans="MMYY";
    else if(flagYM) ans="YYMM";
    else ans="NA";
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
a = tuple(map(int, input().split()))


def comb(n: int, k: int) -> int:
    if n < k or n < 0 or k < 0:
        return 0
    k = min(k, n - k)
    ans = 1
    for i in range(1, k + 1):
        ans *= n - i + 1
        ans //= i
    return ans


d = defaultdict(int)
comb_list = [0] * n
for ai in a:
    d[ai] += 1

ans_sum = 0
for i in d:
    ans_sum += comb(d[i], 2)

for i in range(n):
    ans_i = ans_sum - comb(d[a[i]], 2) + comb(d[a[i]] - 1, 2)
    print(ans_i)


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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

//repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

struct Mystruct
{
    long long atack;
    long long mp;
    double cost;

    Mystruct(long long input_a, long long input_b)
    {
        atack = input_a;
        mp = input_b;
        cost = input_a * 1.0 / input_b;
    }
    bool operator<(const Mystruct &another) const
    {
        if (cost == another.cost)
        {
            return mp < another.mp;
        }
        return cost < another.cost; //年齢を比較
    };
};

int solve(int n, int x)
{
    int ret = 0;
    FOR(i, 1, n - 2)
    {
        FOR(j, i + 1, n - 1)
        {
            FOR(k, j + 1, n)
            {
                if(i+j+k == x){
                    ret++;
                }
            }
        }
    }
    return ret;
}
int main()
{
    int n, x;
    while (true)
    {
        cin >> n >> x;
        if (n == 0 && x == 0)
            break;

        ANS(solve(n, x));
    }

    return 0;
}



Measured memory_bytes: 3116
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
let sp = input.split("\n");
for( let i = 0; sp[i] !== "0 0"; i++ ) {
  let hw = sp[i].split(" ").map(Number);
  let h = hw[0]; w = hw[1];
  for( let hh = 0; hh < h; hh++ ) {
    let row = "";
    for( let ww = 0; ww < w; ww++ ) {
      row += "#";
    }
    console.log(row);
  }
  console.log();
}


Measured memory_bytes: 19248
import java.io.*;
import java.util.*;
public class Main{

	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] cmd=br.readLine().split(" ");
		long x=Long.valueOf(cmd[0]);
		long k=Long.valueOf(cmd[1]);
		long[] sum1=new long[(int)x+2];
		for(long i=1;i<=x+1;i++)
		{
			sum1[(int)i]=sum1[(int)i-1]+i;
		}
		long[] sum2=new long[(int)x+2];
		for(long i=x+1;i>=1;i--)
		{
			sum2[(int)(x+2-i)]=sum2[(int)(x+1-i)]+i;
		}
		long ans=0;
		for(long i=k;i<=x+1;i++)
		{
			long diff=sum2[(int)i]-sum1[(int)i]+1;
			ans=(ans+diff)%1000000007;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 35772
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val k = sc.nextInt()
    var ans = 0L
    if (k == 0) {
        println(n * n.toLong())
        return
    }
    for (b in k + 1..n) {
        val r = b - k
        ans += n / b * r
        val l = n % b
        ans += Math.max(0, l - k + 1)
    }
    println(ans)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 31400
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;


ll dp[100100];
ll h[100100];

int main()
{
    int n,k; cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    for(int i = 0; i < 100100; i++){
        dp[i] = INF;
    }
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= k; j++){
            dp[i+j] = min(dp[i + j], dp[i] + abs(h[i+j] - h[i]));
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(void) {
    long N, K, Q;
    int user[100002]={};
    scanf("%ld %ld %ld", &N, &K, &Q);
    for(long i=0; i<Q; i++){
        long tmp;
        scanf("%ld", &tmp);
        user[tmp]++;
    }
    for(long i=1; i<=N; i++){
        if(user[i]+K-Q>0) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const ll mod = 1e9+7;
const int N = 2e5+5;
ll a[N];
ll b[N];
void solve(){
    int n;
    cin>>n;
    for(int i=0;i<=n;i++)cin>>a[i];
    b[n] = a[n];
    for(int i=n-1;i>=0;i--)b[i] = b[i+1]+a[i];
    ll ans = 0;
    ll nl = 0;
    ll l = 0;
    nl = 1;
    if(n==0){
        if(a[0]!=1){
            cout<<-1<<endl;
        }
        else{
            cout<<1<<endl;
        }
        return ;
    }
    if(a[0]==1){
        if(n>0){
            cout<<-1<<endl;
        }
        else{
            cout<<1<<endl;
        }
        return ;
    }
    for(int i=1;i<=n;i++){
        if(nl*2ll<a[i]){
            cout<<-1<<endl;
            return;
        }
        nl = nl*2;
        nl = min(nl,b[i]);
        ans+=nl;
        nl-=a[i];
    }
    cout<<ans+1<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    scanf("%d",&t);
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 5228
// https://atcoder.jp/contests/abc173/tasks/abc173_b
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;
#define lli long long int
#define numberofdigits(x) floor(log10(x)) + 1

int main()
{
    lli n,i,ac=0,wa=0,tle=0,re=0;
    string s;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>s;
        if(s=="WA") wa++;
        if(s=="AC") ac++;
        if(s=="TLE")tle++;
        if(s=="RE") re++;
    }
    cout<<"AC x "<<ac<<"\n";
    cout<<"WA x "<<wa<<"\n";
    cout<<"TLE x "<<tle<<"\n";
    cout<<"RE x "<<re<<"\n";
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);



int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    
    freopen("output.txt", "w", stdout);
    #endif

    ll n,m,i,j;
    cin>>n>>m;

    string arr[n];
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }

    ll dp[n][m];
    memset(dp,0,sizeof(dp));

    dp[0][0]=1;

    for(i=1;i<m;i++)
    {
        if(arr[0][i]!='.')
        {
            dp[0][i] = 0;
        }
        else
        {
            dp[0][i] = dp[0][i-1]; 
        } 
    }

    for(i=1;i<n;i++)
    {
        if(arr[i][0]!='.')
        {
            dp[i][0]=0;
        }
        else 
        {
            dp[i][0] = dp[i-1][0];
        }
    }
    dp[0][0]=0;

    for(i=1;i<n;i++)
    {
        for(j=1;j<m;j++)
        {
            if(arr[i][j]=='.')
            {
                dp[i][j] =  (dp[i-1][j]%mod + dp[i][j-1]%mod)%mod;
            }
        }
    }

    // for(i=0;i<n;i++)
    // {
    //     for(j=0;j<m;j++)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }

    cout<<dp[n-1][m-1]%mod<<endl;
}

Measured memory_bytes: 13296
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
typedef long long ll;
#include <cmath>

int main(int argc, char *argv[])
{
	ll n;
	cin >>n;

	ll n3=n/3,n5=n/5,n15=n/15;
	ll ret=n*(n+1)/2;
	ret-=3*n3*(n3+1)/2;
	ret-=5*n5*(n5+1)/2;
	ret+=15*n15*(n15+1)/2;

	cout<< ret<< endl;
	return 0;
}


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

int main() {
  int n, a, b, c, d;
  string s;
  cin >> n >> a >> b >> c >> d >> s;
  bool ok = false;
  s = '#' + s + '#';
  
  if(c<=d) ok=true;
  else {
    srep(i,b,d+1) {
      if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.') ok=true;
    }
  }

  srep(i,a-1,c) {
    if(s[i]=='#'&&s[i+1]=='#') ok=false;
  }
  srep(i,b-1,d) {
    if(s[i]=='#'&&s[i+1]=='#') ok=false;
  }

  cout << (ok? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 772
def gcd(a,b) :
    if b>0 :
        return gcd(b,a % b)
    elif b == 0:
        return a


N,X = map(int,input().split())
x = list(map(int,input().split()))
if N == 1:
    print(abs(x[0] - X))
else:
    xlen = []
    for i in range(N):
        xlen.append(abs(x[i] - X))
        #print(xlen[i])
    ans = xlen[0]
    for i in range(1,N):
        ans = gcd(ans,xlen[i])
        #print(ans)
    print(ans)

Measured memory_bytes: 14224
class BIT:
    def __init__(self, N):
        self.size = N
        self.tree = [0] * (N + 1)
        self.bisect_K = [1 << k for k in reversed(range(N.bit_length()))]

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def bisect(self, w):
        if w <= 0:
            return 0
        bit, N = self.tree, self.size
        i = 0
        for k in self.bisect_K:
            ni = i + k
            if ni <= N and bit[ni] < w:
                w -= bit[ni]
                i = ni
        return i + 1


class Multiset:
    def __init__(self, N):
        self.N = N
        self.bit = BIT(N)

    def insert(self, x):
        self.bit.add(x, 1)

    def erase(self, x):
        self.bit.add(x, -1)

    def lower_bound(self, x):
        return self.bit.bisect(self.bit.sum(x))

    def size(self):
        return self.bit.sum(self.N)

def main():

    # https://atcoder.jp/contests/abc134/tasks/abc134_e

    N, *A = map(int, open(0).read().split())

    memo = {a: i for i, a in enumerate(sorted(set(A)), 1)}
    M = len(memo)

    ms = Multiset(M)
    for b in (memo[a] for a in A):
        i = ms.lower_bound(b - 1)
        if i != 0:
            ms.erase(i)
        ms.insert(b)

    print(ms.size())


if __name__ == '__main__':
    main()


Measured memory_bytes: 25448
#include<stdio.h>



int main()
{
    int N, T, A, i;
    scanf("%d", &N );
    scanf("%d %d", &T, &A);
    int H;
    double tem[N];
    int min = 1;
    for(i = 0; i < N; i++){
        scanf("%d", &H);
        tem[i] = T - H * 0.006 - A;
        if(tem[i] < 0.0) tem[i] = -tem[i];
        if(tem[i] < tem[min-1] ) min = i+1;
    }
    
    printf("%d\n", min );
    return 0;
}

Measured memory_bytes: 128
N = int(input())
A_list = [int(e) for e in input().split()]

all_A_xor = A_list[0]
#print(A_list[0],bin(A_list[0]))

for i in range(1,N):
    #print(A_list[i],bin(A_list[i]))
    all_A_xor ^= A_list[i]

#print(all_A_xor,bin(all_A_xor))

ans = [A^all_A_xor for A in A_list]
print(' '.join(map(str, ans)))

Measured memory_bytes: 41788
#include<bits/stdc++.h>
using namespace std;
int const MAXN=201000;
int n, d;
int A[MAXN];
multiset<int> vis;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>A[i];
		vis.insert(A[i]);
	}
	for(int i=0;i<n;i++){
		vis.erase(vis.find(A[i]));
		cout<<*(vis.rbegin())<<'\n';
		vis.insert(A[i]);
	}
	
}

Measured memory_bytes: 11776
import sys
input = sys.stdin.readline
A = input()
B = input()
C = input() # 入力が1つ
# map(int, input().split()) # 入力が複数
# [int(i) for i in input().split()] # 配列で数字

turn = 'a'
while A and B and C:
    if turn == 'a':
        turn = A[0]
        A = A[1:]
        if len(A) == 0:
            print('A')
            break
    elif turn == 'b':
        turn = B[0]
        B = B[1:]
        if len(B) == 0:
            print('B')
            break
    else:
        turn = C[0]
        C = C[1:]
        if len(C) == 0:
            print('C')
            break

Measured memory_bytes: 38256
package main

import "fmt"

func isOdd(n int) bool { return n%2 != 0 }

func f(n int) (a int) {
	for n != 0 {
		a++
		n /= 10
	}
	return a
}

func main() {
	var n int
	fmt.Scan(&n)

	ans := 0
	for i := 1; i <= n; i++ {
		if isOdd(f(i)) {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>

int main() {
    int n, m;
    std::cin >> n >> m;
    int pt = 0, pen = 0;
    std::vector<bool> ac(n);
    std::vector<int> wa(n);
    for (int i = 0; i < m; i++) {
        int p;
        std::string s;
        std::cin >> p >> s;
        p--;
        if ((ac[p] == false) and s == "AC") {
            ac[p] = true;
            pt++;
            pen += wa[p];
        } else if ((ac[p] == false) and s == "WA") {
            wa[p]++;
        }
    }

    std::cout << pt << " " << pen << std::endl;
    return 0;
}


Measured memory_bytes: 640
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from fractions import gcd

n = int(readline())
t = [int(readline()) for _ in range(n)]
ans = t[0]
for tt in t:
    ans = ans * tt // gcd(ans, tt)
print(ans)


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

int main(void)
{
    int A, B;
    cin >> A >> B;

    int ans = max({A + B, A - B, A * B});
    cout << ans << endl;
    return (0);
}

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

int main(){
    int n,k;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int max = a[0] + (k- a[n-1]);
    int gap;
    rep(i,n-1){
        gap = a[i+1] - a[i];
        if(gap > max) max = gap;
    }
    cout << k -max << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

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

LL num(LL a,LL c,LL d){
	LL s=0;
	s=a/c+a/d-a/(c*d/gcd(c,d));
	return a-s;
}

int main(){
	LL a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<num(b,c,d)-num(a-1,c,d)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <map>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)

int main (){
  int n;
  cin>>n;
  vector<ll> a(n);
  r(i,n){
    cin>>a.at(i);
  }
  sort(a.rbegin(),a.rend());

  ll i=0,j=0,b=0,c=0;
  bool f=false;

  while(i<a.size()-1){
    if(a[i]!=a[i+1])i++;
    if(a[i]==a[i+1]){
        if(!f){
          b=a[i];
          f=true;
          i+=2;
        }else{
          c=a[i];
          break;
        }
    }
  }

  cout<<b*c<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL) ; cout.tie(NULL);


int main()
{
   int n,i,j;
   cin>>n;
   int a[n+1];
   int h[n+1];
   
   for(i=0;i<n;i++)
   {
   	cin>>a[i];
   	h[i]=INT_MAX;
   }
   
   h[0]=0;

   for(i=0;i<n;i++)
   {
   	if(i+1<n&&h[i+1]>h[i]+abs(a[i]-a[i+1]))
     h[i+1]=h[i]+abs(a[i]-a[i+1]);
    
    if(i+2<n&&h[i+2]>h[i]+abs(a[i]-a[i+2]))
     h[i+2]=h[i]+abs(a[i]-a[i+2]);
   }
    
    cout<<h[n-1]<<"\n";
 	return 0;
}

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

int main(){
	int a,b,c,x,d=0;
	cin>>a>>b>>c>>x;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				if(500*i+100*j+50*k==x) d++;
			}
		}
	}
	cout<<d;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<list>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back

#define ll __int64
#define P pair<ll,ll>
//#define __int64 long long


int n,m;
vector<int>G[210000];
int main(){	
	cin>>n>>m;

	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	
	}

	rep(i,G[0].size()){
   	rep(j,G[G[0][i]].size()){
   	 	if(G[G[0][i]][j]==n-1){
   	 	 		cout<<"POSSIBLE"<<endl;
					return 0;
			}
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}


Measured memory_bytes: 12144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string n;
    cin >> n;
    ll sum=0;
    REP(i,n.length()){
        sum += (n[i] - 0x30);
    }
    if(sum%9==0){
        cout << "Yes";
    }else{;
        cout << "No";
    }
    cout << "\n";
    
    return 0;
}

Measured memory_bytes: 3736
str = input().split()
N = int(str[0])
x = int(str[1])

if(N-(N-2)<=x<=N+(N-2)):
    print("Yes")
    arr = [0] * (2 * N - 1)
    for i in range(2 * N - 1):
        arr[i] = i

    def flip(a,b):
        arr[a],arr[b]=arr[b],arr[a]

    if(x!=N):
        flip(x-1, N-1)
        if(x<N):
            flip(0, N)
        else:
            flip(2*N-1-1, N-2)

    for i in range(2 * N - 1):
        print(arr[i]+1)
else:
    print("No")


Measured memory_bytes: 12564
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
using namespace std;
int phi(int x)
{
	int r = 1;
	for (int i = 2;; i++)
	{
		if (i*i > x)break;
		if (x%i == 0)
		{
			int t = i - 1;
			x /= i;
			for (;;)
			{
				if (x%i == 0)x /= i, t *= i;
				else break;
			}
			r *= t;
		}
	}
	if (x != 1)r *= x - 1;
	return r;
}
typedef long long ll;
ll po(ll a, ll b, ll m)
{
	if (b == 0)return 1;
	ll z = po(a, b / 2, m);
	z = z*z%m;
	if (b & 1)z = z*a%m;
	return z;
}
typedef pair<ll, ll>pii;
pii calc(ll a, ll m)
{
	if (m == 1)return make_pair(0, 0);
	ll pm = phi(m);
	pii z = calc(a, pm);
	return make_pair(po(a, z.first + pm * 50, m), z.first);
}
pii extgcd(ll a, ll b)//ax+by=gcd(a,b) の解(x,y)を返す
{
	if (a == 0)
	{
		if (b > 0)return make_pair(0, 1);
		else return make_pair(0, -1);
	}
	else if (b == 0)
	{
		if (a > 0)return make_pair(1, 0);
		else return make_pair(-1, 0);
	}
	else if (abs(a) < abs(b))
	{
		ll p = b / a, q = b - p*a;
		pii z = extgcd(a, q);
		return make_pair(z.first - p*z.second, z.second);
	}
	else
	{
		ll p = a / b, q = a - p*b;
		pii z = extgcd(q, b);
		return make_pair(z.first, z.second - p*z.first);
	}
}
ll gcd(ll a, ll b)
{
	if (a == 0)return b;
	if (b == 0)return a;
	for (;;)
	{
		if (a < b)swap(a, b);
		a %= b;
		if (a == 0)return b;
	}
}
int main()
{
	int data;
	scanf("%d", &data);
	for (int p = 0; p < data; p++)
	{
		ll a, m;
		scanf("%lld%lld", &a, &m);
		ll pm = phi(m);
		pii r = calc(a, m);
		//printf("%lld %lld   %lld\n", r.first, r.second, gcd(m, phi(m)));
		ll g = gcd(m, pm);
		pii z = extgcd(m, pm);
		//printf("%lld %lld\n", z.first, z.second);
		ll ans = (r.second - r.first) / g*z.first%pm*m + r.first;
		ans %= (m*pm);
		ans += m*pm;
		ans %= (m*pm);
		if (ans < 35)ans += (35 + m*pm) / (m*pm)*(m*pm);
		printf("%lld\n", ans);
		//printf("%lld %lld\n", po(a, ans, m), ans%m);
	}
}

Measured memory_bytes: 128