akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pair < pii, int > a, pair < pii, int > b)//true for a before b
{
	if(a.F.F/900 < b.F.F/900)
		return 1;
	if(a.F.F/900 > b.F.F/900)
		return 0;
	if(a.F.S <= b.F.S)
		return 1;
	return 0;
}

const int N = (1e2) + 9;
const int M = (1e3) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 8000;

int p[N], c[N], val[N][N], dp[M], dp2[M];

void solve()
{
	int n, i, ans, x, j, m = 0, k;
	cin >> n >> x;
	fo(i,1,n+1)
	{
		cin >> p[i] >> c[i];
		m += p[i];
	}
	fo(i,1,n+1)
	{
		fo(j,1,p[i]+1)
			val[i][j] = 100*i*j;
		val[i][p[i]] += c[i];
	}
	fo(i,0,m+1)
		dp[i] = -INF;
	dp[0] = 0;
	fo(i,1,n+1)
	{
		fo(k,0,m+1)
			dp2[k] = -INF;
		fo(j,1,p[i]+1)
			for(k = m-j; k >= 0; k--)
				dp2[k+j] = max(dp2[k+j], dp[k] + val[i][j]);
		fo(k,0,m+1)
			dp[k] = max(dp[k], dp2[k]);
	}
	fo(i,0,m+1)
		if(dp[i] >= x)
		{
			cout << i << '\n';
			return;
		}
	return;
}

int main()
{
	sws;
	// clock_t clk;
	// clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	// cout << fixed << setprecision(6);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	// clk = clock() - clk;
	// cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define pb push_back
#define REP(i,m,n) for (int i=m;i<n;i++)
#define FOR(i,m,n,a) for(int i=m;i<n;i+=a)
const ll MOD=1e9+7;


vvl graph;
int ct=0;

bool check(vl visit){
  REP(i,0,visit.size()){
    if(visit[i]==0){
      return false;
    }
  }
  return true;
}

void dfs(int n,vl visit){
  visit[n]=1;
  REP(i,0,graph[n].size()){
    if(visit[graph[n][i]]==0){
      dfs(graph[n][i],visit);
    }
  }

  if(check(visit)) ct++;
}

int main(){
  int N,M;
  cin >> N >> M;
  graph = vvl(N);

  int a,b;
  REP(i,0,M){
    cin >> a >> b;
    graph[a-1].pb(b-1);
    graph[b-1].pb(a-1);
  }

  vl visit(N,0);
  dfs(0,visit);

  cout << ct << endl;

  return 0;
}


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

int main() {
    char a[8];
    while(scanf("%s", a)!=EOF) {
        int foo=0;
        for(int i=0; a[i]; i++) {
            foo+=(a[i]=='1');
        }
        printf("%d\n", foo);
    }
}

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

using namespace std;

typedef long long ll;

const int maxn = 210000;

char str[maxn];
int suf[maxn];
int ct[maxn];

int main(int argc, const char * argv[]) {
    int n, p;
    cin >> n >> p;
    cin >> (str + 1);
    if (p == 2 || p == 5){
        ll ans = 0;
        for (int i = 1;i <= n;i++){
            if ((str[i] - '0') % p == 0) ans += i;
        }
        cout << ans << endl;
        return 0;
    }
    else{
        int cur = 1;
        ll ans = 0;
        ct[0]++;
        for (int i = n;i >= 1;i--){
            suf[i] = suf[i+1] + cur * (str[i] - '0');
            suf[i] %= p;
            cur = cur * 10 % p;
            ans += ct[suf[i]];
            ct[suf[i]]++;
        }
        cout << ans << endl;
    
    }
    return 0;
}


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

long long nCr(int n, int r) {
  unsigned long long ans=1;
  for (int i=1; i<=r; i++) {
    ans *= n--;
    ans /= i;
  }

  return ans;
}

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

  vector<int> a;
  int cnt_odd = 0, cnt_even = 0;
  for (int i=0; i<n; i++) {
    int tmp;
    cin >> tmp;
    if (tmp%2==0) {
      cnt_even++;
    } else {
      cnt_odd++;
    }
    a.push_back(tmp);
  }

  if (p==1 && cnt_odd==0) {
    cout << 0 << endl;
    return 0;
  }

  unsigned long long ans = 0;
  unsigned long long comb = 1;
  for (int i=0; i<cnt_even; i++) {
    comb*=2;
  }
  if (p==0) {
    for (int i=0; i<=cnt_odd; i+=2) {
      ans += nCr(cnt_odd, i);
    }
  }

  if (p==1) {
    for (int i=1; i<=cnt_odd; i+=2) {
      ans += nCr(cnt_odd, i);
    }
  }

  ans *= comb;
  cout << ans << endl;

  return 0;
}


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

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

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

    ll n;
    cin >> n;
    vector<string> s(n);
    for (ll i = 0;i < n;i++){
        cin >> s[i];
    }

    vector<vector<ll>> x(n, vector<ll>(26));
    for (ll i = 0; i < n; i++){
        ll m = s[i].size();
        for (ll j = 0; j < m; j++){
            x[i][s[i][j] - 'a']++;
        }
    }

    for (ll i = 0; i < 26; i++){
        ll c = x[0][i];
        for (ll j = 0; j < n; j++){
            c = min(c,x[j][i]);
        }
        char w = 'a' + i;
        for (ll k = 0; k < c; k++){
            cout << w;
        }
    }
    cout << endl;
}

