akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int D = sc.nextInt();
		String Chr = "Christmas";

		if(D == 25) {
			Chr = "Christmas";
		}else if(D == 24){
			Chr = "Christmas Eve";
		}else if(D == 23){
			Chr = "Christmas Eve Eve";
		}else if(D == 22){
			Chr = "Christmas Eve Eve Eve";
		}





		System.out.println(Chr);




	}

}

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

unsigned long long GCD(unsigned long long a, unsigned long long b) {
	if (a < b) return GCD(b, a);
	if (b == 0) return a;
	return GCD(b, a % b);
}

int main(){
	int a, b; cin >> a >> b;
	cout << GCD(a, b) << endl;
	return 0;
}



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

int main(void){
    long long n, k, cnt=0;
    cin >> n >> k;
    for(long long i=k+1;i<=n;++i){
        long long plu = i-k;
        long long ref = n/i;
        cnt += plu*ref;
        if((n%i-k)>=0)cnt += n%i-k+1;
    }
    if(k==0) cnt -= n-k;
    cout << cnt << endl;
}

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

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

      if(m == -1 && f == -1 && r == -1)break;
      
      int sum = m+f;

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



Measured memory_bytes: 3036
#include <iostream>

using namespace std;

int main()
{
    int x=1,t,k,ans=0;
    cin>>t>>k;
    for(int i=0;i<t;i++){
      if(x*2 < x +k)
    x= x*2;
else x =x + k;
    }
        cout<<x;
}


Measured memory_bytes: 256
s = list(input())
b = [None]*len(s)
for i in range(len(b)):
  s.pop()
  if len(s) % 2 == 0:
    a = int(len(s) / 2)
    if s[:a] == s[a:]:
      print(len(s))
      break
    else:
      continue
  else:
    continue

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
using ll = long long; 
using P = pair<int,int>;
ll mod = 1000000007;
template <class _T> inline bool chmax (_T& a,_T b){if(a<b){a=b;return true;}return false;}
template <class _T> inline bool chmin (_T& a,_T b){if(a>b){a=b;return true;}return false;}
const int inf = 2147483647;
const long long INF = 1LL << 60;
const int MAX_N = 11000;
const int MAX_W = 10100;


int main(void){
    int n;cin >> n;
    int k = 0;
    for(int i=0;i<n;i++){
        int a,b; cin >> a >> b;
        if(a==b)k++;
        else k=0;
        if(k==3){
            cout << "Yes" << endl;
            return 0;
        } 
    }
    cout << "No" << endl;
	return 0;
}

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

int main(){
    int N, X;
    cin >> N >> X;
    vector<int> M(N);
    for(int i = 0; i < N; i++){
        cin >> M.at(i);
    }

    int count = 0; 

    for(int i = 0; i < N; i++){
        X -= M.at(i);
        count++;
    }

    if(count != 0){
        sort(M.begin(),M.end());
        int A = X / M.at(0);
        count += A;
    }

    cout << count << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int A,B,C,D,sum=0;
    scanf("%d%d%d%d",&A,&B,&C,&D);
    if(A>=B) sum=sum+B;
    else sum=sum+A;
    if(C>=D) sum+=D;
    else sum+=C;
    printf("%d\n",sum);

    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
    char S[4];
  
    scanf("%s",S);
  
    if((S[0]=='S')&&(S[1]=='U'))
      printf("7\n");
    else if((S[0]=='S')&&(S[1]=='A'))
      printf("1\n");
    else if(S[0]=='M') printf("6\n");
    else if((S[0]=='T')&&(S[1]=='U')) 
      printf("5\n");
    else if(S[0]=='W') printf("4\n");
    else if((S[0]=='T')&&(S[1]=='H'))
      printf("3\n");
    else if(S[0]=='F') printf("2\n");
  
    return 0;
}
      

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

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

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

const int ma = 5001;
vi x;
bool ok = true;

P dfs(int now, int prev, const vvi &g) {
  if(!ok) return {-1, -1};
  bitset<ma> bs(1);
  int su = 0;
  REP(i, SZ(g[now])) {
    int nxt = g[now][i];
    if(nxt == prev) continue;
    P res = dfs(nxt, now, g);
    if(!ok) break;
    su += res.first + res.second;
    bitset<ma> tmp = bs << (res.first);
    tmp |= bs << (res.second);
    bs = tmp;
  }

  bool nowok = false;
  int arg = -1;
  RREP(i, x[now]) {
    if(bs[i]) {
      nowok = true;
      arg = i;
      break;
    }
  }
  if(!nowok) {
    ok = false;
    return {-1, -1};
  }

  return {x[now], su - arg};
}

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

  int n; cin >> n;
  vvi g(n);
  FOR(i, 1, n) {
    int p; cin >> p;
    p--;
    g[p].push_back(i);
  }

  x.resize(n);
  REP(i, n) cin >> x[i];
  dfs(0, -1, g);
  cout << (ok ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}
























Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
 
