akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long ll;

int main(){
  ll N,M; cin >> N >> M;
  vector<vector<ll>> S((ll)8,vector<ll>(N,0));
  
  vector<ll> x(N); vector<ll> y(N); vector<ll> z(N);
  
  for(ll i = 0; i < N; i++){ cin >> x[i] >> y[i] >> z[i];}
  
  for(ll i = 0; i < 8; i++){
   for(ll j = 0; j < N; j++){
     ll x0 = x[j]; ll y0 = y[j]; ll z0 = z[j];
    if( i >> 0 & 1){ S[i][j] += x0;}
     else{ S[i][j] -= x0;}
    if( i >> 1 & 1){ S[i][j] += y0;}
     else{ S[i][j] -= y0;}
    if( i >> 2 & 1){ S[i][j] += z0;}
     else{ S[i][j] -= z0;}  }}
                    
  for(ll i = 0; i < 8; i++){
   sort(S[i].begin(),S[i].end()); reverse(S[i].begin(),S[i].end());}
    
  ll max_sum = 0;
 
    for( ll i = 0; i < 8; i++){ ll sum = 0;
     for(ll j = 0; j < M; j++){ sum += S[i][j];}
      max_sum = max(max_sum,sum);}
    
  cout << max_sum << endl; return 0;}
  

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
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; }

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*------------------------------------/
for library*/

/*------------------------------------*/
const int IMAX = 2000000;
int H[IMAX],W[IMAX];
int X[IMAX],Y[IMAX];
int a[IMAX],b[IMAX];
int N,M;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    while(1){
        cin>>N>>M;
        if(N==0&&M==0)break;
        rep(i,max(N,M) + 5){
            X[i] = Y[i] = 0;
        }
        rep(i,IMAX){
            a[i] = b[i] = 0;
        }
        rep(i,N){
            cin>>H[i];
            Y[i+1] += H[i] + Y[i];
        }
        rep(i,M){
            cin>>W[i];
            X[i+1] += W[i] + X[i];
        }
        for(int i = 0;i<=N;i++){
            for(int j = i + 1;j<=N;j++){
                a[Y[j]-Y[i]]++;
            }
        }
        for(int i = 0;i<=M;i++){
            for(int j = i + 1;j<=M;j++){
                b[X[j]-X[i]]++;
            }
        }
        ll ans = 0;
        for(int i = 0;i < IMAX;i++){
            ans += a[i] * b[i];
        }
        /*rep(i,N+1){
            cerr<<X[i]<<" "<<Y[i]<<endl;
        }
        rep(i,N+1){
            cerr<<a[i]<<" "<<b[i]<<endl;
        }*/
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 18884
N ,M= map(int,input().split())
a  = list(map(int, input().split()))
count = 0
s = 0
for i in a:
    s +=i
lim = (1/(M*4))*s
for i in a:
    if i >=lim:
        count+=1
    else:
        pass
if count >= M:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import java.util.Scanner;

class Main
{
	public static void main(String[] args)
	{
		int s;
		int m = 0;
		int h = 0;
		
		Scanner scan = new Scanner(System.in);
		s = scan.nextInt();
		
		for(; s >= 60 ;){
			s -= 60;
			m++;       }
			
		for(; m >= 60 ;){
			m -= 60;
			h++;       }
		
		System.out.println(h+":"+m+":"+s);
	}
}


Measured memory_bytes: 26156
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    long long int n,m;
    cin >> n >> m;
    if(n * 2 < m)
    {
        cout << (n * 2 + m) / 4;
    }
    else
    {
        cout << m / 2;
    }

    return 0;
}

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

using namespace std;