Measured memory_bytes: 3668
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double EPS = 1e-10;

ll dfs(const string& S, int n, vector<bool>& v) {
  // ベースケース
  if (n == v.size()) {
    ll sum = 0;
    int l = 0;
    rep(i, v.size()) {
      if (v[i]) {
        string s = S.substr(l, i - l + 1);
        l += i - l + 1;
        ll x = stoll(s);
        sum += x;
      }
    }
    string t = S.substr(l);
    ll y = stoll(t);
    sum += y;
    return sum;
  }

  // 再帰ステップ
  ll ans = 0;
  v[n] = true;
  ans += dfs(S, n + 1, v);
  v[n] = false;
  ans += dfs(S, n + 1, v);

  return ans;
}


int main(void) {
  string S;
  cin >> S;

  // +を差し込むか否かの配列
  vector<bool> v(S.length() - 1, false);
  ll ans = dfs(S, 0, v);

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

Measured memory_bytes: 3612
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
typedef long long ll;

using namespace std;

int main(){
	ll a,b,c;
	cin>>a>>b>>c;
	if(a%2==1 or b%2==1 or c%2==1){
		cout<<0;
	}
	else{
		ll d[3];
		int i=0;
		if(a==b and b==c){
			cout<<-1;
		}
		else{
		while(a%2==0 and b%2==0 and c%2==0){
			d[0]=(b+c)/2;
			d[1]=(a+c)/2;
			d[2]=(a+b)/2;
			a=d[0];
			b=d[1];
			c=d[2];
			i++;
		}
		cout<<i;
	}
}
}



Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
//---------------------------------------------------------------------------//

int main(){
        int n,y,k,b;
        cin>>n>>y>>k>>b;
        int s=0;
        for(int i=1; i<=y && i<=n; i++) {
                s+=k;
        }
        for(int i=y+1; i<=n; i++) {
                s+=b;
        }
        cout<<s<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))
#define LLONG_MAX numeric_limits<long long>::max()
#define INT_MAX numeric_limits<int>::max()

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

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

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}


template <typename T>
void vecOutPadding(vector<T>& vec, string pad = " ") {
	for (const T& elem : vec)
		cout << elem << pad;
}

