akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define NMAX 51
using namespace std;
int n;
const long long MOD=1e9+7;
long long p[NMAX][NMAX],r[NMAX][NMAX],sol[NMAX][NMAX],s,k;
void inmultire(long long m1[NMAX][NMAX],long long m2[NMAX][NMAX])	
{
    int i,j,k,m3[n][n];
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            m3[i][j]=0;
            for(k=0;k<n;k++)
            {
                m3[i][j]=(m3[i][j]+m1[i][k]*m2[k][j])%MOD;
            }
        }
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            m1[i][j]=m3[i][j];
        }
    }
}	
void ridicare()	
{
    while(k>0)
    {
        if(k%2==1)
        {
            inmultire(sol,p);
        }
        inmultire(p,p);
        k=k/2;
    }
}
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        sol[i][i]=1;
        for(int j=0;j<n;j++)
            cin>>p[i][j];
    }
    ridicare();
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            s+=sol[i][j];
            s%=MOD;
        }

    }
    cout<<s;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	ll x,cost;
};
int main() {

	int a,b,m;
	ll a2[100001],b2[100001];
	cin>>a>>b>>m;
	ll t=0,mi=100002;
	rep(i,a){
		cin>>a2[i+1];
		mi=min(mi,a2[i+1]);
	}
	t+=mi;
	mi=100001;
	rep(i,b){
		cin>>b2[i+1];
		mi=min(mi,b2[i+1]);
	}
	t+=mi;
	rep(i,m){
		ll x,y,c;
		cin>>x>>y>>c;
		t=min(t,a2[x]+b2[y]-c);
	}
	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

class Main {  
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    double a = in.nextDouble();
    double b = in.nextDouble();
    int C    = in.nextInt();

    double S = 0.5 * a * b * Math.sin(Math.toRadians(C));
    double L = a + b + Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(Math.toRadians(C)));
    double h = b * Math.sin(Math.toRadians(C));
    
    System.out.printf("%5.8f", S);
    System.out.println();
    System.out.printf("%5.8f", L);
    System.out.println();
    System.out.printf("%5.8f", h);
  }
}

