akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()


template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int N;cin>>N;
  int cnt = 1;
  for (int i = 0; i < N; i++)
  {
    int X;cin>>X;
    if(X%2 == 0)
    {
      cnt *=2;
    }
  }
  cout<<(int)pow(3,N) - cnt<<endl;
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);

std::cout << std::fixed;
std::cout << std::setprecision(9);
solve();

return 0;
}

Measured memory_bytes: 384
n,k,q= list(map(int, input().split()))
lis=[k-q]*n
for i in range(q):
    a=int(input())
    a-=1
    lis[a]+=1
    
for i in range(n):
    if lis[i]>0:
        print("Yes")
    else:
        print("No")

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

long int M = 1e+9+7;
int main(void){
    int n;
    ll k;
    cin >> n >> k;
    vi a(n+1);
    rrep(i,n){
        cin >> a[i];
    }
    int now=1;
    int nk;
    vi kita(n+1,-1);
    rep(i,k){
        if(kita[now]==-1){
            kita[now]=i;
            //cout << i << " " << now  << " " << a[now] << endl;
            now = a[now];
        }else{
            int sa=i-kita[now];
            nk = (k-i)%sa;
            break;
        }
    }
    rep(i,nk){
        now = a[now];
    }
    cout << now << endl;
    return 0;
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;

int w, h, si, sj, gi, gj;
int dp[1005][1005];
string s[1005];
vector<P> pos[5];

int rec(int i, int j, int S, int pre){
    if(S==(1<<5)-1){
        return abs(i-gi)+abs(j-gj);
    }
    if(dp[i][j] != -1) return dp[i][j];
    int res = IINF/3, m = (pre+1)%5;
    for(auto p : pos[m]){
        int pi = p.first, pj = p.second;
        res = min(res, rec(pi, pj, S|(1<<m), m) + abs(i-pi) + abs(j-pj));
    }
    return dp[i][j] = res;
}

int main() {
    while(cin >> w >> h, w){
        for(int i=0;i<h;i++) cin >> s[i];
        for(int i=0;i<5;i++) pos[i].clear();
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(s[i][j] != '.'){
                    if(s[i][j]=='S'){
                        si = i;
                        sj = j;
                    }
                    else if(s[i][j]=='G'){
                        gi = i;
                        gj = j;
                    }
                    else{
                        pos[s[i][j]-'1'].push_back({i,j});
                    }
                }
            }
        }
        bool ok = true;
        for(int i=0,cnt=0;i<5;i++){
            if(pos[i].size()==0)cnt++;
            if(cnt>=2){
                cout << "NA" << endl;
                ok = false;
                break;
            }
        }
        if(!ok) continue;
        int ans=IINF, id=0;
        for(int i=0;i<5;i++){
            for(int i=0;i<h;i++) fill(dp[i], dp[i]+w, -1);
            int tmp = rec(si, sj, 1<<i, i);
            if(tmp < ans){
                ans = tmp;
                id = i+1;
            }
        }
        cout << id << " " << ans << endl;
    }
    
    return 0;
}



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

namespace d
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var As = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var Q = int.Parse(Console.ReadLine());

            var arr = new long[100001];
            for (var i = 0; i < As.Length; i++)
            {
                arr[As[i]]++;
            }
            var sum = As.Sum();

            for (int i = 0; i < Q; i++)
            {
                var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
                sum += (input[1] - input[0]) * arr[input[0]];
                arr[input[1]] += arr[input[0]];
                arr[input[0]] = 0;
                Console.WriteLine(sum);
            }
        }
    }
}