template <typename T>
void matOut(vector<vector<T>>& mat) {
	for (const auto& row : mat) {
		for (const T& col : row)
			cout << col << " ";
		cout << endl;
	}
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


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

	int ans = 0;
	for (auto n : N) {
		ans += int(n - '0');
	}

	if (ans < 2) ans *= 10;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
def isRightTriangle(lineList):
    if lineList[0]**2 + lineList[1]**2 == lineList[2]**2:
        return True
    else:
        return False
if __name__ == '__main__':
    n = (int)(input())
    for _ in range(0,n):
        tmp = list(map(int,input().split()))
        tmp.sort()
        print("YES" if isRightTriangle(tmp) else "NO")
        

Measured memory_bytes: 7684
n = int(input())
p = list(map(int,input().split()))
a = 0
for i in range(1,n-1):
  if p[i] > p[i-1] and p[i]<p[i+1]:
    a += 1
  elif p[i] < p[i-1] and p[i] > p[i+1]:
    a += 1
print(a)

Measured memory_bytes: 9152
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
int gcd(int a, int b) {
	return b ? gcd(b, a%b) : a;
}
int main() {
	int N;
	cin >> N;
	int g = 0;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		g = gcd(g, A);
	}
	cout << g << endl;

}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if (e-a > k){
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n,a,b;
    cin >> n >> a >> b;
    vector<int>va,vb,vc;
    rep(i,n){
        int t; cin >> t;
        if(t <= a) va.push_back(t);
        else if(t <= b)vb.push_back(t);
        else vc.push_back(t);
    }
    int ans = 0;
    sort(all(va));
    sort(all(vb));
    sort(all(vc));
    int ib = 0,ic = 0;
    rep(i,va.size()){
        if(ib >= vb.size()  or ic >= vc.size())break;
        if(va[i] < vb[ib] and vb[ib] < vc[ic]){
            ++ans; ib++;ic++;
        } else break;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
r,g,b,n = gets.split.map(&:to_i)
ans = 0
rr = n/r
gg = n/g
bb = n/b
(0..rr).each do |rrr|
  (0..gg).each do |ggg|
    next if rrr * r + ggg * g > n
    if (n - (rrr * r + ggg * g)) / b <= bb && (n - (rrr * r + ggg * g)) % b == 0
      # puts "#{rrr} #{ggg}"
      ans += 1
    end
    # (0..bb).each do |bbb|
    #   if rrr * r + ggg * g + bbb * b == n
    #     ans += 1
    #   end
    # end
  end
end
puts ans

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

int n, a[200005], inv[200005];

vector<pair<int,int> > v;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		v.push_back({a[i],i});
	}
	sort(v.begin(), v.end());
	for(int i=0;i<n;i++) {
		inv[v[i].second] = i;
	}
	for(int i=1;i<=n;i++) {
		printf("%d\n",v[n/2-(inv[i] >= n/2)].first);
	}
}


Measured memory_bytes: 5488
#include <iostream>
#include <map>
#include <algorithm>
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

int main (void) {
    string s;
    cin >> s;
    if (s.size() == 26) {
        if (s == "zyxwvutsrqponmlkjihgfedcba") s = "-1";
        else {
            int i = 25;
            char mini = s[i];
            while (s[i-1] > s[i]) {
                // mini = min(s[i], mini);
// if (s[i] < mini and s[i] 
                i--;
            }
            // s[i-1] = mini;
sort(s.begin()+i, s.end());
s[i-1] = *lower_bound(s.begin()+i, s.end(), s[i-1]) ;
            s.resize(i);
        }
    }
    else {
        map<char, bool> memo;
        for(auto c: s) memo[c] = true;
        rep(i, 26) {
            if (!memo[i+ 'a']) {
                s.push_back(i+'a');
                break;
            }
        }
    }
    cout << s << endl;

    return 0;
}



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

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

