akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
vector<pair<int,int>> v[1010][1010];
int a[1010][1010];
int n,num[1010][1010] = {},dp[1010][1010] = {};
vector<pair<int,int>> top_sort(){
	vector<pair<int,int>> vec;
	int i,j;
	for(i=0;i<n;i++){
		for(j=i + 1;j<n;j++){
			for(auto x:v[i][j]){
				num[x.first][x.second]++;
			}
		}
	}
	for(i=0;i<n;i++){
		for(j=i + 1;j<n;j++){
			if(num[i][j]==0){
				vec.push_back({i,j});
			}
		}
	}
	i=0;
	while(i<vec.size()){
		pair<int,int> x = vec[i];
		for(auto y:v[x.first][x.second]){
			num[y.first][y.second]--;
			if(num[y.first][y.second]==0){
				vec.push_back(y);
			}
		}
		i++;
	}
	return vec;
}
int solve(int a, int b){
	if(dp[a][b]!=-1) return dp[a][b];
	int mx = 0;
	for(auto p:v[a][b]){
		mx = max(mx,solve(p.first,p.second));
	}
	return dp[a][b] = mx + 1;
}
int main(){
	int i,j;
	cin >> n;
	for(i=0;i<n;i++){
		for(j=0;j<n - 1;j++){
			cin >> a[i][j];
			a[i][j]--;
		}
	}
	for(i=0;i<n;i++){
		for(j=1;j<n - 1;j++){
			int x = a[i][j],y = a[i][j - 1];
			int s1 = min(i,y),s2 = max(i,y),t1 = min(i,x),t2 = max(i,x);
			v[s1][s2].push_back({t1,t2});
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			sort(v[i][j].begin(),v[i][j].begin());
			v[i][j].erase(unique(v[i][j].begin(),v[i][j].end()),v[i][j].end());
		}
	}
	vector<pair<int,int>> p = top_sort();
	if(p.size()<n*(n - 1)/2){
		cout << -1 << endl;
		return 0;
	}
	for(i=0;i<n;i++){
		for(j=i;j<n;j++){
			dp[i][j] = -1;
			if(v[i][j].size()==0){
				dp[i][j] = 0;
			}
		}
	}
	for(i=0;i<n;i++){
		for(j=i + 1;j<n;j++){
			solve(i,j);
		}
	}
	int ans = 0;
	for(i=0;i<n;i++){
		for(j=i;j<n;j++){
			ans = max(ans,dp[i][j] + 1);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 55792
def to_time(i)
  h = (i / 3_600).to_i
  m = (i - (h * 3_600)) / 60.to_i
  s = (i - h * 3_600 - m * 60) % 3_600
  "#{h}:#{m}:#{s}"
end

s = gets.chomp.to_i
puts to_time(s)

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

vector<int> gather_component_marks(const int n,
                                   const unordered_multimap<int, int> &g) {
    vector<int> cs(n, -1);
    int curr = -1;

    function<void(int)> dfs;
    dfs = [&dfs, &g, &cs, &curr](const int x) {
        cs[x] = curr;

        const auto [first, last] = g.equal_range(x);
        for (auto it = first; it != last; ++it) {
            if (cs[it->second] >= 0) continue;
            dfs(it->second);
        }
    };

    for (int i = 0; i < n; ++i) {
        if (cs[i] == -1) {
            ++curr;
            dfs(i);
        }
    }

    return cs;
}

unordered_map<int, int> gather_counts(const vector<int> &xs) {
    unordered_map<int, int> ans;

    for (const auto x : xs) {
        ++ans[x];
    }

    return ans;
}

int max_component_size(const int n, const unordered_multimap<int, int> &g) {
    int ans = -1;

    for (const auto [k, v] : gather_counts(gather_component_marks(n, g))) {
        ans = max(ans, v);
    }

    return ans;
}

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

    int n, m;
    cin >> n >> m;

    unordered_multimap<int, int> g;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;

        g.emplace(a - 1, b - 1);
        g.emplace(b - 1, a - 1);
    }

    cout << max_component_size(n, g) << '\n';

    return 0;
}


Measured memory_bytes: 33036
package main

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

var A []int

func solve(x int) int {
	for _, v := range A {
		if r := v % x; r != 0 {
			return solve(r)
		}
	}
	return x
}

func main() {
	var n int
	fmt.Scan(&n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	A = make([]int, n)
	min := 1000000001
	for i := range A {
		sc.Scan()
		A[i], _ = strconv.Atoi(sc.Text())
		if A[i] < min {
			min = A[i]
		}
	}

	fmt.Println(solve(min))
}


Measured memory_bytes: 3072
using System;
using System.Linq;
class B
{
    public static void Main() {
        int n = int.Parse(Console.ReadLine());
        int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int q = partition(ref A, 0, n - 1);
        for(int i = 0; i < A.Length; i++) {
            if (i > 0) {
                Console.Write(" ");
            }
            if (i == q) {
                Console.Write("[" + A[i] + "]");
            } else {
                Console.Write(A[i]);
            }
        }
        Console.WriteLine();
    }

    public static int partition(ref int[] A, int p, int r) {
        int x = A[r];
        int i = p - 1;
        int temp = 0;
        for(int j = p; j < r; j++) {
            if (A[j] <= x) {
                i += 1;
                temp = A[i];
                A[i] = A[j];
                A[j] = temp;
            }
        }
        temp=A[i + 1];
        A[i+1] = A[r];
        A[r] = temp;
        return i + 1;
    }
}


Measured memory_bytes: 17736
#include <iostream>
using namespace std;
int main(){
  while(1){
    int a, b;
    char op;
    cin >> a >> op >> b;
    if(op == '?') break;
    switch(op){
      case '+':
        a = a + b;
        break;
      case '-':
        a = a - b;
        break;
      case '*':
        a = a * b;
        break;
      case '/':
        a = a / b;
        break;
      default:
        return 0;
    }
    cout << a << endl;
  }
}

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

int main() {
  int N, Norg, sum, N1, N2, N3, N4, N5, N6, N7, N8;
  cin >> N;//もともとの数字
  
  Norg = N;
  sum = 0;
  N1 = 0;
  N2 = 0;
  N3 = 0;
  N4 = 0;
  N5 = 0;
  N6 = 0;
  N7 = 0;
  N8 = 0;
  
  N1 = N % 10;
  N = N - N1;
  if (Norg > 9) {
    N2 = (N % 100) / 10;
    N = N - N2;
  }
  if (Norg > 99) {
    N3 = (N % 1000) / 100;
    N = N - N3;
  }
  if (Norg > 999) {
    N4 = (N % 10000) / 1000;
    N = N - N4;
  }
  if (Norg > 9999) {
    N5 = (N % 100000) / 10000;
    N = N - N5;
  }
  if (Norg > 99999) {
    N6 = (N % 1000000) / 100000;
    N = N - N6;
  }
  if (Norg > 999999) {
    N7 = (N % 10000000) / 1000000;
    N = N - N7;
  }
  if (Norg > 9999999) {
    N8 = (N % 100000000) / 10000000;
  }
  sum = N1 + N2 + N3 + N4 + N5 + N6 + N7 + N8;
  
  //for (int i = 0; i < 8; i++) {
    //string syu;
    //cin >> st >> en;
    //if (syu == "Y") {
    //  cout << "Four"<< endl;
    //  break;
    //}
    
    //sum = sum + en - st + 1;
  //}
  if ((Norg % sum) == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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()
{
  int N;
  cin >> N;
  
  ll sum = 0;
  for (int i = 1; i <= N; i++)
  {
    if ((0 != i % 3) && (0 != i % 5))
    {
      sum += i;
    }
  }
  
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#ifdef __DEBUG__
    void debug_out() { cerr << endl; } 
    template <typename Head, typename... Tail>
    void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);}
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 
#endif

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<bool> D;
inline void input(){
    fast_io();
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int a,b; cin >> a >> b;
        D.emplace_back((a==b));
    }
    
}

inline int solve(){
    string ans = "No";
    for (int i = 0; i+2 < N; i++)
    {
        if(D[i] && D[i+1] && D[i+2]) ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}   

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


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <cstring>
#include <bitset>
#include <functional>
using namespace std;
typedef pair<int,int> P;
typedef unsigned long long int ull;
#define pb push_back
#define INF 1000000000
#define fi first
#define sec second
int dist1[100100],dist2[100100];
int c[40100],d[40100];
bitset<1024> dp[100100];
struct edge{
    int to,cost;
    edge(int to,int cost):to(to),cost(cost){}
};
vector<edge> g[100100];
int comp(int x,int y){
    return dist1[x]<dist1[y];
}
void dijkstra(int s,int t){
    for(int i=0;i<100100;i++)dist1[i]=INF,dist2[i]=INF;
    dist1[s]=0,dist2[t]=0;
    priority_queue<P,vector<P>,greater<P> >q;
    q.push(P(0,s));
    while(!q.empty()){
        P a = q.top();
        q.pop();
        int v = a.sec;
        for(int i=0;i<g[v].size();i++){
            edge e = g[v][i];
            if(dist1[e.to]>dist1[v]+e.cost){
                dist1[e.to] = dist1[v]+e.cost;
                q.push(P(dist1[e.to],e.to));
            }
        }
    }
    q.push(P(0,t));
    while(!q.empty()){
        P a = q.top();
        q.pop();
        int v = a.sec;
        for(int i=0;i<g[v].size();i++){
            edge e = g[v][i];
            if(dist2[e.to]>dist2[v]+e.cost){
                dist2[e.to] = dist2[v]+e.cost;
                q.push(P(dist2[e.to],e.to));
            }
        }
    }
    return;
}
int S,R,Q;
int a,b;
int main(){
    scanf("%d %d",&S,&R);
    for(int i=0;i<R;i++){
        int u,v,w;
        scanf("%d %d %d",&u,&v,&w);
        u--;v--;
        g[u].pb(edge(v,w));
        g[v].pb(edge(u,w));
    }
    scanf("%d %d %d",&a,&b,&Q);
    a--;b--;
    dijkstra(a,b);
    /*for(int i=0;i<S;i++)
    {
        cout << dist1[i] << ' ' << dist2[i] << endl;
    }*/
    vector<int> tp;
    for(int i=0;i<S;i++)tp.pb(i);
    sort(tp.begin(),tp.end(),comp);
    //for(int i=0;i<S;i++)cout << tp[i] << ' ';
    for(int i=0;i<Q;i+=1024){
    	for(int j=0;j<100100;j++)dp[j]=bitset<1024>();
        for(int j=0;j<min(1024,Q-i);j++){
            scanf("%d %d",&c[j],&d[j]);
            c[j]--;d[j]--;
            dp[c[j]].set(j);
        } 
        for(int j=0;j<S;j++){
            int f = tp[j];
            if(dist1[f]+dist2[f]!=dist1[b])continue;
            for(int k=0;k<g[f].size();k++){
                edge e = g[f][k];
                if(dist1[e.to]+dist2[e.to]!=dist1[b])continue;
                if(dist1[e.to]!=dist1[f]+e.cost)continue;
                dp[e.to]|=dp[f];
            }
        }
        for(int j=0;j<min(1024,Q-i);j++){
            if(dp[d[j]][j])printf("Yes\n");
            else printf("No\n");
        }
    }
    return 0;
}

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

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

	if (S == "RRR") {
		cout << "3" << endl;
	}

	if (S == "RRS") {
		cout << 2 << endl;
	}

	if (S == "RSS") {
		cout << 1 << endl;
	}

	if (S == "SSS") {
		cout << 0 << endl;
	}

	if (S == "SSR") {
		cout << 1 << endl;
	}

	if (S == "SRR") {
		cout << 2 << endl;
	}

	if (S == "RSR") {
		cout << 1 << endl;
	}

	if (S == "SRS") {
		cout << 1 << endl;
	}
}

Measured memory_bytes: 3632
a = int(input())
b = a//1000
c = (a//100)%10
d = (a//10)%10
e = a%10
cou = 0
if b is c:
  cou = cou + 1
elif c is d:
   cou = cou + 1
elif d is e:
   cou = cou + 1
else:
  print("Good")
if cou > 0:
  print("Bad")

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

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

    vector<int> a = {5, 5, 7}, b(3);
    cin >> b[0] >> b[1] >> b[2];
    sort(b.begin(), b.end());
    cout << ((b == a)? "YES" : "NO");
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int N;cin>>N;
    vector<int>A(N);
    vector<ll>s(N);
    ll ans=0;
    rep(i,N){
        cin>>A.at(i);
        if(i==0){
            s.at(i)=A.at(i);
        }else{
            s.at(i)+=s.at(i-1)+A.at(i);
        }
    }
    rep(i,N){
        ll sum=(s.at(N-1)-s.at(i))%mod;
        ans+=A.at(i)*sum;
        ans%=mod;
    }
    cout<<ans<<endl;



}


Measured memory_bytes: 5592
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(void){
  int n;
  while(cin >> n && n != -1){
    double x = 1.0, y = 0.0;
    for(int i = 1; i < n; i++){
      double newx, newy;
      newy = x / sqrt(x * x + y * y);
      newx = -y / sqrt(x * x + y * y);
      x += newx; y += newy;
    }
    printf("%.2f\n", x);
    printf("%.2f\n", y);
  }
  return 0;
}

Measured memory_bytes: 1196
#include <cstdio>

#define fin stdin
#define fout stdout
//FILE *fin = fopen("a.in", "r"), *fout = fopen("a.out", "w");

#define MAXN 200009

char s[MAXN + 10];

int main() {
    fgets(s, MAXN + 5, fin);
    int n = 0;
    while (s[n] != '\n') n++;

    int ans = 0, p = 0;
    bool a = 1;
    while (p < n - 1) {
        ans++;
        if (a)
            p++, a = 0;
        else if (s[p] == s[p - 1]) {
            a = 1;
            p += 2;
        } else
            p++, a = 0;
    }

    if (p == n - 1 && (a || s[p] != s[p - 1]))
        ans++;

    fprintf(fout, "%d\n", ans);

    fclose(fin);
    fclose(fout);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <stack>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;

void printarray(int n, int a[])
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i];
        if (i != n - 1)
            cout << " ";
    }
    cout << endl;
}

void printpairaraay(int n, pair<int, int> a[])
{
    int x, y;
    for (int i = 0; i < n; i++)
    {
        x = a[i].first;
        y = a[i].second;
        cout << x << " " << y << "\n";
    }
    cout << endl;
}

void swaprange(int b, int t, int e, int a[])
{
    for (int i = 0; i < e - b; i++)
    {
        swap(a[b + i], a[i + t]);
    }
}

int my_binarysearch(int n, int a[], int x)
{
    int ret = 0;
    if (distance(lower_bound(a, a + n, x), upper_bound(a, a + n, x)) != 0)
        ret = 1;
    return ret;
}

int main()
{
    int n, m, x, r;
	r = 0;
    cin >> n;
    int a[n];

    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    cin >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> x;
    	cout << distance( a, lower_bound(a, a + n, x) ) << " ";
    	cout << distance( a, upper_bound(a, a + n, x) ) << endl;
    }


    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

#define MAX_T 100010


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n,c;
  cin >> n >> c;

  vector<pair<ll, pll>> tl(n);
  REP(i, n){
    cin >> tl[i].SE.FI >> tl[i].SE.SE >> tl[i].FI;
  }

  sort(tl.begin(), tl.end());
  ll pre = 0;
  REP1(i, n){
    if(tl[i].FI == tl[pre].FI && tl[i].SE.FI == tl[pre].SE.SE){
      tl[pre].SE.SE = tl[i].SE.SE;
      tl[i].FI = -1;
    }
    else
      pre = i;
  }


  vll imos(2*MAX_T, 0);
  REP(i, n){
    ll st = tl[i].SE.FI;
    ll en = tl[i].SE.SE;
    ll chan = tl[i].FI;

    if(chan == -1)
      continue;
    imos[2*st-1] += 1;
    imos[2*en] -= 1;
  }

  ll ans = 0;
  ll now = 0;
  REP(i, imos.size()){
    now += imos[i];
    ans = max(ans, now);
  }


  cout << ans << endl;

}