Measured memory_bytes: 45400
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  vector<string> vec = {"SAT","FRI","THU","WED","TUE","MON","SUN"};

  int ans;
  for (ans = 0; vec.at(ans) != S; ans++) {
  };
  cout << ans+1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, m;
	cin >> n >> m;

	vector<string> grid;
	grid.push_back(string(m + 2, '.'));
	string s;
	for (int i = 0; i < n; ++i) {
		cin >> s;
		s = '.' + s;
		s.push_back('.');
		grid.push_back(s);
	} 

	grid.push_back(string(m + 2, '.'));

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			if (grid[i][j] == '.') {
				int bombs = 0;
				if (grid[i - 1][j - 1] == '#') {
					++bombs;
				}
				if (grid[i - 1][j] == '#') {
					++bombs;
				}
				if (grid[i - 1][j + 1] == '#') {
					++bombs;
				}
				if (grid[i][j - 1] == '#') {
					++bombs;
				}
				if (grid[i][j + 1] == '#') {
					++bombs;
				}
				if (grid[i + 1][j - 1] == '#') {
					++bombs;
				}
				if (grid[i + 1][j] == '#') {
					++bombs;
				}
				if (grid[i + 1][j + 1] == '#') {
					++bombs;
				}

				grid[i][j] = bombs + '0';
			}
		}
	}

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			cout << grid[i][j];
		}

		cout << "\n";
	}

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
using namespace std;
const int mod=1e9+7;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main(){
    fast;
    int n,k;
    cin>>n>>k;
    bool a[n]={false};
    int d;
    for(int i=0;i<k;i++){
        cin>>d;
        int b[d];
        for(int i=0;i<d;i++){
            cin>>b[i];
            a[b[i]-1]=1;
        }
    }
    int sum=0;
    for(int i=0;i<n;i++){
        if(!a[i]) sum++;
    }
    cout<<sum;
}


Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{	
	int e,y,x;	
	scanf("%d %d",&e,&y);
	if(e==1){
	x=1867+y;
	printf("%d\n",x);
	}
	else if(e==2){
	x=1911+y;
	printf("%d\n",x);
	}
	else if(e==3){
	x=1925+y;
	printf("%d\n",x);
	}
	else if(e==4){
	x=1988+y;
	printf("%d\n",x);
	}
	else if(e==0){
		if(y>=1868&&y<=1911){
		x=y-1868+1;
		printf("M%d\n",x);
		}
		else if(y>=1912&&y<=1925){
		x=y-1912+1;
		printf("T%d\n",x);
		}
		else if(y>=1926&&y<=1988){
		x=y-1926+1;
		printf("S%d\n",x);
		}
		else if(y>=1989&&y<=2016){
		x=y-1989+1;
		printf("H%d\n",x);
		}
		}
	return 0;
}


Measured memory_bytes: 2760
#include<bits/stdc++.h>
#define sd(x) scanf("%d",&x)
#define ss(x) scanf("%s",x)
#define sc(x) scanf("%c",&x)
#define sf(x) scanf("%f",&x)
#define slf(x) scanf("%lf",&x)
#define slld(x) scanf("%lld",&x)
#define me(x,b) memset(x,b,sizeof(x))
#define pd(d) printf("%d\n",d);
#define plld(d) printf("%lld\n",d);
// #define Reast1nPeace

typedef long long ll;

using namespace std;

const int INF = 0x3f3f3f3f;

map<string , int> m;

int dir[4] = {-4,4,-1,1};

void bfs(){
	queue<string> q;
	m["01234567"] = 1;
	q.push("01234567");
	
	while(!q.empty()){
		string t =  q.front() ; q.pop();
		
		int pi;
		for(int i = 0 ; i<8 ; i++){
			if(t[i] == '0'){
				pi = i;
				break;
			}
		}
		
		for(int i = 0 ; i<4 ; i++){
			if(pi==4 && i==2)	continue;
			if(pi==3 && i==3)	continue;
			
			int np = pi+dir[i];
			if(np<0||np>=8)	continue;
			
			string st = t;
			swap(st[pi],st[np]);
			if(m[st] == 0){
				m[st] = m[t]+1;
				q.push(st);
			}
		}
	}
}

int main(){
#ifdef Reast1nPeace
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	bfs();
	string s;
	while(getline(cin,s)){
		string mapp = "";
		for(int i = 0 ; i<s.size() ; i++){
			if(i%2==0){
				mapp += s[i];
			}
		}
		cout<<m[mapp]-1<<endl;
	}
	return 0;
}



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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

// constexpr int INF = 1e9;
constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

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


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

const ll MAX = 4000010;
const ll MOD = 1e9 + 7;
long long fac[MAX], finv[MAX], inv[MAX];
 
 
void COMinit() {
 fac[0] = fac[1] = 1;
 finv[0] = finv[1] = 1;
 inv[1] = 1;
  for (ll i = 2; i < MAX; i++){
  fac[i] = fac[i - 1] * i % MOD;
  inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
       finv[i] = finv[i - 1] * inv[i] % MOD;
        }
      }
 
   long long COM(ll n, ll k){
  if (n < k){ return 0;}
  if (n < 0 || k < 0) {return 0;}
     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
     }

int main(){
ll N; cin >> N; map<ll,ll> mp; ll d; COMinit();
 
  vector<ll> A(N+1); for(ll i = 0; i <= N; i++){
    cin >> A[i]; mp[A[i]]++; if( mp[A[i]] == 2){ d = A[i]; }}
  vector<ll> itr;
  for(ll i = 0; i <= N; i++){ if(A[i] == d){ itr.push_back(i);}}
  
  ll a = itr[0];ll b = itr[1]-itr[0]-1; ll c = N-itr[1];
 
  for(ll k = 1; k <= N+1; k++){//数列からk個とってくることを考える
    if( k == 1){ cout << N << endl;}
    else{
      ll sum = 0;
      if(a+b+c>=k){sum += COM(a+b+c,k); sum %= MOD;}
      if(a+b+c>=k-1){sum += 2*COM(a+b+c,k-1); sum %= MOD;}
      if(a+b+c>=k-2){sum += COM(a+b+c,k-2); sum %= MOD;}
      if(a+c>=k-1){sum += MOD-COM(a+c,k-1); sum %= MOD;}
      cout << sum << endl; }
  }
  
  return 0;}
      
    
                                