typedef long long lld;
typedef vector<lld> vlld;
typedef pair<lld,lld> pi;
typedef tuple<lld,lld,lld> tup;
const lld mod=(lld)1e9+7;
 
 
int main() {
    
    int n;
    cin>>n;
    forn(i,n)
    {
      cout<<"ACL";
    }

  
  return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
 ll ar[2000007];
int main()
{
    ll test,c=0,i;
    map<ll,ll> mp;

    cin>>test;

    for(i=0;i<test;i++)
    {
        cin>>ar[i];
        mp[ar[i]]++;

    }
    for(i=0;i<test;i++)
    {
        if(mp[ar[i]]>1)
        {
            c=1;
            break;
        }
    }

    if(c==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 14336
N = int(input())
h_ls=list(map(int, input().split()))

kaisu=0

while max(h_ls)>0:
	M=h_ls.index(max(h_ls))
	takasa=h_ls[M]
	i=0
	while M+i<N and h_ls[min(M+i,N-1)]==takasa:
		h_ls[M+i]+=(-1)
		i+=1
	
	kaisu+=1

print(kaisu)


Measured memory_bytes: 3060
import math
a, b, x = map(int, input().split())
if x >= a * a * b / 2:
    h = x / a / a * 2 - b
    ans = math.atan((b-h)/a)*180/math.pi
else:
    c = 2*x/b/a
    ans = math.atan(b/c)*180/math.pi
print(ans)


Measured memory_bytes: 2940
#include <stdio.h>

int main(void)
{
	int i,j,k,n,x,ans;
	while(1) {
		scanf("%d %d",&n,&x);
		if(n==0 && x==0) break;
		ans = 0;
		for (i=1; i<=n-2; i++) {
			for (j=i+1; j<=n-1; j++) {
				for (k=j+1; k<=n; k++) {
					if(i+j+k == x) ans++;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  ll r,d,x;
  cin>>r>>d>>x;
  ll l[11];
  l[0]=x;
  rep1(i,11){
    l[i]=r*l[i-1]-d;
    cout<<l[i]<<'\n';
  }
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int N = sc.nextInt();
		long sum=0,left=0;
		int[] A = new int[N + 1];
		for (int i = 0; i <= N; i++) {
			A[i] = sc.nextInt();
			sum += A[i];
		}
		for (int i = 0; i < N; i++) {
			int temp = sc.nextInt();
			if(temp>=A[i]){
				temp -= A[i];
				if(A[i+1]>temp) A[i+1] -= temp;
				else A[i+1] = 0;
				A[i]=0;
			}else A[i] -= temp;
		}
		for(int i=0;i<=N;i++) left += A[i];
		System.out.println(sum-left);
	}
}

Measured memory_bytes: 59412
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(std::string S_A, std::string S_B, std::string S_C){
    int sum = S_A.size() + S_B.size() + S_C.size();
    char c = S_A[0];
    char win;
    REP(i, sum) {
        if (c == 'a') {
            if (S_A.size() == 0) {
                win = 'A';
                break ;
            }
            c = S_A[0];
            S_A.erase(0, 1);
        }
        else if (c == 'b') {
            if (S_B.size() == 0) {
                win = 'B';
                break ;
            }
            c = S_B[0];
            S_B.erase(0, 1);
        } else {
            if (S_C.size() == 0) {
                win = 'C';
                break ;
            }
            c = S_C[0];
            S_C.erase(0, 1);
        }
    }
    cout << win << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string S_A;
    std::cin >> S_A;
    std::string S_B;
    std::cin >> S_B;
    std::string S_C;
    std::cin >> S_C;
    solve(S_A, S_B, S_C);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
using namespace std;

int main()
{
    ll n,k;
    string s;

    cin>>n>>k>>s;

    ll cnt = 0;
    for(ll i=1;i<n;i++)
        if(s[i] != s[i-1])  cnt++;

    ll tmp = k - min(k,cnt/2);
    if((cnt%2) == 1 && tmp)
    {
        cnt--;
        k--;
    }

    cnt -= 2*min(k,cnt/2);

    ll ans = n-1 - cnt;
    cout<<ans;

    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int a[10],i=0;
	for(;i<10;i++)scanf("%d",&a[i]);
	sort(a,a+10);
	for(i=9;i>6;i--)printf("%d\n",a[i]);
	return 0;
}

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

#define ll long long
#define str string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second

#define vc vector<char>
#define vvc vector<vc>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvvll vector<vvll>
#define vs vector<str>
#define vvs vector<vs>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define vvpll vector<vpll>
#define vb vector<bool>
#define vvb vector<vb>
#define rep(i, a, b) for (int i = (a); i < int(b); i++)
#define repi(i, a, b) for (int i = (a); i <= int(b); i++)


using namespace std;
ll INF = LONG_LONG_MAX;
ll mod = 1000000000 + 7;

template <typename T, typename L>
void read(vector<T> & _data, L & _size, bool _shift) {
    _data.resize(_size + (ll)_shift);
    for (ll i = (ll)_shift; i < _size + (ll)_shift; i++)
        cin >> _data[i];
}

template <typename T, typename L>
void read(vector<vector<T>> & _data, L & _rows, L & _cols, bool _shiftRows, bool _shiftCols) {
    _data.resize(_rows + (ll)_shiftRows);
    for (ll i = 0; i < _rows + (ll)_shiftRows; i++)
        _data[i].resize(_cols + (ll)_shiftCols);
    for (ll i = (ll)_shiftRows; i < _rows + (ll)_shiftRows; i++)
        for (ll j = (ll)_shiftCols; j < _cols + (ll)_shiftCols; j++)
            cin >> _data[i][j];
}

template <typename T>
void write(vector<T> & _data, bool _shift) {
    for (ll i = (ll)_shift; i < _data.size(); i++)
        cout << _data[i] << " ";
    cout << endl;
}


//TODO: SOLUTION


void solve() {
   ll n; cin >> n;
   vll a; read(a, n, 1);
   vll dp(n + 1, 0);
   dp[1] = 1;
   vll prev(n + 1, 0);
   vll pos(2e5 + 1, 0);

   repi(i, 1, n) {
       prev[i] = pos[a[i]];
       pos[a[i]] = i;
   }

   repi(i, 2, n) {
       if (a[i] == a[i-1] || prev[i] == 0)
           dp[i] = dp[i-1];
       else
           dp[i] = dp[prev[i]] + dp[i - 1];
       dp[i] = dp[i] % mod;
   }
   cout << dp[n] << endl;
}


int main() {

    // TODO: Set value of this variable manually
    bool _multipleTestCases = false;

    if (_multipleTestCases) {
        ll t; cin >> t;
        while (t--)
            solve();
    }
    else {
        solve();
    }

    return 0;
}

Measured memory_bytes: 9576
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	const MAX = 100000 + 2

	N, C := nextInt(), nextInt()
	pp := make([][MAX]int, C)
	for i := 0; i < N; i++ {
		s, t, c := nextInt(), nextInt(), nextInt()-1
		pp[c][s]++
		pp[c][t+1]--
	}

	ans := 0
	for i := 1; i < MAX; i++ {
		a := 0
		for j := range pp {
			pp[j][i] += pp[j][i-1]
			if pp[j][i] > 0 {
				a++
			}
			// a += pp[j][i]
		}
		ans = max(ans, a)
	}

	puts(ans)
}


Measured memory_bytes: 26112
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var u = new int[N - 1];
        var v = new int[N - 1];
        var w = new int[N - 1];
        for (int i = 0; i < N - 1; i++)
        {
            var line = ReadLine().Split(' ');
            u[i] = int.Parse(line[0]) - 1;
            v[i] = int.Parse(line[1]) - 1;
            w[i] = int.Parse(line[2]);
        }

        var tree = new List<Edge>[N];
        for (int i = 0; i < tree.Length; i++)
        {
            tree[i] = new List<Edge>();
        }
        for (int i = 0; i < N - 1; i++)
        {
            tree[u[i]].Add(new Edge { to = v[i], dist = w[i] });
            tree[v[i]].Add(new Edge { to = u[i], dist = w[i] });
        }

        var ans = new bool[N];
        var q = new Queue<Triple>();
        q.Enqueue(new Triple { from = -1, to = 0, color = false });
        while (q.Count != 0)
        {
            var e = q.Dequeue();
            ans[e.to] = e.color;
            foreach (var a in tree[e.to])
            {
                if (e.from != a.to)
                {
                    if (a.dist % 2 == 0) q.Enqueue(new Triple { from = e.to, to = a.to, color = e.color });
                    else
                    {
                        q.Enqueue(new Triple { from = e.to, to = a.to, color = !e.color });
                    }
                }
            }
        }

        foreach (var c in ans)
        {
            WriteLine(c ? "1" : "0");
        }
    }
}

struct Edge
{
    public int to;
    public int dist;
}

struct Triple
{
    public int from;
    public int to;
    public bool color;
}



Measured memory_bytes: 31680
n,t=[int(i) for i in input().split()]
time=[int(i) for i in input().split()]
now=time[0]
ans=t
for i in range(1,n):
    if now+t>time[i]:
        ans+=time[i]-now
    else:
        ans+=t
    now=time[i]
print(ans)

Measured memory_bytes: 25200
N = int(input())
N = str(N)
Hon = [2, 4, 5, 7, 9]
Pon = [0, 1, 6, 8]
for i in Hon:
    if int(N[-1]) == i:
        print('hon')
    else:
        pass
for j in Pon:
    if int(N[-1]) == j:
        print('pon')
    else:
        pass
if int(N[-1]) == 3:
    print('bon')

Measured memory_bytes: 9220
#include <stdio.h>
int i,r;
char s[100100];
int main() {
  scanf("%s",s);
  for (i=0; s[i]; i++) if (i&1) r+=int(s[i]=='g'); else r-=int(s[i]=='p');
  printf("%d\n",r);
  return 0;
}


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

int main() {
  int N;
  cin>>N;
	vector<pair<pair<string,int>,int>> p(N+1);
  string a;
  int b;
  for(int i=1;i<=N;i++) {
    cin>>a>>b;
    p[i]=make_pair(make_pair(a,-b),i);
  }
  sort(p.begin(),p.end());
  for(int i=1;i<=N;i++){
    cout<<p[i].second<<endl;
  }
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define pb push_back
#define Ceil(a,b)              ((a)+(b)-1)/(b)
#define MrGAFs                 file();
#define rep(i,limits)          for(int i = 0;i<(limits);++i)
#define allr(v)                ((v).rbegin()), ((v).rend())
#define all(v)                 ((v).begin()), ((v).end())
#define endl                   "\n"
#define sz(v)	               ((int)((v).size()))
#define dep(x)		       cout << #x << " = " << x << endl ;
#define rt(v)                  return cout<<v,0;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int oo = INT_MAX;
const ll OO = LLONG_MAX;
using namespace std;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int dx1[] = { -1, 1, 0, 0 };
int dy1[] = { 0, 0, -1, 1 };

	//classes
        void file (){
      #ifndef ONLINE_JUDGE 
         freopen ("in.txt", "r", stdin);
   //     x = freopen ("out.txt", "w", stdout);
      #else
#endif
  ios_base::sync_with_stdio (false);
  cout.tie (NULL);
  cin.tie (NULL);
}
  /******Functions*********/
  
  /******Main Function*********/
int main (){
  MrGAFs
string str ;
  cin >> str ;
  (str == "ABC") ?cout << "ARC" :cout << "ABC"; 
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}

int n;
int a[5][5];
bool is[5][5];

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

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }

    cin >> n;
    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (a[j][k] == b[i]) {
                    is[j][k] = true;
                }
            }
        }
    }

    for (int i = 0; i < 3; i++) {
        if (is[i][0] && is[i][1] && is[i][2]) {
            cout << "Yes";
            return 0;
        }
        if (is[0][i] && is[1][i] && is[2][i]) {
            cout << "Yes";
            return 0;
        }
    }

    if (is[0][0] && is[1][1] && is[2][2]) {
        cout << "Yes";
        return 0;
    }

    if (is[0][2] && is[1][1] && is[2][0]) {
        cout << "Yes";
        return 0;
    }

    cout << "No";


    return 0;
}


