akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) (x.begin(),x.end())
#include<math.h>
using namespace std;

int main()
{
    int n,a;
    cin>>n;
    double sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        sum+=(1.0/a*1.0);
    }
    printf("%.14lf\n",1.0/sum);
    return 0;

}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n:i32,
        y:i32,
    }
    let y = y / 1000;

    // i * 10 + j * 5 + k == y
    // k = y - i * 10 - j * 5
    // i + j + k == n
    // i + j + y - i *10 - j * 5 = n
    // i + j + y = n + i * 10 + j * 5
    // y = n + i * 9 + j * 4
    // j * 4 = y - n - i * 9
    // j = (y-n-i*9) / 4
    for i in 0..=n {
        let j = (y - n - i * 9) / 4;
        let k = n - i - j;
        if i * 10 + j * 5 + k == y && j >= 0 && k >= 0 {
            println!("{} {} {}", i, j, k);
            return;
        }
    }

    println!("-1 -1 -1")
}


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

using namespace std;

typedef unsigned uint;
typedef long long Int;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }

int main()
{
	int sum, a;
	while (cin >> sum, sum){
		for (int i = 0; i < 9; i++){
			cin >> a;
			sum -= a;
		}
		cout << sum << endl;
	}

    return 0;
}

Measured memory_bytes: 1160
#include<iostream>

int main(){
    int W,H;
    while(true){
        std::cin>>H>>W;
        if(W==0&&H==0)break;
        
        else{
        
            for(int i=0;i<H;i++){
                if(i%2==0){
                    for(int j=0;j<W;j++){
                        if(j%2==0)std::cout<<"#";
                        else std::cout<<".";
                    }
                }
                else{
                    for(int j=0;j<W;j++){
                        if(j%2==0)std::cout<<".";
                        else std::cout<<"#";
                    }
                }
                std::cout<<"\n";

            } 
        } 
        std::cout<<"\n";
       
    }
   
}


Measured memory_bytes: 3080
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>P;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string s;cin>>s;
    int i0=0,i1=1,i2=2,i3=3;
    int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';
    for(int bit=0;bit < (1<<i3); bit++)
    {
        int sum=a;
        if(bit & (1<<i0))
            sum+=b;
        else
            sum-=b;
        if(bit & (1<<i1))
            sum+=c;
        else
            sum-=c;
        if(bit & (1<<i2))
            sum+=d;
        else
            sum-=d;
        if(sum==7){
            cout<<a;
            if(bit & (1<<i0))
                cout<<'+';
            else
                cout<<'-';
            cout<<b;
            if(bit & (1<<i1))
                cout<<'+';
            else
                cout<<'-';
            cout<<c;
            if(bit & (1<<i2))
                cout<<'+';
            else
                cout<<'-';
            cout<<d<<'='<<sum<<endl;
            return 0;
        }
    }
    

    
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


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

using namespace std;

// https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/all/ALDS1_4_B

int bin(int x, const vector<int>& S, int from, int to) {
    if (x == S[from]) {
        return from;
    }
    else if (x == S[to]) {
        return to;
    }
    else if (x > S[to]) {
        return -1;
    }
    else if (to - from == 1) {
        return -1;
    }

    int mid = (from + to) / 2;
    int ret = 0;
    if (S[mid] <= x) {
        return bin(x, S, mid, to);
    }
    else {
        return bin(x, S, from, mid);
    }
    return ret;
}