bool array_equal(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return false;
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return false;
    }
  }
  return true;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int main() {
  std::cout << std::setprecision(9);
  int n;
  cin >> n;

  vector<double> v(n);
  for(int i=0; i<n; i++) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  double ans = v.at(0);
  for(int i=1; i<n; i++) {
    ans += v.at(i);
    ans /= 2.0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3824
/** author: __nishad__ **/
//#pragma GCC optimize(2)
//#pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a,b) for(ll i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    int a, b;
    cin>>a>>b;
    cout<<a*b;

}


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

int main()
{
	int N;
	cin >> N;
	vector<string> s(N);
	for(int i = 0; i < N; i++) {
		cin >> s[i];
	}
	int M;
	cin >> M;
	vector<string> t(M);
	for(int i = 0; i < M; i++) {
		cin >> t[i];
	}
	vector<string> p(N);
	p = s;
	sort(p.begin(),p.end());
    p.erase(unique(p.begin(),p.end()),p.end());
	int maxv = 0;
	for(int i = 0; i < p.size(); i++) {
		int c = 0;
		c += count(s.begin(), s.end(), p[i]);
		c -= count(t.begin(), t.end(), p[i]);
		maxv = max(maxv,c);
	}
	cout << maxv << endl;
}

Measured memory_bytes: 256
// Contest: AtCoder Beginner Contest 147 (https://atcoder.jp/contests/abc147)
// Problem: B: Palindrome-philia (https://atcoder.jp/contests/abc147/tasks/abc147_b)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion }}}

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

    string s; cin >> s;
    int c = 0;
    for (int i = 0; i < sz(s) / 2; ++i)
        c += s[i] != s[sz(s) - 1 - i];

    cout << c << '\n';
    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()

n = int(input())
ls, rs = [], []
total = 0
for i in range(n):
    s = input()
    h, b = 0, 0
    for c in s:
        if c=='(':  h += 1
        else:       h -= 1
        b = min(b, h)
    if h > 0:   ls.append((b, h))       # 増減+ はb:最下点, h:増減を取る
    else:       rs.append((b-h, -h))    # 増減- は、上下左右逆さに考え、b:右から見た最下点、h:増減のマイナスを取る
    total += h
ls.sort(reverse=True)
rs.sort(reverse=True)   # 増減-は右から見るので、大きい順にsort

def chk(s):
    h = 0
    for sb, sh in s:
        b = h + sb
        if b < 0: return False
        h += sh
    return True

if (chk(ls) and chk(rs) and total==0):
    print("Yes")
else:
    print("No")

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

using ll=long long int;

std::string str;

int main() {

    std::cin>>str;

    ll ans=0;

    std::string ss;

    for(int i=0;i<(1<<(str.size()-1));++i){
        ss="";
        for(int j=0;j<str.size()-1;++j){
            ss+=str[j];
            if((i>>j)&1){
                ans+=std::stoi(ss);
                ss="";
            }
        }
        ss+=str.back();
        ans+=std::stoll(ss);
    }

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

    return 0;
}

Measured memory_bytes: 256
str = gets.split
N,K = str[0].to_i, str[1].to_i
a = Array.new(N)
str = gets.split
for i in 0...N do
    a[i] = str[i].to_i
end
a.sort!
x = N-K
if x <= 0
    puts 0
else
    answer = 0
    for i in 0...x do
        answer += a[i]
    end
    puts answer
end

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

int	main(void)
{
	int a, b, answer;
	char op;
	cin >> a >> op >> b;

	if (op == '+')
		answer = a + b;
	else
		answer = a - b;
	cout << answer << endl;
	return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=303;
int n,m,a[N][N];
int ans=1e9;
int res[N],vis[N];
int cac() {
	memset(res,0,sizeof(res));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(vis[a[i][j]]==1)continue;
			res[a[i][j]]++; break;
		}
	}
	int mx=0,mxpos=1;
	for(int i=1;i<=m;i++){
		if(res[i]>=mx){
			mx=res[i]; mxpos=i;
		}
	}
	//printf("mxpos=%d, mx=%d\n", mxpos,mx);
	vis[mxpos]=1;
	return mx;
}
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)scanf("%d",&a[i][j]);	
	for(int i=1;i<=m;i++) ans=min(ans,cac());
	cout<<ans<<endl;
}

Measured memory_bytes: 640
N = int(input())
A = list(map(lambda x: int(x) % 2 == 1or((int(x) % 2 == 0) and (int(x) % 5 == 0 or int(x) % 3 == 0)),input().split()))
if all(A) == True:
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <stack>
using namespace std;
int n, m;
int x, y;
string s;
int GCD(int x, int y){
    if(y==0) return x;
    return GCD(y, x%y);
}
int main() {
    cin >> x >> y;
    if(x<y) swap(x, y);
    cout << GCD(x, y) << endl;;
    
    return 0;
}