Measured memory_bytes: 256
open System.Linq;

let n = stdin.ReadLine() |> int
let s = [|for _ in 1.. n -> stdin.ReadLine()|]

s.Select(fun x -> new string (x.OrderBy(fun s -> s).ToArray())).GroupBy(fun s -> s).Select(fun g -> g.Count()).Where(fun c -> c > 1).Sum(fun c -> int64 c * int64 (c-1) / 2L)
|> stdout.WriteLine

Measured memory_bytes: 37144
from math import floor

a, b, n = map(int, input().split())

max_v = 0
if n < b:
  max_v = floor(a * n / b)
else:
  if b != 1:
    for i in range(b - 1, n + 1, b):
      j = 0
      t = floor(a * i / b) - a * j
      if t > max_v:
        max_v = t
      j += 1
print(max_v)

Measured memory_bytes: 9140
#include<iostream>
#include<string>
using namespace std;
int main() {
	string S;
	cin >> S;
	int a=0, b=0;
	for (int i = 0; i < S.size(); ++i) {
		if (S[i] == 'A') {
			a = i;
			break;
		}
	}
	for (int j = 0; j < S.size(); ++j) {
		if (S[j] == 'Z') {
			b = j;
		}
	}
	cout << b - a + 1 << endl;
	return 0;
}

