akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


void solve(){
    ll n;
    cin>>n;
    ll ans=0;
    REP(i,n){
        REP(j,n){
            REP(k,n){
                ans+=gcd(i+1,gcd(j+1,k+1));
            }
        }
    }
    cout<<ans<<en;
}

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

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
int main(void){
    int n,m;
    cin>>n>>m;
    long long ans=(n-m)*100+m*1900;
    for(int i=0;i<m;i++)ans*=2;
    cout<<ans<<endl;
    
}


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

using namespace std;

long long A[200005];

int main(){
	long long N, K;
	scanf("%lld %lld", &N, &K);
	for (int i = 0; i < N; i++){
		scanf("%lld", A + i);
	}
	sort(A, A + N);
	long long ans = 0;
	for (int i = N - K - 1; i >= 0; i--) {
		ans += A[i];
	}
	printf("%lld\n", ans);
}

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

using namespace std;

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

    int N;
    cin >> N;
    vector<double> v(N);
    for (int i = 0; i < N; ++i) cin >> v[i];
    sort(v.begin(), v.end());
    double init_value = (v[0] + v[1]) / 2;
    for (int i = 2; i < N; ++i) init_value = (init_value + v[i]) / 2;
    cout << fixed << setprecision(10) << init_value << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main (){
int i,p=0,q=0;
	cin>>i;
	while(i--){
	string X,Y;
		cin>>X>>Y;
		if(X>Y)p+=3;
		if(X<Y)q+=3;
		if(X==Y){q++;p++;}
		
	}
	cout<< p <<" "<< q << endl;
return 0;
}

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int N;
    cin >> N;
    tuple<int, int, int> hxy[N];
    for(int i = 0; i < N; i++) {
        int x, y, h;
        cin >> x >> y >> h;
        hxy[i] = make_tuple(h, x, y);
    }
    sort(hxy, hxy + N, greater<tuple<int, int, int>>());
    for(int cx = 0; cx <= 100; cx++) {
        for(int cy = 0; cy <= 100; cy++) {
            int h0, x0, y0;
            tie(h0, x0, y0) = hxy[0];
            int H = h0 + abs(x0 - cx) + abs(y0 - cy);
            bool isok = true;
            for(int i = 1; i < N; i++) {
                int h, x, y;
                tie(h, x, y) = hxy[i];
                isok &= h == max(H - abs(x - cx) - abs(y - cy), 0);
            }
            if(isok) {
                cout << cx << " " << cy << " " << H << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
#define MAX_N 100000

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N, K, c[MAX_N+1];

int main(){
  while(scanf("%d%d", &N, &K) && N+K){
    memset(c, 0, sizeof(c));
    int card;
    rep(i, K){
      scanf("%d", &card);
      c[card] = 1;
    }
    int f = c[0], res = 0;
    if(f){
      int  start = 0, n = 1, zero = 0;
      REP(i, 1, N+1){
	if(c[i] == 0){ n = i+1; zero = i; break;}
      }
      while(n <= N+1){
	if(c[n]){
	  n++;
	}else{
	  res = max(res, n - start - 1);
	  start = zero;
	  zero = n;
	  n++;
	}
      }
    }else{
      int count = 0;
      rep(i, N+1){
	if(c[i]) res = max(res, ++count);
	else count = 0;
      }
      res = max(res, count);
    }
    printf("%d\n", res);
  }
  return 0;
}

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

using namespace std;



int main()
{
    int m , n;
    int mod = 1e9 + 7;
    cin>>m>>n;
    
    int dp[m][n];
    memset(dp , 0 , sizeof(dp));
    
    char g[m][n];
    
    for(int i =0 ; i < m ; i++)
        for(int j = 0 ;  j < n ; j++)
            cin>>g[i][j];
    
    
    dp[m-1][n-1] = (g[m-1][n-1] == '#' ? 0 : 1);
    
    for(int i = m - 1; i >= 0 ; i--){
        for(int j = n - 1 ; j >= 0 ; j--){
            if(g[i][j] == '#'){
                dp[i][j] = 0;
                continue;
            }
            
            if(i == m-1 && j == n-1)
                continue;
            
            dp[i][j] = ((i+1 < m ? dp[i+1][j] : 0)%mod + (j+1 < n ? dp[i][j+1] : 0)%mod)%mod;
            
        }
    }
    
    cout<<dp[0][0]<<endl;
    return 0;
    
}

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

using namespace std;

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

    long out(0);
    for (int i = 1; i < N; ++i)
        for (int j = 0; j < i; ++j)
            out = max(out, abs(A[i] - A[j]));

    cout << out << endl;
}


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

int suretu(int x, int y, int z, int w);

int main() {
	int N1, N2, N3, N4;
	cin >> N1 >> N2 >> N3 >> N4;

	suretu(N1, N2, N3, N4);

	return 0;
}

int suretu(int x, int y, int z, int w) {
	int sum[4] = { x, y, z, w };
	int ans[4] = { 0 };

	int j;	int a = 0;
	for (j = 0; j < 4; j++) {
		if (sum[j] == 1) {
			ans[0] = sum[j];
			sum[j] = 0;
			a += 1;
			break;
		}
	}
	for (j = 0; j < 4; j++) {
		if (sum[j] == 9) {
			ans[1] = sum[j];
			sum[j] = 0;
			a += 1;
			break;
		}
	}
	for (j = 0; j < 4; j++) {
		if (sum[j] == 7) {
			ans[2] = sum[j];
			sum[j] = 0;
			a += 1;
			break;
		}
	}
	for (j = 0; j < 4; j++) {
		if (sum[j] == 4) {
			ans[3] = sum[j];
			sum[j] = 0;
			a += 1;
			break;
		}
	}
	if (a == 4) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl//1次元配列の出力
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl//二次元配列の出力
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
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; }
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl kai(intl k){//k!を求める関数
    intl a = 1;
    for(int i = 2; i <= k; i++){ a *= i; }
    return a;
}
intl digit10(intl a){//aを10進数で表したときの桁数を求める関数
    intl b = 0;
    do{ a /= 10; b++; }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    intl m[n + 2];
    m0(m);
    repi(i,1,n+1){
        for(intl j = i; j <= n; j += i){
            m[j]++;
            //debug(m[j]);
        }
    }
    intl ans = 0;
    repi(i,1,n + 1){
        ans += (m[i] * i);
        //debug(ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 81704
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstring>

using namespace std;

typedef long long LL;
const int N = 100000 + 5;

int n;
int a[N];
int dp[N];
int b[N];
vector<int> adj[N];

int cmp(int a, int b)
{
    return ::a[a] < ::a[b];
}

void solve()
{
    cin >> n;
    for(int i = 0; i < n; ++ i) {
        scanf("%d", a + i);
        b[i] = i;
    }
    for(int i = 1; i < n; ++ i) {
        int u, v;
        scanf("%d%d", &u, &v);
        --u, --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    sort(b, b + n, cmp);
    for(int i = 0, j; i < n; i = j) {
        for(j = i; j < n && a[b[j]] == a[b[i]]; ++ j) {
            int u = b[j];
            for(auto e: adj[u]) {
                if (dp[e] < 0) {
                    dp[u] = 1;
                }
            }
        }
        for(j = i; j < n && a[b[j]] == a[b[i]]; ++ j) {
            int u = b[j];
            if (dp[u] != 1) dp[u] = -1;
        }
    }
    for(int i = 0; i < n; ++ i) {
        if (dp[i] == 1) {
            cout << i + 1 << ' ';
        }
    }
    cout << endl;
}

int main()
{
    solve();
    return 0;
}


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

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

int main(void){
  int n, m;
  long ans1 = 0, ans2 = 0;
  cin >> n >> m;
  
  if(!(n < 2))
    ans1 = nCr(n, 2);
  if(!(m < 2))
    ans2 = nCr(m, 2);
  
  cout << ans1 + ans2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));

    rep(i, n-1) {
        if (a[i] == a[i+1]) {
            puts("NO");
            return 0;
        }
    }

    puts("YES");
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		boolean opened = false;

		String ids = " ";// IDを空白区切りで登録
		for (int i = 0; i < N; i++) {
			String id = scanner.next();
			ids += id + " ";
		}
		int M = scanner.nextInt();
		for (int i = 0; i < M; i++) {
			String user = scanner.next();
			if (ids.indexOf(" " + user + " ") != -1) {
				if (opened) {
					opened = false;
					System.out.print("Closed by");
				} else {
					opened = true;
					System.out.print("Opened by");
				}
			} else {
				System.out.print("Unknown");
			}
			System.out.print(" " + user);
			System.out.print("\n");
		}

	}

}

Measured memory_bytes: 23624
def gcd(a:int, b:int)->int:
    while a:
        a, b = b%a, a
    return b

def main():
    n, x, *a = map(int, open(0).read().split())
    ans = abs(x-a[0])
    for i in a:
        dif = abs(x-i)
        if dif%ans:
            ans = gcd(ans, dif)
    print(ans)

main()

Measured memory_bytes: 14052
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

void solve(){
    char c;
    cin >> c;
    if('A' <= c && c <= 'Z') cout << "A" << endl;
    else cout << "a" << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}

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

int main() {
    int n, k ,ans;
    cin >> n >> k ;
    ans = 0;
    vector<int> p(n);
    rep(i,n) {
        cin >> p.at(i);
    }
    
    sort(p.begin(), p.end());
    
    rep(i,k) {
        ans = ans + p.at(i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(void){
    
    int w,h,x,y,r;
    cin>>w>>h>>x>>y>>r;
    
    if(x-r>=0&&y-r>=0&&x+r<=w&&y+r<=h){
        cout<<"Yes"<<endl;
    }
    
    else{cout<<"No"<<endl;}
    
    return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
#include <assert.h>
using namespace std;

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

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) cin >> a[i];
    REP(i,n) REP(j,n){
        if (a[i] != a[j] && abs(a[i] - a[j]) % (n - 1) == 0){
            cout << a[i] << " " << a[j] << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3104
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vvl = vector<vl>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 1000000000000;



int main(){
    int N;
    cin >>N;
    
    ll M=1e18;
    bool judge =true;
    
    vl A(N);
    rep(i,N){
        cin >>A[i];
    } 
    sort(all(A));
    if(A[0]==0) cout <<0<<endl;
    else{
        ll ans=1;
        rep(i,N){
            if(log10(ans)+log10(A[i]) <= 19){
                ans=ans*A[i];
                if(ans > M){
                    cout<<-1<<endl;
                    judge =false;
                    break;
                }
            }
            else{
                cout <<-1<<endl;
                judge = false;
                break;
            }
        }
        if(judge) cout <<ans<<endl;
    }
}


Measured memory_bytes: 4116
#include<stdlib.h>
int ROW_INDEX = 1;
//[min_range, max_range]からn_ints個の整数の組をすべてとりだしcomb[組][整数]に格納する
void AllCombs_ints(int min_range, int max_range, int depth, int n_ints, int *comb[]){
	if(depth > 0){
		for(int x = min_range; x <= max_range; x++){
			//combの0行目を一時的な格納場所として使っている。これも気持ち悪い。
			comb[0][depth-1] = x;
			if(depth == 1){
				for(int num_i = 1; num_i <= n_ints; num_i++)
					comb[ROW_INDEX][num_i-1] = comb[0][n_ints-num_i];
				ROW_INDEX++;
			}
			AllCombs_ints(x + 1, max_range, depth - 1, n_ints, comb);
		}
	}
	if(depth == n_ints)
		ROW_INDEX = 1;
}
int Find_Rightmost_Col(int threshold, int from, int n_rows, int n_slices, int n_cols, 
						int slices[n_slices], int mat[n_rows+1][n_cols+1]){
	int current_col = from;
	int value_cell[n_slices+1];
	for(int cell_i = 0; cell_i <= n_slices; cell_i++)
		value_cell[cell_i] = 0;
	while(current_col <= n_cols){
		for(int slice_i = 0; slice_i <= n_slices; slice_i++){
			for(int row_i = (slice_i == 0 ? 1 : slices[slice_i-1] + 1); 
				row_i <= (slice_i == n_slices ? n_rows : slices[slice_i]); row_i++){
				value_cell[slice_i] += mat[row_i][current_col];
			}
			if(value_cell[slice_i] > threshold)
				return current_col - 1;
		}
		current_col++;
	}
	return current_col - 1;
}
int Factorial(int upto){
	if(upto == 0)
		return 1;
	return upto * Factorial(upto-1);
}
int main(){
	int n_rows, n_cols, nmax_white;
	scanf("%d %d %d", &n_rows, &n_cols, &nmax_white);
	int mat_choco[n_rows+1][n_cols+1];
	for(int row_i = 1; row_i <= n_rows; row_i++){
		char str[n_cols];
		scanf("%s", str);
		for(int col_i = 1; col_i <= n_cols; col_i++){
			if(str[col_i-1] == '0')
				mat_choco[row_i][col_i] = 0;
			else
				mat_choco[row_i][col_i] = 1;
		}
	}
	int ans = n_rows * n_cols;
	for(int n_slices = 0; n_slices < n_rows; n_slices++){
		int n_combs = Factorial(n_rows-1) / Factorial(n_slices) / Factorial(n_rows-1-n_slices);
		int *pt_slice[n_combs+1];
		for(int pt_i = 0; pt_i <= n_combs; pt_i++)
			pt_slice[pt_i] = (int *) malloc(sizeof(int) * (n_slices>0 ? n_slices : 1));
		AllCombs_ints(1, n_rows-1, n_slices, n_slices, pt_slice);
		for(int comb_i = 1; comb_i <= n_combs; comb_i++){
			int ans_temp = n_slices;
			int current_col = 1;
			while(current_col <= n_cols){
				int col_temp = current_col;
				current_col = Find_Rightmost_Col(nmax_white, current_col, n_rows, n_slices, n_cols, pt_slice[comb_i], mat_choco);
				if(col_temp > current_col){
					ans_temp = n_rows * n_cols;
					break;
				}
				ans_temp++;
				current_col++;
			}
			if(--ans_temp < ans)
				ans = ans_temp;
		}
		for(int pt_i = 0; pt_i <= n_combs; pt_i++)
			free(pt_slice[pt_i]);
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=input()
b=input()
c=input()
sum=0
for i in range(n):
  x=a[i]
  y=b[i]
  z=c[i]
  if (x==y and x!=z) or (x==z and x!=y) or (y==z and y!=x):
    sum+=1
  elif x!=y and x!=z and y!=z:
    sum+=2
print(sum)

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


int main() {
  int n ;
  cin >> n;
  vector<string> s(n);
  int c=1;
  for(int i=0;i<n;i++){
    cin >> s.at(i);
  
    if(i>0){
      if(s.at(i).at(0)==s.at(i-1).at(0)){
        c++;
      }
    }
    reverse(s.at(i).begin(),s.at(i).end());
  }
  sort(s.begin(),s.end());
  int d=0;
  for(int i=1;i<n;i++){
    if(s.at(i)==s.at(i-1)){
      d++;
      break;
    }
  }
    
  if(c==n&&d==0){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


template<typename T>
class SegTree {
    int n;
    T def;
    vector<T> data;
    function<T(T, T)> operation;
    function<T(T, T)> update;
    
    T _query(int a, int b, int k, int l, int r) {
        if (r <= a || l >= b) return def;
        if (a <= l && r <= b) return data[k];
        T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2);
        T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r);
        return operation(c1, c2);
    }
    
public:
    SegTree<T>(int _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update)
            : def(_def), operation(_operation), update(_update) {
                n = 1;
                while (n < _n) n *= 2;
                data = vector<T>(2 * n - 1, def);
            }
    
    void change(int i, T x) {
        i += n - 1;
        data[i] = update(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }
    
    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }
    
    T operator[](int i) { return data[i + n - 1]; }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1);
    rep(i, n) cin >> a[i + 1];
    rep(i, n) (a[i + 1] += a[i]) %= m;
    // rep(i, n + 1) cout << a[i] << " "; cout << endl;
    
    map<int, int> mp;
    ll ans = 0;
    rep(i, n + 1) {
        ans += mp[a[i]];
        ++mp[a[i]];
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 3584
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        char[] arr = s.toCharArray();
        int len = s.length();
        if(len == 0){
            System.out.println("a");
            return;
        }
        HashSet<Character> set = new HashSet<>();
        for(int i=0;i<len;i++){
            set.add(arr[i]);
        }
        for(char x='a';x<='z';x++){
            if(!set.contains((Object)(x))){
                System.out.println(x);
                return;
            }
        }
        System.out.println("None");
    }
}

Measured memory_bytes: 26396
import math

def move(i,j,angle):
    rad = 2*(angle/360)*math.pi
    si = i + math.cos(math.radians(angle))
    sj = j + math.sin(math.radians(angle))
    return [round(si,5),round(sj,5)]

x = int(input())

i,j = 0,0
angle = 90
ans = 0
# t=10
while 1:
    # t-=1
    i,j = move(i,j,angle)
    # print(str(i) +'  '+str(j))
    angle += x
    ans += 1
    if(i == 0 and j == 0):
        break

print(ans)

Measured memory_bytes: 62716
from collections import Counter

n = int(input())
a = list(map(int,input().split()))
q = int(input())

C = Counter(a)
s = sum(a)

for _ in range(q):
  b,c = map(int,input().split())
  s = s - b*C[b] + c*C[b]
  C[c] += C[b]
  C[b] = 0
  print(s)

Measured memory_bytes: 24004
class StringEditor:
    def __init__(self, s):
        self.s = s

    def __str__(self):
        return self.s

    def print(self, start, end):
        """print command

        >>> e = StringEditor('abcde')
        >>> e.print(1, 3)
        bcd
        """
        print(self.s[start:end+1])

    def replace(self, start, end, word):
        """replace command

        >>> e = StringEditor('abcde')
        >>> e.replace(1, 3, 'xyz')
        >>> e.print(0, 4)
        axyze
        """
        self.s = self.s[:start] + word + self.s[end+1:]

    def reverse(self, start, end):
        """reverse command

        >>> e = StringEditor('abcde')
        >>> e.reverse(0, 2)
        >>> e.print(0, 4)
        cbade
        >>> e.reverse(2, 3)
        >>> e.print(0, 4)
        cbdae
        """
        if start > 0:
            rev = self.s[end:start-1:-1]
        else:
            rev = self.s[end::-1]

        self.s = self.s[:start] + rev + self.s[end+1:]


def run():
    s = input()
    num = int(input())
    editor = StringEditor(s)

    for _ in range(num):
        com, *args = input().split()

        if com == 'print':
            start, end = [int(i) for i in args]
            editor.print(start, end)
        elif com == 'reverse':
            start, end = [int(i) for i in args]
            editor.reverse(start, end)
        elif com == 'replace':
            start, end = [int(i) for i in args[0:2]]
            word = args[-1]
            editor.replace(start, end, word)
        else:
            raise ValueError('invalid command')


if __name__ == '__main__':
    run()


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

const int N = 101, K = 1e5 + 1;

int n, k, val[N];
bool b[K][2], pos[K][2];

bool DFS(int s, int nb) {
  if(s > k)
    return true;
  if(s == k)
    return false;
  if(b[s][nb])
    return pos[s][nb];
  b[s][nb] = true;
  pos[s][nb] = false;
  for(int i = 0; i < n; i++)
    if(!DFS(s + val[i], 1-nb)) {
      pos[s][nb] = true;
      return true;
    }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  cin >> n >> k;
  
  for(int i = 0; i < n; i++)
    cin >> val[i];
  if(DFS(0, 0))
    cout << "First";
  else
    cout << "Second";
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a-1);i>=(b);i--)
#define all(x) (x).begin(), (x).end()
const int INF = 1e18;
const int MOD = 1e9+7;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<string> vstr;
void print() {cout<<'\n';}template<class Head,class...Tail>void print(Head&&head,Tail&&...tail){cout<<head;if(sizeof...(tail)!=0)cout<<" ";print(forward<Tail>(tail)...);}template<class T>void print(vector<T>&vec){for(auto&a:vec){cout<<a;if(&a!=&vec.back())cout<<" ";}cout<<'\n';}template<class T>void print(vector<vector<T>>&df){for(auto&vec:df){print(vec);}}
template<class T=int>T in() {T x;cin>>x;return(x);}
template<class T=int>vector<T> input_to_vector(int n) {vector<T>x;rep(i,n){T a;cin>>a;x.push_back(a);}return(x);}

signed main(){
    int n = in();
    int t = in();
    int a = in();
    vint H = input_to_vector(n);
    double min = INF;
    int ans = 0;
    rep(i, n) {
        double tmp = abs((double)a - ((double)t - (double)H[i] * 0.006));
        if(tmp < min) {
            min = tmp;
            ans = i;
        }
    }
    print(ans+1);
}

Measured memory_bytes: 256
'use strict';

function Main(input) {
  const S = String(input.split('\n')[0]);
  const K = Number(input.split('\n')[1]);

  const checker = (S.search(/[2-9]/)) + 1;

  if(checker === 1) {
    console.log(S.substr(0, 1));
  } else if (checker > K) {
    console.log(1);
  } else {
    console.log(S.substr(checker-1, 1));
  }

};

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


Measured memory_bytes: 7372
import sys
import numpy as np

str = [int(i) for i in input().split()]
l, r = str

for i in range(991):
  if l <= 2019 * i and r >= 2019 * i:
    print(0)
    exit(0)
if r - l >= 2019:
  print(0)
elif l * r < 2019:
    print(l * (l + 1))
else:
    s = 2020
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            if (i * j) % 2019 < s:
                s = (i * j) % 2019
    print(s)



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

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

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

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

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

  vector<int> A;
  vector<mint> cumsum(1, 0);
  mint sum = 0;

  rep(i, n) {
    int a;
    cin >> a;
    A.push_back(a);
    sum += a;
    cumsum.push_back(sum);
  }

  mint res = 0;

  rep(i, n - 1) {
    mint mult = cumsum.back() - cumsum[i + 1];
    mint ai = A[i];
    // printf("%d %d\n", ai, mult);
    mint s = ai * mult;
    res += s;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 6764
import numpy as np

a, b = map(int, input().split())
#N = int(input())
#S = input()

ans = ""
if a > b:
    for i in range(a):
        ans += str(b)
else:
    for i in range(b):
        ans += str(a)
print(ans)
    
#map(int, input().split())



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

int main(){
    int a,b;
    cin>>a>>b;
    if(a>=6&&a<=12){
        cout<<b/2<<endl;
    }
    else if(a<=5){
        cout<<"0"<<endl;
    }else{

    cout<<b<<endl;

    }


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;
int a[100005],b[100005],c[100005];
int dp[100005][4];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
	}
	for(int i=1;i<=n;i++)
	{
		dp[i][1]=max(dp[i-1][2],dp[i-1][3])+a[i]+dp[i][1];
		dp[i][2]=max(dp[i-1][1],dp[i-1][3])+b[i]+dp[i][2];
		dp[i][3]=max(dp[i-1][1],dp[i-1][2])+c[i]+dp[i][3];
	}
	int ans=max(dp[n][1],max(dp[n][2],dp[n][3]));
	cout<<ans<<endl;
}

Measured memory_bytes: 6368
#include<stdio.h>
#include<string.h>
 
int main(void){

  char s[100001];
  int a=0,n,i;
  
  scanf("%s",s);
  n=strlen(s);
  
  for(i=0;i<n;i++){
    
    if(s[i]=='0')
      if(s[i+1]=='0'){
        s[i+1]='1';
        a++;
      }
    
    if(s[i]=='1')
      if(s[i+1]=='1'){
        s[i+1]='0';
        a++;
      }
  }
    
    printf("%d",a);
   
  return 0;
}

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

int main(){
  long long int a,b,c,k;
  cin>>a>>b>>c>>k;
  if(a>=k){
    cout<<k<<endl;
  }
  else if(a<k){
    if(a+b>=k){
      cout<<a<<endl;
    }
    else if(a+b<k){
      if(a+b+c>=k){
        cout<<a*2+b-k<<endl;
      }
    }
  }
}

Measured memory_bytes: 3580
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main() {
	string a;
	cin >> a;
	int k = 0, u = 0, p = 0, c = 0;
	for (int i = 0; i < a.length(); i++) {
		switch ( a[i])
		{
		case 'K':
			k++;
			break;
		case 'U':
			u++;
			break;
		case 'P':
			p++;
			break;
		case 'C':
			c++;
			break;
		default:
			break;
		}
	}
	int sum = min(min(min(k, u), p), c);
	cout << sum << endl;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N; cin >> N;
    vector<string> S(N); for (auto &s: S) cin >> s;
    int a = 0, b = 0, c = 0, ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 1; j < S[i].size(); j++) {
            if (S[i][j-1] == 'A' && S[i][j] == 'B') ans++;
        }
        if (S[i].back() == 'A' && S[i].front() == 'B') c++;
        else if (S[i].back() == 'A') a++;
        else if (S[i].front() == 'B') b++;
    }
    if (a == 0 && b == 0) ans += max(0, c - 1);
    else ans += min(a + c, b + c);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) (x.begin(), x.end())

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    cin >> n;
    cout << n/2 * (n-n/2) << endl;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    int gap = b-a;
    int height=0;
    for(int i=1;i<gap;i++){
        height+=i;
    }
    cout << height-a << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <climits>

using namespace std;

int array[32];
void search(int n, int depth)
{
	if(n == 0){
		for(int i=0; i<depth; ++i){
			printf("%s%d", i?" ":"", array[i]);
		}
		puts("");
	}else{
		for(int i=min(n, depth?array[depth-1]:INT_MAX); i; --i){
			array[depth] = i;
			search(n-i, depth+1);
		}
	}
}

int main()
{
	int n;
	while(scanf("%d", &n), n){
		search(n, 0);
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>

#define INF 1<<29

typedef long long LL;
using namespace std;

//mapわからん

int main(void) {
	LL n;
	cin >> n;
	vector<LL>A(n);
	LL sum=0, ans = 0;
	map<LL, LL>count;
	count[0] = 1;
	for (LL i = 0; i < n; i++) {
		cin >> A[i];
		sum += A[i];
		ans += count[sum];
		count[sum]++;
	}
	cout << ans;
	return 0;
	
}

Measured memory_bytes: 14336
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

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;
}
ll calc(ll h){
    if(h==1)return 1;
    return 1+2*calc(h/2);
}
int main(){
    ll h;
    cin >> h;
    cout << calc(h) << endl;
    return 0;
}

Measured memory_bytes: 256
import collections
n = int(input())
a = list(map(int,input().split()))
b = [0]
s = 0
for x in a:
  s += x
  b.append(s)
c = collections.Counter(b)
k = 0
for x in c.values():
  k += x*(x-1)//2
print(k)

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

int main() {
  int x1,y1,x2,y2,x3,y3,x4,y4;
  cin>>x1>>y1>>x2>>y2;
  x3=x2+y1-y2;
  y3=y2-x1+x2;
  x4=x1+y1-y2;
  y4=y1-x1+x2;
  cout<<x3<<' '<<y3<<' '<<x4<<' '<<y4<<endl;
}


Measured memory_bytes: 256
nums = [list(map(int, input().split())) for _ in range(3)]
bingo = [[0, 0, 0] for _ in range(3)]
n = int(input())
bs = [int(input()) for _ in range(n)]
for b in bs:
	for i in range(3):
		for j in range(3):
			if nums[i][j] == b:
				bingo[i][j] = 1
ans = 0
ans += bingo[0][0] * bingo[1][0] * bingo[2][0]
ans += bingo[0][1] * bingo[1][1] * bingo[2][1]
ans += bingo[0][2] * bingo[1][2] * bingo[2][2]
ans += bingo[0][0] * bingo[0][1] * bingo[0][2]
ans += bingo[1][0] * bingo[1][1] * bingo[1][2]
ans += bingo[2][0] * bingo[2][1] * bingo[2][2]
ans += bingo[0][0] * bingo[1][1] * bingo[2][2]
ans += bingo[2][0] * bingo[1][1] * bingo[0][2]

if ans >= 1:
	print("Yes")
else:
	print("No")



Measured memory_bytes: 3064
#include<bits/stdc++.h>
//#include<iostream>
using namespace std;
 
typedef long long ll;
const int N = 200005;
const int MOD = 1e9+7;

int n,k;
ll a[N];

ll fact[N],infact[N];

ll powermod(ll a,ll b){
	ll ret = 1;
	while(b){
		if(b&1){
			ret *= a;
			ret %= MOD;
		}
		b >>= 1;
		a *= a;
		a %= MOD;
	}
	return ret;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin>>n>>k;
	fact[0] = 1;
	infact[0] = powermod(fact[0],MOD-2);
	for(int i=1;i<=n;i++){
		fact[i] = fact[i-1] * i;
		fact[i] %= MOD;
		infact[i] = powermod(fact[i],MOD-2);
	}
	
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	
	ll ans = 0;
	for(int i=n-1;i>=k-1;i--){
		ll tmp = fact[i]*infact[i-k+1];
		tmp %= MOD;
		tmp *= infact[k-1];
		tmp %= MOD;
		tmp *= a[i];
		tmp %= MOD;
		ans += tmp;
		ans %= MOD;
	}
	
	for(int i=0;i<= n-k;i++){
		ll tmp = fact[n-1-i] * infact[n-1-i-k+1];
		tmp %= MOD;
		tmp *= infact[k-1];
		tmp %= MOD;
		tmp *= a[i];
		tmp %= MOD;
		ans -= tmp;
		ans %= MOD;
	}
	
	ans += MOD;
	ans %= MOD;
	cout<<ans;
	
	return 0;
}


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

using namespace std;

#define reps(i, n, m) for (int i = (int) (n); i < (int) (m); i++)
#define rep(i, n) reps(i, 0, (n))
#define all(v) (v).begin(), (v).end()

int main() {
    int n; cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    int q; cin >> q;
    while (q--) {
        int a; cin >> a;
        cout << lower_bound(all(v), a) - v.begin() << " ";
        cout << upper_bound(all(v), a) - v.begin() << endl;
    }
}



Measured memory_bytes: 3100
fn read_line() -> String {
    use std::io;
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

fn main() {
    let line = read_line();
    let mut iter = line.split_whitespace();
    let x:i64 = iter.next().unwrap().parse().unwrap();
    let y:i64 = iter.next().unwrap().parse().unwrap();
    let z:i64 = iter.next().unwrap().parse().unwrap();
    println!("{}", (x-z)/(y+z));
}

Measured memory_bytes: 4352
dis,num,move=map(int,input().rstrip().split())
if dis<0:
    dis=-dis
a=dis%move
b=move-dis%move
c=int((dis-a)//move)
if dis-num*move>0:
    result=dis-num*move
elif (num-c)%2==0:
    result=a
else:
    result=b
print(result)


Measured memory_bytes: 9152
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int[] s = new int[14];
        int[] h = new int[14];
        int[] c = new int[14];
        int[] d = new int[14];
        
        String str ; int m ;
        for(int i=0;i<n;i++){
            str=sc.next();m=sc.nextInt();
            switch(str.charAt(0)){
                case 'S':s[m]=-1;break;
                case 'H':h[m]=-1;break;
                case 'C':c[m]=-1;break;
                case 'D':d[m]=-1;break;
            }
        }
        
        for(int i=1;i<=13;i++){
            if (s[i]==0)System.out.printf("S %d\n",i);
        }
        for(int i=1;i<=13;i++){
            if (h[i]==0)System.out.printf("H %d\n",i);
        }
        for(int i=1;i<=13;i++){
            if (c[i]==0)System.out.printf("C %d\n",i);
        }
        for(int i=1;i<=13;i++){
            if (d[i]==0)System.out.printf("D %d\n",i);
        }
    }
}


Measured memory_bytes: 26368
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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 ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    int N, A, B; cin >> N >> A >> B;
    vector<ll> h(N);
    rep(i, N) cin >> h[i];

    auto check = [&](ll x) -> bool {
        ll cnt = 0;
        rep(i, N) if(h[i]-B*x > 0) { cnt += (h[i]-B*x + (A-B-1)) / (A-B); }
        return cnt <= x;
    };

    ll ng = 0, ok = 1e9;
    while(ok-ng > 1){
        ll mid = (ok + ng) / 2;
        if(check(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    
    return 0;
}

Measured memory_bytes: 1024
//int a = stoi(c); 文字列をintへ
//transform (s.begin (), s.end (), s.begin (), toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

int main() {
	string a, b,c; cin >> a >> b >> c;
	transform(a.begin(), a.end(), a.begin(), ::toupper);
	transform(b.begin(), b.end(), b.begin(), ::toupper);
	transform(c.begin(), c.end(), c.begin(), ::toupper);
	
	cout << a[0] << b[0] << c[0] << endl;
}

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

int main() {

	string s; 
	ll k;
	cin >> s >> k;

	ll firstNot1Index = -1;
	for (ll i = 0; i < s.size(); i++) {
		if (s[i] != '1') {
			firstNot1Index = i;
			break;
		}
	}

	if (firstNot1Index == -1) {
		cout << '1' << endl;
		return 0;
	}

	k--;
	if (firstNot1Index <= k) {
		cout << s[firstNot1Index] << endl;
	}
	else {
		cout << '1' << endl;
	}

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
//	"strconv"
	"sort"
//	"math"
//	"regexp"
)


var N,L int
var ans string
func main(){
	fmt.Scan(&N,&L)
	S := make([]string,N)

	for i:=0;i<N;i++{
		fmt.Scan(&S[i])
	}

	sort.Strings(S)
	for _,str := range S{
		ans += str		
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
      
      	while(true) {
        	String strArr[] = br.readLine().split(" ");
	        int a = Integer.parseInt(strArr[0]);
    	    int b = Integer.parseInt(strArr[1]);
          	if (a == 0 && b == 0) {
            	break;
            }
            StringBuilder sb = new StringBuilder();
            for(int i = 0; i < b; i++) {
                sb.append("#");
            }
            for(int i = 0; i < a; i++) {
                System.out.println(sb.toString());
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 25360