int main(){
  string X;
  cin >> X;
  int count = 0,Scount = 0;
  for(int i=0;i<X.size();i++){
    if(X[i]=='S'){
      Scount ++ ;
      count ++;
    }else{
      if(Scount > 0){
        Scount--;
        count --;
        
      }else{
        count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}

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

int x;

int main(){

	scanf("%d",&x);
int ans=0;
int plus=0;
for(int i=1;i<=x;i++){
	ans++;
	plus+=i;
	if(plus>=x)break;
}
printf("%d\n",ans);

	
//	printf("%lld\n",ans);
}

Measured memory_bytes: 256
(n,),*t=[map(int,t.split())for t in open(0)]
*e,=eval('[],'*-~n)
q=[(1,0)]
f=[-1]*n
for v,w,c in t:e[v]+=(w,c),;e[w]+=(v,c),
for v,c in q:
 f[v-1]=c&1
 for w,d in e[v]:q+=[(w,c+d)]*(f[w-1]<0)
print(*f)

Measured memory_bytes: 164440
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

int main(){
    ll N;
    cin >> N;
    
    for(ll x = 1; x <= 3500; x++){
        for(ll y = 1; y <= 3500; y++){
            ll devided, devide;
            devided = N * x * y;
            devide = 4 * x * y - N * (x + y);
            if(devide > 0 && devided % devide == 0){
                cout << x << " " << y << " " << devided / devide << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#define p 1000000007
using namespace std;
int n,K,a[101010];
long long fac[101010],ny[101010],ans;
long long C(int x,int y){ return x<y?0:fac[x]*ny[y]%p*ny[x-y]%p;}
int main()
{
	scanf("%d%d",&n,&K);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	fac[0]=ny[0]=ny[1]=1;
	for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%p;
	for(int i=2;i<=n;i++) ny[i]=ny[p%i]*(p-p/i)%p;
	for(int i=2;i<=n;i++) ny[i]=ny[i-1]*ny[i]%p;
	for(int i=1;i<=n;i++)
	(ans+=1LL*(C(i-1,K-1)-C(n-i,K-1)+p)%p*a[i]%p+p)%=p;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template <class T>
T inf = numeric_limits<T>::max();

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

  ll N;
  cin >> N;
  map<ll, ll> mp;
  ll ans = 0;
  // 右端を固定する
  repr(i, N, 0) {
    ll a;
    cin >> a;
    ll d = i - a;
    ans += mp[d];
    mp[a+i] += 1;
  }

  cout << ans << endl;
}


Measured memory_bytes: 26196
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, X, Y;
vector<int> G[2003];
int S[2003];
int Cnt[2003]; // idx長さの個数
typedef pair<int, int> P;

void bfs() {
  int no_kiroku = -1; 
}

int main() {
  INCANT;
  cin >> N >> X >> Y;
  X--;Y--;
  rep(i, N) {
    if (i==X) G[i].push_back(Y);
    if (i==Y) G[i].push_back(X);
    if (i<N-1) G[i].push_back(i+1);
    if (i>0) G[i].push_back(i-1);
  }
  int no_kiroku = -1;
  rep(i, N-1) {
    rep(j, N) S[j]=-1;
    queue<P> que;
    que.push(P(i, 0));
    while (!que.empty()) {
      P p = que.front(); que.pop();
      if (S[p.first] >=0) continue;
      S[p.first] = p.second;
      if (p.first > no_kiroku) {
        Cnt[p.second]++;
      }
      for(auto ne: G[p.first]) {
        if (S[ne]<0) {
          que.push(P(ne, p.second+1));
        }
      }
    }
    no_kiroku =  i;
  }
  rep(i, N-1) cout << Cnt[i+1] << "\n";
  return 0;
}

Measured memory_bytes: 384
#include <string>
#include <vector>
#include <cmath>
#include <list>
#include <set>
#include <algorithm>
#include <map>
#include <iostream>
#include <sstream>
#include <queue>
#include <iomanip>

#include <string.h>

typedef unsigned long long u64; 
typedef unsigned int uint;

using namespace std;

#define MIN(a, b) a < b ? a : b

#define MOD 1000000007

int main()
{
	int n;
	int h, w;
	vector<int> a;
	vector<int> answer;
	vector<int> l;

	cin >> h >> w;
	cin >> n;

	for(int i = 0; i < n; i++)
	{
		int _a;
		cin >> _a;
		a.push_back(_a);
	}

	answer.resize(h*w, 0);

	bool bFlip = false;
	int p = 0;
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < a[i]; j++)
		{
			answer[p] = i;
			if((p % w) == 0 && bFlip)
			{
				bFlip = false;
				p += w;
			}
			else if((p%w) == w-1 && !bFlip )
			{
				bFlip = true;
				p += w;
			}
			else
			{
				if(bFlip)
				{
					p--;
				}
				else
				{
					p++;
				}
			}
		}
	}
	
	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{
			cout << answer[i*w + j]+1;
			if(j != w-1)
			{
				cout << " ";
			}
		}
		if(i != h-1)
		{
			cout << "\n";
		}
	}

	return 0;
}

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

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

	for(int loop = N; loop >= 1; --loop) {
		int tmp = sqrt(loop);
		if(tmp * tmp == loop) {
			cout << loop <<endl;
			return 0;
        }
    }

	return 0;
}


Measured memory_bytes: 3656
#include <iostream>

using namespace std;

int main()
{
    string s,t;
    cin>>s>>t;
    int a,ans=0;
    for(a=0;a<s.size();a++)
    {
        if(s[a]!=t[a])ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int t[N+1], x[N+1], y[N+1];
  t[0]=0;x[0]=0;y[0]=0;
  for(int i=1;i<=N;i++){
    cin >> t[i] >> x[i] >> y[i];
  }

  int flag = 0;
  int dist, time;
  for(int i=1;i<=N;i++){
    dist = abs(x[i] + y[i] - x[i-1] - y[i-1]);
    time = t[i] - t[i-1];
    if(time<dist||abs(time - dist)%2!=0){
      flag = 1;
      break;
    }
  }

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

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

int n;
int town[10][10];

void solve(){
	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++){
			for(int l=0; l<10; l++){
				int dis = town[j][i]+town[i][l];
				if(dis<town[j][l])
					town[j][l] = dis;
			}
		}
	}
	int ans=0,t[10]={0};
	for(int i=0; i<10; i++){
		for(int k=0; k<10; k++)
			t[i] += town[i][k];
		if(t[ans] > t[i])
			ans = i;
	}
	cout << ans << ' ' << t[ans]%1000000 << endl;
}

int main(){
	while(true){
		cin >> n;
		if(!n)
			return 0;
		for(int i=0; i<10; i++)
			for(int k=0; k<10; k++){
				town[i][k] = 1000000;
				if(i==k)
					town[i][k] = 0;
			}
		for(int i=0; i<n; i++){
			int a,b,c;
			cin >> a >> b >> c;
			town[a][b] = c;
			town[b][a] = c;
		}
		solve();
	}
}

Measured memory_bytes: 0
using System;
using System.Linq;

class Program {
  static void Main() {
    int n = int.Parse(Console.ReadLine());
    int k = int.Parse(Console.ReadLine());
    var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int ans = 0;
    foreach (var x in arr) {
      ans += Math.Min(x, k - x) * 2;
    }
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 13268
n,x = map(int,input().split())
m = []
sum_m = 0
min_m = x
for i in range(n):
    m.append(int(input()))
    sum_m += m[i]
    min_m = min(min_m,m[i])
tmp = x - sum_m
print(n+tmp//min_m)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
long long value(string S){
  int N = S.size();
  long long ans = 0;
  long long tmp = 0;
  for (int i = 0; i < N; i++){
    if (S[i] == '+'){
      ans += tmp;
      tmp = 0;
    } else {
      tmp = tmp * 10 + S[i] - '0';
    }
  }
  ans += tmp;
  return ans;
}
int main(){
  string S;
  cin >> S;
  int N = S.size();
  int M = 1 << (N - 1);
  long long ans = 0;
  for (int i = 0; i < M; i++){
    string T;
    for (int j = 0; j < N - 1; j++){
      T += S[j];
      if ((i >> j) & 1){
        T += '+';
      }
    }
    T += S[N - 1];
    ans += value(T);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N = input()
A = list(map(int, input().split()))
plus = []
minus = []
for a in A:
    if a >= 0:
        plus.append(a)
    else:
        minus.append(-a)
if len(minus) % 2 == 0:
    sum_value = sum(plus + minus)
    print(sum_value)
else:
    min_value = min(plus + minus)
    sum_value = sum(plus + minus) - min_value*2
    print(sum_value)

Measured memory_bytes: 65552
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

ll n, a, b;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0) {
		cout << (b - a) / 2 << "\n";
		return 0;
	}

	ll ans = min((b - a - 1) / 2 + a, (b - a - 1) / 2 + n - b + 1);

	cout << ans << "\n";

	return 0;
}




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

using namespace std;

int main() {
    int n, cont=0, contr=0;
    char c, l[212345];

    scanf("%d", &n);
    scanf(" %s", l);

    for (int i=0; i<n; ++i) {
        if (l[i] == 'W')
            continue;
        else
            contr++;
    }

    for (int i=contr; i<n; ++i) {
        if (l[i] == 'R') {
            ++cont;
        }
    }

    printf("%d\n", cont);

    return 0;
}

Measured memory_bytes: 4020
#include<stdio.h>
#include<stdlib.h>
#define MAX_N 100

typedef struct{
  int x;
  int y;
} p;

using namespace std;
int N, i, j, cnt, donecd[MAX_N], doneab[MAX_N];
p ab[MAX_N],  cd[MAX_N];

int x_asc(const void *a, const void *b) {
  p A = *(p *)a, B = *(p *)b;
  if (A.x < B.x) {
    return -1;
  } else if (A.x > B.x) {
    return 1;
  } else {
    return 0;
  }
}

int y_desc(const void *a, const void *b) {
  p A = *(p *)a, B = *(p *)b;
  if (A.y > B.y) {
    return -1;
  } else if (A.y < B.y) {
    return 1;
  } else {
    return 0;
  }
}
int not_done(int i, int j) {
  return doneab[j] == 0 && donecd[i] == 0;
}

int main () {
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%d %d", &ab[i].x, &ab[i].y);
  }
  for (i = 0; i < N; i++) {
    scanf("%d %d", &cd[i].x, &cd[i].y);
  }
  qsort((void *)ab, N, sizeof(ab[0]), y_desc);
  qsort((void *)cd, N, sizeof(cd[0]), x_asc);
  for (i = 0; i < N; i++) { donecd[i] = 0; doneab[i] = 0; };
  for (i = 0, cnt = 0; i < N; i++) {
     for (j = 0; j < N; j++) {
        if (not_done(i, j) && cd[i].x > ab[j].x && cd[i].y > ab[j].y) {
          donecd[i] = 1;
          doneab[j] = 1;
          cnt++;
        }
     }
  }
  printf("%d", cnt);
}

Measured memory_bytes: 128
abcd = list(input())
l = list(map(int,abcd))
ans_list = []
ans_list.append(l[0]+l[1]+l[2]+l[3])
ans_list.append(l[0]+l[1]+l[2]-l[3])
ans_list.append(l[0]+l[1]-l[2]+l[3])
ans_list.append(l[0]+l[1]-l[2]-l[3])
ans_list.append(l[0]-l[1]+l[2]+l[3])
ans_list.append(l[0]-l[1]+l[2]-l[3])
ans_list.append(l[0]-l[1]-l[2]+l[3])
ans_list.append(l[0]-l[1]-l[2]-l[3])

for i in range(7):
	if ans_list[i] == 7:
		if i == 0:
			print(str(l[0])+'+'+str(l[1])+'+'+str(l[2])+'+'+str(l[3])+'=7')
			break
		elif i == 1:
			print(str(l[0])+'+'+str(l[1])+'+'+str(l[2])+'-'+str(l[3])+'=7')
			break
		elif i == 2:
			print(str(l[0])+'+'+str(l[1])+'-'+str(l[2])+'+'+str(l[3])+'=7')
			break
		elif i == 3:
			print(str(l[0])+'+'+str(l[1])+'-'+str(l[2])+'-'+str(l[3])+'=7')
			break
		elif i == 4:
			print(str(l[0])+'-'+str(l[1])+'+'+str(l[2])+'+'+str(l[3])+'=7')
			break
		elif i == 5:
			print(str(l[0])+'-'+str(l[1])+'+'+str(l[2])+'-'+str(l[3])+'=7')
			break
		elif i == 6:
			print(str(l[0])+'-'+str(l[1])+'-'+str(l[2])+'+'+str(l[3])+'=7')
			break
		elif i == 7:
			print(str(l[0])+'-'+str(l[1])+'-'+str(l[2])+'-'+str(l[3])+'=7')
			break

Measured memory_bytes: 3192
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	LL n,a[1010]={},rm[1010]={};
	cin>>n;
	FORQ(i,1,n)cin>>a[i];
	LL p=0,qq=0,id=0,mn=-mod,mid=0;
	FORQ(i,1,n){
		if(a[i]<=0&&mn<a[i]){
			mid=i;
			mn=a[i];
		}
		if(i&1){
			if(a[i]>0)p+=a[i];
		}else{
			if(a[i]>0)qq+=a[i];
		}
	}
	if(p==0&&qq==0){
		cout<<mn<<endl;
		cout<<n-1<<endl;
		FORD(i,n+1,mid+1){
			cout<<i<<endl;
		}
		FOR(i,1,mid){
			cout<<1<<endl;
		}
		return 0;
	}
	if(p>qq){
		id=1;
		cout<<p<<endl;
	}else{
		id=0;
		cout<<qq<<endl;
	}
	//cout<<"t"<<endl;
	queue<int> q;
	int c=0,tmp=n;
	FORD(i,n+1,1){
		if((i&1)==id){
			tmp=i;
			break;
		}
		q.push(i);
		rm[i]=1;
		c++;
	}
	//cout<<"t1 c:"<<c<<endl;
	FORD(i,tmp+1,1){
		if((i&1)==id){
			if(a[i]<0){
				q.push(i);
				rm[i]=1;
				c++;
				q.push(i-1);
				rm[i-1]=1;
				c++;
			}else{
				tmp=i;
				break;
			}
		}
	}
	int last=0;
	FORD(i,tmp+1,2){
		if((i&1)==id){
			if(a[i]<0){
				q.push(i);
				rm[i-1]=1;
				if(last==0)last=i+1;
				rm[last]=1;
				c++;
				last=i;
			}else{
				last=0;
			}
		}
	}
	if(id==0){
		if(last==0)last=1;
		q.push(1);
		rm[last]=1;
		c++;
	}

	int num=1;
	FORQ(i,1,n){
		if(rm[i]==0){
			rm[num]=a[i];
			num++;
		}
	}
	num--;
	//cout<<"num:"<<num<<endl;
	FORD(i,num+1-2,3){
		if(i&1){
			q.push(i+1);
			c++;
		}
	}

	if(rm[1]>0){
		q.push(2);
		c++;
	}else{
		q.push(1);
		c++;
		q.push(1);
		c++;
	}
	cout<<c<<endl;
	FOR(i,0,c){
		cout<<q.front()<<endl;
		q.pop();
	}
  return 0;
}


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

int main() {
 string s;
 cin >> s;
int n = s.size();
int count = 0;
for(int i = 0; i<n-1; i++){
  if(s[i] == '0'){
    if(s[i] == s[i+1]){
      count++;
      s[i+1] = '1';
    }
 }
 else{
   if(s[i] == s[i+1]){
     count++;
     s[i+1] = '0';
   }
 }
}
cout << count << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {

    int n; cin >> n;
    vector<ll> A(n); rep(i,n) cin >> A[i];
    Sort(A);
    Reverse(A);

    ll a = 0; ll b = 0;
    rep(i,n-1) {
        if (A[i] == A[i+1]) {
            a = A[i];
            A[i] = A[i+1] = 0;
            break;
        }
    }
    Sort(A);
    Reverse(A);
    rep(i,n-1) {
        if (A[i] == A[i+1]) {
            b = A[i];
            break;
        }
    }


    out(a*b);





    return 0;
}









Measured memory_bytes: 1024
#include <iostream>
#include <complex>

using namespace std;

typedef complex<double> P;
struct L { P p, q; L(P p, P q) : p(p), q(q) {} };

double cross(P a, P b) { return imag(conj(a)*b); }

P ssCrosspoint(L a, L b){
	double A = cross(a.q-a.p, b.q-b.p);
	double B = cross(a.q-a.p, a.q-b.p);
	return b.p + B/A * (b.q-b.p);
}

int main(){
	int n; cin >> n;
	while(n--){
		P p[3];
		for(int i=0;i<3;i++) cin >> real(p[i]) >> imag(p[i]);
		P m0 = 0.5*(p[0]+p[1]);
		P m1 = 0.5*(p[0]+p[2]);
		P c = ssCrosspoint(L(m0, m0+(p[1]-p[0])*P(0,1)), L(m1, m1+(p[2]-p[0])*P(0,1)));
		printf("%.3lf %.3lf %.3lf\n", real(c), imag(c), abs(c-p[0]));
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>     // [PRIMES]               1777 ~2^10.80  
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(ll)(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

vl h;
ll C;
ll f(ll i){
    ll res = -1*oo;
    if(i == 0) return 0;
    FOR(j,0,i){
        ll tmp = 2*h[j] * h[i] + -1*(h[j] * h[j] - f(j));
        res = max(res, tmp);
    }
    res += -1*(C+h[i]*h[i]);
    return res;
}

int main(){
    

    ll N;
    cin >> N >> C;
    FOR(hjk,0,N){
        ll in;
        cin >> in;
        h.pb(in);
    }

	// Berechne ein DP der folgenden Form in O(n) Zeit:
	// dp[i] = c(i) + max (a(j)*x(i) + b(j)), für 0 <= j < i
	// wobei für j < i: a(j) <= a(i), x(j) <= x(i)
	ll n = N;

    vl dp(n), v(n); // v ist Stack von Geraden
	auto a = [&] (ll i) { return 2*h[i];};
    auto b = [&] (ll i) {return -1*h[i]*h[i] + dp[i];}; 
    auto c = [&] (ll i) {return -1*(C+h[i]*h[i]);};
    auto x = [&] (ll i){ return h[i];};
 
    auto eval = [&](ll j, ll i) {
        return a(j)*x(i) + b(j);
    };
    auto bad = [&](ll i, ll j, ll k) {
        return (a(j)-a(i))*(b(k)-b(i)) >= (a(k)-a(i))*(b(j)-b(i));
    };
 
    ll p = 0, q = 1; // p ist aktuelle Gerade, q ist end-of-stack Pointer
    dp[0] = 0;
    FOR(i,1,n) {
        p = min(p,q-1);
        while (p+1 < q && eval(v[p+1],i) > eval(v[p],i)) p++;
        dp[i] = c(i) + eval(v[p],i);
        v[q++] = i;
        while (q >= 3 && bad(v[q-3],v[q-2],v[q-1])) v[q-2] = v[q-1], q--;
    }
    cout<<dp[n-1] * -1<<endl;

} //cin.tie(0) bei schnellem Wechseln




Measured memory_bytes: 5104
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] l = new long[n + 1];
        l[0] = 2;
        l[1] = 1;
        for (int i = 0 ; i <= n ; i++) {
            if (i >= 2) l[i] = l[i - 1] + l[i -2];
        }
        System.out.println(l[n]);
    }

}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <string.h>
#include <utility>
#include <stack>
#include <queue>
#include <iomanip>
#include <cctype>
using namespace std;
typedef long long ll;

int cal(vector<string>&str, vector<int>&level, int n, int max){
    int lev= level[n];
    if(str[n][lev]>='0' && str[n][lev] <= '9'){
        return str[n][lev]-'0';
    }
    if(str[n][lev]=='+'){
        int ans=0;
        for(int i=n+1; i<max; i++){
            if(level[i]<=level[n]) break;
            else if(level[i]==level[n]+1){
                ans += cal(str, level, i, max);
            }
        }
        return ans;
    }
    if(str[n][lev]=='*'){
        int ans=1;
        for(int i=n+1; i<max; i++){
            if(level[i]<=level[n]) break;
            else if(level[i]==level[n]+1){
                ans *= cal(str, level, i, max);
            }
        }
        return ans;
    }
    //return -1;
    
}

int main()
{
    int n;
    cin>>n;
    while(n)
    {
        vector<string>w(n);
        vector<int>l(n,0);
        for(int i=0;i<n;i++)
        { cin>>w[i];
            for(int j=0;w[i][j]=='.';j++)
                l[i]++;
        }
        cout<<cal(w,l,0,n)<<endl;
        cin>>n;
    }
    return 0;
}



Measured memory_bytes: 3212
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	while(1){
		int n,m; cin>>n>>m;if(n==0) return 0;
		vector<int>a,b; int x=0,y=0;
		rep(i,n){int c;cin>>c;a.push_back(c);x+=c;}
		rep(i,m){int c;cin>>c;b.push_back(c);y+=c;}
		int ans1=1e9,ans2=1e9;
		rep(i,n)rep(j,m){
			if(x-a[i]+b[j] == y-b[j]+a[i] && ans1 > a[i]){
				ans1 = a[i];
				ans2 = b[j];
			}
		}
		if(ans1 > 1e8) puts("-1");
		else cout << ans1 << " " << ans2 << endl;
	}
}



Measured memory_bytes: 3132
import java.util.*;

public class Main{
	public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      String books = sc.next();
      char x = books.charAt(books.length()-1);
      switch(x){
        case '2':
        case '4':
        case '5':
        case '7':
        case '9':
          System.out.println("hon");
          break;
        case '0':
        case '1':
        case '6':
        case '8':
          System.out.println("pon");
          break;
        default:
          System.out.println("bon");
          break;        
      }     
    }
}

Measured memory_bytes: 35720
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i < (n);i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define SCANF(i) int i;scanf("%d",&i)
typedef long long ll;
using namespace std;
using P = pair<int,int>;
const long long INF = 1LL << 60;
const int IINF=100000000;
const int MOD = (int)1e9 + 7;
//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
vector<int> dx={1,0,-1,0};vector<int> dy={0,-1,0,1};

signed main () {
    string a,b;cin >> a >> b;
    int ans = 0;
    int leng = a.size();
    REP(i,leng){
        if(a[i]!=b[i])ans++;
    }
    cout << ans << endl;
}//https://atcoder.jp/contests/abc172/tasks/abc172_b

Measured memory_bytes: 3824
#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
using namespace std;

long long int N, M, X;
long long int c, a;
vector<long long int> C;
vector<vector<long long int>> A;

long long int dfs(long long int i, long long int cost, vector<long long int> K) {
    bool ok = true;
    for (int n = 0; n < K.size(); n++) {
        if (K[n] < X) {
            ok = false;
            break;
        }
    }
    if (ok) {
        return cost;
    }
    if (i == N) {
        return 0;
    }
    long long int ans1 = dfs(i+1, cost, K);
    vector<long long int> tmp(M);
    for (long long int j = 0; j < M; j++) {
        tmp[j] += K[j] + A[i][j];
    }
    long long ans2 = dfs(i+1, cost+C[i], tmp);
    if (ans1 == 0 || ans2 == 0) {
        return max(ans1, ans2);
    } else {
        return min(ans1, ans2);
    }
}

int main(){
    cin >> N >> M >> X;
    for (int i = 0; i < N; i++) {
        cin >> c;
        C.push_back(c);
        vector<long long int> tmp;
        for (int j = 0; j < M; j++) {
            cin >> a;
            tmp.push_back(a);
        }
        A.push_back(tmp);
    }
    vector<long long int> K(M);
    long long int ans = dfs(0, 0, K);
    if (ans == 0) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(){
  int x;
  scanf("%d", &x);

  int cards[x];
  for (int i = 0; i < x; ++i) {
    scanf("%d", &cards[i]);
  }
    
  sort(cards, cards + x, greater<int>());

  int alice = 0;
  int bob = 0;

  for(int i = 0; (int)sizeof(cards) / (int)sizeof(int) > i; i++){
    int card = cards[i];
    if(i % 2 == 0){
      alice += card;
    }else{
      bob += card;
    }
  }

  printf("%d\n", alice - bob);

  return 0;
}


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

using namespace std;

map<int, int> DP;
int PosDP[500000];

int& Get(int pos) {
    if (DP.count(pos)) return DP[pos];
    return DP[pos] = 1e9;
}

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


    int cur_mask = 0;
    DP[0] = 0;

    int n = s.size();
    for (int i = 0; i < n; ++i) {
        int norm = s[i] - 'a';
        cur_mask ^= (1 << norm);
        PosDP[i] = 1 + Get(cur_mask);

        for (int a = 0; a <= 26; ++a) {
            int nw_mask = cur_mask;
            nw_mask ^= (1 << a);

            
            if (PosDP[i] > 1 + Get(nw_mask))
                PosDP[i] = 1 + Get(nw_mask);
            
        }
        if (Get(cur_mask) > PosDP[i])
            Get(cur_mask) = PosDP[i];
    }
/*
    for (int i = 0; i < n; ++i)
        cerr << PosDP[i] << " ";
            cerr << endl;
*/
    cout << PosDP[n - 1] << endl;
    return 0;
}


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

namespace Contest
{
    partial class Program
    {
        static void Main(string[] args)
        {
            ABC152_B();
        }
        #region ABC152
        static void ABC152_A()
        {
            var nm = ReadIntN();
            Console.WriteLine(nm[0] == nm[1] ? "Yes" : "No");
        }
        static void ABC152_B()
        {
            var ab = ReadIntN();
            var A = ab[0];
            var B = ab[1];
            Console.WriteLine(A < B ? String.Join("", Enumerable.Repeat(A, B)) : String.Join("", Enumerable.Repeat(B, A)));
        }
        static void ABC152_C()
        {
            var N = ReadInt();
            var P = ReadIntN();
            int min = P[0];
            int count = 0;
            for (int i = 0; i < N; ++i)
            {
                if (min >= P[i])
                {
                    count += 1;
                    min = P[i];
                }
            }
            Console.WriteLine(count);
        }
        static void ABC152_D()
        {
            var N = ReadInt();
            long[,] count = new long[10, 10];
            for (int i = 1; i <= N; ++i)
            {
                var A1 = i;
                while (A1 > 9) { A1 /= 10; }
                var A0 = i % 10;
                count[A1, A0]++;
            }
            Console.WriteLine(Enumerable.Range(1, 9).Select(i => Enumerable.Range(1, 9).Select(j => count[i, j] * count[j, i]).Sum()).Sum());
        }
        static void ABC152_E()
        {
            var N = ReadInt();
            var A = ReadIntN();
        }
        #endregion


        static string ReadStr()
        {
            return Console.ReadLine();
        }
        static string[] ReadStrN()
        {
            return Console.ReadLine().Split(' ');
        }
        static int ReadInt()
        {
            return Convert.ToInt32(Console.ReadLine());
        }
        static int[] ReadIntN()
        {
            return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
        }
        static long ReadLong()
        {
            return Convert.ToInt64(Console.ReadLine());
        }
        static long[] ReadLongN()
        {
            return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
        }
        static Tuple<long, long>[]  ReadTupleLong(int n)
        {
            List<Tuple<long, long>> list = new List<Tuple<long, long>>();
            for (int i = 0; i < n; ++i)
            {
                var ab = ReadLongN();
                list.Add(new Tuple<long, long>(ab[0], ab[1]));
            }
            return list.ToArray();
        }
    }
}


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

#define rep(i,a,b)      for(int i=a;i<=b;i++)
#define revp(i,a,b)     for(int i=b;i>=a;i--)

int n,temp,p,neg,arr1[22],arr2[22],ans,cn=0,cp=0;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
   
    cin>>n;
    rep(i,1,n)
        cin>>arr1[i];
    rep(i,1,n)
        cin>>arr2[i],arr1[i]-=arr2[i];
    rep(i,1,n)
        if(arr1[i]>0)
            p+=arr1[i];
    cout<<p;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);
  ll x;
  cin >> x;
  bitset<32> bs_(x);
  auto bs = bs_;
  cout << bs.to_string() << endl;
  bs.flip();
  cout << bs.to_string() << endl;
  bs = bs_;
  bs <<= 1;
  cout << bs.to_string() << endl;
  bs = bs_;
  bs >>= 1;
  cout << bs.to_string() << endl;
  return 0;
}



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

using namespace std;

#define rep(i, a, b)  for(int i = (a); i < (b); i++)
#define rrep(i, a, b) for(int i = (a); i > (b); i--)
#define sq(x) ((x) * (x))
#define bit(x) bitset<32>(x)
#define vsort(v)  sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<llint>())
#define debug(x) cout << #x << " " << (x) << endl
#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


template<typename Tn> Tn __lcm(Tn a, Tn b)
{
    return a / __gcd(a, b) * b;
}

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int n;
vi edge[10001];
int c[10001];
bool done[10001];
int ans[10001];

int f(int idx, int cidx)
{
    if(done[idx]) return 0;
    done[idx] = true;
    int rec = 1;
    ans[idx] = c[cidx];

    for(int i = 0; i < edge[idx].size(); i++) {
	rec += f(edge[idx][i], cidx + rec);
    }
    
    return rec;
}

int main()
{
    ci >> n;

    int a, b;
    rep(i, 0, n - 1) {
	ci >> a >> b;
	edge[a].pb(b);
	edge[b].pb(a);
    }

    llint sum = 0;
    rep(i, 0, n) {
	ci >> c[i];
	sum += c[i];
    }
    sort(c, c + n, greater<int>());
    sum -= c[0];

    f(1, 0);
    co << sum << en;
    rep(i, 1, n + 1) co << ans[i] << " ";ln;
    
  
    return 0;
}


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

int main () {
  int N;
  cin >> N;
  vector<int> num(N);
  for (int i = 0; i < N; i++)
    cin >> num.at(i);
  
  for (int i = 0; i < N; i++) {
    for (int j = i; j < N; j++) {
      if (num.at(i) < num.at(j)) {
        int x;
        x = num.at(i);
        num.at(i) = num.at(j);
        num.at(j) = x;
      }
    }
  }
  
  int A = 0, B = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0)
      A += num.at(i);
    else {
      B += num.at(i);
    }
  }
  
  cout << A - B << endl;
}

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

