akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
main(){
  int n;
  cin>>n;

  while(n!=0){
    int i,j,c,h,t;
    int taro[n];
    int hana[n];  
    for(i=0;i<n;i++)
      cin>>taro[i];

    sort(taro,taro+n);
    c=0;
    for(j=1;j<taro[0];j++){
      hana[c]=j;
      c++;	
    }
    for(i=0;i<n-1;i++){
      for(j=taro[i]+1;j<taro[i+1];j++){
	hana[c]=j;
	c++;
      }
    }
    for(j=taro[n-1]+1;j<=n*2;j++){
      hana[c]=j;
      c++;
    }

    t=0;
    h=0;
    c=0;
   
    while(t<n && h<n){
      bool f=false;
      for(i=0;i<n;i++){
	if(c<taro[i]){
	  c=taro[i];
	  t++;
	  taro[i]=0;
	  f=true;
	  break;
	}
      }
      if(!f) c=0;
  
      if(!(t<n && h<n)) break;

      f=false;
      for(i=0;i<n;i++){
	if(c<hana[i]){
	  c=hana[i];
	  h++;
	  hana[i]=0;
	  f=true;
	  break;
	}
      }
      if(!f)c=0;
   
    }


  
    if(t>=n)
      cout<<n-h<<endl<<0<<endl;
    else if(h>=n)
      cout<<0<<endl<<n-t<<endl;
    cin>>n;
  }
  return 0;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

class UnionFind {
public:
  const static int MAX_N = 505;
  int par[MAX_N];
  int s[MAX_N];
  UnionFind() { init(); }
  UnionFind(int n) { init(n); }
  void init() { for(int i=0; i<MAX_N; ++i) par[i] = i, s[i] = 1; }
  void init(int n) { for(int i=0; i<n; ++i) par[i] = i, s[i] = 1; }
  int find(int x) {
    if(par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(s[x] < s[y]) par[x] = y, s[y] = s[x] + s[y];
    else par[y] = x, s[x] = s[x] + s[y];
  }
  bool same(int x, int y) { return find(x) == find(y);}
};
UnionFind uf;

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

  int n, m;
  cin >> n >> m;
  VVI edge(m, VI(3, 0));
  REP(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    edge[i] = {c, a, b};
  }

  VVI g(500, VI());
  VVI tree;
  sort(ALL(edge));
  REP(i, m) {
    if(uf.same(edge[i][1], edge[i][2])) continue;
    uf.unite(edge[i][1], edge[i][2]);
    g[edge[i][1]].PB(edge[i][2]);
    g[edge[i][2]].PB(edge[i][1]);
    tree.PB(edge[i]);
  }

  int cnt = 0, ret = 0;
  int type[505] = {};
  bool used[505] = {};

  // cout << tree << endl;
  REP(i, tree.size()) {
    function<void(int,int)> dfs = [&](int v, int t) {
      type[v] = t;
      used[v] = true;
      for(auto e: g[v]) {
        bool cond = tree[i][1] == v && tree[i][2] == e;
        cond |= tree[i][2] == v && tree[i][1] == e;
        if(!used[e] && !cond) dfs(e, t);
      }
    };
    // tree[i] を削除したときの頂点の分割
    int t = 0;
    memset(used, false, sizeof(used));
    REP(j, n) {
      if(used[j]) continue;
      dfs(j, t);
      t++;
    }
    bool ok = true;
    REP(j, m) {
      // cout << j << " " << edge[j] << " " << type[j] << endl;
      // j番目のedgeの両端のtypeが異なる
      if(tree[i] == edge[j]) continue;
      if(type[edge[j][1]] != type[edge[j][2]] && tree[i][0] == edge[j][0]) {
        ok = false;
        break;
      }
    }
    if(ok) {
      cnt++;
      ret += tree[i][0];
    }
  }

  cout << cnt << " " << ret << endl;

  return 0;
}



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

int INF = 1<<20;
int main() {
	int n;
	while(cin >> n && n){
		map<string, double> sd;
		vector<string> svec;
		string str;
		int p, a, b, c, d, e, f, s, m;
		for(int i = 0; i < n; ++i){
			cin >> str >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			svec.push_back(str);
			int t = a + b + c + (d + e) * m;
			sd[str] = (double)(s * f * m - p) / t;
		}
		sort(svec.begin(), svec.end());
		double max_bf = -INF;
		string max_str;
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				if(max_bf < sd[svec[j]]){
					max_bf = sd[svec[j]];
					max_str = svec[j];
				}
			}
			cout << max_str << endl;
			max_bf = -INF;
			sd[max_str] = -INF;
		}
		cout << "#" << endl;
	}
	return 0;
}

Measured memory_bytes: 1228
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
A = []
for a in a1:
  A.append([a, False])
