akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
using ull = unsigned long long;

int main(){
	string s;
	cin >> s;
	int index = s.size() - 1;
	ull answer = 0;
	unsigned bc = 0;
	while(index >= 2){
		while(index >= 2 && !(s[index - 1] == 'B' && s[index] == 'C')) index--;
		if(index < 2) break;
		while(index >= 2 && s[index - 1] == 'B' && s[index] == 'C'){
			index -= 2;
			bc++;
		}
		while(index >= 0 && s[index] == 'A'){
			index--;
			answer += bc;
		}
		if(!(s[index - 1] == 'B' && s[index] == 'C')) bc = 0;
	}
	printf("%llu\n", answer);
	return 0;
}

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

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A > B && A > C) {
        cout << B*C/2 << endl;
    }
    else if(B > A && B > C) {
        cout << A*C/2 << endl;
    }
    else {
        cout << A*B/2 << endl;
    }
}



Measured memory_bytes: 256
K,A,B = map(int,input().split())
if B-A <= 2:
    ans = K+1
elif K-A+1 <= 0:
    ans = K+1
else:
    x = (K-A+1)%2
    y = (B-A)*((K-A+1)//2)
    ans = A + x + y
print(ans)

Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
int main() {
  int n,a,b,ans = 0;
  cin >> n >> a >> b;
  
  rep(i,n){
    int quo = i+1,sum = 0;
    while(quo >= 10){
      sum += quo%10;
      quo = quo/10;
      
    }
    sum += quo;
    if(sum >= a && sum <= b) ans += i+1;
    //cout << i+1 << " " <<  sum << " " << ans << endl;
  }
  dunk(ans);
}


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

using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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; }

const long long INF = 1LL << 60;

bool dp[100100];

int main () {
    int H1 , M1, H2, M2,K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int time = (H2*60+M2)-K;
    cout << time-(H1*60+M1) << endl;

}



Measured memory_bytes: 3632
MOD = 1000000007
def hoge(a):
    b = a//2
    return (b*(b+1) + (a%2)*(b+1))%MOD
def power(a):
    return (a*a)%MOD
def abss(a):
    if a<0:
      return -a
    else:
      return a
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
dx = []
dy = []
n-=1
m-=1
for i in range(n):
    dx.append(x[i+1]-x[i])
for i in range(m):
    dy.append(y[i+1]-y[i])