using namespace std;

#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;

// bool has_key_using_count(map<char, int> const &m, char c) {
//     if (m.count(c) == 0) {
//         return false;
//     } else {
//         return true;
//     }
// }

// template <typename Map>
// bool map_compare(Map const &lhs, Map const &rhs) {
//     for(auto s1: lhs){
//         if(!has_key_using_count(rhs, s1.first)){
//             return false;
//         }
//     }
//     return lhs.size() == rhs.size() &&
//            std::equal(lhs.begin(), lhs.end(), rhs.begin());
// }

int fact(int n) {
    if (n == 0) return 1;
    if (n > 0) return n * fact(n - 1);
}

int NCR(int n, int r) {
    if (n == r) return 1;
    if (r == 0 && n != 0)
        return 1;
    else
        return (n * fact(n - 1)) / fact(n - 1) * fact(n - r);
}

int main() {
    ll N;
    ll count = 0;
    cin >> N;
    vector<string> S(N);
    map<string, ll> anag;
    for (ll i; i < N; i++) {
        cin >> S[i];
        sort(all(S[i]));
    }

    for (auto c : S) {
        anag[c]++;
    }
    for (auto c : anag) {
        if (c.second >= 2) {
            // count += NCR(c.second, 2);
            count += (c.second) * (c.second - 1) / 2;
        }
    }
    // for(auto c : anag){
    //     cout << c.first << " " << c.second << endl;
    // }

    cout << count << endl;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;

  if (b % a == 0)
    cout << a + b << endl;
  else
    cout << b - a << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> vec(M);
  REP(i, M) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  vector<int> diff(M-1);
  
  REP(i, M-1) {
    diff[i] = abs(vec[i] - vec[i+1]);
  }
  sort(diff.begin(), diff.end());
  int ans = 0;
  REP(i, M-1-(N-1)) {
    ans += diff[i];
  }
  cout << ans << endl;
  return 0;
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

namespace IO {
    #define gc getchar()
    template <typename T>
    inline void read(T& x) {
        x = 0; bool f = 1; char ch;
        for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1;
        for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48);
        x = f ? x : -x;
    }
    #undef gc
}

