akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int a[4];
	int b[4];
	while(cin>>a[0]){
		rep(i,3)cin>>a[i+1];
		rep(i,4)cin>>b[i];
		int h=0,br=0;
		rep(i,4)rep(j,4)if(a[i]==b[j]){
			if(i==j)h++;
			else br++;
		}
		cout<<h<<" "<<br<<endl;
	}
}

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

int main() {
	int N;
	int a=1,b;
	string s;
	cin >> N;
	int d[N];
	int i;
	for(i=0;i<N;i++){
	    cin >> d[i];
	}
	sort(d,d+N);
	for(i=1;i<N;i++){
	    if(d[i]!=d[i-1])a++;
	}
	cout << a << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int D = sc.nextInt();
    int X = sc.nextInt();
    int A[] = new int[N];
    int sum = X;
    D -= 1;
    
    for(int i=0; i<N; i++) {
      A[i] = sc.nextInt();
      sum = sum + 1 + D / A[i];
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 21844
s=input()
k=int(input())
if len(s)==1:
  print(k//2)
else:
  ans=0
  chg=0
  for i in range(1,len(s)):
    if chg==0 and s[i-1]==s[i]:
      ans+=1
      chg=1
    else:
      chg=0
  ans2=1
  chg2=1
  for i in range(1,len(s)):
    if chg2==0 and s[i-1]==s[i]:
      ans2+=1
      chg2=1
    else:
      chg2=0
  if s[0]!=s[-1] or chg==1:
    print(k*ans)
  elif chg2==0:
    print((k-1)*ans2+ans)
  else:
    print(ans*((k+1)//2)+ans2*(k//2))

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

if 1<=N<10:
  print(N)
elif 10<=N<100:
  print(9)
elif 100<=N<1000:
  print(N-90)
elif 1000<=N<10000:
  print(909)
elif 10000<=N<100000:
  print(N-9090)
else:
  print(90909)

Measured memory_bytes: 9180
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace2(a,b) cerr <<"a is " << a << " b is " << b << el;
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;
ll n , m ;
vl v[100005];
ll visited[100005] , low[100005] , disc[100005] , Time = -1;
vector<pll> ans;
void dfs(ll curr , ll par)
{
    visited[curr] = 1 ;
    low[curr] = disc[curr] = ++Time;
    for(auto &to : v[curr]){
        if(to == par) con ;
        if(visited[to]){
            low[curr] = min(low[curr] , disc[to]) ;
        }
        else{
            dfs(to , curr);
            low[curr] = min(low[curr] , low[to]) ;
            if(disc[curr] < low[to]){
                ans.pb({curr ,to});
            }
        }
    }
}
int main()
{
    ios;
    cin >> n >> m ;
    forn( i ,1 , m ) {
       ll x , y;
       cin >>x >> y ;
       v[x].pb(y) ;
       v[y].pb(x) ;
    }
    memset(visited , 0 , so visited) ;
    forn(i , 1 , n){
       if(visited[i] == 0){
        dfs(i , -1);
       }
    }
    cout << ans.sz << el ;
    ro ;
}




Measured memory_bytes: 3456
nums = input().split()

A = int(nums[0])
B = int(nums[1])
C = int(nums[2])
D = int(nums[3])

at_T = (C+B-1) // B
at_A = (A+D-1) // D

if (at_T > at_A ):
	print("No")
else:
	print("Yes")

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std; 
#define rint register int
inline int read(){int r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}
int s[100005], n, Ans = 100; int main(){n = read(); for(rint i = 1; i < n; s[i] = s[i/10]+i%10, i++); for(rint i = 1; i < n; Ans = min(Ans,s[i]+s[n-i]), i++); return !printf("%d\n",Ans);}

Measured memory_bytes: 640
# python template for atcoder1
import sys


class UnionFind:
    """
    sizeによる実装
    """

    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def union(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.size[px] < self.size[py]:
            self.parent[px] = py
            self.size[py] += self.size[px]
        else:
            self.parent[py] = px
            self.size[px] += self.size[py]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def connectedNum(self, x):
        return self.size[self.find[x]]

    def componentNum(self):
        ret = 0
        for i in range(N):
            if self.parent[i] == i:
                ret += 1
        return ret


sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, M = map(int, input().split())
hint = []
for _ in range(M):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    hint.append([x, y, z])
Un = UnionFind(N)

for x, y, z in hint:
    Un.union(x, y)
comp = Un.componentNum()
print(comp)


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

int main(void) {
    int n, c, sum=0;
    int cakes[100];
    scanf("%d", &n);
    scanf("%d", &c);


    for(int i = 0 ; i < c; i++) {
        scanf("%d", &cakes[i]);
        sum += cakes[i];
    }
    
    if (sum%(n+1) == 0) {
        printf("%d\n", sum/(n+1));
    } else {
        printf("%d\n", sum/(n+1) + 1);
    }
    
    return 0;
}



Measured memory_bytes: 3212
#include <stdio.h>

int main(){
    
    int a, i;
    int n, p = 0;
    scanf("%d",&a);

    for(i=0; i<6; i++){
        if(a % 10 == 1){
            n++;
        }

        a = a / 10;
    }

    printf("%d", n);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              3.14159265358979323844
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
	ll n;
	cin>>n;
	ll arr[n];
	rep(i,0,n){
		cin>>arr[i];
		if (arr[i]%2==0){
			if (arr[i]%3!=0 && arr[i]%5!=0){
				cout<<"DENIED"<<endl;
				return;
			}
		}
	}
	cout<<"APPROVED"<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using i64 = int64_t;

const string YES = "Yes", NO = "No";

int N, a[100000];

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    for (int j = 0; j < N; ++j) {
        cin >> a[j];
    }
    sort(a, a+N);
    int x = a[0], y = a[N-1];
    if (x + 2 <= y) {
        cout << NO << endl;
        return 0;
    }
    if (x == y) {
        cout << ((N == x+1 || N >= 2*x) ? YES : NO) << endl;
        return 0;
    }
    // x + 1 == y
    assert(x + 1 == y);
    int xc = upper_bound(a, a+N, x) - a,
        yc = N - xc;

    bool flg = xc <= x && yc >= (x - xc + 1) * 2;
    cout << (flg ? YES : NO) << endl;
    return 0;
}


Measured memory_bytes: 640
// Boudy is 32
// Tsunami is :gift_heart:
// Yassora is :sparkling_heart:
// Zetamoo is :heartbeat:
// Nour is Mo7nk
// Pillow is habd
// Lulu ...... meen Lulu?!!!
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;
//const long long mod = 998244353;
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

// watch this
using ll = long long;
//typedef long long LL;
#define ll long long
#undef ll

const int mxN = 50;

long long A[mxN][mxN];
long long B[mxN];
long long C;
long long N, M;

int main(int argc, char** argv) {
#ifdef ONLINE_JUDGE	
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
//	freopen("highways.in", "r", stdin);
//	freopen("highways.out", "w", stdout);
#endif

	cin >> N >> M >> C;
	for (int i = 0; i < M; i++)
		cin >> B[i];
	int res = 0;
	for (int i = 0; i < N; i++) {
		long long cur = C;
		for (int j = 0; j < M; j++)
			cin >> A[i][j], cur += A[i][j] * B[j];
		res += cur > 0;
	}
	cout<<res<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

int main() {
    map<char, int> mp;
    string str;
    cin >> str;
    
    bool flag=true;
    for(int i=0; i<str.size(); i++) {
        mp[str[i]]++;
        if(mp[str[i]]>1) {
            flag=false;
            break;
        }
    }
    if(flag) {
        cout << "yes" << endl;
    } else {
        cout << "no" << endl;
    }



    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#define INF (long)1e9
const long MOD = 1e9 + 7;
const long dx[] = {1, -1, 0, 0};
const long dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	long n, k;
	cin >> n >> k;
	long A[n + 1];
	for(long i = 0; i < n; i++)
		cin >> A[i];
	A[n] = INF;
	vector<long> d;
	for(long i = 0; i < n; i++)
	{
		if(A[i + k - 1] == INF)
			break;
		if(A[i] == A[i + k - 1])
			d.push_back(A[i]);
		else if(A[i] < 0 && A[i + k - 1] < 0 || A[i] > 0 && A[i + k - 1])
			d.push_back(max(abs(A[i]), abs(A[i + k - 1])));
		else if(A[i] < 0 && A[i + k - 1] > 0)
		{
			d.push_back(abs(A[i]) + abs(A[i + k - 1]));
			d[i] += min(abs(A[i]), abs(A[i + k - 1]));
		}
	}
	long ans = INF;
	for(long i = 0; i < d.size(); i++)
	{
		if(d[i] < ans)
			ans = d[i];
	}
	cout << ans << endl;
	return 0;
}



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

int main(){
	long long a, b, c;
	std::cin >> a >> b >> c;
	bool d;
	if(a+b>=c) d = false;
	else{
		d = (a*a+b*b+c*c-2*(a*b+b*c+c*a) > 0);
	}
	// bool d = (std::sqrt((long double)a) + std::sqrt((long double)b) < std::sqrt((long double)c));
	if(d){
		std::cout << "Yes\n";
	}else{
		std::cout << "No\n";
	}
	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 rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int inf = 1e9;

int main() {
	int N,amin=inf,amax=-inf;
	cin>>N;
	vector<int> a(N);
	rep(i,N){
		cin>>a[i];
		amax=max(amax,a[i]);
		amin=min(amin,a[i]);
	}
	int ans=inf;
	for (int A = amin; A <= amax; ++A){
		int cost=0;
		rep(i,N){
			cost+=(a[i]-A)*(a[i]-A);
		}
		ans=min(ans,cost);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cctype>
#include <cassert>
#include <string>
#include <vector>
#include <map>
#include <stdexcept>

char parse(const std::string& s, size_t& i, std::map<char, int>& av) {
  if (isalpha(s[i])) return s[i++];
  if (s[i] == '[') {
    char c1=parse(s, ++i, av);
    assert(s[i] == '-');
    char c2=parse(s, ++i, av);
    assert(s[i] == ']');
    ++i;

    if (av[c1] == av[c2]) throw std::logic_error("1");
    if (av[c1] > av[c2]) std::swap(c1, c2);

    assert(av[c1] < av[c2]);
    if (av[c1] != 0) throw std::logic_error("1");
    --av[c2];
    return c2;
  }
  assert(false);
}

int main() {
  char buf[1024];
  scanf("%s", buf);
  std::string s=buf;

  std::map<char, int> av;
  while (true) {
    char a;
    int v;
    if (scanf(" %c %d", &a, &v) == EOF) break;
    av[a] = v;
  }

  try {
    size_t i=0;
    char z=parse(s, i, av);
    if (av[z]) throw std::logic_error("1");
    puts("Yes");
  } catch (std::logic_error&) {
    puts("No");
  }
}


Measured memory_bytes: 2916
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, k = ns()
    a = na()

    dp = [False] * (k + 1)

    for i in range(k + 1):
        for ai in a:
            if i + ai < k + 1:
                dp[i + ai] |= not dp[i]

    print("First" if dp[k] else "Second")


if __name__ == '__main__':
    main()


Measured memory_bytes: 11384
#include <stdio.h>

using namespace std;

int main(){
        int a,b,d,r;
        double f;

        scanf("%d %d",&a,&b);
        d = a/b;
        r = a%b;
        f = (double)a/(double)b;

        printf("%d %d %0.5lf\n",d,r,f);
}


Measured memory_bytes: 2760
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int xx = sc.nextInt();
    int yy = sc.nextInt();
    if(xx>=yy){
      System.out.println("War");
      return;
    }
    int[] x = new int[n+1];
    int[] y = new int[m+1];
    x[0] = xx;
    y[0] = yy;
    for(int i = 1;i<=n;i++){
      x[i] = sc.nextInt();
    }
    Arrays.sort(x);
    for(int i = 1;i<=m;i++){
      y[i] = sc.nextInt();
    }
    Arrays.sort(y);
    if(x[n]>=y[0]){
      System.out.println("War");
      return;
    }
    System.out.println("No War");
  }
}


Measured memory_bytes: 36248
#include <iostream>
using namespace std;
int p=1000000007;
#define ll long long int
int main() {
	ll i,j,n,m;
	cin>>n>>m;
	char a[n][m];
	ll b[n][m];
	for(i=0;i<n;i++)
	{
	    for(j=0;j<m;j++)
	    {
	        cin>>a[i][j];
	    }
	}
	for(i=0;i<n;i++)
	{
	    for(j=0;j<m;j++)
	    {
	        if(a[i][j]=='.')
	        {
	        if(i==0&&j==0)
	        b[i][j]=1;
	        else if(j==0)
	        b[i][j]=b[i-1][j];
	        else if(i==0)
	        b[i][j]=b[i][j-1];
	        else
	        b[i][j]=(b[i-1][j]+b[i][j-1])%p;
	        }
	        else
	        b[i][j]=0;
	    }
	}
	cout<<b[n-1][m-1]<<endl;
	return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int INF = 10e8;
const int maxN = 30010;
const int maxM = 100010;
 
int a,b;
int main()
{
	scanf("%d %d",&a,&b);
	if((a+b) == 15)
	{
		puts("+");
	}
	else if((a*b) == 15)
	{
		puts("*");
	}
	else
	{
		puts("x");
	}
	return 0;
}  

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int n,k,x,y;
	cin >> n >> k >> x >> y;

	cout << min(k,n)*x + max(0,n-k)*y << endl;

	return 0;
}

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

using namespace std;

long long int load_arr[1000001];

int check(long long int P, int car_num, int load_num)
{
    int res = 0;    //货物标记
    
    for (int i = 0; i < car_num; i++)
    {
        long long int tmp = 0;
        while ((tmp + load_arr[res]) <= P)
        {
            tmp += load_arr[res];
            res++;
            if (res == load_num)
            {
                return load_num;
            }
        }
    }
    
    return res;
}

long long int solve(int car_num, int load_num)
{
    long long int left = 0;
    long long int right = 100000 * 10000;
    long long int mid;
    
    while ((right - left) > 1)
    {
        mid = (right + left) / 2;
        int val = check(mid, car_num, load_num);
        if (val >= load_num)    //当前的P能够装下全部获取
        {
            right = mid;
        }
        else    //当前的P不能装下全部货物
        {
            left = mid;
        }
    }
    
    return right;
}

int main(int argc, const char * argv[]) {
    int load_num;
    int car_num;
    long long int ans;
    
    cin >> load_num >> car_num;
    for (int i = 0; i < load_num; i++)
    {
        cin >> load_arr[i];
    }
    
    ans = solve(car_num, load_num);
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 3860
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

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

	Int N;
	cin >> N;

	vector<Int> x(N);
	for (Int i = 0; i < N; i++) {
		cin >> x[i];
	}

	vector<Int> temp(N);
	temp = x;
	sort(temp.begin(), temp.end());

	Int temp_M = temp[N / 2];

	for (Int i = 0; i < N; i++) {
		if (x[i] >= temp_M) {
		    printf("%lld\n", temp[N / 2 - 1]);
		}
		else {
		    printf("%lld\n", temp_M);
		}
	}

}

Measured memory_bytes: 5376
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		char[][] c=new char[3][3];
		for(; sc.hasNext();){
			String s=sc.next();
			for(int j=0; j<3; j++)
				for(int i=0; i<3; i++)
					c[j][i]=s.charAt(j*3+i);
			String ans="d";
			for(int i=0; i<3; i++){
				if(c[i][0]==c[i][1]&&c[i][1]==c[i][2]&&c[i][0]!='s')
					ans=c[i][0]+"";
				if(c[0][i]==c[1][i]&&c[1][i]==c[2][i]&&c[0][i]!='s')
					ans=c[0][i]+"";
			}
			if(c[0][0]==c[1][1]&&c[1][1]==c[2][2]&&c[0][0]!='s')
				ans=c[0][0]+"";
			if(c[0][2]==c[1][1]&&c[1][1]==c[2][0]&&c[0][2]!='s')
				ans=c[0][2]+"";
			println(ans);
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

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

using namespace std;

int main()
{
    int n,k;
    cin>>k>>n;
    int ar[n],i,j;
    int sm=0;
    for(i=0;i<n;i++) {cin>>ar[i];}
    int diff,mx=INT_MIN;
    // for(i=0;i<n;i++) cout<<ar[i]<<" ";cout<<"\n";
    for(i=1;i<n;i++)
    {
        diff=ar[i]-ar[i-1];
        mx=max(mx,diff);
        sm+=diff;
    }
    // cout<<sm<<"\n";
    diff=k-sm;
    mx=max(mx,diff);
    cout<<k-mx<<"\n";
    return 0;
}

Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(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 speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 7;
int main(){
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    string w = "";
    vector<pair<char, char> > v;
    for(int i = 0; i < s.size(); i++){
        v.pb(mp(s[i], s[i]));
    }
    for(int i = 0; i < t.size(); i++){
        v[i].second = t[i];
    }
    for(int i = 0; i < v.size(); i++){
        cout << v[i].first << v[i].second;
    }
}

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

LL sum[100010];
LL a[100010];
map<LL,LL> Q;

int main()
{
    LL n,m;
    while(scanf("%lld%lld",&n,&m)!=EOF)
    {
        Q.clear();
        sum[0]=0;
        LL ans=0;
        for(LL i=1;i<=n;i++)
        {
            scanf("%I64d",&a[i]);
            sum[i]=sum[i-1]+a[i];
            sum[i]%=m;
            Q[sum[i]]++;
        }
        Q[0]++;
        map<LL,LL>::iterator it=Q.begin();
        while(it!=Q.end())
        {
            ans+=(it->second)*(it->second-1)/2;
            it++;
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 5760
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;

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 m = Integer.parseInt(sa[1]);
		List<List<Integer>> list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			int b = Integer.parseInt(sa[1]) - 1;
			list.get(a).add(b);
			list.get(b).add(a);
		}
		br.close();

		int[] ans = new int[n];
		Arrays.fill(ans, -1);
		Queue<Integer> que = new ArrayDeque<>();
		que.add(0);
		ans[0] = 0;
		while (!que.isEmpty()) {
			int cur = que.poll();
			for (int next : list.get(cur)) {
				if (ans[next] == -1) {
					que.add(next);
					ans[next] = cur;
				}
			}
		}

		PrintWriter pw = new PrintWriter(System.out);
		pw.println("Yes");
		for (int i = 1; i < n; i++) {
			pw.println(ans[i] + 1);
		}
		pw.flush();
	}
}


Measured memory_bytes: 71908
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
    int n;
    cin>>n;
    int sum=0;
    int temp=n;
    while(temp>0){
        int rem=temp%10;
        temp=temp/10;
        sum+=rem;
    }
    if(n%sum==0)cout<<"Yes";
    else cout<<"No";
}


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

typedef complex<double> P;

int main(){
	int n;
	while(cin >> n && n){
		int ans = -1e9;
		int tot = 0;
		for(int i = 0 ; i < n ; i++){
			if( tot < 0 ) tot = 0;
			int x;
			cin >> x;
			tot += x;
			ans = max(ans,tot);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
bool visited[100005];
const int max_N=1e5+10;
int N, M, C;
int A[25][25];
int B[25];
int main(void)
{
  cin >> N >> M >> C;
  for(int i=0; i<M; i++){
    cin >> B[i];
  }
  for(int i=0; i<N; i++){
    for(int j=0; j<M; j++){
      cin >> A[i][j];
    }
  }
  int count=0;
  for(int i=0; i<N; i++){
    int sum=C;
    for(int j=0; j<M; j++){
      sum = sum + B[j]*A[i][j];
    }
    if(sum > 0)count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		String S = nextString();

		String ans = "None";
		for(int i=0;i<='z'-'a';i++){
			if(S.replaceAll(String.valueOf((char)('a'+i)), "").length()==S.length()){
				ans=String.valueOf((char)('a'+i));
				break;
			}
		}
		System.out.println(ans);
	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 38496
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
#define reps(i, S, E) for (ll i = (S); i <= (E); i++)
#define rep(i, N) reps(i, 0, N-1)
#define deps(i, E, S) for (ll i = (E); i >= (S); i--)
#define dep(i, N) deps(i, N-1, 0)
void chmax(ll &a, ll b) { if (a < b) a = b; }

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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

//D
void chmin(int &a, int b) { if (a > b) a = b; }

int main() {
	ll N;
	scanf("%lld", &N);
	char s[101010];
	scanf("%s", s);
	ll len = strlen(s);

	//vector<vector<bool>> a(1000, vector<bool>(3, false));
	vector<bool> a1(10, false);
	vector<bool> a2(100, false);
	vector<bool> a3(1000, false);

	rep(i, N) {
		int num = s[i] - '0';

		rep(j, 100) {
			if (a2[j] == true) {
				a3[j + num * 100] = i;
			}
		}

		rep(j, 10) {
			if (a1[j] == true) {
				a2[j + num * 10] = i;
			}
		}

		a1[num] = true;
	}

	ll result = 0;

	rep(i, 1000) {
		if (a3[i] == true) {
			result++;
		}
	}

	printf("%lld\n", result);
}


//C
/*
int main() {
	ll X;
	scanf("%lld", &X);

	ll div = X / 100;
	ll mod = X % 100;

	if (div * 5 >= mod) {
		printf("1\n");
	}
	else {
		printf("0\n");
	}
}
*/

//B
/*
int main() {
	ll N;
	scanf("%lld", &N);

	ll temp = (ll)((double)N / 1.08);

	ll result = 0;

	if ((ll)((double)temp * 1.08) == N) {
		result = temp;
	}
	else if ((ll)((double)(temp - 1) * 1.08) == N) {
		result = temp - 1;
	}
	else if ((ll)((double)(temp + 1) * 1.08) == N) {
		result = temp + 1;
	}
	else {
		printf(":(\n");
		return 0;
	}

	printf("%lld\n", result);
}
*/

//A
/*
int main() {
	ll M1;
	scanf("%lld", &M1);
	ll D1;
	scanf("%lld", &D1);
	ll M2;
	scanf("%lld", &M2);
	ll D2;
	scanf("%lld", &D2);

	ll result = 0;

	if (M1 != M2) {
		result = 1;
	}

	printf("%lld\n", result);
}
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll a[200005];
ll hx[200005];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(ll i=0;i<n;i++){
		cin >> a[i];
		hx[a[i]]++;
	}
	ll sum=0;
	for(ll i=0;i<200005;i++){
		if(hx[i]>0) sum+=(hx[i])*(hx[i]-1)/2;
	}
	//cout << sum << endl;
	for(ll i=0;i<n;i++){
		ll hhh=sum;
		hhh-=(hx[a[i]])*(hx[a[i]]-1)/2;
		if(hx[a[i]]-1>0) hhh+=(hx[a[i]]-1)*(hx[a[i]]-2)/2;
		cout << hhh << endl;
	}
	return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,int> li;
typedef pair<int,ll> il;
typedef vector<il> vil;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
vector<vil> graph;
vector<ll> dist;
void dijkstra()
{
	dist[1] = 0ll;
	priority_queue<li,vector<li>,greater<li> >pq;
	pq.push(li(0ll,1));
	while(!pq.empty())
	{
		li x = pq.top();pq.pop();
		ll a = x.first;
		int b = x.second;
		if(dist[b]==a)
		{
			for(int i=0;i<graph[b].size();++i)
			{
				il c = graph[b][i];
				if(dist[c.first]==-1||dist[c.first] > dist[b] + c.second)
				{
					dist[c.first] = dist[b] + c.second;
					pq.push(li(dist[c.first],c.first));
				}
			}
		}
	}
}
int main()
{
	int n,m,i,x,y;
	ll w;
	cin>>n>>m;
	graph.assign(n+1,vil());
	dist.assign(n+1,-1);
	for(i=1;i<=n;++i)
	{
		graph[i].push_back(il(i-1,0ll));
	}
	for(i=1;i<=m;++i)
	{
		cin>>x>>y>>w;
		graph[x].push_back(il(y,w));
		graph[y].push_back(il(x,w));
	}
	dijkstra();
	printf("%lld",dist[n]);
}

Measured memory_bytes: 13048
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
vector<int>g[2005];
int n,m,ml,sum;
inline void dfs(int x,int fa,int d)
{
	if(d>m/2)
		sum++;
	for(int i=0;i<g[x].size();i++)
		if(g[x][i]!=fa)
			dfs(g[x][i],x,d+1);
}
inline void dfs1(int x,int fa,int d)
{
	if(d>m/2)
		sum++;
	for(int i=0;i<g[x].size();i++)
		if(g[x][i]!=fa)
			dfs(g[x][i],x,d+1);
	for(int i=0;i<g[fa].size();i++)
		if(g[fa][i]!=x)
			dfs(g[fa][i],fa,d+1);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int ans=0x3f3f3f3f;
	if(m%2==0)
	{
		for(int i=1;i<=n;i++)
		{
			sum=0;
			dfs(i,0,0);
			ans=min(sum,ans);
		}
		printf("%d\n",ans);
	}
	else
	{
		for(int i=1;i<=n;i++)
			for(int x=0;x<g[i].size();x++)
			{
				sum=0;
				dfs1(i,g[i][x],0);
				ans=min(sum,ans);
			}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 384
from collections import Counter
from heapq import heappush, heappop, heapreplace


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

AC = Counter(A)
BC = Counter(B)
S = AC + BC

q = []
for k, v in S.items():
    heappush(q, (-v, k))

ans = []
while q:
    v, k = q[0]
    v = -v
    if v == 0:
        heappop(q)
    elif v != S[k]:
        heapreplace(q, (-S[k], k))
    else:
        heapreplace(q, (-(v - 1), k))
        if v > N:
            print('No')
            exit()
        else:
            if AC[k] > 0:
                a = k
                for l in BC.keys():
                    if l != k:
                        b = l
                        break
            else:
                b = k
                for l in AC.keys():
                    if l != k:
                        a = l
                        break
            ans.append((a, b))
            S[a] -= 1
            S[b] -= 1
            AC[a] -= 1
            if not AC[a]:
                AC.pop(a)
            BC[b] -= 1
            if not BC[b]:
                BC.pop(b)

print('Yes')
ans.sort()
X = [b for a, b in ans]
print(*X)


Measured memory_bytes: 198852
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,k,r,s,p;
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  vi enemy(n);
  vi player(n);
  int ans = 0;
  rep(i, n){
    if(t[i] == 'r'){
      enemy[i] = 0;
      player[i] = 2;
      if(i < k || player[i - k] != 2) ans += p;
      else player[i] = -1;
    }else if(t[i] == 's'){
      enemy[i] = 1;
      player[i] = 0;
      if(i < k || player[i - k] != 0) ans += r;
      else player[i] = -1;
    }else if(t[i] == 'p'){
      enemy[i] = 2;
      player[i] = 1;
      if(i < k || player[i - k] != 1) ans += s;
      else player[i] = -1;
    }
  }
  cout << ans << endl;
}

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

int main()
{
    long long L, R;
    cin >> L >> R;
    if (2019 <= R - L)
    {
        cout << 0 << endl;
    }
    else
    {
        long long ans = 2019;
        for (long long i = L; i <= R; i++)
        {
            for (long long j = i + 1; j <= R; j++)
            {
                ans = min(ans, (i * j) % 2019LL);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;


int main()
{
    int n;
    ll ans = 0;
    cin >> n;
    int sg[9][9];
    for(int i = 0; i < 9; i++){
        for(int j = 0; j < 9; j++){
            sg[i][j] = 0;
        }
    }
    for(int i = 1; i <= n; i++){
        string s;
        s = to_string(i);
        int f = s[0] - '0';
        int l = s[s.size()-1] - '0';
        if(f > 0 && l > 0){
            sg[f-1][l-1]++;
        }
        
    }
    for(int i = 0; i < 9; i++){
        for(int j = 0; j <= i; j++){
            int tmp = min(sg[i][j],sg[j][i]);
            if(i == j){
                ans += sg[j][i]*sg[i][j];
            }else{
                ans +=  sg[j][i]*sg[i][j]* 2;
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

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

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

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

ll K;
void input(){
    fast_io();
    cin >> K;
}

int solve(){
    int N=50;
    ll x = K/N;
    ll r = K%N;
    vector<ll> A(N,N-1+x-r);
    for (int i = 0; i < r; i++)
    {
        A[i]+=(N+1);
    }
    cout << N << endl;
    cout << A << endl;
    

    return 0;
}   

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

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln

void main() {
	int n;
	scanf("%d", &n);
	int[] x = new int[n];
	foreach (i; 0..n) scanf("%d", &x[i]);
	int[] y = x.dup;
	y.sort;
	int l = y[n/2-1], r = y[n/2];
	foreach (i; 0..n) {
		if (x[i] <= l) writeln(r);
		else writeln(l);
	}
}

Measured memory_bytes: 5108
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s,t;cin>>s;cin>>t;
  bool is_possible=true; ll pos=0;
  vector<char> v(26,' '),v_(26,' ');
  rep(i,s.length()) {
    pos=t[i]-'a';
    if(v[pos]==' ') v[pos]=s[i];
    if(v[pos]!=' '&&v[pos]!=s[i]) {is_possible=false;break;}
  }
  if (is_possible) {
    rep(i,t.length()) {
      pos=s[i]-'a';
      if(v_[pos]==' ') v_[pos]=t[i];
      if(v_[pos]!=' '&&v_[pos]!=t[i]) {is_possible=false;break;}
    }
  }
  print(is_possible?"Yes":"No");
  return 0;
}

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

int main() {
	int m, f, r;
	
	while(1){
		cin >> m >> f >> r;

		if (m == -1 && f == -1 && r == -1)
			break;
		else if (m == -1 || f == -1)
			cout << 'F' << endl;
		else if (m + f >= 80)
			cout << 'A' << endl;
		else if (m + f >= 65 && m + f < 80)
			cout << 'B' << endl;
		else if (m + f < 65 && m + f >= 50)
			cout << 'C' << endl;
		else if (m + f >= 30 && m + f < 50) {
			if (r >= 50)
				cout << 'C' << endl;
			else cout << 'D' << endl;
		}
		else cout << 'F' << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
import java.util.Arrays;
import java.util.Scanner;

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

		int N=sc.nextInt();
		int M=sc.nextInt();
		int atari=0;
		int hazure=0;
		int okane=0;
		int[] amari=new int[1000];
		int goods=M-1;
		for(int i=0; i<M; i++) {
			atari=sc.nextInt();
			hazure=sc.nextInt();
			if(atari>=N) {
				goods--;
			}
			else {
				amari[okane]=atari;
				okane++;
			}
		}
		int kingaku=0;
		if(goods>0) {
			Arrays.sort(amari);

			for(int i=0; i<goods; i++) {
				kingaku+=N-amari[999-i];
			}
		}
		System.out.println(Math.max(kingaku,0));
	}
}



Measured memory_bytes: 33580
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int n,a[202020];
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	fo(i,0,n)cin>>a[i];
	sort(a,a+n);
	fo(i,0,n-1) if(a[i]==a[i+1]){
		cout<<"NO\n";
		return 0;
	}
	cout<<"YES\n";
	return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def dfs(N, nodes, src):
    """ DFS(木、スタック、重みあり) """

    stack = [(src, -1, 0)]
    dist = [INF] * N
    while stack:
        u, prev, c1 = stack.pop()
        dist[u] = c1
        for v, c2 in nodes[u]:
            if v != prev:
                stack.append((v, u, c1+c2))
    return dist

N = INT()
nodes = [[] for i in range(N)]
for i in range(N-1):
    a, b, c = MAP()
    a -= 1; b -= 1
    nodes[a].append((b, c))
    nodes[b].append((a, c))

Q, K = MAP()
K -= 1
res = dfs(N, nodes, K)
for i in range(Q):
    x, y = MAP()
    x -= 1; y -= 1
    ans = res[x] + res[y]
    print(ans)


Measured memory_bytes: 47020
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a>> b>> c>> d;
    
    if((c+b-1)/b <= (a+d-1)/d)
        cout << "Yes" <<endl;
    else cout << "No" << endl;
    
    
    
    return 0;
}


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

int div2c(int a) {
  int c = 0;
  while(a % 2 != 1) {
    a/=2;
    c++;
    if (c>=2) break;
  }
  return c;
}

int main() {
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  string ans = "No";
  map<int,int> m;

  rep(i,n) {
    m[div2c(a[i])]++;
  }
  int d = n - m[1];
  if (d/2 <= m[2]) ans = "Yes";
  if ((d-m[2]) > d/2 && m[1] > 0) ans = "No";

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

Measured memory_bytes: 3788
#include <stdio.h>
#include <string.h>
#include <algorithm>


using LL = long long ;
const int kN = 100000 + 5;
int n, k, a[kN], b[kN];

int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++ i)
        scanf("%d%d", a + i, b + i);

    LL result = 0;
    k += 1;
    for (int diff = 30; diff >= 0; -- diff) if (k >> diff & 1) {
        int mask = k >> diff ^ 1;
        LL tmp = 0;
        for (int i = 0; i < n; ++ i)
            if ((a[i] >> diff & ~mask) == 0)
                tmp += b[i];
        result = std::max(result, tmp);
        // printf("diff = %d, tmp = %lld\n", diff, tmp);
    }
    printf("%lld\n", result);
}


Measured memory_bytes: 1024
from math import floor, sqrt, ceil


def f(b, n):
    if n < b:
        return n

    return f(b, floor(n / b)) + n % b


n = int(input())
s = int(input())

if n == s:
    print(n + 1)
    exit()

for b in range(2, floor(sqrt(n)) + 1):
    if f(b, n) == s:
        print(b)
        exit()

for p in range(1, ceil(sqrt(n)))[::-1]:
    b = (n - s) / p + 1
    if b.is_integer():
        b = int(b)
        if 1 <= p < b and 0 <= s - p < b:
            print(b)
            exit()

print(-1)


Measured memory_bytes: 3064
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int cnt[30];
signed main(void)
{
  int n;
  cin >> n;
  VI d(n+1);
  cnt[0] = 1;
  REP(i, n) cin >> d[i], cnt[d[i]]++;
  REP(i, 13) if(cnt[i] >= 3) {
    cout << 0 << endl;
    return 0;
  }

  if(n == 1) {
    cout << min(d[0], 24-d[0]) << endl;
    return 0;
  }

  d[n] = 0;
  sort(ALL(d));

  int lim = 12;
  REP(i, n+1) {
    FOR(j, i+1, n+1) {
      if(d[i] == d[j]) chmin(lim, 24-d[j]-d[i]);
      // cout << i << " " << d[i] << " " << j << " " << d[j] << " " << lim << endl;
    }
  }
  // cout << "lim:" << lim << endl;
  FOR(i, 1, n) {
    chmin(lim, min(d[i], 24-d[i]));
  }

  d.erase(unique(ALL(d)), d.end());

  VI v;
  int m = d.size();
  int ret = 0;
  REP(i, 1<<m) {
    v.clear();
    REP(j, m) {
      if(cnt[d[j]] == 2) v.PB(d[j]), v.PB(24-d[j]);
      else if(i&1<<j) {
        v.PB(d[j]);
      } else {
        v.PB((24-d[j])%24);
      }
    }
    sort(ALL(v));
    // for(int j: v) cout << j << " "; cout << endl;
    int res = INF;
    REP(j, v.size()) {
      FOR(k, j+1, v.size()) {
        chmin(res, min(v[k]-v[j], 24-(v[k]-v[j])));
      }
    }
    // cout << "i:" << i << " " << res << endl;
    chmax(ret, res);
  }
  cout << min(lim, ret) << endl;

  return 0;
}


Measured memory_bytes: 256