akhauriyash/Code-Regression huggingface dataset:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_4_A&lang=jp
# Reverse

from collections import deque
import sys
input = sys.stdin.readline

def main():
    n1 = int(input())
    l1 = list(map(int,input().split()))
    for i in range(int(input())):
        (a,b) = map(int,input().split())
        for ni in range((b-a)//2):
            l1[a+ni],l1[b-1-ni] = l1[b-1-ni],l1[a+ni]
    print (" ".join(map(str,l1)))


if __name__ == '__main__':
    main()


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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef map<int,int> mii;

const int MOD = 1e9+7;
int dp[105][4][2];
string n;
int k;

int f (int pos,int cnt,int tight) {
	if (cnt > k) return 0;
	if (pos == n.size()) {
		if (cnt == k) return 1;
		else return 0;
	}
	if (dp[pos][cnt][tight] != -1) return dp[pos][cnt][tight];
	int limit = (tight)?n[pos]-'0':9;
	int ret = 0;
	for (int i = 0;i <= limit;++i) {
		int newTight = (n[pos]-'0' == i)?tight:0;
		ret += f(pos+1,(i != 0)+cnt,newTight);
	}
	dp[pos][cnt][tight] = ret;
	return ret;
}

void solve () {
	memset(dp,-1,sizeof(dp));
	cin >> n >> k;
	int res = f(0,0,1);
	cout << res << '\n';
} 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}



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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  ll x=round(pow(2,m));
  cout<<(1900*m+100*(n-m))*x<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    
    int a, b , c;
    
    scanf("%d %d %d", &a , &b , &c);
    
    if ( a < b && b<c ){
        printf("Yes\n");
        }
    
    else{
        printf("No\n");
        }
   
    return 0;
}

Measured memory_bytes: 580
#include <iostream>
using namespace std;
int main()
{
 int k,x,n;
 //k=3&x=7
 cin>>k>>x;
 n=x-(k-1);

 for(int i=0;i<2*k-1;i++)
   {
    cout<<n<<" ";
    n++;
   }














}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
	int res = 0;
	if (s[0] == t[0]) ++res;
	if (s[1] == t[1]) ++res;
	if (s[2] == t[2]) ++res;
	cout << res << endl;
}

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

bool isPrime(int n)
{
    if(n <= 1) return false;
    if(n <= 2) return true;
    if(n % 2 == 0) return false;

    for(int i = 3; i < sqrt(n); ++i)
    {
        if(n % i == 0) return false;
    }
    return true;
}

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

    if(isPrime(x))
        cout << x << "\n";
    else 
    {
        bool found = false;
        while(!found)
        {
            x++;
            if(isPrime(x)) 
                found = true;
        }
        cout << x << "\n";
    }
    return 0;
}

Measured memory_bytes: 3628
import java.util.*;
	
public class Main
{ 
	public static int getDigit(Integer i,Integer x)
	{
		return Integer.parseInt(x.toString().charAt(i)+"");
		
	}
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		
		int x = scan.nextInt();
		int y = scan.nextInt();
		int counter = 0;
		
		for(int i=x;i<=y;i++)
			if(getDigit(0,i)==getDigit(4,i)&&getDigit(1,i)==getDigit(3,i))
				counter++;
		
		System.out.println(counter);
		
		
		scan.close();		
	}
}


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

int main(){
	cin>>N;
	if(N%2==0){
		cout<<N/2-1<<endl;
	}else{
		cout<<N/2<<endl;
	}
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
		int	cnt = parseCnt();

		while (cnt-- > 0) {
			solve(parseStdin());
		}
	}

	private static void solve(String stdin) {
		Train	ct = null;
		Train	pt = new Train();
		Train	ht = pt;
		Train	tt = pt;
		int		ti = 0;
		String	ot = "";

		pt.tc = stdin.charAt(ti);

		while ((ti = stdin.indexOf('-', ti)) != -1) {
			ct = new Train();
			if (stdin.charAt(ti+1) == '>') {
				ct.tc = stdin.charAt(ti+2);
				if (tt.tc == pt.tc) {
					tt.nt = ct;
					tt = ct;
				}
				ti+=3;
			} else {
				ct.tc = stdin.charAt(ti+1);
				if (ht.tc == pt.tc) {
					ct.nt = ht;
					ht = ct;
				}
				ti+=2;
			}
			pt = ct;
		}

		while (ht != null) {
			ot += ht.tc;
			ht = ht.nt;
		}
		System.out.println(ot);
	}

	private static int parseCnt() {
		int		cnt = 0;
		String	str = null;

		if ((str = parseStdin()) != null) {
			cnt = Integer.parseInt(str);
		}

		return cnt;
	}

	private static String parseStdin() {
		String  stdin = null;

		try {
			String  tmp = br.readLine();
			if (tmp != null) {
				if (!tmp.isEmpty()) stdin = tmp;
			}
		}
		catch (IOException e) {}

		return stdin;
	}
}

class Train {
	char	tc = 0;
	Train	nt = null;
}

Measured memory_bytes: 22964
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iostream>
typedef long long ll;
using namespace std;
int main()
{
	string s,t;
	int ans = 0;
	cin >> s >> t;
	for(int i = 0; i<s.size(); i++){
		if(s[i] != t[i]){
			ans++;
		}
	}
	cout << ans << endl;
	
}