const int MAXN = 2e5 + 10;
const int P = 1e9 + 7;

typedef long long ll;

int n, k;
ll ans = 1, arr[MAXN];

int main() {
    IO::read(n), IO::read(k);
    rep(i, 1, n) IO::read(arr[i]);
    sort(arr + 1, arr + n + 1);
    if (k & 1 && arr[n] < 0) {
        per(i, n, n - k + 1) ans = 1ll * ans * arr[i] % P;
        printf("%lld\n", (ans + P) % P);
        return 0;
    }
    int l = 1, r = n, tot = 0;
    if (k & 1) ans = arr[n] % P, r--, tot++;
    while (l <= r && tot <= k) {
        if (tot == k) break;
        ll numl = arr[l] * arr[l + 1];
        ll numr = arr[r] * arr[r - 1];
        if (numl > numr) ans = 1ll * numl % P * ans % P, l += 2, tot += 2;
        else ans = 1ll * numr % P * ans % P, r -= 2, tot += 2;
    }
    printf("%lld\n", (ans % P + P) % P);
    return 0;
}

Measured memory_bytes: 5244
#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

template <typename T> void print_vec(const vector<T>& v) {
	for(int i = 0; i < SZ(v); i++) {
		if (i) cout << " ";
		cout << v[i];
	}
	cout << "\n";
}

