akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e+9 + 7;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main()
{
  ll n;
  cin >> n;
  ll ans = 0;
  rep(i, n + 1)
  {
    if (i % 3 != 0 && i % 5 != 0)
    {
      ans += i;
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3196
#include<iostream>

using namespace std;

int main(){
  int max,hoge=0,x;
  
  cin>>max>>x;
  for(int i=0;i<x;++i){
   int g;
    cin>>g;
    hoge+=g;
    
  }
  
  if(hoge<max){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }
  
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = pow(3, n);
    int odd = 1;
    rep(i, n) {
        if (a[i] % 2 == 0)
            odd *= 2;
    }
    cout << ans - odd << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int gcd(int a,int b){
  if(a<b) return gcd(b,a);
  if(b==0) return a;
  return gcd(b,a%b);
}
int main(){
  int n;
  scanf("%d",&n);
  int a,ans=0,i;  
  for(i=0;i<n;i++){
    scanf("%d",&a);
    ans=gcd(a,ans);    
  }
  printf("\n%d",ans);
}

Measured memory_bytes: 128
N, M = map(int,input().split())
foods = [0 for m in range(M)]
for n in range(N):
    A = list(map(int, input().split()))
    for a in A[1:]:
        foods[a-1]+=1
foods_ans = [f for f in foods if f == N]
#print(foods)
#print(foods_ans)
print(len(foods_ans))       


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

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

typedef struct{
    int A;
    int x[15];
    int y[15];
}DATA;

int process(DATA *data,int N,ULL type);
int Set(DATA *data, int *honest, bool *check,int pos);
int main(){
    int N;
    int A;
    int x,y;
    ULL i,j;
    DATA *data;
    int count=0;
    int ans;
    cin >> N;
    data = new DATA[N];
    for(i=0;i<N;i++){
        cin >> A;
        data[i].A = A;
        for(j=0;j<A;j++){
            cin >> x >> y;
            data[i].x[j] = x;
            data[i].y[j] = y;
        }
    }
    
    //cout << endl;
    ans = 0;
    for(i=0;i< ( 0x01 << ( N  ));i++){
        count = process(data,N,i);
        if( count > ans){
            ans = count;
        }
    }
    cout << ans << endl;
    return 0;
}

int process(DATA *data,int N,ULL type){
    int i,j;
    int *honest;
    bool *check; 
    int count;
    int temp;

    honest = new int[N];
    check = new bool[N];
    for(i=0;i<N;i++){
        honest[i] = -1;
        check[i] = false;
    }
    for(i=0;i<N;i++){
        if( ((type >> i) & 0x01) == 0x01){
            temp = Set(data,honest,check,i);
            if( temp == -1){
                return -1;
            }
        }
    }
    count = 0;
    for(i=0;i<N;i++){
        if( honest[i] == 1){
            count++;
        }
    }

    return count;
}
int Set(DATA *data, int *honest, bool *check,int pos){
    int i,j;
    int x;
    int y;
    int temp;
    if( honest[pos] == 0){
        return -1;
    }
    honest[pos] = 1;
    check[pos] = true;
    for(i=0;i < data[pos].A;i++){
        x = data[pos].x[i] -1 ;
        y = data[pos].y[i];
        if( honest[x] == -1){
            honest[x] = y;            
        }else if(honest[x] != y){
            return -1;
        }
    }
    for(i=0;i<data[pos].A;i++){
        if( check[data[pos].x[i]-1] == false && data[pos].y[i] == 1){
            temp = Set(data,honest,check,data[pos].x[i]-1);
            if( temp == -1){
                return -1;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3840
n, m = map(int, input().split())
*a, = map(int, input().split())

needs = [9,2,5,5,4,5,6,3,7,6]
table = [-1] * (n+10)
table[0] = 0

for i in range(n):
    if table[i] != -1:
        for j in a:
            table[i + needs[j]] = max(table[i]*10 + j, table[i + needs[j]])

print(table[n])

Measured memory_bytes: 50908
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x;
	cin>>n>>x;
	vector<int>v(n);
	for(int i=0;i<n;i++){
		int z;
		cin>>z;
		z=abs(z-x);
		v[i]=z;
	}
	int ans=v[0];
	for(int i=0;i<n;i++){
		ans=__gcd(ans,v[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	string en;
	cin>>en;
	for(int i=0;i<3;i++)for(int j=i+1;j<3;j++)if(en[i]!=en[j]){
		cout<<"Yes\n";
		return 0;
	}
	cout<<"No\n";
	
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <queue>

using namespace std;


const int INF = 2e9;


const int N = 2510, M = 5010;


struct edge
{
	int from, to, dis;
	edge() { }
	edge(int _1, int _2, int _3) : from(_1), to(_2), dis(_3) { }
} edges[M];

int head[N], nxt[M], tot;

inline void init()
{
	memset(head, -1, sizeof(head));
	tot = 0;
}

inline void add_edge(int x, int y, int z)
{
	edges[tot] = edge(x, y, z);
	nxt[tot] = head[x];
	head[x] = tot++;
}


int n, m;


int s[N];
int dist[N]; bool inq[N];

int SPFA()
{
	for (int i = 1; i <= n; i++)
		dist[i] = -INF;
	queue <int> q;
	q.push(1);
	dist[1] = 0;
	s[1]++;
	
	while (!q.empty())
	{
		int x = q.front(); q.pop();
		inq[x] = 0;
		for (int i = head[x]; ~i; i = nxt[i])
		{
			edge & e = edges[i];
			if (dist[e.to] < dist[x] + e.dis)
			{
				dist[e.to] = dist[x] + e.dis;
				if (!inq[e.to])
				{
					inq[e.to] = 1;
					s[e.to]++;
					if (s[n] > n) return -1;
					q.push(e.to);
				}
			}
		}
	}
	
	return dist[n] > -INF ? max(dist[n], 0) : -1;
}


int main()
{
	int p;
	scanf("%d %d %d", &n, &m, &p);
	
	init();
	
	for (int i = 1; i <= m; i++)
	{
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c); 
		add_edge(a, b, c-p);
	}
	
	printf("%d\n", SPFA());
	
	return 0;
}

Measured memory_bytes: 384
# 0以外は全部同じ 0だけ先頭につけることができない
N=int(input())
# 90通りある組み合わせを選ぶのだ
combination = [[0 for j in range(10)] for i in range(10)]
for i in range(1,N+1):
    s = str(i)
    start = int(s[0])
    end=int(s[-1])
    combination[start][end] += 1
count=0
for row in range(10):
    for column in range(10):
        count+=combination[row][column]*combination[column][row]

print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    string S;
    cin >> S;
    int N = S.size(), np = 0, ng = 0;
    char hand;
    int ans = 0;
    rep(i, N)
    {
        if (np >= ng)
        {
            ng++;
            hand = 'g';
            if (S[i] == 'p')
                ans--;
        }
        else if (S[i] == 'g')
        {
            np++;
            hand = 'p';
            ans++;
        }
        else if (S[i] == 'p')
        {
            np++;
            hand = 'p';
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		sc.close();

		for (int x = 0; x <= k; x++) {
			for (int y = 0; y <= k; y++) {
				for (int z = 0; z <= k; z++) {
					if (x + y + z <= k) {
						long ax = a * (1 << x);
						long by = b * (1 << y);
						long cz = c * (1 << z);
						if (ax < by && by < cz) {
							System.out.println("Yes");
							return;
						}
					}
				}
			}
		}
		System.out.println("No");
	}
}


Measured memory_bytes: 35664
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	char a, b, c; cin >> a >> b >> c;
	cout << (a != b && b != c && a != c ? "Yes": "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000000 + 7;
long long fac(long long n) {
    long long res = 1;
    for (long long i = 2; i <= n; i++) {
        res *= i;
        res %= mod;
    }
    return res;
}

long long binpow(long long k, long long n) {
    if(k == 0 || n == 1)
        return 1;
    if (k % 2) {
        return (n * binpow(k -1 , n)) % mod;
    } else {
        long long b = binpow(k / 2, n);
        return (b * b) % mod;
    }
}

void nextPermutation(vector<int>& a){ // n — длина перестановки
    int n = a.size();
    for (int i = n - 2; i >= 0; i--) {
        if (a[i] < a[i + 1]) {
            int mn = i + 1;
            for (int j = i + 1; j <= n - 1; j++)
                if (a[j] < a[mn] && a[j] > a[i])
                    mn = j;
            swap(a[i], a[mn]);
//            cout << i << " " << mn << endl;
            reverse(a.begin() + i + 1, a.end());
            return;
        }
    }
}

double sqr(double v) {
    return v * v;
}

int main() {
    long long x, y;
    cin >> x >> y;
    if ((x + y) % 3 !=0) {
        cout << 0;
        return  0;
    }
    long long n= (x + y) / 3;
    if (x < n || y < n) {
        cout << 0;
        return 0;
    }
    if (x == n || y == n) {
        cout << 1;
        return 0;
    }
    long long k = min(x, y) - n;
    long long ans = fac(n);
    ans *= binpow(mod - 2, fac(k));
    ans %= mod;
    ans *= binpow(mod -2, fac(n- k));
    ans %= mod;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=3e5+10;
set<int>s;
void dfs(int n)
{
	if(n>1e10)
		return;
	s.insert(n);
	int k=n%10;
	if(k==0)
	{
		dfs(n*10+0);
		dfs(n*10+1);
	}
	else if(k<=8)
	{
		dfs(n*10+k-1);
		dfs(n*10+k);
		dfs(n*10+k+1);
	}
	else
	{
		dfs(n*10+k-1);
		dfs(n*10+k);
	}

}
int32_t main()
{
	int k;
	cin>>k;
	for(int i=1;i<=9;i++)
	{
		dfs(i);
	}
	int cnt=0;
	for(auto it:s)
	{
		cnt++;
		if(cnt==k)
		{
			cout<<it<<endl;
			return 0;
		}
	}



}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

//main code

int main(int argc, char const* argv[])
{
	LL n;
	cin >> n;
	VL a(n);
	VL b(n);
	cin >> a;
	b = a;
	sort(RALL(b));
	for (int i = 0; i < n; i++) {
		if (a[i] == b[0]) {
			cout << b[1] << endl;
			continue;
		}
		cout << b[0] << endl;
	}
	return 0;
}


Measured memory_bytes: 4736
import Base.parse
import Base.StringVector

parse(::Type{String},  str::AbstractString) = str

isdelim(x::UInt8, xs::Set{UInt8}) = x in xs

function myreaduntil(s::IO, delims::Set{UInt8})::Vector{UInt8}
    out = StringVector(0)
    c::UInt8 = 0x00
    while !eof(s)
        c = read(s, UInt8)
        if !isdelim(c, delims)
            break
        end
    end
    push!(out, c)
    if eof(s)
        return out
    end
    while !eof(s)
        c = read(s, UInt8)
        if isdelim(c, delims)
            break
        end
        push!(out, c)
    end
    return out
end

delimset = Set([0x0a, 0x20])

function readword(io::IO = stdin, delims = delimset)::String
    word = myreaduntil(io, delims)
    i = length(word)
    if i == 0 || word[i] != 0x0a
        return String(word)
    elseif i < 2 || word[i-1] != 0x0d
        return String(resize!(word,i-1))
    else
        return String(resize!(word,i-2))
    end
end

pread(ty) = parse(ty, readword())

reads(tys...)::Tuple{tys...} = Tuple{tys...}(pread(ty) for ty in tys)

readvec(tys::Tuple , len::Signed)::Vector{Tuple{tys...}} = @inbounds Tuple{tys...}[reads(tys...) for i in 1:len]

readvec(ty::Type, len::Signed)::Vector{ty} = @inbounds ty[pread(ty) for i in 1:len]

function readmat(ty::Type, s...)::Matrix{ty}
    v = Matrix{ty}(undef, s...)
    @inbounds for i = 1:s[1]
        v[i,:] = readvec(ty, s[2])
    end
    v
end

function main()
    N,K = reads(Int, Int)
    v = readvec(Int, N)
    checked = zeros(Int, N)
    np = 1
    lp = 0
    fi = 0
    sa = 0
    for i in 0:K
        if i == K
            println(np)
            return
        end
        if checked[np] != 0
            sa = i - checked[np]
            lp = np
            fi = i
            break
        end
        checked[np] = i
        np = v[np]
    end
    np = lp
    for i in 1:(K-fi)%sa
        np = v[np]
    end
    println(np)
end

main()


Measured memory_bytes: 211372
#include <cstdio>

void to_time(int* h, int* m, int* s, const int sec) {
  *h = sec / 3600;
  *m = (sec % 3600) / 60;
  *s = sec % 60;
}

int main() {
  int h, m, s, S = 0;
  scanf("%d", &S);
  to_time(&h, &m, &s, S);
  printf("%d:%d:%d\n", h, m, s);
  return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define _ 				ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int32_t main(){	
	_;

	int n;
	cin >> n;
	int ans=0;
	int x = n;

	while(x >= 500){
		ans+=(1000*(x/500));
		x = x%500;
	}

	while( x >= 5){
		ans += (5 * (x/5));
		x = x%5;
	}

	cout << ans << '\n';
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 998244353LL
#define MOD2 996491788296388609LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}

template<int N, typename T, T M>
struct ModFact {
    T fact[N+1];
    T ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        fact[0] = 1;
        for (int i=0; i<N; ++i)
            fact[i+1] = (fact[i]*(i+1))%M;
        ifact[N] = power(fact[N], M-2);
        for (int i=N-1; i >= 0; --i)
            ifact[i] = (ifact[i+1]*(i+1))%M;
    }
    constexpr T power(T a, T b) {
        T r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
    constexpr T comb(T n, T r) {
        return (((fact[n]*ifact[r])%M)*ifact[n-r])%M;
    }
};
 
ModFact<300000, ll, MOD> fact;

int main() {
    fastio();
    ll N, A, B, K, ans = 0;
	cin >> N >> A >> B >> K;
    ll g = gcd(A, B);
    if(K%g==0) {
        ll s, ca=B/g, cb=A/g;
        ll oa=min(N, K/A), ob=min(N, K/B);
        int i=0, j=ob;
        while(i<=oa) {
            while (i*A+j*B>K) j--;
            if (i*A+j*B==K) break;
            i++;
        }
        while(i<=oa && j>=0) {
            ans += fact.comb(N,i)*fact.comb(N,j);
            if(ans >= MOD2) ans -= MOD2;
            i += ca; j -= cb;
        }
    }
    cout << ans%MOD << "\n";
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
  	public static int max = 1000000007;
	public static void main(String args[]) throws IOException{
      Scanner sc = new Scanner(System.in);
      int r = sc.nextInt();
      int c = sc.nextInt();
      char grid[][] = new char[r][c];
      
      for(int i=0;i<r;i++){
        String row = sc.next();
        for(int j=0;j<c; j++){
          grid[i][j] = row.charAt(j);
        }
      }
    
      
      System.out.println(countPath(grid,  r,  c));
      
      /*
      String dp[][] =  new String[n.length()][m.length()];
      System.out.println(sub(n, m , 0, 0, dp));
      */
    }
  
  public static int countPath(char grid[][], int r, int c){
    int dp[][] = new int[r][c];
    dp[r-1][c-1] = 1;
      for(int i=r-2; i>=0; i--)
        dp[i][c-1] = grid[i][c-1]=='.' && dp[i+1][c-1] == 1 ? 1 : 0;
    
      for(int j=c-2; j>=0; j--)
        dp[r-1][j] = grid[r-1][j]=='.' && dp[r-1][j+1] == 1 ? 1 : 0;
    
     for(int i=r-2; i>=0; i--){
       for(int j=c-2; j>=0; j--){
       		if(grid[i][j] == '#') {
               dp[i][j] = 0;
              continue;
            }
         dp[i][j] = (dp[i+1][j] % max + dp[i][j+1]%max)%max;
       }
     }
    
    
      return dp[0][0];
  }
   
}


Measured memory_bytes: 41148
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

bool check[100];
typedef pair<int,int> P;
bool comp(const P x, const P y){
  return x.second>y.second;
}
int main(){
  int n;
  cin>>n;
  vector<P> r(n),b(n);
  for(int i=0;i<n;i++){
    cin>>r[i].first>>r[i].second;
  }

  for(int i=0;i<n;i++){
    cin>>b[i].first>>b[i].second;
  }
  sort(b.begin(),b.end());
  sort(r.begin(),r.end(),comp);
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if((b[i].first>r[j].first) && (b[i].second>r[j].second) && !check[j]){
        ans++;
        check[j]=true;
        break;
      }
    }
  }

  cout<<ans<<"\n";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }


int main(){
  int n;
  int ans = 0;
  cin >> n;
  if(n % 2 == 0)ans = n;
  else ans = n * 2;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()

ll a[100][100], b[100][100], s;

int main() {
	int n, m, l;
	cin >> n >> m >> l;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			cin >> a[i][j];
	for (int i = 0; i < m; ++i)
		for (int j = 0; j < l; ++j)
			cin >> b[i][j];
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < l; ++j) {
			s = 0;
			for (int k = 0; k < m; ++k) {
				s += a[i][k] * b[k][j];
			}
			cout << s;
			if (j < l - 1)
				cout << " ";
		}
		cout << endl;
	}

	return 0;
}


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

int main()
{
	int n, l[100];
	cin >> n;
	for (int i=0; i < n; i++)
	{
		cin >> l[i];
	}

	int max = 0;
	int sum = 0;

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


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

int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  int t=pow(2,K);
  cout << max(A+B+C*t,max(A+B*t+C,A*t+B+C)) << endl;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[129]={0,1,1,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
int x;
int main()
{
	cin>>x;
	for(int i=x;i>=1;i--)
	if(a[i]==1){cout<<i<<endl;break;
	}
	return 0;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 100;
const ll W = 1e5;
ll n, w;

ll weights[N];
ll vs[N];

// considering items up to i, w weight so far = max value
ll dp[N][W + 1];


int main() {
    cin >> n >> w;
    for (ll i = 0; i < n; i++) {
        cin >> weights[i] >> vs[i];
    }
    for (ll i = 1; i <= w; i++) {
        dp[0][i] = i >= weights[0] ? vs[0] : 0;
        //cout << "dp[0][" << i << "] = " << dp[0][i] << "\n";
    }
    for (ll i = 1; i < n; i++) {
        for (ll ww = 1; ww <= w; ww++) {
            // VALUE for
            ll leave = dp[i - 1][ww];
            ll take =
                weights[i] > ww
                    /* ei voi ottaa */
                    ? leave
                    /* voi ottaa */
                    : dp[i - 1][ww - weights[i]] + vs[i];
            // => max
            dp[i][ww] = max(take, leave);
            //cout << "dp[" << i << "][" << ww << "] = " << dp[i][ww] << "\n";
        }
    }
    ll ans = 0;
    for (ll ww = 1; ww <= w; ww++) {
        ans = max(ans, dp[n - 1][ww]);
    }
    cout << ans << endl;
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M; cin >> N >> M;
    int sx[N], sy[N], px[M], py[M];
    rep(i, N) cin >> sx[i] >> sy[i];
    rep(i, M) cin >> px[i] >> py[i];
    rep(i, N){
        int res = 0;
        int dist = mod;
        rep(j, M){
            int eval = abs(sx[i]-px[j]) + abs(sy[i]-py[j]);
            if(eval < dist){
                res = j+1;
                dist = eval;
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,v,q,x,y;
  cin>>n;
  deque<int>vec;
  for(int i=0;i<n;i++)
  {
    cin>>q;
    if(q==0)
    {
      cin>>x>>y;
      if(x==0)
      {
        vec.push_front(y);
      }
      else
      {
        vec.push_back(y);
      }
    }
    else if(q==1)
    {
      cin>>x;
      cout<<vec[x]<<endl;
    }
    else
    {
      cin>>x;
      if(x==0)
      {
        vec.pop_front();
      }
      else
      {
        vec.pop_back();
      }
    }
  }
  return 0;
}



Measured memory_bytes: 4672
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        for (int i = 1; i <= s.length(); i++) {
            if (i % 2 == 1) {
                System.out.print(s.charAt(i - 1));
            }
        }
        System.out.println();
    }
}


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

using namespace std;

const int MAXN = 110;

bool cmp (int x, int y) {
    return x > y;
}

int n, wm, w0, w[MAXN], v[MAXN];
long long sum1, sum[5][MAXN], maxval;

vector <int> val[5];


int main () {
    scanf ("%d %d", &n, &wm);
    scanf ("%d %d", &w[0], &v[0]);
    for (int i = 1; i < n; i++) {
        scanf ("%d %d", &w[i], &v[i]);
        w[i] -= w[0];
        val[w[i]].push_back(v[i]);
    }
    w0 = w[0];
    w[0] = 0;
    val[w[0]].push_back(v[0]);
    for (int i = 0; i < 4; i++) {
        sort(val[i].begin(), val[i].end(), cmp);
    }
    for (int i = 0; i < 4; i++) {
        //if (val[i].size() > 0) sum[i][0] = val[i][0];
        for (int j = 1; j <= (int) val[i].size(); j++) {
            sum[i][j] = sum[i][j-1] + val[i][j-1];
        }
    }
    for (int i = 0; i <= (int) val[0].size() && i * w0 <= wm; i++) {
        for (int j = 0; j <= (int) val[1].size() && j + i * w0 + j * w0 <= wm; j++) {
            for (int k = 0; k <= (int) val[2].size() && j + 2 * k + i * w0 + j * w0 + k * w0 <= wm; k++) {
                long long s = j + 2 * k + i * w0 + j * w0 + k * w0;
                int l = min((int) (wm - s) / (3 + w0), (int) val[3].size());
                maxval = max(maxval, (long long) sum[0][i] + sum[1][j] + sum[2][k] + sum[3][l]);
            }
        }
    }
    cout << maxval;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  vector<ll> v(N*3);
  rep(i,N*3){
    cin >> v[i];
  }
  sort(ALLOF(v));
  reverse(ALLOF(v));
  ll ret = 0;
  int idx=0;
  rep(i,N){
    ret += v[idx+1];
    idx += 2;
  }
  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main() {
  char c;
  cin >> c;
  if (c == 'A') {
    cout << 'T' << endl;
  }
  else if (c == 'T') {
    cout << 'A' << endl;
  }
  else if (c == 'C') {
    cout << 'G' << endl;
  }
  else if (c == 'G') {
    cout << 'C' << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7;

template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (int i = 0; i < v.size(); ++i)
    {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < v.size() - 1; ++i)
    {
        os << v[i] << " ";
    }
    if (v.size() > 0)
    {
        os << v[v.size() - 1] << endl;
    }
    return os;
}


int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    FOR(i,1, n)
    {
        if (i > n - i)
        {
            break;
        }
        if (i != n - i)
        {
            ++ans;
        }
    }
    cout << ans << endl;
}

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

const double pi = atan(1.0) * 4;

int main() {
  double a, b, x;
  cin >> a >> b >> x;

  double area_b = a * b;
  double area_w = x / a;

  double area = 0;
  double h = 0;

  if (area_b / 2 >= area_w) {
    double d = a / 1000000;
    while (area < area_w) {
      area = b * h / 2;
      h += d;
    }
    d /= 10000;
    while (area > area_w) {
      area = b * h / 2;
      h -= d;
    }
    printf("%.9f\n", atan(b / h) / pi * 180);
  } else {
    double d = b / 1000000;
    while (area < area_b - area_w) {
      area = a * h / 2;
      h += d;
    }
    d /= 10000;
    while (area > area_b - area_w) {
      area = a * h / 2;
      h -= d;
    }
    printf("%.9f\n", atan(h / a) / pi * 180);
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	
	int a2 = 0, b2 = 0;
	for(int i = 0; i < b; i++)
		a2 = a2 * 10 + a;
	for(int i = 0; i < a; i++)
		b2 = b2 * 10 + b;
	
	if(a < b)
		cout << a2;
	else
		cout << b2;
}


Measured memory_bytes: 256
def dfs(i, f):
  if i == n-1:
    return sum(list(map(int, f.split('+'))))
  
  return dfs(i+1, f+s[i+1]) + dfs(i+1, f+'+'+s[i+1])

s = input()
n = len(s)

print(dfs(0, s[0]))

Measured memory_bytes: 9000
#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++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

int main() {
    int w, h; cin >> w >> h;
    vector<pair<int,int>> pq(w + h);
    REP(i, w) {
        cin >> pq[i].first;
        pq[i].second = 0;
    }
    REP(i, h) {
        cin >> pq[i+w].first;
        pq[i + w].second = 1;
    }
    ll ans = 0;
    sort(pq.begin(), pq.end());
    ll rest_w = w + 1, rest_h = h + 1;
    REP(i, w + h) {
        if (pq[i].second == 0) {
            ans += rest_h * pq[i].first;
            rest_w--;
        }
        else {
            ans += rest_w * pq[i].first;
            rest_h--;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    REP(i,k){
        int x, y;
        cin >> x >> y;
        x = min(x,n-x+1);
        y = min(y,n-y+1);
        cout << min(x-1,y-1)%3+1 << endl;
    }
    return 0;
}   



Measured memory_bytes: 3100
n = int(input())
x = []
y = []
for _ in range(n):
    li = list(map(int, input().split()))
    x.append(li[0])
    y.append(li[1])
line = []
for i in range(n):
    for j in range(i+1, n):
        line.append(((x[i]-x[j])**2 + (y[i]-y[j])**2)**0.5)
ans = sum(line) * 2 / n
print(ans)

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

using namespace std;

int N, M;
char S[100000], T[100000];

int main() {
  scanf("%d%d", &N, &M);
  scanf("%s%s", S, T);
  
  int g = __gcd(N, M);
  int stepS = N / g;
  int stepT = M / g;
  for (int i = 0; i < g; ++i) {
    if (S[stepS * i] != T[stepT * i]) {
      puts("-1");
      return 0;
    }
  }
  printf("%lld", 1ll * N / g * M);
  return 0;
}

Measured memory_bytes: 384
def cross(z1, z2):
    return z1.real * z2.imag - z1.imag * z2.real

def ccw(p1, p2, p3):
    return cross(p2 - p1, p3 - p1) > 0

def triangle_area(p1, p2, p3):
    # returns signed trangle area
    return cross(p2 - p1, p3 - p1) / 2

from sys import stdin
file_input = stdin

N = int(file_input.readline())
P = []
M = {}

for i in range(1, N + 1):
    x, y = map(int, file_input.readline().split())
    z = x + y * 1j
    P.append(z)
    M[z] = i # point to id

Q = int(file_input.readline())
query = [int(file_input.readline()) for i in range(Q)]
ql = max(query) - 2

P.sort(key=lambda x: (x.imag, x.real))

max_area = 20000 * 20000
CP_area = [max_area for i in range(ql)]
CP_points = [None for i in range(ql)]

from cmath import phase
from itertools import combinations

for i, bp in enumerate(P[:-2], start=1):
    tP = P[i:]
    tP.sort(key=lambda x: phase(x - bp))
    pn = N - i
    
    tM = dict(zip(range(pn), tP)) # id to point
    
    # making triangles
    t_rec = [[None for k in range(pn)] for j in range(pn)]
    for j, k in combinations(range(pn), 2):
        pj, pk = tM[j], tM[k]
        ta = triangle_area(bp, pj, pk)
        t_rec[j][k] = [ta, [bp, pj, pk]]
        if ta < CP_area[0]:
            CP_area[0] = ta
            CP_points[0] = [bp, pj, pk]
    
    # making convex polygons
    prev = t_rec.copy()
    cur = [[None for k in range(pn)] for j in range(pn)]
    for i in range(1, ql):
        for j, k, s in combinations(range(pn), 3):
            pre_cp = prev[j][k]
            if pre_cp:
                pj, pk, ps = tM[j], tM[k], tM[s]
                if ccw(pj, pk, ps):
                    ta = pre_cp[0] + t_rec[k][s][0]
                    if not cur[k][s] or cur[k][s][0] > ta:
                        cur[k][s] = [ta, pre_cp[1] + [tM[s]]]
                        if ta < CP_area[i]:
                            CP_area[i] = ta
                            CP_points[i] = cur[k][s][1]
        
        prev = cur.copy()
        cur = [[None for k in range(pn)] for j in range(pn)]

# output
for q in query:
    if CP_points[q-3]:
        print(' '.join(map(lambda x: str(M[x]), CP_points[q-3])))
    else:
        print("NA")


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

int N;
const int MAX_N = 1.0e5 + 100;
map<int, int> mp;

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        int a_in;
        cin >> a_in;
        mp[a_in - 1]++;
        mp[a_in]++;
        mp[a_in + 1]++;
    }

    int ans = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        int val = itr->second;

        ans = max(ans, val);
    }

    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 4736
public class Hello{
    public static void Main(){
        // Your code here!
        var line=int.Parse(System.Console.ReadLine());
        int ok=0;
        int result=0;
        while(ok==0)
        {
            if(result<line)
            {
                result=result+1000;
            }else
            {
                ok=1;
            }
        }
        System.Console.WriteLine(result-line);
    }
}


Measured memory_bytes: 27480
#include<iostream>
#include<vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp make_pair
#define pin pair<int,int>
pin solve(V<pin>& ab, int ex) {
	if (!ex) { return mkp(0, 0); }
	V<V<pin>> qab(2);
	int sz = ab.size();
	qab[0].reserve(sz);
	qab[1].reserve(sz);
	for (pin& x : ab) {
		qab[x.second & 1].push_back(mkp(x.first / 2, x.second / 2));
		if (x.first & 1) { qab[(x.second + 1) & 1].push_back(mkp(x.first / 2, (x.second + 1) / 2)); }
	}
	int c = 0;
	for (pin& x : qab[0]) {
		int qc = (2 * x.first + x.second) % 3;
		c ^= (qc + 1);
	}
	if (!c) {
		pin ans = solve(qab[1], ex - 1);
		ans.first *= 2; ans.second *= 2; ans.second++;
		return ans;
	}
	pin ans = solve(qab[0], ex - 1);
  	c=0;
  	for (pin& x : qab[1]) {
		int qc = (2 * x.first + x.second) % 3;
		c ^= (qc + 1);
	}
  	if (!c) {
		ans.first *= 2; ans.second *= 2;
		return ans;
	}
	c = 0;
	for (pin& x : qab[1]) {
		int w = ans.second - x.second-1;
		if ((w & x.first) == w) { c ^= 1; }
	}
	ans.first *= 2; ans.first++; ans.second *= 2; ans.second -= c;
	return ans;
}
signed main() {
	cin.tie(0); ios::sync_with_stdio(false);
	long long inf = 1e17;
	int n; cin >> n;
	V<pin> ab(n);
	rep(i, n) {
		long long a, b; cin >> a >> b;
		ab[i] = { a + inf,b + inf };
	}
	pin ret = solve(ab, 59);
	cout << ret.first - inf << " " << ret.second - inf << "\n";
}


Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;

ll d[100010];
ll rd[100010];
ll Ep(int x, int y){
  if(y==1) return x;
  ll r = Ep(x,y/2);
  if(y%2==1) return r *r%MOD *x%MOD;
  else return r *r%MOD;
}
ll Ftl(ll x){
  if(x == 1 || x == 0) return 1;
  if(d[x] != 0) return d[x];
  return d[x] = Ftl(x-1) *x%MOD;
}
ll rFtl(ll x){
  if(x == 1 || x == 0) return 1;
  if(rd[x] != 0) return rd[x];
  return rd[x] = rFtl(x-1)*Ep(x,MOD-2)%MOD;
}
ll comb(ll m, ll n){
  if(m < n) return 0;
  return Ftl(m) *rFtl(n)%MOD *rFtl(m-n)%MOD;
}

int main(){
  int n, k;
  cin >> n >> k;
  if(k == 1){
    cout << 0 << endl;
    return 0;
  }
  
  vector<int> an(n);
  vector<ll> sm(n);
  for(int i=0; i<n; ++i) cin >> an[i];
  sort(an.begin(),an.end());
  for(int i=0; i<n; ++i){
    if(i==0) sm[i] = an[i];
    else sm[i] = sm[i-1] + an[i];
  }
  
  ll ans = 0;
  for(int i=0; i<n-1; ++i){
    ll kei = (sm[n-1]-sm[n-2-i]) - sm[i];
    kei %= MOD;
    ans += kei * comb(n-2-i,k-2);
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for(int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if(k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

string n;
combination c(100);

ll f(int i, int k, bool smaller) {
  if(k == 0) return 1;
  if(i == n.size()) return 0;
  if(smaller) return c(n.size() - i, k).x * pow(9, k);
  if(n[i] == '0') return f(i + 1, k, false);
  return f(i + 1, k, true) + (n[i] - '1') * f(i + 1, k - 1, true) +
         f(i + 1, k - 1, false);
}

int main() {
  int k;
  cin >> n >> k;
  // cout << f(0, k, false) << endl;
  int N = n.size();
  reverse(all(n));
  ll dp[N + 1][k + 1][2] = {};
  dp[0][0][0] = dp[0][0][1] = 1;
  rep(i, N) rep(j, k + 1) rep(m, 2) {
    if(j == 0)
      dp[i + 1][j][m] = 1;
    else if(m == 1)
      dp[i + 1][j][m] = c(i + 1, j).x * pow(9, j);
    else if(n[i] == '0')
      dp[i + 1][j][m] = dp[i][j][0];
    else
      dp[i + 1][j][m] =
          dp[i][j][1] + dp[i][j - 1][1] * (n[i] - '1') + dp[i][j - 1][0];
    // printf("dp[%d][%d][%d]=%d\n", i + 1, j, m, dp[i + 1][j][m]);
  }
  cout << dp[N][k][0] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
typedef long long ll;
#define out(i) cout<<(i)<<endl

int main() {
  ll N,K,cnt=0;
  cin>>N>>K;
  for(ll k=K;k<=N+1;k++){cnt+=(N*(N+1))/2-((N-k)*(N-k+1))/2-(k*(k-1))/2+1;}
  cout<<cnt%(1000000000+7)<<endl;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String string = sc.next();
		int con = 0;
		int max = 0;

		for (int i = 0; i < string.length(); i++) {
			if (string.charAt(i) == 'R') {
				con++;
				if (max <con) {
					max = con;
				}
			}else {
				con = 0;
			}
		}
		System.out.println(max);

	}
}

Measured memory_bytes: 35652
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int h=sc.nextInt();
        int w=sc.nextInt();
        char[][] f=new char[h][w];
        for (int i = 0; i < h; i++) {
            String t=sc.next();
            for (int j = 0; j < w; j++) {
                f[i][j]=t.charAt(j);
            }
        }
        long ans=0;
        int[] dx={-1,0,1,0};
        int[] dy={0,-1,0,1};
        int[][] node=new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if(node[i][j]==0) {
                    Queue<Point> q = new ArrayDeque<>();
                    q.add(new Point(i, j));
                    node[i][j]++;
            //    out.println("s:" + q.peek());
                    long tempW = 0, tempB = 0;
                    while (!q.isEmpty()) {
                        Point p = q.poll();
                     //   out.println(p);
                        if (f[p.x][p.y] == '.') tempW++;
                        else tempB++;
                        for (int k = 0; k < 4; k++) {
                            int x = p.x + dx[k];
                            int y = p.y + dy[k];
                            if (0 <= x && x < h && 0 <= y && y < w) {
                                if (node[x][y] == 0 && f[p.x][p.y] != f[x][y]) {
                                    q.add(new Point(x, y));
                                    node[x][y]++;
                                }
                            }
                        }
                    }
                 //   out.println("GraphSize=" + (tempB + tempW));
                 //   out.println("fin");
                    ans += tempB * tempW;
                }
            }
        }
        out.println(ans);
/*
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                out.print(node[i][j]);
            }
            out.println();
        }*/

    }
}

Measured memory_bytes: 42328
import sys
from itertools import accumulate


def main():
    n, *A = map(int, sys.stdin.read().split())
    minA = min(A) - 1
    lr = [[i - 1 - minA, i + 1 - minA] for i in A]
    lst = [0] * (max(A) - minA + 3)
    for i, j in lr:
        lst[i] += 1
        lst[j + 1] -= 1
    lst = list(accumulate(lst))
    print(max(lst))


if __name__ == '__main__':
    main()

Measured memory_bytes: 25572
#include <stdio.h>

#define Max 36

typedef struct{
  char m;
  int v;
}Trump;

int main(){
  
  int n, i, j, flag, min;
  Trump x[Max], y[Max], temp ;


  scanf("%d",&n);


  for(i = 0 ; i < n ; i++){
    //scanf("%c%d",&x[i].m, &x[i].v);
    scanf("%c%c%d",&x[i].m, &x[i].m, &x[i].v);
    y[i] = x[i];
  }
  

 

  for(i = 0 ; i < n ; i++)
    for(j = n-1 ; j >= i+1 ; j--)
      if(x[j].v < x[j-1].v){
	temp = x[j];
	x[j] = x[j-1];
	x[j-1] = temp;
      }
  


  for(i = 0 ; i < n ; i++){
    min = i;
    for(j = i ; j < n ;j++)
      if(y[j].v < y[min].v)
	min = j;
    temp = y[i];
    y[i] = y[min];
    y[min] = temp;     
  }




  for( i = 0 ; i < n-1 ; i++){
    printf("%c%d ",x[i].m, x[i].v);
  }
  printf("%c%d\n",x[n-1].m, x[n-1].v);
  printf("Stable\n");
 
  for( i = 0 ; i < n-1 ; i++){
    printf("%c%d ",y[i].m, y[i].v);
  }
  printf("%c%d\n",y[n-1].m, y[n-1].v);


  flag = 1;


  for(i = 0 ; i < n ; i++)
    if(x[i].m != y[i].m)
      flag = 0;


  if(flag == 1)
    printf("Stable\n");
  else 
    printf("Not stable\n");
 

  return 0;
}

Measured memory_bytes: 608