akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;
const int H_MAX = 500000;

int H, A[H_MAX + 1];

void maxHeapify(int i)
{
    int l = 2 * i;
    int r = 2 * i + 1;
    int largest = i;
    // left, self, right get max node
    if (l <= H && A[l] > A[largest]) {
        largest = l;
    }
    if (r <= H && A[r] > A[largest]) {
        largest = r;
    }
    if (largest != i) {
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

void buildMaxHeap()
{
    for (int i = H / 2; i >= 1; --i) {
        maxHeapify(i);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> H;
    for (int i = 1; i <= H; ++i) {
        cin >> A[i];
    }

    buildMaxHeap();

    for (int i = 1; i <= H; ++i) {
        printf(" %d", A[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 5068
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll a;
  long double b;
  cin >> a >> b;
  b*=100;
  b+=0.00001;
  int c=b;
  ll ans=a*c;
  cout << ans/100;
}


Measured memory_bytes: 3680
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        S: chars,
    }
    let mut ans = VecDeque::new();
    for s in S{
        if s=='0' || s=='1'{
            ans.push_back(s);
        }else if s=='B' && ans.len()!=0{
            ans.pop_back();
        }
    }
    for x in ans{
        print!("{}",x);
    }
}

Measured memory_bytes: 4352
#include <iostream>

int main() {
	int N, L;
	int sum = 0;
	int max = 0;
	std::cin >> N;
	for (int i = 0; i < N; ++i) {
		std::cin >> L;
		sum += L;
		max = L > max ? L : max;
	}
	if (max < sum - max) std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
	return 0;
}

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

using namespace std;

#define INF 1e9

inline void moveState(vector<int> &v,int p){
  const int dx[4] = {-1,0,1,0};
  const int dy[4] = {0,-1,0,1};
  bool tmp[16][4],use[16][4] = {{0}};
  fill(use[p],use[p]+4,1);
  bool update = 1;
  while(update){
    vector<int> next = v;
    update = 0;
    memset(tmp,0,sizeof(tmp));
    for(int i = 0 ; i < 16 ; i++){
      for(int j = 0 ; j < 4 ; j++){
        if(!use[i][j]){ continue; }
        int nx = i%4 + dx[j], ny = i/4 + dy[j];
        int np = nx + 4*ny;
        if(nx < 0 || nx >= 4 || ny < 0 || ny >= 4){
          continue;
        }
        update = 1;
        if(v[np] > 0){ next[np]++; }
        else{ tmp[np][j] = 1; }
      }
    }
    for(int i = 0 ; i < 16 ; i++){
      if(next[i] >= 5){
        next[i] = 0;
        fill(tmp[i],tmp[i]+4,1);
      }
    }
    v = next;
    memcpy(use,tmp,64);
  }
}

int solve(vector<int> &v,int step){
  if(count(v.begin(),v.end(),0) == 16){
    return step;
  }
  if(step == 5){ return INF; }
  int res = INF;
  for(int i = 0 ; i < 16 ; i++){
    vector<int> next = v; next[i]++;
    if(next[i] == 5){
      next[i] = 0;
      moveState(next,i);
    }
    res = min(res,solve(next,step+1));
  }
  return res;
}

int main(){
  vector<int> v(16);
  for(int i = 0 ; i < 16 ; i++){
    cin >> v[i];
  }
  int res = solve(v,0);
  cout << (res < INF ? res : -1) << endl;
  return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 4e3 + 5;
char ss[N], c[3]={'R','G','B'};
int sum1[N][3];
int main()
{
    int n;
    scanf("%d", &n);
    scanf("%s", ss + 1);
    for (int i = 1; i <= n;i++)
    {
        for (int j = 0; j < 3;j++)
            sum1[i][j] = sum1[i - 1][j] + (ss[i] == c[j]);
    }
    ll ans = 0;
    for (int i = 2; i < n;i++)
    {
        for (int j = 1; j < i;j++)
        {
            if(ss[i]==ss[j])
                continue;
            int t = i - j;
            if(ss[j]==c[0])
            {
                if(ss[i]==c[1])
                {
                    int tm = i + t;
                    if(tm<=n)
                        ans += (sum1[tm-1][2] - sum1[i][2]);
                    else
                        ans += (sum1[n][2] - sum1[i][2]);
                    if(tm<n)
                        ans += (sum1[n][2] - sum1[tm][2]);
                }
                else if(ss[i]==c[2])
                {
                    int tm = i + t;
                    if(tm<=n)
                        ans += (sum1[tm-1][1] - sum1[i][1]);
                    else
                        ans += (sum1[n][1] - sum1[i][1]);
                    if(tm<n)
                        ans += (sum1[n][1] - sum1[tm][1]);
                }
            }
            else if(ss[j]==c[1])
            {
                if(ss[i]==c[2])
                {
                    int tm = i + t;
                    if(tm<=n)
                        ans += (sum1[tm-1][0] - sum1[i][0]);
                    else
                        ans += (sum1[n][0] - sum1[i][0]);
                    if(tm<n)
                        ans += (sum1[n][0] - sum1[tm][0]);
                }
                else if(ss[i]==c[0])
                {
                    int tm = i + t;
                    if(tm<=n)
                        ans += (sum1[tm-1][2] - sum1[i][2]);
                    else
                        ans += (sum1[n][2] - sum1[i][2]);
                    if(tm<n)
                        ans += (sum1[n][2] - sum1[tm][2]);
                }
            }
            else 
            {
                if(ss[i]==c[1])
                {
                    int tm = i + t;
                    if(tm<=n)
                        ans += (sum1[tm-1][0] - sum1[i][0]);
                    else
                        ans += (sum1[n][0] - sum1[i][0]);
                    if(tm<n)
                        ans += (sum1[n][0] - sum1[tm][0]);
                }
                else if(ss[i]==c[0])
                {
                    int tm = i + t;
                    if(tm<=n)
                        ans += (sum1[tm-1][1] - sum1[i][1]);
                    else
                        ans += (sum1[n][1] - sum1[i][1]);
                    if(tm<n)
                        ans += (sum1[n][1] - sum1[tm][1]);
                }
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
// make pair, tuple
// make pair, tuple
// 
// __gcd(int, int);
// lcm = a * b / __gcd(a, b);
// 
// bool isPrime(int n){
//       if(n <= 1)return false;
//       if(n <= 3)return true;
//       if(n % 2 == 0 || n % 3 == 0)return false;
//       for(int i = 5;i * i <= n;i += 6){
//             if(n % i == 0 || n % (i + 2) == 0)return false;
//       }
//       return true;
// }
// int countSubString(string s, string temp){
//       int ans = 0;
//       size_t f = s.find(temp);
//       while(f != string::npos){
//             ans++;
//             f = s.find(temp, f + 1);
//       }
//       return ans;
// }
// 
// #Count leading & trailing zero of an integer bits
// __builtin_clz(n);
// __builtin_clzll(n);
//
// #Count 1s bits of an integer
// __builtin_popcount(n);
// __builtin_popcountll(n);
//
// #Error checking
// assert(n == 3);
// 
// #Error Printing
// cerr << "Some thing";

int main(){
    long long int MOD = 1e9 + 7;
    int n,m;cin >> n >> m;
    vector<long long int> dp(n + 5, 0);
    vector<bool> v(n + 5, true);
    dp[0] = 1;
    for(int i = 0;i < m;i++){
        int t;cin >> t;
        v[t] = false;
    }
    for(int i = 1;i <= n;i++){
        if(!v[i])continue;
        if(i - 1 >= 0)dp[i] += dp[i - 1];
        if(i - 2 >= 0)dp[i] += dp[i - 2];
        dp[i] %= MOD;
    }
    cout << dp[n];
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>


#define rep(i,n) for(int i = 0; i < n; ++i)
#define all(x) x.begin(),x.end()
using namespace std;

int gcd(int a, int b){
  if(a == 0 || b == 0) return 0;
  while(a != b){
    if(a>b) a=a-b;
    else b = b-a;
  }
  return a;
}
//(8 4)

int main(void){
  int x[2], y[2];
  cin >> x[0] >> y[0] >> x[1] >> y[1];
  int  X,Y;
  X = abs(x[0]-x[1]);
  Y = abs(y[0]-y[1]);
  if( X < Y) swap(X,Y);

  if(gcd(X,Y) == 1){
    cout << X + Y - 1 << endl;
  }else{
    int g=gcd(X,Y);
    X/=g;
    Y/=g;
    cout << (X + Y -1) * g << endl;
  }
  

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int N;
	cin >> N;
	vl A(N), B(N);
	rep(i, N)
		cin >> A[i] >> B[i];
	sort(A.begin(), A.end(), less<ll>());
	sort(B.begin(), B.end(), less<ll>());
	ll ans;
	if (N % 2 == 1) {
		ans = B[(N - 1) / 2] - A[(N - 1) / 2] + 1;
	}
	else {
		ans = (B[N / 2 - 1] + B[N / 2]) - (A[N / 2 - 1] + A[N / 2]) + 1;
	}

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

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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    cout << "ABC" << N << endl;
    return 0;
}

Measured memory_bytes: 3620
n = int(input())
a = [0]+list(map(int, input().split()))+[0]
INF = 1000000000000000000
F = [-INF]*(n+2)
G = [-INF]*(n+2)
F[1] = 0
for i in range(1, n):
	F[i+1] = max(F[i+1], F[i]+a[i], G[i]-a[i])
	G[i+1] = max(G[i+1], F[i]-a[i], G[i]+a[i])
print(max(F[n]+a[n], G[n]-a[n]))


Measured memory_bytes: 17312
def getter(targ,x,y):
    #print(x,y,len(targ[0]),len(targ))
    if 0 > x or x >= len(targ) or 0 > y or y >= len(targ[0]) or targ[x][y] == '#':
        return 0
    else:
        targ[x][y] = '#'
        return 1 + getter(targ,x+1,y) + getter(targ,x-1,y) + getter(targ,x,y+1) + getter(targ,x,y-1)
width,height = [int(n) for n in input().split(" ")]
global lab
while True:
    lab,start = [],[]
    for a in range(height):
        disp = [n for n in input().rstrip('\n')]
        if '@' in disp:
            start.extend([disp.index('@'),a])
        lab.append(disp)
    else:
        a,b = start
        print(getter(lab,b,a))
        width,height = [int(n) for n in input().split(" ")]
        if width == 0 and height == 0:
            break

Measured memory_bytes: 7660
n, a, b = map(int, input().split())
s = input()
total_n = a + b
total_rank = 1
b_rank = 1
for i in range(n):
    if s[i] == "a":
        if total_rank <= total_n:
            print("Yes")
            total_rank += 1
        else:
            print("No")
    elif s[i] == "b":
        if total_rank <= total_n and b_rank <= b:
            print("Yes")
            total_rank += 1
            b_rank += 1
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 4016
#include <bits/stdc++.h>
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>
#include <boost/math/constants/constants.hpp>
using namespace std;
namespace rng {
    using namespace boost::range;
    using namespace boost::adaptors;
}

struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

using boost::irange;
using boost::math::double_constants::pi;
using i64 = int64_t;
constexpr char nl = '\n';
auto yesno(bool b) { return b ? "Yes" : "No"; }

template<class T> istream& operator>>(istream& in, vector<T>& vs) { for (T& v :vs) in >> v; return in; }
template<class T> ostream& operator<<(ostream& out, const vector<T>& vs) { for (size_t i = 0; i < vs.size(); ++i) { if(i) { out << ' '; } out << vs[i]; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const T& v) { cout << v; }
template<class T> void trace_(const vector<vector<T>>& m) { cout << nl; for (const auto& v : m) { trace_(v); cout << nl; } }
template<class T> void trace_(const char* s, const T& v) { cout << s << "="; trace_(v); cout << nl; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cout << *s; } cout << "="; trace_(v); cout << ","; trace_(++s, vs...); }
#define TRACE(...) trace_(#__VA_ARGS__, __VA_ARGS__)
#else
#define TRACE(...)
#endif

int main() {
    i64 N, K;
    cin >> N >> K;
    vector<i64> A(N), F(N);
    cin >> A >> F;
    rng::sort(A);
    rng::sort(F, greater<i64>());
    auto r = irange(0l, i64(1e12));
    auto m = partition_point(begin(r), end(r), [&](i64 x) {
        TRACE(x);
        auto k = K;
        for (auto i : irange(0l, N)) {
            if (A[i] * F[i] > x) {
                k -= A[i] - x / F[i];
                TRACE(x, i, A[i], F[i], k);
                if (k < 0) {
                    return true;
                }
            }
        }
        return false;
    });
    cout << *m << nl;
}


Measured memory_bytes: 3328
// Kを始点とした深さ優先探索
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#include <cmath>
#include <utility>
#include <numeric>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i=0;(i)<(n);(i)++)
#define repi(i, n) for (int i=0;(i)<=(n);(i)++)
#define repr(i, n) for (int i=n;(i)>=0;(i)--)
#define print(x) (cout<<(x)<<"\n")

const int limit = 100010;
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d) {
    depth[v] = d;
    for (auto &e: tree[v]) {
        if (e.to==p) continue;
        dfs(e.to, v, d+e.cost);
    }
}

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int n; cin>>n;
    rep(i, n-1) {
        int a, b, c; cin>>a>>b>>c;
        a--; b--;
        tree[a].push_back({b, c});
        tree[b].push_back({a, c});
    }

    int q, k; cin>>q>>k;
    k--;
    dfs(k, -1, 0);
    rep(i, q) {
        int x, y; cin>>x>>y;
        x--; y--;
        print(depth[x]+depth[y]);
    }
}

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


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

	set<string> s;
	int N;
	cin >> N;
	for (int i = 0 ; i < N ; i++)
	{
		string a;
		cin >> a;
		s.insert(a);
	}
	cout<<s.size()<<endl;
}

Measured memory_bytes: 19252
import sys
sys.setrecursionlimit(10**7)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = list(range(n))
        self.size = [1]*n
        
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        
    def unit(self,x,y):
        x, y = self.find(x), self.find(y)
        if x==y: return
        if self.size[x] < self.size[y]:
            x,y = y,x
        self.size[x] += self.size[y]
        self.par[y] = x
        
    
n,m = map(int,input().split())
uf = UnionFind(n)
for _ in range(m):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    uf.unit(a,b)
    
ans = max(uf.size[i] for i in range(n))
print(ans)

Measured memory_bytes: 18404
N = int(input())
A = [int(a) for a in input().split()]
negcnt = 0
mi = 1<<100
s = 0
for a in A:
    s += abs(a)
    mi = min(mi, abs(a))
    if a <= 0:
        negcnt += 1
if negcnt % 2:
    print(s-2*mi)
else:
    print(s)

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{
    gearup;
    ll a,b,c; cin >> a >> b >> c;
    rep(i,1000){
        if(a & 1 || b & 1 || c & 1){
            out(i);
            return 0;
        }
        ll aa = a;
        ll bb = b;
        a = (b+c)/2;
        b = (aa + c)/2;
        c = (aa + bb)/2;
    }
    out(-1);
}

Measured memory_bytes: 3556
h, w = list(map(int, input().split()))  
power = [list(map(int, input().split())) for i in range(10)]  

for i in range(10):
    for j in range(10):
        for k in range(10):
            power[j][k] = min(power[j][i] + power[i][k], power[j][k])  

ans = 0
for i in range(h):
    wall = list(map(int, input().split()))  
    for item in wall:
        if item < 0:
            continue
        ans += power[item][1]  
print(ans)


Measured memory_bytes: 9124
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

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

Measured memory_bytes: 256
fun main(args: Array<String>) {
    data class Submit(val n: Int, val result: String)
    val (n, m) = readLine()?.split(" ")?.map(String::toInt) ?: return
    0.until(m)
        .map {
            readLine()?.split(" ")?.let {
                Submit(it[0].toInt(), it[1])
            } ?: return
        }
        .groupBy { it.n }
        .map {
            val submitList = it.value
            Pair(
                // AC
                if (submitList.any { it.result == "AC" }) {
                    1
                } else {
                    0
                },
                // WA
                submitList.indexOfFirst { it.result == "AC" }.let {
                    if (it == -1) {
                        0
                    } else {
                        it
                    }
                }
            )
        }
        .let {
            println("${it.sumBy { it.first }} ${it.sumBy { it.second }}")
        }
}



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

using namespace std;
int main() {
    int n,i,max=3,sum=0,temp;
    cin>>n;
    vector<int> l(n);

    for(i=0;i<n;i++){
        cin>>l[i];
        sum += l[i];
        if(l[i]>max)max=l[i];
    }
    sum-=max;
    if(sum>max){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }



    return 0;
}

Measured memory_bytes: 256
def slove():
    import sys
    import fractions
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    g_l = [[0, 0] for _ in range(n + 1)]

    for i in range(n):
        g_l[i+1][0] = fractions.gcd(g_l[i][0], a[i])
        g_l[-i-2][1] = fractions.gcd(g_l[-i-1][1], a[-i-1])
    m_g = 0
    for i in range(n):
        m_g = max(m_g, fractions.gcd(g_l[i][0], g_l[i + 1][1]))
    print(m_g)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 93844
N=int(input())
AB=[]
for i in range(N):
    AB.append(list(map(int,input().split())))
CD=[]
for i in range(N):
    CD.append(list(map(int,input().split())))
AB=sorted(AB,key=lambda x:(x[0],x[1]))
CD=sorted(CD,key=lambda x:(x[1],x[0]))
ct=0
for ab in AB[::-1]:
    for i in range(len(CD)):
        cd=CD[i]
        if ab[0]<cd[0] and ab[1]<cd[1]:
            ct+=1
            CD.pop(i)
            break
print(ct)

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

using namespace std;

typedef long long ll;
const ll mod=998244353;
const ll N=1e6;
ll a[N];
ll b[N];
ll pow_mod(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res%mod;
}
int main()
{
	int n;
	cin>>n;
	int k;
	ll ans=0;
	cin>>k;
	if(k!=0){
		cout<<ans<<endl;
		return 0;
	}
	a[k]++;
	b[0]=k;
	for(int i=1;i<n;i++){
		cin>>k;
		b[i]=k;
		a[k]++;
	}
	if(a[0]>1){
		cout<<ans<<endl;
		return 0;
	}
	sort(b,b+n);
	for(int i=0;i<=b[n-1];i++){
		if(a[i]==0){
			cout<<ans<<endl;
			return 0;
		}
	}
	ans=1;
//	cout<<"************\n";
	for(int i=1;i<=b[n-1];i++){
		ans=(ans%mod*pow_mod(a[i-1],a[i]))%mod;
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;
const int N=3e5+5;
int a[N],b[N];
int n,k;
int ans=1;
void solve(int v)
{
    for(int i=0;i<n;i++)
        b[i]=a[i]%v;
    sort(b,b+n);
    int i=0,j=n-1;
    int cur=0,t=0;
    while(i<=j)
    {
        if(cur<=0)
        {
            cur+=b[i];
            t+=b[i];
            i++;
        }
        else
        {
            cur-=(v-b[j]);
            j--;
        }
    }
    if(cur!=0)
        assert(0);
    if(t<=k)
        ans=max(ans,v);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>k;
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    for(long long i=1;i*i<=sum;i++)
    {
        if(sum%i==0)
        {
            solve(i);
            solve(sum/i);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

bool isPrime(int x){
    if(2 == x){
        return true;
    }

    int i = 2;
    while(i < std::sqrt(x)){
        if(0 == x % i++){
            return false;
        }
    }

    return true;
}

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

    bool flg = false;
    while(!flg){
        if(isPrime(x)){
            flg = true;
        }else{
            ++x;
        }
    }

    std::cout << x << std::endl;

    return 0;
}

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

int h[110];

int main(){
    int n;
    cin >> n;
    int ans = 0;
    rep(i, n) {
        cin >> h[i];
    }
    for (int i = 0; i < n; i++) {
        bool whi = true;
        for (int j = 0; j < i; j++){
            if (h[j] > h[i]) {
                whi = false;
                break;
            }
        }
        if (whi) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    s = input()
    ans = "AC"
    # 条件1
    if s[0] != "A":
        ans = "WA"
    # 条件2,3
    cnt = 0
    for i in range(1, len(s)):
        if s[i].isupper():
            if i == 1 or i == len(s)-1 or s[i] != "C":
                ans = "WA"
            cnt += 1
    if cnt != 1:
        ans = "WA"

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
/**
 *    author:  FromDihPout
 *    created: 2020-08-20
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> a(n+1);
    for (int i = 0; i < n+1; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    
    int ans = a[1] - a[0];
    for (int i = 2; i < n+1; i++) {
        ans = __gcd(ans, a[i] - a[i-1]);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3696
#include<stdio.h>
int main()
{  int x;
   scanf("%d",&x);
   if(x<600) printf("8");
   else if(x<800) printf("7");
   else if(x<1000) printf("6");
   else if(x<1200) printf("5");
   else if(x<1400) printf("4");
   else if(x<1600) printf("3");
   else if(x<1800) printf("2");
   else printf("1");
} 

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

const long long inf = 30000000000000001;
int N, len[60];
long long c[60];
long long dp[2][60][30];
char s[2][60][50];
long long dfs(const int &N, const int &l, const char &f);
char pal(char *l, char *r);

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		scanf("%s%lld", s[0][i], &c[i]);
		len[i] = strlen(s[0][i]);
		for (int j = 0; j < len[i]; ++j)
			s[1][i][j] = s[0][i][len[i] - 1 - j];
	}
	long long ans = inf;
	memset(dp, -1, sizeof(dp));
	for (int i = 0; i < N; ++i)
		ans = min(ans, c[i] + dfs (i, 0, 0));
	printf("%lld\n", ans == inf ? -1 : ans);
	return 0;
}

char pal(char *l, char *r) {
	for (; l < r; ++l, --r)
		if (*l != *r)
			return 0;
	return 1;
}

long long dfs(const int &n, const int &l, const char &f) {
	long long &ret = dp[f][n][l];
	if (ret != -1)
		return ret;
	const int r = len[n] - 1;
	if (pal(&s[f][n][l], &s[f][n][r]))
		return ret = 0;
	ret = inf;
	for (int i = 0; i < N; ++i) {
		if (r - l + 1 <= len[i]) {
			for (int j = 0; j <= r - l; ++j)
				if (s[f][n][j + l] != s[!f][i][j])
					goto LABLE;
			ret = min(ret, c[i] + dfs(i, r - l + 1, !f));
		}
		else {
			for (int j = 0; j < len[i]; ++j)
				if (s[f][n][j + l] != s[!f][i][j])
					goto LABLE;
			ret = min(ret, c[i] + dfs(n, l + len[i], f));
		}
LABLE:;
	}
	return ret;
}



Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
int min(int x, int y)
{
  if(x>y)
    return y;
  else
    return x;
}
signed main()
{
  fastio;
  
  int a,b,m;
  cin>>a>>b>>m;

  int mini=200000;

  vector<int> arr(a),brr(b);

  int res=min(a,b);

  for(int i=0;i<a;i++)
  {
    cin>>arr[i];
  }
  for(int i=0;i<b;i++)
  {
    cin>>brr[i];
  }
  vector<int> crr(res);

  for(int i=0;i<res;i++)
  {
    crr[i]=arr[i]+brr[i];
  }
  for(int i=0;i<m;i++)
  {
      int x,y,z;
      cin>>x>>y>>z;

      int sum=arr[x-1]+brr[y-1]-z;

      if(sum<mini)
      {
        mini=sum;
      }
  }
  sort(arr.begin(),arr.end());
  sort(brr.begin(),brr.end());

  int sum=arr[0]+brr[0];

  if(sum<mini)
    mini=sum;


  cout<<mini<<endl;
  
  return 0;
}


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

#define _USE_MATH_DEFINES
#include<cmath>

int main()
{
    double a, b, t;
    int C;
    cin >> a >> b >> C;
    t = (M_PI * C * 1.0) / 180;

    cout << fixed << setprecision(10) << endl;
    cout << 0.5 * a * b * sin(t) << endl;
    cout << a + b + sqrt(a * a + b * b - 2 * a * b * cos(t)) << endl;
    cout << b * sin(t) << endl;

    return 0;
}

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

int main(){
    long long k, s;
    cin >> k >> s;

    long long ans = 0;
    for(long long x = 0; x <= k; x++){
        for(long long y = 0; y <= k; y++){
            long long z = s - x - y;
            if(0 <= z and z <= k) ans++;
        }
    }

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

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    ll ans=0;
    FOR(a,1,N){
        int b = (N-1)/a;
        ans+=b;
    }
    cout<<ans<<endl;
    return 0;
}


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

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; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
const int MAX=2e5;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  int a,b;
  cin >> a >> b;
  set<int> S;
  S.insert(1);S.insert(2);S.insert(3);
  S.erase(a);S.erase(b);
  for(auto c:S){
    cout << c << endl;
  }
}


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

int main(){
	long long a,b,c,d;
    cin>>a>>b>>c>>d;
    long long p=max(a*c,a*d),q=max(b*c,b*d),r;
    if((a<=0&&b>=0)||(c<=0&&d>=0)) r=0;
    else r=-5000000000000000000;
    cout<<max(max(p,q),r);
}


Measured memory_bytes: 3672
#include <stdio.h>
#include <stdlib.h>
#define MAX(A,B) ((B) > (A) ? (B) : (A))

int main(int argc, char *argv[]) {
  int c, i, j;
  
  for (c = 1; ; ++c) {
    int W, N, v[1000], w[1000], p[1001] = {0};
    scanf(" %d", &W);
    if (W == 0) break ;
    scanf(" %d", &N);
    for (i = 0; i < N; ++i)
      scanf(" %d,%d", &v[i], &w[i]);
    for (i = 0; i < N; ++i) {
      for (j = W; j >= w[i]; --j)
        p[j] = MAX(p[j], p[j - w[i]] + v[i]);
    }
    for (i = W; i > 0 && p[i - 1] == p[W]; ) --i;
    printf("Case %d:\n%d\n%d\n", c, p[W], i);
  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 1800
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char) 
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let (a, b): (usize, usize) = (read(), read());
  println!("{}", (a - 1) * (b - 1));
}

Measured memory_bytes: 4352
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
delta=int(input())
l=[b-a,c-a,d-a,e-a,c-b,d-b,e-b,d-c,e-c,e-d]
if max(l)<=delta:
  print('Yay!')
else:
  print(':(')

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

int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  
  for(int i=0;i<N;i++){
    cin >> v.at(i);
  }
  
  bool find = 0;
  
  for(int i = 0;i<N;i++){
    for(int j = 0;j<N;j++){
      vector<int> u(N); //uを宣言
      vector<int> w(N); //こっちはvのコピーそのもの
      w = v;
      sort(w.begin(), w.end());
      for(int k = 0;k<N;k++){
        if(k == i){
          u.at(k) = v.at(j);
        }else if(k == j){
          u.at(k) = v.at(i);
        }else{
          u.at(k) = v.at(k); //uにvをコピー
        }
      }
      if(u == w){
        cout << "YES" << endl;
        find = 1;
        break;
      }else if(u != w && i == N-1 && j == N-1){
        cout << "NO" << endl;
      }
    }
    if(find){break;}
  }
  
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 1000000000
#define max 500001


int count = 0;

void merge(int *A,int left,int mid,int right){

	int i,j,k,n1,n2,L[max],R[max];

	n1 = mid - left;
	n2 = right - mid;

	for(i = 0; i < n1; i++) L[i] = A[left + i];
  	for(i = 0; i < n2; i++) R[i] = A[mid + i];
  	L[n1] = MAX;
  	R[n2] = MAX;

  	i = 0;
  	j = 0;

  	for(k = left; k < right; k++){

    	if(L[i] <= R[j]){
      	A[k] = L[i];
      	i++;
    	}
    	else{ 
      	A[k] = R[j];
      	j++;
  		}
  		count++;
	}
}

void mergeSort(int *A,int left,int right){

	int mid;

  	if(left+1 < right){
  		mid = (left + right)/2;
    	mergeSort(A,left,mid);
    	mergeSort(A,mid,right);
    	merge(A,left,mid,right);
	}
}


int main(){

	int i,n,A[max];

	scanf("%d",&n);
	for(i = 0; i < n; i++) scanf("%d",&A[i]);
	mergeSort(A,0,n);
	for(i = 0; i < n-1; i++) printf("%d ",A[i]);
	printf("%d\n",A[n-1]);
	printf("%d\n",count);


	return 0;
}

Measured memory_bytes: 5484
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {

            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       




        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = Read();
            }
            long ans = 0;
            long next = 1;
            while (ans < n)
            {
                ans++;
                if (a[next-1] == 2) break;
                next = a[next-1];
            }
            Console.WriteLine(ans == n ? -1 : ans);


            Console.Out.Flush();
        }
    }
}




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

int main(){
    int N;
    cin>>N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin>>A[i];

    for(int i=0; i<N; i++) A[i] -= (i+1);

    sort(A.begin(),A.end());

    int med = A[N/2];

    long long ans = 0;

    for(int i=0; i<N; i++){
        ans += abs(A[i]-med);
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

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

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

struct Hashing {
    ull seed, mod;
    vector <ull> hs, pw;

    Hashing(ull seed = 31, ull mod = 1000173169) :
        seed(seed),
        mod(mod) {}

    void build(int n, const string& s) {
        hs.assign(n + 1, 0);
        pw.assign(n + 1, 1);
        pw[0] = 1;

        for (int i = 1; i <= n; ++i)
            pw[i] = pw[i - 1] * seed % mod;
        for (int i = 1; i <= n; ++i)
            hs[i] = (hs[i - 1] * seed + s[i]) % mod;
    }

    ull hash(int l, int r) {
        return (hs[r] - hs[l - 1] * pw[r - l + 1] % mod + mod) % mod;
    }
};

int solve()
{
    int N;

    std::cin >> N;

    if (N % 2 == 0)
        cout << (N / 2) << endl;
    else
        cout << (N / 2 + 1) << endl;

    return 0;
}

int main()
{
//    std::cout << solve() << std::endl;
    solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
const int inf = 1e18 + 7;
const int N = 2e5 + 7;
const int md = 1e9 + 7;
int vis[N];
void sol() {
  int n, a;
  cin >> n;
  for(int i = 2; i <= n; i++) {
    cin >> a;
    vis[a]++;
  }
  for(int i = 1; i <= n; i++) {
    cout << vis[i] << "\n";
  } //cout << ".\n";
  for(int i = 1; i <= n; i++) vis[i] = 0;
}

int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;

  /*COMMENT BELOW WITHOUT FAIL*/
  //freopen("input.txt", "r", stdin);
  /*REMOVE ABOVE WITHOUT FAIL BEFORE SUBMITTING */

  //cin >> T;
  for(int i = 1; i <= T; i++) {
    //cout << "Case " << "#" << i << ": ";
    sol();
  }
  return 0;
}


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

int main()
{
  int A, B;
  cin >> A;
  cin >> B;

  int max;
  max = (((A + B) > (A - B)) ? A + B : A - B);
  max = (max < (A * B) ? (A * B) : max);
   cout << max;

   return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma once
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
typedef pair<int,int> P;
const ll INF = 1e16;
const int MOD = 1000000007;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
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 pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}

vector<ll> fac, finv, inv;
void COMinit(const int MAX = 5000000, const ll &MOD = MOD){
  fac.resize(MAX);finv.resize(MAX);inv.resize(MAX);
  fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
  repd(i,2,MAX){
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}
ll COM(int n, int k){
  if(n < k)return 0;
  if(n < 0 || k < 0)return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}


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

int n,k,ans,a[110000];
signed main(){
  cin>>n>>k;rep(i,n)cin>>a[i];
  sort(a,a+n);
  COMinit();
  rep(i,n){
    if(i >= k-1)ans = (ans + a[i]*COM(i,k-1) % MOD)%MOD;
    if(n-i-1 >= k-1)ans = (ans - a[i]*COM(n-i-1,k-1)%MOD)%MOD;
  }
  cout << ans << endl;
}




Measured memory_bytes: 118272
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
/*typedef priority_queue<string> prique<string>;
typedef priority_queue<int> prique<int>;
typedef priority_queue<ll> prique<ll>;
typedef priority_queue<char> prique<char>;
typedef priority_queue<string,vector<string>,greater<string>> rprique<string>;
typedef priority_queue<int,vector<int>,greater<int>> rprique<int>;
typedef priority_queue<ll,vector<ll>,greater<ll>> rprique<ll>;
typedef priority_queue<char,vector<char>,greater<char>> rprique<char>;*/
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
int exp(int x,int y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    int t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/
    
    int n,W;cin >> n >> W;
    vector<int> w(n),v(n);rep(i,n)cin >> w[i] >> v[i];
    //dp[i][j]:=i個目までで重さj以下にした時の価値のma
    vector<vector<ll>> dp(n+1,vector<ll>(W+1));
    rep(i,n)rep(j,W+1){//配るdpをする
        dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
        if(j+w[i]<=W)dp[i+1][j+w[i]]=max(dp[i+1][j+w[i]],dp[i][j]+v[i]);
    }
    cout << dp[n][W] << '\n';
}

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

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

    vector<int> vec(N);

    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }

    for (int i = 0; i < N; i++) {
        int v = vec.at(i);
        int j = i - 1;

        while(j >= 0 && vec.at(j) > v) {
            vec.at(j + 1) = vec.at(j);
            j--;
        }

        vec.at(j + 1) = v;

        for (int k = 0; k < N; k++) {

            if(k == N - 1) {
                cout << vec.at(k);
            } else {
                cout << vec.at(k) << " ";
            }
        }
        cout << endl;
    }

    return 0;

}



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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int taka=(a-1)/d+1;
    int aoki=(c-1)/b+1;
    if(taka>=aoki) {
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<math.h>
int main(void) {
	int n, d, k;
	scanf("%d %d", &n, &d);
	k = d * 2 + 1;
	if (n % k == 0) {
	printf("%d\n", n / k);}
else {
printf("%d\n", n / k + 1);
}
	return 0;
}

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

int main(void){
  int x[10];
  int sum[2];

  for(int i=0;i<2;i++){
    for(int j=0;j<10;j++){
      cin>>x[j];
    }
    sort(x,x+10);
    sum[i] = x[9]+x[8]+x[7];
  }
  cout<<sum[0]<<" "<<sum[1]<<endl;

  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void){
    int n;

    scanf("%d", &n);

    switch (n%10)
    {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        puts("hon");
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        puts("pon");
        break;
    case 3:
        puts("bon");
        break;
    default:
        break;
    }

    return 0;
}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  ll N,M;
  string s,t;
  cin>>N>>M>>s>>t;
  ll g = gcd(N,M);
  ll n = N/g;
  ll m = M/g;
  // cout << g << endl;
  rep(k,g) {
    if(s[n*k]!=t[m*k]) {
      cout << "-1" << endl;
      // cout << k << endl;
      return 0;
    }
  }
  cout << N*M/g << endl;
  return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long X, A, B;
  cin >> X >> A >> B;
  X -= A;
  X %= B;
  cout << X << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#import <stdio.h>
#import <stdlib.h>
#define ABS(a) ((a)>0?(a):(-(a)))
typedef long long INT;

int compare_int(const void *a, const void *b)
{
    return (int)(*(INT*)a - *(INT*)b);
}

int main(){
    INT n;
    scanf("%lld",&n);
    INT A[200003] = {0};
    for (INT i=1;i<=n;i++){
        INT a;
        scanf("%lld",&a);
        A[i-1] = a-i;
    }
    qsort(A, n, sizeof(INT), compare_int);

    INT k=(n-1)/2;
    INT s=0;
    for (INT i=0;i<n;i++){
        s += ABS(A[i]-A[k]);
    }
    printf("%lld",s);
}


Measured memory_bytes: 8652