Measured memory_bytes: 3900
def intersect_segment?(p,q,r,s)
  # ----p---q---- with r---s
  ((p[0] - q[0]) * (r[1] - p[1]) + (p[1] - q[1]) * (p[0] - r[0])) * \
  ((p[0] - q[0]) * (s[1] - p[1]) + (p[1] - q[1]) * (p[0] - s[0])) < 0
end

def intersect?(p,q,r,s)
  intersect_segment?(p,q,r,s) && intersect_segment?(r,s,p,q)
end

def inner_triangle?(p,q,r,t)
  g = [p,q,r].transpose.map{|i| i.inject(:+)}.map{|i| i/=3.0}
  not (intersect_segment?(p,q,g,t) || intersect_segment?(q,r,g,t) || intersect_segment?(r,p,g,t))
end

$<.to_a.each do |line|
  t = line.chomp.split(' ').map(&:to_f)
  p1 = t[0..1]
  p2 = t[2..3]
  p3 = t[4..5]
  target = t[6..7]

  puts inner_triangle?(p1,p2,p3,target) ? 'YES' : 'NO'
end

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll a, b;
  cin >> a >> b;
  vector<bool> v(4, true);
  v[a] = false;
  v[b] = false;
  for (ll i = 1; i <= 3; i++)
    if (v[i])
      cout << i << endl;
  return 0;
}


Measured memory_bytes: 256
function Main(input) {
  const length = input.split('\n')[0];
  const numbers = input.split('\n')[1].split('');
  var counter = 0;
  numbers.forEach ( function(color) {
    if (color === "R") {
      counter ++;
    }
  });
  if (counter > length / 2) {
    console.log("Yes");
  } else {
    console.log("No");
  }
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));


Measured memory_bytes: 21064
N, Y = map(int, input().split())
ans = []
for i in range(N + 1):
    for j in range(N + 1):
        k = N - i - j
        if k < 0:
            break

        if 10000 * i + 5000 * j + 1000 * k == Y:
            ans = [i, j, k]

if ans == []:
    ans = [-1, -1, -1]

print(ans[0], ans[1], ans[2])

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] p = new int[n];
		
		for(int i = 0; i < n; i++) {
			p[i] = stdIn.nextInt();
		}
		/*boolean [] flag = new boolean[n];
		for(int i = 0; i < n; i++) {
			flag[i] = true;
		}
		*/
	/*	//ここがTLEの部分
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < i; j++) {
				if(p[i] > p[j]) {
					flag[i] = false;
				}
			}
		}*/
		int cnt = 1;
		/*
		for(int i = 1; i < n; i++) {
			Arrays.sort(p,0,i);
			if(p[i]<=p[0]) {
				cnt++;
			}
		}*/
		
		/*for(int i = 0; i < n; i++) {
			for(int j = 0; j < i; j++) {
				if(p[i] > p[j]) {
					break;
				}
				if(j== i-1) {
					cnt++;
				}
			}
		}*/
		
		/*for(int i = 0; i < n; i++) {
			if(flag[i]) {
				cnt++;
			}
		}*/
		/*
		for(int i = 0; i < n; i++) {
			int left = 0;
			int right = i;
			while(left < right) {
				int mid = (left+right)/2;
				if(p[i] > p[j]) {
					break;
				}else {
					
				}
			
				
			
			}
		}
		
		*/
		int min = p[0] ;
		
		for(int i = 0; i < n-1; i++) {
			if(min >= p[i+1]) {
				cnt++;
				min = p[i+1];
			}
		}
		
		
		System.out.println(cnt);
	}

}


Measured memory_bytes: 65612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

//long longのシフト演算には気をつけよう

int dp[101][4][4][4];

int main(){
    int N; cin >> N;
    int mod = 1000000007;

    dp[0][3][3][3] = 1;

    for(int len=0; len<N; len++){
        for(int i=0; i<4; i++){
            for(int j=0; j<4; j++){
                for(int k=0; k<4; k++){

                    if(dp[len][i][j][k] == 0) continue;

                    for(int a=0; a<4; a++){

                        if(j == 0 && k == 1 && a == 2) continue;
                        if(j == 1 && k == 0 && a == 2) continue;
                        if(j == 0 && k == 2 && a == 1) continue;
                        if(i == 0 && k == 1 && a == 2) continue;
                        if(i == 0 && j == 1 && a == 2) continue;

                        dp[len+1][j][k][a] += dp[len][i][j][k];
                        dp[len+1][j][k][a] %= mod;
                    }
                }
            }
        }
    }

    ll ans = 0;
    for(int i=0; i<4; i++){
        for(int j=0; j<4; j++){
            for(int k=0; k<4; k++){
                ans += dp[N][i][j][k];
                ans %= mod;
            }
        }
    }

    cout << ans << endl;
}

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