for a in a2:
  A.append([a, False])
for a in a3:
  A.append([a, False])

N = int(input())
B = []
for _ in range(N):
  b = int(input())
  B.append(b)

for i, a in enumerate(A):
  if (a[0] in B):
    A[i][1] = True

result = "No"
if (A[0][1] == True and A[1][1] == True and A[2][1] == True):
  result = "Yes"
elif (A[3][1] == True and A[4][1] == True and A[5][1] == True):
  result = "Yes"
elif (A[6][1] == True and A[7][1] == True and A[8][1] == True):
  result = "Yes"
elif (A[0][1] == True and A[3][1] == True and A[6][1] == True):
  result = "Yes"
elif (A[1][1] == True and A[4][1] == True and A[7][1] == True):
  result = "Yes"
elif (A[2][1] == True and A[5][1] == True and A[8][1] == True):
  result = "Yes"
elif (A[0][1] == True and A[4][1] == True and A[8][1] == True):
  result = "Yes"
elif (A[2][1] == True and A[4][1] == True and A[6][1] == True):
  result = "Yes"
else:
  result = "No"

print(result)

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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 (a>b) { a=b; return 1; } return 0; }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    reverse(bit.begin(), bit.end());
    return bit;
}

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

    ll H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    REP(i, H) cin >> S[i];

    ll res = 0;
    REP(mask1, (1ll<<H)){
        REP(mask2, (1ll<<W)){
            ll cnt = 0;
            REP(i, H){
                REP(j, W){
                    if(mask1>>i & 1){
                        if(mask2>>j & 1){
                            if(S[i][j] == '#') cnt++;
                        }
                    }
                }
            }
            if(cnt==K) res++;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 1000000000


int main(){
	
	int X,Y,A,B,C;
	cin>>X>>Y>>A>>B>>C;
	
	priority_queue<long long,vector<long long>,greater<long long>> Q1,Q2;
	
	for(int i=0;i<A;i++){
		long long x;
		cin>>x;
		Q1.push(x);
		while(Q1.size()>X)Q1.pop();
	}
	for(int i=0;i<B;i++){
		long long x;
		cin>>x;
		Q2.push(x);
		while(Q2.size()>Y)Q2.pop();
	}
	for(int i=0;i<C;i++){
		long long x;
		cin>>x;
		if(Q1.top()>Q2.top())Q2.push(x);
		else Q1.push(x);
		while(Q1.size()>X)Q1.pop();
		while(Q2.size()>Y)Q2.pop();
	}
	
	long long ans = 0;
	
	while(Q1.size()!=0){
		ans += Q1.top();
		Q1.pop();
	}
	
	while(Q2.size()!=0){
		ans += Q2.top();
		Q2.pop();
	}
	
	cout<<ans<<endl;
	
	
	
    return 0;
}


Measured memory_bytes: 2420
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int N, Sn, x, y;
    scanf("%d", &N);
    if (N < 1 || N > pow(10, 9))
        exit(1);
    y = N;
    while (y)
    {
        x = y % 10;
        Sn = Sn + x;
        y = y / 10;
    }
    if (Sn != 0 && N % Sn == 0)
        printf("Yes");
    else
        printf("No");
    return 0;
}

Measured memory_bytes: 128
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve
bool dp[5001][5001], dp2[5001][5001];

int main(int argc, char const* argv[])
{
  int n, k;
  cin >> n >> k;
  vector<ll> a;
  rep(i, n){
    ll x;
    cin >> x;
    a.pb(x);
  }
  dp[0][0] = true;
  rep(i, n){
    rep(j, k+1){
      dp[i+1][j] = dp[i][j];
      if(j - a[i] >= 0)dp[i+1][j] |= dp[i][j-a[i]];
    }
  }
  dp2[n][0] = true;
  for(int i = n - 1; i >= 0; i--){
    rep(j, k+1){
      dp2[i][j] = dp2[i+1][j];
      if(j - a[i] >= 0)dp2[i][j] |= dp2[i+1][j-a[i]];
    }
  }
  vector<int> vec = vector<int>(k + 1, 0);
  int res = 0;
  rep(i, n){
    if(a[i] >= k){
      res++;
      continue;
    }
    vec = vector<int>(k + 1, 0);
    rep(j, k+1){
      if(j > 0)vec[j] = vec[j-1];
      if(dp2[i+1][j])vec[j]++;
    }
    rep(j, k){
      if(!dp[i][j])continue;
      int tmp = vec[k-j-1];
      if(k - a[i] - j > 0)tmp -= vec[k - a[i] - j - 1];
      if(tmp > 0){
        res++;
        break;
      }
    }
  }
  cout << n - res << endl;
	return 0;
}


Measured memory_bytes: 49152
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int N = sc.nextInt();
        int lastPoints = 0;
        int firstDistance = 0;
        int[] distanceArray = new int[N];
        for (int i = 0; i < N; i++) {
            int point = sc.nextInt();
            int distance = 0;
            if (i == 0) {
                lastPoints = point;
                firstDistance = point;
                continue;
            }
            distance = point - lastPoints;
            if (i == N - 1) {
                int lastDistance = K - point + firstDistance;
                distanceArray[i] = lastDistance;
            }
            distanceArray[i - 1] = distance;
            lastPoints = point;
        }
        sc.close();
        Arrays.sort(distanceArray);
        int minDistance = 0;
        for (int i = 0; i < N - 1; i++) {
            minDistance += distanceArray[i];
        }

        System.out.println(minDistance);
    }
}