inline ll floorDiv(ll x, ll y) {
	ll d = x / y;
	ll r = x % y;
	return r ? (d - ((x < 0) ^ (y < 0))) : d;
}

ll ceilDiv(ll x, ll y) {
	return -floorDiv(-x,y);
}

bool predicate(ll mid) {
	return mid>10;
}

ll bin_search(ll lo, ll hi) {
	int sign = lo < hi ? 1 : -1;
	lo*=sign;
	hi*=sign;
	hi++;
	while(lo < hi) {
		ll mid = floorDiv(lo+hi,2);
		if (!predicate(sign*mid)) {
			lo = mid+1;
		} else {
			hi = mid;
		}
	}
	return sign*lo;
}
const ll MOD = 1000000007;
const int MAXN = 200005;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	bool good = false;
	cin >> n;
	int cnt = 0;
	while(n--){
		int x, y;
		cin >> x >> y;
		if (x == y) {
			cnt++;
		} else {
			cnt = 0;
		}
		good|=cnt>=3;
	}
	cout << (good ? "Yes" : "No") << "\n";
	
	
	
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define LL long long
 
const int maxn=5e5+10;
 
int n,L,H,T;
 
struct Point{
	LL x;
	double y;
	Point() {}
	Point(LL x,double y):x(x),y(y) {}
	Point operator + (const Point &p) const {return Point(x+p.x,y+p.y);}
	Point operator - (const Point &p) const {return Point(x-p.x,y-p.y);}
};
 