Measured memory_bytes: 102016
#include<stdio.h>

int main(){
    int a[1000000] = {0};
    int i, j, n, cnt;
    
    while(scanf("%d",&n)!=EOF){
        for (i = 0; i <= n; i++) a[i] = 0;
        
        cnt = 0;
    
        for (i = 2; i <= n; i++) {
            if (a[i] == 0) {
	            cnt++;
                for (j = 1; i*j <= n; j++) a[i*j] = 1;
            }
        }
        printf("%d\n",cnt);
    }
  return 0;
}


Measured memory_bytes: 5676
# include <bits/stdc++.h>
using namespace std;
int main()
{
	int A,B,C;
	cin>>A>>B>>C;
	if(A==B&&A!=C){
		cout<<C;
	}else if(A==C&&A!=B){
		cout<<B;
	}else if(B==C&&B!=A){
		cout<<A; 
	}
	
	
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, D, X[10][10], res;


int main() {
	cin >> N >> D;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < D; ++j) {
			cin >> X[i][j];
		}
	}
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			int c = 0;
			for (int k = 0; k < D; ++k) {
				c += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
			}
			for (int k = 0; k*k <= c; ++k) {
				if (k*k == c) {
					++res;
					break;
				}
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 384
n = int(input())
data = [[[],[]] for _ in range(n)]
ans = 0
for i in range(n):
    a = int(input())
    for _ in range(a):
        x,y = map(int,input().split())
        data[i][y].append(x-1)
for i in range(1,2**n):
    S1 = set([])
    S2 = set([])
    for j in range(n):
        if (i >> j) & 1:
            S1.add(j)
        else:
            S2.add(j)
    flag = True
    for i in S1:
        for j in range(2):
            if data[i][j]:
                if j == 0:
                    for k in data[i][j]:
                        if k in S1:
                            flag = False
                else:
                    for k in data[i][j]:
                        if k in S2:
                            flag = False
    else:
        if flag:
            ans = max(ans,len(S1))
print(ans)    

Measured memory_bytes: 3064
N=int(input())
num_list=list(map(int,input().split(" ")))
MAX=500000
L=[None]*((MAX)//2+2)
R=[None]*((MAX)//2+2)
def merge(A,left,mid,right):
    cnt=0
    n1=mid-left
    n2=right-mid


    for i in range(n1):
        L[i]=A[i+left]
    for i in range(n2):
        R[i]=A[i+mid]
    L[n1]=(10**9+1)
    R[n2]=(10**9+1)
    j,k=0,0
    for i in range(left,right):
        cnt+=1
        if L[j]<=R[k]:
            A[i]=L[j]
            j+=1
        else:
            A[i]=R[k]
            k+=1
    return cnt
def mergesort(A,left,right):
    if left+1<right:
        mid=(left+right)//2
        cntL=mergesort(A,left,mid)
        cntR=mergesort(A,mid,right)
        return merge(A,left,mid,right)+cntL+cntR
    return 0
cnt=mergesort(num_list,0,N)
print(*num_list)
print(cnt)


Measured memory_bytes: 61660
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<sstream>
#include<iomanip>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=100005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
string s;
int cnt,ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>s;
	forn(i,s.size())
		if(s[i]=='R')
		{
			cnt++;
			ans=max(ans,cnt);
		}
		else cnt=0;
	cout<<ans;
	return 0;
}


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

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            return Array().Select(int.Parse).ToArray();
        }
        public long[] LongArray()
        {
            return Array().Select(long.Parse).ToArray();
        }
    }

    class Program
    {
        private int N;
        private int[] T, X, Y;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            T = new int[N];
            X = new int[N];
            Y = new int[N];
            for (int i = 0; i < N; i++)
            {
                T[i] = sc.NextInt();
                X[i] = sc.NextInt();
                Y[i] = sc.NextInt();
            }
        }

        public void Solve()
        {
            Scan();
            int xx = 0;
            int yy = 0;
            int tt = 0;
            for (int i = 0; i < N; i++)
            {
                int dist = Math.Abs(X[i] - xx) + Math.Abs(Y[i] - yy);
                int time = T[i] - tt;
                if (dist > time || (time - dist) % 2 == 1)
                {
                    Console.WriteLine("No");
                    return;
                }
                xx = X[i];
                yy = Y[i];
                tt = T[i];
            }
            Console.WriteLine("Yes");
        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  string s ; 
  int k ;
  cin >> s >> k ; 
  bool OK = true ;
  int now = 0 ; 
  int x = s.size() - 1 ;
  
  while(OK){
    if(s.at(now) != '1') {
      cout << s.at(now) <<endl ; 
      OK =false ; 
      break ; 
    }
    if(now ==min(x,k-1) ) {
      cout << 1 ;
      OK = false ; 
    }
    now ++ ; 
  }
    
}