Measured memory_bytes: 87072
NK = list(map(int, input().split()))
N=NK[0]
K=NK[1]
sunukes = [i+1 for i in range(N)]
for i in range(K):
  d = int(input())
  A = map(int, input().split())
  for a in A:
    if a in sunukes:
      sunukes.remove(a)

print(len(sunukes))



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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int N, M;
    cin >> N >> M;
    
    map<int, set<int>> mp;
    for (int i = 0; i < M; ++i) { 
        int k, v; cin >> k >> v; mp[k].insert(v);
    }
    for (auto& p : mp) if (p.second.size() > 1) { cout << "-1\n"; return 0; }
    vector<int> d(N + 1, -1);
    for (auto& p : mp) d[p.first] = *p.second.begin();
    
    if (d[1] == 0 && N > 1) { cout << "-1\n"; return 0;}
    if (d[1] == -1 && N > 1) d[1] = 1; 

    int ans = 0, factor = 1;
    for (int i = N; i >= 1; --i) {
        d[i] = (d[i] == -1 ? 0 : d[i]);
        ans += d[i] * factor;
        factor *= 10;
    }
    cout << ans << endl;
}


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


int main()
{
	std::string s_1, s_2, s_3;

	std::cin >> s_1 >> s_2 >> s_3;

	transform(s_1.begin(), s_1.begin()+1, s_1.begin(), toupper);
	transform(s_2.begin(), s_2.begin()+1, s_2.begin(), toupper);
	transform(s_3.begin(), s_3.begin()+1, s_3.begin(), toupper);

	std::cout << s_1[0] << s_2[0] << s_3[0] << "\n";

	return 0;
}

Measured memory_bytes: 256
A, B, C, X = [int(input()) for _ in range(4)]

y = []
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            y.append(500 * a + 100 * b + 50 * c)

print(y.count(X))

Measured memory_bytes: 8276
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
LL n,s;

inline bool check(LL n,LL b) {
    LL sum=0;
    while (n>=b) {
        sum+=(n%b);
        n/=b;
    }
    if (n<b) sum+=n;
    return sum==s;
}

int main() {
    scanf("%lld%lld",&n,&s);
    if (s>n) { puts("-1");return 0; }
    if (s==n) { printf("%lld\n", n+1);return 0; }
    LL t=sqrt(n)+1;
    for (LL i=2;i<=t;i++) {
        if (check(n,i)) {
            printf("%lld\n", i);
            return 0;
        }
    }
    LL ans=1e12;
    for (LL p=1;p*p<=n-s;p++) {
        if ((n-s)%p==0) {
            LL b=(n-s)/p+1;
            if (check(n,b)) ans=min(ans,b);
        }
    }
    printf("%lld\n",ans==1e12?-1:ans);
    return 0;
}

Measured memory_bytes: 128
<?php

$n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));
$as = [];
for ($i=0; $i < $n; $i++) { 
	$as[] = (int)$input[$i];
}

$q = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));
$qs = [];
for ($j=0; $j < $q; $j++) { 
	$qs[] = (int)$input[$j];
}

// 総当たり
$hash = [];
$hash[0] = true;