double Cross(Point A,Point B) {return A.x*B.y-A.y*B.x;}
 
Point P[maxn];
 
Point GetPoint(Point A,Point B,LL x)
{
	double t=((double)x-A.x)/(B.x-A.x);
	return Point(x,A.y+t*(B.y-A.y));
}
 
int main()
{
#ifdef h10
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
	scanf("%d%d",&n,&L);
	H=T=1;
	P[1]=Point(0,0);
	while (n--)
	{
		Point p;
		scanf("%lf%lld",&p.y,&p.x);
		p.y*=p.x;
		T++;
		P[T]=P[T-1]-p;
		while (H!=T&&P[H+1].x-P[T].x>=L) H++;
		if (P[H].x-P[T].x>L)
			P[H]=GetPoint(P[H],P[H+1],P[T].x+L);
		while (H+1<T&&Cross(P[T-1]-P[T],P[T-2]-P[T])>=0) P[T-1]=P[T],T--;
		printf("%.10lf\n",((double)P[H].y-P[T].y)/L);
	}
}
///err

Measured memory_bytes: 18304
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define all(c) (c).begin(), (c).end()
#define endl '\n'

ll pow(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}




int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
//      int t;
//      cin >> t;
//      while(t--){



// }

int count = 1;
int n;
int flag = 1;
while(cin >> n){
	if(n == 0)flag = 0;
	if(flag)count++;
}
cout << count << endl;