#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define sc(a) scanf("%c",&a)
#define ss(a) scanf("%s",a)
#define pi(a) printf("%d\n",a)
#define pl(a) printf("%lld\n",a)
#define pc(a) putchar(a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i, a, b) for(register int i=a;i<=b;++i)
#define repd(i, a, b) for(register int i=a;i>=b;--i)
#define reps(s) for(register int i=head[s];i;i=Next[i])
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pii pair<int,int>
#define mii unordered_map<int,int>
#define msi unordered_map<string,int>
#define lowbit(x) ((x)&(-(x)))
#define ce(i, r) i==r?'\n':' '
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;

inline int qr() {
    int f = 0, fu = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')fu = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        f = (f << 3) + (f << 1) + c - 48;
        c = getchar();
    }
    return f * fu;
}

const int N = 1e6 + 10;

/*
素数存在prime中 下标1 - cntp
MAX_N若开到1e7 prime表注意除10
*/
const ll MAX_N=1e6+1;
bool is_prime[MAX_N];
int prime[MAX_N/10],cntp=0,mndiv[MAX_N];//mndiv最小质因数
void init()
{
    for(ll i=2;i<MAX_N;++i)  is_prime[i]=1; mndiv[1]=1;
    for(ll i=2;i<MAX_N;++i){
        if(is_prime[i]) prime[++cntp]=i,mndiv[i]=i;
        for(int j=1;j<=cntp&&i*prime[j]<MAX_N;j++){
            is_prime[i*prime[j]]=false,mndiv[i*prime[j]]=prime[j];
            if(i%prime[j]==0) break;
        }
    }
}


int n, cnt[N],a[N];

int main() {
    init(),n=qr();
    repi(i,1,n) a[i]=qr();
    repi(t,1,n){
        int x=a[t];
        repi(i,1,cntp){
            if(1ll*prime[i]*prime[i]>x) break;
            if(x%prime[i]==0) cnt[prime[i]]++;
            while(x%prime[i]==0) x/=prime[i];
        }
        if(x>1) cnt[x]++;
    }
    int mx=0;
    repi(i,2,MAX_N-1) mx=max(mx,cnt[i]);
    if(mx<=1) puts("pairwise coprime");
    else if(mx<n) puts("setwise coprime");
    else puts("not coprime");
    return 0;
}


Measured memory_bytes: 16548
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    int n,l;cin >>n>>l;
    vector<string>s(n);
    for (int i = 0; i < n; ++i) {
        cin >>s[i];
    }
    sort(all(s));
    string ans="";
    for (int i = 0; i < n; ++i) {
        ans+=s[i];
    }
    cout <<ans <<endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

map<int, int> table;

vector<int> search_table;

int table_end;

void table_init(void)
{
	int n = 6;

	search_table.push_back(n);

	for (int i = 1; i < 6; i++)
	{
		n *= 6;
		search_table.push_back(n);
	}

	n = 9;

	search_table.push_back(n);

	for (int i = 1; i < 5; i++)
	{
		n *= 9;
		search_table.push_back(n);
	}

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

	table_end = search_table.size() - 1;
}

int search(int rem, int mini)
{
	if (rem < 6)
	{
		return rem;
	}

	int ta;

	int best_N = 100000;

	if ((ta = table[rem]) != 0)
	{
		return ta;
	}

	for (int i = table_end; i >= 0; i--)
	{
		int ta = search_table[i];
		if (rem >= ta)
		{
			int N = search(rem - ta, best_N) + 1;

			if (N < best_N)
			{
				best_N = N;
			}
		}
	}

	table[rem] = best_N;

	return best_N;
}