void Main() {
    int n;
    cin >> n;
    vector<int> S(n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> S[i];
    }
    int q;
    cin >> q;
    vector<int> T(q, 0);
    for (int i = 0; i < q; ++i) {
        cin >> T[i];
    }

    sort(T.begin(), T.end());
    int ans = 0;
    int from = 0;
    for (int i = 0; i < q; ++i) {
        int res = bin(T[i], S, from, n - 1);
        if (res >= 0) {
            ++ans;
            from = res;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}



Measured memory_bytes: 3416
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

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

  int ans=K;
  for(int i=0;i<N;i++){
    int diff=0;
    if(i+1<N) diff=A[i+1]-A[i];
    else diff=A[(i+1)%N]+K-A[i];
    chmin(ans,K-diff);
  }

  cout<<ans<<endl;

  return 0;
}


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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;
using ld = long double;  using vld = vector<ld>; 

int main(void) {
    string s; cin >> s;

	vll a(3);a[0]=0;a[1]=0;a[2]=0;
	for(int i=0;i<3;i++){
		if(s[i]=='a') a[0]++;
		if(s[i]=='b') a[1]++;
		if(s[i]=='c') a[2]++;
	}
	
	if(a[0]==1&&a[1]==1&&a[2]==1)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define rep(i,l,n) for(i=l;i<n;i++)
 
int main(void){
    double x1,y1,x2,y2,z,ans;
     
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
     
    z=pow(x1-x2,2)+pow(y1-y2,2);
    ans=pow(z,0.5);
     
    printf("%f\n",ans);
    return 0;
}


Measured memory_bytes: 2096
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
import bisect
ans = 0
cnt = []
for i in b:
    cnt.append(n-bisect.bisect_right(c,i))
cnt += [0]
for i in range(n-1,-1,-1):
    cnt[i] += cnt[i+1]
for i in a:
    ans += cnt[bisect.bisect_right(b,i)]
print(ans)

Measured memory_bytes: 23200
# -*- coding: utf-8 -*-

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

N = int(input())
A = [int(a) for a in input().split()]

# GCDの結合則を利用する
# 左端、右端からの累積GCDを求めておくと、Aiを取り除いた場合のGCDがすぐに計算できる。
# つまり、
# L(i): n=0,...,iまでのGCD 
# R(i): n=i,...,N-1までのGCD
# このとき、Aiを除いた全体のGCDは、GCD(L(i-1), R(i+1))で計算できる。

L = [0] * N
R = [0] * N

L[0] = A[0]
R[-1] = A[-1]
for i in range(1, N):
    L[i] = gcd(L[i-1], A[i])
    idx = N-1-i
    R[idx] = gcd(R[idx+1], A[idx])

mx = 0
for i in range(N):
    if i == N-1:
        v = L[N-2]
    elif i == 0:
        v = R[1]
    else:
        v = gcd(R[i+1], L[i-1])
    mx = max(v, mx)
print(mx)


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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, a, n) for (int i = (n); i < (a); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int m;
  cin>>m;
  cout<<48-m<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <stdio.h>
#include <stdlib.h>

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

using namespace std;

int main(){
    char s[4];
    cin >> s;
    int num = atoi(s);
    bool mmyy = false;
    bool yymm = false;
    if ( 100 <= num && num <= 1299){
        mmyy = true;
    }

    if ( 1 <= (num % 100) && (num % 100) <= 12){
        yymm = true;
    }

    if (!mmyy && !yymm){
        cout << "NA" << endl;
    }else if (mmyy && !yymm){
        cout << "MMYY" << endl;
    }else if (!mmyy && yymm){
        cout << "YYMM" << endl;
    }else{
        cout << "AMBIGUOUS" << endl;
    }

    return 0;
}

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

int main()
{
    int  A, B;
    cin >> A >> B;
    int x = 1;
    while (A > x * 0.08)
        x++;
    int value10 = B * 10;
    value10 = max((x), value10);
    if (value10 < A / 0.08 +1/0.08 && value10 < B*10 + 10)
    {
        cout << value10;
    }
    else
    {
        cout << -1;
    }
    
    return 0;
}

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

using namespace std;


class combination
{
public:

	//Nの最大値がわかれば代入する
	combination( long long int combinationThreshold = 1e7 ) {
		(*this).combinationThreshold = combinationThreshold;
	}

	//a^p % mod
	inline long long int powmod( long long int A, long long int P, long long int M = LLONG_MAX ) {
		long long int ans = 1;
		long long int mul = A;
		for( ; P > 0; P >>= 1, mul = (mul*mul) % M ) {
			if( (P & 1) == 1 ) ans = (ans*mul) % M;
		}
		return ans;
	}

	//nCk mod m
	inline long long int cb( long long int N, long long int K, long long int M = LLONG_MAX ) {
		if( N < combinationThreshold ) {// 事前計算O(N)、答えるのはO(1)
			if( inv.size() == 0 ) {
				inv = vector<long long int>( combinationThreshold );
				inv[1] = 1;
				for( long long int i = 2; i < combinationThreshold; i++ ) {
					inv[i] = M - (M / i)*inv[M%i] % M;
				}
				fact = vector<long long int>( combinationThreshold );
				fact[0] = 1;
				revFact = vector<long long int>
					( combinationThreshold );
				revFact[0] = 1;
				for( long long int i = 1; i < combinationThreshold; i++ ) {
					fact[i] = (fact[i - 1] * i) % M;
					revFact[i] = (revFact[i - 1] * inv[i]) % M;
				}
			}
			return (((fact[N] * revFact[K]) % M)*revFact[N - K]) % M;
		} else {
			return cbOnce( N, K, M );
		}
	}

	//一回だけなら最速 O(K + log(M))
	inline long long int cbOnce( long long int N, long long int K, long long int M = LLONG_MAX ) {
		if( K > N / 2 ) return cb( N, N - K, M );
		long long int ans = 1;
		long long int div = 1;
		for( long long int i = 0; i < K; i++ ) {
			ans *= N - i;
			ans %= M;
			div *= i + 1;
			div %= M;
		}
		ans *= powmod( div, M - 2, M );
		return ans%M;
	}

private:
	vector<vector<long long int>>C;//3000以下の答え
	vector<long long int>fact;//階乗
	vector<long long int>revFact;//階乗の逆元
	vector<long long int>inv;//mod pでの逆元

	long long int combinationThreshold;//Nの最大値がわかれば入れる。
};

int main() {
	long long int H, W, A, B;
	cin >> H >> W >> A >> B;
	long long int ans = 0;
	if( min( H - A, W - B ) > min( A, B ) ) {
		combination cb( max( H - A + B - 1, A + W - B - 1 ) +2);
		for( long long int i = 0, lim = min( A, B ); i < lim; i++ ) {
			ans += cb.cb( H - A + B - 1, -i + B - 1, 1e9 + 7 )*cb.cb( A + W - B - 1, -i + A - 1, 1e9 + 7 );
			ans %= (long long int)1e9 + 7;
		}
		ans = (cb.cbOnce( H + W - 2, H - 1, 1e9 + 7 ) - ans + (long long int)1e9 + 7) % (long long int)(1e9 + 7);
	} else {
		combination cb( max( H - A + B - 1, A + W - B - 1 ) + 2 );
		for( long long int i = 0, lim = min( H - A, W - B ); i < lim; i++ ) {
			ans += cb.cb( H - A + B - 1, i + B, 1e9 + 7 )*cb.cb( A + W - B - 1, i + A, 1e9 + 7 );
			ans %= (long long int)1e9 + 7;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3968
#include <stdio.h>

int t[100005];
int x[100005];
int y[100005];

int main() {

	int N;

	scanf("%d",&N);

	int i;

	for(i=0;i<N;i++){
	scanf("%d %d %d",&t[i],&x[i],&y[i]);
	}

	int pos_x=0;
	int pos_y=0;
	int now_t=0;

	int ans=1;

	for(i=0;i<N;i++){
	int next_x=x[i]-pos_x;
	int next_y=y[i]-pos_y;
	int next_t=t[i]-now_t;
	if((next_t-next_x-next_y)%2==1 ||(next_t-next_x-next_y)<0 ){ans=0;}
	pos_x=next_x;
	pos_y=next_y;
	now_t=next_t;
	}

	if(ans==1){
	printf("Yes\n");
	}
	else{
	printf("No\n");
	}

	return 0;
}

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

int main(){
  int n;cin >> n;
  int h[n];rep(i,n)cin >> h[i];
  int dp[n+1];
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);
  for(int i=2;i<n;++i){
    dp[i] = min(abs(h[i]-h[i-1]) + dp[i-1],abs(h[i]-h[i-2]) + dp[i-2]);
  }
  cout << dp[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <stdlib.h>
#include <iomanip>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

int main() {
  ll n;
  cin >> n;
  ll p[n];
  for (ll i=0;i<n;i++) cin >> p[i];
  ll count = 0;
  for (ll i=1;i<n-1;i++){
    if (p[i-1]<p[i] && p[i]<=p[i+1]) count += 1;
    else if (p[i+1]<p[i] && p[i]<=p[i-1]) count += 1;
  }
  cout << count << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e7;  
using  p = pair<char,ll>;
int n,m;

int main(){
   cin >> n;
   auto s = map<string,int>();
   for (int i = 0; i < n; i++)
   {
      string ss;
      cin >> ss;
      if(s.find(ss)!=s.end()){
         s[ss]++;
      }else{
         s[ss]=0;
      }
   }
   
   auto m = vector<ll>(5,0);
   for (auto i : s)
   {
     //if(i.second!=0) continue;
      if(i.first[0]=='M'){
         m[0]++;
      }else if(i.first[0]=='A'){
         m[1]++;
      }else if(i.first[0]=='R'){
         m[2]++;
      }else if(i.first[0]=='C'){
         m[3]++;
      }else if(i.first[0]=='H'){
         m[4]++;
      }
   }
   s.clear();

   ll _max =0;
   if(m[0]!=0&&m[1]!=0&&m[2]!=0){
      _max+=m[0]*m[1]*m[2];
   }
   if(m[0]!=0&&m[1]!=0&&m[3]!=0){
      _max+=m[0]*m[1]*m[3];
   }
   if(m[0]!=0&&m[1]!=0&&m[4]!=0){
      _max+=m[0]*m[1]*m[4];
   }
   if(m[0]!=0&&m[2]!=0&&m[3]!=0){
      _max+=m[0]*m[2]*m[3];
   }
   if(m[0]!=0&&m[2]!=0&&m[4]!=0){
      _max+=m[0]*m[2]*m[4];
   }
   if(m[0]!=0&&m[3]!=0&&m[4]!=0){
      _max+=m[0]*m[3]*m[4];
   }
   if(m[1]!=0&&m[2]!=0&&m[3]!=0){
      _max+=m[1]*m[2]*m[3];
   }
   if(m[1]!=0&&m[2]!=0&&m[4]!=0){
      _max+=m[1]*m[2]*m[4];
   }
   if(m[1]!=0&&m[3]!=0&&m[4]!=0){
      _max+=m[1]*m[3]*m[4];
   }
   if(m[2]!=0&&m[3]!=0&&m[4]!=0){
      _max+=m[2]*m[3]*m[4];
   }
   cout << _max;
}
  
  

Measured memory_bytes: 11648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll N;
  cin>>N;
  ll a[N],b[N];
  for(ll i=0;i<N;i++) b[i]=0;
  for(ll i=0;i<N;i++){
    cin>>a[i];
    b[a[i]-1]++;
  }
  ll c=0;
  for(ll i=0;i<N;i++) c+=(b[i]*(b[i]-1))/2;
  ll ans[N];
  for(ll i=0;i<N;i++){
    ans[i]=c-(b[a[i]-1]-1);
    cout<<ans[i]<<endl;
  }
}


Measured memory_bytes: 7296
X = int(input())
go = 0
gohyaku = 0

while X >= 500:
    gohyaku += 1
    X -= 500
    
    
while X >= 5:
    go += 1
    X -= 5
    

ans = (gohyaku * 1000) + (go * 5)
print(ans)


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

vector<int> group = {0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};

int main() {
  int x, y;
  cin >> x >> y;
  string ans = (group[x-1] == group[y-1]) ? "Yes" : "No";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pl;
const ll N = 2e3 + 50;
const ll MOD = 1e9+7;

int a, b;

int main() {
cin>>a>>b;
  if(b>=a) {
  	cout<<"unsafe"<<endl;
  } else {
  	  	cout<<"safe"<<endl;

  }

   return 0;
}


Measured memory_bytes: 3580
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
/* 最大公約数 */
ll gcd(ll a, ll b) 
{
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

	vector<int> diffX;
	REP(i, N) {
		int x;
		cin >> x;
		diffX.emplace_back(abs(X - x));
	}

	ll ans = diffX[0];
	for (int i = 1; i < N ;i++) {
		ans = min(ans, gcd(ans, diffX[i]));
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> K(N, 0);
  vector<int> count(M, 0);
  for (int i = 0; i < N; ++i) {
    cin >> K[i];
    for (int j = 0; j < K[i]; ++j) {
      int A;
      cin >> A; A--;
      count[A]++;
    }
  }
  
  int ans = 0;
  for (int i = 0; i < M; ++i) {
    if (count[i] == N) ans++;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  vi a(3,0);
  cin >> a[0] >> a[1] >> a[2];
  vi loop = {0,1,2};
  int ans = 100000000;
  rep(i,6) {
    int cost = 0;
    cost+=abs(a[loop[0]]-a[loop[1]]);
    cost+=abs(a[loop[1]]-a[loop[2]]);

    ans=min(ans,cost);
    next_permutation(rng(loop));
  }

  cout << ans << endl;

}


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

  class Program
    {
        static void Main(string[] args)
        {
           //First Input
           var arr1 = Console.ReadLine().ToCharArray();

           var arr2 = Console.ReadLine().ToCharArray();

              //Zipping the data

           // var result = arr1.Zip(arr2, x => x, y => y, r => x + '' + y )


           var result = GetDifferences(arr1, arr2);

            Console.WriteLine(result.Count());

            Console.ReadKey();



        }

        public static IEnumerable<char> GetDifferences(char[] arr1, char[] arr2)
        {
            for (int i = 0; i < arr1.Length; i++)
            {
                if (arr1[i] == arr2[i])
                    yield return arr2[i];
            }
        }

    }

Measured memory_bytes: 13268
#include <string>
#include <iostream>
#include <list>

using namespace std;

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

void solve(){
    string t; getline(cin,t);
    list<char> s(t.begin(),t.end());

    auto it=s.begin();
    int n; cin>>n; cin.get();
    while(n--){
        string cmd; getline(cin,cmd);

        if(cmd=="forward char"){
            if(it!=s.end()) ++it;
        } else if(cmd=="forward word"){
            while(it!=s.end() && *it==' ')
                ++it;
            while(it!=s.end() && *it!=' ')
                ++it;
        } else if(cmd=="backward char"){
            if(it!=s.begin()) --it;
        } else if(cmd=="backward word"){
            while(it!=s.begin() && *--it==' ')
                ;
            while(it!=s.begin()){
                --it;
                if(*it==' '){
                    ++it;
                    break;
                }
            }
        } else if(cmd.substr(0,6)=="insert"){
            int i=cmd.find('"')+1,j=cmd.find('"',i);
            s.insert(it,cmd.begin()+i,cmd.begin()+j);
        } else if(cmd=="delete char"){
            if(it!=s.end()) it=s.erase(it);
        } else if(cmd=="delete word"){
            auto it2=it;
            while(it2!=s.end() && *it2==' ') ++it2;
            if(it2==s.end()) continue;
            while(it2!=s.end() && *it2!=' ') ++it2;
            it=s.erase(it,it2);
        }
    }
    for(auto i=s.begin();;++i){
        if(i==it)
            cout<<'^';
        if(i==s.end())
            break;
        cout<<*i;
    }
    cout<<endl;
}

int main(){
    int t; cin>>t;
    cin.get();
    rep(i,t) solve();
}

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

using namespace std;

int main(){
    int N; string S;
    while(cin >> N >> S){
        S += "0";
        vector<int> v;
        int cnt = 0;
        for(const auto& c : S){
            if(c == '0'){
                v.push_back(cnt);
                cnt = 0;
            } else {
                ++cnt;
            }
        }
        vector<vector<int>> dp(3, vector<int>(v.size(), 0));
        for(int i=0;i+1<v.size();i++){
            for(int dec=0;dec<3;dec++){
                dp[0][i+1] = max(dp[0][i+1], dp[dec][i]);
                if(dec < 2){
                    int l = v[i] - dec;
                    int r = v[i+1];
                    if(l > 0 && r > 0){
                        dp[1][i+1] = max(dp[1][i+1], dp[dec][i]+l);
                        dp[2][i+1] = max(dp[2][i+1], dp[dec][i]+r); 
                    }
                } else if(v[i] >= 2) {
                    int l = 1;
                    int r = v[i+1];
                    if(l > 0 && r > 0){
                        dp[1][i+1] = max(dp[1][i+1], dp[dec][i]+l-1);
                        dp[2][i+1] = max(dp[2][i+1], dp[dec][i]+r-1); 
                    }
                }
            }
        }
        cout << max(dp[0].back(), max(dp[1].back(), dp[2].back())) << endl;
    }
}

Measured memory_bytes: 10744
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s,t="";
    cin >> s;
    for(int i=0;i<s.length();i++){
        t+=s[s.length()-1-i];
    }
    int i=0;
    while(1){
        if(i==t.length())break;
        if(t.substr(i,6)=="resare"){
            i+=6;
        }
        else if(t.substr(i,5)=="esare"){
            i+=5;
        }
        else if(t.substr(i,7)=="remaerd"){
            i+=7;
        }
        else if(t.substr(i,5)=="maerd"){
            i+=5;
        }
        else break;
    }
    cout << ((i==t.length())?"YES":"NO") << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#define max(i,j) (i<j?j:i)
short dp[4001][4001];
int main(void){
	char s[4001],t[4001];
//	printf("%d\n",4000*4000);
	while(scanf("%s",s)!=EOF){
		scanf("%s",t);
//		dp[0][0]=s[0]==t[0];
		for(int i=0;i<4001;i++)dp[i][0]=dp[0][i]=0;
		int sl = strlen(s),tl = strlen(t);
		int ans = 0;
		for(int i=1;i<=sl;i++){
			for(int j=1;j<=tl;j++){
				if(s[i-1]==t[j-1]){
					dp[i][j]=dp[i-1][j-1]+1;
					ans = max(ans,dp[i][j]);
				}else dp[i][j]=0;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 32244
#include<bits/stdc++.h>                          
using namespace std;                          
int t[200],ans[200],ch[200];
                     
int main(){
	int n;
	cin>>n;      
	string s; 
		for(int i=0;i<200;i++)
	{		
	   ans[i]=0x3f3f3f3f;
    }   
	
	for(int i=0;i<n;i++)
	{		
	    cin>>s; 
	    memset(ch,0,sizeof(ch));
		       
		for(int i=0;i<s.size();i++)
		{
		    ch[s[i]]++;	
		}  
		for(int i='a';i<='z';i++)
		{
	    	ans[i]=min(ans[i],ch[i]);			
		}
    }   
	for(int i='a';i<='z';i++)
	{
		for(int j=0;j<ans[i];j++)
		{
			cout<<(char)i;
		}
	}    
	return 0;
}                                               

Measured memory_bytes: 256
#include<stdio.h>
    int main(){
      int n,x;
      scanf("%d%d", &n, &x);
      int i, l, sum=0, c=1;
      for(i=0;i<n;i++){
        scanf("%d", &l);
        sum+=l;
        if(sum<=x) c++;
      }
      printf("%d", c);
      return 0;
    }

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


// float calc_sum (int num){
//     if (num%2 == 0) {
//         return (num+1)*(num/2);
//     } else {
//         return (num+1)*(num/2)+num/2+1;
//     }
// }

int main() {

	int n, k; cin >> n >> k;
    vector<double> p(n), q(n + 1, 0);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        q[i + 1] = q[i] + (p[i] + 1) / 2;
    }
    
    double ans = 0;
    for (int i = 0; i < n - k + 1; i++) {
        ans = max(ans, q[i + k] - q[i]);
    }

    // cout << ans << endl;
    printf("%.10f", ans);
}


Measured memory_bytes: 3328
// C++のテンプレート
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main(void){
    int N,L;
    cin >> N >> L;
    vector<string> S(N);
    for(int i=0;i<N;i++)
        cin >> S[i];
    sort(S.begin(),S.end());
    for(int i=0;i<N;i++){
        cout << S[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
package main

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

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

const LIM = 100000

func eratosthenes(prime []bool, n int) {
	for i := 2; i <= n; i++ {
		if !prime[i] {
			continue
		}
		for j := i * i; j <= n; j += i {
			prime[j] = false
		}
	}
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	prime := make([]bool, LIM+1)
	for i := 2; i <= LIM; i++ {
		prime[i] = true
	}
	eratosthenes(prime, LIM)

	acc := make([]int, LIM+1)
	for i := 3; i < LIM; i += 2 {
		switch {
		case prime[i] && prime[(i+1)/2]:
			acc[i] = acc[i-2] + 1
		default:
			acc[i] = acc[i-2]
		}
	}

	q := nextInt()
	for i := 0; i < q; i++ {
		l, r := nextInt(), nextInt()
		switch {
		case l == 1:
			fmt.Println(acc[r])
		default:
			fmt.Println(acc[r] - acc[l-2])
		}
	}
}


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

int main(void){
    long long n,q;
    long long t;
    cin>>n>>t>>q;
    vector<pair<long long,int> >c(n);
    vector<long long> ans;
    for (int i = 0; i < n; ++i) {
        cin>>c[i].first>>c[i].second;
        if(c[i].second==2)c[i].second=-1;
    }
    for (int i = 0; i < n-1; ++i) {
        if(c[i].second==1)if(c[i].second!=c[i+1].second)ans.push_back((c[i].first+c[i+1].first)/2);
    }
    for (int i = 0; i < q; ++i) {
        int a;
        cin>>a;
        a=a-1;
        if(c[a].second==1) {
            for (int j = 0; j < ans.size(); ++j) {
                    if (c[a].first < ans[j]) {
                        if (abs(ans[j] - c[a].first) < t) {
                            cout << ans[j] << endl;
                            break;
                        }
                        else {
                            long long an = t * c[a].second + c[a].first;
                            cout << an << endl;
                            break;
                        }
                    }
                    if(j==ans.size()-1){
                    long long an = t * c[a].second + c[a].first;
                    cout << an << endl;
                    break;
                }

            }
        }
        else{
            for (int j = ans.size()-1; j >= 0; --j) {
                if (c[a].first > ans[j]) {
                    if (abs(ans[j] - c[a].first) < t) {
                        cout << ans[j] << endl;
                        break;
                    } else {
                        long long an = t * c[a].second + c[a].first;
                        cout << an << endl;
                        break;
                    }
                }
                if(j==0){
                    long long an = t * c[a].second + c[a].first;
                    cout << an << endl;
                    break;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4820
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#include<set>
using namespace std;
using ll = long long;

int main(){
    while(1){
        string str;
        int y,m,d;
        cin >> str;
        if(str=="#")    break;
        cin >> y >> m >> d;
        if(y==31&&m>=5) cout << "? " << y-30 << " " << m << " " << d<<endl;
        else if(y>31)   cout << "? " << y-30 << " " << m << " " << d<<endl;
        else    cout << str << " " << y << " " << m << " "  << d << endl;
    } 
}



Measured memory_bytes: 3164
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
using namespace std;
#define MOD 1000000007




int main() {
	string s;
	cin >> s;
	int a = 0;
	int b = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0') {
			a++;
		}
		else {
			b++;
		}
	}
	if (a < b) {
		cout << 2 * a;
	}
	else {
		cout << 2 * b;
	}
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007

int main(){
    string s; cin >> s;
    sort(s.begin(), s.end());
    if(s.size()==1){
        cout << "No" << endl;
        return 0;
    }
    s.push_back('A');
    int c = 1;
    for(int i=0; i<s.size()-2; i++){
        if(s[i+1]==s[i]) c++;
        else {
            if(c%2){
                cout << "No" << endl;
                return 0;
            }
            c = 1;
        }
    }
        
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
/* ** *** Be Name Khoda *** ** */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
bool mark[maxn];
vector <int> v[maxn];
void dfs(int a)
{
    mark[a] = 1;
    for (int u : v[a])
        if (!mark[u]) dfs(u);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, ans = 0;
    cin >> n >> m;
    while (m--)
    {
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for (int i=1;i<=n;i++)
    {
        if (!mark[i]) dfs(i),ans++;
    }
    cout << ans - 1;
    return 0;
}

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

int main() {
    long long n, retl = 0, retr = 0;
    std::cin >> n;
    std::vector<long long> l(n), r(n);
    std::multiset<std::tuple<long long, long long, long long>> mr;
    std::multiset<std::tuple<long long, long long, long long>, std::greater<>> ml;
    for (auto i = 0ll; i < n; i++) {
        std::cin >> l[i] >> r[i];
        ml.emplace(l[i], r[i], i);
        mr.emplace(r[i], l[i], i);
    }

    auto pos = 0ll;
    // when i is odd, go left; go right otherwise
    for (auto i = 0ll; i < n; i++) {
        long long lp, rp, index;
        if (i % 2) {
            auto curr = *mr.begin();
            rp = std::get<0>(curr), lp = std::get<1>(curr), index = std::get<2>(curr);
            if (rp < pos) {
                retl += pos - rp;
                pos = rp;
            }
        } else {
            auto curr = *ml.begin();
            lp = std::get<0>(curr), rp = std::get<1>(curr), index = std::get<2>(curr);
            if (pos < lp) {
                retl += lp - pos;
                pos = lp;
            }
        }
        mr.erase(mr.find(std::make_tuple(rp, lp, index)));
        ml.erase(ml.find(std::make_tuple(lp, rp, index)));
    }
    retl += (pos < 0 ? -pos : pos);

    for (auto i = 0ll; i < n; i++) {
        ml.emplace(l[i], r[i], i);
        mr.emplace(r[i], l[i], i);
    }

    pos = 0;
    for (auto i = 0ll; i < n; i++) {
        long long lp, rp, index;
        if (i % 2 == 0) {
            auto curr = *mr.begin();
            rp = std::get<0>(curr), lp = std::get<1>(curr), index = std::get<2>(curr);
            if (rp < pos) {
                retr += pos - rp;
                pos = rp;
            }
        } else {
            auto curr = *ml.begin();
            lp = std::get<0>(curr), rp = std::get<1>(curr), index = std::get<2>(curr);
            if (pos < lp) {
                retr += lp - pos;
                pos = lp;
            }
        }
        mr.erase(mr.find(std::make_tuple(rp, lp, index)));
        ml.erase(ml.find(std::make_tuple(lp, rp, index)));
    }
    retr += (pos < 0 ? -pos : pos);

    std::cout << std::max(retl, retr) << std::endl;

    return 0;
}

Measured memory_bytes: 14336
#include <iostream>
using namespace std;
int main(){
	int n;
	while(cin >> n){
	int x = 0;
	for(int a=0;a<10;a++){
	for(int b=0;b<10;b++){
	for(int c=0;c<10;c++){
	for(int d=0;d<10;d++){
		if(a+b+c+d==n) x++;
	}}}}
	cout << x << endl;
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  
 if(s.at(0)==s.at(1) && s.at(1)==s.at(2)){
   cout << "No" << endl;
 }
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
const int maxn =2e5;

int main()
{
    string a;cin>>a;
    int n=a.size();
    string b="";
    for(int i=0;i<n;i++)
    {
        if(a[i]=='?')b+='D';
        else b+=a[i];
    }
    cout<<b<<endl;
}


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

int main() {
    string S;
    bool alpha[26];
    cin >> S;
    for(int i = 0; i < 26; i++)
        alpha[i] = false;
    for(int i = 0; i < S.size(); i++)
        alpha[S[i] - 'a'] = true;
    for(int i = 0; i < 26; i++) {
        if(!alpha[i])
        {
            cout << char(i + 'a') << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A =new int[N];
    for(int i =0; i<N; i++){
      A[i] = sc.nextInt();
    }
    int oCost = Math.abs(A[0]) + Math.abs(A[N-1]);
    for(int i =0; i<N-1; i++){
        oCost = oCost + Math.abs(A[i]-A[i+1]);
    }
    for(int i=0; i<N; i++){
      int tCost = 0;
      if(i == 0){
        tCost = oCost - Math.abs(A[0]) - Math.abs(A[0]-A[1]) + Math.abs(A[1]);
      }
      else if(i == N-1){
        tCost = oCost - Math.abs(A[N-1]) - Math.abs(A[N-1]-A[N-2]) + Math.abs(A[N-2]);
      }
      else{
        tCost = oCost - Math.abs(A[i]-A[i-1]) - Math.abs(A[i]-A[i+1]) + Math.abs(A[i-1]-A[i+1]);
      }
      System.out.println(tCost);
    }
  }
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n = 55555;
    int p[n + 1];
    rep(i, n + 1) p[i] = 1;
    p[0] = 0, p[1] = 0;
    for (int i = 2; i <= (int)sqrt(n); i++)
    {
        if (p[i] == 1)
        {
            for (int j = 2; i * j <= n; j++)
            {
                p[i * j] = 0;
            }
        }
    }
    int m;
    cin >> m;
    int cnt = 0;
    vector<int> a;
    rep(i, 55555)
    {
        if (cnt == m)
            break;
        if (p[i] == 1 && i % 5 == 1)
        {
            a.push_back(i);
            cnt++;
        }
    }
    rep(i, m) i != 0 ? cout << " " << a[i] : cout << a[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 512
using System;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;

class Program
    {
        static void Main(string[] args)
        {
            var inp = Console.ReadLine().Split();
            var inp2 = Console.ReadLine().Split();

            int[] nInp = Array.ConvertAll(inp, int.Parse);
            int[] nInp2 = Array.ConvertAll(inp2, int.Parse);

            Array.Sort(nInp2);

            int totCost = 0;

            for(var i = 0; i<nInp[1]; i++)
            {
                totCost = totCost + nInp2[i];
            }
            Console.WriteLine(totCost);
        }
    }

Measured memory_bytes: 27916
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define ALL(c) (c).begin(),(c).end()
typedef pair<int,int> P;
vector<P> pl,mi;
int main(){
	int n;
	cin >> n;
	rep(i,n){
		string s;
		cin >> s;
		int now=0,mn=0;
		rep(j,s.size()){
			if(s[j]=='(') now++;
			else now--;
			mn=min(mn,now);
		}
		int a=-mn,b=now-mn;
		if(b-a>0) pl.push_back(P(a,b));
		else mi.push_back(P(b,a));
	}
	int now=0;
	sort(ALL(pl));
	sort(ALL(mi),greater<P>());
	rep(i,pl.size()){
		if(now<pl[i].first){
			cout << "No" << endl;
			return 0;
		}
		now+=(pl[i].second-pl[i].first);
	}
	rep(i,mi.size()){
		if(now<mi[i].second){
			cout << "No" << endl;
			return 0;
		}
		now+=(mi[i].first-mi[i].second);
	}
	if(now==0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3204
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

k, n = inpl()
a = inpl()
a.append(k+a[0])
l = 0
for i in range(n):
    l = max(l, a[i+1] - a[i])
print(k-l)

Measured memory_bytes: 26952
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int n;


	cin >> n;

	// 正直
	vector< vector<int> > right(n);
	//  不親切
	vector< vector<int> > wrong(n);


	for (int i = 0; i < n; i++) {
		//cout << "i:" << i << endl;
		int a;

		cin >> a;
		for(int j = 0; j < a; j++) {
			int x, y;
			cin >> x >> y;
			x--;
			if (y == 0) {
				wrong[i].push_back(x);
			} else {
				right[i].push_back(x);
			}
		} 
	}



	int search_max = (1 << n);

	int max_right = 0;

	//cout << "search_max:" << search_max << endl;

	for (int i = 0; i < search_max; i++) {
		//cout << "i:" << i << endl;
		int rw[n];
		int tmp = i;
		int count = 0;
		for (int j = 0; j < n; j++) {
			rw[j] = ( tmp & 1);
			tmp = (tmp >> 1);
			if (rw[j] == 1) {
				count ++;
			}

		}

		if (count <= max_right) {
			continue;
		}


		bool result = true;
		for (int j = 0; j < n; j++) {
			if (rw[j] == 0) continue;

			//cout << "j:" << j << " rw==1" << endl; 
			
			for (int r : right[j]) {
				if (rw[r] == 0) {
					result = false;
					break;
				} 
				//cout << "r:" << r << endl;
			}
			if (result == false) break;
			for (int w : wrong[j]) {
				if (rw[w] == 1) {
					result = false;
					break;
				}
				//cout << "w:" << w << endl;

			}
			if (result == false) break;
		}
		//cout << "end:" << max_right <<endl;
		if (result == false) continue;
		//cout << "OK:" << i << " c:" << count <<  endl;
		max_right = count;

	}


	cout << max_right << endl;
 
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <bitset>
#include <string>
#include <array>
#include <random>
#include <chrono>
#include <algorithm>
 
int main(void){
	int n, m;
	std::cin >> n >> m;
	std::vector<int> a(n);
	for(int i=0;i<n;i++){
		std::cin >> a[i];
	}
	std::sort(a.begin(), a.end());
	std::vector<std::pair<int, int>> bc(m);
	for(int i=0;i<m;i++){
		std::cin >> bc[i].first;
		std::cin >> bc[i].second;
	}
	std::sort(bc.begin(), bc.end(), [](const std::pair<int, int>& lhs, const std::pair<int, int>& rhs){
		return lhs.second > rhs.second;
	});
	int idx=0;
	for(int i=0;i<m;i++){
		for(int j=0;j<bc[i].first;j++){
			if(a[idx] < bc[i].second){
				a[idx] = bc[i].second;
				idx++;
			}
			else{
				break;
			}
		}
	}
	uint64_t sum = 0;
	for(int i=0;i<n;i++)sum+=a[i];
	std::cout << sum << std::endl;

}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main()
{
    string a[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string s;
    cin >> s;
    for (int i = 0;i<7;++i){
        if (a[i] == s){
            cout << 8-(i+1);
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll,ll>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
ll rnd(){
	ull ans=0;
	For(i,0,4)ans=ans<<15^rand();
	return ans%((ull)1<<63);
}
const int N=1000005;
char ch[N];
int ans;
int main(){
	#ifdef Brollan
		//freopen("1.in","r",stdin);
	#endif
	scanf("%s",ch+1);
	int n=strlen(ch+1);
	int x=0,y=0;
	Rep(i,n,1){
		if(ch[i]=='0'){x++; y--;}
		else if(ch[i]=='1'){x--; y++;}
		else {x--; y--;}
		x=max(x,0);
		y=max(y,0);
		ans=max(ans,max(x,y));
	}
	int mx=0,l=0,r=0,sum=0,zt=0;
		For(i,1,n){
			if(l==r)zt=0;
			if(ch[i]=='0'){
				l++; r++; 
				if(l>sum){
					l=r=++sum; if(mx&1)l--; mx=0; zt=l!=r;
				}else if(r>sum){if(zt)r=sum; else {r=sum-1; mx|=2;}}
				else if(r==sum){
					if(!zt)mx&=1;
				}
			}else if(ch[i]=='1'){
				l--; r--; 
				if(r<0){
					sum++; l=r=0; if(mx&2)r++; mx=0; zt=l!=r;
				}else if(l<0){if(zt)l=0; else {l=1; mx|=1;}}
				else if(l==0){
					if(!zt)mx&=2;
				}
			}else{
				if(i==1){
					l=0; r=1; sum=1; zt=1; continue;
				}
				l--; r++;
				if(r>sum){if(zt)r=sum; else {r=sum-1; mx|=2;}}
				else if(r==sum){
					if(!zt)mx&=1;
				}
				if(l<0){if(zt)l=0; else {l=1; mx|=1;}}
				else if(l==0){
					if(!zt)mx&=2;
				}
			}
			//cout<<l<<" "<<r<<" mx:"<<mx<<" sum:"<<sum<<" "<<zt<<endl;
		}
	cout<<sum<<endl;
}
/*
04
13
04
13
22
*/

Measured memory_bytes: 4744
input = gets.chomp.split(" ").map(&:to_i)

X = input[0]
Y = input[1]
money = 0

case X
when 1 then
  money += 300000
when 2 then
  money += 200000
when 3 then 
  money += 100000
end
  
case Y
when 1 then
  money += 300000
when 2 then
  money += 200000
when 3 then
  money += 100000
end
  
if money == 600000
  money += 400000
end
  
puts money

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	vector<string> s(3);
	for (int i = 0; i < 3; i++) cin >> s[i];
	string ans;
	for (int i = 0; i < 3; i++) {
		ans.push_back(s[i][0] - 'a' + 'A');
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>

int main()
{
	int N;
	std::cin >> N;
	if (N%27==0) std::cout << N*25/27 << std::endl;
	else {
		int M = N * 25/27 + 1;
		if (M*27/25==N) std::cout << M << std::endl;
		else std::cout << ":(" << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3584