Measured memory_bytes: 19256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int z[24][60],n,a,b,k=0;
    for(int i=0;i<24;i++)for(int j=0;j<60;j++)z[i][j]=0;
    for(int w=0;w<2;w++){
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>a>>b;
            z[a][b]=1;
        }
    }
    for(int i=0;i<24;i++){
        for(int j=0;j<60;j++){
            if(z[i][j]==1){
                if(k)cout<<" ";
                if(j<10){cout<<i<<":"<<"0"<<j;k++;}
                else {cout<<i<<":"<<j;k++;}
            }
        }
    }
    cout<<endl;
    return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    int result = 0;
    for (int i = 1; i <= n; ++i) {
        if(i % 2 == 0) continue;
        int temp = 0;
        for (int j = 1; j <= i; ++j) {
            if(i % j == 0)
            {
                temp++;
            }
        }
        if(temp == 8) result++;
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    int sum = 0;
    for(int i = 0; i < n; i++){
        int a;  cin >> a;
        sum += min(a,k - a);
    }
    cout << 2 * sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9 + 7;

int imos[ARRAY_MAX];//y方向
int imos2[ARRAY_MAX];//x方向

int main() {


	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, w, h;
	cin >> n >> w >> h;

	for (int i = 0; i < n; i++)
	{
		int x, y, z;
		cin >> x >> y >> z;
		imos[max(y - z, 0)]++;
		imos[min(y + z, h + 1)]--;
		imos2[max(0, x - z)]++;
		imos2[min(x + z, w + 1)]--;
	}

	for (int i = 0; i <= h; i++)
	{
		imos[i + 1] += imos[i];
	}

	for (int i = 0; i <= h; i++)
	{
		imos2[i + 1] += imos2[i];
	}


	bool flag = true;
	bool flag2 = true;

	for (int i = 0; i < h; i++) {
		//縦方向
		if (imos[i] <= 0)
		{
			flag = false;
			break;
		}
	}
	for (int i = 0; i < w; i++) {
		//横方向
		if (imos2[i] <= 0)
		{
			flag2 = false;
			break;
		}
	}

	if (flag || flag2)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<pair<pair<string, int>, int>> spnum(n);
  rep(i, n) {
    cin >> spnum.at(i).first.first >> spnum.at(i).first.second;
    spnum.at(i).second = i + 1;
    spnum.at(i).first.second = -1 * spnum.at(i).first.second;
  }
  sort(spnum.begin(), spnum.end());
  rep(i, n) cout << spnum.at(i).second << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextInt();
        long b = sc.nextInt();
        long c = sc.nextInt();
        if (c-(a+b)>0 && (c-(a+b))*(c-(a+b))>4*a*b) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
 
    for(int i=0; i<=n/7; i++){
        if((n - 7 * i) % 4 == 0){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
def sieve(n):
    num = [True] * n
    num[0] = num[1] = False
    for i in range(2,int(n**0.5)+1):
        if num[i]:
            for j in range(i**2, n, i):
                num[j] = False
    return [i for i in range(2, n) if num[i]]

prime = sieve(110000)

while True:
	n = int(input())
	if n == 0: break
	print(sum(prime[:n]))

Measured memory_bytes: 7780
import numpy as np
import scipy.stats as stats

n = int(input())
p = np.array([complex(0,0)]*n)
for i in range(n):
    x, y = (int(k) for k in input().split())
    p[i] = complex(x, y)
m = np.zeros((n, n), dtype=np.complex)
m[:, :] = np.nan
for i in range(n):
    for j in range(i+1, n):
        m[i, j] = p[i] - p[j]
        m[j, i] = p[j] - p[i]
mode_val, mode_num =stats.mode(np.array(m).ravel())
print(np.sum(np.all(m != mode_val, axis=1)))

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int h,w,n;
  cin>>n>>h>>w;
  cout << (n-h+1)*(n-w+1) << endl;
  return 0;
}


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

int main() {
  int n,count=0,highest=0;
  cin >> n;
  vi h(n);
  rep(i,n) cin >> h[i];
  rep(i,n){
    if(highest <= h[i]){
      count++;
      highest = h[i];
    }
  }
  cout << count << endl;
}


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

int main(){
    int N;
    int A[114514],B[114514],C[114514];
    long long int sum1=0,sum2=0,Ans=0;
    cin >> N;
    REP(i,N){cin >> A[i];}
    REP(i,N){cin >> B[i];}
    REP(i,N){cin >> C[i];}
    
    sort(A,A+N);
    sort(B,B+N);
    sort(C,C+N);
    REP(i,N){
        
        sum1=distance(A,lower_bound(A,A+N,B[i]));
        sum2=N - distance(C,lower_bound(C,C+N,B[i]+1));
        //cout << sum1 <<" "<< sum2 <<" " << sum1*sum2 << endl;
        Ans+=sum1*sum2;
    }
    cout  << Ans << endl;
	return 0;
}


Measured memory_bytes: 1408
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int num = sc.nextInt();
    ArrayList<Long> array = new ArrayList<Long>();
    long sum = 0;
    long mod = 1000000007;
    for(int i = 0;i < num;i++){
      array.add(sc.nextLong());
      sum += array.get(i);
      sum %= mod;
    }
    long ans = 0;
    for(int i = 0;i < num;i++){
      sum -= array.get(i);
      if(sum < 0){
        sum += mod;
      }
      ans += array.get(i) * sum;
      ans %= mod;
    }
    System.out.println(ans);
  }
}

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

int main(void) {
	// in
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	for(int i = 0; i < n; ++i) std::cin >> a[i];

	// count 4x and 1x
	int n_4x = 0, n_1x = 0;
	for(int i = 0; i < n; ++i) {
		if(a[i] % 4 == 0) n_4x += 1;
		else if(a[i] % 2 != 0) n_1x += 1;
	}
	
	bool is_possible = false;
	if(n_4x >= n_1x) is_possible = true;
	else if(n_4x + 1 >= n_1x && n_4x + n_1x == n) is_possible = true;

	std::cout << (is_possible ? "Yes" : "No") << std::endl;

	return 0;
}


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

class Program {
  static void Main(string[] args) {
    var dg = Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray();
    var spc = new List<int[]>();

    for (int i = 0; i < dg[0]; i++) {
      var a = Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToList();
      a.Insert(0, (i + 1) * 100);
      spc.Add(a.ToArray());
    }

    int ans = -1;
    for (int i = 0; i < spc.Count; i++) {
      int a = dfs(dg[1], 0, 0, i, spc);
      if (a != -1 && (ans == -1 || a < ans)) {
        ans = a;
      }
    }

    Console.WriteLine(ans);
  }

  static int dfs(int g, int q, int s, int i, List<int[]> spc) {
    var os = s;
    s += spc[i][0] * spc[i][1] + spc[i][2];

    if (s >= g) {
      if (s - spc[i][2] >= g) {
        q += (int)Math.Ceiling((g - os) / (float)spc[i][0]);
      } else {
        q += spc[i][1];
      }

      return q;
    } else if (spc.Count == 1) {
      return -1;
    } else {
      q += spc[i][1];
      var bk = spc[i];
      spc.RemoveAt(i);
      int ans = -1;

      for (int j = 0; j < spc.Count; j++) {
        int a = dfs(g, q, s, j, spc);
        if (a != -1 && (ans == -1 || a < ans)) {
          ans = a;
        }
      }

      spc.Insert(i, bk);
      return ans;
    }
  }
}


Measured memory_bytes: 13524
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    l=[list(map(int,input().replace('a','0').replace('b','1').replace('c','2')))[::-1] for _ in range(3)]
    n=0
    z=['A','B','C']
    while True:
        if not l[n]:
            print(z[n])
            break
        n=l[n].pop()

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

bool is_pal(string s){
	int n = s.length();
	bool res = 1;
	rep(i,0,n){
		res &= s[i] == s[n - i-1];
	}
	return res;
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	int n = s.length();
	bool val = (is_pal(s) && is_pal(s.substr(0,(n-1)/2)) && is_pal(s.substr((n+3)/2-1, -1)));
	cout << (val?"Yes":"No") << '\n';
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

	while(n + 1 != c){
		if(a[0] == 2)
			break;
		a[0] = a[a[0] -1];
		c++;
	}
	if(c == n + 1)
		cout << -1 << endl;
	else
		cout << c << endl;

	return 0;
}


Measured memory_bytes: 640
n = int(input())
A = list(map(int, input().split()))
#答えを表示するための行列
Rank = [0]*n
#教室にいる人数をカウントする変数
kyousitu =0
count =0

for i in range(n):
    #まずは教室に入場する
    Rank[A[i]-1] = i+1 
for i in range(n):
   print(Rank[i],end=' ')

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

int main(){
    int n,m;
	double sum=0;
    cin >> n >> m;
    vector<int> ninki(n);
    for(int i=0;i<n;i++){
        int num;
        cin >> num;
        sum += num;
        ninki.at(i) = num;
    }
    stable_sort(ninki.begin(),ninki.end());
    if(ninki.at(n-m) < sum/(4*m)){
            cout << "No" << endl;
            return 0;
    }
    cout << "Yes" << endl;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

vector<vll> d;
const ll INF = 1e18;

void warshall_floyd(int n) { // n: 頂点数
    rep(k, n) { // k : 経由する頂点
        rep(i, n) {
            rep(j, n) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

void Main() {
    int n, m, R; 
    cin >> n >> m >> R;

    vi r(R); 
    rep(i, R) {
        cin >> r[i]; 
        r[i]--;
    }
    
    d = vector<vll>(n, vll(n, INF));
    rep(i, n) d[i][i] = 0;
    
    rep(i, m){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--; b--;
        d[a][b] = c;
        d[b][a] = c;
    }
    
    warshall_floyd(n);
    
    ll ans = INF;
    sort(all(r));
    
    do{
        ll tot = 0;
        rep(i, R-1) tot += d[r[i]][r[i+1]];
        ans = min(ans, tot);
    }while(next_permutation(all(r)));
    
    cout << ans << endl;
    return;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 3788
#!/usr/bin/env python3
from collections import defaultdict,deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    s = SR(n)
    c = Counter(s)
    print("AC x", c["AC"])
    print("WA x", c["WA"])
    print("TLE x", c["TLE"])
    print("RE x", c["RE"])
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 84816
def main():
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    E = int(input())

    l = [A, B, C, D, E]
    c = []
    for i in range(len(l)):
        if i == 0:
            c.append(l[i])
        else:
            if c[0] % 10 > l[i] % 10 and l[i] % 10 != 0:
                c.insert(0, l[i])
            else:
                c.append(l[i])
    ans = 0
    for i in range(len(c)):
        if i == 0:
            ans += c[i]
        else:
            if c[i] % 10 != 0:
                t = c[i] % 10
                ans = ans + c[i] + (10 - t)
            else:
                ans = ans + c[i]
    print(ans)        
main()

Measured memory_bytes: 9240
//stayhome
//staysafe
#include<bits/stdc++.h>
using namespace std;
#define pb push_back

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mxn 2005

int vis[mxn];
int lvl[mxn];
map<int,int>mp,tp;

vector<int>g[mxn];


void bfs(int s)
{

    queue<int>q;
    q.push(s);
    vis[s]=1;
    lvl[s]=0;
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(int i=0;i<g[u].size();i++)
        {
            int v=g[u][i];
           // if(tp[v]) continue;
            if(vis[v]) continue;
            vis[v]++;
            lvl[v]=lvl[u]+1;

            q.push(v);
        }
    }


}



int main()
{
    IOS;

    int n,x,y;
    cin>>n>>x>>y;
    g[x].pb(y);
    g[y].pb(x);

    for(int i=1;i<n;i++)
    {
        g[i].pb(i+1);
        g[i+1].pb(i);
    }


    for(int i=1;i<n;i++)
    {
        bfs(i);
        for(int j=i+1;j<=n;j++)
        {
           // cout<<lvl[j]<<" ";
            int p=lvl[j];

            mp[p]++;
        }
      //  cout<<endl;

        memset(vis,0,sizeof vis);
        memset(lvl,0,sizeof lvl);
        //tp[i]++;

        //for(int j=1;j<n;j++) cout<<mp[i]<<" ";
       // cout<<endl;
    }

    for(int i=1;i<n;i++)
    {
        cout<<mp[i]<<endl;
    }






}


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

using namespace std;

const int MX = 100000;

int a[MX];

int main() {
	int n, m, v, p;
	ignore = scanf("%d %d %d %d", &n, &m, &v, &p);
	for (int i = 0; i < n; i++) ignore = scanf("%d", a + i);
	
	sort(a, a + n);
	
	int ans = p - 1;
	n -= ans;
	v = max(v - ans, 1);
	
	reverse(a, a + n);
	
	int k = 0;
	for (int q = (1 << 20); q > 0; q /= 2) {
		if (k + q >= n) continue;
		
		k += q;
		
		int mx = a[k] + m;
		
		long long S = 0;
		for (int i = 0; i < n; i++) {
			if (i == k) continue;
			
			S += min(mx - a[i], m);
		}
		
		if (S >= (v - 1LL) * m && a[0] <= mx) { }
		else k -= q;
	}
	
	ans += k + 1;
	
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 640
//Name: Book Index
//Level: 2
//Category: やるだけ
//Note:

/**
 * mapを使って語句とページ番号を管理すると、語句は勝手に昇順に並ぶ。
 * ページ番号は出力時にソートする。
 *
 * オーダーは O(N|S| log N)。
 * ただしNは語句の個数、|S|は語句の最大長。
 */
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

bool solve() {
    string word;
    int page;
    map<string,vector<int>> dict;
    while(cin >> word >> page) {
        dict[word].push_back(page);
    }
    for(auto &e : dict) {
        cout << e.first << endl;
        sort(begin(e.second), end(e.second));
        for(int i = 0; i < (int)e.second.size(); ++i) {
            if(i > 0) cout << ' ';
            cout << e.second[i];
        }
        cout << endl;
    }
    return false;
}

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

    while(solve()) ;
    return 0;
}

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

typedef struct{
    int val;
    string name;
    int point;
}Rec;

int main(){
    //input
    int N;
    cin >> N;
    Rec rec[N];
    for(int i=0;i<N;i++){
        rec[i].val=i+1;
        cin >> rec[i].name >> rec[i].point;
    }

    //process
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(rec[i].name>rec[j].name){
                Rec tmp=rec[i];
                rec[i]=rec[j];
                rec[j]=tmp;
            }
        }
    }

    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(rec[i].name==rec[j].name && rec[i].point<rec[j].point){
                Rec tmp=rec[i];
                rec[i]=rec[j];
                rec[j]=tmp;
            }
        }
    }

    //output
    for(int i=0;i<N;i++){
        cout << rec[i].val <<endl;
    }
    return 0;
}

Measured memory_bytes: 384
import numpy as np
 
X,N = map(int,input().split())
p = input()
 
if N != 0:
    
    p_list = [int(n) for n in p.split()]
    
    X_near = np.array(list(range(int(np.ceil(X - N/2 - 1)), int(np.floor(X + N/2)) + 2)))
 
    remain_list = []
 
    for i in X_near:
        if i not in p_list:
            remain_list.append(i)
        
 
    remain_array = np.array(remain_list)
    min_bool = np.abs(X - remain_array).min() == np.abs(X - remain_array)
    print(remain_array[min_bool].min())
    
if N == 0:
    print(X)

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

int main(){
	int n;
	cin>>n;
	int p1=0,p2=0;
	for(int i=0; i<n; i++){
		string str1,str2;
		cin>>str1>>str2;
		if ( str1 == str2 ){
			p1++;
			p2++;
		}else if ( str1 < str2 ){
			p2+=3;
		}else if ( str1 > str2 ){
			p1+=3;
		}
	}
	cout<<p1<<" "<<p2<<endl;
	return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define REPE(i, a, b) for (int i = (a); i <= int(b); ++i)
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()
#define PB push_back
#define EB emplace_back
using LL = long long;
using PII = pair<int, int>;
#define F first
#define S second

int n;
PII a[222];

LL dp[222][222][222];

LL p[222];
const LL mod = 998244353;

PII operator-(const PII &a, const PII &b) {
  return {a.F - b.F, a.S - b.S};
}
ostream& operator<<(ostream &os, const PII &a) {
  os << "(" << a.F << "," << a.S << ")";
  return os;
}

int dir(int x, int y, int z) {
  PII v1 = a[y] - a[x];
  PII v2 = a[z] - a[x];
  LL r = 1LL * v1.F * v2.S - 1LL * v1.S * v2.F;
  return r == 0 ? 0 : (r > 0 ? 1 : -1);
}

bool f(int x, int y, int z) {
  PII v1 = a[y] - a[x];
  PII v2 = a[z] - a[x];
  return 1LL * v1.F * v2.S - 1LL * v1.S * v2.F > 0;
}

LL g(int x, int y, int z) {
  LL &r = dp[x][y][z];
  if (r >= 0) return r;
  int c1 = 0, c2 = 0;
  r = 0;
  for (int i = x + 1; i < n; ++i) {
    if (y != i && z != i) {
      if (dir(x, y, i) >= 0 && dir(y, z, i) >= 0) {
        int t = dir(z, x, i);
        if (t >= 0) {
          if (t == 0) c1++;
          else if (t == 1) c2++;
        }
      }
      if (f(x, z, i) && f(y, z, i)) {
        r += g(x, z, i);
        r %= mod;
      }
    }
  }
  r = (r * p[c2] + p[c1 + c2]) % mod;
  return r;
}


int main() {
  p[0] = 1;
  REPE(i, 1, 221) p[i] = p[i - 1] * 2 % mod;
  scanf("%d", &n);
  REP(i, n) scanf("%d%d", &a[i].F, &a[i].S);
  sort(a, a + n);
  memset(dp, -1, sizeof dp);
  LL ans = 0;
  REP(i, n) {
    for (int j = i + 1; j < n; ++j) {
      for (int k = i + 1; k < n; ++k) if (j != k && f(i, j, k)) {
        ans += g(i, j, k);
        ans %= mod;
        // cout << a[i] << ' ' << a[j] << ' ' << a[k] << ": " << g(i, j, k) << endl;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}



Measured memory_bytes: 85760
import math
import numpy
K = int(input())

total = 0

ab_list = []
ab_ap = ab_list.append
for a in range(1,K+1) :
    for b in range(1,K+1) :
        ab_ap(math.gcd(a,b))

for ab in ab_list :
    for c in range(1,K+1) :
        total += math.gcd(ab,c)

# for a in range(1,K+1) :
#     for b in range(1,K+1) :
#         for c in range(1,K+1) :
#             total += math.gcd(math.gcd(a,b),c)

print(total)

Measured memory_bytes: 27280
#include <stdio.h>

#define N 32

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    int d[ N ], n;
    int r = 32;

    scanf ( "%d", &n );
    if ( !( n ) ) break ;
    for ( i = 0; i < n; ++i )
    {
      scanf ( "%d", d + i );
    }

    for ( i = 0; r > 0; ++i )
    {
      if ( i & 1 )
      {
        r -= d[ ( i >> 1 ) % n ];
        if ( r < 0 ) r = 0;
      }
      else
      {
        r -= ( r - 1 ) % 5;
      }
      printf ( "%d\n", r );
    }
  }

  return ( 0 );
}

Measured memory_bytes: 0
import java.util.*;

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

        int N = sc.nextInt();
        int x = 0; 
        int ans = 0;

        for(int i=1; i<=N; i+=2){
            for(int j=1; j<=i; j++){
                if(i%j==0){
                    x += 1;
                }
            }
            if(x==8){
                ans += 1;
            }
            x = 0;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
using System;
namespace OJ_C_Sharp {
	class Program {
		static void Main(string[] args) {
			int n = int.Parse(Console.ReadLine());
			int fn = 0;
			int n0 = n;
			while (n0>0){
				fn += n0 % 10;
				n0 /= 10;
			}
			if (n%fn==0){
				Console.WriteLine("Yes");
			}
			else{
				Console.WriteLine("No");
			}
		}
	}
}


Measured memory_bytes: 13140
#include "stdio.h"
#include "iostream"
using namespace std;

int main()
{
	int N;
	int temp;
	int ret = 0;
	cin >> N;
	temp = N;
	while (temp / 10)
	{
		temp = temp / 10;
		ret++;
	}
	if (ret == 0)
	{
		ret = N;
	}
	else if (ret==1)
	{
		ret = 9;
	}
	else if (ret == 2)
	{
		ret = 9 + N - 100+1;
	}
	else if (ret == 3)
	{
		ret = 9 + 900;
	}
	else if (ret == 4)
	{
		ret = 9 + 900 + N - 10000 + 1;
	}
	else if (ret == 5)
	{
		ret = 9 + 900 + 90000;
	}
	cout << ret;
	return 0; 
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    s=input()
    s2=list(s.replace('BC','D'))
    N=len(s2)
    ans=0
    c=0
    for i in range(N):
        if s2[i]=='A':
            c+=1
        elif c!=0 and s2[i]=='D':
            ans+=c
        else:
            c=0
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 63088
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> c(m);
	vector<int> dp(n+1);
	for (int i = 0; i < n+1; i++) {
		dp[i] = i;
	}
	for (int i = 0; i < m; i++) {
		cin >> c[i];
		dp[c[i]] = 1;
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			if (j > i-j) {
				break;
			}
			dp[i] = min(dp[i], dp[j]+dp[i-j]);
		}
	}
	cout << dp[n] << endl;
	return 0;
}

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

char calc (string s) {
    char c = s[s.size()-1];
    int sum = 0;
    for (int i = 0; i < s.size() - 1; i++) {
        sum += s[i] == '-' ? -1 : 1;
    }

    if (c == '?') {
        c = 'A';
    } else {
        c = 'A' + (((c - 'A') + 26 + (sum % 26)) % 26);
    }

    return c;
}

string dfs (string str) {
    int i = 0;
    string res = "";

    string tmp = "";
    for (int i = 0; i < str.size(); i++) {
        if (str[i] == '+' || str[i] == '-') {
            tmp += str[i];
        } else if ('A' <= str[i] && str[i] <= 'Z' || str[i] == '?') {
            tmp += str[i];
            res += calc(tmp);
            tmp = "";
        } else if (str[i] == '[') {
            int count = 1;
            i++;
            string str_ = "";
            while (count) {
                if (str[i] == '[') count++;
                if (str[i] == ']') count--;
                if (count) {
                    str_ += str[i];
                }
                i++;
            }
             i--;
            str_ = dfs (str_);
            for (int j = str_.size()-1; j >= 0; j--) {
                res += str_[j];
            }
        }
    }

    return res;
}

int main () {
    string str;
    while (cin >> str, str != ".") {
        cout << dfs(str) << endl;
    }

    return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin>>s;
  in sm=0;
  forn(i,sz(s)-1)
    sm+=(s[i]!=s[i+1]);
  cout<<sm<<endl;
  return 0;
}


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

const int maxn = 110;
int n, ans1 = INT_MAX, sz[maxn];
long long ans2;
vector<int> G[maxn];

int main() {
    scanf("%d", &n);
    for (int i = 1, u, v; i < n; i++) {
        scanf("%d %d", &u, &v);
        G[u].push_back(v), G[v].push_back(u);
    }
    int mxd;
    function<void(int, int)> dfs = [&](int v, int fa) {
        mxd = 0, memset(sz, 0, sizeof(sz));
        function<void(int, int, int)> dfs2 = [&](int v, int fa, int d) {
            int s = 0;
            for (int u : G[v]) if (u ^ fa) s++, dfs2(u, v, d + 1);
            mxd = max(mxd, d), sz[d] = max(sz[d], s);
        };
        dfs2(v, 0, 0);
        long long tot = 1;
        for (int i = 0; i < mxd; i++) tot *= sz[i];
        if (mxd < ans1) ans1 = mxd, ans2 = tot;
        else if (mxd == ans1) ans2 = min(ans2, tot);
        for (int u : G[v]) if (u ^ fa) {
            mxd = 0, memset(sz, 0, sizeof(sz));
            dfs2(u, v, 0), dfs2(v, u, 0);
            long long tot = 2;
            for (int i = 0; i < mxd; i++) tot *= sz[i];
            if (mxd < ans1) ans1 = mxd, ans2 = tot;
            else if (mxd == ans1) ans2 = min(ans2, tot);
            dfs(u, v);
        }
    };
    dfs(1, 0), printf("%d %lld\n", ans1 + 1, ans2);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<time.h>
#define ll long long 
using namespace std;
ll X,K,D;
ll false1(ll x,ll k,ll d){
	x=abs(x);
	if(x==0){
		if(k%2==0){
			return 0;
		}else 
		    return d;
	}else {
	    ll num=x/d;
		if(((x-k*d)>=0)){
			return x-k*d;
		}else{
			ll kk=k-num;
			if(kk%2==0){
				return abs(x-num*d);
			}else{
				return abs(x-num*d-d);
			}
		}
	}
}
ll true1(ll x,ll k,ll d){
	x=abs(x);
	if(x==0){
		if(k%2==0){
			return 0;
		}else 
		    return d;
	}else {
	    ll num=x/d;
		if(num>=k){
			return x-k*d;
		}else{
			ll kk=k-num;
			if(kk%2==0){
				return abs(x-num*d);
			}else{
				return abs(x-num*d-d);
			}
		}
	}
}
int main(){
//	srand((unsigned)time(NULL));
//	while(true){
	cin>>X>>K>>D;
	cout<<true1(X,K,D)<<endl;
//	cout<<false1(X,K,D)<<endl;
//		cout<<X<<" "<<K<<" "<<D<<endl;
//		ll T=true1(X,K,D);
//		ll F=false1(X,K,D);
//		if(T!=F){
//			cout<<"true = "<<" "<<T<<endl;
//			cout<<"false = "<<" "<<F<<endl;
//			break;
//		}
//	}
	return 0;
}

Measured memory_bytes: 3216
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;

    ll L, R;
    cin >> L >> R;

    if (L / 2019 != R / 2019) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = INF;
    reps(i, L, R) {
        reps(j, L + 1, R + 1) { chmin(ans, (i * j) % 2019); }
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P, ll> PL;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll h,w;
string s[606];

int main(){
  cin>>h>>w;
  rep(j,w+2){
    s[0]+=".";
    s[h+1]+=".";
  }
  repl(i,1,h+1){
    string in;
    cin>>in;
    s[i]="."+in+".";
  }
  w+=2; h+=2;
  vector<PL> ps;
  rep(i,h-1)rep(j,w-1){
    if(s[i][j]=='#'&&s[i][j+1]=='#'&&s[i+1][j]=='#'&&s[i+1][j+1]=='.'){ // inc
      ps.push_back(PL(P(j,h-2-i),1));
    }
    if(s[i][j]=='.'&&s[i][j+1]=='.'&&s[i+1][j]=='.'&&s[i+1][j+1]=='#'){ // inc
      ps.push_back(PL(P(j,h-2-i),1));
    }

    if(s[i][j]=='.'&&s[i][j+1]=='#'&&s[i+1][j]=='#'&&s[i+1][j+1]=='#'){ // dec
      ps.push_back(PL(P(j,h-2-i),0));
    }
    if(s[i][j]=='#'&&s[i][j+1]=='.'&&s[i+1][j]=='.'&&s[i+1][j+1]=='.'){ // dec
      ps.push_back(PL(P(j,h-2-i),0));
    }
  }

  sort(all(ps),[=](const PL& a,const PL& b){
    ll l=a.fi.se*b.fi.fi,r=a.fi.fi*b.fi.se;
    if(l==r)return a.se < b.se;
    else return l > r;
  });

  ll res=1,crt=1;
  rep(i,ps.size()){
    if(ps[i].se)crt++;
    else crt--;
    maxch(res,crt);
  }
  cout<<res<<endl;
  return 0;
}



Measured memory_bytes: 6636
let decrypt str =
  let alpha_l = [1; 3; 5; 7; 9; 11; 15; 17; 19; 21; 23; 25] in (*26*)
  let solve beta =
    let check alpha =
      let f gu =
        let g = (int_of_char gu) - (int_of_char 'a') in
        if g < 0 || g >= 26 then gu else
          let ans = (alpha * g + beta) mod 26 in
          char_of_int (ans + (int_of_char 'a'))
      in
      let conv = String.map f str in
      let rec pad from =
        let next = try String.index_from conv from ' '
                   with Not_found -> String.length conv
        in
        if (next - from = 4) && (let s = String.sub conv from 4 in s = "this" || s = "that") then
          true
        else
          if next <> String.length conv then
            pad (next+1)
          else false
      in
      let res = pad 0 in
      if res then Printf.printf "%s\n" conv;
      res
    in
    List.exists check alpha_l
  in
  let rec rep = function
      26 -> ()
    | n -> if not (solve n) then rep (n+1)
  in
  rep 0

let () =
  let n = read_int () in
  let rec solve = function
      0 -> ()
    | n -> decrypt (read_line ()); solve (n-1)
  in
  solve n

Measured memory_bytes: 2680
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

int main()
{
    int a,b,c;
    while(scanf("%d%d%d",&a,&b,&c)==3)
        {
            if(a==b)
               a=c;
            else
            {
                if(a==c)
                    a=b;
            }
            printf("%d\n",a);
        }
    return 0;
}


Measured memory_bytes: 256
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as MP
import qualified Data.Set as ST
import qualified Data.Sequence as SQ
import Data.Array
import Data.Array.ST
import Data.Array.IO
import Data.Maybe
import Data.Ratio
import Data.Char
import Data.Bits
import Data.List
import Data.Tuple
import Data.Functor
import Data.IORef
import Data.STRef
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Debug.Trace

dfs :: Int -> String -> [String]
dfs n acc
  | length acc == n = [reverse acc]
  | otherwise = concat [dfs n (c:acc) | c <- ['a'..succ m]]
    where
      m = maximum acc

main = do
  n <- readLn :: IO Int
  let res = sort $ dfs n "a"
  mapM_ putStrLn res

Measured memory_bytes: 47612
while(h,w=gets.split.map &:to_i)!=(x,y=[0,0]);m,f=[],[];h.times{f.push [1]*w;m.push gets};b=1;while(?.<c=m[y][x])&&0<b=f[y][x]do;f[y][x]=0;c[?v]?y+=1:c[?^]?y-=1:c[?<]?x-=1:x+=1;end;puts ["LOOP","#{x} #{y}"][b]end

Measured memory_bytes: 6148
#include <bits/stdc++.h>
using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int n;
	cin>>n;
	int x,y;
	bool b[101];
	for(int i=0;i<n;i++)
    {
        cin>>x>>y;
        if(x==y)
            b[i]=1;
        else b[i]=0;
    }
    for(int i=1;i<n-1;i++)
    {
        if(b[i-1]&&b[i]&&b[i+1])
        {
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;


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

	if (k % 2 == 0) {
		cout << (k / 2) * (k / 2) << endl;
	}
	else {
		cout << (k / 2) * ((k / 2) + 1) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
n, m = gets.chomp.split(" ").map(&:to_i)
ans = Array.new(n, 0)
m.times do
    a, b = gets.chomp.split(" ").map(&:to_i)
    ans[a-1] += 1
    ans[b-1] += 1
end

puts ans.join("\n")

Measured memory_bytes: 1788
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  as <- readInts
  print $ f' as

f' :: [Int] -> Int
f' as@[a,b,c,x,y]
  | 2*c < a + b = 2*c*min x y + min (g a b x y)
                                    (2*c*abs (x-y))
  | otherwise   = a*x + b*y
  where
    g a b x y
      | x < y     = (y-x)*b
      | otherwise = (x-y)*a

Measured memory_bytes: 380
N, K = map(int, input().split())
ans = 0

if K == 0:
  print(N**2)
  exit()

for r in range(K, N):
  for q in range((N-r)//(r+1) + 1):
    if q == 0:
      ans += N - r
    else:
      ans += max(0, (N-r)//q - r)

print(ans)

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

int main() {
    int n;
    cin >> n;
    vector<ll> r(n);
    rep(i, n) cin >> r[i];
    ll maxa = -1000000000;
    ll mina = r[0];
    for(int i = 1; i < n; i++) {
        maxa = max(maxa, r[i]-mina);
        mina = min(mina, r[i]);
    }
    cout << maxa << endl;
    return 0;
}


Measured memory_bytes: 4424
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const int MINF = -1e9;


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

	vector<int> x;
	rep(i, m) {
		int a;
		cin >> a;
		x.push_back(a);
	}

	if (x.size() <= n) {
		cout << 0 << endl;
		return 0;
	}
	sort(x.begin(), x.end());
	vector<int> d(m-1);
	rep(i, m - 1) {
		d[i] = x[i + 1] - x[i];
	}
	sort(d.begin(), d.end());
	
	rep(i, n-1) {
		d.pop_back();
	}

	int ans = 0;
	rep(i, d.size()) {
		ans += d[i];
	}
	cout << ans << endl;
	return 0;
}


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


Measured memory_bytes: 2048
// in case of multiple test cases and N=1e5 don't intialize arrays as global except for graph vector-array
// always check whether or not you are doing mod of a negative number
// always use 1LL instead of 1
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

#define double      	long double
#define int         	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
// just comment the line below in case of interactive problems
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x,y) 		memset(x, y, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N=2e5 + 5;
const int MOD=1e9 + 7;

int n,m;
vector<int> g[N];
int vis[N];
int c;

void dfs(int u)
{
	vis[u]=1;
	c++;
	for(int v: g[u])
	{
		if(vis[v]==0)
			dfs(v);
	}
}

int32_t main()
{
	IOS;
	int T=1;
	//cin >> T;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		cin >> n >> m;
		rep(i,1,m)
		{
			int x,y;
			cin >> x >> y;
			g[x].pb(y);
			g[y].pb(x);
		}
		int ans = -1;
		rep(i,1,n)
		{
			c = 0;
			if(vis[i]==0)
				dfs(i);
			ans = max(ans,c);
		}
		cout << ans << endl;
	}
}

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

using namespace std;

const int INF=1e9+5;

int main(){
	int n;
	scanf("%d",&n);
	vector<int> h(n+1,0);
	h[0]=INF;
	for(int i=1;i<n+1;i++){
		scanf("%d",&h[i]);
	}
	vector<int> dp(n+1,INF);
	dp[0]=0;dp[1]=0;
	for(int i=2;i<n+1;i++){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	/*for(int i=1;i<n+1;i++){
		printf("%d ",dp[i]);
	}*/
	//printf("\n");
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int N;
int A[15];

int main(void)
{
	cin >> N;
	for(int i = 0; i < N; i++) cin >> A[i];
	
	int n = 1;
	for(int i = 0; i < N; i++) n *= 3;
	
	int m = 1;
	for(int i = 0; i < N; i++){
		if(A[i] % 2 == 0) m *= 2;
	}
	
	cout << n - m << endl;
	return 0;
}

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

void solve(long long N, long long M, long long P, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    vector<long long> dp(N, -(1ll<<31));
    dp[0] = 0;
    for(int t=0;t<2*M;++t){
        for(int k=0;k<M;++k){
            dp[B[k]-1] = max(dp[B[k]-1], dp[A[k]-1] + C[k] - P);
        }
    }
    long long res = dp[N-1];
    vector<long long> dp2(N, -(1ll<<31));
    dp2[0] = 0;
    for(int t=0;t<4*M;++t){
        for(int k=0;k<M;++k){
            dp2[B[k]-1] = max(dp2[B[k]-1], dp2[A[k]-1] + C[k] - P);
        }
    }
    vector<bool> b1(N), b2(N);
    b1[0]=1;
    b2[N-1]=1;
    for(int t=0;t<2*M;++t){
        for(int k=0;k<M;++k){
            b1[B[k]-1] = b1[B[k]-1]|b1[A[k]-1];
            b2[A[k]-1] = b2[A[k]-1]|b2[B[k]-1];
        }
    }
    for(int i=0;i<N;++i){
        if(b1[i]&&b2[i]&&dp[i]<dp2[i]){
            cout<<-1<<endl;
            return;
        }
    }
    if(dp[N-1]>res||res==-(1ll<<31)){
    }
    else{
        cout<<max(res, 0ll)<<endl;
    }
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long P;
    scanf("%lld",&P);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    std::vector<long long> C(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
        scanf("%lld",&C[i]);
    }
    solve(N, M, P, std::move(A), std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 384
/*
      @author: Charan Sai
*/
#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define ppi pair<int, int>
#define endl "\n"
#define nl cout << "\n"
#define deb(x) cout << #x << " " << x << endl;

const int N = 1e5 + 10;
int height[N];
int n, k;

// 1. Backtrack Solution = 2^N Time
int minCost1(int i) {
    // Base Cases
    if(i == n) return 0;
    if(i > n) return INT_MAX;

    // Choice
    int cost1 = minCost1(i+1) + abs(height[i+1] - height[i]);
    int cost2 = minCost1(i+2) + abs(height[i+2] - height[i]);

    return min(cost1, cost2);
}

// 2. Top-Down Solution = Remove read-only arguments and redundant arguments
// and cache the results
// Time = (Range of possible values of the variable arguments) * (Time Compl of each function call)
// O(N*K) time
int dp[N];
int minCost2(int i) {
    // Base Cases
    if(i == n) return 0;

    if(dp[i] != -1) return dp[i];

    // Choice
    dp[i] = INT_MAX;
    for(int j = i + 1; j <= i + k; ++j) {
        if(j > n) break;
        dp[i] = min(dp[i], 
                    minCost2(j) + abs(height[j] - height[i])
                );
    }
    return dp[i];
}

// 3. Bottom-Up Solution
int minCost3() {
    dp[n] = 0;
    dp[n+1] = INT_MAX;
    for(int i = n - 1; i >= 1; --i) {
        int cost1 = dp[i+1] + abs(height[i+1] - height[i]);
        int cost2 = dp[i+2] + abs(height[i+2] - height[i]);        
        dp[i] = min(cost1, cost2);
    }
    return dp[1];
}


int32_t main() {
      IOS;
      int t = 1;
      //cin >> t;
      while(t--) {
        memset(dp, -1, sizeof(dp));
        cin >> n; cin >> k;
        for(int i = 1; i <= n; ++i) cin >> height[i];
        cout << minCost2(1) << endl;
      }
}

Measured memory_bytes: 4992
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
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<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<28;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const int mod=1e9+7;
const vi emp;
const int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

int n;
vi a;

int main(){
	cin>>n;
	a=vi(n);
	int M=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		M=max(M,a[i]);
	}
	vi b(M+1);
	for(int i=0;i<n;i++) b[a[i]]++;
	for(int i=M;i>=(M+1)/2;i--) b[i]-=2;
	if(M%2==0) b[M/2]++;
	for(int i=0;i<=M;i++) if(b[i]<0){
		cout<<"Impossible"<<endl;
		return 0;
	}
	for(int i=0;i<=M;i++) if(b[i]){
		if(i>=(M+1)/2+1) cout<<"Possible"<<endl;
		else cout<<"Impossible"<<endl;
		return 0;
	}
	cout<<"Possible"<<endl;
}

Measured memory_bytes: 256