Measured memory_bytes: 3608
s=str(input())
L=len(s)
if L==1:
    print('-1 -1')
    exit()
elif L==2 and s[0]==s[1]:
    print('1 2')
    exit()
elif L==2 and s[0]!=s[1]:
    print('-1 -1')
    exit()
    


for i in range(L-1):
    if s[i]==s[i+1] and i+1==L-1:
        print(i,i+2)
        exit()
    elif s[i]==s[i+1] and i+1<L-1:
        print(i+1,i+3)
        exit()
        
for i in range(L-2):
    if s[i]==s[i+2]:
        print(i+1,i+3)
        exit()
 
print('-1 -1')

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

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

    int test[s];

    for (int i = 0; i < s;i++){
        cin >> test[i];
    }
    bool a = true;
    for (int i = 0; i < s-1; i++){
        if(test[i] >= test[i + 1]){
            a = false;
        }
    }
    if(a == true){
        cout << "YES" << endl;
        return 0;
    }
    int test_a[s];
    for (int t = 0; t < s; t++)
    {
        test_a[t] = test[t];
    }
    bool b = true;
    for (int i = 0; i < s - 1;i++){
        for (int j = i + 1; j < s;j++){
            for (int t = 0; t < s; t++){
                test[t] = test_a[t];
            }
            b = true;
            int tmp;
            tmp = test[j];
            test[j] = test[i];
            test[i] = tmp;
            for (int m = 0; m < s - 1; m++){   
                if (test[m] >= test[m + 1]){
                    b = false;
                }
            }
            if(b == true){
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
// Author - Sumit

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define int ll
#define ps push
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
#define mp make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

void solve(){
    int n;
    cin>>n;
    int a[n];
    rep(i,0,n) cin>>a[i];   
    int ar[n];
    ar[0]=0;
    ar[1]=abs(a[1]-a[0]);
    rep(i,2,n){
        ar[i] = min(ar[i-1]+abs(a[i]-a[i-1]),ar[i-2]+abs(a[i]-a[i-2]));
    }
    // for(auto x:ar){
    //     cout<<x<<" ";
    // }cout<<endl;
    debug(ar[n-1]);
}

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

    int t=1;
    // cin>>t;
    WL(t){
        solve();
    }    
}

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
const int mod = 1000000007;
int n;
int a[200100];
struct st {
	int loc, val;
	bool operator<(const st&r)const {
		return val < r.val;
	}
};
st s[200100];
const int itsz = 1 << 18;
int ita[2 * itsz];
int itb[2 * itsz];
long long int mpow(long long int x, long long int y) {
	if (y == 0)return 1;
	long long int r = mpow(x, y / 2);
	r *= r;
	r %= mod;
	if (y % 2 == 1) {
		r *= x;
		r %= mod;
	}
	return r;
}
long long int minv(long long int x) {
	return mpow(x, mod - 2);
}
void itupd(int *it, int loc, int val) {
	loc += itsz;
	it[loc] = val;
	loc /= 2;
	while (loc > 0) {
		it[loc] = (it[loc * 2] + it[loc * 2 + 1]) % mod;
		loc /= 2;
	}
}
int itcalc(int *it, int start, int end) {
	int res = 0;
	start += itsz;
	end += itsz;
	while (start <= end) {
		if (start % 2 == 1) {
			res += it[start];
			res %= mod;
			start++;
		}
		if (end % 2 == 0) {
			res += it[end];
			res %= mod;
			end--;
		}
		start /= 2;
		end /= 2;
	}
	return res;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; i++) {
		s[i].loc = i;
		s[i].val = a[i];
	}
	std::sort(s, s + n);
	int rs = n - 1;
	int cnt = 0;
	long long int permn = 1;
	for (int i = n; i > 0; i--) {
		while (rs >= 0 && s[rs].val == i) {
			rs--;
			cnt++;
		}
		permn *= cnt;
		permn %= mod;
		cnt--;
	}
	if (permn == 0) {
		printf("0");
		return 0;
	}
	rs = n - 1;
	cnt = 0;
	long long int avgd = 0;
	long long int cadd = 1;
	int lz = n;
	for (int i = n; i > 0; i--) {
		while (rs >= 0 && s[rs].val == i) {
			avgd += itcalc(itb, 0, s[rs].loc - 1);
			avgd += mod - (itcalc(ita, 0, s[rs].loc - 1)*cadd%mod*minv(2)) % mod;
			avgd += itcalc(ita, s[rs].loc + 1, n)*cadd%mod*minv(2) % mod;
			avgd %= mod;
			itupd(ita, s[rs].loc, minv(cadd));
			itupd(itb, s[rs].loc, 1);
			rs--;
			cnt++;
		}
		cadd *= minv(cnt);
		cadd %= mod;
		cadd *= (cnt - 1);
		cadd %= mod;
		if (cnt == 1) {
			cadd = 1;
			for (int j = rs + 1; j < lz; j++) {
				itupd(ita, s[j].loc, 0);
			}
			lz = rs + 1;
		}
		cnt--;
	}
	long long int ans = permn*avgd%mod;
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define fi first
#define se second
#define pb push_back
#define pbb pop_back
#define make_pair mp
#define all(x) x.begin(), x.end()
#define mem(array, value) memset(array, value, sizeof(array))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a,b))*b
#define line cout << "==========" << endl
#define mod 1000000007
#define SIZE 1000001

int main ()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((abs(a-b) <= d && abs(b-c) <= d) || abs(a-c) <= d){
        cout << "Yes\n";
    }
    else
        cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let k: usize = read();
    let a: Vec<u64> = (0..n).map(|_| read()).collect();

    let mut map = HashMap::new();

    for v in a.into_iter(){
        let count = map.entry(v).or_insert(0);
        *count += 1;
    }

    let mut syuuyaku: Vec<(u64, u64)> = Vec::new();
    for (k,v) in map.into_iter(){
        syuuyaku.push((k,v));
    }
    syuuyaku.sort_by(|a,b| a.1.partial_cmp(&b.1).unwrap());

    if syuuyaku.len() <= k {
        println!("0");
    }else{
        let mut ans = 0;
        for i in 0..(syuuyaku.len() - k) {
            ans += syuuyaku[i].1;
        }
        println!("{}",ans);
    }

}


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

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

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

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

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int x, y;
  while (cin >> x >> y) {
    cout << x + (y / 2) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

struct book {
    int price;
    int genre;

    book() {}
    ~book() {}

    bool operator < (const book& o) const {
        return genre < o.genre;
    }
};

int N, K;
book b[2010];
vector<vector<int>> tb;
vector<int> tc;

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

    cin >> N >> K;
    for (int j = 0; j < N; ++j) {
        cin >> b[j].price >> b[j].genre;
    }

    sort(b, b + N);

    int prev_g = 1, g;
    int ta[2010], cnt = 1;
    fill(ta, ta + K+1, 0);

    for (int j = 0; j < N; ++j, prev_g = g) {
        g = b[j].genre;
        ++cnt;

        if (g != prev_g) {
            tb.emplace_back(ta, ta + K+1);
            fill(ta + 1, ta + K+1, 0);
            cnt = 1;
        }
        
        for (int k = min(K, cnt); k >= 1; --k) {
            ta[k] = max(ta[k], ta[k-1] + b[j].price + 2 * (k-1));
        }
    }
    tb.emplace_back(ta, ta+K+1);

    tc.resize(K+1);
    for (int j = 1; j < tb.size(); ++j) {
        fill(begin(tc), end(tc), 0);
        for (int k = 0; k <= K; ++k) {
            for (int l = 0; l <= k; ++l) {
                tc[k] = max(tc[k], tb[j][k-l] + tb[j-1][l]);
            }
        }
        for (int k = 0; k <= K; ++k) {
            tb[j][k] = tc[k];
        }
    }

    int answer = 0;
    for (int j = 0; j <= K; ++j) {
        answer = max(answer, tb.back()[j]);
    }
    cout << answer << endl;

    return 0;
}

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

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  priority_queue<ll, vector<ll>, greater<ll>> ans;
  //卓1で試合をするとき
  ll ans1 = 0;
  ans1 = max(A-1, B-1);
  ans.push(ans1);
  //卓Nで試合するとき
  ll ans2 = 0;
  ans2 = max(N-A, N-B);
  ans.push(ans2);
  //2人の中間ポイントで試合するとき
  if ((B-A) % 2 == 0) {
    ll ans3;
    ans3 = (B-A)/2;
    ans.push(ans3);
  }
  else {
    ll ans6;
    ans6 = min(A-1, N-B) + 1 +(B-A-1)/2;
    ans.push(ans6);
  } 
  cout << ans.top() << endl;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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

      
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(M)]
r = 0

