akhauriyash/Code-Regression huggingface dataset:
/*
                    NAYEEM
    Information and Communication Engineering ,
            University of Rajshahi
*/
#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define ll long long
#define pii pair<int,int>
#define uu first
#define vv second


#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scd(x) scanf("%lf",&x)

#define pfi(x) printf("%d",x)
#define pfl(x) printf("%lld",x)
#define pfd(x) printf("%lf",x)
#define pfc(x) printf("Case %d: ",x)
#define ps printf(" ")
#define pn printf("\n")
#define pb(x) push_back(x)
#define ppb(x) pop_back(x)
#define pf(x) push_front(x)
#define ppf(x) pop_front(x)
#define in(x,y) insert({x,y})
#define sv(a) sort(a.begin(),a.end())
#define zero(arr,a) memset(arr,a,sizeof arr)
#define mx 1005

int fx[]={0,1,1,1,0,-1,-1,-1};
int fy[]={1,1,0,-1,-1,-1,0,1};



int main()
{
    //IOS
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b,c;
    cin>>a>>b>>c;
    int k = b+c;
    int mm = min(a,k);
    cout<<c-(mm-b)<<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++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N, T;
  cin >> N >> T;
  vector<int> A(N);
  REP(i,N) cin >> A[i];

  vector<int> dp(N);
  dp[N - 1] = A[N - 1];
  for(int i = N - 2; i >= 0; --i) {
    dp[i] = max(dp[i + 1], A[i]);
  }
  int x = 0;
  REP(i,N) x = max(x, dp[i] - A[i]);

  int res = 0;
  vector<pair<int,int>> B(N);
  REP(i,N) B[i] = make_pair(A[i], i);
  sort(ALL(B));
  vector<int> C(N);
  REP(i,N) C[i] = B[i].first;
  REP(i,N) {
    auto f = equal_range(ALL(C), A[i] + x);
    if(f.second - f.first == 1 && B[f.first - C.begin()].second > i) {
      ++res;
    }
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 2176
#include <stdio.h>

int main(int argc, char** argv)
{
  int d;
  
  while (fscanf(stdin, "%d", &d) == 1) {
    int s = 0;
    
    for (int i = 0; i < 600 / d; i ++)
      s += i * d * i * d * d;
    
    fprintf(stdout, "%d\n", s);
  }
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class hawawa
{
  static Printer sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };

  static void Main()
  {
    Console.SetOut(sw);
    solve();
    Console.Out.Flush();
  }
  
  static void solve()
  {
    Scanner scanner = new Scanner();
    int n = scanner.nextInt();
    SortedSet<int> set = new SortedSet<int>();
    for(int i = 0; i < n; i++)
    {
      int num = scanner.nextInt();
      if (set.Contains(num)) set.Remove(num);
      else set.Add(num);
    }
    Console.WriteLine(set.Count());
  }
}

class Scanner
{
  string[] s;
  int i;


  char[] cs = new char[] { ' ' };

  public Scanner()
  {
    s = new string[0];
    i = 0;
  }

  public string next()
  {
    if (i < s.Length) return s[i++];
    string st = Console.ReadLine();
    while (st == "") st = Console.ReadLine();
    s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
    i = 0;
    return next();
  }

  public int nextInt()
  {
    return int.Parse(next());
  }

  public long nextLong()
  {
    return long.Parse(next());
  }

  public double nextDouble()
  {
    return double.Parse(next());
  }

}

class Printer : StreamWriter
{
  public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
  public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
  public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { }
}

Measured memory_bytes: 21024
S = input()
N = len(S)
dp = [[0 for i in range(13)] for j in range(N+5)]
mod = 10**9+7

dp[N][0] = 1
# DP = np.array(dp)
# print(DP)
mul = 1
for i in reversed(range(N)):
    if(S[i]=='?'):
        c = -1
    else:
        c = int(S[i])

    for j in range(10):
        if(c != -1 and c != j):
            continue
        for k in range(13):
            dp[i][(j*mul+k)%13] += dp[i+1][k]
            dp[i][(j*mul+k)%13] %= mod
    mul *=10
    mul %=13

# DP = np.array(dp)
result = dp[0][5]
# print(DP)
print(result)

Measured memory_bytes: 67420
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int r = sc.nextInt();
        // スペース区切りの整数の入力

        double a = r * 2 * 3.14;

        System.out.println(a);



    }
}



Measured memory_bytes: 35980
package main

import(
      "fmt"
)

func main(){
  var n int
  fmt.Scan(&n)
  fmt.Println(1110-n)
}

//====  ↓↓↓ template functions ↓↓↓  ======================

func min(a, b int) int{
  if a < b {
    return a
  }
  return b
}

func max(a, b int) int{
  if a > b {
    return a
  }
  return b
}

func abs(x int) int{
  if x < 0 {
    return -x
  }
  return x
}

func gcd(a, b int) int{
  if b == 0 {
    return a
  }else{
    return gcd(b, a%b)
  }
}

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

Measured memory_bytes: 512
package main

import "fmt"