Measured memory_bytes: 3132
#include<stdio.h>
int main(){
	int a[201][3],d,n,k,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
	for(k=0;k<3;k++){
		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				if(i==j)continue;
				else if(a[i][k]%100==a[j][k]%100){
					a[i][k]=a[i][k]+100;
					a[j][k]=a[j][k]+100;
				}
			}
		}
		for(i=0;i<n;i++){
			if(a[i][k]>100)a[i][k]=0;
		}
	}
	for(i=0;i<n;i++)printf("%d\n",a[i][0]+a[i][1]+a[i][2]);
	return 0;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int a,b;
    cin>>a>>b;
    int x=a+b;
    int y=a-b;
    int z=a*b;
    int ans=max(x,max(y,z));
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(void){

  ll n,k;
  cin>>n>>k;

  string s;
  cin>>s;

  char c_past='2';

  vector<ll> num[3];
  ll tmp=0;
  for(char c:s){
    if(c_past != c){
      num[c_past-'0'].pb(tmp);
      tmp=1;
    }
    else{
      tmp++;
    }
    c_past=c;
  }
  num[c_past-'0'].pb(tmp);
  
  ll sum=0;
  

  if( k >= num[0].size() ){
    sum=0;
    for(auto x:num[0]) sum+=x;
    for(auto x:num[1]) sum+=x;
    cout << sum << endl;
    return 0;
  }

  if( num[0].size()==0 ){
    sum=0;
    for(auto x:num[1]) sum+=x;
    cout << sum << endl;
    return 0;
  }

  ll ahead_1=0;
  if(s[0]=='1'){
    sum+=num[1][0];
    ahead_1=1;
  }
  ll tail_1=0;
  if(s[n-1]=='1'){
    tail_1=1;
  }

  vector<pair<ll,ll>> nums;

  if(ahead_1){
    rep(i,num[0].size()) nums.pb(make_pair(num[1][i],num[0][i]));
    if(num[1].size() > num[0].size() ) nums.pb(make_pair(num[1][ num[1].size()-1 ],0));
  }
  else{
    nums.pb( make_pair(0,num[0][0]) );
    rep(i,num[0].size()-1) nums.pb(make_pair(num[1][i],num[0][i+1]));
    if(num[1].size() == num[0].size() ) nums.pb(make_pair(num[1][ num[1].size()-1 ],0));
    
  }

  //for(auto x:nums) cout << x.first << "," << x.second << endl;

  sum=nums[0].first;
  

  rep(i,k){
    sum+=nums[i].second;
    sum+=nums[i+1].first;
  }

  ll ans=sum;

  for(ll i=k;i<nums.size()-1;i++){
    sum-=nums[i-k].second;
    sum-=nums[i-k].first;
    sum+=nums[i].second;
    sum+=nums[i+1].first;
    ans=max(ans,sum);
  }
  tmp=nums.size()-1;
  sum-=nums[tmp-k].second;
  sum-=nums[tmp-k].first;
  sum+=nums[tmp].second;
  ans=max(ans,sum);

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 2356
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    vector<int> v(5);
    int ans = 0;
    for (int i = 0; i < 5; i++) {
        cin >> v[i];
        ans += v[i];
    }

    vi vv(5);
    for (int i = 0; i < 5; i++) {
        vv[i] = (10 - v[i] % 10) % 10;
    }
    sort(all(vv));

    for (int i = 0; i < 4; i++) {
        ans += vv[i];
    }

    cout << ans << endl;
    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll H, N;
  cin >> H >> N;
  vll A(N), B(N);
  vvll dp(N+1, vll(H+1, INF));
  for(int i = 0; i < N; i++){
    cin >> A.at(i) >> B.at(i);
  }
  for(int i = 0; i <= N; i++){
    dp.at(i).at(0) = 0LL;
  }
  for(int i = 1; i <= H; i++){
    dp.at(1).at(i) = (i + A.at(0) - 1) / A.at(0) * B.at(0);
  }

  for(int i = 0; i < N; i++){
    for(int j = 0; j <= H; j++){
      chmin(dp.at(i+1).at(j), dp.at(i).at(j));
      if(j-A.at(i)>=0){
        chmin(dp.at(i+1).at(j), dp.at(i+1).at(j-A.at(i)) + B.at(i));
      }
      else{
        chmin(dp.at(i+1).at(j), B.at(i));
      }
    }
  }
  cout << dp.at(N).at(H) << endl;
}

