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

using namespace std;

int main(){

  int m,f,r;
  int sum=0;
  
  while(cin>>m>>f>>r){
    if((m==-1)&&(f==-1)&&(r==-1)){
      break;
    }
    
    sum=(m+f);
    
    if((m==-1)||(f==-1)){
      cout<<"F"<<endl;
    }

    else if(sum>=80){
      cout<<"A"<<endl;
    }
    
    else if((65<=sum)&&(sum<80)){
      cout<<"B"<<endl;
    }
    
    else if((50<=sum)&&(sum<65)){      
      cout<<"C"<<endl;
    }
    else if((30<=sum)&&(sum<50)){
      if(r>=50){
	cout<<"C"<<endl;
      }
      else {
      cout<<"D"<<endl;
      }
    }
    else if(sum<30){
      cout<<"F"<<endl;
    }
    

  }


  return 0;
}



Measured memory_bytes: 3088
#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; }
//------------------------------------------------------------------------------
template<typename T, int N, T F(const T& a, const T& b)>
struct SegTree
{
public:
    SegTree()
    {
        dat = vector<T>(N * 2 - 1, 0);
    }

    void update(int i, T x)
    {
        i += N - 1;
        dat[i] = x;
        while (i > 0)
        {
            i = (i - 1) / 2;
            dat[i] = F(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }

    T query(int a, int b, int k = 0, int l = 0, int r = N)
    {
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return dat[k];
        else
        {
            T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return F(vl, vr);
        }
    }

    vector<T> dat;
};

/*------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
------------------------------------------------------------------------------*/











//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int H, W, N;
    cin >> H >> W >> N;
    vector<int> a(N);
    rep(i, 0, N) cin >> a[i];
    int m[H][W];
    int color = 0;
    int colorNum = 0;
    rep(r, 0, H)
    {
        rep(c, 0, W)
        {
            m[r][r % 2 == 0 ? c : W - c - 1] = color + 1;
            ++colorNum;
            if (colorNum >= a[color])
            {
                ++color;
                colorNum = 0;
            }
        }
    }
    rep(r, 0, H)
    {
        rep(c, 0, W)
        {
            cout << m[r][c] << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>b){
        printf("a > b\n");
    }
    if(a<b){
        printf("a < b\n");
    }
    if(a==b){
        printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

vector<vector<P>> g;
vector<int> ans;

void dfs(int v, int p, int o){
    for(auto d : g[v]){
        if (d.first == p) continue;
        if (d.second % 2 != 0) o++;
        if (o % 2 == 0) ans[d.first] = 0;
        else ans[d.first] = 1;
        dfs(d.first, v, o);
        if (d.second %2 != 0) o--;
    }
}

int main(){
    int n;
    cin >> n;
    g.resize(n);
    ans.resize(n);
    rep(i,n-1){
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        g[u].push_back(make_pair(v, w));
        g[v].push_back(make_pair(u, w));
    }
    dfs(0, -1, 0);
    rep(i,n) cout << ans[i] << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define int ll

int32_t main(){
    FAST
    int n; cin >> n;
    int sum = 0;
    map<int, int> has;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        has[a]++;
        sum += a;
    }
    int q; cin >> q;
    while(q--){
        int a, b; cin >> a >> b;
        sum -= has[a]*a;
        sum += b*has[a];
        has[b] += has[a];
        has[a] = 0;
        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 9604
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<cmath>
using namespace std;
using Graph = vector<vector<int>>;
typedef unsigned long long ll;
ll mod = (10e+8)+ 7;

#define For(N,i) for(int i = 0; i < N; i++)


int main(){
	int N;
	cin>>N;
	int k = 0;
	for(int i = 1; i < 10; i++){
		for(int j = 0; j < 10; j++){
			if(N == i * j){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
}

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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};



#define pb push_back
#define F first
#define S second
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define gap ' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///

 int main()
 { ll l,r,d,i,coun=0;
 cin>>l>>r>>d;
 for(i=l;i<=r;i++)
 {
     if(i%d==0)coun++;
 }
 cout<<coun<<endl;





 return 0;


}


///Thanking you by Roxy






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

typedef long long ll;
#define mod 1000000007

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

void solve(){
    float n, x, t;
    cin>>n>>x>>t;
    cout<<(int)(ceil(n/x) * t);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    // pre();
    while (t--)
        solve();

    return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
using Graph = vector<vector<ll>>;
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);


int main(){
    ll a,b; cin >>a >>b;
    if(a >=10 || b >= 10) cout <<-1<<endl;
    else cout <<a*b<<endl;
}


Measured memory_bytes: 3672
#include<stdio.h>
  
int main(){
  
  int num,i,j,k,v;
  int A[1000];
  
  
  scanf("%d",&num);
  
  for(i=0;i<num;i++){
    scanf("%d",&A[i]);
  }
  
    for(i=0;i<num-1;i++){
      printf("%d ",A[i]);
    }
    printf("%d\n",A[i]);
  
  for(i = 1 ; i <= num-1 ; i++){
    v=A[i];
    j=i-1;
  
    while(j>=0 && A[j]>v){
  
      A[j+1]=A[j];
      j--;
    }
      A[j+1]=v;
      
  
    for(k=0;k<num-1;k++){
      printf("%d ",A[k]);
    }
    printf("%d\n",A[k]);
      
  }
  return 0;
}

Measured memory_bytes: 1852
N = int(input())

A = input().split(" ")
A = [int(n) for n in A]

ans = 0

for i in range(N): 
  if i == 0:
    max = A[i]
  elif i > 0 and max >A[i]:
    dif = max - A[i]
    ans += dif
  elif i > 0 and max < A[i]:
    max = A[i]

print(ans)

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

using namespace std;

using ll = long long;

int main() {
  int n;
  cin >> n;
  int ans = -1;
  for (int i = 1; i * (i + 1) <= 2 * n; ++i) {
    if (i * (i + 1) == 2 * n)
      ans = i + 1;
  }
  if (ans == -1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    cout << ans << endl;
    int k = 1;
    vector<vector<int>> v(ans);
    for (int i = 0; i < ans; ++i) {
      for (int j = i + 1; j < ans; ++j) {
        v[i].push_back(k);
        v[j].push_back(k);
        k++;
      }
    }
    for (int i = 0; i < ans; ++i) {
      cout << ans - 1 << " ";
      for (int j = 0; j < ans - 1; ++j) {
        cout << v[i][j];
        if (j < ans - 2) {
          cout << " ";
        }
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 2304
import java.util.Scanner;

public class Main {
  private static Scanner sc;

  public static void main(String[] args) {
    sc = new Scanner(System.in);
    new Main().solve();
  }


  private void solve() {
    int N = sc.nextInt();
    int num = 1;
    int ans = 0;
    while (num <= N) {
      int cnt = 0;
      for (int i = 1; i <= num; i += 2) {
        if (num % i == 0) cnt++;
      }
      if (cnt == 8) ans++;
      num++;
    }
    System.out.println(ans);
  }
}



Measured memory_bytes: 23252
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long
#define INF 10e9

using namespace std;
using P = pair<int, int>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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;
}

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

  bool check = false;

  rep(i, 9) {
    rep(j, 9) {
      if (N == i * j) {
        check = true;
        break;
      }
    }
  }

  if (check) {
    cout << "Yes" << "\n";
  } else {
    cout << "No\n";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int count=0;
  int B=b;
  while(B>0){
    B/=10;
    count++;
  }
  int ab=b+(a*pow(10,count));
  for(int i=1;i<1000;i++){
    if(pow(i,2)==ab){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3876
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int ans[100000]={};
    int rnum=0,lnum=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='R')
            rnum++;
        else{
            lnum++;
            if(i==s.size()-1||s[i+1]=='R'){
                ans[i-lnum]=(rnum+lnum)/2+(rnum%2&&!(lnum%2));
                ans[i-lnum+1]=(rnum+lnum)/2+(lnum%2&&!(rnum%2));
                rnum=0;
                lnum=0;
            }
        }
    }
    for(int i=0;i<s.size();i++)
        cout<<ans[i]<<(i+1==s.size()?'\n':' ');
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


int main(){
  int k;
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2] >> k;

  sort(ALL(a));
  cout << a[0]+a[1]+(a[2]<<k) << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
    char str[21];
    char ans[21];
    int len,i;
    scanf("%s",str);
    len=strlen(str);
    for(i=0;i<len;i++){
        ans[i]=str[len-1-i];
    }
    ans[len]='\0';

    printf("%s\n",ans);

    return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
  ll n;
  cin >> n;
  vector<ll> v(5,0);
  for(int i=0; i<n; i++){
    string s;
    cin >> s;
    if(s[0]=='M') v[0]++;
    if(s[0]=='A') v[1]++;
    if(s[0]=='R') v[2]++;
    if(s[0]=='C') v[3]++;
    if(s[0]=='H') v[4]++;
  }

  ll ans=0;
  for(int i=0; i<3; i++){
    for(int j=i+1; j<4; j++){
      for(int k=j+1; k<5; k++){
        ans+=v[i]*v[j]*v[k];
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define oset tree < int ,  null_type ,  less ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define endl '\n'
#define int long long int
#define db long double
#define str string
#define mod 1000000007
#define ff first
#define ss second
#define pqi priority_queue<int>
#define vi vector<int>
#define si set<int>
#define li list<int>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define For(i,s,n) for(int i=s;i<n;i++)
#define read(a) {for(auto &x:a)cin >> x;}
#define print(x) cout<<x<<endl
#define mat2D(T,r,c) vector<vector<int> > T(r,vector<int>(c))
#define vec2D vector<vector<int> >
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define debug(x) {for(auto i :x) cout << i << " ";cout << endl;}
#define debPair(x) {for(auto i :x) cout << i.ff << " " << i.ss << endl;}

map<int, vector<int>> adj;
// map<int, bool> visited;
bool ok = false;

void addEdge(int u, int v) {
	adj[u].push_back(v);
	adj[v].push_back(u);
}

void dfs(int src, bool visited[]) {
	// cout << src << ' ';
	ok = true;
	visited[src] = true;
	for (auto nbr : adj[src]) {
		if (!visited[nbr]) dfs(nbr, visited);
	}
}

void solve() {
	int n, m;
	cin >> n >> m;
	set<int> s;
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		addEdge(a, b);
	}
	bool visited[n + 1] = {false};
	int c = 0 ;
	// for (int i = 1; i <= n; i++) visited[i] = false;
	for (int i = 1; i <= n; ++i) {
		if (!visited[i]) dfs(i, visited);
		if (ok) ++c;
		ok = false;
		// cout << endl;
	}
	cout << c - 1;
}

int32_t main() {
	fastIO;
	/*
	int t;
	cin >> t;
	For(i, 1, t + 1) {
	  // cout << "Case " << i << ": ";
	  solve();
	}*/
	solve();
	return 0;
}

Measured memory_bytes: 17084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxn = 1e5 + 9;
#define BITS 60
ll n, a[maxn], cnt[BITS];

// Number of bits to 
// represent int 
#define INT_BITS 60 

// Function to return 
// maximum XOR subset 
// in set[] 
ll maxSubarrayXOR(ll set[], ll n) 
{ 
	// Initialize index of 
	// chosen elements 
	ll index = 0; 

	// Traverse through all 
	// bits of integer 
	// starting from the most 
	// significant bit (MSB) 
	for (int i = INT_BITS-1; i >= 0; i--) 
	{ 
		// Initialize index of 
		// maximum element and 
		// the maximum element 
		ll maxInd = index; 
		ll maxEle = INT_MIN; 
		for (int j = index; j < n; j++) 
		{ 
			// If i'th bit of set[j] 
			// is set and set[j] is 
			// greater than max so far. 
			if ( (set[j] & (1LL << i)) != 0 
					&& set[j] > maxEle) 
				maxEle = set[j], maxInd = j; 
		} 

		// If there was no 
		// element with i'th 
		// bit set, move to 
		// smaller i 
		if (maxEle == INT_MIN) 
		continue; 

		// Put maximum element 
		// with i'th bit set 
		// at index 'index' 
		swap(set[index], set[maxInd]); 

		// Update maxInd and 
		// increment index 
		maxInd = index; 

		// Do XOR of set[maxIndex] 
		// with all numbers having 
		// i'th bit as set. 
		for (int j=0; j<n; j++) 
		{ 
			// XOR set[maxInd] those 
			// numbers which have the 
			// i'th bit set 
			if (j != maxInd && 
			(set[j] & (1LL << i)) != 0) 
				set[j] = set[j] ^ set[maxInd]; 
		} 

		// Increment index of 
		// chosen elements 
		index++; 
	} 

	// Final result is 
	// XOR of all elements 
	ll res = 0; 
	for (int i = 0; i < n; i++) 
		res ^= set[i]; 
	return res; 
} 

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    cin >> n;
    rep(i, 0, n) {
        cin >> a[i];
        rep(j, 0, BITS)
            if ((a[i] >> j) & 1)
                cnt[j]++;
    }
    
    
    ll res = 0;
    rep (i, 0, BITS){
        if (cnt[i] & 1){
            res += (1LL << i);
            rep(j, 0, n){
                a[j] -= ((a[j] >> i) & 1)*(1LL << i);
                //cout << a[j] << ' ';
            }
            //cout << '\n'<< '\n';
        }
         
    }
    
    res += 2*maxSubarrayXOR(a, n);
    cout << res << '\n';
    
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int n,x,t;
    cin >> n >> x >> t;
    cout << (n+x-1)/x*t << endl;
}


Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <tuple>
using namespace std;
#define lli long long int

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x;
	int i;
	int n;
	int cnt = 0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>x;
		if(x!=i)
			cnt++;
	}
	if(cnt<=2)
		cout<<"YES\n";
	else
		cout<<"NO\n";
	return 0;
}

Measured memory_bytes: 256
code = """

# distutils: language=c++
# distutils: include_dirs=[/home/USERNAME/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl]
# cython: boundscheck=False
# cython: wraparound=False


cdef extern from "<atcoder/fenwicktree>" namespace "atcoder" nogil:
    cdef cppclass fenwick_tree[T]:
        fenwick_tree(int n)
        void add(int p, T x)
        T sum(int l, int r)

cdef class FenwickTree:
    cdef fenwick_tree[long long] *_thisptr
    def __cinit__(self, int n):
        self._thisptr = new fenwick_tree[long long](n)
    cpdef void add(self, int p, long long x):
        self._thisptr.add(p, x)
    cpdef long long sum(self, int l, int r):
        return self._thisptr.sum(l, r)
"""


import os, sys, getpass

if sys.argv[-1] == 'ONLINE_JUDGE':
    code.replace("USERNAME", getpass.getuser())
    open('atcoder.pyx','w').write(code)
    os.system('cythonize -i -3 -b atcoder.pyx')
    sys.exit(0)


from atcoder import FenwickTree

import sys

input = sys.stdin.buffer.readline
n, q = map(int, input().split())
bit = FenwickTree(n)
*map(bit.add, range(n), map(int, input().split())),
res = []
for i in range(q):
    t, u, v = map(int, input().split())
    if t: res.append(bit.sum(u, v))
    else: bit.add(u, v)
print('\n'.join(map(str, res)))

Measured memory_bytes: 50520
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int h, w;
    while(cin >> h >> w) {
        if (h == 0) break;
        rep(i, h) {
            rep(j, w) {
                if (i == 0 || i == h-1) cout << '#';
                else if (j == 0 || j == w-1) cout << '#';
                else cout << '.';
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


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

int main() {
	char X, Y;
	cin >> X >> Y;
	if (X > Y) {
		puts(">");
	}
	else if (X < Y) {
		puts("<");
	}
	else {
		puts("=");
	}
	return 0;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val n = sc.nextInt()
    val m = sc.nextLong()
    val a = Array.fill(n)(sc.nextLong()).sorted(Ordering.Long.reverse)

    val qe = new QE(n, m, a)

    println(qe.ans)
  }
}

class QE(n: Int, m: Long, a: Array[Long]) {
  private val r = Array.fill(n)(0L)
  r(0) = a.head
  for (i <- 1 until n) {
    r(i) = r(i - 1) + a(i)
  }

  def searchIndex(p: Long) = {
    if (p > a.head) {
      -1
    } else if (p <= a.last) {
      a.length - 1
    } else {
      var left = 0
      var right = a.length
      while (left < right) {
        val mid = (left + right) / 2
        if (a(mid) < p) {
          right = mid
        } else {
          left = mid + 1
        }
      }
      left - 1
    }
  }

  def numHandShake(p: Long) = {
    a.foldLeft(0L) { (acc, cur) =>
      acc + searchIndex(p - cur) + 1
    }
  }

  def search() = {
    var left = 0L
    var right = a.head * 2 + 1
    while (left + 1 < right) {
      val mid = (left + right) / 2
      if (numHandShake(mid) < m) {
        right = mid
      } else {
        left = mid
      }
    }
    left
  }

  def ans = {
    val p = search()
    val c = numHandShake(p)

    a.foldLeft((0L))((acc, cur) => {
      searchIndex(p - cur) match {
        case x if x >= 0 => acc + r(x) + cur * (x + 1)
        case _ => acc
      }
    }) - (c - m) * p
  }
}

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

int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    int counter = 0;
    int total = a[0] + a[1] + a[2];
    if((a[1]-a[0])%2==1){
        a[2]++;
        a[1]++;
        int temp = a[2] - a[1];
        temp += a[2] - a[0];
        counter = temp/2 + 1;
    }else{
        int temp = a[2] - a[1];
        temp += a[2] - a[0];
        counter = temp/2;
    }
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int state[100001];
int wa_count[100001];

int main() {
  int N, M, i, wa = 0, ac = 0;
  scanf("%d %d", &N, &M);
  for (i = 0; i < M; i++) {
    int pi;
    char Si[20];
    scanf ("%d %s", &pi, Si);
    switch (Si[0]) {
    case 'A': state[pi]++; break;
    case 'W': if (state[pi] == 0) { wa_count[pi]++; } break;
    }
  }

  for (i = 1; i <= N; i++) {
    if (state[i]) { ac++; wa += wa_count[i]; }
  }
  printf("%d %d\n", ac, wa);
}



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

int main(){
	int n;
	int sum=0;
	std::vector<int> aList;
	std::cin>>n;

	aList.resize(n);
	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	std::sort(aList.begin(), aList.end(),[](int x, int y){return x>y;});

	for(int i=1; i<n; i++)
		sum+= aList[i];

	if(aList[0]>= sum)
		std::cout<<"No"<<std::endl;
	else
		std::cout<<"Yes"<<std::endl;

	return 0;
}

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

AC_n = 0
WA_n = 0
TLE_n = 0
RE_n = 0

for i in range(N):
    ans = input()
    if (ans == "AC"):
        AC_n += 1
    elif(ans == "WA"):
        WA_n += 1
    elif(ans == "TLE"):
        TLE_n += 1
    elif(ans == "RE"):
        RE_n += 1

print(f'AC x {AC_n}')
print(f'WA x {WA_n}')
print(f'TLE x {TLE_n}')
print(f'RE x {RE_n}')


Measured memory_bytes: 69896
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define mod 1000000007
#define FOR(i,m,n) for(int i = (m); i < (n); i++)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(),v.end()
#define sz(v) int(v.size())
 
 
typedef long long ll;
typedef vector<int> vi; 
typedef pair<int,int> ii;

const int N=1e5+9;




int main(){
	
	fastio; 
	
	int n, k, x; cin>>n>>k;
	int pos=-1;
	vector<ll> v, d(n), ac1(n), ac2(n);
	bool p=1;
	FOR(i,0,n){
		cin>>x;
		if(x==0) p=0, k--, pos=i;
		if(x>0 && p) v.pb(0), pos=i, p=0;
		v.pb(x);
		if(p && x<0 && i==n-1) v.pb(0), pos=i+1, p=0;
	}
	ll ans=1e15;
	
	FOR(r,pos,pos+k+1){
		if(r>=k && r<sz(v)){
			ans=min(ans, 2*abs(v[r])+abs(v[r-k]));
			ans=min(ans, abs(v[r])+2*abs(v[r-k]));
		}
	}
	
	//FOR(i,0,sz(v)) cout<<v[i]<<" ";
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 6608
import sys
input = sys.stdin.readline
# import math
# sqrt = math.sqrt

# def int_sqrt2(n):
#     def f(prev):
#         while True:
#             m = (prev + n / prev) / 2
#             if m >= prev:
#                 return prev
#             prev = m
    
#     return f(int(sqrt(n) * (1 + 1e-20)))

# from decimal import *

# getcontext().prec = 20      # デフォルト28桁のところを20桁にする
# m = int(Decimal(n).sqrt())
# print m ** 2 - n            # -2222221948

def linput():
    return list(map(int, input().split()))

def gcd(n,m):
    while m:
        n,m = m, n%m
    return n

def lcm(n,m):
    return n*m//gcd(n,m)


def main():
    # N = int(input())
    A,B,C = linput()
    # vA = linput()
    # S = input()
    # mX = [linput() for _ in [0,]*N]

    # res = 0
    # res = -(-N//M)

    # LH = A**.5 + B**.5
    # RH = C**.5

    # rtAB = int(Decimal(A*B).sqrt())
    # rtAB = int_sqrt2(A*B)

    LH = A * B * 4
    RH = (C-A-B)**2

    # LH = A * B * 4
    # RH = abs(C-A-B)
    print(LH,RH, file=sys.stderr)

    res = ("No","Yes")[LH < RH if C-A-B>=0 else 0]

    print(res)

main()


Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int KK =1;
    for (int i=1; i<=N-1; i++) KK *= K-1;
    System.out.println(K * KK);
  }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#define ll long long int
#define FOR(i,a,b) for(ll (i)=(a);i<(ll)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,n)
#define outi(a) printf("%lld\n",(a))
using namespace std;
inline ll sc ()
{
    ll x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
    return x;
}
map<ll, ll>memo;
int main()
{
  //freopen("input.txt", "r", stdin);
  ll a = sc();
  ll sum = 0;
  for(int i = 1; i <= a;i++)
  {
    for(int j = 1; j <= a; j++)
    {
      for(int k = 1; k <= a; k++)
      {
        sum += __gcd(__gcd(i, k), j);
      }
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <ctype.h>

int main(){
    int count[26]={0};
    char ch;
    int i, num;

    while(scanf("%c", &ch)!=EOF){
        if(islower(ch)){
            num=ch-'a';
        }else if(isupper(ch)){
            num=ch-'A';
        }else{
            continue;
        }
        count[num]++;
    }
    for(i=0;i<26;i++){
        printf("%c : %d\n", 'a'+i, count[i]);
    }

    return 0;
}


Measured memory_bytes: 2064
#include <bits/stdc++.h>
 
using namespace std;
 
int gcd(int a, int b)
{
	if (a == 0)
		return b;
	return gcd(b % a, a);
}
 
int main() {
	int k;
	cin >> k;
    long long sum = 0;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
            long long f = gcd(i, j);
			for (int c = 1; c <= k; c++) {
				long long temp = gcd(f, c);
                sum += temp;
			}
		}
	}
    cout << sum;
}

Measured memory_bytes: 3596
import numpy as np

H, W, K = map(int,input().split())
D = np.zeros([H,W])

black_count = 0
for i in range(H):
    C = list(input())
    for j in range(len(C)):
        if(C[j] == "#"):
            D[i][j] = 1


#print(D)
for i in range(2**H):
    h = format(i, '06b')
    for j in range(2**W):
        w = format(j, '06b')
        d = D.copy()

        for hi in range(H):
            if(h[5-hi] == '1'):
                d[hi,:]=0
        for wi in range(W):
            if(w[5-wi] == '1'):
                d[:,wi]=0
            
        if (d.sum() == K):
            black_count += 1

print(black_count)

Measured memory_bytes: 27188
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

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

    int n; cin >> n;
    vector<int> ans(100001);

    for(int x = 1;x < 101;x ++){
        for(int y = 1;y < 101;y ++){
            for(int z = 1;z < 101;z ++){
                ans.at(x*x+y*y+z*z+x*y+y*z+z*x) ++;
            }
        }
    }

    for(int i = 1;i < n+1;i ++) cout << ans.at(i) << endl;
}

Measured memory_bytes: 3896
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N, K := nextInt(), nextInt()
	snuke := make([]int, N)
	for i := 0; i < K; i++ {
		d := nextInt()
		for i := 0; i < d; i++ {
			snuke[nextInt()-1]++
		}
	}
	var ans int
	for _, a := range snuke {
		if a == 0 {
			ans++
		}
	}
	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

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


Measured memory_bytes: 1848
import heapq
N, M, init_silver = map(int, input().split())
MAX_COST = 2500
init_silver = min(init_silver, MAX_COST)

G = [[] for _ in range(N)]
for i in range(M):
    u, v, silver_cost, time_cost = map(int, input().split())
    u, v = u - 1, v - 1
    G[u].append([v, silver_cost, time_cost])
    G[v].append([u, silver_cost, time_cost])

change_rate, change_cost = [], []
for i in range(N):
    rate, cost = map(int, input().split())
    change_rate.append(rate)
    change_cost.append(cost)


# dp[i][silver] := 頂点iにいて銀貨をsilver枚持っているような状況を作るために必要な最小時間
dp = [[float('inf')] * (MAX_COST + 1) for _ in range(N)]
dp[0][init_silver] = 0

# 優先度付きキュー: (time, node, silver)
hq = [(0, 0, init_silver)]
while hq:
    time, node, silver = heapq.heappop(hq)

    self_loop_silver = min(silver + change_rate[node], MAX_COST)
    self_loop_cost = time + change_cost[node]
    if self_loop_cost < dp[node][self_loop_silver]:
        dp[node][self_loop_silver] = self_loop_cost
        heapq.heappush(hq, (time + change_cost[node], node, self_loop_silver))

    for to, silver_cost, time_cost in G[node]:
        remain_silver = min(silver - silver_cost, MAX_COST)
        if remain_silver < 0:
            continue

        dp_next_value = time + time_cost
        if dp[to][remain_silver] <= dp_next_value:
            continue

        dp[to][remain_silver] = dp_next_value
        heapq.heappush(hq, (dp_next_value, to, remain_silver))

print(*[min(d) for d in dp[1:]], sep="\n")


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

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

	int g_cnt = 0, ans = 0;

	for (int i = 0; i < s.size(); ++i)
	{
		if (s[i] == 'g' && g_cnt > 0)
		{
			--g_cnt;
			++ans;
		}

		else if (s[i] == 'g' && g_cnt == 0)
		{
			++g_cnt;
		}

		else if (s[i] == 'p' && g_cnt > 0)
		{
			--g_cnt;
		}

		else if (s[i] == 'p' && g_cnt == 0)
		{
			++g_cnt;
			--ans;
		}
	}

	std::cout << ans << std::endl;

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main() {
  int a, b, c;
  int tmp = 0;
  cin >> a >> b >> c;
  if(a > b){
    tmp = a;
    a = b;
    b = tmp;
}
if(b > c){
  tmp = b;
  b = c;
  c = tmp;
}
if(a > c){
  tmp = a;
  a = c;
  c = tmp;
}
if(a > b){
  tmp = a;
  a = b;
  b = tmp;
}
cout << a << ' ' << b << ' ' << c << endl;
  return 0;
}

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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
#define P pair<int, int>
struct data{
	int place;
	int cost;

	bool operator<(const data &ri) const{
		return cost < ri.cost;
	}
	bool operator>(const data &ri) const{
		return cost > ri.cost;
	}
};
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};



int main(){
	int n;
	int a[100];
	double ave = 0.0;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		ave += a[i];
	}
	ave /= 1.0 * n;
	int index = -1;
	double dis = 99999;
	for(int i = 0; i < n; i++){
		if(abs(ave - a[i]) < dis){
			dis = abs(ave - a[i]);
			index = i;
		}
	}

	cout << index << endl;

	return 0;
}

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

using namespace std;

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i =0;i<t;i++)
#define bs(a,x) binary_search(a.begin(),a.end(),x)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int,int> 
#define umpl unordered_map<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mod 1000000007 
#define N 10000000
#define all(a) a.begin(),a.end()
#define point pair<int,int>
const int inf = 1000000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM =1000005;

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll min(ll a, ll b){return a<b?a:b;}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};


int main()
{
    fio;
    ll n;cin>>n;
    vector<ld> p(n);
    f(n)cin>>p[i];
    vector<ld> dp(n+1);
    //dp[i] will store the probability of i heads so far
    dp[0]=1;
    for(ll numberofcoins=0;numberofcoins<n;numberofcoins++)
    {
        for(ll i=numberofcoins+1;i>=0;i--)
        {
            dp[i]=(i==0?0:p[numberofcoins]*dp[i-1])+(1-p[numberofcoins])*dp[i];
        }
    }
    ld ans=0;
    for(ll numberofheads=0;numberofheads<=n;numberofheads++)
    {
        ll numberoftails=n-numberofheads;
        if(numberofheads>numberoftails)
        {
            ans+=dp[numberofheads];
        }
    }
    cout<<setprecision(10)<<ans<<"\n";
}




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

int main(){
  string c1, c2;
  cin >> c1 >> c2;
  
  string ans ="NO";
  
  if(c1[0] == c2[2] && c1[2] == c2[0] && c1[1] == c2[1]){
    ans = "YES";
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#pragma GCC optimize("O3", "unroll-loops")
#include <bits/stdc++.h>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a, b) << ' ' << max(0, a + b - n) << '\n';
	return 0;
}

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

using namespace std;
int main(){
    string s;
    string t;
    cin>>s;
    cin>>t;
    int a;
    int b;
    cin>>a;
    cin>>b;
    string u;
    cin>>u;
    if(u==s){
        a--;
    }else{
        b--;
    }
    cout<<to_string(a)+" "+to_string(b);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))


int main() {

  int N,M;
  cin >> N;
  cin >> M;

  if(N>=M){
    cout << 0 <<endl;
    return 0;
  }

  vector<int> X(M);
  vector<int> adj(M-1);

  for( int i =0; i<M;i++){
    cin >> X[i];
  }
  
  sort(X.begin(),X.end());
  for( int i =0; i<M-1;i++){
    adj[i]=X[i+1]-X[i];
  }

  sort(adj.begin(),adj.end());
  
  int sum;
  sum=X[M-1]-X[0];

  for( int i =0; i<N-1;i++){
    sum -= adj.back();
    adj.pop_back();
  }
  
  cout <<sum<<endl;
  return 0;
  
   
}


Measured memory_bytes: 1024
n = int(input())
x = list(map(int, input().split()))
x.sort()


for i in range(x[0], x[n-1]+1):
    cnt = 0
    for j in range(n):
        cnt += (x[j] - i)**2
    if i == x[0]:
        ans = cnt
    ans = min(ans, cnt)

print(ans)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  string s,t;
  cin>>s;
  cin>>t;
  
  REP(i,s.size()){
    REP(j,s.size()){
      if(s[(i+j)%s.size()]==t[j]){
        if(j==s.size()-1){
          cout<<"Yes"<<endl;
          return 0;
        }
        continue;
      }else{
        break;
      }
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <time.h>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

const int N = 55;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int n;
string s1,s2;
int z = -1;

int main(){
    cin>>n>>s1>>s2;
    long long answ = 1ll;
    for(int i=0;i<n;i++){
        if(i == 0){
            if(s1[i] == s2[i]){
                answ *= 3ll;
                answ %= mod;
                z = 0;
            }
            else{
                answ *= 6ll;
                answ %= mod;
                z = 1;
                i++;
            }
        }
        else{
            if(z == 0){
                answ *= 2ll;
                answ %= mod;
                if(s1[i] == s2[i])
                    z = 0;
                else{
                    z = 1;
                    i++;
                }
            }
            else{
                if(s1[i] == s2[i])
                    z = 0;
                else{
                    z = 1;
                    i++;
                    answ *= 3ll;
                    answ %= mod;
                }
            }
        }
    }
    cout<<answ<<endl;
    return 0;
}



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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  cout << N / 3 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iostream>
#include<string>
#include<sstream>
#include<set>
#include<map>
#include<vector>
#include<algorithm>
#include<queue>
#include<utility>
using namespace std;

#define i64 long long int
int M;

int la;
struct pnt {
	int x, y;
	pnt() {}
	pnt(int _x, int _y) { x = _x; y = _y; }
} a[303 * 303];
int mp[606][606];
void st() {
	memset(mp, -1, sizeof(mp));
	for (int i = 0; i < la; i++)
		mp[a[i].x][a[i].y] = i;
}
bool exis(int x,int y) {
	if (x < 0 || x > M || y < 0 || y > M)return false;
	return mp[x][y] != -1;
}

int sum[606][606];
int Sum(int x, int y1, int y2) {
	if (y2 > M)y2 = M;
	if (y1 <= 0)return sum[x][y2];
	return sum[x][y2] - sum[x][y1 - 1];
}

int main() {
	int row, col; char s[999];
	scanf("%d%d", &row, &col);
//	row = col = 300;
	for (int i = 0; i < row; i++){
		scanf("%s", s);
		for (int j = 0; j < col; j++) {
			if (s[j] == '#') {
				a[la++] = pnt(i + j, i + col - 1 - j);
			}
		}
	}
	M = row - 1 + col - 1;
	i64 res = 0;
	for (int run = 0; run < 2; run++) {
		st();
		for (int k = 1; k <= M; k++) {
			for (int i = 0; i <= M; i++) {
				for (int j = 0; j <= M; j++) {
					sum[i][j] = j == 0 ? 0 : sum[i][j - 1];
					if (exis(i, j) && exis(i, j + k))sum[i][j] ++;
				}
			}
			for (int i = 0; i < la; i++) {
				int X = a[i].x - k;
				if (X >= 0) {
					res += Sum(X, a[i].y - k, a[i].y);
				}
				X = a[i].x + k;
				if (X <= M) {
					res += Sum(X, a[i].y - k, a[i].y);
				}
			}
		}
		for (int i = 0; i < la; i++)swap(a[i].x, a[i].y);
	}
	st();
	for (int i = 0; i < la; i++) {
		for (int k = 1; k <= M; k++) {
			int A = 0, B = 0;
			if (exis(a[i].x + k, a[i].y))A++;
			if (exis(a[i].x - k, a[i].y))A++;
			if (exis(a[i].x, a[i].y + k))B++;
			if (exis(a[i].x, a[i].y - k))B++;
			res -= A * B;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3840
def keta(n):
    cnt=1
    while(n//10!=0):
        n=n//10
        cnt+=1
    return cnt

def main():
    n=int(input())
    ans=n
    r=n**0.5
    r=int(r)
    r+=1
    for i in range(r):
        i+=1
        if(n%i==0):
            ans=min(max(keta(i),keta(n//i)),ans)
    print(ans)
    
main()    



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int x,y,z;

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  for(int i=0;i<n;i++){
    int p;
    cin>>p;
    if(p<=a)x++;
    else if(p>b)z++;
    else y++;
  }
  cout<<min(x,min(y,z))<<endl;
  return(0);
}


Measured memory_bytes: 256
p = [[0 for i in range(14)] for j in range(14)]
while True:
    try:
        x_inp, y_inp, s = map(int, input().split(","))
        x = x_inp + 2
        y = y_inp + 2
        if s == 1:
            p[y-1][x] = p[y-1][x] + 1
            p[y][x-1] = p[y][x-1] + 1
            p[y][x]   = p[y][x]   + 1
            p[y][x+1] = p[y][x+1] + 1
            p[y+1][x] = p[y+1][x] + 1
        elif s == 2:
            p[y-1][x-1] = p[y-1][x-1] + 1
            p[y-1][x]   = p[y-1][x]   + 1
            p[y-1][x+1] = p[y-1][x+1] + 1
            p[y][x-1]   = p[y][x-1]   + 1
            p[y][x]     = p[y][x]     + 1
            p[y][x+1]   = p[y][x+1]   + 1
            p[y+1][x-1] = p[y+1][x-1] + 1
            p[y+1][x]   = p[y+1][x]   + 1
            p[y+1][x+1] = p[y+1][x+1] + 1
        else:
            p[y-2][x] += 1
            p[y-1][x-1] = p[y-1][x-1] + 1
            p[y-1][x]   = p[y-1][x]   + 1
            p[y-1][x+1] = p[y-1][x+1] + 1
            p[y][x-2]   = p[y][x-2]   + 1
            p[y][x-1]   = p[y][x-1]   + 1
            p[y][x]     = p[y][x]     + 1
            p[y][x+1]   = p[y][x+1]   + 1
            p[y][x+2]   = p[y][x+2]   + 1
            p[y+1][x-1] = p[y+1][x-1] + 1
            p[y+1][x]   = p[y+1][x]   + 1
            p[y+1][x+1] = p[y+1][x+1] + 1
            p[y+2][x] += 1
    except:
        break
p_trim = [p[i][2:12] for i in range(2,12)]
p_flatten = sum(p_trim,[])
print(sum(x==0 for x in p_flatten))
print(max(p_flatten))



Measured memory_bytes: 5640
def resolve():
    n = int(input())
    r = [int(input()) for _ in range(n)]

    maxv = -1000000000
    minv = r[0]

    for i in range(1,n):
        maxv = max(maxv, r[i] - minv)
        minv = min(minv, r[i])

    print(maxv)
resolve()


Measured memory_bytes: 13596
sub f{map{push@$_,$_[--$|]for@_=glob}<>;$Y[$_]=++$d;$Y[$_]||&f for@$_;--$d}@X=@Y,f@Y=()for(glob<>)[1,2];$X[$j++]<$_&&\$@[$_]for@Y;print@@-3

Measured memory_bytes: 161152
#include <stdio.h>
int main() {
	int n, c, r = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		c = 0;
		if (i % 2 == 0)continue;
		for (int j = 1; j <= i; j++)if (i % j == 0)c++;
		if (c == 8)r++;
	}
	printf("%d", r);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#define N 100
#define INF (1<<21)
#define QSIZE 100005

int queue[QSIZE];
int head=0,tail=0;
int n,M[N][N];
int d[N];

void enqueue(int y)
{
int next=(tail+1)%QSIZE;
if(next==head){
  printf("Queue overflow\n");
  exit(2);
}
queue[tail]=y;
tail=next;
}

int dequeue(void)
{
  int x;
  if(head ==tail){
    printf("Queue is empty\n");
    exit(3);
  }
  x=queue[head];
  head=(head+1)%QSIZE;
  return x;
}



void bfs(int s)
{
  int i,u,v;

  enqueue(s);
  for(i=0;i<n;i++){
    d[i]=INF;
  }
  d[s]=0;
  while(head !=tail){
    u=queue[head];
    dequeue();
    for(v=0;v<n;v++){
      if(M[u][v]==0) continue;
      if(d[v]!=INF) continue;
      d[v]=d[u]+1;
      enqueue(v);
    }
  }
for(i=0;i<n;i++){
  printf("%d %d\n",i+1,((d[i]==INF)?(-1):d[i]));
}
}

int main(){
  int i,j,u,k,v;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  bfs(0);

  return 0;
}


Measured memory_bytes: 2000