func main() {
	var n, d, x int
	fmt.Scan(&n, &d, &x)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&as[i])
	}

	ans := x
	for i := 0; i < n; i++ {
		a := as[i]
		for j := 0; j*a+1 <= d; j++ {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1776
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main(void){
    int i;
    int flag = 0;
    char s[11];
    scanf("%s", s);
    if ( s[0] != 'A' ) {
        printf("WA\n");
        return 0;
    }
    if ( !islower(s[1]) || !islower(s[strlen(s)-1]) ) {
        printf("WA\n");
        return 0;
    }
    for ( i = 2; i < strlen(s) - 1; i++ ) {
        if ( s[i] == 'C' || !islower(s[i]) ) {
            flag += 1;
        }
    }
    if ( flag != 1 ) {
        printf("WA\n");
    } else {
        printf("AC\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define endl       "\n"
#define ll         long long
#define pb         push_back
#define FIO        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define NUM        1000000007
#define MOD        998244353
#define F          first
#define S          second
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a-1;i>=b;i--)
#define vi         vector<ll>
#define pii        pair<ll,ll>
#define vpi        vector<pii>
#define mi         map<ll,ll>
#define mpi        map<pii,ll>
#define all(v)     (v).begin(),(v).end()
#define rall(v)    (v).rbegin(),(v).rend()
#define fac(a)     tgamma(a+1)

/*bool compare(const pair<ll,ll> &a,const pair<ll,ll> &b)
{ 
    return (a.second < b.second);      // compare function for sorting modification
}

vector<ll> primes;
vector<bool> PRIME(1000005,true);       // prime no.s less than 10^6
void sieve(ll n)                        // PRIME[i]=true => i=prime no.
{  PRIME[0]=false;PRIME[1]=false;
    for (ll p=2; p*p<=n; p++) { 
        if (PRIME[p] == true) { 
            for (ll i=p*p; i<=n; i += p){PRIME[i]=false;} 
        } 
    } rep(i,2,n+1){if(PRIME[i]){primes.pb(i);}}
}  

ll nCr[1001][1001];
void combination(ll n)                  // nCr values
{
    rep(i,0,n+1){
        rep(j,0,i+1){
            if(j==0 or j==i)nCr[i][j]=1;
            else nCr[i][j]=(nCr[i-1][j-1]+nCr[i-1][j])%NUM;
        }
    }
}

#define N  1000005
*/
ll a,b,c,d,e,i,j,k,l,m,n,q,p,r,u,v,w,x,y,z,mn,mx;

//ll dp[2005][2005];


int main() 
{
    FIO;
    ll t=1;
    //cin >> t;
    while(t--)
    {
        cin>>n>>m>>k;
        vi a(n),b(m);
        rep(i,0,n){cin>>a[i];}
        rep(i,0,m){cin>>b[i];}
        i=0;
        ll ans=0;
        ll curr=0;
        while(i<n and curr+a[i]<=k)curr+=a[i++];
        j=0;
        while(j<m and curr+b[j]<=k)curr+=b[j++];
        
        ans=max(ans,i+j);
        i--;
        while(i>=0 and j<m)
        {
            curr-=a[i--];
            while(j<m and curr+b[j]<=k)curr+=b[j++];
            ans=max(ans,i+1+j);
        }
        cout<<ans;
        
        
        
        
        
        
        
        
        
        
        
        
        h:;
        cout<<endl;
    }
    
    return 0;
}


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

int main()
{
	auto lcm = [](int64_t a, int64_t b) {
		auto gcd = [](int64_t a, int64_t b) {
			while (b)
			{
				int64_t tmp = b;
				b = a % b;
				a = tmp;
			}
			return a;
		};
		return a / gcd(a, b) * b;
	};

	int64_t a, b, c, d;
	cin >> a >> b >> c >> d;

	cout << max(int64_t(0), b - a + 1 - b / c + (a - 1) / c - b / d + (a - 1) / d + b / lcm(c, d) - (a - 1) / lcm(c, d)) << endl;

	return 0;
}

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

int main() {
  int n, m, c; cin >> n >> m >> c;
  vector<int> b(m);
  vector< vector<int> > a(n,vector<int>(m));
  int count=0;
  for (int i=0;i<m;i++) {
    cin >> b.at(i);
  }
  for(int i=0;i<n;i++) {
    int ans=0;
    for (int j=0;j<m;j++) {
      cin >> a.at(i).at(j);
      ans+= a.at(i).at(j)*b.at(j);
    }
   ans+=c;
    if(ans>0) {
        count++;
      }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

struct node {
    node *l = nullptr;
    node *r = nullptr;
    node *p = nullptr;
    long long val = 0;
    long long sum = 0;
    node() {}
};

void fix(node *x) {
    x->sum = x->val;
    if (x->l) x->sum += x->l->sum;
    if (x->r) x->sum += x->r->sum;
}

void rot(node *x) {
    node *y = x->p, *z = y->p;
    if (z) {
        if (y == z->l) z->l = x;
        if (y == z->r) z->r = x;
    }
    x->p = z; y->p = x;
    if (x == y->l) {
        y->l = x->r; x->r = y;
        if (y->l) y->l->p = y;
    } else {
        y->r = x->l; x->l = y;
        if (y->r) y->r->p = y;
    }
    fix(y);
}

node *splay(node *x) { while (x->p) { node *y = x->p, *z = y->p;
        if (z) rot((x == y->l) == (y == z->l) ? y : x);
        rot(x);
    }
    fix(x);
    return x;
}

void join(node *x, node *y) {
    if (!x || !y) return;
    splay(x);
    while (x->r) x = x->r;
    splay(x);
    splay(y);
    x->r = y;
    y->p = x;
}

node *split_left(node *x) {
    splay(x);
    node *y = x->l;
    if (y) y->p = x->l = nullptr;
    return y;
}

node *split_right(node *x) {
    splay(x);
    node *y = x->r;
    if (y) y->p = x->r = nullptr;
    return y;
}

void rotate(node *x) {
    join(x, split_left(x));
}


pair<node *, node *> link(node *u, node *v) {
    node *uv = new node();
    node *vu = new node();
    rotate(u);
    rotate(v);
    join(u, uv);
    join(uv, v);
    join(v, vu);
    return { uv, vu };
}

void cut(pair<node *, node *> e) {
    rotate(e.first);
    split_right(e.first);
    split_left(e.second);
    split_right(e.second);
    delete e.first;
    delete e.second;
}

int par[100000];

int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
}

void unite(int x, int y) {
    par[find(x)] = find(y);
}


int N, M;
int X[100000];
int A[100000], B[100000], Y[100000], P[100000];
node *V[100000];
pair<node *, node *> E[100000];
int used[100000];

int main() {
    for (int i = 0; i < 100000; i++) {
        par[i] = i;
    }
    scanf("%d %d", &N, &M);
    for (int i = 0; i < N; i++) {
        scanf("%d", &X[i]);
        V[i] = new node();
        V[i]->val = X[i];
        V[i]->sum = X[i];
    }
    for (int i = 0; i < M; i++) {
        scanf("%d %d %d", &A[i], &B[i], &Y[i]);
        A[i]--;
        B[i]--;
        P[i] = i;
    }
    sort(P, P + M, [&](int i, int j) { return Y[i] < Y[j]; });
    for (int i = 0; i < M; i++) {
        int j = P[i];
        if (find(A[j]) != find(B[j])) {
            unite(A[j], B[j]);
            used[j] = 1;
            E[j] = link(V[A[j]], V[B[j]]);
        }
    }
    int ans = 0;
    for (int i = M - 1; i >= 0; i--) {
        int j = P[i];
        splay(V[A[j]]);
        if (used[j]) {
            if (V[A[j]]->sum < Y[j]) {
                ans++;
                cut(E[j]);
            }
        } else {
            if (V[A[j]]->sum < Y[j]) {
                ans++;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 19328
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,c;
  cin>>n;
  c=n;
  string s[n];
  cin>>s[0];
  for(int i=1;i<n;i++){
    cin>>s[i];
    for(int j=0;j<i;j++){
      if(s[i]==s[j]){
        c--;
        break;
      }
    }
  }
  cout<<c;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

cn = True
cnt = 0
while cn:
    i = 0
    for a1 in a:
        if a1 % 2 == 0:
            a[i] = a1 / 2
        else:
            cn = False
            break
        if i == N-1:
            cnt += 1
            break
        else:
            i += 1
print(cnt)


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

using namespace std;

int main(int argc, char *argv[]) {
    vector<int> arr = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    cout << arr[K - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
function digit_sum(n::Int)
  ret=0
  while n>0
  	ret+=n%10
    n=div(n,10)
  end
  ret
end

n,a,b=parse.(split(readline()))
sum=0
for i in 1:n
  ds=digit_sum(i)
  if a<=ds<=b
    sum+=i
  end
end
println(sum)

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    int n;
    cin >> n;
    vector<pii> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i].first;
        v[i].second = i + 1;
    }
    sort(v.begin(), v.end());

    for (int i = 0; i < n-1; ++i) {
        cout << v[i].second << " ";
    }
    cout << v[n-1].second << endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	
	int a, b;
	cin >> a >> b;
	int digit = 10;
	while(b / digit != 0){
		digit *= 10;
	}
	int x = a * digit + b;
	double sqrtx = sqrt((double) x);
	if(x == (int) sqrtx * sqrtx) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
k = int(input())
s = input()

mod = 10**9+7
n = len(s) + k

frac = [1]*(n+1)
finv = [1]*(n+1)
for i in range(n):
    frac[i+1] = (i+1)*frac[i]%mod
finv[-1] = pow(frac[-1],mod-2,mod)
for i in range(1,n+1):
    finv[n-i] = finv[n-i+1]*(n-i+1)%mod
def nCr(n,r,m):
    if n<0 or r<0 or n<r: return 0
    r = min(r,n-r)
    return frac[n]*finv[n-r]*finv[r]%mod
a,b = [1],[1]
for _ in range(k+1):
    a.append(a[-1]*25%mod)
    b.append(b[-1]*26%mod)
n = len(s)
ans = 0
for i in range(k+1):
    ans += a[i]*b[k-i]*nCr(i+n-1,n-1,mod)
    ans %= mod
print(ans)

Measured memory_bytes: 214976
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<iomanip>
#include<cmath>
#define pb push_back
#define LL long long
#define ff first
#define ss second
#define in inline
#define RE register
#define pa pair<int,int>
using namespace std;
const int MAXN=0x3f3f3f3f;
const int MAXL=0x7ffff;
in void read(int &x){
   x=0;
   char c=getchar();
   while(c>'9'||c<'0')c=getchar();
   while(c<='9'&&c>='0'){
   x=x*10+c-'0';
   c=getchar();
   }
}
inline void write(int re)
 {     /*
     if (re<0)
     {
         putchar('-');
         re=-re;
     }
     */
     if (re>9) write(re/10);
     putchar(re%10+'0');
}
int n,m,d;
bool a[10];
int main()
{
	read(n);
	read(m);
	for(int i=0;i<m;i++)
	{
		int b;
		cin>>b;
		a[b]=1;
	}
    while(1){
    	d=n;
    	bool h=1;
    	while(d!=0)
    	{
    		if(a[d%10]==1)h=0;
    		d=d/10;
    	}
    	if(h==1){
    		cout<<n;
    		return 0;
    	}
    	n++;
    }

} 

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

int main() {
  int X,ans;
  cin>>X;
  int num_a,num_b;
  num_a=X/500;
  X=X-500*num_a;
  num_b=X/5;
  ans=num_a*1000+num_b*5;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

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

int main(){
    ll x;
    cin >> x;
    ll num=100;
    ll ans=0;
    while(num<x){
        num+=num*0.01;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
pa = -2
for a in A:
    a -= 1
    ans += B[a]
    if a == pa + 1:
        ans += C[pa]
    pa = a
print(ans)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
edges = {}
for _ in range(M):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  if a not in edges:
    edges[a] = set()
  if b not in edges:
    edges[b] = set()
  edges[a].add(b)
  edges[b].add(a)

to_check = set(range(N))
max_size = 0
while to_check:
  checked = set()
  s = set()
  s.add(next(iter(to_check)))
  #print(s)
  while s:
    current = s.pop()
    checked.add(current)
    if current in edges:
      for n in edges[current]:
        if n not in checked:
          s.add(n)
  max_size = max(max_size, len(checked))
  #print(checked)
  for c in checked:
    to_check.remove(c)
print(max_size)



Measured memory_bytes: 197540
#include <bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

vector<int> v(25);

int main()
{
    FAST_IO;
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        v[i] = x;
    }
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        v[i] -= x;
    }
    sort(v.rbegin(), v.rend());
    int ans = 0;
    for (int i = 0; i < n; i++)
        ans = max(ans+v[i] , ans);
    printf("%d\n", ans);
    return 0;
}

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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n, a[100100];
ll ans;

ll solve(){
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    
    ll sum = 0;
    ll ans1 = 0;
    for(int i = 0, j = -1; i < n; ++i, j *= -1){
        sum += a[i];
        if(j == -1){
            if(sum < 0) continue;
            else{
                ans1 += sum + 1;
                sum = -1;
            }
        }else{
            if(sum > 0) continue;
            else{
                ans1 += 1 - sum;
                sum = 1;
            }
        }
    }

    sum = 0;
    ll ans2 = 0;
    for(int i = 0, j = 1; i < n; ++i, j *= -1){
        sum += a[i];
        if(j == -1){
            if(sum < 0) continue;
            else{
                ans2 += sum + 1;
                sum = -1;
            }
        }else{
            if(sum > 0) continue;
            else{
                ans2 += 1 - sum;
                sum = 1;
            }
        }
    }

    return min(ans1, ans2);
}

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

    cout << solve() << "\n";
    
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int K;
  cin>>K;
  int even, odd;
  if(K%2==0) {
    even = K/2;
    odd = K/2;
  }
  else {
    even = K/2;
    odd = K/2+1;
  }
  cout<<odd*even<<endl;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  string S; cin >> S;
  for (char c = 'a'; c <= 'z'; c++) {
    if(count(all(S),c) >= 2) {
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <bitset>
#include <string>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <list>
#include <deque>
using namespace std;
#define INF 10000000
#define LLINF 100000000000000
typedef pair<long long, long long> P;
typedef long long ll;
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define VSORT(v) sort(v.begin(), v.end());
#define fi first
#define se second
#define out(x) cout << x << endl;
int dx[] = { 1, 0, -1, 0 }, dy[] = { 0,1,0,-1 };
ll MOD = 1000000007;

struct edge {
	ll from, to, cost;
};

vector<P> es[500005];
int v, e, s;

void dijkstra() {
	ll d[100005] = { 0 };
	rep(i, v + 5) d[i] = LLINF;
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P>>que;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top();
		que.pop();
		ll v = p.second;
		if (d[v] < p.first) continue;
		for (int u = 0; u < es[v].size(); u++) {
			ll to = es[v][u].first;
			ll cost = es[v][u].second;
			if (d[to] > d[v] + cost) {
				d[to] = d[v] + cost;
				que.push(P(d[to], to));
			}
		}
	}
	for (int i = 0; i < v; i++) {
		if (d[i] != LLINF) { out(d[i]); }
		else cout << "INF" << endl;
	}
	return;
}


int main() {
	cin >> v >> e >> s;
	for (int i = 0; i < e; i++) {
		ll s, t, d;
		cin >> s >> t >> d;
		es[s].pb(P(t, d));
	}
	dijkstra();
	return 0;
}


Measured memory_bytes: 28780
#include<stdio.h>

int main(){

  int n,x[100],i,j,temp,flag=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&x[i]);
  }

  for(i = 0; i < n; i++){
    for(j = n-1; j > i; j--){
      if(x[j-1] > x[j]){
	temp = x[j];
	x[j] = x[j-1];
	x[j-1] = temp;
	flag++;
      }
    }
  }
  for(i = 0; i < n; i++){
    printf("%d",x[i]);
    if(i==n-1){
      break;
    }
      printf(" ");
  }
  
    
  printf("\n");
  printf("%d\n",flag);

  return 0;
}

Measured memory_bytes: 604
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	char a[105];
	while(~scanf("%d",&n))
	{
		scanf("%s",a);
		int w=0;
		if(n%2)w=1;
		else {
			for(int i=0;i<n/2;i++)
			{
				if(a[i]!=a[i+n/2]){w=1;break;}
			}
		}
		if(w)printf("No\n");
		else printf("Yes\n");
	}
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int MOOD=1000*1000*1000+7;
int main()
{
	int n;
	cin>>n;
	vector<int>A(n);
	int sum=0;
	for(int i=0;i<n; i++){cin>>A[i];if(i%2)sum-=A[i];else sum+=A[i];}
	vector<int>ans;
	ans.push_back(sum);
	cout<<sum<<" ";
	for(int i=0; i<n-1; i++)
	{
		A[i]*=2;
		sum= A[i]-sum;
		cout<<sum<<" ";
		ans.push_back(sum);
	}
}


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

string s;
vector<string> vs; 

void dfs(string t, int now){
    if(now == s.size()){
        vs.push_back(t);
        return;
    }
    int d[26] = {};
    rep(i, 0, now) d[t[i] - 'a']++;
    if(t[now] != 'z' && d[t[now] + 1 - 'a'] == 0){
        string tmp = t;
        tmp[now] = tmp[now] + 1;
        dfs(tmp, now + 1);
    }
    if(t[now] == 'a' || d[t[now] - 'a'] != 0) dfs(t, now + 1);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    while (1) {
        cin >> s;
        if(s == "#") break;
        vs.clear();
        dfs(s, 0);
        int ans = vs.size();
        sort(vs.begin(), vs.end());
        cout << ans << endl;
        if(ans <= 10){
            rep(i, 0, ans){
                cout << vs[i] << endl;
            }
        }else{
            rep(i, 0, 5){
                cout << vs[i] << endl;
            }
            rep(i, ans - 5, ans){
                cout << vs[i] << endl;
            }
        }
    }
}


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

using namespace std;

int main() {
    long long N, M;
    cin >> N >> M;

    vector<long long> vt[M + 1];
    for (int i = 0; i < N; i++) {
        long long a, b;
        cin >> a >> b;
        if (a <= M) vt[a].push_back(b);
    }

    long long ans = 0;
    priority_queue<long long> pq;
    for (int i = 1; i <= M; i++) {
        for (auto x:vt[i]) pq.push(x);
        if (!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
    }

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

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

using namespace std;

const int maxn = 1e5+100;
const long long Mod = 1e9+7;
long long ans, a, t[maxn],n;

int main(){
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a;
        t[a]++;
    }
    ans = 1;
    if(n%2 == 1){
        for(int i=0; i<n; i+=2){
            if((i!=0 && t[i]!=2) || (i==0 && t[i]!=1)){
                cout << 0;
                return 0;
            }
            if(i!=0) ans = (ans*2) % Mod;
        }
        cout << ans;
    }
    else{
        for(int i=1; i<n; i+=2){
            if(t[i]!=2){
                cout << 0;
                return 0;
            }
             ans = (ans*2)%Mod;
        }
        cout << ans;
    }
    
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
    ll n,m,n1,m1,n2,m2;
    cin>>n>>m;
    if(n%2==0)
    {
        n1=n/2;
        n2=n1;
    }
    else
    {
        n1=n/2+1;
        n2=n1-1;
    }
    if(m%2==0)
    {
        m1=m/2;
        m2=m1;
    }
    else
    {
        m1=m/2+1;
        m2=m1-1;
    }
    if(n==1 || m==1)
    {
        n1=0;
        n2=1;
        m2=1;
    }
    cout<<n1*m1 + n2*m2;
}


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

using namespace std;

using cap_t = int;

const cap_t cap_inf = 0x3f3f3f3f;

namespace flow {
struct edge {
  int to, rev;
  cap_t cap;

  edge(int t, cap_t c, int r) {
    to = t;
    cap = c;
    rev = r;
  }
};

vector<vector<edge>> g;
vector<int> ptr, dist;
int n, src, snk;
cap_t ans;

void init(int v, int s, int t) {
  n = v;
  ans = 0;
  src = s;
  snk = t;
  g.clear();
  g.resize(n);
  ptr.resize(n);
  dist.resize(n);
}

void add(int x, int y, cap_t c, cap_t rev_c = 0) {
  g[x].emplace_back(y, c, g[y].size());
  g[y].emplace_back(x, rev_c, g[x].size() - 1);
}

bool bfs() {
  queue<int> q;
  for (int i = 0; i < n; ++i) {
    dist[i] = -1;
  }
  dist[src] = 0;
  q.push(src);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (edge e : g[v]) {
      if (e.cap && !~dist[e.to]) {
        dist[e.to] = dist[v] + 1;
        if (e.to == snk) {
          return true;
        }
        q.push(e.to);
      }
    }
  }
  return false;
}

cap_t dfs(int v, cap_t f) {
  if (v == snk) {
    return f;
  }
  for (int &i = ptr[v]; ~i; --i) {
    edge &e = g[v][i];
    if (e.cap && dist[e.to] == dist[v] + 1) {
      cap_t w = dfs(e.to, min(e.cap, f));
      if (w) {
        e.cap -= w;
        g[e.to][e.rev].cap += w;
        return w;
      }
    }
  }
  return 0;
}

cap_t max_flow() {
  while (bfs()) {
    for (int i = 0; i < n; ++i) {
      ptr[i] = g[i].size() - 1;
    }
    while (true) {
      cap_t flow = dfs(src, cap_inf);
      if (!flow) {
        break;
      }
      ans += flow;
    }
  }
  return ans;
}
}

using flow::src;
using flow::snk;
using flow::add;
using flow::init;
using flow::max_flow;

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  vector<int> pp(n, -1);
  int np = 0;
  for (int i = 0; i < n; ++i) {
    if (pp[i] == -1) {
      int j = i;
      while (pp[j] == -1) {
        pp[j] = np;
        j = p[j];
      }
      ++np;
    }
  }
  vector<int> q(n);
  for (int i = 0; i < n; ++i) {
    cin >> q[i];
  }
  vector<int> qq(n, -1);
  int nq = 0;
  for (int i = 0; i < n; ++i) {
    if (qq[i] == -1) {
      int j = i;
      while (qq[j] == -1) {
        qq[j] = nq;
        j = q[j];
      }
      ++nq;
    }
  }
  init(np + nq + 2, np + nq, np + nq + 1);
  vector<int> vp(np);
  vector<int> vq(nq);
  int res = n;
  for (int i = 0; i < n; ++i) {
    if (p[i] == i && q[i] == i) {
      --res;
    } else if (p[i] == i) {
      ++vq[qq[i]];
    } else if (q[i] == i) {
      ++vp[pp[i]];
    } else {
      add(pp[i], np + qq[i], p[i] == q[i], 1);
    }
  }
  for (int i = 0; i < np; ++i) {
    add(src, i, vp[i]);
  }
  for (int i = 0; i < nq; ++i) {
    add(np + i, snk, vq[i]);
  }
  cout << res - max_flow() << "\n";
  return 0;
}


Measured memory_bytes: 12664
n, a = map(int, input().split())
x = list(map(int, input().split()))

dp = [[[0 for k in range(n+1)] for j in range(n+1)] for s in range(2501)]


dp[0][0][0] = 1
for s in range(2501):
    for j in range(1, n+1):
        for k in range(j+1):
            idx = j-1
            if x[idx] > s:
                dp[s][j][k] = dp[s][j-1][k]
            else:
                dp[s][j][k] = dp[s][j-1][k] + dp[s-x[idx]][j-1][k-1]

ans = 0
for k in range(1, n+1):
    ans += dp[k*a][n][k]

print(ans)

Measured memory_bytes: 113344
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdlib.h>
using namespace std;

#define INF 1e9
#define PI 3.141592653589793238
typedef long long ll;

int main() {
    int flag=1;
    string s,t;cin>>s>>t;
    for(int i=0; i<s.size(); i++){
        if(s[i]!=t[i]) flag=0;
    }

    if(flag==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 3612
import heapq
MOD = 10 ** 9 + 7

N, M = map(int, input().split())
S, T = map(lambda x: int(x) - 1, input().split())

adjList = [[] for i in range(N)]
for i in range(M):
    U, V, D = map(int, input().split())
    adjList[U - 1].append((V - 1, D))
    adjList[V - 1].append((U - 1, D))

# 頂点Sから各頂点への最短路の個数
numRouteS = [0 for i in range(N)]
numRouteS[S] = 1

cost = [float('inf')] * N
cost[S] = 0
prev = [None] * N

pq = []
heapq.heappush(pq, (0, S))

vs = []
while pq:
    c, vNow = heapq.heappop(pq)
    if c > cost[vNow]: continue
    if c > cost[T]: break
    vs += [vNow]

    for v2, wt in adjList[vNow]:
        c2 = cost[vNow] + wt
        if c2 <= cost[v2]:
            if c2 == cost[v2]:
                prev[v2] += [vNow]
                numRouteS[v2] = (numRouteS[v2] + numRouteS[vNow]) % MOD
            else:
                cost[v2] = c2
                prev[v2] = [vNow]
                numRouteS[v2] = numRouteS[vNow]
                heapq.heappush(pq, (c2, v2))

# 頂点Tから各頂点への最短路の個数
numRouteT = [0] * N
numRouteT[T] = 1
for v in reversed(vs[1:]):
    for v0 in prev[v]:
        numRouteT[v0] = (numRouteT[v0] + numRouteT[v]) % MOD

# 二人の最短路の選び方の組から、途中で出会うものを引く
cST = cost[T]
ans = (numRouteS[T] ** 2) % MOD

for v, c in enumerate(cost):
    if c * 2 == cST:
        x = (numRouteS[v] ** 2) % MOD
        y = (numRouteT[v] ** 2) % MOD
        ans = (ans - x * y) % MOD

for v, c in enumerate(cost):
    if c * 2 < cST:
        for v2, wt in adjList[v]:
            if (cost[v2] * 2 > cST) and c + wt == cost[v2]:
                x = (numRouteS[v] ** 2) % MOD
                y = (numRouteT[v2] ** 2) % MOD
                ans = (ans - x * y) % MOD

print(ans)


Measured memory_bytes: 124832
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;
//const int MOD=1e9+7;


int main(){
	string N;
	cin>>N;
	int ans=0;
	rep(i,4){
		if(N[i]=='2')ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    var tmpLine = readLine()
    var tmps = tmpLine!!.split("\\s+".toRegex())

    for (i in 0..4) {
        val tmpx = tmps[i]
        if (tmpx.toInt() == 0) {
            println("${i+1}")
        }
    }
}

Measured memory_bytes: 35112
#include<stdio.h>
#include<stdlib.h>
#define MAX 500000

struct NODE{
  int key;
 struct NODE *parent;
 struct NODE *left;
 struct NODE *right;
};

typedef struct NODE NODE;

NODE T[MAX];
NODE *root,*NIL;

int scancommand(char *);
void insert(int);
int find(NODE *,int);
void inorder(NODE *);
void preorder(NODE *);

int main()
{
  int n;
  int i,j;
  int x;
  int t;
  char command[30];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",command);
    //printf("%s\n",command);
    
    if(scancommand(command) == 1){
      scanf("%d",&x);
      insert(x);
      //printf("%d\n",x);
    }
    else if(scancommand(command) == 2){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(scancommand(command) == 3){
      scanf("%d",&x);
      t = find(root, x);
      if(t == 0) printf("no\n");
      else printf("yes\n");
    }
  }
  
  return 0;
}

int scancommand(char *com)
{
  if(com[0] == 'i') return 1;
  else if(com[0] == 'p') return 2;
  else if(com[0] == 'f') return 3;
  else return 0;
}

void insert(int k)
{
  //printf("===insert===\n");
  NODE *y = NIL; // xの親
  NODE *x = root; //Tの根
  NODE *z;

  z = (NODE *)malloc(sizeof(NODE));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    y = x; //親を設定
    if(z->key < x->key) x = x->left;
    else x = x->right;
       }
  z->parent = y;

  if (y == NIL){ //Tが空の場合
    root = z;
  }
  else if (z->key < y->key) y->left = z;
  else y->right = z;
}

int find(NODE *x,int k)
{
  while(x != NIL && k != x->key){
    if( k < x->key ) x = x->left;
    else x = x->right;
  }
  if(x == NIL) return 0;
  else return 1;
}

void inorder(NODE *u){
  if( u == NIL ) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(NODE *u){
  if( u == NIL ) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}




Measured memory_bytes: 20452
import Control.Monad.ST
import Data.Char
 
 
readInt :: IO Int
readInt = read <$> getLine :: IO Int
 
readIntSplit :: IO [Int]
readIntSplit = map read . words <$> getLine :: IO [Int]
 
readStr :: IO String
readStr = getLine
 
readStrSplit :: IO [String]
readStrSplit = map read . words <$> getLine


solve :: String -> String -> String
solve s t
  | s == init t = "Yes"
  | otherwise = "No"

main = do
  s <- readStr
  t <- readStr
  putStrLn $ solve s t

Measured memory_bytes: 3680
# -*- coding: utf-8 -*-
from collections import defaultdict
from operator import itemgetter

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(n)]
cd.sort()

m = defaultdict(lambda: [])
for i in range(n):
    for j in range(n):
        a,b = ab[i]
        c,d = cd[j]
        if a<c and b<d:
            m[j].append([i,a,b])

used = set()
res = 0
for j in range(n):
    if len(m[j])>0:
        l = sorted(m[j],key=itemgetter(2),reverse=True)
        for i,_,_ in l:
            if i not in used:
                used.add(i)
                res += 1
                break
print(res)

Measured memory_bytes: 3572
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define pi pair<int,int> 
#define pii pair<pi,int>
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	for(int i = 1;i*i<=n;i++){
		if(n%i == 0 && i <= 9 && n/i <= 9){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 3496
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define mod 1000000007
#define pb push_back
 
typedef long long ll;

using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >>c ;
  if(b-a==c-b){
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int h = Integer.parseInt(sa[1]);
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			a[i] = Integer.parseInt(sa[0]);
			b[i] = Integer.parseInt(sa[1]);
		}
		br.close();

		int max = 0;
		for (int i = 0; i < n; i++) {
			max = Math.max(max, a[i]);
		}

		Arrays.parallelSort(b);

		int ans = 0;
		for (int i = n - 1; i >= 0; i--) {
			if (b[i] <= max) {
				break;
			}

			h -= b[i];
			ans++;
			if (h <= 0) {
				System.out.println(ans);
				return;
			}
		}

		System.out.println(ans + (h + max - 1) / max);
	}
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
typedef map<int,int> mp;

const int MOD = 1e9 + 7;


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

    int n, m;
    cin >> n >> m;
    vi x(m);
    rep(i, m){
        cin >> x[i];
    }

    ll ans = m - n;
    if(ans <= 0){
        cout << 0 << endl;
        return 0;
    }
    sort(all(x));

    vi diff;
    rep(i, m-1){
        ll res = abs(x[i] - x[i+1]);
        diff.push_back(res);
    }
    sort(all(diff), greater<int>());
    diff.erase(diff.begin(), diff.begin()+n-1);

    ans  = 0;
    for(auto& p : diff){
        ans += p;
    }

    cout << ans << endl;

    return 0;
}



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

int n;
string s;
int fst[4] = {0, 0, 1, 1};
int snd[4] = {0, 1, 0, 1};
int animal[100000];
bool flag;

int main(){
  cin >> n >> s;
  flag = false;
  for(int i = 0; i < 4; i++){
    animal[0] = fst[i];
    animal[1] = snd[i];
    for(int j = 2; j < n; j++){
      if(s[j - 1] == 'o' && animal[j - 1] == 0){
	animal[j] = animal[j - 2];
      }
      else if(s[j - 1] == 'o' && animal[j - 1] == 1){
	animal[j] = (animal[j - 2] + 1) % 2;
      }
      else if(s[j - 1] == 'x' && animal[j - 1] == 0){
	animal[j] = (animal[j - 2] + 1) % 2;
      }
      else{
	animal[j] = animal[j - 2];
      }
    }
    if(s[0] == 'o' && animal[0] == 0){
      if(animal[n - 1] == animal[1]){
	flag = true;
      }
    }
    if(s[0] == 'o' && animal[0] == 1){
      if(animal[n - 1] == (animal[1] + 1) % 2){
	flag = true;
      }
    }
    if(s[0] == 'x' && animal[0] == 0){
      if(animal[n - 1] == (animal[1] + 1) % 2){
	flag = true;
      }
    }
    if(s[0] == 'x' && animal[0] == 1){
      if(animal[n - 1] == animal[1]){
	flag = true;
      }
    }
    //
    if(s[n - 1] == 'o' && animal[n - 1] == 0){
      if(animal[0] != animal[n - 2]){
	flag = false;
      }
    }
    if(s[n - 1] == 'o' && animal[n - 1] == 1){
      if(animal[0] != (animal[n - 2] + 1) % 2){
	flag = false;
      }
    }
    if(s[n - 1] == 'x' && animal[n - 1] == 0){
      if(animal[0] != (animal[n - 2] + 1) % 2){
	flag = false;
      }
    }
    if(s[n - 1] == 'x' && animal[n - 1] == 1){
      if(animal[0] != animal[n - 2]){
	flag = false;
      }
    }
    if(flag){
      break;
    }
  }

  if(flag){
    for(int i = 0; i < n; i++){
      if(animal[i] == 0){
	cout << "S";
      }
      else{
	cout << "W";
      }
    }
    cout << endl;
  }
  else{
    cout << -1 << endl;
  }
}


Measured memory_bytes: 896
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    String S = "";
    String A[] = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
    while(N>26){
      long tmp = (N-1L)%26;
      // if(tmp==-1L){
      //   tmp = 25L;
      // }
      S+=A[(int)tmp];
      N = (N -1L) /26L ;
      // System.out.println(N);
    }
    long tmp2 = N-1L;
    // if(tmp2==-1L){
    //   tmp2 = 25L;
    // }
    S+=A[(int)tmp2];
    StringBuffer str = new StringBuffer(S);
    String S2 = str.reverse().toString();
    System.out.println(S2);

  }
}

// 1000000000000001
// 9223372036854775807

Measured memory_bytes: 39352
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d){
    cout<<"Left\n";
  }else if(a+b==c+d){
    cout<<"Balanced\n";
  }else{
    cout<<"Right\n";
  }
}

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

import static java.lang.System.in;

public class Main {
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x= new int[n+1];
        for(int i=1;i<=n;i++) x[i]=sc.nextInt();
        long mod = 1000000000+7;
        long ans = 1;
        if(n<=2){
            System.out.println(n);
            return;
        }
        int done=0,i=3;
        while(done<n){
            while(i<=n&&x[i-1]>=2*(i-1-done)-1) i++;
            ans = ans*(i-1-done)%mod;
            done++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 51156
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	ll N;
	cin >> N;
 
	// 解法
	ll ans = 0;
	REP(i,4){
		if (N%10==2) ans++;
		N = N/10;
	}

	//出力
	cout << ans << endl;
}


Measured memory_bytes: 256
def left_p(i)
  2 * i
end
def right_p(i)
  2 * i + 1
end
def parent_p(i)
  i / 2
end


n = STDIN.gets.to_i
arr = STDIN.gets.split(' ')

arr.each_with_index { |a, i|
  id = i + 1
  parent_p = parent_p(id)
  left_p = left_p(id)
  right_p = right_p(id)

  parent_s =
    if parent_p != 0 && arr.size >= parent_p
      "parent key = #{arr[parent_p - 1]}, "
    else
      ""
    end

  left_s =
    if arr.size >= left_p
      "left key = #{arr[left_p - 1]}, "
    else
      ""
    end

  right_s =
    if arr.size >= right_p
      "right key = #{arr[right_p - 1]}, "
    else
      ""
    end

  puts "node #{id}: key = #{a}, #{parent_s}#{left_s}#{right_s}"
}

Measured memory_bytes: 8664