for z in range(M):
  uf = UnionFind(N)
  for i in range(M):
    if z == i:
      continue
    uf.union(ab[i][0]-1,ab[i][1]-1)
  r += uf.group_count()-1

print(r)

Measured memory_bytes: 3064
n = int(input())
if n >= 10**5:
  print(90909)
elif n >= 10**4:
  print(n - 10000 + 910)
elif n >= 10**3:
  print(909)
elif n >= 10**2:
  print(n - 100 + 10)
elif n >= 10**1:
  print(9)
elif n >= 10**0:
  print(n)

Measured memory_bytes: 38448
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  vi A(N),B(N);
  rep(i,N) {
    cin >> A[i];
  }
  rep(i,N) {
    cin >> B[i];
  }
  deque<int> a,b;
  rep(i,N) {
    int diff = B[i] - A[i];
    if(diff == 0) continue;
    if(diff > 0) {
      a.push_back(diff);
    } else {
      b.push_back(-1 * diff);
    }
  }
  int alen = sz(a);
  int blen = sz(b);
  sort(rng(a));
  sort(rng(b));
  reverse(rng(b));
  ll x = 0;
  bool ok = false;
  while(1) {
    if(a.empty()) {
      ok = true;
      break;
    }
    if(b.empty()) {
      break;
    }
    x += b[0];
    b.pop_front();
    while(!a.empty()) {
      ll y = a[0];
      if(y > x) {
        break;
      }
      a.pop_front();
      x -= y;
    }
  }
  if(!ok) {
    cout << -1 << endl;
    return 0;
  }
  cout << blen + alen - sz(b) - sz(a) << endl; 
  return 0;
}