int main(void)
{
	int n;
	cin >> n;

	table_init();

	cout << search(n, 100000) << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

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

int main(){
    int N;
    cin >> N;
    int a[N];
    REP(i,N){
        cin >> a[i];
    }
    sort(a,a+N);
    cout << a[N-1]-a[0];
}


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

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;

#define mp make_pair
#define pb push_back

int n, a, b;

int main()
{
  scanf("%d %d %d", &n, &a, &b);
  int dif = abs(a-b)-1;
  dif %= 2;
  puts(dif?"Alice":"Borys");
}


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

int main(){
    int A, B, C;
    vector <int> num;

    cin >> A >> B >> C;
    num.push_back(10*A + B + C);
    num.push_back(C + 10*B + A);
    num.push_back(A + 10*C + B);

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

    cout << num[2] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define BR cout<<endl;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const ll mod=1000000007;

ll powmod(ll x,ll y){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}

double expect(int x){
    double kitai,tem=0;
    for(int i=1;i<=x;i++){
        tem += i;
    }
    kitai = tem/x;
    cout << kitai << endl;
    return kitai;
    
}

int main(){
    int n, m, c;cin >> n >> m >> c;
    int B[m];
    rep(i,m)cin >> B[i];

    int A[n][m];
    rep(i,n){
        rep(j,m){
            cin >> A[i][j];
        }
    }

    int ans = 0;

    for (int i = 0; i < n; i++){
        int tem = 0;
        for (int j = 0; j< m; j++){
            tem += A[i][j] * B[j];
        }
        if(tem + c > 0)ans++;
    }

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



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

using namespace std;

int N, Place;
string Input;
int Cards[10];


void solve() {
	int index;

	index = Place = 0;
	for (int i = 0; i < 100; ++i) {
		++Cards[index];
		if (Input[i] == 'S') {
			Place += Cards[index];
			Cards[index] = 0;
		}
		else if (Input[i] == 'L') {
			Cards[index] += Place;
			Place = 0;
		}
		index = (index + 1) % N;
	}

	sort(Cards, Cards + N);
}

int main() {

	while (cin >> N, N) {
		memset(Cards, 0, sizeof(Cards));
		cin >> Input;
		//cout << Input << endl;
		solve();
		for (int i = 0; i < N; ++i) {
			cout << Cards[i] << " ";
		}
		cout << Place << endl;
	}
	
	return 0;
}



Measured memory_bytes: 3160
s=input()
n=len(s)
def pal(x):
    for i in range(len(x)//2):
        if x[i]!=x[-1-i]:
            return False
    return True
if pal(s[:n//2]) and pal(s[n//2+1:]) and pal(s):
    print('Yes')
else:
    print('No')


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

using namespace std;


bool check7(int n) {
	while (n > 0) {
		if (n % 10 == 7) return true;
		n /= 10;
	}
	return false;
}

int main() {
	int n;
	cin >> n;
	cout << (check7(n) ? "Yes" : "No");

	return 0;
}

Measured memory_bytes: 3600
module Main where

import Control.Applicative
import Data.List

solve :: [Int] -> Int
solve = sum . map subSolve . group . sort
    where subSolve xs@(x:_) | n >= x = n - x
                            | otherwise = n
              where n = length xs

main :: IO ()
main = do
  _ <- getLine
  xs <- map read . words <$> getLine
  print $ solve xs


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

using namespace std;

#define PROBLEM "D"
#define TESTC ""

#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)
typedef pair<int, int> P;
#define F first
#define S second
#define INF 0x3f3f3f3f
#define MP make_pair
#define PB push_back
#define MAXN 100005
#define LL long long

int main()
{
	#ifdef DBG
	freopen(PROBLEM TESTC ".in", "r", stdin);
	freopen(PROBLEM ".out", "w", stdout);
	#endif

	int ball,point;
	

	while(~scanf("%d %d",&ball,&point))
	{
		vector<int> arr;
		vector<int> ran;
		for(int i = 0; i < point; i++)
		{
			int tmp;
			scanf("%d",&tmp);
			arr.PB(tmp);
		}

		sort(arr.begin(),arr.end());
		// for (int i = 0; i < point ; i++)
		// 	printf("%d ",arr[i]);

		// printf("\n");

		for (int i = 0; i < point - 1; i++)
			ran.PB(abs(arr[i + 1] - arr[i]));
		
		sort(ran.begin(),ran.end());

		int knife = ball - 1;
		
		while(knife--)
		{
			if(ran.size() == 0)
				break;
			else
				ran.pop_back();
		}
			

		LL ans = 0;
		for(auto i : ran)
			ans += i;
	
		cout << ans << '\n';
			
		// for(auto i : ran)
		// 	cout << i << '\n';


	}

	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;
typedef double D;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }





int main() {
	D in, mini = (D)lINF, maxi = 0.0;
	while (cin>>in) { mini = min(mini, in); maxi = max(maxi, in); }
	cout << maxi-mini << endl;
	return 0;
}

Measured memory_bytes: 1280
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

int func(long long n) {
	if (n < 10)return 1;
	return func(n/10)+1;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n,a[100010],sum;
	ll seifu = 0, fusei = 0;
	scanf("%d", &n);
	REP(i, n) scanf("%d", &a[i]);
	sum = 0;
	REP(i, n) {
		sum += a[i];
		if (i % 2 == 0) {
			if (sum <= 0) {
				seifu += (1 - sum);
				sum = 1;
			}
		}
		else {
			if (sum >= 0) {
				seifu += (sum + 1);
				sum = -1;
			}
		}
	}
	sum = 0;
	REP(i, n) {
		sum += a[i];
		if (i % 2 == 0) {
			if (sum >= 0) {
				fusei += (sum + 1);
				sum = -1;
			}
		}
		else {
			if (sum <= 0) {
				fusei += (1 - sum);
				sum = 1;
			}
		}
	}

	cout << min(seifu,fusei) << endl;
	return 0;
}


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

main() {
    int N; cin >> N; double ans = 0;
    rep(i,N){
        double x; string u; cin >> x >> u;
        if(u=="JPY") ans+=(double)x;
        else ans+=(double)x*380000;
    }
    cout << fixed << setprecision(8) << (double)ans << endl;

    return 0;
}

Measured memory_bytes: 256
/**
*   Author : Krishna Purohit
*/

#include "bits/stdc++.h"
#define sync ios_base::sync_with_stdio(false)
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define mod 10000000007
using namespace std;

ll t, n;

ld dist(ll x1, ll y1, ll x2, ll y2) {
    return sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
}

int main() {
    sync;
    cin >> n;
    cout << setprecision(20);
    vector<pair<ll, ll> > m(n);
    for(int i = 0; i < n; ++i) {
        cin >> m[i].first >> m[i].second;
    }
    sort(all(m));
    ld path = 0;
    for(int i = 0; i < n-1; ++i) {
        path += dist(m[i].first, m[i].second, m[i+1].first, m[i+1].second);
    }
    int iter = 1;
    while(next_permutation(all(m))) {
        // cout << iter++ << endl;
        for(int i = 0; i < n-1; ++i) {
            path += dist(m[i].first, m[i].second, m[i+1].first, m[i+1].second);
        }
        // cout << iter++ << " :" << path << endl;
    }
    ld fact = 1;
    for(int i = 1; i <= n; ++i) fact *= i;
    path /= fact;
    cout << path << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios()                \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1e9;
inline int in()
{
	int x;
	cin >> x;
	return x;
}
template <typename T>
inline void out(const T &x) { cout << x << endl; }
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
	if (a < b)
		gcd(b, a);
	int r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}
void eratos(bool *isPrime, int max)
{
	fill(isPrime, isPrime + max, true);
	isPrime[0] = false;
	isPrime[1] = false;
	for (int i = 2; i <= max / i; ++i)
		if (isPrime[i])
			for (int j = 2; j <= max / i; ++j)
				isPrime[i * j] = false;
}
//

vector<int> divisor(int n)
{
	vector<int> ret;
	for (int i = 0; i * i <= n; i++)
	{
		ret.push_back(i);
		if (i * i != n)
			ret.push_back(i);
	}
	sort(ALL(ret));
	return ret;
}

char m[51][51];
int w, h;

void dfs(int x, int y, vector<vector<bool>> &cmap, char color, vector<vector<bool>> &checked)
{
	if (x >= w || y >= h || y < 0 || x < 0) return;
	if (checked[x][y]) return;
	checked[x][y] = true;
	if (m[x][y] != '.') return;

	cmap[x][y] = true;
	for (int di = 0; di < 4; di++)
	{
		dfs(x + dx[di], y + dy[di], cmap,color,checked);
	}
}

void checkAllGrid(vector<vector<bool>> &inArea, char color)
{

	vector<vector<bool>> checked(w,vector<bool>(h,false)) ;
	for (int xi = 0; xi < w; xi++)
	{
		for (int yi = 0; yi < h; yi++)
		{
			if (m[xi][yi] == color)
			{
				for(int i = 0; i < 4; i++) {
					dfs(xi + dx[i], yi + dy[i], inArea, color, checked);

				}
			}
		}
	}
}

signed main()
{
	while(true) {
		cin >> w >> h;
		if(w == 0 && h == 0) {
			break;
		}
		for (int yi = 0; yi < h; yi++)
		{
			for (int xi = 0; xi < w; xi++)
			{
				cin >> m[xi][yi];
			}
		}
		vector<vector<bool>> warea(w,vector<bool>(h,false));
		vector<vector<bool>> barea(w,vector<bool>(h,false));
		checkAllGrid(warea, 'W');
		checkAllGrid(barea, 'B');
		int wAns = 0;
		for (int xi = 0; xi < w; xi++)
		{
			for (int yi = 0; yi < h; yi++)
			{
				if(!barea[xi][yi] && warea[xi][yi]) {
					wAns ++;
				}
			}
		}
		int bAns = 0;
		for (int xi = 0; xi < w; xi++)
		{
			for (int yi = 0; yi < h; yi++)
			{
				if(barea[xi][yi] && !warea[xi][yi]) {
					bAns ++;
				}
			}
		}
		cout << bAns <<" "<< wAns << endl;
	}
}



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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define inn(x, y) int x,y;cin>>x>>y
#define innn(x, y, z) int x,y,z;cin>>x>>y>>z
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define outt(x,y) cout<<(x)<<" "<<(y)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;
#define errrr(x,y,z) cerr<<(x)<<" "<<(y)<<" "<<(z)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 100010
#define lim9 1000000010

#define deg(rad) (((rad)/2/M_PI)*360)
#define mid(min, max) ((min + max) / 2)

int main() {
    in(r);
    out(2 * 3.141592656358979 * r);
    return 0;
}


Measured memory_bytes: 3788
#include <cstdio>
#include <cstring> 
#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a
#define N 200006
int a,b,c,d;
int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&d);
	printf("%d",max(a*b,c*d));
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	int n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	vi dp(n + 1, -1);
	dp[n] = 0;
	int step = 0, pos = n;
	bool reached = false;
	bool next_step = true;
	while(!reached && next_step) {
		while(pos > 0 && dp[pos] == step) pos--;
		pos++;
		while(pos < n && s[pos] == '1') pos++;
//		cout << step << ' ' << pos << endl;
		step++;
		next_step = false;
		for(int j = 1; j <= m; j++) {
			if(pos - j >= 0) {
				dp[pos - j] = step;
				if(s[pos - j] == '0') next_step = true;
			}
			if(pos - j == 0) {
				reached = true;
				break;
			}
		}
		pos--;
	}
	if(!reached) {
		cout << -1 << endl;
		return 0;
	}
	pos = 0;
	step = dp[pos];
	vi ans;
	for(step = dp[pos] - 1; step >= 0; step--) {
		int pre_pos = pos;
		while(dp[pos] != step) pos++;
		ans.push_back(pos - pre_pos);
	}
	rep(i, ans.size()) {
		cout << ans[i] << ' ';
	}
	cout << endl;
	return 0;
}


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

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pii> vii; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 

double EPS=1e-9; 
int INF=1000000005; 
long long INFF=1000000000000000005ll; 
double PI=acos(-1); 
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 }; 
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 }; 
const ll MOD = 1000000007;

#define DEBUG fprintf(stderr, "====TESTING====\n") 
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl 
#define OUT(x) cout << x << endl 
#define OUTH(x) cout << x << " " 
#define debug(...) fprintf(stderr, __VA_ARGS__) 
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a)) 
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a)) 
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a)) 
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a)) 
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a)) 
#define EACH(a, b) for (auto&(a) : (b)) 
#define REP(i, n) FOR(i, 0, n) 
#define REPN(i, n) FORN(i, 1, n) 
#define MAX(a, b) a=max(a, b) 
#define MIN(a, b) a=min(a, b) 
#define SQR(x) ((ll)(x) * (x)) 
#define RESET(a, b) memset(a, b, sizeof(a)) 
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back 
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define SIZE(v) (int)v.size() 
#define SORT(v) sort(ALL(v)) 
#define REVERSE(v) reverse(ALL(v)) 
#define SORTA(arr, sz) sort(ALLA(arr, sz)) 
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) 
#define PERMUTE next_permutation 
#define TC(t) while (t--) 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)