Measured memory_bytes: 78592
#include<bits/stdc++.h>
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
using namespace std;
int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b,a % b);
}
int combination(int n, int k){
    int spaceOptimize[k+1];
    memset(spaceOptimize, 0, sizeof(spaceOptimize));
    spaceOptimize[0] = 1;
    for(int i=1;i<=n; i++){
        for(int j= min(i,k);j>0;j--){
            spaceOptimize[j] = spaceOptimize[j] + spaceOptimize[j-1];
        }
    }
    return spaceOptimize[k];
}
int count_permutation(int arr[], int n){
    int a[n];
    for(int i=0;i<n;i++){
        a[i] = i+1;
    }
    int count = 0;
    do {
        count++;
        if (equal(a, a + n, arr)){
            return count;
        }
    } while (next_permutation(a, a + n));
    return 0;
}

signed main(){
#ifndef ONLINE_JUDGE
   // freopen("input.txt","r", stdin);
#endif
    fastIO

    string s;
    cin >> s;
    char odd = 'R';
    char even = 'L';
    bool fail = false;
    for(int i=0;i<s.length();i++){
//        cout << i << " " << " s[i] = " << s[i] << endl;
        if(i%2 == 0 && s[i] == even) {fail = true;
        }
        else if(i%2 == 1 && s[i] == odd ) {fail = true;}
    }
    if(!fail) cout << "Yes";
    else cout << "No";


    return 0;
}


Measured memory_bytes: 256
import std;

auto input()
{
    return readln().chomp();
}

alias sread = () => readln.chomp();

void main()
{
    long n, m;
    scan(n, m);
    //writeln(n, m);
    auto color = new bool[](n);
    color[0] = true;
    auto cup = new long[](n);
    cup[] = 1;
    foreach (i; 0 .. m)
    {
        long x, y;
        scan(x, y);
        //writeln(x, y);
        cup[x - 1] -= 1;
        cup[y - 1] += 1;
        if (color[x - 1])
        {
            color[y - 1] = true;
        }
        if (cup[x - 1] == 0)
        {
            color[x - 1] = false;
        }
    }
    // writeln(cup);
    // writeln(color);
    auto cnt = 0L;
    foreach (i; 0 .. n)
    {
        if (cup[i] != 0 && color[i])
        {
            cnt += 1;

        }
    }
    writeln(cnt);
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;

    }
}


Measured memory_bytes: 5496
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    
    ll n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector <ll> v;
    ll tmp = 0;
    for(ll i=0;i<n;i++){
        if(i==0){
            if(s[i] == '0'){
                v.push_back(0);
            }
            tmp++;
            continue;
        }
        if(s[i] != s[i-1]){
            v.push_back(tmp);
            tmp = 1;
        }else{
            tmp++;
        }
    }
    v.push_back(tmp);
    if(s[n-1] == '0'){
        v.push_back(0);
    }
//    for(ll i=0;i<v.size();i++){
//        cout << v[i] << " ";
//    }

    queue <ll> q;
    ll ans = 0;
    ll now = 0;
    for(ll i=0;i<v.size();i++){
        if(q.size() >= 2*k+1){
            now -= q.front();
            q.pop();
        }
        q.push(v[i]);
        now += v[i];

        if(i%2 == 0 and ans < now){
            ans = now;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 1528
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];puts("");}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")

struct UnionFind{
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return 0;
        if(data[y]<data[x])swap(x,y);
        data[x]+=data[y],data[y]=x;
        return 1;
    }
    bool findSet(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,m;
	cin>>n>>m;
	vvi in(m,vi(2));
	rep(i,m)rep(j,2)cin>>in[m-1-i][j];
	UnionFind uf(n);
	int co=0;
	vi out(m);
	rep(i,m){
		out[m-1-i]=n*(n-1)/2-co;
		int a=in[i][0],b=in[i][1];a--;b--;
		if(uf.root(a)-uf.root(b)){
		 	int A=uf.size(a),B=uf.size(b);
			co-=A*(A-1)/2+B*(B-1)/2;
			uf.unionSet(a,b);
			A=uf.size(a);
			co+=A*(A-1)/2;
		}
	}
	rep(i,m)cout<<out[i]<<endl;
}


