akhauriyash/Code-Regression huggingface dataset:
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from itertools import combinations as comb
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)
def y(f):
    if f:
        print('Yes')
    else:
        print('No')
def Y(f):
    if f:
        print('YES')
    else:
        print('NO')

n = int(input())
print(3 * n * n)

Measured memory_bytes: 5880
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;
#define pi 3.1415926

int a[(int)2e5][11];

int main(){
    string s;
    cin >> s;
    if(s[2]==s[3] && s[4]==s[5])
        cout << "Yes";
    else
        cout << "No";
    

}

    

		


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int m[26][26];

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    string s, t; cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        m[s[i]-'a'][t[i]-'a'] = 1;
    }    
    for (int i = 0; i < 26; i++) {
        int c = 0;
        for (int j = 0; j < 26; j++)
            if (m[i][j])
                c++;
        if (c >= 2) {
            cout << "No\n";
            return 0;
        }
    }

    for (int i = 0; i < 26; i++) {
        int c = 0;
        for (int j = 0; j < 26; j++)
            if (m[j][i])
                c++;
        if (c >= 2) {
            cout << "No\n";
            return 0;
        }
    }


    cout << " Yes\n";
    
    
    return 0;
}


Measured memory_bytes: 916
package main

import (
	"fmt"
	"math"
)

func main() {
	var x1, x2, y1, y2 float64
	fmt.Scan(&x1, &y1, &x2, &y2)
	fmt.Println(math.Sqrt(math.Pow(x1-x2, 2) + math.Pow(y1-y2, 2)))
}