int main()  
{ 
    FAST_INP;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
    #endif
    
    ll h,w,m,a,b;
    cin >> h >> w >> m;
    // vvl g(h,vl(w,0));
    // map<ll,ll> row,col;
    // REP(i,m){
    //     cin >> a >> b;
    //     --a, --b;
    //     g[a][b]=1;
    //     row[a]++;
    //     col[b]++;
    // }
    // ll ans=0;
    // REP(i,h){
    //     REP(j,w){
    //         MAX(ans,row[i]+col[j]-(g[i][j]==1?1:0));
    //     }
    // }
    // OUT(ans);
    set<pll> s;
    vii cntR(h + 1), cntC(w + 1);
    REP(i, h + 1) cntR[i].se = i;
    REP(i, w + 1) cntC[i].se = i;
    REP(i, m) {
        int r, c;
        cin >> r >> c;
        cntR[r].fi++, cntC[c].fi++;
        s.emplace(r, c);
    }
    sort(cntR.rbegin(), cntR.rend());
    sort(cntC.rbegin(), cntC.rend());
    for(int row = 0; cntR[row].fi == cntR[0].fi; row++)
        for(int col = 0; cntC[col].fi == cntC[0].fi; col++)
            if(!s.count(mp(cntR[row].se, cntC[col].se))) {
                OUT((cntC[col].fi + cntR[row].fi));
                return 0;
            }
    OUT(max(0, cntC[0].fi + cntR[0].fi - 1));
    return 0; 
} 