return 0;
}



Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define ll long long int
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define inputv(a) forall(i,0,a.size()) cin>>a[i]
#define outputv(a) for(auto i:a) cout<<i<<" ";br;
#define fs first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define minv(a) *min_element(all(a))
#define maxv(a) *max_element(all(a))
#define br cout<<"\n"
using namespace std;
int dr[]={-1,1,0,0};
int dc[]={0,0,-1,1};
ll mod=1000000007;
ll po(ll x,ll n){
    ll res = 1;
    while(n>0){
        if(n%2==1)
            res = ((res)*(x));
        x = (x*x);
        n = n/2;
    }
    return res;
}
ll ceil(ll x,ll y)
{
    if(x%y==0)
        return x/y;
    else
        return(x/y)+1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll a[n],b[n],c[n];
    rep(i,0,n) cin>>a[i]>>b[i]>>c[i];
    ll dpa[n+1],dpb[n+1],dpc[n+1];
    dpa[0]=0;
    dpb[0]=0;
    dpc[0]=0;
    for(ll i=1;i<=n;i++)
    {
        dpa[i]=a[i-1]+max(dpb[i-1],dpc[i-1]);
        dpb[i]=b[i-1]+max(dpa[i-1],dpc[i-1]);
        dpc[i]=c[i-1]+max(dpa[i-1],dpb[i-1]);

    }
    cout<<max({dpa[n],dpb[n],dpc[n]});
}