Measured memory_bytes: 1408
while True:
    try:
        a= list(map(int,input().split()))
        b= list(map(int, input().split()))
        hit = sum([1 for i in range(4) if a[i] == b[i]])
        blow = sum([1 for i in range(4) for j in range(4) if i != j and a[i] == b[j]])
        print(str(hit) + " " + str(blow))
    except:
        break


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

int main(){
	int x1, x2, y1, y2;
	scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
	int x3, x4, y3, y4;
	x4 = -(y2 - y1) + x1;
	y4 = (x2 - x1) + y1;
	x3 = -(y1 - y4) + x4;
	y3 = (x1 - x4) + y4;
	printf("%d %d %d %d\n", x3, y3, x4, y4);
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    int z = sc.nextInt();
    int k = sc.nextInt();
    long[] a = new long[x];
    long[] b = new long[y];
    long[] c = new long[z];
    for(int i = 0; i < x; i++) {
      a[i] = sc.nextLong();
    }
    for(int i = 0; i < y; i++) {
      b[i] = sc.nextLong();
    }
    for(int i = 0; i < z; i++) {
      c[i] = sc.nextLong();
    }
    long[] ab = new long[x * y];
    for(int i = 0; i < x; i++) {
      for(int j = 0; j < y; j++) {
        ab[i * y + j] = a[i] + b[j];
      }
    }
    Arrays.sort(ab);
    long[] abc = new long[k * z];
    for(int i = x * y - 1; i >= Math.max(x * y - k, 0); i--) {
      for(int j = 0; j < z; j++) {
        abc[(x * y - 1 - i) * z + j] = ab[i] + c[j];
      }
    }
    Arrays.sort(abc);
    for(int i = k * z - 1; i >= k * z - k; i--) {
      System.out.println(abc[i]);
    }
  }
}

Measured memory_bytes: 62056
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D){
    cout << "Left" << endl;
  }else if (A + B < C + D){
    cout << "Right" << endl;
  }else if (A + B == C + D){
    cout << "Balanced" << endl;
  }
}


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

int dele(vector<vector<int>> &st){
    int res=0;
    for(int i=0;i<st.size();i++){
        int pre=-1;
        int cnt=0;
        for(int j=0;j<=5;j++){
            if(j<5 && pre==st[i][j])
                cnt++;
            else{
                if(cnt>=3){
                    for(int r=j-cnt;r<j;r++)
                        res+=st[i][r],st[i][r]=0;
                    cnt=1;
                }
                else if(j<5){
                    pre=st[i][j];
                    cnt=1;
                }

            }


        }

    }
    return res;

}

void drop(vector<vector<int>> &st){
    for(int j=0;j<5;j++){
        int cnt=0;
        for(int i=st.size()-1;i>=0;i--){
            if(st[i][j]==0)
                cnt++;
            else{
                if(cnt>0){
                for(int r=i;r>=0;r--){
                    st[r+cnt][j]=st[r][j];
                    st[r][j]=0;
                }
                i=i+cnt;
                cnt=0;
                }
            }

        }



    }


}

int main()
{
    int h;
    while(cin>>h,h){
        vector<vector<int>> st(h,vector<int>(5));
        for(int i=0;i<h;i++)
            for(int j=0;j<5;j++){
                cin>>st[i][j];
            }
        int res=0;
        while(true){
            int sc=dele(st);
            if(sc==0)
                break;
            res+=sc;
            drop(st);

        }
        cout<<res<<endl;
    }
}
                  

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define f18 1000000000000000000

int main()
{
  ll a;cin>>a;
  string b;cin>>b;
  vector<int> bs(3);
  bs[0]=b[0]-'0';
  bs[1]=b[2]-'0';
  bs[2]=b[3]-'0';
  ll bn=bs[0]*100+bs[1]*10+bs[2];
  cout<<a*bn/100<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    int N;
    string S;
    cin >> N >> S;
    vector<int> alp(26, 0);
    for (char c : S)
    {
        alp[c - 'a']++;
    }
    ll ans = 1;
    for (int a : alp)
    {
        ans = (ans * (a + 1)) % MOD;
    }
    if (ans != 0)
    {
        cout << ans - 1 << endl;
    }
    else
    {
        cout << MOD - 1 << endl;
    }
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 512
n,m = map(int,input().split())
par , rank = [],[] 

for i in range(n): 
    par.append(i)
    rank.append(0)

def find(x):
    if par[x] == x : return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y): 
    x = find(x)
    y = find(y)
    if (x != y):
        if rank[x] < rank[y]:
            par[x] = y
        else :
            par[y] = x
            if (rank[x] == rank[y]) : rank[x] += 1

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

    
p = list(map(int,input().split()))