// o b o
// x o x 

Measured memory_bytes: 26668
#include<stdio.h>
int main(void){
    int s_in = -1, h, m, s;
    while(s_in < 0 || 86400 < s_in){
        scanf("%d", &s_in);
    }
    s = s_in % 60;
    s_in = (s_in - s) / 60;
    m = s_in % 60;
    h = (s_in - m) / 60;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;

const static char c[] = {'J','O','I'};
int N;
string S;
int T[3][1000001];
vector<pair<int,int> > v;

bool isLevelK(int k, int p) {
  if(p+k >= N || p+2*k >= N) return false;
  return T[1][p+k] == k && T[2][p+2*k] >= k;
}

int main() {
  cin >> S;
  N = S.size();

  for(int p = 0; p < 3; ++p) {
    for(int i = N-1; i >= 0; --i) {
      if(S[i] == c[p]) {
	if(i+1 == N) T[p][i] = 1;
	else T[p][i] = T[p][i+1]+1;
	if(p == 0) v.push_back(make_pair(-T[p][i],i));
      } else {
	T[p][i] = 0;
      }
    }
  }
  sort(v.begin(), v.end());
  int ans = 0;
  for(int i = 0; i < v.size(); ++i) {
    if(isLevelK(-v[i].first, v[i].second)) {
      ans = -v[i].first;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 0
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
#define biggest(A,B) A=max(A,B)
#define smallest(A,B) A=min(A,B)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	fastio;
	int n;
	cin>>n;
	int a[1000];
	rb(i,1,n)
		cin>>a[i];
	int res=0;
	rb(i,1,n){
		if(i&1){
			if(a[i]&1){
			res++;	
			}
		}
	}cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 3612
n = int( input() )
#print( n )

#print( range( n-1 ) )

x = 1
y = 1
w = 1
z = 1000000007
for i in range( n ):
    x = ( x % z ) * 10
    y = ( y % z ) * 9
    w = ( w % z ) * 8
#    print( i, x, y )

ans = ( x % z ) - 2 * ( y % z ) + ( w % z )
print( ans % z )


Measured memory_bytes: 8976
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define P(s)     cout<<(s)<<endl
#define vi   vector<int>
#define vvi  vector<vi >
#define vvvi vector<vvi >
#define pii  pair<int,int>
#define INF  (int)1e9
#define MOD  (int)1e9+7
typedef long long llong;
using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	
	int d=a-b;
	
	if(c>d) P(c-d);
	else P(0);
}

Measured memory_bytes: 256
A = list(map(int, input().split()))
A += list(map(int, input().split()))
A += list(map(int, input().split()))
flag=0
for a1 in range(101):
    for a2 in range(101):
        for a3 in range(101):
            b1=A[6]-a1
            b2=A[7]-a1
            b3=A[8]-a1
            if b1<0 or b2<0 or b3<0:
                break
            if a3+b1==A[0] and a3+b2==A[1] and a3+b3==A[2] and a2+b1==A[3] and a2+b2==A[4] and a2+b3==A[5]:
                flag=1
print("Yes" if flag==1 else "No")


Measured memory_bytes: 86976
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long int lnt;
typedef pair<lnt,lnt> P;
typedef double db;
lnt H,W;
char grid[333][333];
char a[333],b[333];
lnt dp[333][333];//aをi段　bをj段のコスト
lnt cost[333][333];//aをi段　bをj段のコスト
lnt ans=0;
const lnt INF = 0xffffffffff;
//X段削ると 0 ~ H-X-1


lnt calc(char* a,char* b){
	memset(cost,0,sizeof(cost));
	for(lnt i=H-1;i>=0;i--){
		cost[i][i] = cost[i+1][i+1] + (a[H-i-1] == b[H-i-1]?1:0);
	}
	
	for(lnt d=1;d<H;d++){
		for(lnt i=H-1;i-d>=0;i--){ //aをi段 bを i-d(=j)段
			lnt j=i-d;
			cost[i][j] = cost[i+1][j+1] + (a[H-i-1] == b[H-j-1]?1:0);
			cost[j][i] = cost[j+1][i+1] + (a[H-j-1] == b[H-i-1]?1:0);
		}
	}
	
	//for(lnt i=0;i<=H;i++){
	//	for(lnt j=0;j<=H;j++){
	//		cout<<"cost["<<i<<"]["<<j<<"]="<<cost[i][j]<<endl;
	//	}
	//}
	
	fill(dp[0],dp[333],INF);
	dp[0][0]=0;
	for(lnt i=0;i<=H;i++){
		for(lnt j=0;j<=H;j++){
			if(i-1>=0) dp[i][j]=min(dp[i][j],dp[i-1][j]+cost[i-1][j]);
			if(j-1>=0) dp[i][j]=min(dp[i][j],dp[i][j-1]+cost[i][j-1]);
		}
	}
	return dp[H][H];
}


int main()
{
	scanf("%lld%lld",&H,&W);
	for(lnt i=0;i<H;i++) scanf("%s",grid[i]);
	for(lnt i=0;i<W-1;i++){
		for(lnt j=0;j<H;j++){
			a[j]=grid[j][i];
			b[j]=grid[j][i+1];//上から0 ~ H-1
		}
		ans+=calc(a,b);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 2176
#include <iostream>

using namespace std;

long long solve(long long A, long long B){
	if(A == B) return 1;
	int a = 60;
	while(!((A^B)&(1LL<<a))) --a;
	A %= (1LL<<a);
	B %= (1LL<<a);
	long long res = 2 * ((1LL<<a) - A);
	int b = a-1;
	while(b >= 0 && !((B&(1LL<<b)))) --b;
	res += min(A, (1LL<<(b+1)));
	return res;
}

int main(){
	long long A, B;
	while(cin >> A >> B){
		cout << solve(A, B) << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll n,a[200];
  cin >> n;
  rep(i,n)cin >> a[i];
  sort(a,a+n);
  printf("%lld",a[n-1]-a[0]);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int s = sc.nextInt();
		int count = 0;
		
		for(int x = 0;x <= k && x <= s;x++) {
			for(int y = 0;y <= k && y <= s;y++) {
				int z = s - x - y;
				if(z >= 0 && z <= k) {
					count++;
				}
			}
		}

		System.out.println(count);
    }
}

Measured memory_bytes: 22740
#include <stdio.h>
#include <stdlib.h>
#define NUM_MT 10
int compare(const void *a, const void *b) {
	return *(int*)b - *(int*)a;
}
int main() {
	int i, data[NUM_MT];
	for (i = 0; i < NUM_MT; i++)
		scanf(" %d", &data[i]);
	qsort(data, NUM_MT, sizeof(int), compare);
	for (i = 0; i < 3; i++)
		printf("%d\n", data[i]);
	return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N=2e5+5;
const int MOD=1e9+7;
ll a[N];
//struct node{
//    ll v;
//    ll d;
//}p[N];
//ll sum;
//ll ans[N];
 
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n;
    cin >>n;
    for(int i=1;i<=n;i++)   cin >>a[i],a[i]-=i;
    sort(a+1,a+1+n);
    ll mid=n/2;
    ll b[4]={a[mid],a[mid+1],a[mid-1]};
    ll ans=1e18;
    for(int i=0;i<=2;i++){
        ll tb=b[i];
        ll res=0;
        for(int j=1;j<=n;j++){
            res+=abs(a[j]-tb);
        }
        ans=min(ans,res);
    }
    cout << ans << endl;
 
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void){

	int a,b;
	char op;

	while(1){
		scanf("%d %c %d",&a,&op,&b);
		if(op=='+')printf("%d\n",a+b);
		else if(op=='-')printf("%d\n",a-b);
		else if(op=='*')printf("%d\n",a*b);
		else if(op=='/')printf("%d\n",a/b);
		else if(op=='?')break;
	}

	return 0;

}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int n,a,b;
int main() {
	cin>>n>>a>>b;
	if (a+b-1>n||1ll*a*b<n) return cout<<-1,0;
	int d=n-a;
	for (int i=n-a+1;i<=n;++i) cout<<i<<' ';
	for (int i=2;i<=b;++i) {
		int t=min(d-(b-i),a);
		for (int j=d-t+1;j<=d;++j) cout<<j<<' ';
		d-=t;
	}
}

Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>

int main() {
	int a, b, c, d;
	std::cin >> a >> b >> c >> d;
	if (a >= b)
		std::cout << b*c + (a - b)*d << std::endl;
	else
		std::cout << a*c << std::endl;
	return 0;
}
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T>
void print(T& x){printf("%d\n", x);}
void printvec(vector<int> a){
    rep(i, a.size()-1){
        printf("%d ", a[i]);
    }
    printf("%d\n", a[a.size()-1]);
}
 
int main()
{
    deque<int> que;
    int q;
    cin >> q;

    int com, d, x;
    rep(i, q){
        cin >> com;
        if(com==0){
            cin >> d >> x;
            if(d==0){
                que.emplace_front(x);
            }else{
                que.emplace_back(x);
            }
        }else if(com==1){
            cin >> d;
            print(que[d]);
        }else if(com==2){
            cin >> d;
            if(d==0) que.pop_front();
            else que.pop_back();
        }
    }
    return 0;
}


Measured memory_bytes: 4796
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    bool can=false;

    rep(i,k){
        if(a>=b) b*=2;
        else c*=2;
        if(a<b && b<c) can=true;
    }

    if(can) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <utility> 
#include <tuple>
#include <iterator>
#include <functional>
#include <numeric>
using namespace std;
#define rep(i,n) for(long i=0; i<n; i++)


void solve(){
  int n;
  cin >> n;
  int a[n+10];
  rep(i,n){
    cin >> a[i]; 
  }
  int l[n+10];
  int r[n+10];
  l[0] = a[0];
  r[0] = a[n-1];
  for(int i=1; i<n-1; i++){
     l[i] = max(l[i-1], a[i]);
  }
  for(int i=1; i<n-1; i++){
     r[i] = max(r[i-1], a[n-i-1]);
  }
  
  cout << r[n-2] << endl;
  for(int i=0; i<n-2; i++){
    cout << max(l[i], r[n-3-i]) << endl; 
  }
  cout << l[n-2] << endl;
  
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 3968
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    long long n,a[200005],sum[200005],i,j,cnt=0,ans=0,ans1=0;
    scanf("%lld",&n);
    for(i=0;i<n;i++)
        scanf("%lld",&a[i]);
    for(i=0;i<n;i++)
    {
        cnt+=a[i];
        sum[i]=cnt;
    }
    sum[n]=0;
    sort(sum,sum+n+1);
    for(i=1;i<=n;i++)
    {
        if(sum[i-1]==sum[i])
            ans++;
        else{ans1+=ans*(1+ans)/2;  ans=0;}
    }
    ans1+=ans*(1+ans)/2;
    printf("%lld\n",ans1);
}


Measured memory_bytes: 3328
#include<iostream>
#include<string>

int main(){
    int n;
    std::string s;

    std::cin >> n >> s;

    if(n % 2 == 1){
        std::cout << "No" << std::endl;
    }else{
        std::string s1={}, s2={};
        for(int i = 0; i < s.size() / 2; i++){
            s1 += s.at(i);
            s2 += s.at(s.size() / 2 + i);
        }
        if(s1 == s2){
            std::cout << "Yes" << std::endl;
        }else{
            std::cout << "No" << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if( H > 0 ){
        if( W - r >= x && H - r >= y && r <= x && r <= y){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }    
    }    
    if( H < 0 ){
        if( W - r >= x && H - r <= y && r <= x && r >= y){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }    
    }
    if( H == 0){cout << "No" << endl;}
}


Measured memory_bytes: 3096
import numpy as np
import sys
input = sys.stdin.readline

n = int(input())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
cn = list(map(int, input().split()))

an.sort()
cn.sort()

a_pair = []
for i in bn:
    if i <= an[0]:
        a_pair.append(0)
        continue
    if i > an[-1]:
        a_pair.append(n)
        continue
    front = 0
    back = n-1
    while front != back:
        mid = (front+back)//2
        if an[mid] < i:
            front = mid + 1
        else:
            back = mid
    a_pair.append(front)

c_pair = []
for i in bn:
    if i >= cn[-1]:
        c_pair.append(0)
        continue
    if i < cn[0]:
        c_pair.append(n)
        continue
    front = 0
    back = n-1
    while front != back:
        mid = (front+back)//2
        if cn[mid] > i:
            back = mid
        else:
            front = mid + 1
    c_pair.append(n-back)

a_pair = np.array(a_pair)
c_pair = np.array(c_pair)
print(np.sum(a_pair*c_pair))

Measured memory_bytes: 33136