Measured memory_bytes: 9856
def main():

    H,W = map(int,input().split())
    A = [list(map(int,input().split())) for _ in range(H)]
    B = [list(map(int,input().split())) for _ in range(H)]

    C = [[0 for j in range(W)] for i in range(H)]

    for i in range(H):
        for j in range(W):
            C[i][j] = abs(A[i][j]-B[i][j])

    dp = [[0 for k in range(6400)] for g in range(H*W)]
    dp[0][C[0][0]] = 1

    for g in range(H*W):
        i,j = divmod(g,W)
        for k in range(6400):
            if not dp[i*W+j][k]:
                continue
            ni,nj = i+1,j+1
            if ni < H:
                if k+C[ni][j]<6400:
                    dp[ni*W+j][k+C[ni][j]] = 1
                dp[ni*W+j][abs(k-C[ni][j])] = 1
            if nj < W:
                if k+C[i][nj]<6400:
                    dp[i*W+nj][k+C[i][nj]] = 1
                dp[i*W+nj][abs(k-C[i][nj])] = 1

    for k in range(6400):
        if dp[-1][k]:
            print(k)
            break

main()

Measured memory_bytes: 380168
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    int k,n;
    cin>>n>>S>>k;
    for(int i=0;i<S.size();i++){
        if(S[i]!=S[k-1]){
            S[i]='*';
        }
    }
    cout<<S<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