for i in range(m):
    x,y = map(int,input().split())
    unite(x-1,y-1)

dic = {}

for i in range(n):
    i1 = find(i)
    if i1 in dic:
        dic[i1].append(i)
    else:
        dic[i1] = [i]
        

cnt = 0
for pp in list(dic):
    l = dic[pp]
    ll = []
    for i in l:
        ll.append(p[i]-1)
    for q in ll:
        if(par[q] == pp):cnt += 1
    
print(cnt)

Measured memory_bytes: 31960
# include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll L[90];
void init(){
	L[0]=2;
	L[1]=1;
	for(int i=2;i<=87;i++){
		L[i]=L[i-1]+L[i-2];
	}
}
int main()
{
	int n;
	init();
	scanf("%d",&n);
	printf("%lld\n",L[n]);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        String[] a = new String[n];
        String[] b = new String[m];
        for (int i = 0; i < n; i++) {
            a[i] = sc.next();
        }
        for (int i = 0; i < m; i++) {
            b[i] = sc.next();
        }
        for (int i = 0; i < n - m + 1; i++) {
            for (int j = 0; j < a[0].length() - b[0].length() + 1; j++) {
                int count = 0;
                for (int k = 0; k < m; k++) {
                    if (b[k].equals(a[k + i].substring(j, b[k].length() + j)))
                        count++;
                    else
                        ;
                }
                if (count == m) {
                    System.out.println("Yes");
                    System.exit(0);
                }
            }
        }
        System.out.println("No");
    }
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001001001001l;

int N,K,Q;
int A[2222];

int calc(int Y){
    vector<int>lis;
    int cur=0;
    while(cur<N){
        if(A[cur]<Y){
            cur++;continue;
        }
        int nex=cur;
        vector<int>v;
        while(nex<N&&A[nex]>=Y){
            v.pb(A[nex]);
            nex++;
        }
        sort(all(v));
        rep(i,(int)v.size()-K+1)lis.pb(v[i]);
        cur=nex;
    }
    sort(all(lis));
    if(lis.size()<Q)return INF;
    return lis[Q-1]-Y;
}

signed main(){
    cin>>N>>K>>Q;
    rep(i,N)cin>>A[i];

    int ans=INF;
    rep(i,N)chmin(ans,calc(A[i]));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
N, M = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

X.sort()
if N == 1:
    print(X[-1]-X[0])

X.append(0)
A = []
for x, y in zip(X[:-1], X[1:]):
    A.append(y-x)
B = A[:-1]
C = sorted(B)

if N == 2:
    print(sum(C[:-1]))
elif N > 2:
    print(sum(C[:-N+1]))


Measured memory_bytes: 13840
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int h, w;
  cin >> h >> w;
  int cnt = 0;
  char x[8][8] = {};
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> x[i][j];
      if (x[i][j] == '#') cnt++;
    }
    getchar();
  }
  cnt == h+w-1 ? dump("Possible") : dump("Impossible");
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define sd second
#define lson (nd<<1)
#define rson (nd+nd+1)
#define PB push_back
#define mid (l+r>>1)
#define MP make_pair
#define SZ(x) (int)x.size()
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
const int MAXN=200'005;
const int MOD=1000000007;
void addmod(int& a, int b){a+=b;if(a>=MOD)a-=MOD;}
int mulmod(int a, int b){return 1ll*a*b%MOD;}
int a,b,c;
int x,y;
int A[MAXN], B[MAXN], C[MAXN];
priority_queue<int,vector<int>, greater<int>> q;
int main(){
	cin>>x>>y;
    cin>>a>>b>>c;
	for(int i=1;i<=a;++i)cin>>A[i];
    for(int i=1;i<=b;++i)cin>>B[i];
    for(int i=1;i<=c;++i)cin>>C[i];
    sort(A+1,A+1+a);
    sort(B+1,B+1+b);
    sort(C+1,C+1+c);
    LL ans=0;
    for(int i=a;i>=a-x+1;--i)q.push(A[i]), ans+=A[i];
    for(int i=b;i>=b-y+1;--i)q.push(B[i]), ans+=B[i];
    for(int i=c;i>=1;--i){
        if(C[i]>q.top()){
            ans-=q.top();
            q.pop();
            q.push(C[i]);
            ans+=C[i];
        }
    }
    cout<<ans;
    return 0;
}


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

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





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 16;
const ll inf = 1e18;

