akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
using ll = long long;


int main() {
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  
  rep(i,N) cin >> A.at(i);

  rep(Ki,K){
    vector<int> B(N+1);
    rep(i,N){
      
      int l = max(0,i-A[i]);
      int r = min(i+A[i]+1,N);
      B[l]++;
      B[r]--;
    }
    rep(i,N) B[i+1] += B[i];
    B.pop_back();
    if(A==B) break;
    A = B;
  }

  rep(i,N){
    cout << A.at(i) << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 4844
#include<iostream>
#include<algorithm>
#include <stdio.h>
using namespace std;
#define TREE_N (1<<17)
 
int ans,c,n,tree[ TREE_N * 2 -1]={};
 
void update(int i){
  i+=TREE_N-1;
  ans+=tree[i];
  while(i>0){
    i=(i-1)/2;
    ans+=tree[i];
  }
}
 
void rec(int a,int b,int k=0,int l=0,int r=TREE_N){
  if((l<a&&a<r)||(l<b&&b<r)){
    int m=(l+r)/2;
    rec(a,b,k*2+1,l,m);
    rec(a,b,k*2+2,m,r);
  }else if(a<=l&&r<=b){
    tree[k]+=c;
  }
}
 
int Rec(int a,int b,int k=0,int l=0,int r=TREE_N){
  if((l<a&&a<r)||(l<b&&b<r)){
    int m=(l+r)/2;
    int left = Rec(a,b,k*2+1,l,m);
    int right = Rec(a,b,k*2+2,m,r);
    return min(left,right);
     
  }else if(a<=l&&r<=b){
    return tree[k];
  }else{
    return 2147483647;
  }
}
 
int main(){
  int q,com,a,b;
  cin>>n>>q;
  for(int i=0;i<q;i++){
    cin>>com;
    if(com){
      cin>>a;
      ans=0;
      update(a);
      printf("%d\n",ans);
    }
    else {
      cin>>a>>b>>c;
      rec(a,b+1);
    }
  }
  return 0;
}


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

int main(){
  int n;
  ll x;
  cin>>n>>x;
  ll vec[n],ans=0,zero=0;
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  for(int i=0;i<n-2;i++){
    if(vec[i]+vec[i+1]<=x){
      continue;
    }
    if(vec[i]<=x){
      ans+=vec[i+1]-(x-vec[i]);
      vec[i+1]=x-vec[i];
      continue;
    }
    ans+=vec[i+1];
    vec[i+1]=0;
    ans+=vec[i]-x;
    vec[i]=x;
  }
  cout<<ans+max(zero,vec[n-2]+vec[n-1]-x)<<endl;
}

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

int main(){
    long long n;
    cin>>n;
    vector<long long> a(n);
    long long ans=0;
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    vector<long long> b(n,-1);
    b[(n-1)/2]=a[0];
    long t;
    for (int i = 1; i <= n/2; ++i) {
        if(i==n/2&&n%2==0){
            if(n/2%2==1)b[n-1]=a[n/2];
            else t=a[n/2-1];
            break;
        }
        if(i%2==1){
            b[(n-1)/2-i]=a[n-i];
            b[(n-1)/2+i]=a[n-i-1];
        }
        else{
            b[(n-1)/2-i]=a[i];
            b[(n-1)/2+i]=a[i-1];
        }
    }
    if(n%2==0&&n/2%2==0){ans+=abs(t-b[0]);
        for (int i = 0; i < n-2; ++i) {
            ans+=abs(b[i]-b[i+1]);
        }
    }
    else {
        for (int i = 0; i < n-1; ++i) {
            ans+=abs(b[i]-b[i+1]);
        }

    }

    long long ans2=0;
    for (int i = 1; i <= n/2; ++i) {
        if(i==n/2&&n%2==0){
            if(n/2%2==0)b[n-1]=a[n/2-1];
            else t=a[n/2];
            break;
        }
        if(i%2==1){
            b[(n-1)/2+i]=a[n-i];
            b[(n-1)/2-i]=a[n-i-1];
        }
        else{
            b[(n-1)/2+i]=a[i];
            b[(n-1)/2-i]=a[i-1];
        }
    }
    if(n%2==0&&n/2%2==1){
        ans2+=abs(t-b[0]);
        for (int i = 0; i < n-2; ++i) {
            ans2+=abs(b[i]-b[i+1]);
        }
    }
    else {
        for (int i = 0; i < n-1; ++i) {
            ans2+=abs(b[i]-b[i+1]);
        }

    }

    b[(n-1)/2]=a[n-1];
    long long ans3=0;
    for (int i = 1; i <= n/2; ++i) {
        if(i==n/2&&n%2==0){
            if(n/2%2==1)b[n-1]=a[(n-2)/2];
            else t=a[(n-2)/2];
            break;
        }
        if(i%2==1){
            b[(n-1)/2-i]=a[i-1];
            b[(n-1)/2+i]=a[i];
        }
        else{
            b[(n-1)/2-i]=a[n-i-1];
            b[(n-1)/2+i]=a[n-i];
        }
    }
    if(n%2==0&&n/2%2==0){ans3+=abs(t-b[0]);
        for (int i = 0; i < n-2; ++i) {
            ans3+=abs(b[i]-b[i+1]);
        }
    }
    else {
        for (int i = 0; i < n-1; ++i) {
            ans3+=abs(b[i]-b[i+1]);
        }

    }

    ans=max(ans,max(ans2,ans3));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define N 200003
#define LL long long
#define mod 998244353

int n,len;
char s[N];

inline int read(){
	int X=0,w=0;
	char ch=0;
	while (ch<'0' || ch>'9')
	  w|=ch=='-',ch=getchar();
	while (ch>='0' && ch<='9')
	  X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
	return w ? -X : X;
}

int main(){
	n=read();
	scanf("%s",s+1);
	len=strlen(s+1);
	if (n>=3200){
		for (int i=1;i<=len;i++)
		  printf("%c",s[i]);	
	}
	else puts("red");
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys
input = sys.stdin.readline


n = int(input())
edges = defaultdict(list)
for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

colors = [-1] * n

colors[0] = 0

todo = []
for to in edges[0]:
    todo.append([to, 1])

while todo:
    node, color = todo.pop()

    if colors[node] != -1:
        continue

    colors[node] = color
    new_color = 1 - color
    for to in edges[node]:
        if colors[to] != -1:
            continue
        todo.append([to, new_color])

red_count = sum(colors)  # 1
blue_count = n - red_count  # 0

ans = [0] * n

num3s = list(range(3, n+1, 3))
nums = [num for num in range(1, n+1) if num % 3 != 0]

if red_count <= n // 3:
    for node in range(n):
        if colors[node] == 1:
            ans[node] = num3s.pop()

        else:
            if nums:
                num = nums.pop()
            else:
                num = num3s.pop()
            ans[node] = num


elif blue_count <= n // 3:
    for node in range(n):
        if colors[node] == 0:
            ans[node] = num3s.pop()

        else:
            if nums:
                num = nums.pop()
            else:
                num = num3s.pop()
            ans[node] = num

else:
    num1s = list(range(1, n+1, 3))
    num2s = list(range(2, n+1, 3))

    for node in range(n):
        if colors[node] == 1:
            if num1s:
                num = num1s.pop()
            else:
                num = num3s.pop()
            ans[node] = num

        else:
            if num2s:
                num = num2s.pop()
            else:
                num = num3s.pop()
            ans[node] = num

print(*ans)

Measured memory_bytes: 119900
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int N, A, B;
int h[100010];
bool C(ll T) {
    ll cnt = 0;
    rep(i, 0, N) {
        ll tmp = 1ll * h[i] - 1ll * B * T;
        if(tmp > 0) {
            cnt += (tmp / (A - B));
            if(tmp % (A - B)) cnt++;
        }
    }

    return T >= cnt;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    cin >> N >> A >> B;
    rep(i, 0, N) cin >> h[i];

    int left = 0, right = 1e9;
    while(right - left > 1) {
        ll mid = (left + right) / 2;
        if(C(mid)) right = mid;
        else left = mid;
    }

    cout << right << endl;


}


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

signed main() {
int H, W;
cin >> H >> W;

vector<string> A(H);
for( int i = 0; i < H; i++ ) cin >> A.at(i);

int fg = 0;
for( int i = 0; i < H; i++ ){
for( int j = 0; j < W; j++ ){
if( j < fg && A.at(i).at(j) == '#' ){
cout << "Impossible" << endl;
return 0;
}else if( A.at(i).at(j) == '#' ) fg = j;
}
}
cout << "Possible" << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

int main() {
  int n, d; cin >> n >> d;
  int ans = 0;
  
  for(int i=1; i<=n; i++) {
    double p, q; cin >> p >> q;
    p = abs(p); q = abs(q);
    double distance;
    distance = sqrt(pow(p, 2) + pow(q, 2));
    if (distance <= d) ans++;
  }
  
  cout << ans << endl;
}

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

vector<long long> layer = {1}, patty = {1};

long long getPatty(int n, long long x) {
    if (n == 0) {
        return 1;
    } else {
        if (x == 1) {
            return 0;
        } else if (x <= layer[n - 1] + 1) {
            return getPatty(n - 1, x - 1);
        } else if (x == layer[n - 1] + 2) {
            return patty[n - 1] + 1;
        } else if (x <= 2 * layer[n - 1] + 2) {
            return patty[n - 1] + 1 + getPatty(n - 1, x - (layer[n - 1] + 2));
        } else if (x == 2 * layer[n - 1] + 3) {
            return 2 * patty[n - 1] + 1;
        } else {
            exit(1);
        }
    }
}

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

    for (int i = 1; i <= N; i++) {
        layer.push_back(2 * layer[i - 1] + 3);
        patty.push_back(2 * patty[i - 1] + 1);
    }

    cout << getPatty(N, X) << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr ll INF = 1e16;

#define rep(i, N) for(ll i=0; i<N; ++i)

ll max(ll a, ll b) {return a < b ? b : a; }
ll min(ll a, ll b) {return a > b ? b : a; }

int main() {
  ll N, M, R;
  cin >> N >> M >> R;
  vector<ll> r(R);
  rep(i, R) cin >> r[i];
  vector<ll> A(M);
  vector<ll> B(M);
  vector<ll> C(M);
  rep(i, M) cin >> A[i] >> B[i] >> C[i];
  
  //ワーシャルフロイド
  vector<vector<ll>> G(N, vector<ll>(N, INF));
  for(ll i=0; i<N; ++i) {
    G[i][i] = 0;
  }
  //デフォルトは直接の辺の長さ
  for(ll i=0; i<M; ++i) {
    G[A[i] - 1][B[i] - 1] = C[i];
    G[B[i] - 1][A[i] - 1] = C[i];
  }
  //更新．辺kを経由した時，など
  for(ll k=0; k<N; ++k) {
    for(ll i=0; i<N; ++i) {
      for(ll j=0; j<N; ++j) {
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
      }
    }
  }
  
  //次に全探索して8!通りのうちから最短を探す
  //rを破壊的に更新
  vector<int> v;
  rep(i, R) v.push_back(i);
  
  ll mv = INF;
  do {
    ll len = 0;
    for(ll i=0; i<r.size()-1; ++i) {
      len += G[r[v[i]] - 1][r[v[i+1]] - 1];
    }
    mv = min(len, mv);
  } while(next_permutation(v.begin(), v.end()));
  
  cout << mv << endl;
  
}

Measured memory_bytes: 1024
#include <cstdio>

int main()
{
  int n;
  while (scanf("%d", &n), n)  
  {
      int left = 1000 - n;
      int coin[] = { 500, 100, 50, 10, 5, 1 };
      int res = 0;
      for (int i = 0; left; ++i)
	  while (left >= coin[i])
	      ++res, left -= coin[i];
      printf("%d\n", res);
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    Rep (i, N) {
        cin >> A[i];
    }

    ll now = 2, ans = A[0] - 1;
    Rep (i, N-1) {
        ans += ((A[i+1] + now - 1) / now - 1 );
        if (A[i+1] == now) {
            now++;
        }
        // cout << now << " " << ans << "\n";
    }

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

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

using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  int q;
  cin >> q;
  list<int> v;
  list<int> ::iterator cur = v.end();
  // vector<int> output;
  int tmp;
  int tmp2;
  int tmp3;
  rep_i(i, q){
    cin >> tmp;
    if(tmp == 0){
      cin >> tmp2;
      cur = v.insert(cur, tmp2);
    }else if(tmp == 1){
      cin >> tmp2;
      if(tmp2 > 0){
        rep_i(i, tmp2){
          cur++;
        }
      }else{
        rep_i(i, abs(tmp2)){
          cur--;
        }
      }
    }else{
      cur = v.erase(cur);
    }
  }
  for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
      printf("%d\n", *it);
  }
}


Measured memory_bytes: 18628
#include<bits/stdc++.h>
using namespace std;
char s[6005],t[6005];
int f[6005][6005],k[6005][6005];
int ans[6005],cnt;
int main()
{
	scanf("%s%s",s+1,t+1);
	int lens=strlen(s+1);
	int lenc=strlen(t+1);
	//cout << lens<<" "<<lenc<<endl; 
	for(int i=1;i<=lens;++i)
	{
		for(int j=1;j<=lenc;++j)
		{
			f[i][j]=f[i-1][j];
			if(f[i][j-1] > f[i-1][j])
			   f[i][j]=f[i][j-1],k[i][j]=1;
			else 
			   k[i][j]=2;
			if(s[i]==t[j] && f[i-1][j-1] + 1 > f[i][j])
			{
				f[i][j]=f[i-1][j-1]+1;
				k[i][j]=3;
			 } 
		}
	}
	int a=lens;
	int b=lenc;

	for(int i=1;i<=f[lens][lenc];++i)
	{
		while( a>0 && b > 0 && k[a][b]!=3 )
		{
			if(k[a][b]==1) --b;
			else --a;
		}
		if(a<=0 || b <= 0 )
		  break;
		ans[++cnt]=a;
		--a;
		--b;
			
	}
	for(int i=cnt;i>=1;--i)
	   printf("%c",s[ans[i]]);
	printf("\n");
	return 0;
} 


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

#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define all(x) (x).begin(), (x).end()

#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
const int MOD = 1000000007;
ll dp[100001];
int main() {
    IOS;
    int n, k;
    cin >> n >> k;
    std::vector<int> h(n + 1);
    for(int i = 1; i <= n; i++) cin >> h[i];
    dp[1] = 0;
    for(int i = 2; i <= n; i++) {
        int mini = INT_MAX;
        for(int j = 1; j <= k; j++) {
            if(i - j < 1) break;
            mini = MIN(mini, dp[i - j] + abs(h[i] - h[i - j]));
        }
        dp[i] = mini;
    }
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>

int main(void)
{
	int i, c, x, n, min, s;
	
	scanf( "%d", &n );
	int a[n];
	for( i = 0; i < n; i++ ){
		scanf( "%d", &a[i] );
	}
	
	for( i = 0; i < n; i++ ){
		min = i;
		for( s = i; s < n; s++ ){
			if( a[s] < a[min] ){
				min = s;
			}
		}
		
		if( i != min ){
			x = a[i];
			a[i] = a[min];
			a[min] = x;
			c++;
		}
	}
	
	printf( "%d", a[0] );
	for( i = 1; i < n; i++ ){
		printf( " %d", a[i] );
	}
	printf( "\n%d\n", c );
	
	return 0;
}


Measured memory_bytes: 2068
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<climits> //INT_MIN/MAX


using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(e);(i)++)
#define FORR(i,s,e) for(int (i)=(s);(i)>(e);(i)--)
#define MOD 1000000007
#define llong long long
#define debug(x) cout<<#x<<": "<<x<<endl


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

    llong int N,ans=0;
    llong int a[100005];
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
     }

   llong int price = 1;
    FOR(i, 0, N) {
        if (a[i] > price) {
            int kk= (a[i] - 1) / price;
            ans += kk;
        }
        else if (a[i] == price) {
            price++;
        }
        if (price == 1)
            price++;
       
    }

        cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define INF 1e+18
using namespace std;

signed main(){
	int n;
	cin >> n;
	set<string> st;
	for(int i = 0;i < n;i++){
		string s;
		cin >> s;
		st.insert(s);
	}
	if(st.size() == 3) cout << "Three" << endl;
	else cout << "Four" << endl;
	return 0;
}

Measured memory_bytes: 256
import math
 
a,b,h,m = (int(x) for x in input().split())
dh = 30*h+0.5*m
dm = 6*m
if dh==dm:
  print(abs(a-b))
elif dh<dm:
  print(math.sqrt(a*a+b*b-2*a*b*math.cos(math.radians(dm-dh))))
else:
  print(math.sqrt(a*a+b*b-2*a*b*math.cos(math.radians(dh-dm))))

Measured memory_bytes: 62640
n = int(input())
A = [int(x) for x in input().split()]

B = {}
for i, a in enumerate(A):
    aa1 = i + 1 - a
    if aa1 > 0:
        if aa1 not in B:
            B[aa1] = []
        B[aa1].append((i + 1, a))

count = 0
for i, a in enumerate(A):
    aa1 = i + 1 + a
    if aa1 in B:
        count += len(B[aa1])
print(count)


Measured memory_bytes: 56284
/**
 *    author: codeforces-yuhongtao 
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<deque>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<sstream>
using namespace std;
#define pi acos(-1.0) 
#define ms(x,n) memset(x,n,sizeof(x));
#define pb push_back
typedef long long ll;//string::npos
typedef long long iint;
ll gcd(ll a,ll b){ return a%b==0?b:gcd(b,a%b); }
const int inf=0x3f3f3f3f;
const int maxn=5e5+5;
const int mod=1e9+7;
//priority_queue<ll,vector<ll>,greater<ll> > q;//小根堆 
//vector<int> vt[205];
//pair<int,int> p;
//map<string,int> m;
int main(){
	ios::sync_with_stdio(false);
	double k=100;
	long long t;
	cin>>t;
	int sum=0;
	while(k<t){
		k=floor(k*1.01);
		sum++;
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 3644
def insertion_sort(array, n, g)
  cnt = 0
  g.upto n - 1 do |i|
    v = array[i]
    j = i - g
    while j >= 0 && array[j] > v
      array[j + g] = array[j]
      j -= g
      cnt += 1
    end
    array[j + g] = v
  end
  cnt
end

def shell_sort(array, n)
  cnt = 0
  g = [1]
  g << 3 * g[-1] + 1 until 3 * g[-1] + 1 > n
  m = g.length
  g.reverse_each do |value|
    cnt += insertion_sort(array, n, value)
  end
  [array, cnt, m, g]
end

n = gets.to_i
array = []
n.times do
  array << gets.to_i
end

result = shell_sort array, n

puts result[2]
puts result[3].reverse.join(' ')
puts result[1]
puts result[0]



Measured memory_bytes: 14804
#include<bits/stdc++.h>
#include <ext/rope>

#define min3(a,b,c)   min(a,min(b,c))
#define max3(a,b,c)   max(a,max(b,c))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))

#define count_one(a) __builtin_popcount(a)  // Returns the number of set bits(1) in a number(a). In long long use __builtin_popcountll(a)
#define parity(i)    __builtin_parity(i)  //even parity 0 and odd parity 1
#define blz(a)       __builtin_clz(a) //Returns the number of leading zeroes in a number(a)
#define btz(a)       __builtin_ctz(a) //Returns the number of trailing zeroes in a number(a)
#define gcd(a,b)     __gcd(a,b)
#define lcm(a,b)     (a*(b/gcd(a,b)))

#define pb   push_back
#define PI   M_PI
#define endl "\n"
#define sc   scanf
#define pf   printf

#define ll  long long
#define ull unsigned long long

#define W(t)            while(t--)
#define rep1(i,n)       for(int i = 0; i < n; i++)
#define rep2(a,b)       for(int i = a; i <= b; i++)
#define rep3(a,b,c)     for(int i = a; i <= b; i+=c)
#define irep(a,b,c)     for(int i = b; i >=a; i-=c)
#define repit(it,type)  for(it = type.begin(); it != type.end(); it++)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
using namespace __gnu_cxx;

int main()
{
    IOS
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ll n,m,l,r,left = -1,right = INT_MAX;

    cin>>n>>m;

    W(m)
    {
        cin>>l>>r;
        left = max(left,l);
        right = min(r,right);
    }
    if(right-left+1>0)
        cout<<right-left+1<<endl;
    else
        cout<<0<<endl;


    return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,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; }

signed main(){
  int n;
  cin >> n;
  vstring ans(n);
  rep(i,0,n) cin >> ans[i];
  int ac = 0,wa = 0,tle = 0,re = 0;
  rep(i,0,n){
    if(ans[i] == "AC") ac++;
    if(ans[i] == "WA") wa++;
    if(ans[i] == "TLE") tle++;
    if(ans[i] == "RE") re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long int
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define Pb push_back
#define Mp make_pair
#define ff first
#define ss second
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define MOD (ll)1000000007
 
 
signed main()
{
    IOS;
    int n,cnt=0;
    cin >> n;
    string s;
    cin >> s;
    for(int i=0;i<s.size()-2;i++)
    {
      if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
      {
        cnt++;
      }
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


int main()
{
	int N;
	int D, X;
	cin >> N >> D >> X;

	vector<int> v( N );
	rep( i, N ) cin >> v[i];

	ll total = 0;
	rep( i, N )
	{
		for ( int j = 1; j <= D; j += v[i] )
		{
			total += 1;
		}
	}
	total += X;

	cout << total << endl;

	return ( 0 );
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll=long long;

int main(){
    ll n;
    cin>>n;
    if(n/100==7 || (n/10)%10==7 || (n%10)==7){
        cout<<"Yes";
    }else{
        cout<<"No";
    }

    return 0;
}


Measured memory_bytes: 3568
import math
n=int(input())
i=0
c=0
while i<n:
    m=int(input())
    sq=int(math.sqrt(m))
    j=2
    while j<=sq:
        if m%j==0:
            break
        else:
            j+=1
    if j>sq:
        c+=1
    i+=1
print(c)



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

int main()
{
  int n;
  int j, k;
  int suma, sumb;
  
  
  while (cin >> n){
    if (n == 0){
      break;
    }
    suma = sumb = 0;
    for (int i = 0; i < n; i++){
      cin >> j >> k;

      if (j < k){
        sumb += j + k;
     }
      else if (j > k){
        suma += j + k;
      }
     else {
        suma += j;
       sumb += k;
      }
    }
   cout << suma << " " << sumb << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <climits>
#include <algorithm>
using namespace std;




int main() 
{
	string s;
	
	cin>>s;
	
	if(s=="ABC"){
		cout<<"ARC";
	}
	else{
		cout<<"ABC";
	}


	





}




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

int main(void){
  int *a;
  int n, i, j;
  int max = -1000000000;
  scanf("%d", &n);
  a = malloc(n * sizeof(int));
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }

  int minv = a[0];
  for(i = 1; i < n; i++){
    if(max < a[i] - minv) max = a[i] - minv;
    if(minv > a[i]) minv = a[i];
  }


  printf("%d\n", max);
  return 0;
}

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

namespace CSharpSample01
{
    
    class Program
    {
        static bool Is_Prime(int n)
        {
            bool is_prime = true;

            for(int i = 2; i <= Math.Sqrt(n); i++)
            {
                if(n % i == 0)
                {
                    is_prime = false;
                    break;
                }
            }

            return is_prime;
        }


        static int Chebyshev(int n)
        {
            int num = 0;

            for(int i = n + 1; i <= 2 * n; i++)
            {
                if (Is_Prime(i))
                {
                    num++;
                }
            }

            return num;
        }





        static void Main(string[] args)
        {

            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0) break;

                Console.WriteLine(Chebyshev(n));

            }

        }
    }
}


Measured memory_bytes: 15936
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#define _USE_MATH_DEFINES

#include<math.h>
#include<unordered_map>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int main()
{
	int n;
	int a[100];
	int t = 0;

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

	for (int i = 0; i < n - 1; i++)
	{
		for (int j = n - 1; j != i; j--)
		{
			if (a[j] < a[j - 1])
			{
				int temp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = temp;
				t++;
			}
		}
	}

	for (int i = 0; i < n; i++)
	{
		cout << a[i];
		if (i < (n - 1))
		{
			cout << " ";
		}
	}
	cout << endl;
	cout << t << endl;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> B(N-1);
  ll sum=0;
  for(int i=0;i<N-1;i++){
    cin >> B.at(i);
  }
  sum += B.at(0);
  sum += B.at(N-2);
  for(int i=0;i<=N-3;i++){
    sum += min(B.at(i),B.at(i+1));
  }
  cout << sum << endl;
}

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

int main() {
	long long D, G, P[11], C[11], ans = 1000000000;
	cin >> D >> G;
	for (int i = 1; i <= D; i++) {
		cin >> P[i] >> C[i];
	}
	for (int i = 0; i < pow(2, D); i++) {
		long long count = 0, sum = 0, max = 0, X = i;
		for (int j = 1; j <= D; j++) {
			if (X % 2 == 1) {
				count += 100 * j * P[j] + C[j];
				sum += P[j];
			}
			else {
				max = j;
			}
			X /= 2;
		}
		if (count < G) {
			int N = (G - count) / (max * 100);
			if ((G - count) % (max * 100) != 0) N++;
			if (N < P[max]) sum += N;
			else sum = 1000000000;
		}
		ans = min(ans, sum);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=2*1e5+5;
bool primes[maxn];
void fl()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
int main()
{
//    fl();
	memset(primes,0,sizeof(primes));
	primes[1]=true;
	for(int i=2;i*i<=maxn;i++)
		if(primes[i]==false)
			for(int j=2*i;j<=maxn;j+=i)
				primes[j]=true;
	int n;
	scanf("%d",&n);
	for(int i=n;;i++)
		if(primes[i]==false)
		{
			printf("%d\n",i);
			return 0;
		}
	return 0;
}


Measured memory_bytes: 384
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    int solve(int n, int K) {
        vector<long long> dp(K + 1, 0);

        auto count = [&](int d) {
            int m = K / d;
            // cout << m << ": " << n << endl;
            return powM(m, n);
        };

        for (int i = K; i > 0; --i) {
            (dp[i] += count(i)) %= MOD;
            for (int j = 1; j * j <= i; ++j) {
                if (i % j == 0) {
                    int a = j;
                    int b = i / j;
                    if (a != i) {
                        (dp[a] += MOD - dp[i]) %= MOD;
                    }
                    if (b != a && b != i) {
                        (dp[b] += MOD - dp[i]) %= MOD;
                    }
                }
            }
            // cout << i << " " << dp[i] << endl;
        }

        long long res = 0;
        for (int i = 1; i <= K; ++i) {
            (res += i * 1LL * dp[i] % MOD) %= MOD;
        }

        return res;
    }

private:
    const static long long MOD = 1000000007;

    vector<long long> pow2;
    vector<long long> F;
    vector<long long> IF;

    long long norm(long long a) {
        a %= MOD;
        if (a < 0) {
            a += MOD;
        }
        return a;
    }

    long long inverse(long long a) {
        long long b = MOD;
        long long u = 0, v = 1;
        a = norm(a);
        while (a != 0) {
            long long d = b / a;
            b -= d * a;
            u -= d * v;
            swap(a, b);
            swap(u, v);
        }
        return norm(u);
    }

    long long powM(long long x, long long e) {
        long long res = 1;
        while (e > 0) {
            if (e & 1) {
                res = res * x % MOD;
            }
            x = x * x % MOD;
            e >>= 1;
        }
        return res;
    }

    void init(int n) {
        F.clear();
        F.resize(n + 1, 1);
        IF = F;
        pow2.clear();
        pow2.resize(n + 1, 1);
        for (int i = 1; i <= n; ++i) {
            pow2[i] = pow2[i - 1] * 2 % MOD;
        }

        for (int i = 1; i <= n; ++i) {
            F[i] = F[i - 1] * i % MOD;
        }
        IF[n] = inverse(F[n]);
        for (int i = n - 1; i > 0; --i) {
            IF[i] = IF[i + 1] * (i + 1) % MOD;
        }
    }

    long long nCr(int n, int r) {
        if (r < 0 || r > n) {
            return 0;
        }
        long long res = F[n] * IF[r] % MOD * IF[n - r] % MOD;
        return res;
    }

};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;
    Solution sol;

    cout << sol.solve(n, k) << "\n";

    return 0;
}

Measured memory_bytes: 3992
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int a, b, q;
    constexpr i64 inf = 1000000000000;
    std::cin >> a >> b >> q;
    std::vector<i64> s(a + 2), t(b + 2);
    s[0] = t[0] = -inf;
    s[a + 1] = t[b + 1] = inf;
    for (int i = 1; i <= a; i++) std::cin >> s[i];
    for (int i = 1; i <= b; i++) std::cin >> t[i];
    while (q--) {
        i64 x;
        std::cin >> x;
        i64 ret = std::numeric_limits<i64>::max();
        auto sit = std::upper_bound(s.begin(), s.end(), x),
            tit = std::upper_bound(t.begin(), t.end(), x);
        auto su = *sit, sl = *(sit - 1), tu = *tit, tl = *(tit - 1);
        ret = std::min(ret, std::max(su, tu) - x);
        ret = std::min(ret, x - std::min(sl, tl));
        ret = std::min(ret, tu - sl + std::min(tu - x, x - sl));
        ret = std::min(ret, su - tl + std::min(su - x, x - tl));
        std::cout << ret << std::endl;
    }

    return 0;
}


Measured memory_bytes: 2944
#include"bits/stdc++.h"
using namespace std;

long long N;
vector<long long> a;
vector<long long> a2;
//Binary Indexed Treeを用いる
//最大で200000までしかいかない
int bit[200100];
//bitを足す時はLSBが小さい方から大きい方へ
void add(long long a, int w){
    for (long long x = a; x<=200000; x += x & -x) bit[x] += w;
}
//和を求める時は、LSBが大きい方から小さい方へ
int sum(long long a){
    int ret = 0;
    for (long long x = a; x>0; x -= x & -x) ret += bit[x];
    return ret;
}

//x以上の要素がaの半数より多く存在するときture
bool check(long long x){
    //bitを初期化
    for (int i = 0; i<200100; i++) bit[i] = 0;
    //x以上とx未満を1と−1に置き換え
    vector<int> a3(N);
    for (int i = 0; i<N; i++){
        if (a2[i]>=x) a3[i] = 1;
        else a3[i] = -1;
    }
    //累積和
    //BITでは0以下の数を扱えないので、10^5を足しておけばよい
    vector<long long> acc(N+1);
    for (int i = 0; i<N+1; i++) acc[i] = 100000;
    for (int i = 0; i<N; i++) acc[i+1] = a3[i] + acc[i];
    
    long long ans = 0;
    for (int i = 0; i<N+1; i++){
        ans += sum(acc[i]);
        if (sum(acc[i])>100000) cout << sum(acc[i]) << endl;
        add(acc[i],1);
    }
    //ansがNの半数より大きいならtrue
    if (ans*2 >= N*(N+1)/2) return true;
    else return false;
}

//checkを満たす最小の整数を返す
int binarysearch(){
    int ng = N;
    int ok = -1;
    while (abs(ok-ng)>1){
        int mid = (ok+ng)/2;
        if (check(a[mid])) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(){
    cin >> N;
    vector<long long> raw_a(N);
    for (int i = 0; i<N; i++){
        cin >> raw_a[i];
    }
    a = raw_a;
    a2 = raw_a;
    sort(a.begin(),a.end());
    
    cout << a[binarysearch()] << endl;
    
}

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

int main(){
  string X;
  int a=0;
  int b;
  cin >> X;
  
  for(int i=0;i<X.size();i++){
    b = X.at(i);
    a = b +a -48;
  }
  if(a%9 == 0){
    cout << "Yes";
  }else{
    cout << "No";
  }
}

Measured memory_bytes: 3692
N = int(input())
ISP = []
for i in range(N):
  s,p = input().split()
  ISP.append([i+1,s,int(p)])

ISP = sorted(ISP,key= lambda x:-x[2])
ISP = sorted(ISP,key= lambda x:x[1])

for isp in ISP:
    print(isp[0])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define n 26

int main() {
       	string w;
       	cin >> w;
       	int array[n];
       	int flag = 0;
       	for(int i = 0; i < n; i++) {
       		array[i] = 0;
       	}

       	for(int i = 0; i < w.length(); i++) {
       		array[w[i] - 'a']++;
       	}
       	for(int i = 0; i < n; i++) {
       		if(array[i] % 2) {
       			flag = 1;
       			break;
       		}
       	}

       	if(flag) {
       		cout << "No" << endl;
       	} else {
       		cout << "Yes" << endl;
       	}

       	return 0;
}

Measured memory_bytes: 256
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime>
#include <bitset>

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};

int main() {
  ll x,k,d; cin>>x>>k>>d;
  x=abs(x);
  if (x/d >= k) {
    cout<<x - k*d<<endl;
    return 0;
  }
  k -= x/d;
  x %= d;
  //cout<<k<<" "<<x<<endl;
  if (k%2 == 0) {
    cout<<x<<endl;
  } else {
    cout<<abs(x-d)<<endl;
  }
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<complex>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph=vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;


int main(void)

{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << ketasitei;
	
	ll k, n;
	cin >> k >> n;

	vector<ll> a(n);
	ll sum = 0;
	ll m = 0;
	rep(i, n)
	{
		cin >> a[i];
	}

	for (int i = 1; i < n; i++)
	{
		sum += abs(a[i] - a[i - 1]);
		m = max(m, abs(a[i] - a[i - 1]));
	}
	sum += abs(a[0]+k-a[n-1]);
	m = max(m, abs(a[0]+k-a[n-1]));

	cout << sum - m << endl;

	return 0;
}

Measured memory_bytes: 1920
#include <stdio.h>

int main()
{
    int a, b;

    while (scanf("%d%d", &a, &b) == 2 && !(a == 0 && b == 0)) {
        if (a <= b) {
            printf("%d %d\n", a, b);
        } else {
            printf("%d %d\n", b, a);
        }
    }
}

Measured memory_bytes: 1028
#include<cstdio>
#include<algorithm>
using namespace std;
int Abs(int x)
{
	if(x<0)return -x;
	return x;
}
int main()
{
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	int n;
	scanf("%d",&n);
	int x=0,y=0,t=0;
	for(int i=1;i<=n;i++)
	{
		int tx,ty,tt;
		scanf("%d %d %d",&tt,&tx,&ty);
		int s=Abs(tx-x)+Abs(ty-y);
		if(tt-s-t<0||(tt-s-t)%2)
		{
			printf("No\n");
			return 0;
		}
		x=tx,y=ty,t=tt;
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class BBattle {
public:
	void solve(std::istream& in, std::ostream& out) {
        int a,b,c,d;
        in >> a >> b >> c >> d;
        bool t = true;
        while(a>0&&c>0){
            if(t){
                c-=b;
                t=false;
            }else{
                a-=d;
                t=true;
            }
        }
        if(a<=0){
            out << "No" << endl;
        }else{
            out << "Yes" << endl;
        }
	}
};


int main() {
	BBattle solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3636
H, W, K = [int(x) for x in input().split()]
 
init_map = []
 
for i in range(H):
    row = list(input())
    init_map.append(row)
 
#print(init_map)
 
ans = 0
 
for paint_h in range(2 ** H):
    #print("h: " + str(paint_h))
    for paint_w in range(2 ** W):
        #print("w: " + str(paint_w))
        cnt = 0
        for i in range(H):
            for j in range(W):
                if (paint_h >> i)&1 == 0 and (paint_w >> j)&1 == 0:
                    if init_map[i][j] == "#":
                        cnt += 1
        if cnt == K:
            ans += 1
print(ans)

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

template <class T, T MOD>
class ModuloCombination {
 private:
  std::vector<T> factrial, inverse_factrial;
  T Pow(T x, T y) {
    if (y == 0) return 1;
    if (y % 2 == 0) return Pow(x * x % MOD, y / 2);
    return x * Pow(x, y - 1) % MOD;
  }

 public:
  ModuloCombination(T n) : factrial(n + 1), inverse_factrial(n + 1) {
    inverse_factrial[0] = factrial[0] = 1;
    for (T i = 1; i <= n; i++) {
      factrial[i] = factrial[i - 1] * i % MOD;
      inverse_factrial[i] = Pow(factrial[i], MOD - 2);
    }
  }
  T operator()(T n, T k) {
    if (n < 0 || k < 0 || n < k) return 0;
    return factrial[n] * inverse_factrial[k] % MOD * inverse_factrial[n - k] % MOD;
  }
};

int main() {
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();

  vector<ll> p25(k + n + 1), p26(k + n + 1);
  p25[0] = p26[0] = 1;
  for (int i = 1; i < p25.size(); i++) {
    p25[i] = p25[i - 1] * 25 % MOD;
    p26[i] = p26[i - 1] * 26 % MOD;
  }

  ModuloCombination<ll, MOD> c(k + n);

  ll r = 0;
  for (int i = n; i <= n + k; i++) {
    r += c(i - 1, n - 1) * p25[i - n] % MOD * p26[n + k - i] % MOD;
    r %= MOD;
  }
  cout << r << endl;
}


Measured memory_bytes: 66668
<?php
//$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($H,$W,$M) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));
$bomb=array();
for($i=0;$i<$M;$i++) {
  list($h,$w) = array_map('intval',explode(" ",trim(fgets(STDIN))));
  $h--;
  $w--;
  $bomb[$h][$w]=1;
  if (isset($hbomb[$h])) {
    $hbomb[$h]++;
  }
  else {
    $hbomb[$h]=1;
  }
  if (isset($wbomb[$w])) {
    $wbomb[$w]++;
  }
  else {
    $wbomb[$w]=1;
  }
}
$hmax=max($hbomb);
$hmaxcnt=0;
//設置可能行数
foreach($hbomb as $h=>$v) {
  if ($v==$hmax) {
    $hmaxcnt++;
  }
}
//設置可能列数
$wmax=max($wbomb);
$wmaxcnt=0;
foreach($wbomb as $w=>$v) {
  if ($v==$wmax) {
    $wmaxcnt++;
  }
}
$bombpos=0;
//爆弾がある位置で設置可能位置の数
foreach($bomb as $h=>$v) {
  if ($hbomb[$h]!=$hmax) continue;
  foreach($v as $w=>$vv) {
    if ($wbomb[$w]!=$wmax) continue;
     $bombpos++;
  }
}
$ans = $hmax+$wmax;
//設置可能個所数と爆弾の数が一致しているときは爆弾がない場所には置けない
if ($bombpos==$hmaxcnt*$wmaxcnt) {
  $ans--;
}
printf("%d\n",$ans);


Measured memory_bytes: 167468
k=int(input())
two={4,6,9,10,14,21,22,25,26}
f={8,12,18,20,27}
if k in two:
    print(2)
elif k in f:
    print(5)
elif k==16:
    print(14)
elif k==24:
    print(15)
elif k==28 or k==30:
    print(4)
elif k==32:
    print(51)
else:
    print(1)


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

struct queue
{
string name;
int time;
};

int tail, head;
queue Q[1000000];

void enqueue(queue x);
queue dequeue();

int main()
{
	int n, q, t = 0, sum = 0;
	string str;
	cin >> n >> q;
	tail = n;
	head = 0;
	for(int i = 0; i < n; i++)
		cin >> Q[i].name >> Q[i].time;

	while(sum != n)
	{	
		if(Q[head].time <= q)
			t += Q[head].time;
		else
			t += q;
		Q[head].time -= q;
		if(Q[head].time<=0)
		{
			cout << Q[head].name << ' ' << t << endl;
			head++;
			sum++;
		}
		else
			enqueue(dequeue());
	}
	return 0;
}

void enqueue(queue x) { Q[tail++] = x; }

queue dequeue() { return Q[head++]; }

Measured memory_bytes: 19176
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void c_p_c()
{
	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*/
}

int32_t main()
{
	c_p_c();
	int n, k; cin >> n >> k;
	vi v(n);

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

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

	if (k >= n)
		cout << 0 << '\n';

	else
	{
		n = n - k;

		int ans = 0;

		for (int i = 0; i < n; ++i)
			ans += v[i];

		cout << ans << '\n';
	}
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#include <cmath>
#include <set>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <assert.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}


int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    set<string> s;

    int n;
    cin>>n;
    while (n--){
        string t;
        cin>>t;
        s.insert(t);
    }
    cout<<s.size()<<"\n";
    return 0;
}





Measured memory_bytes: 15600