const int64_t R = 1e9 + 7;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int64_t a[2'000];
int64_t b[2'000];
int64_t c[2'000];

int main()
{
    int64_t n, k;
    cin >> n >> k;

    rep(i, n)
    {
        cin >> a[i];
    }

    rep(i, n)
    {
        b[i] = 0;
        for (int j = i + 1; j < n; j++) {
            if (a[i] > a[j]) {
                b[i]++;
            }
        }
        c[i] = 0;
        rep(j, n)
        {
            if (a[i] > a[j]) {
                c[i]++;
            }
        }
    }

    int64_t bsum = 0;
    int64_t csum = 0;
    rep(i, n)
    {
        bsum = (bsum + b[i]) % R;
        csum = (csum + c[i]) % R;
    }
    int64_t kk = k * (k - 1) / 2 % R;

    int64_t result = (k * bsum % R + kk * csum % R) % R;

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

//変数
ll N, M;
vector<ll> vec;

//解法
void solve() {

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

	vector<ll> vec2(M - 1);
	SORTL2S(ll, vec);
	rep(i, M - 1) {
		vec2[i] = vec[i] - vec[i + 1];
	}
	SORTS2L(ll, vec2);

	ll ans = 0;
	rep(i, M - N) {
		ans += vec2[i];
	}

	cout << ans;

	return;
}

int main() {
	//入力

	cin >> N >> M;
	vec.resize(M);
	rep(i, M) cin >> vec[i];

	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 1792
N, M = map(int, input().split())
p = [0] * M
S = [0] * M
count_AC = [0] * N
count_WA = [0] * N
for i in range(M):
    p[i],S[i] =  input().split()
    p[i] = int(p[i]) - 1

    if S[i] == 'AC':
        if count_AC[p[i]] == 0:
            count_AC[p[i]] = 1
            
    if S[i] == 'WA':
        if count_AC[p[i]] == 0:
            count_WA[p[i]] = count_WA[p[i]] + 1
            
print(sum(count_AC) , sum([x * y for (x, y) in zip(count_AC, count_WA)]))

Measured memory_bytes: 15792
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()


ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  ios::sync_with_stdio(false);
  ll n;
  cin>>n;
  vector<ll> a(n),b(n),c(n);
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  rep(i,n) cin>>c[i];
  sort(ALL(a));
  sort(ALL(b));
  sort(ALL(c));
  ll ans=0;
  rep(i,n){
    ll x=lower_bound(ALL(a),b[i])-a.begin();
    ll y=c.end()-upper_bound(ALL(c),b[i]);
    ans+=x*y;
  }
  cout<<ans<<endl;
  
  
  
  
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N, L;
    cin >> N >> L;
    vector<int> apple(N);
    long long s = 0;
    long long small = INF;
    REP(i, N) {
        apple[i] = L + i;
        s += apple[i];
        if(abs(apple[i]) < abs(small)) {
            small = apple[i];
        }
    }
    cout << s - small << endl;
}

Measured memory_bytes: 256
import Data.Char

main = readLn >>= putStrLn . solve

solve n
  | n < 1 = ""
  | 1 <= n && n <= 26 = [chr $ n - 1 + ord 'a']
  | otherwise = solve ((n - 1) `div` 26) ++ solve ((n - 1) `mod` 26 + 1)

Measured memory_bytes: 3884
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#define int long long
using namespace std;

int n;
string str;
map<string, int>a;
int ans=0;

signed main() {
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> str;
    sort(str.begin(), str.end());
    a[str]++;
  }
  
  for (auto x:a) {
    ans += x.second*(x.second-1)/2;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 11136
import math as mt
n=int(input())
l=list(map(int,input().split()))
gd=l[0]
sv=[0]*(10**6+1)
for i in range(2,len(sv)):
  if not sv[i]:
    sv[i]=i
    for j in range(2*i,len(sv),i):
      sv[j]=i
an="not coprime"
for i in range(n):
      gd=mt.gcd(gd,l[i])
if gd!=1:
	print(an)
else:
    an="setwise coprime"
    pos=1
    vis=[0]*(10**6+2)
    for i in range(n):
      cr=l[i]
      while cr>1:
          dv=sv[cr]
          if vis[dv]:
            pos=0;break
          while cr%dv==0:
            cr//=dv
          vis[dv]=1
    if pos:
      an="pairwise coprime"
    print(an)


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

int main() {
    int x;
    cin >> x;
    int ans = 0;
    int kijun = x/100;
    int amari = x%100;
    if (kijun*5 >= amari) {
        ans = 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
typedef long long int ll;
using namespace std;

int main() {
   ll d,t,s;
   cin>>d>>t>>s;
   ll temp=t*s;
   if(temp>=d)
   {
       cout<<"Yes";
   }
   else
   cout<<"No";

    //cout<<"Sum of x+y = " << z;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, M, C;
    cin >> N >> M >> C;
    int B[20], A[20][20];
    for(int i=0;i<M;i++)
        cin >> B[i];
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cin >> A[i][j];
        }
    }
    
    int ans = 0, d;
    // N個のソースコード
    for(int i=0;i<N;i++){
        d = 0;
        for(int j=0;j<M;j++){
            d += A[i][j]*B[j];
        }
        d += C;
        if(d > 0)
            ans++;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a,s;
int main()
{ cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin>>n;
  for(int i=1;i<=n;i++)
  { cin>>a;
    if(i%2==1 && a%2==1)
       s++;
  }
  cout<<s<<'\n';
  return 0;
}


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

int main(){
  int N; cin >> N;
  string S; cin >> S;
  
  for(int i = 0; i < (int) S.size(); i++){
    int c = S[i]-'A';
    c = (c+N)%26;
    S[i] = (char)(c+'A');
  }
  
  cout << S << endl;
  
  return 0;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a,b,c=0,d[1000001],i;
    string s;
    cin>>a>>b;
    for(i=1;i<=b;i++){
        cin>>d[i];
        c=c+d[i];
    }
    if(c>a){
        cout<<-1;
    }
    if(c<=a){
        if(c==a){
            cout<<0;
        }
        else{
            cout<<a-c;
        }
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
ll MOD = 1000000007;
ll INF = 200000000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

int main(){
  string S;
  cin >> S;
  ll N = S.size();
  vector<ll> A(2,1);
  rep(i,N-1){
      if(S[i] == S[i+1]) A.back()++;
      else A.push_back(1);
  }
  ll ans = 0;
  if(S[N-1] == '<') A.push_back(1);
  if(S[0] == '<'){
      FOR(i,1,A.size()){
      ans += ((min(A[i],A[i+1])-1) * min(A[i],A[i+1]))/2;
      ans += (max(A[i],A[i+1]) * (max(A[i],A[i+1])+1))/2;
      i++;
      }
  }else{
      rep(i,A.size()){
      ans += ((min(A[i],A[i+1])-1) * min(A[i],A[i+1]))/2;
      ans += (max(A[i],A[i+1]) * (max(A[i],A[i+1])+1))/2;
      i++;
      }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3068
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)

def main():
    n = int(input())
    flag = True
    for _ in range(n):
        a = int(input())
        if a%2 != 0:
            flag = False
            break
    
    if flag:
        print('second')
    else:
        print('first')
if __name__=='__main__':
    main()




Measured memory_bytes: 3316