Measured memory_bytes: 640
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
from itertools import permutations

N, M, R = map(int, input().split())
r = list(input().split())
edge = np.array([input().split() for _ in range(M)], dtype = np.int64).T
graph = csr_matrix((edge[2], (edge[:2] - 1)), (N, N))

lst = floyd_warshall(graph, directed = False)
# print (lst)
def calc(path):
    cost = 0
    s = int(path[0]) - 1
    for i in range(1, R):
        g = int(path[i]) - 1
        cost += lst[s, g]
        s = g
    return cost

ans = 10 ** 18
for tmp in permutations(r):
    # print (tmp)
    ans = min(ans, calc(tmp))

print (int(ans))

Measured memory_bytes: 25688
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}
  
int main()
{
  int i,j;
  int N; cin >> N;
  int d[N]; rep(i,N){cin >> d[i];}
  int ans = 0;

  repd(i,0,N-1){
      repd(j,i+1,N){
          ans += d[i] * d[j];
      }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#define maxn 100005
using namespace std;

int a[maxn];

int main() {
	int n, k;	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++)	scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	int mi = 0x3f3f3f3f;
	for (int i = 1; i <= n - k + 1; i++)	mi = min(mi, a[i + k - 1] - a[i]);
	printf("%d\n", mi);
	return 0;
}

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


int main(){
  int N,M;
  vector<int> path[100001];
  int pathed[100001] = {0};

  cin>>N>>M;
  for (int i(0);i<M;i++){
    int x,y,z;
    cin>>x>>y>>z;
    path[x].push_back(y);
    path[y].push_back(x);
  }

  ll ans(0);
  for (int i(1);i<=N;i++){
    if (pathed[i] == 0){
      queue <int> q;
      q.push(i);
      while(!q.empty()){
        int now = q.front();q.pop();
        pathed[now] = 1;
        for (int j(0);j<path[now].size();j++){
          int next = path[now][j];
          if (pathed[next] == 0 ){
            q.push(next);
          }
        }
      }
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6904
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n; cin>>n;
    map<int,int> mp;
    rep(i,n){
        int a; cin>>a;
        mp[a]++;
    }
    int cnt=0;
    for(auto i:mp){
        if(i.second%2==0) cnt++;
    }
    int ans=mp.size()-(cnt%2?1:0);
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r;
    cin >> r;
    cout << std::fixed << std::setprecision(15) << 2*r*M_PI << endl;
    return 0;
}

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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x,y,_x,_y; cin >> x >> y >> _x >> _y;
    int dx = _x - x, dy = _y - y;
    for(int i = 0; i < dx; i++) cout << 'R';
    for(int i = 0; i < dy; i++) cout << 'U';
    for(int i = 0; i < dx; i++) cout << 'L';
    for(int i = 0; i <= dy; i++) cout << 'D';
    for(int i = 0; i <= dx; i++) cout << 'R';
    for(int i = 0; i <= dy; i++) cout << 'U';
    cout << 'L';
    cout << 'U';
    for(int i = 0; i <= dx; i++) cout << 'L';
    for(int i = 0; i <= dy; i++) cout << 'D';
    cout << "R\n";
    return 0;
}


Measured memory_bytes: 256
n,h=map(int,input().split())
l=sorted([list(map(int,input().split())) for _ in [0]*n],key=lambda x:[-x[1],-x[0]])
m=0
k=0
for i in range(n):
    if l[i][0]>=m:
        m=l[i][0]
        k=i
hp=0
c=0
for i in range(n):
    if l[i][1]<l[k][0]:break
    if i==k:continue
    hp+=l[i][1]
    c+=1
    if hp>=h:print(c);exit()
print((h-hp-l[k][1]+l[k][0]-1)//l[k][0]+c+1)

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

using lli = long long int;

std::map<lli, lli> m;
lli a;
int n, ans=0;

int main() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> a;
        m[a]++;
    }
    for (auto e: m) {
        if (e.second % 2 == 1) {
            ans++;
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>


int main()
{
	int N, L,sum;
	std::vector<int> v;
	
	std::cin >> N;

	for (int i = 0; i < N; i++) {
		std::cin >> L;
		v.push_back(L);
	}

	std::sort(v.begin(), v.end());
	sum = std::accumulate(v.begin(), v.end() - 1, 0);

	if (v[N - 1] < sum) std::cout <<"Yes\n";
	else std::cout << "No\n";

	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def next_vary(S):
    if len(S) < 26:
        alpha = [0] * 26
        for s in S:
            alpha[ord(s) - 97] += 1
        add = None
        for i in range(26):
            if alpha[i] == 0:
                add = chr(i + 97)
                break
        S.append(add)
        return ''.join(S)
    
    else:
        before = set(S)
        flag = False
        for i in range(25,-1,-1):
            s = S[i]
            if s == 'z':
                before.discard('z')
                S.pop()
            else:
                asc = ord(s)
                for j in range(1,25):
                    if asc + j <= 122 and chr(asc + j) not in before:
                        S[i] = chr(asc + j)
                        flag = True
                        break
                if flag:
                    break
                before.discard(s)
                S.pop()
        return ''.join(S)

def main():
    S = input()
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
        return
    
    ans = next_vary(list(S))
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 9152
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <iomanip>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
#define int ll

using namespace std;
using Graph = vector<vector<int> >;


long double A[120];

signed main() {
  int N; cin >> N;
  long double ans = 0;
  for (int i = 0; i < N; i++) {
    long double a; cin >> a;
    ans += (1/a);
  }
  cout << setprecision(20) << (1/ans) << endl;
}


Measured memory_bytes: 256
from sys import stdin
N = int(stdin.readline().rstrip())
hk = [int(i) for i in stdin.readline().rstrip().split(" ")]

def calcCount(hks):
    counter = 0
    counter += min(hks)
    nhks = [i - counter for i in hks]
    splitTo = []
    for i in nhks:
        if i == 0:
            if len(splitTo) > 0:
                counter += calcCount(splitTo)
                splitTo = []
        else:
            splitTo.append(i)
    if len(splitTo) > 0:
        counter += calcCount(splitTo)
    return(counter)

print(calcCount(hk))

Measured memory_bytes: 3188
module Main where

import Control.Monad
import Data.List
import Debug.Trace

main :: IO ()
main = do
  paths' <- map getPair <$> replicateM 3 getLine
  putStrLn $ if p paths' then "YES" else "NO"
  where
    p :: [(Int, Int)] -> Bool
    p paths'' = any (hasPath [] paths'') [0..3]
    hasPath acc paths node
      | length acc == 3 = True
      | null paths = False
      | otherwise = case getNext node paths of
        Just (nextNode, nextPath) ->
          hasPath (nextNode : acc) (delete nextPath paths) nextNode
        Nothing -> False
    getNext n ps =
      case find (\(x, y) -> n == x || n == y) ps of
        Nothing -> Nothing
        Just nP -> let
          nN = if fst nP == n then snd nP else fst nP
          in Just (nN, nP)
 

getPair = (\[x, y] -> (x, y)) 
  . map pred
  . map (read::String -> Int) 
  . words

Measured memory_bytes: 508
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
long long cost[101],cap[101],n;
long long dp[101][100005];
 
long long knap(int n,int c){
    
    for(int i=0;i<=n;i++){
        for(int j=0;j<=c;j++){
            if(i==0 || j==0) dp[i][j]=0;
            else if(cap[i-1]>j) dp[i][j]=dp[i-1][j];
            else{
                long long t1,t2;
                t1=dp[i-1][j];
                t2=dp[i-1][j-cap[i-1]]+cost[i-1];
                dp[i][j]=max(t1,t2);
            }
        }
    }
    return dp[n][c];
}
int main(){
    
        memset(dp,-1,sizeof(dp));
      
        long long c;
        cin >> n >> c;
       
        for(int i=0;i<n;i++){
            cin >> cap[i] >> cost[i] ;
           
        }
        
        cout << knap(n,c) << endl;
    
}

Measured memory_bytes: 82520
#include<bits/stdc++.h>
using namespace std;
long long s1, s2, s3, ans = 10000000000, maxS, minS;

void search(long long A, long long B){
  for ( int a = 1; a < A; a++){
    s1 = a * B;
    int da = A-a;
    s2 = da/2 * B ;
    s3 = da * B - s2;
    maxS = max(s1, max(s2, s3));
    minS = min(s1, min(s2, s3));
    ans = min(ans, maxS-minS );
    s2 = da * (B/2);
    s3 = da * B - s2;
    maxS = max(s1, max(s2, s3));
    minS = min(s1, min(s2, s3));
    ans = min(ans, maxS-minS );
  }
}

int main(){
  int H, W;
  cin >> H >> W;
  search(H, W);
  search(W, H);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
def main():
    N, T = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    ans = 0
    for i in range(N-1):
        ans += min(A[i+1] - A[i], T)
    ans += T
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 85328
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<int, int>
const ll  MOD = 1000000007;

int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll> a;
	rep(i, m) {
		ll A;
		cin >> A;
		a.push_back(A);
	}
	if (m == 0) a.push_back(-1);
	if (n < 3) {
		cout << n - m;
		return 0;
	}
	vector<ll> dp(n + 1, 0);
	dp.at(0) = 1; dp.at(1) = 1;
	ll k = 0;
	if (a.at(0) == 1) {
		dp.at(1) = 0;
		if (k < m - 1) k++;
	}
	rep(i, n - 1) {
		dp.at(i + 2) = dp.at(i + 1) + dp.at(i);
		if (i + 2 == a.at(k)) {
			dp.at(i + 2) = 0;
			if (k < m - 1) k++;
		}
		dp.at(i + 2) %= MOD;
	}
	cout << dp.at(n) % MOD;
	return 0;
}

Measured memory_bytes: 1908
class Node
  attr_accessor :id, :k, :children, :parent, :left, :right

  def set_info(id, k, children)
    @id = id
    @k = k
    @children = children
    if @parent.nil?
      @parent = -1
      @depth = 0
    end
  end

  def set_parent(parent_id)
    @parent = parent_id
  end

  def type?
    if @parent == -1
      return 'root'
    elsif @children.empty?
      return 'leaf'
    else
      return 'internal node'
    end
  end

  def set_right(right)
    @right = right
  end

  def set_left(left)
    @left = left
  end
end

n = gets.to_i
$nodes = Array.new(n).map{ Node.new() }
$depth = Array.new(n)

n.times do |num|
  input = gets.split.map(&:to_i)
  id, k, children = input[0], input[1], input[2...input.length]
  $nodes[id].set_info(id, k, children)
  $nodes[id].set_left(children[0])
  $nodes[id].children.each_with_index do |c, i|
    $nodes[c].set_right($nodes[id].children[1..-1]) if i == 0
    $nodes[c].set_parent($nodes[id].id)
  end
end

def setDepth(u, p)
  $depth[u] = p
  if $nodes[u].right != nil
    $nodes[u].right.each do |r|
      setDepth(r, p)
    end
  end
  if $nodes[u].left != nil
    setDepth($nodes[u].left, p + 1)
  end
end

c = 0
while $depth.include?(nil)
  setDepth(c, 0)
  c += 1
end

$nodes.each do |e|
  puts "node #{e.id}: parent = #{e.parent}, depth = #{$depth[e.id]}, #{e.type?}, #{e.children}"
end



Measured memory_bytes: 32956
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <functional>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;




int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> a(n);
    int i, j;
    for(i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    if(a[n - 1] % 2 == 0) {
        int mid = a[n - 1] / 2;
        int e = -1, mind = 1e9 + 1;
        for(i = 0; i < n - 1; i++) {
            if(abs(mid - a[i]) < mind) {
                mind = abs(mid - a[i]);
                e = a[i];
            }
        }
        swap(e, a[n - 1]);
        cout << e << " " << a[n - 1];
    }
    else {
        int m1 = a[n - 1] / 2;
        int m2 = m1 + 1;
        int mind = 1e9 + 1;
        int e;
        for(i = 0; i < n - 1; i++) {
            if(abs(m1 - a[i]) < mind) {
                mind = abs(m1 - a[i]);
                e = a[i];
            }
            if(abs(m2 - a[i]) < mind) {
                mind = abs(m2 - a[i]);
                e = a[i];
            }
        }
        swap(e, a[n - 1]);
        cout << e << " " << a[n - 1];
    }

    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<ll, ll>;
// Welcome to (not) my source code!
 
int main() {
    int n;
    cin >> n;
    ll a[n];
    vector<ll> cnt(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
        cnt[a[i]]++;
    }
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        sum += cnt[i] * (cnt[i] - 1) / 2;
    }
    for (int i = 0; i < n; i++) {
        ll t = sum;
        t -= cnt[a[i]] * (cnt[a[i]] - 1) / 2;
        t += (cnt[a[i]] - 1) * (cnt[a[i]] - 2) / 2;
        cout << t << endl;
    }
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000000;

string s, t;

int main(){
  cin >> s >> t;
  int a, b;
  a = s.size(), b = t.size();
  bool flag = false;
  int c = INF;
  rep(i, a-b+1){
    bool fl = true;
    rep(j, b){
      if(s.at(i+j) != t.at(j) && s.at(i+j) != '?'){
        fl = false;
        break;
      }
    }
    if(fl) c = i;
  }
  if(c <= 50) flag = true;
  if(flag){
    rep(i, c){
      if(s.at(i) == '?') s.at(i) = 'a';
    }
    for(int i = c; i < c+b;i++) s.at(i) = t.at(i-c);
    for(int i=c+b;i<a;i++) if(s.at(i) == '?') s.at(i) = 'a';
    cout << s <<endl;
  }else{
    cout << "UNRESTORABLE" <<endl;
  }
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,x=1;
    string s;
    cin>>a>>b>>s;
    for(int i=0;i<=a+b;i++){
        if((i<a||i>a)&&(s[i]>57||s[i]<48)) x=0;
        else if(i==a&&s[i]!='-') x=0;
    }
    if(x) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define LOCAL
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define forn(i,a,b) for(ll i=a;i<=b;i++)
#define ft first
#define sd second
#define sz size()
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
//cout << fixed << setprecision(12) <<x<<endl;
const int MAX = 1e7;
ll a[MAX],b[MAX];
int main(){
fastIO;
#ifdef LOCAL
     freopen("in.txt", "r", stdin);
#endif

int n;
cin>>n;
ll ans=0;
forn(i,1,n){
    ll div=n/i;
    ll s=(div*(div+1))/2;
    ans+=s*i;
}
cout<<ans<<endl;
}



Measured memory_bytes: 3544
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	int x;
	cin >> x;
	if(x < 1200) puts("ABC");
	else puts("ARC");
 	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=600005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int fac[MAXN],inv[MAXN],a[MAXN];
inline int quick_pow(int x,int y)
{
	int ret=1;
	for (;y;y>>=1)
	{
		if (y&1) ret=1ll*ret*x%mods;
		x=1ll*x*x%mods; 
	}
	return ret;
}
inline int upd(int x,int y){ return x+y>=mods?x+y-mods:x+y; }
inline int C(int x,int y){ return 1ll*fac[x]*inv[y]%mods*inv[x-y]%mods; }
void Init(int n)
{
	fac[0]=1;
	for (int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mods;
	inv[n]=quick_pow(fac[n],mods-2);
	for (int i=n-1;i>=0;i--) inv[i]=1ll*inv[i+1]*(i+1)%mods; 
}
int main()
{
	int n=read(),k=read(),ans=0;
	Init(n);
	for (int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++)
	{
		if (n-i>=k-1) ans=upd(ans,mods-1ll*upd(a[i],mods)*C(n-i,k-1)%mods);
		if (i-1>=k-1) ans=upd(ans,1ll*upd(a[i],mods)*C(i-1,k-1)%mods);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 4736
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

k = ni()
s = ns().strip()
mod = 1000000007

n = k + len(s)

def enumfif(n, mod):
    f = [0] * (n+1)
    invf = [0] * (n+1)
    f[0] = 1
    for i in range(1, n+1):
        f[i] = f[i-1] * i % mod

    a = f[n]
    b = mod
    p, q = 1, 0
    while b > 0:
        c = a//b
        d = a; a = b; b = d % b
        d = p; p = q; q = d-c*q
    invf[n] = p + mod if p < 0 else p
    for i in range(n-1,-1,-1):
        invf[i] = invf[i+1] * (i+1) % mod
    return f, invf

def C(n, r, mod, fif):
    if n < 0 or r < 0 or r > n:
        return 0
    return fif[0][n] * fif[1][r] * fif[1][n-r] % mod

fif = enumfif(2000005, mod)

ans = 0
v = 1
for i in range(n, len(s)-1, -1):
    ans += v * C(n, i, mod, fif)
    v = v * 25 % mod
print(ans%mod)


Measured memory_bytes: 132892
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long LL;
const int N = 4e5+10;
inline int read()
{
    register int x = 0 , f = 0; register char c = getchar();
    while(c < '0' || c > '9') f |= c == '-' , c = getchar();
    while(c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0' , c = getchar();
    return f ? -x : x;
}
int n;
int fp[N] , fa[N];
struct node
{
    int id;
    LL s[2];
    bool operator < (const node &A) const 
    { 
        if(s[0] * A.s[1] == s[1] * A.s[0])
        {
        /*
            if(s[0] < A.s[0]) return true;
            if(s[1] < A.s[1]) return true;
            return id < A.id;
        */
            if(s[0] != A.s[0]) return s[0] < A.s[0];
            if(s[1] != A.s[1]) return s[1] < A.s[1];
            return id < A.id;
        }
        else return (s[0] * A.s[1] < s[1] * A.s[0]);
    }
    node operator + (const node &A) const { node tmp; tmp.id = id; tmp.s[0] = s[0] + A.s[0]; tmp.s[1] = s[1] + A.s[1]; return tmp; }
    bool operator == (const node &A) const { return id == A.id && s[0] == A.s[0] && s[1] == A.s[1]; }
}t[N];

struct PQ
{
    priority_queue<node> A , B;
    void Insert(node &t) { A.push(t); }
    void Delete(node &t) { B.push(t); }
    node top()
    {
        while(A.size() && B.size() && A.top() == B.top()) A.pop() , B.pop();
        return A.top();
    }
}q;

int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }

int main()
{
    n = read();
    for(int i = 2 ; i <= n ; ++i) fp[i] = read();
    for(int i = 1 ; i <= n ; ++i) t[i].s[read()]++ , t[i].id = i , fa[i] = i;
    for(int i = 2 ; i <= n ; ++i) q.Insert(t[i]);
    LL ans = 0;
    for(int i = 2 ; i <= n ; ++i)
    {
        node v = q.top() , u = t[find(fp[v.id])];
        if(u.id != 1) q.Delete(u); q.Delete(v);
        ans += v.s[0] * u.s[1]; u = u + v; fa[v.id] = fa[u.id]; t[u.id] = u; t[v.id] = v;
        if(u.id != 1) q.Insert(u);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 30444
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
int a,b;
int main(){
	cin>>a>>b;
	for(int i=1;i<10000;i++){	
		if((int)(i*0.08)==a&&(int)(i*0.1)==b){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, a, b;
  in(n);
  vector<ll> c(n);
  rep(i, n)
    in(c[n - i - 1]);
  if(c[0] != 2){
    out(-1);
    memi;
    return 0;
  }
  a = 2;
  b = 3;
  rep2(i, 1, n){
    if((a - 1) / c[i] == b / c[i]){
      out(-1);
      memi;
      return 0;
    }
    a = ((a + c[i] - 1) / c[i]) * c[i];
    b = (b / c[i] + 1) * c[i] - 1;
  }
  out(a);
  hina;
  out(b);
  memi;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

int main(){

	int table[31],tmp;

	for(int i = 1; i <= 30; i++)table[i] = 0;

	for(int i = 0; i < 28; i++){
		scanf("%d",&tmp);
		table[tmp] = 1;
	}

	for(int i = 1; i <= 30; i++){
		if(table[i] == 0)printf("%d\n",i);
	}

    return 0;
}

Measured memory_bytes: 2716
#include<stdio.h>

int main(void)
{
	int a, b, c;
	int n;
	
	n = 0;
	
	scanf("%d %d %d", &a, &b, &c);
	
	while (a <= b) {
		if (c % a == 0) {
			n++;
		}
		
		a++;
	}
	
	printf("%d\n", n);
	
	return (0);
}

Measured memory_bytes: 596
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; } value
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int64_t ans = 0;
  REP(j,n) {
    if((j+1) % 3 != 0 && (j+1) % 5 != 0) {
      ans += j+1;
    }
  }
  cout << ans << endl;
}

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

const int INF = 1000000000;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    vector<vector<int>> C(M);
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        for (int j = 0; j < B[i]; j++) {
            int c;
            cin >> c;
            c--;
            C[i].push_back(c);
        }
    }

    vector<int> dp(4096, INF);
    dp[0] = 0;
    for (int i = 0; i < M; i++) {
        int now = 0;
        for (int j = 0; j < B[i]; j++) {
            now |= (1 << C[i][j]);
        }
        for (int bits = 0; bits < (1 << N); bits++) {
            dp[bits | now] = min(dp[bits | now], dp[bits] + A[i]);
        }
    }

    if (dp[(1 << N) - 1] == INF) {
        cout << -1 << endl;
    } else {
        cout << dp[(1 << N) - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 384