Measured memory_bytes: 4992
//============================================================================
// Name        : ITP_1_9_C.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <string>
using namespace std;

int main() {
	string str_taro, str_hanako;
	int st=0,sh=0,n;
	cin >> n;
	for(int i=0; i<n; ++i) {
		cin >> str_taro >> str_hanako;
		if(str_taro>str_hanako) {
			st+=3;
		} else if(str_taro<str_hanako) {
			sh+=3;
		} else {
			++st;
			++sh;
		}
	}
	cout << st << " " << sh << endl;
	return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define M_PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string S;
	int ans = 0;

	cin >> S;
	rep(i, S.length() - 1) {
		if (S[i] != S[i + 1]) ans++;
	}

	cout << ans << endl;

	return 0;
}


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

int main () {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int sumW = 0;
  int sumE = 0;
  int countW = 0;
  int countE = 0;
  vector<int>M(N+1);
  M.at(0) = 0;
  
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'W'){
      sumW++;
      countW++;
    }
    else if (S.at(i) == 'E'){
      sumE++;
      countE++;
    }
    M.at(i+1) = countW - countE;
  }
  sort(M.begin(), M.end());
  
  cout << M.at(0) + sumE << endl;
}
    
  
    
  
   

Measured memory_bytes: 4776
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n<1200){
    cout<<"ABC"<<endl;
  }
  else if(n<2800){
    cout<<"ARC"<<endl;
  }
  else{
    cout<<"AGC"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256