Measured memory_bytes: 1184
function Main (input) {
  input = input.split(" ").map(inp => parseInt(inp, 10));
  input = input[0] + input[1] + input[2];
  
  if (input >= 22) console.log("bust");
  else console.log("win");
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
import math
n, p = map(int, input().split())

def factorize(m):
    a = []
    while m % 2 == 0:
        a.append(2)
        m //= 2
    f = 3
    while f*f <= m:
        if m%f == 0:
            a.append(f)
            m //= f
        else:
            f += 2
    if m != 1:
        a.append(m)
    return sorted(a)


if n == 1:
    print(p)
elif p != 1:
    a = factorize(p)
    count, ans = 1, 1
    for i in range(len(a)-1):
        if a[i] == a[i+1]:
            count += 1
        else:
            ans *= a[i]**math.floor(count/n)
            count = 1
    if count != 1:
        ans *= a[-1]**math.floor(count/n)
    print(ans)
            
else:
    print(1)



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

bool G[51][51];
ll n, m;

int main(int argc, char **argv)
{
	cin >> n >> m;


	memset(G, 0, sizeof(G));
	for (int i = 0; i < m; ++i)
	{
		int a, b; cin >> a >> b; --a, --b;
		G[a][b] = true;
		G[b][a] = true;
	}

	vector<ll> v;
	for (int i = 0; i < n; ++i)
		v.push_back(i);

	int count{0};
	do 
	{
		if (v[0] != 0) break;

		bool flag = true;
		for (int i = 0; i < n-1; ++i)
		{
			int current = v[i];
			int target = v[i+1];
			if (!G[current][target]) flag = false;
		}
		if (flag) count++;
	} while (next_permutation(v.begin(), v.end()));

	std::cout << count << std::endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define P pair<int, int>
#define rep(i,n)         for(int i=0; i<(n); i++)
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"

//----------------------------------------------------

int main(){
    string s; cin >> s;
    rep(i, s.size()){
        if(s[i] == '1') s[i] = '9';
        else if(s[i] == '9') s[i] = '1';
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
 int x, a, b;
 int A, B;
 scanf("%d %d %d", &x, &a, &b);
 if(x-a < 0){
  A = (x-a) * -1;
 }
  else if(x-a>=0){
   A= x-a;
  }
 if(x-b < 0){
  B = (x-b) * -1;
 }
  else if(x-b>=0){
   B= x-b;
  }
 if(A>B){
  printf("B");
 }
 else if(B>A){
  printf("A");
 }
 return 0;
}

Measured memory_bytes: 1628
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
#define mx 10000000000008
#define mod 1000000007
ll n,t,arr[sz],brr[sz],m;
vector<ll>v[sz];
char c[sz];
void bfs(ll node,ll par)
{
    for(int i=0;i<v[node].size();i++)
    {
        ll x=v[node][i];
        if(arr[x])
            continue;
        arr[x]=1;
        bfs(x,node);
    }
    return;
}
int main()
{
    //scanf("%lld",&t);
    t=1;
    while(t--)
    {
        scanf("%lld %lld",&n,&m);
        for(int i=1;i<=m;i++)
        {
            ll a,b;
            scanf("%lld %lld",&a,&b);
            v[a].push_back(b);
            v[b].push_back(a);
        }
        ll ans=0;
        for(int i=1;i<=n;i++)
        {
           if(!arr[i])
           {
               ans++;
               arr[i]=1;
               bfs(i,-1);
           }
        }
        printf("%lld\n",ans-1);
    }
    return 0;
}


Measured memory_bytes: 14032
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long 
#define ld long double
//=======================================================================================================
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
//=================================================================
#define vi vector<int>
#define vll vector<ll>
#define vvi vector< vector<int> >
#define vvll vector< vector<ll> >
#define vs vector<string>
#define si set<int>
#define sll set<ll>
#define ss set<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define pb push_back
#define fxsp(a) fixed<<setprecision(a)
//=============================================================
#define rFor(i,a,b) for(int i=a;i>b;i--)
#define For(i,a,b) for(int i=a;i<b;i++)
//=============================================================
void inout_fast(){
    //input output file && fast input
    ios::sync_with_stdio(0); 
    cin.tie(0);

      
}
//=====================================================================================================

int main(){
    inout_fast();
 //start coding :):):)  


    string s;
    getline(cin, s);
    if(s[0]=='7'||s[1]=='7'||s[2]=='7')
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    
    
    return 0;
}

Measured memory_bytes: 3640
import sys
from itertools import combinations_with_replacement as cwr
input = sys.stdin.readline

N,M,Q = map(int,input().split())
A,B,C,D = [],[],[],[]
for i in range(Q):
    a,b,c,d = map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)

ans = 0
combs = list(cwr(range(1,M+1),N))
ans = [0]*(len(combs))
for i,comb in enumerate(combs):
    for a,b,c,d in zip(A,B,C,D):
        if comb[b-1] - comb[a-1] ==c:
            ans[i] += d
print(max(ans))

Measured memory_bytes: 85688
import sys
input = sys.stdin.readline
H,W=map(int,input().split())
s=[]
s0=""
for i in range(W+2):
    s0+="."
s.append(s0)
for i in range(H):
    ss="."
    ss+=input().strip()+"."
    s.append(ss)
s.append(s0)
#print(s)
flg=True
for h in range(H+1):
    for w in range(W+1):
        if s[h][w]=="#":
            flg=False
            for i in [1,-1]:
                if s[h+i][w]=="#":
                    flg=True
                if s[h][w+i]=="#":
                    flg=True
            if flg==False:
                print("No")
                exit()
print("Yes")


Measured memory_bytes: 39536
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

int main() {
    long long N, M;
    cin >> N >> M;
    //はしだけ調べればよい
    if(N == 1 and M == 1) {
        cout << 1 << endl;
        return 0;
    }
    if(N == 1 or M == 1) {
        cout << max(N, M) - 2 << endl;
    } else {
        cout << N * M - 2 * (M + N) + 4 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include <iomanip>
#include <algorithm>

using namespace std;

int main(){
	/* 
	int a = 0;
	int b = 0;
	scanf("%d",&a);
	scanf("%d",&b);
	
	int array1[3] = {0,0,0};
	array1[0] = a + b;
	array1[1] = a - b;
	array1[2] = a * b;
	sort(array1,array1+3);
	
	cout<< array1[2]<<endl;
	*/
	
	
	int k = 0;
	int x = 0;
	scanf("%d",&k);
	scanf("%d",&x);
	
	for(int i=0;i<2*k - 1;i++){
		int temp = x - k + 1 + i;
		cout<< temp <<" ";
	} 
	cout<<"\n";
	
	
	return 0;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
using namespace std;
int a,b,c;
int main()
{
    while(~scanf("%d%d%d",&a,&b,&c))
    {
        b/=a;
        if(c<=b){printf("%d\n",c);}
        else{printf("%d\n",b);}
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n)           REPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
typedef unsigned long long ull;

int main(){
    int n;
    cin >> n;       // 10^5
    ull total = 0;
    REP(i,n){
        ull t;
        cin >> t;   // >= 10^6
        total += t;
    }
    cout << total/n << endl;
    return 0;
}

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

int arr[100010];
int dp[100010];

int main (){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> arr[i];
	}
	dp[1] = 0;
	dp[2] = abs(arr[1] - arr[2]);
	
	for(int i = 3; i <= n; i++){
		dp[i] = min(abs(arr[i] - arr[i - 1]) + dp[i - 1], abs(arr[i] - arr[i - 2]) + dp[i - 2]);		//nyari dp
	}
	
	cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void){

int i,j,x;

int max=0;

int min=0;

long sum=0L;

scanf("%d",&j);

for(i=0;i<j;i++){

scanf("%d",&x);

sum+=(long)x;

if(i==0){

max=x;

min=x;

}

if(x>max){

max=x;

}else if(x<min){

min=x;

}

x=0;

}

printf("%d %d %ld\n",min,max,sum);

return 0;

}

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

using namespace std;

const int maxn = 200000 + 10;

const int maxw = 200000 + 10;

inline int input() {
   int a = 0,w = 1;
   char ch = getchar();
   while(ch < '0' || ch > '9') {
       if (ch == '-') w = -1;
       ch = getchar();
    }
   while (ch >= '0' && ch <= '9')  {
       a = a * 10 + ch - '0';
       ch = getchar();
   }
   return a * w;
}

int s[maxn]/*, cnt[maxw], b[maxn]*/;
priority_queue<int> que;

int main() {
    int n = input();
    for  (int i = 0; i < n; i++) {
        s[i] = input();
        que.push(s[i]);
        //cnt[s[i]]++;
    }
    int b = que.top(); que.pop();
    int c = que.top(); que.pop();
    //cout << b << " " << c << endl;
    for (int i = 0; i < n; i++) {
        if (s[i] == b) cout << c <<endl;
        else cout << b << endl;
    }
    /*for (int i = 1; i < maxw; i++) {
        cnt[i] += cnt[i - 1];
    }
    for (int i = n - 1; i >= 0; i--) {
        b[i] = s[--cnt[s[i]]];
    }
    for (int i = 0; i < n; i++) {
        if (s[i] == b[n - 1]) cout << b[n - 2] << endl;
        else cout << b[n - 1] << endl;
    }*/
    return 0;
}

Measured memory_bytes: 3316
import java.util.Scanner;

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

        int K = scanner.nextInt();
        int N = scanner.nextInt();

        int[] A = new int[N + 1];

        int longestDist = 0;
        int totalDist = 0;
        for (int i = 1 ; i <= N ; i++) {
            A[i] = scanner.nextInt();
            if (i != 1) {
                int dist = A[i] - A[i - 1];
                totalDist += dist;
                longestDist = Math.max(longestDist, dist);
            }
        }

        int dist = K - A[N] + A[1];
        totalDist += dist;
        longestDist = Math.max(longestDist, dist);
        System.out.println(totalDist - longestDist);
    }
}


Measured memory_bytes: 72216
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <queue>
#include <stack>
#include <deque>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

void yes(){
	cout<<"YES";
	exit(0);
}

void no(){
	cout<<"NO";
	exit(0);
}

const int sz = 5e5 + 7; 
// int arr;
long long int arr[sz];
int dp[sz];
// int d1[size];
// int dn[size];
pair<int, long long int> dl[sz], dr[sz];
// int special_nodes[size];
// bool visited[size];
// vector<int> graph[size];

// void bfs(int u, int *arr) {
// 	queue<int> q;
// 	memset(visited, 0, sizeof(visited));
// 	q.push(u);
// 	visited[u] = true;
// 	while(!q.empty()) {
// 		int t = q.front();
// 		q.pop();
// 		for(int x: graph[t]){
// 			if(!visited[x]) {
// 				visited[x] = true;
// 				arr[x] = arr[t] + 1;
// 				q.push(x);
// 			}
// 		}
// 	}
// }

long long int solve(int i, int n) {
	if(i > n) return INT_MAX;
	if(i== n) return 0;
	if(dp[i] != -1) return dp[i];
	long long int ans = INT_MAX;
	if(i + 1 <= n) ans = min(ans, solve(i +1, n) + abs(arr[i+1] - arr[i]));
	if(i +2<=n) ans = min(ans, solve(i+2, n) + abs(arr[i+2] - arr[i]));
	dp[i] = ans;
	return ans;
}

int main() {
	int n;
	cin>>n;
	for(int x=1;x<=n;x++){
		cin>>arr[x];
	}
	for(int x=0;x<sz;x++) dp[x] = -1;
	// dp[]	
	cout<<solve(1, n);
}


Measured memory_bytes: 11040
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Yes" : "No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int main() {
	string a, b, c;
	int ans = 0;
	cin >> a >> b >> c;

	printf("%c%c%c\n", a[0], b[0], c[0]);
}

Measured memory_bytes: 3608
n = int(input())
w = list(map(int, input().split()))
s = []

for i in range(1, n):
    #print(w[0:i])
    #print(w[i:n])
    s.append(abs(sum(w[0:i])-sum(w[i:n])))
s.sort()
print(s[0])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, l, r;
  int count = 0;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> l >> r;
    count = count + r - l + 1;
  }
  cout << count << endl;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}


int main(){
  string S; cin >> S;
  int N = S.length(), ans = 0;
  for (int i = 0; i < N; i++){
    if (S[i] == 'p') ans--;
  }
  ans += N / 2;
  cout << ans << endl;

  return 0;
}


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

namespace program
{
    class Program
    {
        static void Main()
        {
            int[] input = Input.ScanIntArray();
          Array.Sort(input);
         
          if(input[0]+input[1] == input[2])
	          Console.WriteLine("Yes");
          else
	          Console.WriteLine("No");
            
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


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

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

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

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

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

  ll n, m;
  cin >> n >> m;

  cout << pow(2, m)*(1900*m+100*(n-m)) << endl;
  
  
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const ll sz=1<<17;
ll n, lt=1, rt=1e9, md, ans, a[sz], tr[sz<<1];

void add(int p) {
	while(p < sz<<1) {
		tr[p]++;
		p += p & -p;
	}
}

int sum(int p) {
	ll res=0;
	while(p){
		res += tr[p];
		p -= p & -p;
	}
	return res;
}

bool f(int p){
	ll i, k, cnt=0;
	memset(tr, 0, sizeof(tr));
	for(i=1, k=sz; i<=n; i++) {
		add(k);
		k += a[i]>=p ? 1:-1;
		cnt += sum(k);
	}
	return cnt >= (n*(n+1)/2+1)/2;
}

int main() {
	scanf("%lld", &n);
	for(ll i=1; i<=n; i++) scanf("%lld", &a[i]);
	while(lt<=rt){
		md = lt+rt >> 1;
		if(f(md)) ans=md, lt=md+1;
		else rt=md-1;
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 3072
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

int n,h,w;

int main(){
	scanf("%d%d%d",&n,&h,&w);
	printf("%d\n",(n-h+1)*(n-w+1));
	return 0;
}

Measured memory_bytes: 256
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll mod = 1e9+7;
const ll N = 1e5+5;
ll fact[N],inv[N];
ll power(ll x,ll y)
{
	ll ans=1;
	while(y)
	{
		if(y&1) ans=(ans*x)%mod;
		y>>=1;
		x=(x*x)%mod;
	}
	return ans;
}
void init()
{
	fact[0]=inv[0]=1;
	rep(i,1,N) fact[i]=(fact[i-1]*i)%mod;
	rep(i,1,N) inv[i]=(inv[i-1]*power(i,mod-2))%mod;
}

ll ncr(ll n,ll r)
{
	if(r>n || r<0) return 0;
	if(n<0) return 0;
	return (fact[n]*((inv[n-r]*inv[r])%mod))%mod;
}

int solve()
{
	init();
	ll n,k;cin>>n>>k;
	vi a(n);
	rep(i,0,n) cin>>a[i];
	sort(a.begin(), a.end());
	ll ans=0;
	// whatis(ncr(5,2));
	rep(i,0,n) ans = (ans - (a[i]*ncr(n-1-i,k-1))%mod+(a[i]*ncr(i,k-1))%mod+mod)%mod;
	cout<<ans<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 2560
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

int main() {
  double N, D;
  cin >> N >> D;
  cout << ceil(N / (2 * D + 1)) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200005
using namespace std;
int n,m,len,a[N],c[2*N],S[2*N],ans;
void del(int x)
{
	c[x]--,S[x-c[x]+N]--;
	if(x-c[x]>0&&!S[x-c[x]+N]) ans++;
}
void ins(int x)
{
	S[x-c[x]+N]++,c[x]++;
	if(x-c[x]>=0&&S[x-c[x]+1+N]==1) ans--;
}
int gi(){ int w=0; char c=getchar(); while(c<'0'||c>'9') c=getchar(); while(c>='0'&&c<='9') w=w*10+c-'0',c=getchar(); return w;}
void pr(int x)
{
	char st[8]; len=0;
	if(!x){ putchar('0'),putchar('\n'); return ;}
	while(x) st[++len]=x%10+'0',x/=10;
	for(int i=len;i>=1;i--) putchar(st[i]);
	putchar('\n');
}
int main()
{
	int i,x,y;
	n=gi(),m=gi();
	for(i=1;i<=n;i++)
		a[i]=gi(),c[a[i]]++;
	for(i=1;i<=n;i++) S[i-c[i]+1+N]++,S[i+1+N]--;
	for(i=1;i<2*N;i++) S[i]+=S[i-1];
	for(i=1;i<=n;i++) ans+=(S[i+N]==0);
	while(m--){
		x=gi(),y=gi();
		del(a[x]),ins(y);
a[x]=y;
		pr(ans);
	  }
	return 0;
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int h1, m1, h2, m2, x;
	cin >> h1 >> m1 >> h2 >> m2 >> x;
	cout << h2 * 60 + m2 - h1 * 60 - m1 - x << endl; 
	return 0;
}



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

import collections

s = collections.deque(input().strip())
num = int(input())
query = [0] * num
for i in range(num):
    query[i] = input().strip()

reverse_flag = False
for q in query:
    if q[0] == '1':
        reverse_flag = not reverse_flag
    else:
        _, f, c = q.split()
        if (f == '1' and not reverse_flag) or (f == '2' and reverse_flag):
            s.appendleft(c)
        if (f == '2' and not reverse_flag) or (f == '1' and reverse_flag):
            s.append(c)
if reverse_flag:
    s.reverse()
print(''.join(list(s)))


Measured memory_bytes: 89436
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=3e3+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
}
int n,mo;
void input()
{
	n=read<int>(),mo=read<int>();
}
int f[N][N];
ll power(ll x,int y,int Mod)
{
	ll res=1;
	for(;y;x=x*x%Mod,y>>=1)if(y&1)res=res*x%Mod;
	return res;
}
int g[N];
int mc[N],inv[N];
ll C(int x,int y){return 1ll*mc[x]*inv[y]%mo*inv[x-y]%mo;}
ll cal(int i)
{
	int res=0;
	int x=power(2,n-i,mo-1);
	x=power(2,x,mo);
	For(j,0,i)res=(res+1ll*power(2,(n-i)*j,mo)*f[i][j]%mo)%mo;
	return 1ll*x*res%mo;
}
void work()
{
	f[0][0]=1;
	For(i,1,n)
	{
		f[i][0]=1;
		For(j,1,i)f[i][j]=(f[i-1][j-1]+1ll*f[i-1][j]*(j+1)%mo)%mo;
	}
	mc[0]=inv[0]=1;
	For(i,1,n)mc[i]=1ll*mc[i-1]*i%mo;
	inv[n]=power(mc[n],mo-2,mo);
	Fordown(i,n-1,1)inv[i]=1ll*inv[i+1]*(i+1)%mo;
	int ans=0;
	For(i,0,n)
	{
		if(i&1)ans=(ans+mo-1ll*C(n,i)*cal(i)%mo)%mo;
		else ans=(ans+1ll*C(n,i)*cal(i)%mo)%mo;
	}
	write(ans,'\n');
}
int main()
{
//	file();
	input();
	work();
	return 0;
}

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

// #define int ll
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define fastio    ios::sync_with_stdio(0); cin.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp        make_pair
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second

int inf(0x3fffffff);
int mod(1000000007);
double pi(acos(-1.0));

int32_t main() {
  fastio;
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif

  ll a;
  double b;
  cin >> a >> b;
  ll bb = round(b * 100);
  cout << a * bb / 100;

  return 0;
}


Measured memory_bytes: 3788
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll x,a,b;
  cin >> x >> a >> b;
  if(a>=b){
    cout <<"delicious"<<endl;
  }else if(x>=b-a){
    cout <<"safe"<<endl;
  }else{
    cout <<"dangerous"<<endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<deque>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;


int dijkstra(int K) {
	vector<int> d(K, INF);
	deque<pair<int,int>> q;
	
	q.push_back({1,1});
	
	while(!q.empty()){
		pair<int,int> p = q.front(); q.pop_front();
		
		if(!p.second) return p.first;
		
		if(p.first > d[p.second]) continue;
		
		if(d[(p.second+1)%K] > p.first + 1) {
			d[(p.second+1)%K] = p.first + 1;
			q.push_back({p.first+1, (p.second + 1)%K});
		}
		
		if(d[(p.second*10)%K] > p.first) {
			d[(p.second*10)%K] = p.first;
			q.push_front({p.first, (p.second*10)%K});
		}
	}
}

signed main(){
	cout<<fixed<<setprecision(10);
	
	int K;
	
	cin>>K;
	
	cout<<dijkstra(K)<<endl;
	
	
	return 0;
}

Measured memory_bytes: 4772
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll A,B,C,X,Y;
	while(cin>>A>>B>>C>>X>>Y) {
		VI cs;
		cs.PB(A*X+B*Y);
		ll m=min(X,Y);
		cs.PB(m*C*2+A*(X-m)+B*(Y-m));
		cs.PB(m*C*2+2*C*(X-m)+B*(Y-m));
		cs.PB(m*C*2+A*(X-m)+2*C*(Y-m));
		cs.PB(m*C*2+2*C*(X-m)+2*C*(Y-m));
		ll ans=*min_element(ALL(cs));
		cout<<ans<<endl;
	}
	
	return 0;
}


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

long long gcd(long long a, long long b){
    long long write;
    if(0 == b){
        write = a;
    }else{
        write = gcd(b, a % b);
    }

    return write;
}

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

int main(){
    int n;
    std::cin >> n;

    long long ans = 1, t;
    for(int i = 0; i < n; ++i){
        std::cin >> t;
        ans = lcm(ans, t);
    }

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

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define debug(x) cout << #x << " = " << (x) << endl;
#define pb push_back
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000000000
#define EPS 0.00000000001
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------

    int h,w;
    cin>>h>>w;
    int a[h+10][w+10];
    rep(i,h){
        rep(j,w){
            cin>>a[i][j];
        }
    }
    ll memo=0;
    vector<string> x(h*w+10);
    rep(i,h){
        rep(j,w-1){
            if(a[i][j]%2==1){
                a[i][j+1]++;
                //memo++;
                //cout<<i+1<<" "<<j+1<<" "<<i+1<<" "<<j+2<<endl;
                x[memo]+=to_string(i+1)+" "+to_string(j+1)+" "+to_string(i+1)+" "+to_string(j+2);
                memo++;
            }
        }
    }
    rep(i,h-1){
        if(a[i][w-1]%2==1){
            a[i+1][w-1]++;
            x[memo]+=to_string(i+1)+" "+to_string(w)+" "+to_string(i+2)+" "+to_string(w);
            memo++;
            //cout<<i+1<<" "<<w<<" "<<i+2<<" "<<w<<endl;
        }
    }
    cout<<memo<<endl;
    rep(i,memo){
        cout<<x[i]<<endl;
    }

}


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

int main()
{
  long long int a,b,c;
  cin >> a >> b >> c;
  long long int x,y,z;
  x=a+b;
  y=a-b;
  z=a*b;
  if(x>max(y,z))
  {
    cout << x << endl;
  }
  else
  {
    cout << max(y,z) << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std ;
int main()
{
    int n ,k ,i=1;
     double a,b,c;
    cin >> n >> k ;
    a = 1/( double)n  ;
    for(int i=1;i<=n;i++)
    {
        int x=0,p=i;
        while(p<k)
        {
            p*=2;
            x++;
        }
        c=pow(2,x);
        b += a*(1/c);
    }
    cout << setprecision(12)  << b << endl;
}


Measured memory_bytes: 256
# code-festival-2017-qualaC - Palindromic Matrix
def main():
    H, W, *A = open(0).read().split()
    H, W, C = int(H), int(W), {}
    for i in "".join(A):
        if i not in C:
            C[i] = 0
        C[i] += 1
    single = H & W & 1
    double = (H >> 1 if W & 1 else 0) + (W >> 1 if H & 1 else 0)
    C_mod4 = [i % 4 for i in C.values()]
    flg = C_mod4.count(1) + C_mod4.count(3) <= single and C_mod4.count(2) <= double
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int main(){
int n,i,taro=0,hanako=0;
char card1[101],card2[101];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%s %s",card1,card2);
if(strcmp(card1,card2)==0) taro+=1,hanako+=1;
else if(strcmp(card1,card2)>0) taro+=3;
else if(strcmp(card1,card2)<0) hanako+=3;
}
printf("%d %d\n",taro,hanako);
return 0; }


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;

int sum(int a, int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int sub(int a, int b) {
    return a - b < 0 ? a - b + MOD : a - b;
}
int mul(int a, int b) {
    return (1LL*a*b)%MOD;
}
int pw(int a, int b) {
	if (!b) return 1;
	int r = pw(a, b/2);
	r = mul(r, r);
	if (b%2) r = mul(r, a);
	return r;
}

const int MAXX = 1e6+7;
int fact[MAXX], ifact[MAXX];

int nCr(int n, int r) {
    if (r < 0 || n < r) return 0;
    return mul(fact[n], mul(ifact[r], ifact[n-r]));
}
int nPr(int n, int r) {
    if (r < 0 || n < r) return 0;
    return mul(fact[n], ifact[n-r]);
}

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

    fact[0] = 1;
    for (int i = 1; i < MAXX; i++)      fact[i] = mul(i, fact[i-1]);
    ifact[MAXX-1] = pw(fact[MAXX-1], MOD-2);
    for (int i = MAXX-2; i >= 0; i--)   ifact[i] = mul(i+1, ifact[i+1]);

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

    int ans = 0;
    for (int q = 0; q <= n; q++) {
        int tmp = mul(nCr(n, q), nPr(m-q, n-q));
        if (q&1) tmp = mul(tmp, MOD-1);
        ans = sum(ans, tmp);
    }

    ans = mul(ans, nPr(m, n));
    cout << ans << endl;

    return 0;
}


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

int main() {

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    long long h,w;
    cin>>h>>w;
    if(h == 1 || w ==1) {
    	cout<<1;
    	return 0;
    }

    long long ans = ceil((double)(h*w)/2); 
    cout<<ans;


	return 0;		
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

int n,m;vector<P> v[110000];
bool visited[110000];
int d[110000], mx, mm;
bool dfs(int x){
  chmax(mx, d[x]);chmin(mm, d[x]);
  if(visited[x])return true;
  visited[x] = true;
  bool ret = true;
  rep(i,v[x].size()){
    int to = v[x][i].first, dis = v[x][i].second;
    if(d[to] == INF){
      d[to] = d[x] + dis;
      ret = ret && dfs(to);
    }else if(d[to] == d[x] + dis){
      ret = ret && dfs(to);
    }else{
      return false;
    }
  }
  return ret;
}
signed main(){
  cin>>n>>m;
  rep(i,m){
    int l, r, d;cin>>l>>r>>d;
    l--;r--;
    v[l].push_back(P(r, d));
    v[r].push_back(P(l, -d));
  }
  rep(i,n)d[i] = INF;
  bool ans = true;
  rep(i,n){
    if(!visited[i]){
      d[i] = 0;mx = -INF, mm = INF;
      ans = ans && dfs(i);
      if(mx - mm > 1000000000)ans = false;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
}


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

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

  int N, M;
  cin >> N >> M;
  vector<int> X(M);
  REP(i, M) cin >> X[i];
  sort(X.begin(), X.end());
  vector<int> D(M - 1);
  if(N >= M) {
    cout << 0 << endl;
  } else {
    REP(i, M - 1) D[i] = X[i + 1] - X[i];
    sort(D.begin(), D.end());
    REP(i, N - 1) { D.pop_back(); }
    int ans = 0;
    REP(i, D.size()) { ans += D[i]; }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
n = input()
l = input().split()
w0,w1 = dict(),dict()
flag = 0
for i in l:
  if flag % 2 == 0:
    if i not in w0.keys():w0[i] = 1
    else:w0[i] += 1
  else:
    if i not in w1.keys():w1[i] = 1
    else:w1[i] += 1
  flag += 1
sumv = sum(w0.values()) + sum(w1.values())
def get_val(w0):
  l = list()
  w0_maxval = max(w0.values())
  w0_maxkey = [i for i in w0.keys() if w0[i] == w0_maxval][0]
  l.append({w0_maxkey:w0_maxval})
  del w0[w0_maxkey]
  if len(w0) > 0:
    w0_secval = max(w0.values())
    w0_seckey = [i for i in w0.keys() if w0[i] == w0_secval][0]
  else:
    w0_secval = 0
    w0_seckey = ""
  l.append({w0_seckey:w0_secval})
  return l
w0r = get_val(w0)
w1r = get_val(w1)
max = 0 
for i in w0r:
  for j in w1r:
    if list(i.keys())[0] != list(j.keys())[0]:
      if max < list(i.values())[0]  +  list(j.values())[0] : max = list(i.values())[0]  +  list(j.values())[0] 
print(sumv - max)

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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(c, b / a) << ln;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	string n;
	cin>>n;
	fori(3){
		cout<<(int)((n[i]=='1')?9:1);
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstring>
//#define Mfc_Tanzim
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ff first
#define ss second
#define all(v) (v.begin(), v.end())
#define pi acos(-1.0)
#define FastRead ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define bug(a) cerr << #a << " : " << a << endl
#define pq dp
using namespace std;
const ll mx = 4444444444;

ll posx[] = {1,-1, 0, 0};
ll posy[] = {0, 0, 1,-1};

int main()
{
    FastRead

#ifdef Mfc_Tanzim
    freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
#endif /// Mfc_Tanzim

    ll t=1, n, k, m, a, b, c, d;
    //cin >> t;

    while(t--){
              cin >> n;
              k = 0;
              for(ll i=1; i<1000000; i++){
                              k = (k*10+7)%n;
                              if(k){
                                       continue;
                              }
                              else{
                                       cout << i << endl;
                                       return 0;
                              }
              }
              cout << "-1" << endl;
    }
    return 0;
}


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

int main() {
    int N; cin >> N;
    int arr[N];
    int ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }
    sort(arr, arr + N, greater<int>());
    for (int i = 1; i < N; i++) {
        ans += arr[i - 1] - arr[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3652
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}

//解説AC
//https://atcoder.jp/contests/abc118/submissions/4292391

int num[]={0,2,5,5,4,5,6,3,7,6};
int a[10];
int n,m;

void cng(string &t, string p){
  if(t=="0") t=p;
  else if(t.size() < p.size())t=p;
  else if(t.size() == p.size()){
    if(t<p) t=p;
  }
}

int
main(void){  
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  REP(i,m) cin >> a[i];

  string dp[100100];

  REP(i, n+1) dp[i] = "0";

  dp[0] = "";
  REP(i, n+1){
    if(dp[i] == "0") continue;
    REP(j, m){
      cng(dp[i+num[a[j]]], dp[i]+(char)(a[j]+'0'));
    }
  }
  cout<<dp[n]<<endl;
  
}


Measured memory_bytes: 45568
N = int(input())
S = []
for i in range(N):
    s = input()
    ss = sorted(s)
    S.append("".join(ss))
S.sort()
ans = 0
count = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        count += 1
        ans += count
    else:
        count = 0
print(ans)


Measured memory_bytes: 57432
#include<bits/stdc++.h>
using namespace std;
int n,k;
const int maxn=2e3+10;
const int maxm=4e3+10;
int head[maxn];
int cnt;
int ans;
struct node{
    int u,v,to;
}ed[maxm];
void init(){
    cnt=0;
    for(int i=1;i<=n;++i){
        head[i]=-1;
    }
}
void add(int u,int v){
    ed[++cnt].u=u;
    ed[cnt].v=v;
    ed[cnt].to=head[u];
    head[u]=cnt;
}
void dfs(int x,int pre,int d){
//    cout<<x<<" "<<pre<<" "<<d<<endl;
    if(d>k)ans++;
    for(int i=head[x];i!=-1;i=ed[i].to){
        int u=x;
        int v=ed[i].v;
        if(v==pre)continue;
        dfs(v,u,d+1);
    }
}
int main(){
    cin>>n>>k;
    int nn=n;
    int a,b;
    init();
    ans=0;
    while(--nn){
        cin>>a>>b;
        add(a,b);
        add(b,a);
    }
    int res=0x3f3f3f3f;
    if(!(k&1)){
        k>>=1;
        for(int i=1;i<=n;++i){
            ans=0;
            dfs(i,-1,0);
            res=min(res,ans);
        }
        cout<<res<<endl;
    }
    else{
        k>>=1;
        for(int i=1;i<=2*n-3;i+=2){
            ans=0;
            int u=ed[i].u;
            int v=ed[i].v;
            int tmp=0;
            dfs(u,v,0);
            tmp+=ans;
            ans=0;
            dfs(v,u,0);
            tmp+=ans;
//            cout<<tmp<<endl;
            res=min(res,tmp);
        }
        cout<<res<<endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

// i*a + j*b + k*(a+b) = (i+k)*a + (j+k)*b = x

constexpr ll mod = 998244353;
#define NMAX 300010
ll fac[NMAX];
ll inv[NMAX];

ll mod_pow(ll a, ll n, ll mod){
    ll ret = 1;
    while(n > 0){
        if(n & 1) ret = (ret*(a % mod))%mod;
        a = ((a%mod)*(a%mod)) % mod;
        n = n >> 1;
    }
    return ret;
}

ll mod_inv(ll a, ll mod){
    return mod_pow(a, mod-2, mod);
}

void mae_nck(){
    fac[1] = 1;
    inv[1] = 1;
    for(ll i = 2; i < NMAX; i++){
        fac[i] = (fac[i-1] * i)%mod;
        inv[i] = (inv[i-1] * mod_inv(i, mod))%mod;
    }
}

ll mod_nck(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    if(k == 0 || k == n) return 1;
    ll ret = ((fac[n] * inv[k])%mod * inv[n-k])%mod;
    return ret;
}

int main(){
    mae_nck();

    ll n, a, b, k;
    cin >> n >> a >> b >> k;

    // a * i + b * j = k とすると，i を固定したときに，j = (k - a*i) / b
    // もちろん，割り切れる必要がある
    // ここで，r, g, b について，次のことが言える
    // r + g = i, b + g = j 
    // となると，r, g, b について，nCr x nCb で答えを導出できる

    ll ans = 0;
    rep(i, 0, n+1){
        if((k - a*i) % b != 0) continue;
        ll j = (k - a*i) / b;
        ans += (mod_nck(n, i) * mod_nck(n, j)) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8300