for ($i=0; $i < $n; $i++) { 
	$new_hash = [];
	foreach ($hash as $k => $v) {
		// 使用しない
		$new_hash[$k] = true;
		// 使用する
		$new_hash[$k+$as[$i]] = true;
	}
	$hash = $new_hash;
}
ksort($hash);
foreach ($qs as $v) {
	if (isset($hash[$v])) {
		echo 'yes' . PHP_EOL;
	}else{
		echo 'no' . PHP_EOL;
	}
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define ls(x) (x)<<1
#define rs(x) (x)<<1|1
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll rt<<1
#define rr rt<<1|1
#define PI acos(-1)
//#define MM int m=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (x+mo_num)%mo_num
#define vc vector
#define vct vector<int>
#define fa(i,V) for(auto i:V)
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
//#define P pair<int,int>
using namespace std;
const int INF=LLONG_MAX;
const int maxn=1e5+5;
const int mo_num=1e9+7;
int n,m,a[maxn],b[maxn];
int c[maxn];
bool check(int ans)
{
    int plus=0;
    int M=m;
    fu(i,1,n)c[i]=a[i]%ans;
    sort(c+1,c+1+n);
    int l=1,r=n;
    while(l<r)
    {
        plus+=c[l];
        M-=c[l];
        l++;
        if(M<0)return 0;
        while(plus+c[r]>=ans)
        {
            r--;
            plus-=(ans-c[r]);
        }
    }
    return 1;
}
int32_t main()
{
    IOS
    cin>>n>>m;
    int sum=0;
    fun(i) {
        cin >> a[i];
        sum+=a[i];
    }
    int ans=0;
    int t=sqrt(sum);
    for(int i=1;i*i<=sum;i++)
    {
        if(sum%i)continue;
        if(check(sum/i)) {
            return cout << sum/i, 0;
        }else if(check(i))ans=max(ans,i);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
x = int(input())


quotient = x // 500
remainder = x % 500

presure_1 = 1000 * quotient + (remainder // 5) * 5

presure_2 = (x // 5) * 5

if presure_1 >= presure_2:
  print(presure_1)
else:
  print(presure_2)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long int lli;

int main(){
	ios_base::sync_with_stdio(false);
	int k, x;
	cin >> k >> x;
	for(int i=x-k+1; i<=x+k-1; i++) cout << i << " ";	
	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 FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    int n[3];
    cin >> n[0] >> n[1] >> n[2];
    SORT(n, 3);
    cout << n[0] + n[1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        string str;
        cin >> str;
        long ans = 0;
        ans = 9 *  (str.length() - 1);
        if(str[0] != '1'){
            ans += ((int)(str[0] - '1')); 
        }
        long t = 0;
        for(int i = 0 ; i < str.length() ; i++ ){
            t += ((int)(str[i] - '0'));
        }
        ans = max(t , ans);
        
        cout << ans << endl;
        
        return 0;
    }

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n, a, b;
string str;
int main(void){
    // Your code here!
    cin >> n >> str;
    for (ll i = 0; i < n; i++) {
        if (str[i] == '(') {
            a++;
        } else {
            if (a > 0) a--;
            else b++;
        }
    }
    for (ll i = 0; i < b; i++) cout << '(';
    cout << str;
    for (ll i = 0; i < a; i++) cout << ')';
}


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

int main()
{
	int a;

	cin >> a;

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

		cin >> a;
	}

	return 0;
}


Measured memory_bytes: 3096
smap, tmap = [-1] * 26, [-1] * 26

S = input()
T = input()

ans = 'Yes'
for s, t in zip(S, T):
    s = ord(s) - ord('a')
    t = ord(t) - ord('a')
    if smap[s] >= 0:
        if smap[s] != t:
            ans = 'No'
            break
    else:
        smap[s] = t
    if tmap[t] >= 0:
        if tmap[t] != s:
            ans = 'No'
            break
    else:
        tmap[t] = s
    
print(ans)


Measured memory_bytes: 42804
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
const int N=25;

int n,v[N],c[N],ans;

int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    for (int i=0;i<n;++i) cin>>v[i];
    for (int i=0;i<n;++i) cin>>c[i];
    for (int mask=0;mask<(1<<n);++mask) {
        int x=0, y=0;
        for (int i=0;i<n;++i)
            if ((1<<i)&mask) x+=v[i], y+=c[i];
        ans=max(ans,x-y);
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 256
/*痛みを受け取れ，痛みを知れ*/
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 1e5;
ll a[N],c[N];
bool st[N];
int main()
{
	//freopen("in.txt", "r", stdin);
	int n,k; cin >> n>>k;
	f(i, 1, n)scanf("%lld", &a[i]);
	f(i, 1, n)scanf("%lld", &c[i]);
	ll ans = -2e18;
	f(i,1,n)
	{
		if (!st[a[i]])
		{
			ll t = a[i];
			deque<ll> dq;
			while (!st[t])
			{
				st[t] = true;
				dq.push_back(c[t]);
				t = a[t];
			}
			int sz = dq.size();
			f(j, 1, sz)
			{
				ll it = dq.front();
				dq.pop_front();
				dq.push_back(it);
				ll now = 0, len = 0;
				vector<ll> v;
				ll mx2 = 0;
				for (ll I : dq)
				{
					len++;
					now += I;
					v.emplace_back(now);
					if (k >= len)ans = max(ans, now);
					mx2 = max(mx2, now);
				}
				if (k >=sz&&now>=0)
				{
					ll cishu = k / len;
					ll tmp = cishu * now;
					ll tmp2 = 0;
					if(now>0)tmp2=tmp;
					int re = k % sz;
					ll submx=0;
					f(J, 1, re)
					{
						submx = max(submx, v[J-1]);
					}
					ans = max(ans, tmp+submx);
					if(cishu>0)ans = max(ans, mx2 + tmp - now);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int n,a, now;
  cin >> n;
  vector<int> nums_v;
  vector<long long> cnt(n+1,0);
  long long sum=0,ans,b;
  rep(i,n){
    cin >> a;
    nums_v.push_back(a);
    cnt[a]++;
  }
  rep(i,n+1){
    sum += cnt[i]*(cnt[i]-1)/2;
  }
  rep(i,n){
    b = cnt[nums_v[i]];
    if(b != 0){
      ans = sum - b + 1;
    }else{
      ans = sum;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 5108
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2]){
		cout<<"Yes"<<endl;
	}
	else if(s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1]){
		cout<<"Yes"<<endl;
	}
	else if(s[0]==s[3]&&s[1]==s[2]&&s[0]!=s[1]){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
char x,y;
cin >> x >> y;
if(x>y) {
  cout << ">" << endl;
} else if(x<y) {
  cout << "<" << endl;
} else {
  cout << "=" <<endl;
}
return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i, j, k;
	char s[202][202];
	for (i = 0; i < n; i++)
		scanf("%s", s[i]);
	int ans = -1, v;
	int p;
	for (k = 0; k < n; k++)
	{
		int g[202];
		for (i = 0; i < n; i++)
			g[i] = -1;
		g[k] = 1;
		int q[10006], l = 0, r = 0;
		r++;
		q[0] = k;
			int m;
		while (l < r)
		{
			m = q[l];
			l++;
			for (i = 0; i < n; i++)
			{
				if (s[m][i] == '1' && g[i] < 0)
				{
					g[i] = g[m] + 1;
					q[r] = i;
					r++;
				}
			}
		}
		p = 0;
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				if (s[i][j] == '1')
					if (g[i] - g[j] != 1 && g[j] - g[i] != 1)
						p++;
		if (p == 0)
		{
			v = 0;
			for (i = 0; i < n; i++)
				if (v < g[i])
					v = g[i];
			if (ans < v)
				ans = v;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;

static class MainClass
{
    public static void Main(string[] args)
    {
        var n = Console.ReadLine().ToInt32();
        decimal sum = 0;
        for (int i = 0; i < n; i++)
        {
            var xu = Console.ReadLine().Split(' ');
            var num = decimal.Parse(xu[0]);
            if (xu[1] == "BTC")
            {
                sum += num * 380000;
            }
            else
            {
                sum += num;
            }
        }
        Console.WriteLine(sum);

        Console.ReadLine();
    }

    
    public static long Sums(IEnumerable<int> list)
    {
        var sum = 0l;
        foreach (var item in list)
        {
            sum += item;
        }
        return sum;
    }

    public static long f(long n,long b)
    {
        if (n < b)
        {
            return n;
        }
        else
        {
            return f((long)Math.Floor((double)n/b),b) + n % b;
        }
    }

    public static string N(long n,long b)
    {
        var sb = new StringBuilder();
        while (true)
        {
            sb.Append((n % b).ToString());
            n /= b;
            if (n < b)
            {
                sb.Append(n.ToString());
                break;
            }
        }
        return new string( sb.ToString().Reverse().ToArray() );
    }

    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<long> SplittedStringToInt64List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    public const int INF = int.MaxValue / 2;
    public const long LONGINF = long.MaxValue / 2;
    public const int Mod1e9 = 1000000007;
    



    public static void PrintArray(bool[,] array)
    {
        for (int i = 0; i < array.GetLength(0); i++)
        {
            var sb = new StringBuilder();
            for (int j = 0; j < array.GetLength(1); j++)
            {
                sb.Append(array[i, j]).Append(" ");
            }
            Console.WriteLine(sb.ToString());
        }
    }

    #endregion
}



Measured memory_bytes: 11092
import sys

input = sys.stdin.readline
n = int(input())
a_list = list(map(int, input().split()))

frame = 0
d = 1000
a_mean = sum(a_list)/n
for i in range(n):
    if abs(a_mean-a_list[i]) < d:
        frame = i
        d = abs(a_mean-a_list[i])
print(frame)


Measured memory_bytes: 3316
#include <iostream>

using namespace std;

bool s( int ord[], int const i, int const a = -1, int const b = -1 )
{
    if ( i >= 10 )
        return true;
    
    if ( ord[i] <= a && ord[i] <= b )
        return false;

    if ( ord[i] > a )
        return s( ord, i+1, ord[i], b );

    if ( ord[i] > b )
        return s( ord, i+1, a, ord[i] );

    return true;
}

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

    for( int iii=0; iii<n; ++iii ) {
        int ord[10];
        for( int i=0; i<10; ++i )
            cin >> ord[i];

        cout << ( s( ord, 0 ) ? "YES" : "NO" ) << endl;
    }
}

Measured memory_bytes: 1152
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Integer a[] = new Integer[3];
        a[0] = scan.nextInt();
        a[1] = scan.nextInt();
        a[2] = scan.nextInt();
        
        List<Integer> l = Arrays.asList(a);
        l.sort(null);
        System.out.println(l.get(0) + l.get(1));
    }
}


Measured memory_bytes: 21332
import copy

def bublesort(array, n):
    flag = 1
    while(flag):
        i=0
        flag=0
        for j in range(len(array)-1, i, -1):
            if array[j][1] < array[j-1][1]:
                array[j],array[j-1] = array[j-1],array[j]
                flag = 1
        i += 1

def selectionsort(array,n):
    for i in range(len(array)):
        minj = i
        for j in range(i,len(array)):
            if array[j][1] < array[minj][1]:
                minj = j
        array[minj],array[i] = array[i],array[minj]

factor = int(input())
numbers = input().split()
numbers_select = copy.deepcopy(numbers)


bublesort(numbers,factor)
selectionsort(numbers_select,factor)

print(" ".join(list(map(str, numbers))))
print("Stable")

print(" ".join(list(map(str, numbers_select))))
print("Stable") if numbers == numbers_select else print("Not stable")



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


class Main {

    public static void main(String[] args) throws IOException
    {
        PrintWriter out = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());
        HashMap<String , Integer> hm = new HashMap<>();
        for(int i = 0 ; i < n ; i++)
        {
            String ss = br.readLine();
            hm.put(ss , hm.getOrDefault(ss , 0)+1);
        }
        out.println("AC x " + hm.getOrDefault("AC" , 0) );
        out.println("WA x "  + hm.getOrDefault("WA" , 0));
        out.println("TLE x " + hm.getOrDefault("TLE" , 0) );
        out.println("RE x " + hm.getOrDefault("RE" , 0) );

        out.flush();
        out.close();

    }

    static class pair{
        long x1;
        long x2;

        public pair(long x1 , long x2)
        {
            this.x1 = x1;
            this.x2 = x2;
        }

    }

}


Measured memory_bytes: 44364
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;


// Driver code  
int main()
{
    int n, k;
    cin >> n >> k;
    int arr[1000];
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        arr[i] = a;
    }

    sort(arr, arr + n);

    for (int i = 0; i < k; i++) {
        ans += arr[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  string s,t,u;
  cin>>s>>t;
  cin>>a>>b;
  cin>>u;
  if(s.compare(u)==0)
  {
    cout<<a-1<<" "<<b;
    
  }
  else
  {
    cout<<a<<" "<<b-1;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define maxn 200005
#define max(a,b) (a)>(b)?(a):(b)
using namespace std;
char s[maxn];
int dp[maxn][2];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	dp[1][0]=dp[2][1]=1;
	for (int i=2;i<=n;i++){
		if (s[i]!=s[i-1]) dp[i][0]=dp[i-1][0]+1;
		if (i>2) dp[i][0]=max(dp[i-1][1]+1,dp[i][0]);
		if (i>3&&s[i]!=s[i-2]&&s[i-1]!=s[i-3]) dp[i][1]=dp[i-2][1]+1;
		if (i>2) dp[i][1]=max(dp[i-2][0]+1,dp[i][1]);
	}
	printf("%d\n",max(dp[n][1],dp[n][0]));
	return 0;
}

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

using ll = long long;

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

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

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

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

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int h1, m1, h2, m2, k;
    std::cin >> h1 >> m1 >> h2 >> m2 >> k;
    int a = h1*60+m1, b = h2*60+m2;
    b -= k;
    if (b <= 0) b += 24*60;
    std::cout << b-a << "\n";
}


Measured memory_bytes: 3652
N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)

ret = 0
monsters = A[0]
N.times do |i|
  if monsters > B[i]
    monsters = A[i + 1]
    ret += B[i]
    next
  end
    
  power = B[i] - monsters
  ret += monsters
  if A[i + 1] <= power
    monsters = 0
    ret += A[i + 1]
  else
    monsters = A[i + 1] - power
    ret += power
  end
end
puts ret


Measured memory_bytes: 15380
using ll=long long;using ull=unsigned long long;
#include<limits>
namespace pcl{template<typename T>constexpr T TNF=std::numeric_limits<T>::max()/2;constexpr int INF=TNF<int>;constexpr ll LNF=TNF<ll>;constexpr double DNF=TNF<double>;constexpr double EPS=1e-8;constexpr int P7=1'000'000'007;constexpr int DX[]={1,0,-1,0,1,1,-1,-1};constexpr int DY[]={0,1,0,-1,-1,1,1,-1};}
#include<algorithm>
#include<cmath>
#include<iostream>
namespace pcl{template<typename T>void updmax(T&a,T const&b){a=std::max(a,b);}template<typename T>void updmin(T&a,T const&b){a=std::min(a,b);}template<typename T,typename U,typename V>bool in_range(T const&begin,U const&mid,V const&end){return begin<=mid&&mid<end;}template<typename T,typename U,typename V>bool in_range(T const&begin,std::initializer_list<U>list,V const&end){auto p=std::minmax_element(list.begin(),list.end());return begin<=*p.first&&*p.second<end;}template<typename T,typename U,typename V>bool in_range_strict(T const&begin,std::initializer_list<U>list,V const&end){if(!std::is_sorted(list.begin(),list.end()))return false;return in_range(begin,list,end);}template<typename T>inline T cget(){T x;std::cin>>x;return x;}}
#include<iostream>
#include<vector>
namespace pcl{template<typename T>std::ostream&operator<<(std::ostream&os,std::vector<T>const&v){os<<'[';for(size_t i=0;i<v.size();i++){if(i!=0)os<<",";os<<v[i];}os<<']';return os;}template<typename T>std::istream&operator>>(std::istream&is,std::vector<T>&v){for(size_t i=0;i<v.size();i++)is>>v[i];return is;}}
#include<bits/stdc++.h>
using namespace std;using namespace pcl;int main(){int N,Q;string S;cin>>N>>Q>>S;vector<int>sum(N);for(int i=1;i<N;i++){if(S[i-1]=='A'&&S[i]=='C')sum[i]=1;}partial_sum(sum.begin(),sum.end(),sum.begin());for(int i=0;i<Q;i++){int l,r;cin>>l>>r;l--,r--;cout<<sum[r]-sum[l]<<endl;}}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int h,w,n;cin>>h>>w>>n;
	cout<<min((n+h-1)/h,(n+w-1)/w)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define pb push_back
#define ll long long
using namespace std;
const int N=2003;
struct line{ int k,b; ll f(int x){ return (ll)k*x+b; } }a[N];
int A[N][N];
void solve(int n){
    if (n==2){ A[1][1]=1; return; }
    solve(n>>1); A[n>>1][n>>1]=1;
    rep(i,1,(n>>1)-1)
        rep(j,1,(n>>1)-1)
            A[i+(n>>1)][j]=A[i][j+(n>>1)]=A[i+(n>>1)][j+(n>>1)]=A[i][j];
}
int main(){
    int n,m; scanf("%d%d",&n,&m);
    int t=1<<max(n,m); solve(t);
    rep(i,1,(1<<n)-1){
        rep(j,1,(1<<m)-1) printf("%d",A[i][j]);
        putchar('\n');
    }
    return 0;
}


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

using namespace std;
int main()
{
	int n,a;
	vector<int> array;
	cin>>n;
	
	for(int i=0;i<n;++i)
	{
		cin>>a;
		array.push_back(a);
		
	}
	
	int count=0,temp;
	for(int i=0;i<n;++i)
	{
		int min=i; 
		for(int j=i+1;j<n;++j)//用min指向最小值位置 
		{
		  if(array[j]<array[min])	
		  {
		  	min=j;
		  }
		}
		
		if(min!=i)
		{
		temp=array[i];
		array[i]=array[min];
		array[min]=temp;	
		count++;	
		}
		
	}
	
	
	for(int i=0;i<n;++i)
	{
	    if(i<n-1)
	    cout<<array[i]<<" ";
	    else
	    cout<<array[i]<<endl;
	}
	cout<<count<<endl;
	
	
	return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
ll lcm(ll a, ll b) {return (a*b)/__gcd(a, b); }



void solve()
{
    ll n, m;
    cin >> m >> n;
    ll a[n];
    rep(i, n) cin >> a[i];
    sort(a, a+n);
    ll b[n-1];
    rep(i, n-1) b[i] = a[i+1] - a[i];
    sort(b, b+n-1);
    ll ans = 0;
    for(ll i = 0 ;i < n-m; i++) ans += b[i];
    cout << ans;
}

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#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 fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






string S;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> S;

	int a = (S[0] - '0') * 10 + S[1] - '0';
	int b = (S[2] - '0') * 10 + S[3] - '0';

	bool YYMM = false;
	if (1 <= b and b <= 12) YYMM = true;
	bool MMYY = false;
	if (1 <= a and a <= 12) MMYY = true;

	if (YYMM and MMYY) cout << "AMBIGUOUS" << endl;
	else if (YYMM) cout << "YYMM" << endl;
	else if (MMYY) cout << "MMYY" << endl;
	else cout << "NA" << endl;
}

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

int main () {
	long long x;
	while (scanf("%lld",&x) != EOF) {
		if (x<=6) puts("1");
		else if (x%11==0) printf("%lld\n",2*(x/11));
		else if (x%11 <= 6) printf("%lld\n",(x/11)*2+1);
		else printf("%lld\n",(x/11)*2+2);
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define pb push_back
#define LN 30
#define P(x) (100+(x))//2^x
using namespace std;
vector<string> ans;
I void Pow(CI x,CI p)//a[8]=a[x]*(2^i) (a[x]=0/1)
{
	cout<<"+ 1000 "<<x<<" 8\n";for(int i=1;i<=p;++i) puts("+ 8 8 8");
}
I void Mul(CI x,CI y)//a[9]=a[x]*a[y] (a[x]=0/1)
{
	//15:a[y]+1 10:now_mul 11:new_mul 12:check 13:AND
	cout<<"+ 4 "<<y<<" 15\n",puts("+ 1000 1000 9"),puts("+ 1000 1000 10");
	for(RI i=LN;~i;--i) cout<<"+ 10 "<<P(i)<<" 11\n",puts("< 11 15 12"),
		Pow(12,i),puts("+ 10 8 10"),cout<<"+ "<<x<<" 12 13\n",puts("< 4 13 13"),Pow(13,i),puts("+ 9 8 9");
}
int main()
{
	//0:A 1:B 3:A+1 4:1 1000:0
	RI i;puts("37761"),puts("+ 0 1 4"),puts("< 1000 4 4"),puts("+ 0 4 3");
	for(puts("+ 4 100 100"),i=1;i<=LN;++i) cout<<"+ "<<P(i)-1<<" "<<P(i)-1<<" "<<P(i)<<endl;//Init 2^x
	//2:ans 5:now_mul 6:new_mul 7:check 8,9:tmp
	for(i=LN;~i;--i) cout<<"+ 5 "<<P(i)<<" 6\n",puts("< 6 3 7"),//Try now_mul+=2^i
		Pow(7,i),puts("+ 5 8 5"),Mul(7,1),Pow(9,i),puts("+ 2 8 2");//Update ans and now_mul
	return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define all(a) (a).begin(),(a).end()
#define X first
#define Y second
#define inf 1e18+5
using namespace std;
void solve()
{
  int n; cin>>n; int a[n];
  for(int i=0;i<n;i++)cin>>a[i];
  int dp[n][n],el[n][n];
  for(int i=0;i<n;i++)
  {
      for(int j=0;j+i<n;j++)
      {
          if(!i){dp[j][j]=0; el[j][j]=a[j]; continue;}
          dp[j][j+i]=inf;
          for(int k=j;k<j+i;k++)
          {
              if(dp[j][k]+dp[k+1][j+i]+el[j][k]+el[k+1][j+i]<dp[j][j+i])
              {
                  dp[j][j+i]=dp[j][k]+dp[k+1][j+i]+el[j][k]+el[k+1][j+i];
                  el[j][j+i]=el[j][k]+el[k+1][j+i];
              }
          }
      }
  }
  cout<<dp[0][n-1];
  return;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t; t=1;
    while(t--)solve();
    return 0;
}


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


int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i,1000) {
    string t;
    int x = i;
    rep(j,3) {
      t += '0'+x%10;
      x /= 10;
    }
    int ti = 0;
    rep(j,n) {
      if (s[j] == t[ti]) {
        ti++;
        if (ti == 3) break;
      }
    }
    if (ti == 3) ans++;
  }
  cout << ans << endl;

}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,k,n)       for(i=k;k<=n?i<=n:i>=n;k<=n?i++:i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define vpii            vector<pii>
#define vvi             vector<vi>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
#define inf             1e18
#define mod             1000000007
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}void _p() {cout << "]\n";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p,int m = inf) {int ans=1;x%=m;while(p>0){if(p&1)ans=(ans*x)%m;p=p>>1;x=(x*x)%m;}return ans;}
int inv(int x,int m=mod){return po(x,m-2,m)%m;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
//=========================================================




const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r;








void sol()
{   char a;
    cin>>a;
    if(a>='A' && a<='Z')cout<<'A';
    else cout<<'a';
    
    
    
    //cout<<  <<endl;
}





int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //sp(10);
    // w(t)
    sol();
    return 0;
}

Measured memory_bytes: 3640
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        int w = sc.nextInt();
        sc.close();
        if(s<=w){
            System.out.println("unsafe");

        }else{
            System.out.println("safe");
        }
    }
}

Measured memory_bytes: 35776