int n;
int a[maxn][maxn];

vector<ll> pts; //pts[mask]: points if mask is in same group
vector<ll> dp; //dp[mask]: max points if dp[mask] are in groups



void dfs(int i, vector<int>& avail, int mask, int groupMask, ll val) {
    int len = avail.size();
    if (i == len) {
	dp[mask] = max(dp[mask], val + pts[groupMask]);
	return;
    }

    dfs(i+1, avail, mask, groupMask, val);
    dfs(i+1, avail, mask|(1<<avail[i]), groupMask|(1<<avail[i]), val);
}


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

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

    pts.resize(1<<n, 0);
    for (int mask=0; mask<(1<<n); mask++) {
	for (int i=0; i<n; i++) {
	    for (int j=i+1; j<n; j++) {
		if ((mask>>i&1) && (mask>>j&1)) {
		    pts[mask] += a[i][j];
		}
	    }
	}
    }

    
    
    dp.resize(1<<n, -inf);

    dp[0] = 0;

    for (int mask=0; mask<(1<<n); mask++) {
	assert(dp[mask]>-inf);

	vector<int> v;
	for (int j=0; j<n; j++) {
	    if (!(mask>>j&1)) {
		v.push_back(j);
	    }
	}

	dfs(0, v, mask, 0, dp[mask]);
    }


    cout<<dp[(1<<n)-1]<<endl;
    
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
 
#define INF 1000000007
#define LINF 1000000000000000007
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;


string n;

int main(){
	cin >> n;
	
	for(int i = 0; i < n.size(); i++){
		if(n[i] == '9'){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	
	return 0;
}

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

vector<int> ans;
int k, x;

// claudio van
int main() {
  scanf("%d %d", &k, &x);
  for (int i = 1; i < k; ++i) {
    ans.emplace_back(x - i);
  }
  sort(ans.begin(), ans.end());
  for (int i = 0; i < k; ++i) {
    ans.emplace_back(x + i);
  }
  for (int i = 0; i < (int) ans.size(); ++i) {
    if (i != 0) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
  return 0;
}

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

using namespace std;

const int mod = 1e9 + 7;
int n;

int dp[1000010][2][2];

int main() {

    cin >> n;

    dp[n][1][1] = 1;
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j < 2; ++j) {
            for (int k = 0; k < 2; ++k) {
                int &ans = dp[i][j][k];
                for (int l = 1; l < 9; ++l) {
                    ans += dp[i + 1][j][k];
                    ans %= mod;
                }
                ans += dp[i + 1][1][k];
                ans %= mod;
                ans += dp[i + 1][j][1];
                ans %= mod;
            }
        }
    }

    cout << dp[0][0][0] << "\n";
    
    return 0;
}


Measured memory_bytes: 19240
#include<bits/stdc++.h>
#define ll long long int
#define Y printf("YES\n")
#define N printf("NO\n")
#define mp make_pair
#define pb push_back
#define tp make_tuple
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define pr(a) printf("%lld\n",a)
using namespace std;

#define mod 1000003

ll a[1000005];
void fact()
{
    a[0]=1;

    for(ll i=1; i<=1000000; i++)
    {

        a[i]=(i*a[i-1])%mod;
    }
}



int main()
{
    ll n,m,t;


     char ch;

     cin>>ch;

     if(ch<91){

        cout<<"A"<<endl;
     }
     else {

        cout<<"a"<<endl;
     }
}


Measured memory_bytes: 3548
from fractions import*
def update(k,x):
    k+=N0-1
    data[k]=x
    while k+1:
        k=~-k//2
        data[k]=gcd(data[2*k+1],data[2*k+2])
def query(l,r):
    L,R=l+N0,r+N0
    s=0
    while L<R:
        if R&1:
            R-=1
            s=gcd(s,data[R-1])
        if L&1:
            s=gcd(s,data[L-1])
            L+=1
        L>>=1
        R>>=1
    return s
n,*a=map(int,open(0).read().split())
N0=2**(n-1).bit_length()
data=[0]*2*N0
for i in range(n):
    update(i,a[i])
print(max(gcd(query(0,i),query(i+1,n))for i in range(n)))

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

int main()
{
  int h,f=-1,s=-1,t=-1;
  
  for(int i=0;i<10;i++){
    cin >> h;
    if(h>f){
      t=s;
      s=f;
      f=h;
    }else if(h>s){
      t=s;
      s=h;
    }else if(h>t){
      t=h;
    }
  }
  cout << f << endl << s << endl << t << endl;
  return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#define hhh cerr<<"hhh"<<endl
#define see(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}

const int maxn = 3e5+7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;



int main() {
    int N=read(), K=read();
    int ans=0;
    while(N) {
        ans++; N/=K;
    }
    cout<<max(1,ans)<<endl;
}

Measured memory_bytes: 256