Measured memory_bytes: 4224
def q4():
    import math
    A, B, N = (int(i) for i in input().split())
    x = B - 1 if N >= B else N
    ans = math.floor(x*A//B) - A * math.floor(x//B)
    return ans
 
 
if __name__ == '__main__':
    ans = q4()
    print(ans)

Measured memory_bytes: 9180
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

void chmax(int &a, int b) {
    a = max(a, b);
}

char buf[310];
int dp[310][310][310];
int main() {
    scanf("%s", buf);
    int K; scanf("%d", &K);

    int N = strlen(buf);
    for(int i=0; i<N; i++) {
        dp[i][i+1][0] = 1;
    }

    for(int k=0; k<=K; k++) {
        for(int len=0; len<=N; len++) {
            for(int l=0; l<N-len+1; l++) {
                int r = l + len;
                if(k > 0) chmax(dp[l][r][k], dp[l][r][k-1]);
                if(l-1 >= 0 && r+1 <= N) {
                    int cost = (buf[l-1] != buf[r]);

                    // 変更する
                    if(k + cost <= K) chmax(dp[l-1][r+1][k+cost], dp[l][r][k] + 2);
                    
                    // 変更しない
                    chmax(dp[l-1][r+1][k], dp[l][r][k]);
                }
                if(l-1 >= 0) chmax(dp[l-1][r][k], dp[l][r][k]);
                if(r+1 <= N) chmax(dp[l][r+1][k], dp[l][r][k]);
            }
        }
    }

    /*
    for(int i=0; i<N; i++) {
        for(int j=i+1; j<=N; j++) {
            printf("%s -> %d\n", buf, dp[i][j][K]);
            for(int x=0; x<N; x++) {
                if(i <= x && x < j) printf("=");
                else printf(" ");
            }
            printf("\n");
        }
    }
    */

    int ans = 0;
    for(int i=0; i<=K; i++) {
        chmax(ans, dp[0][N][i]);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 114816
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
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; }

int main() {
  int k, a, b; cin >> k >> a >> b;
  bool flag = false;
  for (int i = a; i <= b; i++)
    if (i % k == 0) flag = true;
  if (flag)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
  return 0;
}


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

int main(){
  int N,K;
  string S;
  cin >> N >> S >> K;
  for (int i = 1;i <= N;i++){
    if(S.at(K-1)!=S.at(i-1))S.at(i-1)='*';
  }
  cout << S<< endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
prev = None
ok = True
seen = set()
for n in range(N):
    w = input()
    if prev is None:
        prev = w
    else:
        if prev[-1] != w[0]:
            ok = False
    if w in seen:
        ok = False
    seen.add(w)
    prev = w
if ok:
    print('Yes')
else:
    print('No')
    
 


Measured memory_bytes: 8008
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        double resum = 0;
        for(int i = 0; i < N; i++) {
            resum += 1 / Double.parseDouble(sc.next());
        }
        
        System.out.println((double)(1 / resum));
    }
}

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

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ld long double
#define forn(low,high,i) for(i = low; i < high; i++)
#define forrev(high,low,i) for(i = high; i >= low; i--)
#define all(v) v.begin(),v.end()
#define decimal_digits cout << fixed << setprecision(15);

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e9;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

inline int add(long long a, long long b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(long long a, long long b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(long long a, long long b){a %= mod; b %= mod; return (int)((long long) a * b % mod);}
inline int modexpo(long long a, long long b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(long long a, long long b){return mul(a, modexpo(b, mod - 2));}
inline int inv(long long a){return modexpo(a, mod - 2);}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

void pre(){ // Reset each global variable (esp. for graphs)
  
}

void solve(){
  long long n, m, t, i, j, k;
  cin >> n >> m >> t;
  vector<long long> a(n), b(m);
  for(i = 0; i < n; i++){
    cin >> a[i];
    if(i)
      a[i] += a[i - 1];
  }
  for(i = 0; i < m; i++){
    cin >> b[i];
    if(i)
      b[i] += b[i - 1];
  }
  long long ans = 0;
  for(i = 0; i < n; i++){
    long long left = t - a[i];
    long long idx = upper_bound(all(b), left) - b.begin() - 1;
    if(a[i] <= t)
      ans = max(ans, idx + 1 + i + 1);
  }
  long long idx = upper_bound(all(b), t) - b.begin() - 1;
  ans = max(ans, idx + 1);
  cout << ans << '\n';
}


#define GOOGLE 0
#define MULTIPLE_TC 0

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);cout.tie(NULL); 

  pre();

  int t = 1, T;
  if(MULTIPLE_TC)
    cin >> t;

  for(T = 1; T <= t; T++){
    if(GOOGLE)
      cout << "Case #" << T << ": ";
    solve();
  }

  ktj();
}

Measured memory_bytes: 6420
N, K = map(int, input().split())
A = [int(a) for a in input().split()]
P = 10**9+7
def cumsum(A):
    B = [A[0]]
    for i in range(1, len(A)):
        B.append((B[-1]+A[i])%P)
    return B

dp = [1] + [0] * (K+N)
for a in A:
    dp = [(dp[i]-(dp[i-a-1] if i>=a+1 else 0))%P for i in range(K+1)]
    dp = cumsum(dp)
print(dp[K])

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  string s;
  for(int b=1; b<=33; b++){
    for(int p=2; p<10; p++){
      int a = pow(b, p);
      if(a <= N){
        ans = max(ans, a);
      }else{
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
    	cin >> a[i];
    }

    while(k--){
    	vector<ll> ret(n+1);
    	for(int i=0;i<n;i++){
    		ll mi = max(0LL, i - a[i]);
    		ll ma = min(n, i + a[i] + 1);
    		ret[mi]++;
    		ret[ma]--;
    	}
    	for(int i=1;i<=n;i++){
    		ret[i] += ret[i-1];
    	}
    	bool maki = true;
    	for(int i=0;i<n;i++){
    		a[i] = ret[i];
    		if(a[i] < n) maki = false;
    	}
    	if(maki){
    		for(int i=0;i<n;i++){
    			a[i] = n;
    		}
    		break;
    	}
    }
    for(int i=0;i<n;i++){
    	cout << a[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 6368
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


nCr = {}


def C(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = C(n-1, r) + C(n-1, r-1)
    return nCr[(n, r)]


MOD = 10**9+7  # 出力の制限
N = 10**6
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % MOD)
    inverse.append((-inverse[MOD % i] * (MOD//i)) % MOD)
    g2.append((g2[-1] * inverse[-1]) % MOD)


def cmb(n, r):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % MOD


@mt
def slv(H, W, A, B):
    MOD = 10**9+7
    ans = 0
    for i in range(W-B):
        # print(ans)
        w1 = cmb(i+(A-1), i)
        w2 = cmb((W-i-1)+(H-A-1), (H-A-1))
        ans += w1*w2
        ans %= MOD

    return ans % MOD


def main():
    H, W, A, B = read_int_n()

    print(slv(H, W, A, B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 126576
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

template<typename CAP, typename COST>
class MinCostFlow {
public:
    explicit MinCostFlow(int N) : g(N) {}
    void addEdge(int src, int dst, CAP cap, COST cost){
        int r1 = g[src].size();
        int r2 = g[dst].size();
        g[src].emplace_back(src, dst, cap, cost, r2);
        g[dst].emplace_back(dst, src, 0, -cost, r1);
    }
    pair<COST, CAP> solve(int s, int t, CAP maxFlow){
        const int n = g.size();
        pair<COST, CAP> res = make_pair(0, 0);
        vector<COST> h(n, 0);
        while(maxFlow > 0){
            vector<COST> dist(n, INF); dist[s] = 0;
            vector<pair<int, int>> prev(n, make_pair(-1, -1));
            priority_queue<pair<COST, int>, vector<pair<COST, int>>, greater<pair<COST, int>>> qu;
            qu.emplace(0, s);
            while(!qu.empty()){
                auto e = qu.top(); qu.pop();
                if(dist[e.second] < e.first) continue;
                for(int i=0;i<g[e.second].size();i++){
                    auto& p = g[e.second][i];
                    if(p.cap > 0 && dist[p.dst] > dist[p.src] + p.cost + h[p.src] - h[p.dst]){
                        dist[p.dst] = dist[p.src] + p.cost + h[p.src] - h[p.dst];
                        prev[p.dst] = make_pair(p.src, i);
                        qu.emplace(dist[p.dst], p.dst);
                    }
                }
            }
            if(prev[t].first == -1) break;
            CAP f = maxFlow;
            for(int u=t;u!=s;u=prev[u].first) f = min(f, g[prev[u].first][prev[u].second].cap);
            for(int u=t;u!=s;u=prev[u].first){
                auto& p = g[prev[u].first][prev[u].second];
                auto& q = g[p.dst][p.rev];
                res.first += f * p.cost;
                p.cap -= f;
                q.cap += f;
            }
            res.second += f;
            for(int i=0;i<n;i++) h[i] += dist[i];
            maxFlow -= f;
        }
        return res;
    }
private:
    class Edge {
    public:
        explicit Edge(int src, int dst, CAP cap, COST cost, int rev) : src(src), dst(dst), cap(cap), cost(cost), rev(rev) {}
        const int src;
        const int dst;
        CAP cap;
        COST cost;
        const int rev;
    };
private:
    const COST INF = 1LL << 30;
    vector<vector<Edge>> g;
};

int main(){
    int V, E, F; cin >> V >> E >> F;
    MinCostFlow<int, int> mcf(V);
    for(int i=0;i<E;i++){
        int a, b, c, d; cin >> a >> b >> c >> d;
        mcf.addEdge(a, b, c, d);
    }
    auto res = mcf.solve(0, V-1, F);
    cout << (res.second == F ? res.first : -1) << endl;
}


Measured memory_bytes: 3164
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	var aAry = make([]int, n+1)
	var bAry = make([]int, n)
	for i := 0; i < n+1; i++ {
		aAry[i] = nextInt()
	}
	for i := 0; i < n; i++ {
		bAry[i] = nextInt()
	}

	ret := 0
	for i := n - 1; i >= 0; i-- {
		if aAry[i+1] < bAry[i] {
			bAry[i] -= aAry[i+1]
			ret += aAry[i+1]
			if aAry[i] > bAry[i] {
				aAry[i] -= bAry[i]
				ret += bAry[i]
			} else {
				ret += aAry[i]
				aAry[i] = 0
			}
		} else {
			ret += bAry[i]
		}
	}
	fmt.Println(ret)
}


Measured memory_bytes: 4736
while True:
    try:
        t1, t2 = map(float, input().split())
    except:
        break
    t1, t2 = int(t1*100), int(t2*100)
    if t1 < 3550 and t2 < 7100:
        print("AAA")
    elif t1 < 3750 and t2 < 7700:
        print("AA")
    elif t1 < 4000 and t2 < 8300:
        print("A")
    elif t1 < 4300 and t2 < 8900:
        print("B")
    elif t1 < 5000 and t2 < 10500:
        print("C")
    elif t1 < 5500 and t2 < 11600:
        print("D")
    elif t1 < 7000 and t2 < 14800:
        print("E")
    else:
        print("NA")

Measured memory_bytes: 7288
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int a,b,c;
    cin >> a >> b >> c;
    cout << min({a+b,b+c,a+c}) << endl;
}


Measured memory_bytes: 3536
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
  // 整数の入力
  ll A,B,C,K;
  cin >> A >> B >> C >> K;
  ll total = 0;
  total += min(A,K);
  K -= min(A,K);
  K -= min(B,K);
  total -= min(C,K);
  K -= min(C,K);
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main{
	static Scanner s=new Scanner(System.in);
	
	class Pair implements Comparable<Pair>{
		int l,r;

		public Pair(int l,int r){
			this.l=l;
			this.r=r;
		}

		@Override
		public int compareTo(Pair o){
			int v=Integer.compare(l,o.l);
			if(v!=0)
				return v;
			return Integer.compare(r,o.r);
		}

		@Override
		public String toString(){
			return "["+l+", "+r+"]";
		}
	}
	
	void solve(){
		int n=gInt(),m=gInt();
		Pair[]p=new Pair[m];
		for(int i:rep(m))
			p[i]=new Pair(gInt(),gInt());
		Arrays.sort(p);
		//Arrays.stream(p).forEach(System.err::println);
		
		int res=1,i=0,l=p[0].l,r=p[0].r;
		for(;i<m;++i) {
			if(l>=p[i].r||r<=p[i].l) {
				++res;
				l=p[i].l;
				r=p[i].r;
			}
			l=Math.max(l,p[i].l);
			r=Math.min(r,p[i].r);
		}
		System.out.println(res);
	}

	public static void main(String[] A){
		new Main().solve();
	}

	static int gInt(){
		return Integer.parseInt(s.next());
	}
	static long gLong(){
		return Long.parseLong(s.next());
	}
	static double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,Main::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,Main::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,Main::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(Main::gInt).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}
class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}


Measured memory_bytes: 63956
#!/usr/bin/env python3

def main():
    na = list(map(int, input().split()))
    H, W = na[0], na[1]
    s = []
    s.append('.' * (W + 2))
    for i in range(H):
        s.append('.' + input() + '.')
    s.append('.' * (W + 2))

    r = True
    for i in range(H):
        for j in range(W):
            if s[i + 1][j + 1] == '#':
                if s[i + 1][j] == '.' \
                        and s[i + 1][j + 2] == '.' \
                        and s[i][j + 1] == '.' \
                        and s[i + 2][j + 1] == '.':
                    r = False
                    break
        if not r:
            break


    print('Yes' if r else 'No')


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void){
  string str,str1,str2;
  cin>>str;
  for(int i=0;i<str.size()/2;i++){
    str1+=str.at(i);
  }
  for(int i=1+str.size()/2;i<str.size();i++){
    str2+=str.at(i);
  }
  if(str1==str2){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }

}

Measured memory_bytes: 256
def c_id():
    from collections import defaultdict
    N, M = [int(i) for i in input().split()]
    Cities = [[int(i) for i in input().split()] for j in range(M)]

    dic = defaultdict(list)
    # 県毎に市をまとめる
    for p, y in Cities:
        dic[p].append(y)
    # 市の認識番号を (座標) 圧縮
    for p, lst in dic.items():
        dic[p] = {v: k for k, v in enumerate(sorted(lst), 1)}
    return '\n'.join(['{0:06d}{1:06d}'.format(p, dic[p][y]) for p, y in Cities])

print(c_id())

Measured memory_bytes: 66592
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long int lli;
using namespace std;
// #define int long long int

inline void swap(int &a, int &b) {
    int tmp = a;
    a = b;
    b = tmp;
}

signed main() {
    string S;
    cin >> S;

    int notMM = 0;
    int index = -1;
    for (int i = 0; i < 2; i++) {
        if (S[0 + i * 2] == '1') {
            if (!(S[1 + i * 2] == '0' || S[1 + i * 2] == '1' || S[1 + i * 2] == '2')) {
                notMM++;
                index = i;
            }
        } else if (S[0 + i * 2] == '0') {
            if (S[1 + i * 2] == '0') {
                notMM++;
                index = i;
            }
        } else {
            notMM++;
            index = i;
        }
    }

    if (notMM == 2) {
        cout << "NA" << endl;
    } else if (notMM == 1) {
        if (index == 0) cout << "YYMM" << endl;
        else cout << "MMYY" << endl;
    } else {
        cout << "AMBIGUOUS" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<ll,ll> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{   
    int n,r;
    while(cin>>n>>r,n!=0)
    {
        stack<int>l;stack<int>cc;stack<int>pp;
        REP(i,n)l.push(i+1);
        REP(i,r)
        {
            int p,c;
            cin>>p>>c;
            REP(j,p-1)
            {
                pp.push(l.top());l.pop();
            }
            REP(j,c)
            {
                cc.push(l.top());l.pop();
            }
            REP(j,p-1)
            {
                l.push(pp.top());pp.pop();
            }
            REP(j,c)
            {
                l.push(cc.top());cc.pop();
            }
        }
        cout<<l.top()<<endl;
    }
}


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

int main() {
  //目標金額の代入
  int price;
  cin >> price;
  
  //0or1で判別できるindexを作る
  int index = 0;
  while (price >= 0) {
    if (price % 4 == 0) {
      index ++;
      break;
    }
    else {
      price -= 7;
    }
  }
  
  if (index == 0) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
    
}

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

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

  int taro = 0;
  int hanako = 0;

  string str1, str2;
  for (int i = 0; i < N; i++) {
    cin >> str1 >> str2;
    if (str1 > str2)
      taro += 3;
    else if (str1 < str2)
      hanako += 3;
    else if (str1 == str2) {
      taro++;
      hanako++;
    }
  }

  cout << taro << ' ' << hanako << endl;
}


Measured memory_bytes: 3144
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)
print(uf.group_count() - 1)

Measured memory_bytes: 12916
n,m = map(int, input().split())

if n >= m:
    print(0)
    exit()

l = list(map(int, input().split()))
l.sort()
x =[]
for i in range(m-1):
    x.append(l[i+1]-l[i])
x.sort()
z = []
for j in range(len(x)-n+1):
    z.append(x[j])
print(sum(z))


Measured memory_bytes: 13968
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll a, b; cin >> a >> b;
  if(a <= 8 && b <= 8 ){
    cout << "Yay!";
  }else{
    cout << ":(";
  }
  cout << endl;
}


Measured memory_bytes: 256
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef vector<pii>vip;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 200005;
 
void task(){
 	int n; cin >> n;
 	map<int,int>ans;
 	rep1(i,1,101)rep1(j,1,101)rep1(k,1,101){
 		int x = i*i+j*j+k*k+i*j+j*k+k*i;
 		if(x>n)continue;
 		ans[x]++;
 	}
 	for(int i = 1; i<=n; i++){
 		cout << ans[i]<<endl;
 	}
}

int main(){
        _
        #ifdef OJ
        freopen("inputf.in", "r", stdin);
        freopen("outputf.in", "w", stdout);
        #endif

        int T = 1; //cin >> T;
        while(T--){
            task();
        }
        
return 0;
}




Measured memory_bytes: 3984
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int A,B,C;

int main(){
	cin>>A>>B>>C;
	cout<<A+B+C+max({A,B,C})*9<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 222222
#define LL long long
using namespace std;
int T,n,i;bool f[N];char s[N];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);f[0]=1;
	for(i=5;i<=n;i++){
		if(s[i-4]=='d'&&s[i-3]=='r'&&s[i-2]=='e'&&s[i-1]=='a'&&s[i]=='m'&&f[i-5])f[i]=1;
		if(s[i-4]=='e'&&s[i-3]=='r'&&s[i-2]=='a'&&s[i-1]=='s'&&s[i]=='e'&&f[i-5])f[i]=1;
		if(i>5)if(s[i-5]=='e'&&s[i-4]=='r'&&s[i-3]=='a'&&s[i-2]=='s'&&s[i-1]=='e'&&s[i]=='r'&&f[i-6])f[i]=1;
		if(i>6)if(s[i-6]=='d'&&s[i-5]=='r'&&s[i-4]=='e'&&s[i-3]=='a'&&s[i-2]=='m'&&s[i-1]=='e'&&s[i]=='r'&&f[i-7])f[i]=1;
	}
	puts(f[n]?"YES":"NO");
/*	for(scanf("%d",&T);T--;){
		
	}*/
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int main() {
    int n, p[20];
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> p[i];

    int cnt = 0;
    for (int i = 0; i < n - 2; ++i) {
        int maxv = max(p[i], p[i + 2]);
        int minv = min(p[i], p[i + 2]);
        int mid = p[i + 1];
        if (minv < mid && mid < maxv) {
            cnt++;
        }
    }

    cout << cnt;

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNING
//#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

// #include <stack>
// #include <queue>
// #include <set>
// #include <tuple>
// #include <list>
// #include <numeric>
// #include <random>
// #include <regex>
// #include <utility>

using namespace std;
const int INF = (int)1e9;

//#define DEBUG

void solution() {
	int n, k, q;
	vector<int> a;
	cin >> n >> k >> q;
	a.resize(n + 1);
	for (int i = 0; i < q; i++) {
		int val;
		cin >> val;
		a[val] += 1;
	}
	for (int i = 1; i < a.size(); ++i) {
		if (q - a[i] >= k) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
	
}

int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
	solution();
  return 0;		
}


Measured memory_bytes: 1024
#include <stdio.h>

int
main(int argc, char *argv[])
{
  int n, m, l[100000], r[100000];
  int maxl = 0, minr = 100000;
  scanf("%d %d", &n, &m);
  for(int i = 0; i < m; i++){
    scanf("%d %d", &l[i], &r[i]);
    if(l[i] > maxl)maxl = l[i];
    if(r[i] < minr)minr = r[i];
  }
  

  if(minr - maxl + 1 > 0){
  printf("%d\n", minr -maxl + 1);
  }else printf("%d\n", 0);

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;



int main() {
  ll n, k;cin>>n>>k;
  ll ans = n%k ;
  ll value = min(ans, abs(ans-k));
  cout<< value <<endl;
	return 0;
}



Measured memory_bytes: 3616
N=int(input())
A=[int(i) for i in input().split()]
A.sort(reverse=True)
for i in range(N-1):
    if A[i]==A[i+1]:
        A[i+1]=0
    else:
        A[i]=0
A.sort(reverse=True)
print(A[0]*A[1])

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

#define ll long long
#define debug(x) cout<<x<<"DE"<<endl;

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n;
    cin>>n;
    ll v[n+1],c[n+1];
    for(int i=1;i<=n;i++){
        cin>>v[i];
    }
    for(int i=1;i<=n;i++){
        cin>>c[i];
    }
    ll x=0;
    for(int i=0;i<(1<<n);i++){
        ll g=0,d=0;
        for(int j=0;j<n;j++){
            if((i>>j)&1){
                g+=v[j+1],d+=c[j+1];
            }
        }
        x=max(x,g-d);
    }
    cout<<x;
}


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

int main(void) {
    long long n, k, cnt[114514] = {};
    cin >> n >> k;
    k;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        cnt[a] += b;
    }
    
    int now = 1;
    long long sum = 0;
    while (true) {
        if (sum < k && k <= sum + cnt[now]) {
            cout << now << endl;
            break;
        }
        else
            sum += cnt[now];
            now++;
    }
}


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

int a, b;

int main() {
    cin >> a >> b;
    for (int i = 1; i <= 3; i++) {
        if ((a * b * i) % 2) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	vector<int> x(N);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> x[i];
		ans += 2 * min(x[i], abs(x[i] - K));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3620