cx = hoge(n)
cy = hoge(m)
sx = 0
sy = 0
for i in range(n):
    if n%2==1:
        sx += dx[i]*(cx-power(abss(i-n//2)))
    else:
        if i<(n//2):
            sx += dx[i]*(cx-(n//2-i-1)*(n//2-i))
        else:
            sx += dx[i]*(cx-(i-n//2)*(i-n//2+1))
    sx%=MOD
for i in range(m):
    if m%2==1:
        sy += dy[i]*(cy-power(abss(i-m//2)))
    else:
        if i<(m//2):
            sy += dy[i]*(cy-(m//2-i-1)*(m//2-i))
        else:
            sy += dy[i]*(cy-(i-m//2)*(i-m//2+1))
    sy%=MOD
ans = (sx*sy)%MOD
if ans<0:
    ans+=MOD
print(ans)

Measured memory_bytes: 19068
package main

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

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	
	n := scanInt()
	h := make([]int, n)

	for i := 0; i < n; i++ {
		h[i] = scanInt()
	}

	f := true

	pre := 0
	for i := 0; i < n; i++ {
		if pre <= h[i]-1 {
			pre = h[i]-1
		} else if pre <= h[i] {
			pre = h[i]
		} else {
			f = false
		}
	}

	if f {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 3072
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0,1,0,-1 };
const ll dy[4] = { -1, 0, 1,0 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////


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


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

vector<bool> flag(1000000);

int main(){
	int s, n;
	n = 1;
	cin >> s;
	flag[s] = true;
	n++;
	while(n < 1100000){
		if(s%2==0){
			s = s/2;
		}else{
			s = 3*s+1;
		}
		if(flag[s]==true){
			cout << n << endl;
			return 0;
		}else{
			flag[s] = true;
			n++;
		}
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n, m;
	cin>>n>>m;
	int ar[n][m];
	fore(i, 0, n)
		fore(j, 0, m)
			cin>>ar[i][j];
	string imp = "";
	int con = 0;
	vector<pair<pair<int,int>, pair<int, int>>> v;
	fore(i, 0, n)
		fore(j, 0, m)
		{
			if(ar[i][j]&1)
			{
				if(j == m-1)
				{
					if(i == n-1)
					{

					}
					else
					{
						ar[i+1][j]++;
						v.pb(mp(mp(i+1,j+1),mp(i+2,j+1)));
					}
				}
				else
				{
					ar[i][j+1]++;
					v.pb(mp(mp(i+1,j+1),mp(i+1,j+2)));
				}
			}
		}
		cout<<v.size()<<'\n';
		fore(i, 0, v.size()) cout<<v[i].f.f<<' '<<v[i].f.s<<' '<<v[i].s.f<<' '<<v[i].s.s<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

Measured memory_bytes: 5232
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
int main() {
	int N, Q;
	cin >> N >> Q;
	Graph G(N+10);
	for (int i = 1; i < N; i++) {
		int a, b;
		cin >> a >> b;
		G[b].push_back(a);
		G[a].push_back(b);
	}
	for (int i = 0; i < Q; i++) {
		int a, b;
		cin >> a >> b;
		sum[a] = b + sum[a];
	}
	queue<int> que;
	vector<int> s(200003);
	que.push(1);
	s[1] = 1;
	while (!que.empty()) {
		int v = que.front();
		que.pop();
		for (int nv : G[v]) {
			if (s[nv] == 1)
				continue;
			que.push(nv);
			s[nv] = 1;
			sum[nv] = sum[nv] + sum[v];
		}
	}
	for (int i = 1; i <= N; i++) {
			cout << sum[i] << " ";
	}
}

Measured memory_bytes: 17140
s = input()
res = 0
st = '0'
for c in s:
    if c !=st:
        res+=1
    if st=='0':
        st = '1'
    else:
        st = '0'
tmp = 0
st = '1'
for c in s:
    if c!=st:
        tmp+=1
    if st=='0':
        st='1'
    else:
        st='0'
res = min(tmp,res)
print(res)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
long long int A, B; 
long long int XXXOR(long long int X){
	long long int r = X % 4; 
	long long int ans = 0; 
	for(long long int i = 0; i < r+1; i++){
		ans ^= (X - i); 
	}
	return ans; 
}
int main(){
	cin >> A >> B; 
	long long int a = XXXOR(A-1); 
  	long long int b = XXXOR(B); 
	cout << (a^b) << endl;  
}

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[] a = new int[n];
    int sum = 0;
    for (int i=0;i<n;i++){
      a[i] = sc.nextInt();
      sum += a[i];
    }
    sc.close();
    double dave = (double)sum/(double)n;
    int ave = (int)Math.round(dave);
    int ans = 0;
    for (int i=0;i<n;i++){
      ans += Math.pow((a[i]-ave),2);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23892
#include<iostream>
using namespace std;
long long a,b,c;
int ans;
int main(){
	cin>>a>>b>>c;
	ans=0;
	if(a+b>=c) ans=b+c;
	else{
		ans=b+a+b+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
using namespace std;

int main()
{
    string S;
    int N,a;

    cin >> N;
    cin >> S;

    a=N;

for(int i=0;i<(N-1);i++){
    if(S.at(i) == S.at(i+1)){
        a--;
    }
}

cout << a <<endl;

}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define ios       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forn(i,a,n) for (ll i = a; i < (ll)(n); i++)
#define fon(i,n) for (ll i = (ll)n-1; i >=0; i--)
#define vi          vector<ll>
#define vii vector<pair<ll,ll>>
#define all(a)      (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ciin(v) forn(i,0,v.size()) cin>>v[i]
#define coutt(v) forn(i,0,v.size()) cout<<v[i]<<" "
using namespace std;
int main(){
    ios
    ll test;
    test=1;
    // cin>>test;
    while(test--){
      ll n,x;
      cin>>n;
      int dp[n][3];
      forn(i,0,n){
        cin>>dp[i][0];
        cin>>dp[i][1];
        cin>>dp[i][2];
      }
      forn(i,1,n){
        dp[i][0]+=max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]+=max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]+=max(dp[i-1][1],dp[i-1][0]);
      }
      cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));

        
       
     
      
       
  }}  


Measured memory_bytes: 4760
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

// doot diddly donger cuckerino Hahahahahah

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef unsigned int UINT;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef tuple<int, int, int> TPL;
typedef priority_queue<int> pqueue;
typedef priority_queue<int, VI, greater<>> pdqueue;

#define sim             template<class T
#define MP              make_pair
#define MT              make_tuple
#define PB              push_back
#define EB              emplace_back
#define F               first
#define S               second
#define ALL(a)          std::begin(a), std::end(a)
#define Sort(X)         sort(ALL(X))
#define UNIQUE(X)       Sort(X); (X).erase(unique(ALL(X)),(X).end())
#define SZ(x)           (int)(x).size()
#define IN_REP          int _t; cin >> _t ; while(_t--)
#define IOS             ios::sync_with_stdio(false);cin.tie(NULL)
#define FOR(i, a, b)    for(int i=(a);i<(b);i++)
#define REP(i, n)       FOR(i,0,n)
#define FORR(i, n)      for(int i=(n);i>=0;i--)
#define EPS             (LD) 1e-9
#define MOD             (LL)(1e9+ 7)
#define cerr2(x,y)      cerr << (x) << " " << (y) << endl;
#define cout2(x,y)      cout << (x) << " " << (y) << endl;
const LD PI = acos(-1);
sim>T gcd(T x, T y) {return (y==0)?x:gcd(y, x % y);}
sim>void mini(T &a, T b) { a = min(a, b); }
sim>void maxi(T &a, T b) { a = max(a, b); }
sim>inline void add(T &x, T y) {x += y;if (x >= MOD) x -= MOD;}
sim>inline void sub(T &x, T y) {x -= y;if (x < 0) x += MOD;}
sim>inline T mul(T a, T b) {LL x = (long long) a * b;x %= MOD;return x;}
sim>inline T power(T base, T exp) {T result = 1; while (exp) {if (exp & 1)result *= base;exp >>= 1;base *= base;}return result;}
sim>inline T power(T a, T b, T mod) {T res = 1;while (b > 0) {if (b & 1) { res = mul(res, a); }a = mul(a, a);b >>= 1;}return res%mod;}
sim>inline T modInverse(T n, T p) { return power(n, p - 2, p)%p; }
sim, class U>string to_string(pair<T, U> p) {return "" + to_string(p.F) + " " + to_string(p.S) + "";}


class AChangingACharacter {
public:
    static void solve(std::istream &cin, std::ostream &cout) {
        int n, k;
        cin >> n >> k;
        string s;
        cin >> s;
        k--;
        if (s[k] >= 'A' && s[k] <= 'Z') {
            s[k] = 'a' + (s[k] - 'A');
        }
        cout << s << endl;
    }
};


int main() {
    IOS;
	AChangingACharacter solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	AChangingACharacter::solve(in,out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;

struct brick{
    ll w, s, v;
    bool operator <(brick other){
        return s + w < other.s + other.w;
    }
} arr[MAXN];

ll dp[MAXN];

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

    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif

    cin>>n;

    for(int i = 1; i <= n; i++){
        int w, s, val;
        cin>>w>>s>>val;
        arr[i] = {w, s, val};
    }
    ll ans = 0;
    sort(arr + 1, arr + n + 1);
    for(int i = 1; i <= n; i++){
        for(int j = arr[i].s; j >= 0 ;j--){
            dp[j + arr[i].w] = max(dp[j + arr[i].w] , dp[j] + arr[i].v);
        }
    }
    for(int i = 0; i < MAXN; i++){
        ans = max(ans, dp[i]);
    }

    cout<<ans<<endl;

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

map<string, vector<string> > grps;

set<string> used;

set<string> dfs(string name){
  if(!grps.count(name)) return {name};
  if(used.count(name)) return {};
  used.insert(name);

  set<string> res;
  for(string mem:grps[name]){
    set<string> S = dfs(mem);
    for(auto s:S) res.insert(s);
  }
  return res;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(1){
    Int N;
    cin>>N;
    if(N == 0) break;
    grps.clear();
    used.clear();

    string grp1;
    for(Int i=0;i<N;i++){
      string s;
      cin>>s;
      string gname;
      Int idx = 0;
      while(s[idx] != ':') gname += s[idx++];
      idx++;
      vector<string> members;
      while(idx < (Int)s.size()){
        string member;
        while(islower(s[idx])) member += s[idx++];
        idx++;
        members.push_back(member);
      }
      if(i == 0) grp1 = gname;
      grps[gname] = members;
    }

    set<string> ans = dfs(grp1);
    cout<<ans.size()<<endl;

  }
  return 0;
}



Measured memory_bytes: 3328
n = int(input())
list = []
max = 0
second = 0
max_index = []

for i in range(n):
    num = int(input())
    if (num > max):
        max = num
    elif (num > second):
        second = num
    list.append(num)

counter = list.count(max)

for i,x in enumerate(list):
    if (x == max) & (counter == 1):
        print(second)
    else:
        print(max)


Measured memory_bytes: 12512
N = int(input())
c = [[0 for i in range(10)] for j in range(10)]
for i in range(1,N+1):
    stri = str(i)
    c[int(stri[0])][int(stri[-1])] += 1
ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += c[i][j]*c[j][i]
print(ans)

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

int main() {
    int N;
    cin >> N;
    char A;
    bool four=false;
    for (int i=0; i<N; i++){
        char A;
        cin >> A;
        if (A=='Y'){
            four=true;
            break;
        }
    }
    if (four) cout << "Four" << endl;
    else cout << "Three" << endl;

}

Measured memory_bytes: 256
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
mod=10**9+7
ans=0
c=1
for i in range(k-1,n):
    ans+=(l[i]-l[n-i-1])*c
    ans%=mod
    c*=i+1
    c*=mod_inv(i-(k-2),mod)
    c%=mod
print(ans)
  
  
  
  
  
exit()
h,w=map(int,input().split())
h-=1
w-=1
ans=1
mod=10**9+7
for i in range(h+1,h+w+1):
    ans*=i
    ans%=mod
for i in range(1,w+1):
    ans*=mod_inv(i,mod)
    ans%=mod
print(ans)


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

int main()
{
  ll N;
  scanf("%lld",&N);
  vector<vector<ll>> a(N, vector<ll>(3, 0));
  for(int i=0; i<N; i++){
    scanf("%lld",&a[i][0]);
    scanf("%lld",&a[i][1]);
    scanf("%lld",&a[i][2]);
  }

  vector<vector<ll>> dp(N+1, vector<ll>(3, 0));
  for (int i=0; i<N; i++) {
    for (int j=0; j<3; j++) {
      for (int k=0; k<3; k++) {
        if (j==k) continue;
        dp[i+1][k] = max(dp[i+1][k], dp[i][j]+a[i][k]);
      }
    }
  }

  ll ans = 0;
  for (int i=0; i<3; i++) {
    ans = max(ans, dp[N][i]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11136
a,b,h,m = map(int,input().split())

import math
import numpy as np 

rad_1 =( (h/6) * math.pi ) + ( (m/360) * math.pi )

rad_2 = m/30 * math.pi 

angle_1 = a * np.array([np.cos(rad_1),np.sin(rad_1)])

angle_2 = b * np.array([np.cos(rad_2),np.sin(rad_2)])

# print(angle_1,angle_2)

# print(np.linalg.norm(angle_1))
# print(np.linalg.norm(angle_2))

inner = np.inner(angle_1,angle_2)

cos_theta = inner/(a*b)


# print(np.arccos(cos_theta)*180/math.pi)

ans = (a**2) + (b**2) - 2 * a * b * cos_theta

print(np.sqrt(ans))
# print(np.linalg.norm(angle_2-angle_1))

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

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " : " << p.second << "}";
	return os;
}

template<typename T>
ostream& operator << (ostream& os, const set<T>& s) {
	for (const T& x : s) os << x << " ";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	int N;
	cin >> N;
	vi T(N);
	cin >> T;
	int M;
	cin >> M;
	vi P(M), X(M);
	for (int i = 0; i < M; i++)
		cin >> P[i] >> X[i];

	int all = 0;
	for (int i = 0; i < N; i++)
		all += T[i];

	for (int i = 0; i < M; i++) {
		cout << all - T[P[i] - 1] + X[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long int

using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    bool ok=false;
    map<lli, lli> q;
    map<lli, lli>::iterator it;
    lli i, n, m, ans=1;
    cin >> n;
    for(i=0;i<n;i++) cin >> m, q[m]++;
    for(it=q.end(),it--;;it--)
    {
        if(it->second>=4) cout<<max(it->first*it->first, it->first*ans)<<endl, exit(0);
        else if(it->second>=2)
        {
            if(ok) cout<<ans*it->first<<endl, exit(0);
            else ok=true, ans=it->first;
        }
        if(it==q.begin()) cout<<"0"<<endl, exit(0);
    }
    return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
using namespace std;


int main() {
	const long long int kuni = 10000000000;
	long long int n, m, p[300000], y[300000],so[300000],cou=0,k;
	map<long long int, long long int>mp;
	string str,sub[99999],min[7];
	min[0] = "zzzzzz";
	min[1] = "zzzzzz";
	min[2] = "zzzzzz";
	min[3] = "zzzzzz";
	min[4] = "zzzzzz";
	min[5] = "zzzzzz";
	cin >>str;
	cin >> k;
	n = str.length();
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < n - i; j++) {
			sub[i*n + j] = str.substr(j, i + 1);
		}
	}
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j < 5 * n ; j++) {
			
			if (min[i] > sub[j]) {
				for (int p = 0; p < i; p++) {
					if (min[p] == sub[j]) {
						goto next;
					}
				}
				min[i] = sub[j];
				next:
				cou++;
			}


		}
	}
	cout << min[k];
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

long long modpow(long long a, long long n, long long m) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % m;
        a = a * a % m;
        n >>= 1;
    }
    return res;
}

int main()
{
  ll N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N,0);
  REP(i, N){
    cin >> A[i];
    B[A[i]]++;
  }
  
  int flag=0;
  if(A[0]!=0){
    flag=1;
  }
  if(B[0]!=1){
    flag=1;
  }
  REP(i,N-1){
    if(B[i]==0&&B[i+1]!=0){
      flag=1;
    }
  }
  if(flag==0){
    mint ans=1;
    REP(i,N-1){
      ans*=modpow(B[i],B[i+1],mod);
    }
    cout << ans << endl;
  }else{
    cout << 0 << endl;
  }
  
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;
string a;
int main()
{
	cin>>a;
	cout<<a[0]<<a.size()-2<<a[a.size()-1];
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int power(int a, int b){ int S = 1; while(b--)S *= a; return S;}

int32_t main(){
	int n, m;
	cin >> n >> m;
	int s = 0;
	int a[m];
	for(int i = 0; i < m; i++){
		cin >> a[i];
		s += a[i];
	}
	if(s > n){
		cout << -1;
	}
	else{
		cout << n - s;
	}
	return 0;
}



Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
typedef pair<int,int>pii;
const int mxN=2e5,M=1e9+7;
int a,b;
// LONG LONG CASE
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>a>>b;
    cout<<(2*b>a ? 0 : a- 2*b);
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define w(t) ll t;cin>>t; while(t--)

int main()
{
  ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll i,n,a,b,k=0,z,p;
cin>>n;

  
  for(i=1000;i<12000;i+=1000)
  {
    if(i>=n)
    {
      
    
    k=i-n; break;
  }}
  cout<<k;
}

 
  

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

using namespace std;

#define N 200005
const int mod = 1e9 + 7;
#define add(x, y) (x + y >= mod ? x + y - mod : x + y)
#define dec(x, y) (x < y ? x - y + mod ? x - y)

int n, a[N], head[N], nxt[N << 1], to[N << 1], cnt = 0, sz[N], f[N], fac[N], inv[N], g[N];

int Pow(int x, int k)
{
	int base = x, ans = 1;
	while(k)
	{
		if(k & 1) ans = 1ll * ans * base % mod;
		base = 1ll * base * base % mod;
		k >>= 1;
	}
	return ans;
}

void adde(int x, int y)
{
	cnt++;
	to[cnt] = y;
	nxt[cnt] = head[x];
	head[x] = cnt;
}

void dfs(int x, int fa)
{
	sz[x] = 1;
	for(int p = head[x]; p; p = nxt[p])
	{
		int v = to[p];
		if(v == fa) continue;
		dfs(v, x);
		sz[x] += sz[v];
	}
	f[x] = fac[sz[x] - 1];
	for(int p = head[x]; p; p = nxt[p])
	{
		int v = to[p];
		if(v == fa) continue;
		f[x] = 1ll * f[x] * inv[sz[v]] % mod * f[v] % mod; 
	}
}

void dfs2(int x, int fa)
{
	for(int p = head[x]; p; p = nxt[p])
	{
		int v = to[p];
		if(v == fa) continue;
		int t = 1ll * g[x] * fac[n - 1 - sz[v]] % mod * inv[n - 1] % mod * fac[sz[v]] % mod * Pow(f[v], mod - 2) % mod;
		int ns = n - sz[v];
		// cout << x << ' ' << v << ' ' << t << ' ' << ns << endl;
		g[v] = 1ll * f[v] * t % mod * inv[ns] % mod * fac[n - 1] % mod * inv[sz[v] - 1] % mod;
		dfs2(v, x);
	}
}

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n - 1; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		adde(x, y), adde(y, x);
	}
	fac[0] = 1, inv[0] = 1, fac[1] = 1, inv[1] = 1;
	for(int i = 2; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod, inv[i] = Pow(fac[i], mod - 2);
	dfs(1, 1);
	// cout << f[1] << endl;
	g[1] = f[1];
	dfs2(1, 1);
	for(int i = 1; i <= n; i++)
		printf("%d\n", g[i]);
	return 0;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("kmp.in","r",stdin);freopen ("kmp.out","w",stdout);
#define mod 1000000009
#define fs(x,y) for(int i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(int i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum;

char s[N],c[N];

int main()
{
	fast;
	ll last=INF;
	cin>>n;
	ll q=0;
	fo(i,1,n)
	{
		ll x;
		cin>>x;
		if(x<=last)
			q++;
		else
			q=1;
		last=x;
		sum=max(sum,q);
	}
	cout<<sum-1;

}



/*     cd onedrive\desktop\kod
cls


*/

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

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

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    int a[4];

	cin >> a[0] >> a[1] >> a[2] >> a[3];

	sort(a, a + 4);

	//1974
	if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) Out("YES");
	else Out("NO");
	
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello{
    public static void Main(){
        var list = new List<long>();
        var s = Console.ReadLine();
        for(var i = 0;i < s.Length - 2;i++){
            list.Add(long.Parse(s.Substring(i,3)));
        }
        var ans = list.Min(x => Math.Abs(x - 753));
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13396
#include <iostream>

using namespace std;

const int MAX_N = 1000;

int main()
{
/*
A TCY	B TCY	C TCY	D TCY	E TCY	F TCY
å«³	60cmÈà	80cmÈà	100cmÈà	120cmÈà	140cmÈà	160cmÈà
d³	2kgÈà	5kgÈà	10kgÈà	15kgÈà	20kgÈà	25kgÈà
¿à	600~	800~	1000~	1200~	1400~	1600~
*/
	const int volume[] = { 0, 60, 80, 100, 120, 140, 160, MAX_N };
	const int wight[]  = { 0,  2,  5,  10,  15,  20,  25, MAX_N };
	const int fee[]    = { 0,600,800,1000,1200,1400,1600 };   
//	cut here before submit 
//	freopen ("testcase.deliveryfee", "r", stdin );
	int n;
	
	while (1){
		cin >> n;
		if (n == 0){
			break;
		} // end if
		
		int i,j,k;
		int res = 0;
		for (i = 0; i < n; ++i){
			int x, y, h, w;
			cin >> x >> y >> h >> w;
			int v = x + y + h;
			int vrange = -1, wrange = -1, range = -1;

			for (j = 1; j < 8; ++j){
				if (volume[j-1] < v && v <= volume[j] ){
					vrange = j;
					break;
				} // end if
			} // end for

			for (k = 1; k < 8; ++k){
				if (wight[k-1] < w && w <= wight[k] ){
					wrange = k;
					break;
				} // end if
			} // end for
			range = max (vrange, wrange );
			
			if (range < 7 ){
				res += fee[range];
			} // end if
		} // end for
		cout << res << endl;
	} // end loop
		
	return 0;
}

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

using namespace std;

int main()
{
  long long int a,b;
  cin>>a>>b;
  if(a>0)
  {
      cout<<"Positive"<<endl;
  }
  if(b==0 || (a<=0 && b>=0))
  {
    cout<<"Zero"<<endl;
  }
  if(a<0 && b<0)
  {
     if((a-b+1)%2==0)
     {
         cout<<"Positive"<<endl;
     }else
     {
         cout<<"Negative"<<endl;
     }
  }
}


Measured memory_bytes: 256
//
//  525.cpp
//  
//
//  Created by Yoshida Satoshi on 2017/11/18.
//
//

#include <stdio.h>
#include<iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int main(){
    int R,C;
    int a[10][10000];
    int b[10][10000];//????????????????????£?????????????????????

    int ans;
    
    while(1){
        cin>>R>>C;
        if(R==0&&C==0) break;
        
        for(int i=0;i<R;i++){
            for(int j=0;j<C;j++){
                cin>>a[i][j];
            }
        }
        ans=0;
        for(int k=0;k<pow(2,R);k++){
            int sum=0;
            for(int i=0;i<R;i++){
                int kaesu=k/(int)pow(2,i);
                for(int j=0;j<C;j++){
                    b[i][j]=a[i][j]+kaesu;
                }
            }
            for(int j=0;j<C;j++){
                int n=0;//b???j??????????????????????£???´??????????????????
                for(int i=0;i<R;i++){
                    if(b[i][j]%2==0) n++;
                }
                sum+=max(n,R-n);
            }
            if(sum>ans) ans=sum;
        }
        cout<<ans<<endl;
    }
    
    
    return 0;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n;
int a[maxn];

map<int,int> mp[2];
vector<pair<int,int>> v[2];

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

  cin>>n;
  for (int i=0; i<n; i++) {
    cin>>a[i];
    mp[i%2][a[i]]++;
  }
  const int inf = 1e6;
  mp[0][inf]=0;
  mp[1][inf]=0;


  for (int i=0; i<=1; i++) {
    for (auto p: mp[i]) {
      v[i].push_back({p.second,p.first});
    }
    sort(v[i].begin(), v[i].end());
    reverse(v[i].begin(), v[i].end());
    while (int(v[i].size()) > 2) v[i].pop_back();
  }

  int ans = inf;

  for (auto p: v[0]) {
    for (auto q: v[1]) {
      if (p.second == q.second) continue;
      int x = n/2 - p.first;
      int y = n/2 - q.first;
      ans = min(ans, x+y);
    }
  }

  cout<<ans<<endl;
  
  

  return 0;
}


Measured memory_bytes: 6524
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int *arr = new int[n];
	for(int i = 0; i < n ; i++)
	{
		cin >> arr[i];
	}
	int flag = 0;
	for(int i = 0; i < n ; i++)
	{
		if(arr[i]%2 == 0)
		{
			if(arr[i]%3 != 0 && arr[i]%5 != 0)
			{
				flag = 1;
				break;
			}
		}
	}
	if(flag)
		cout << "DENIED\n";
	else cout << "APPROVED\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	long a, b;
	scanf("%ld%ld", &a,&b);
	if (a > 0 && b > 0)
	{
		printf("Positive\n");
		return 0;
	}
	if (a <= 0 && b >= 0)
	{
		printf("Zero\n");
		return 0;
	}
	if (a < 0 && b < 0)
	{
		if (labs(a - b) % 2)
			printf("Positive\n");
		else
			printf("Negative\n");
		return 0;
	}
	return (0);
}


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

int findIndex(char c, int i) {
    if (c == 'S')
        return i - 1;
    if (c == 'H')
        return 13 + i - 1;
    if (c == 'C')
        return 2 * 13 + i - 1;
    if (c == 'D')
        return 3 * 13 + i - 1;

    return -1;
}

void print(int i) {
    if (i < 13) {
        cout << "S " << i + 1 << endl;
        return ;
    }
    if (i < 2 * 13) {
        cout << "H " << i % 13 + 1 << endl;
        return ;
    }
    if (i < 3 * 13) {
        cout << "C " << i % 13 + 1 << endl;
        return ;
    }
    if (i < 4 * 13) {
        cout << "D " << i % 13 + 1 << endl;
        return ;
    }
}

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

    char *sym = new char[n];
    int *ary = new int[n];
    for (int i = 0; i < n; ++i) {
        cin >> sym[i];
        cin >> ary[i];
    }

    int flag[52] = {0};
    for (int j = 0; j < n; ++j) {
        flag[findIndex(sym[j], ary[j])] = 1;
    }

    for (int k = 0; k < 52; ++k) {
        if (flag[k] == 0)
            print(k);
    }

    delete[] sym;
    delete[] ary;
    return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T>using numr=std::numeric_limits<T>;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,m;std::cin>>n>>m;
    while(m--){
        lint x;std::cin>>x;
        n-=x;
    }
    std::cout<<(n<0?-1:n)<<'\n';
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
ll S(ll x) { return x*x*x; }
int main() {
    int n, k;
    cin >> n >> k;
    if(k & 1) {
        ll t = n/k;
        cout << t*t*t << endl;
    }
    else {
        ll t1 = n/(k/2);
        ll t2 = n/k;
        t1 -= t2;
        cout << S(t1) + S(t2) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
using namespace std;
int main(){
	char a,b,c,d;
	int A,B,C,D;
	scanf("%c%c%c%c",&a,&b,&c,&d);
	A=a-48;
	B=b-48;
	C=c-48;
	D=d-48;
	if(A+B+C+D==7) printf("%c+%c+%c+%c=7\n",a,b,c,d);
	else if(A-B+C+D==7) printf("%c-%c+%c+%c=7\n",a,b,c,d);
	else if(A+B-C+D==7) printf("%c+%c-%c+%c=7\n",a,b,c,d);
	else if(A+B+C-D==7) printf("%c+%c+%c-%c=7\n",a,b,c,d);
	else if(A-B-C+D==7) printf("%c-%c-%c+%c=7\n",a,b,c,d);
	else if(A-B+C-D==7) printf("%c-%c+%c-%c=7\n",a,b,c,d);
	else if(A+B-C-D==7) printf("%c+%c-%c-%c=7\n",a,b,c,d);
	else if(A-B-C-D==7) printf("%c-%c-%c-%c=7\n",a,b,c,d);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++) 
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
//#define x first
//#define y second

using namespace std;
int k;
string s;
set<string>ans;
set<string>::iterator it;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>s>>k;
	rep2(i,1,min((int)(s.size()+1),6))
	rep(j,s.size()-i+1)
	ans.insert(s.substr(j,i));
	for(it=ans.begin();k>1;it++,k--);
	cout<<*it<<endl;
	return 0;}

Measured memory_bytes: 1664
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() int {
    sc.Scan()
    data, _ := strconv.Atoi(sc.Text())
    return data
}

func main() {
    a,_,_,_,e,k := nextLine(), nextLine(), nextLine(), nextLine(), nextLine(), nextLine()
//    a,_,_,_,e,k := 1,2,4,8,9,15

    var maxLength = e - a
    
    if maxLength <= k {
	fmt.Println("Yay!")
    } else {
	fmt.Println(":(")
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,k,ans=0,cnt=0,x=0;
  cin >> n >> k;
  long long a[n],b[n]={};
  for(int i=0;i<n;i++){
    cin >> a[i];
    b[a[i]-1]++;
    cnt++;
  }
  if(cnt>k){
    cnt-=k;
    sort(b,b+n);
    while(1){
      ans+=b[x];
      cnt--;
      x++;
      if(cnt==0){
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

ll mod = 1e9+7;

// aのp乗を求めるアルゴリズム
ll modpow(ll a, int p){
    if(p == 0){
        return 1;
    }
    if(p % 2 == 0){
        //pが偶数の時
        int halfP = p/2;
        ll half = modpow(a, halfP);
        return half * half % mod;
    }
    else{
        //pが奇数の時
        return a * modpow(a, p-1) % mod;
    }
}

ll calcComb(int a, int b){
    if(b > a-b){
        return calcComb(a, a-b);
    }

    ll ansMul = 1;
    ll ansDiv = 1;

    for(int i=0; i<b; i++){
        ansMul *= (a-i);
        ansDiv *= (i+1);
        ansMul %= mod;
        ansDiv %= mod;
    }

    //フェルマーの小定理を用いて逆元を求め，用いる．
    ll ans = ansMul * modpow(ansDiv, mod-2) % mod;

    return ans;
}

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

    int Mrest = M;
    ll ans = 1;

    for(int i=2; i*i<=Mrest; i++){
        if(Mrest % i == 0){
            int cnt = 0;
            while(Mrest % i == 0){
                cnt++;
                Mrest /= i;
            }
 
            ans *= calcComb(N+cnt-1, N-1);
            ans %= mod;
       
        }
    }


    
    if(Mrest != 1){
        //最後に素数が残っている分を計算
        ans *= calcComb(N+1-1, N-1);
        ans %= mod;
    }

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

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

typedef pair<int,int> pi;
typedef vector<int> vi;
 
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define pb push_back

template<typename T> void max_self(T &a, T b) { a = max(a,b); return;}
template<typename T> void min_self(T &a, T b) { a = min(a,b); return;}
 
const int nax = 1e6 + 5;
const int mod = 1e9 + 7;

int modExpo(int a,int b,int c){
	if(b == 0) return 1;
	int answer = 1;
	while(b){
		if(b & 1) answer = ((answer % c) * (a % c)) % c;
		a = ((a % c) * (a % c)) % c;
		b /= 2; 
	}
	
	return answer;
}

signed main(){
	
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int t = 1;
	//cin >> t;
	while(t--){
		int n;
		cin >> n;
		
		int ans = 0;
		for(int i = 1; i<= n; ++i) ans += i * (n - i + 1);
		
		for(int i = 0; i < n - 1; ++i){
			int a,b;
			cin >> a >> b;
			
			int maxi = max(a,b);
			int mini = min(a,b);
			ans -= mini * (n - maxi + 1);
		}
		
		cout << ans;
	}	
	return 0;
}


Measured memory_bytes: 3640
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

// #define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

signed main(void)
{
  string s; cin >> s;
  vector<bool> v(s.length(), false);

  for (int i = 0; i < s.length(); ++i) {
        if ((i % 2 == 0 && s[i] == 'R')
            || (i % 2 == 1 && s[i] == 'L')
            || s[i] == 'U'
            || s[i] == 'D')
          v[i] = true;
  }

  bool flag = accumulate(v.begin(), v.end(),true, [](bool acc, bool i) { return acc & i;});
  if (flag) cout << "Yes";
  else cout << "No";
  cout << endl;
}


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

long f(long a, long b){
    return max(to_string(a).size(), to_string(b).size());
}

int main(){
    long N;
    cin >> N;
    long min = 100000000;
    for(long i = 1; i <= sqrt(N); i++){
        if(N % i == 0 && f(i, N/i) < min){
            min = f(i, N/i);
        }
    }
    cout << min << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int):
    
    for i in range(1, 50000):
        if i*1.08//1 == N:
            print(i)
            exit()
        
    print(':(')



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
(defun calc (r d xi)
  (- (* r xi) d))

(defun rec (r d xi c)
  (if (> c 9)
    '()
    (append (list (calc r d xi)) (rec r d (calc r d xi) (1+ c)))))

(format t "~{~a~^~%~}~%" (rec (read) (read) (read) 0))

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


int maxtime(int x){
    return (x+9)/10*10;
}

int remtime(int x){
    return maxtime(x) - x;
}


int main(){
    int a[5];
    rep(i,5) cin>>a[i];

    int ans = 0;
    int rem = 0;
    rep(i,5){
        ans += maxtime(a[i]);
        rem = max(rem, remtime(a[i]));
    }

    cout << ans -rem << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <cstdio>
#include <cmath>
#include <climits>
using namespace std;




//---- Min, Max and Sum
//????°????????????§??????????¨????????????????????????§????????????????????????????????????
int main(){
    long long n, a, min = INT_MAX, max = INT_MIN, sum=0;
    scanf("%lld", &n);
    for(int i=0; i<n; i++){
        scanf("%lld", &a);
        if(a<=min){
            min=a;
        }
        if(a>=max){
            max=a;
        }
        sum += a;
    }
    printf("%lld %lld %lld\n", min, max, sum);
}

Measured memory_bytes: 3200